:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
  color-scheme: dark;
  color: var(--ink);
  background: var(--page);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --page: #101512;
  --ink: #e7efea;
  --muted: #a4b0a9;
  --muted-strong: #829088;
  --line: #303c35;
  --surface: #171f1a;
  --surface-soft: #202a24;
  --surface-hover: #26322b;
  --green: #80d2ba;
  --green-button: #176456;
  --green-button-hover: #207565;
  --green-tint: #203c33;
  --gold: #e7bd6b;
  --danger: #ff9189;
  --danger-tint: #432825;
  --shadow: 0 18px 50px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--page); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(128,210,186,.4); outline-offset: 2px; }
a { color: var(--green); }
.boot-screen { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; color: #fff; background: var(--green-button); font-size: 23px; font-weight: 700; box-shadow: 0 8px 22px rgba(0,0,0,.3); }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(ellipse at 50% 0%, #1d382e, transparent 55%), var(--page); }
.auth-card { width: min(100%, 440px); border: 1px solid var(--line); border-radius: 24px; padding: 34px; background: rgba(23,31,26,.96); box-shadow: var(--shadow); }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-logo .brand-mark { width: 44px; height: 44px; }
.auth-logo strong { display: block; font-size: 20px; letter-spacing: -.04em; }
.auth-logo small { display: block; color: var(--muted); font-size: 12px; }
.auth-card h1 { font-size: 23px; margin: 0 0 8px; letter-spacing: -.04em; }
.auth-card p { color: var(--muted); margin: 0 0 23px; line-height: 1.7; font-size: 14px; }
.auth-secure-note { margin-top: 18px; text-align: center; color: var(--muted-strong); font-size: 11px; }
.field { display: grid; gap: 7px; margin-bottom: 15px; }
.field label { color: #c4cec8; font-size: 13px; font-weight: 600; }
.field input, .field textarea, .field select, .search-input, .compose-input { min-width: 0; width: 100%; border: 1px solid var(--line); border-radius: 11px; background: #111814; color: var(--ink); padding: 11px 13px; outline: 0; transition: border .16s, box-shadow .16s; }
.field input:focus, .field textarea:focus, .field select:focus, .search-input:focus, .compose-input:focus { border-color: #5eb59d; box-shadow: 0 0 0 3px rgba(128,210,186,.12); }
.field input::placeholder, .compose-input::placeholder, .field textarea::placeholder { color: #829088; }
.field .hint { color: var(--muted-strong); font-size: 11px; line-height: 1.6; }
.btn { border: 0; border-radius: 11px; padding: 10px 15px; font-weight: 600; transition: .16s ease; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .55; cursor: wait; transform: none; }
.btn-primary { background: var(--green-button); color: white; box-shadow: 0 4px 12px rgba(0,0,0,.22); }
.btn-primary:hover { background: var(--green-button-hover); }
.btn-secondary { color: var(--green); background: var(--green-tint); }
.btn-quiet { color: #c3cec7; background: transparent; }
.btn-quiet:hover { background: var(--surface-hover); }
.btn-danger { color: var(--danger); background: var(--danger-tint); }
.btn-wide { width: 100%; }
.auth-error, .inline-error { color: var(--danger) !important; font-size: 13px !important; margin: 10px 0 0 !important; }
.qr-image { display: block; width: 190px; height: 190px; margin: 16px auto; border: 10px solid #fff; border-radius: 14px; background: #fff; box-shadow: 0 3px 18px rgba(0,0,0,.3); }
.secret-code { direction: ltr; text-align: center; padding: 10px; margin: 0 0 16px; border-radius: 10px; background: var(--surface-soft); font: 600 14px ui-monospace, SFMono-Regular, monospace; letter-spacing: .1em; user-select: all; }
.recovery-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; direction: ltr; margin: 18px 0; }
.recovery-code { background: var(--surface-soft); border: 1px solid var(--line); padding: 9px; border-radius: 8px; text-align: center; font: 600 12px ui-monospace, monospace; }

.app-shell { display: grid; grid-template-columns: 270px minmax(0,1fr); max-width: 1640px; min-height: 100vh; margin: 0 auto; background: var(--surface); box-shadow: 0 0 70px rgba(0,0,0,.3); }
.sidebar-scrim { display: none; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: #141b17; border-left: 1px solid var(--line); padding: 22px 16px 18px; display: flex; flex-direction: column; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 25px; }
.sidebar-brand .brand-mark { width: 40px; height: 40px; border-radius: 14px; font-size: 19px; }
.sidebar-brand strong { display: block; font-size: 18px; line-height: 1.25; letter-spacing: -.04em; }
.sidebar-brand small { display: block; color: var(--muted); font-size: 11px; }
.compose-button { width: 100%; justify-content: flex-start; padding: 12px 15px; margin-bottom: 25px; border-radius: 13px; }
.sidebar-caption { padding: 0 11px; margin: 0 0 8px; color: #95a39a; font-size: 11px; font-weight: 700; }
.nav-list { display: grid; gap: 3px; margin-bottom: 24px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px; border: 0; border-radius: 9px; background: transparent; color: #c0cbc4; text-align: right; font-size: 13px; transition: .14s; }
.nav-item:hover { background: var(--surface-hover); }
.nav-item.active { color: var(--green); background: var(--green-tint); font-weight: 700; }
.nav-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; flex: 0 0 auto; }
svg { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-count { margin-right: auto; color: #98a69e; font-size: 11px; }
.alias-head { display: flex; align-items: center; justify-content: space-between; padding: 0 10px; margin: 0 0 8px; }
.alias-head .sidebar-caption { padding: 0; margin: 0; }
.tiny-button { display: inline-grid; place-items: center; width: 26px; height: 26px; border: 0; border-radius: 8px; background: transparent; color: #a4b0a9; }
.tiny-button:hover { background: var(--surface-hover); color: var(--green); }
.alias-list { display: grid; gap: 2px; }
.alias-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; background: transparent; border-radius: 9px; color: #abb8b0; text-align: right; font-size: 12px; }
.alias-item:hover { background: var(--surface-hover); }
.alias-item.active { color: var(--green); background: var(--green-tint); font-weight: 600; }
.alias-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #76c9af; }
.alias-item.inactive { color: #84938a; }
.alias-item.inactive .alias-dot { background: #58655d; }
.alias-short { flex: 1; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: right; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 13px 5px 0; display: flex; align-items: center; gap: 8px; }
.account-avatar { width: 33px; height: 33px; border-radius: 50%; background: var(--green-tint); color: var(--green); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.account-info { min-width: 0; flex: 1; }
.account-info strong { display: block; font-size: 11px; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: right; }
.account-info small { display: block; font-size: 10px; color: var(--muted); }
.main-area { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 12px; height: 76px; padding: 0 32px; background: rgba(21,28,24,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.mobile-brand { display: none; }
.topbar-title { min-width: 110px; }
.topbar-title strong { display: block; font-size: 16px; letter-spacing: -.03em; }
.topbar-title small { display: block; color: var(--muted); font-size: 11px; }
.search-box { position: relative; width: min(430px, 48%); margin: 0 auto; }
.search-input { border-color: transparent; background: var(--surface-soft); padding: 10px 42px 10px 14px; border-radius: 11px; font-size: 13px; }
.search-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); display: inline-flex; color: #98a69e; }
.search-icon svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.icon-button { display: inline-grid; place-items: center; border: 0; background: transparent; color: #aab6af; border-radius: 9px; width: 38px; height: 38px; flex: 0 0 auto; }
.icon-button:hover { background: var(--surface-hover); color: var(--green); }
.content-area { display: grid; grid-template-columns: minmax(280px, 390px) minmax(0,1fr); flex: 1; min-height: calc(100vh - 76px); }
.list-pane { min-width: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.list-heading { padding: 23px 22px 14px; display: flex; align-items: center; justify-content: space-between; }
.list-heading h1 { margin: 0; font-size: 19px; letter-spacing: -.04em; }
.list-heading span { color: var(--muted); font-size: 11px; }
.list-tools { display: flex; align-items: center; gap: 5px; padding: 0 19px 12px; border-bottom: 1px solid var(--line); }
.result-count { margin-right: auto; color: #91a097; font-size: 11px; }
.message-list { min-height: 0; overflow-y: auto; }
.message-row { position: relative; display: grid; grid-template-columns: 30px minmax(0,1fr) 26px; gap: 10px; align-items: start; padding: 15px 20px 14px 15px; border-bottom: 1px solid #28332d; cursor: pointer; transition: background .14s; }
.message-row:hover { background: #1b2520; }
.message-row.selected { background: #20392f; }
.message-row.unread { background: #19231d; }
.message-row.unread .message-sender, .message-row.unread .message-subject { color: var(--ink); font-weight: 700; }
.sender-avatar { width: 30px; height: 30px; border-radius: 50%; background: #2a352e; color: #c0cbc4; display: grid; place-items: center; font-weight: 700; font-size: 11px; }
.message-row:nth-child(4n+2) .sender-avatar { color: #f0d18c; background: #443923; }
.message-row:nth-child(4n+3) .sender-avatar { color: #d0c0f2; background: #382f49; }
.message-row:nth-child(4n+4) .sender-avatar { color: #f2b6a9; background: #482f2c; }
.message-info { min-width: 0; }
.message-meta { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.message-sender { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #bdc9c2; font-size: 12px; flex: 1; }
.message-time { color: #91a097; font-size: 10px; white-space: nowrap; }
.message-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #d1dad5; font-size: 12px; margin-bottom: 4px; }
.message-address { display: inline-block; max-width: 100%; color: #9aa89f; font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; }
.message-star { color: #77857c; width: 24px; height: 24px; border: 0; background: transparent; padding: 3px; }
.message-star.active { color: var(--gold); }
.message-star svg { width: 16px; height: 16px; fill: currentColor; stroke: currentColor; }
.empty-state { display: grid; justify-items: center; gap: 8px; min-height: 230px; place-content: center; padding: 24px; text-align: center; color: #99a69e; }
.empty-state strong { color: #d0d9d3; font-size: 14px; }
.empty-state p { max-width: 240px; margin: 0; line-height: 1.7; font-size: 12px; }
.loading { display: grid; place-content: center; min-height: 180px; color: #99a69e; font-size: 12px; }
.reader { min-width: 0; display: flex; flex-direction: column; }
.reader-empty { flex: 1; display: grid; place-content: center; justify-items: center; color: #a0ada5; text-align: center; padding: 24px; }
.reader-empty .empty-illustration { width: 92px; height: 74px; margin-bottom: 20px; border: 1px solid var(--line); border-radius: 24px; display: grid; place-items: center; background: #1a231e; color: var(--green); }
.empty-illustration svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.25; }
.reader-empty strong { color: #c5d0c9; font-size: 14px; }
.reader-empty p { margin: 7px 0 0; font-size: 12px; }
.reader-head { padding: 23px 28px 18px; border-bottom: 1px solid var(--line); }
.reader-actions { display: flex; align-items: center; gap: 3px; margin-bottom: 22px; }
.reader-actions .spacer { flex: 1; }
.reader-subject { margin: 0 0 17px; font-size: 22px; line-height: 1.45; letter-spacing: -.04em; overflow-wrap: anywhere; }
.reader-sender { display: flex; align-items: center; gap: 10px; }
.reader-sender .sender-avatar { width: 38px; height: 38px; }
.reader-sender-main { min-width: 0; flex: 1; }
.reader-sender-main strong { display: block; font-size: 12px; }
.reader-sender-main small { display: block; color: var(--muted); font-size: 11px; direction: ltr; text-align: right; overflow-wrap: anywhere; }
.reader-date { color: #98a59d; font-size: 10px; white-space: nowrap; }
.reader-recipient { margin-top: 12px; margin-right: 48px; color: #a4b0a9; font-size: 11px; }
.reader-recipient .recipient-tag { display: inline-block; direction: ltr; color: #d4dfd8; background: #28342d; padding: 2px 7px; border-radius: 6px; margin-right: 4px; }
.reader-body { padding: 26px 30px; overflow-wrap: anywhere; line-height: 1.85; font-size: 14px; color: #d9e2dc; }
.reader-body p:first-child { margin-top: 0; }
.reader-body a { color: var(--green); }
.reader-body table { max-width: 100%; border-collapse: collapse; }
.reader-body td, .reader-body th { border: 1px solid var(--line); padding: 6px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 30px 25px; }
.attachment-link { display: flex; align-items: center; gap: 9px; max-width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; text-decoration: none; color: #d1dcd5; font-size: 11px; background: var(--surface-soft); }
.attachment-link:hover { border-color: #517c6d; background: var(--surface-hover); }
.attachment-meta { display: block; color: #99a69e; font-size: 10px; }
.reader-reply { border-top: 1px solid var(--line); padding: 18px 28px; margin-top: auto; }
.compose-fab { display: none; }

.modal { width: min(100% - 28px, 540px); max-height: min(90vh, 850px); border: 1px solid var(--line); border-radius: 19px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 25px 80px rgba(0,0,0,.58); }
.modal::backdrop, .message-dialog::backdrop { background: rgba(0,0,0,.62); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 17px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; max-height: calc(90vh - 120px); overflow: auto; }
.modal-foot { display: flex; justify-content: flex-start; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.compose-modal { width: min(100% - 24px, 700px); }
.compose-head { display: flex; align-items: center; gap: 8px; padding: 15px 17px; background: var(--surface-soft); border-bottom: 1px solid var(--line); }
.compose-head strong { flex: 1; font-size: 14px; }
.compose-form { padding: 0 20px 14px; }
.compose-line { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 5px 0; }
.compose-line label { width: 48px; flex: 0 0 auto; color: #a5b1aa; font-size: 12px; }
.compose-input { border: 0; border-radius: 0; padding: 9px 0; font-size: 13px; box-shadow: none !important; }
.compose-input:focus { border-color: transparent; }
.compose-select { border: 0; padding: 9px 0; background: transparent; color: var(--ink); flex: 1; outline: 0; direction: ltr; text-align: right; }
.compose-text { width: 100%; min-height: 230px; border: 0; resize: vertical; outline: 0; padding: 17px 0; line-height: 1.8; color: var(--ink); font-size: 13px; }
.compose-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 10px; }
.file-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.file-chip { display: flex; gap: 8px; align-items: center; max-width: 100%; padding: 5px 8px; border-radius: 8px; background: var(--surface-soft); color: #c4cec8; font-size: 10px; }
.file-chip button { border: 0; background: transparent; color: #9aa79f; padding: 0; }
.alias-manager-list { display: grid; gap: 8px; }
.alias-manager-row { display: flex; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--line); border-radius: 12px; }
.alias-manager-row .alias-detail { flex: 1; min-width: 0; }
.alias-detail strong { display: block; direction: ltr; text-align: right; font-size: 12px; overflow-wrap: anywhere; }
.alias-detail small { display: block; color: var(--muted); font-size: 10px; margin-top: 2px; }
.alias-manager-actions { display: flex; gap: 4px; }
.alias-manager-actions .icon-button { width: 32px; height: 32px; }
.toast { position: fixed; z-index: 10; bottom: 24px; left: 24px; max-width: min(420px, calc(100vw - 48px)); padding: 11px 16px; border-radius: 11px; background: #26342c; color: white; box-shadow: 0 8px 25px rgba(0,0,0,.45); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; font-size: 12px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #713631; }
.load-more { margin: 12px; align-self: center; }
.label-chip { display: inline-flex; max-width: 100%; overflow: hidden; text-overflow: ellipsis; align-items: center; gap: 5px; padding: 2px 7px; border-radius: 6px; background: var(--surface-soft); color: #a9b6ae; font-size: 10px; }
.alias-badge { display: inline-block; margin-top: 5px; max-width: 100%; padding: 2px 6px; border-radius: 5px; background: var(--green-tint); color: var(--green); direction: ltr; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }
.mobile-back { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 226px minmax(0,1fr); }
  .content-area { grid-template-columns: minmax(250px, 340px) minmax(0,1fr); }
  .topbar { padding: 0 20px; }
  .reader-head { padding: 20px; }
  .reader-body { padding: 22px; }
  .reader-reply { padding: 16px 20px; }
}
@media (max-width: 720px) {
  body { background: var(--page); }
  .app-shell { display: block; min-height: 100dvh; }
  .sidebar { position: fixed; z-index: 6; inset: 0 0 0 auto; width: min(300px, 84vw); height: 100dvh; transform: translateX(105%); transition: transform .22s ease; box-shadow: var(--shadow); border: 0; border-left: 1px solid var(--line); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { display: none; position: fixed; inset: 0; z-index: 5; background: rgba(0,0,0,.62); }
  .sidebar-scrim.open { display: block; }
  .topbar { height: 64px; padding: 0 12px; gap: 8px; }
  .mobile-brand { display: inline-flex; align-items: center; gap: 8px; min-width: 72px; }
  .mobile-brand .brand-mark { width: 32px; height: 32px; border-radius: 11px; font-size: 15px; }
  .mobile-brand strong { font-size: 13px; }
  .topbar-title { display: none; }
  .search-box { width: auto; flex: 1; margin: 0; }
  .search-input { padding: 9px 35px 9px 10px; font-size: 12px; }
  .search-icon { right: 11px; }
  .topbar > .icon-button { width: 34px; height: 34px; }
  .content-area { display: block; min-height: calc(100dvh - 64px); }
  .list-pane { min-height: calc(100dvh - 64px); border: 0; }
  .list-heading { padding: 17px 17px 12px; }
  .list-heading h1 { font-size: 17px; }
  .list-tools { padding: 0 14px 10px; }
  .message-row { padding: 14px 16px 13px 13px; }
  .reader { display: none; }
  .content-area.reading .list-pane { display: none; }
  .content-area.reading .reader { display: flex; min-height: calc(100dvh - 64px); }
  .reader-head { padding: 14px 17px 16px; }
  .reader-actions { margin-bottom: 14px; }
  .reader-subject { font-size: 19px; margin-bottom: 13px; }
  .reader-body { padding: 20px 18px; font-size: 13px; }
  .attachments { margin: 0 18px 20px; }
  .reader-reply { padding: 14px 17px; }
  .mobile-back { display: inline-grid; }
  .compose-fab { display: inline-flex; position: fixed; z-index: 4; left: 18px; bottom: 19px; border-radius: 16px; padding: 13px 17px; box-shadow: 0 8px 28px rgba(18,102,90,.26); }
}
@media (max-width: 420px) {
  .auth-card { padding: 26px 21px; border-radius: 19px; }
  .mobile-brand strong { display: none; }
  .reader-date { font-size: 9px; }
  .reader-recipient { margin-right: 0; }
  .modal { width: calc(100% - 16px); border-radius: 15px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; scroll-behavior: auto !important; } }
