:root {
  --app-bg: #e8edf2;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --sidebar: #f3f6f8;
  --line: #d8e0e7;
  --line-soft: #edf1f4;
  --text: #182231;
  --muted: #637083;
  --muted-2: #8792a0;
  --teal: #0d9488;
  --teal-ink: #0f5f59;
  --blue: #2563eb;
  --danger: #b91c1c;
  --shadow: 0 18px 48px rgba(22, 34, 51, 0.16);
  --small-shadow: 0 8px 22px rgba(22, 34, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--app-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(13, 148, 136, 0.13), rgba(37, 99, 235, 0.1)),
    var(--app-bg);
}

.login-panel {
  position: relative;
  width: min(430px, 100%);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(216, 224, 231, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
}

.login-accent {
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.brand-row,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 112px;
  height: 42px;
  object-fit: contain;
}

.brand-row h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.1;
}

.brand-row p,
.topbar p,
.empty-state p {
  margin: 4px 0 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 30px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.login-form button,
.compose-btn,
#sendMessageBtn {
  border: 0;
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-weight: 850;
  padding: 12px 14px;
}

.login-form button:hover,
.compose-btn:hover,
#sendMessageBtn:hover {
  background: #0f8278;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.mail-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.sidebar-logo {
  width: 86px;
  height: 32px;
  object-fit: contain;
}

.sidebar-brand {
  padding: 2px 8px 10px;
}

.sidebar-brand span {
  font-weight: 900;
  color: #263241;
}

.sidebar-label {
  padding: 2px 10px 0;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: calc(100% - 8px);
  margin-inline: 4px;
  box-shadow: var(--small-shadow);
}

.icon {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  line-height: 1;
}

.mailbox-list,
.folder-list {
  display: grid;
  gap: 5px;
}

.mailbox-card,
.folder,
.logout-btn {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 10px 11px;
  text-align: left;
  background: transparent;
  color: #334155;
}

.mailbox-card {
  border: 1px solid transparent;
}

.mailbox-card:hover,
.folder:hover,
.logout-btn:hover {
  background: rgba(255, 255, 255, 0.76);
}

.mailbox-card.active,
.folder.active {
  background: #d9f2ee;
  color: var(--teal-ink);
  font-weight: 850;
}

.mailbox-card.active {
  border-color: rgba(13, 148, 136, 0.28);
}

.mailbox-card strong {
  display: block;
  overflow: hidden;
  color: inherit;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-card span {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.folder b {
  min-width: 22px;
  min-height: 18px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.logout-btn {
  margin-top: auto;
  color: var(--danger);
  font-weight: 800;
}

.content {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
  background: var(--surface-soft);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
}

.topbar h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.topbar p {
  font-size: 13px;
}

.search-box {
  display: flex;
  gap: 8px;
  width: min(540px, 52vw);
}

.search-box input {
  height: 42px;
  border-radius: 6px;
  background: #f7fafc;
}

.search-box button,
.list-toolbar button,
.message-tools button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font-weight: 850;
}

.search-box button {
  padding: 0 14px;
}

.mail-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(330px, 38%) minmax(0, 1fr);
}

.message-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: #fff;
}

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.list-toolbar button {
  padding: 6px 9px;
  font-size: 12px;
}

.message-list {
  min-width: 0;
  overflow: auto;
  background: #fff;
}

.message-row {
  position: relative;
  width: 100%;
  min-height: 86px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: #fff;
  padding: 14px;
  text-align: left;
}

.message-row::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
}

.message-row:hover,
.message-row.active {
  background: #f5faf9;
}

.message-row.active::before {
  background: var(--teal);
}

.message-row.unread {
  background: #fbfefe;
}

.message-row.unread .avatar {
  background: #d9f2ee;
  color: var(--teal-ink);
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e7ecf1;
  color: #334155;
  font-size: 12px;
  font-weight: 900;
}

.message-row.unread .sender,
.message-row.unread .subject {
  font-weight: 900;
}

.sender,
.subject,
.preview {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sender {
  color: #1f2937;
  font-size: 14px;
}

.subject {
  margin-top: 4px;
  color: #111827;
  font-size: 14px;
}

.preview {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.message-time {
  color: var(--muted-2);
  font-size: 12px;
  white-space: nowrap;
}

.reader {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(#f8fafc, #f8fafc) padding-box,
    var(--surface-soft);
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 32px;
  text-align: center;
}

.empty-state h3 {
  margin: 16px 0 0;
  font-size: 20px;
}

.empty-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e5edf2;
  color: #486071;
  font-weight: 900;
  font-size: 24px;
}

.message-detail {
  min-height: 100%;
  padding: 26px;
}

.reader-card {
  max-width: 920px;
  min-height: calc(100vh - 124px);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(22, 34, 51, 0.06);
}

.reader-head {
  padding: 24px 26px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.reader-head h3 {
  margin: 0 0 16px;
  font-size: 24px;
  line-height: 1.25;
}

.identity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.identity .avatar {
  flex: 0 0 auto;
}

.identity strong,
.identity span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity span,
.reader-date,
.message-meta {
  color: var(--muted);
  font-size: 13px;
}

.message-meta {
  display: grid;
  gap: 6px;
  padding: 14px 26px 0;
}

.message-body {
  display: block;
  width: calc(100% - 52px);
  min-height: 60px;
  border: 0;
  margin: 24px 26px 30px;
}

.load-images {
  margin: 0 26px 18px;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 26px 18px;
}

.attachment-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: #334155;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.message-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 26px 22px;
  border-top: 1px solid var(--line-soft);
}

.message-tools button {
  padding: 9px 12px;
}

.message-tools button:first-child {
  border-color: rgba(13, 148, 136, 0.45);
  color: var(--teal-ink);
}

.compose-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end end;
  padding: 22px;
  background: rgba(15, 23, 42, 0.18);
}

.compose-window {
  width: min(720px, 100%);
  max-height: calc(100vh - 44px);
  display: grid;
  grid-template-rows: auto auto minmax(220px, 1fr) auto auto;
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #fff;
  overflow: hidden;
}

.compose-window header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 15px;
  background: #243244;
  color: #fff;
  font-weight: 850;
}

.compose-window header button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-weight: 900;
}

.compose-fields {
  display: grid;
  gap: 0;
  border-bottom: 1px solid var(--line-soft);
}

.compose-window label {
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
}

.compose-window label:last-child {
  border-bottom: 0;
}

.compose-window label input,
.compose-window label select {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.compose-window textarea {
  min-height: 260px;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 18px 16px;
}

.compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--line-soft);
}

.compose-actions input {
  min-width: 0;
  border: 0;
  padding-left: 0;
}

#sendMessageBtn {
  min-width: 92px;
}

.compose-window .form-error {
  padding: 0 14px 12px;
}

@media (max-width: 980px) {
  .mail-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content {
    min-height: 760px;
  }

  .mail-grid {
    grid-template-columns: 1fr;
  }

  .reader {
    min-height: 460px;
  }

  .topbar {
    height: auto;
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .login-shell,
  .compose-modal {
    padding: 12px;
  }

  .login-panel {
    padding: 24px 18px;
  }

  .mail-grid {
    display: block;
  }

  .message-pane {
    min-height: 360px;
  }

  .message-detail {
    padding: 14px;
  }

  .reader-card {
    min-height: 420px;
  }

  .reader-head,
  .message-meta,
  .message-body,
  .message-tools,
  .attachment-list {
    padding-left: 16px;
    padding-right: 16px;
  }

  .identity-row {
    align-items: flex-start;
    flex-direction: column;
  }
}
