:root {
  --bg: #f4f6fa; --panel: #ffffff; --panel-2: #f7f8fb; --line: #e3e7ef; --line-2: #d3d9e4;
  --ink: #18202e; --ink-2: #4a5568; --muted: #6b778a;
  --brand: #14284b; --accent: #2457c5; --accent-soft: #e6eefc; --gold: #e8b04a;
  --unread-bg: #ffffff; --read-bg: #f6f8fb; --sel: #dfe8fb; --hover: #eef2f8;
  --danger: #c0392b; --ok: #1f8a4c; --warn: #b7791f; --on-accent: #fff; --brand-ink: #14284b;
  --shadow: 0 10px 40px rgba(16, 30, 60, .18), 0 2px 6px rgba(16, 30, 60, .08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c; --panel: #161c26; --panel-2: #1b2230; --line: #263042; --line-2: #33405a;
    --ink: #e7ebf2; --ink-2: #b9c2d0; --muted: #8b96a8;
    --accent: #7ea6ff; --accent-soft: #1d2a44; --unread-bg: #1a2130; --read-bg: #151b25; --sel: #22345a; --hover: #1e2635;
    --danger: #ff7b6b; --ok: #4cc27d; --warn: #e3a64a; --on-accent: #0b1220; --brand-ink: #e8b04a;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; flex: none; }
input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
kbd { font: 12px ui-monospace, monospace; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line-2); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 550; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; justify-content: center; padding: 11px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; background: none; border-radius: 50%; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.sm { width: 28px; height: 28px; } .icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.flip svg { transform: scaleX(-1); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 6px; font-weight: 550; }
.check { display: inline-grid; place-items: center; width: 36px; height: 36px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.check span { display: none; }

/* gates */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #14284b 0%, #1f3d73 60%, #2a4f8f 100%); }
.gate-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.gate-card h2 { margin: 4px 0 0; font-size: 18px; }
.gate-card p { margin: 0; }
.gate-card label, .settings-card label { display: grid; gap: 6px; font-weight: 550; font-size: 13px; color: var(--ink-2); }
.gate-card input, .settings-card input { padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); }
.gate-card input:focus, .settings-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.brand-lg { display: flex; align-items: center; gap: 12px; font-size: 22px; margin-bottom: 6px; }
.err { color: var(--danger); min-height: 1em; font-size: 13px; }

/* layout */
#app { display: grid; grid-template-columns: 232px minmax(320px, 420px) 1fr; grid-template-rows: 60px 1fr; grid-template-areas: "top top top" "side list read"; height: 100dvh; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 12px; padding: 0 12px 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 17px; width: 204px; flex: none; }
.brand b, .brand-lg b { color: var(--brand-ink); }
.search { flex: 1; max-width: 720px; display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 24px; padding: 0 14px; height: 42px; }
.search:focus-within { background: var(--panel); border-color: var(--accent); }
.search svg { color: var(--muted); }
.search input { flex: 1; border: 0; background: none; outline: none; height: 100%; min-width: 0; }
.me { margin-left: auto; display: flex; align-items: center; gap: 4px; position: relative; }
.avatar-btn { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-weight: 700; cursor: pointer; }
.menu { position: absolute; right: 0; top: 44px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 240px; padding: 6px; z-index: 50; display: grid; }
.menu-head { display: grid; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head span { color: var(--muted); font-size: 12.5px; }
.menu button { text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--hover); }

.sidebar { grid-area: side; padding: 12px 8px; overflow-y: auto; overflow-x: hidden; background: var(--bg); display: flex; flex-direction: column; }
.compose-btn { margin: 0 4px 14px; padding: 13px 20px; border-radius: 14px; background: var(--accent-soft); border: 0; font-weight: 650; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.compose-btn:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); background: var(--accent-soft); }
.folders { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.folders a { display: flex; align-items: center; gap: 14px; padding: 7px 14px; border-radius: 0 18px 18px 0; color: var(--ink-2); text-decoration: none; margin-right: 8px; }
.folders a:hover { background: var(--hover); }
.folders a.active { background: var(--sel); color: var(--ink); font-weight: 650; }
.folders a.has-unread { font-weight: 650; color: var(--ink); }
.folders .count { margin-left: auto; font-size: 12.5px; }
.sidebar-foot { margin-top: auto; padding: 12px 14px 4px; font-size: 12px; overflow-wrap: anywhere; }

.list-pane { grid-area: list; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); border-top-left-radius: 14px; min-height: 0; margin-top: 8px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 4px 8px; border-bottom: 1px solid var(--line); min-height: 48px; }
.bulk { display: flex; gap: 2px; }
.pager { font-size: 12.5px; margin-right: 4px; white-space: nowrap; }
.folder-head { padding: 10px 16px 0; font-size: 12.5px; }
.folder-head:empty { display: none; }
.folder-head .link-btn { padding: 0; }
.msg-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.msg { display: grid; grid-template-columns: 36px 1fr auto; grid-template-rows: auto auto auto; column-gap: 4px; padding: 9px 14px 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; background: var(--read-bg); position: relative; }
.msg.unread { background: var(--unread-bg); }
.msg.unread::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.msg:hover { background: var(--hover); }
.msg.selected, .msg.checked { background: var(--sel); }
.msg .check { grid-row: 1 / 3; width: 36px; height: 24px; }
.msg .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.msg.unread .who, .msg.unread .subj { font-weight: 700; color: var(--ink); }
.msg .when { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
.msg.unread .when { color: var(--accent); font-weight: 650; }
.msg .subj { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .snip { grid-column: 2 / 4; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .tcount { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.msg .badges { display: inline-flex; gap: 4px; align-items: center; vertical-align: middle; }
.msg .badges svg { width: 14px; height: 14px; color: var(--muted); }
.msg .star { grid-row: 3; grid-column: 1; justify-self: center; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px; display: grid; }
.msg .star svg { width: 16px; height: 16px; }
.msg .star.on, .star-btn.on { color: var(--gold); }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); font-weight: 600; }
.pill.warn { color: var(--warn); border-color: currentColor; background: transparent; }
.pill.bad { color: var(--danger); border-color: currentColor; background: transparent; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; }

/* reader */
.reader { grid-area: read; background: var(--panel); overflow-y: auto; min-width: 0; margin-top: 8px; border-top: 1px solid var(--line); }
.reader-empty { height: 100%; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.reader-empty svg { width: 56px; height: 56px; opacity: .35; }
.reader-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px; padding: 4px 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 48px; }
.reader-bar select { border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel); padding: 5px 6px; margin-left: 4px; }
.subject-line { display: flex; align-items: flex-start; gap: 10px; padding: 18px 24px 6px; }
.subject-line h1 { font-size: 21px; font-weight: 500; margin: 0; flex: 1; word-break: break-word; }
.star-btn { color: var(--muted); }
.thread { padding: 4px 0 40px; }
.tmsg { border-top: 1px solid var(--line); margin: 0 16px; }
.tmsg:first-child { border-top: 0; }
.tmsg-head { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; padding: 14px 8px 8px; cursor: pointer; align-items: start; }
.av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; }
.tmsg-who { min-width: 0; }
.tmsg-who b { font-weight: 650; }
.tmsg-who .addr { color: var(--muted); font-size: 12.5px; margin-left: 4px; }
.tmsg-who .to { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tmsg.collapsed .to { display: none; }
.tmsg-who .snip { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: none; }
.tmsg.collapsed .snip { display: block; }
.tmsg-date { color: var(--muted); font-size: 12.5px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.tmsg.collapsed .tmsg-content { display: none; }
.tmsg-content { padding: 0 8px 16px 60px; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 13px; background: var(--panel-2); border: 1px solid var(--line); }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice.warn { border-color: var(--warn); } .notice.warn svg { color: var(--warn); }
.notice.bad { border-color: var(--danger); } .notice.bad svg { color: var(--danger); }
.notice pre { margin: 6px 0 0; white-space: pre-wrap; font-size: 12px; }
.mail-frame { width: 100%; border: 0; display: block; min-height: 60px; background: #fff; border-radius: 4px; color-scheme: light; }
.text-body { white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0; }
.text-body .q { color: var(--muted); }
.text-body a { color: var(--accent); }
.atts { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 4px; padding: 0; list-style: none; }
.att { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 12px 6px 6px; max-width: 280px; text-decoration: none; color: var(--ink); background: var(--panel); }
.att:hover { background: var(--hover); }
.att .thumb { width: 44px; height: 44px; border-radius: 4px; background: var(--panel-2); display: grid; place-items: center; overflow: hidden; flex: none; font-size: 10px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.att .thumb img { width: 100%; height: 100%; object-fit: cover; }
.att .meta { min-width: 0; }
.att .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 550; }
.att .size { font-size: 12px; color: var(--muted); }
.reply-row { display: flex; gap: 10px; flex-wrap: wrap; padding: 6px 24px 0 84px; }
.reply-row .btn { border-radius: 20px; font-weight: 550; }

/* compose */
.compose { position: fixed; right: 24px; bottom: 0; width: 560px; max-width: calc(100vw - 32px); height: min(620px, calc(100dvh - 80px)); background: var(--panel); border-radius: 12px 12px 0 0; box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 40; border: 1px solid var(--line); }
.compose.min { height: auto; width: 320px; } .compose.min .compose-main { display: none; }
.compose.max { right: 50%; transform: translateX(50%); bottom: 4vh; width: min(1000px, 92vw); height: 88vh; border-radius: 12px; }
.compose-head { display: flex; align-items: center; gap: 2px; padding: 6px 8px 6px 16px; background: var(--brand); color: #fff; border-radius: 12px 12px 0 0; cursor: pointer; font-weight: 600; font-size: 13.5px; }
.compose.max .compose-head { border-radius: 12px 12px 0 0; }
.compose-head .icon-btn { color: #dfe6f3; } .compose-head .icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.compose-main { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.field { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 0 14px; min-height: 40px; }
.field .lbl { color: var(--muted); width: 36px; flex: none; }
.field input#c-subject { flex: 1; border: 0; outline: none; background: none; padding: 10px 0; }
.field select { flex: 1; border: 0; background: none; padding: 9px 0; outline: none; }
.chips { flex: 1; display: flex; flex-wrap: wrap; gap: 4px; padding: 5px 0; position: relative; min-width: 0; }
.chips input { flex: 1; min-width: 120px; border: 0; outline: none; background: none; padding: 4px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 14px; padding: 1px 4px 1px 10px; font-size: 13px; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.bad { border-color: var(--danger); color: var(--danger); }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; font-size: 15px; line-height: 1; }
.suggest { position: absolute; top: 100%; left: 0; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); min-width: 280px; max-width: 100%; padding: 4px; list-style: none; margin: 2px 0 0; }
.suggest li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: grid; }
.suggest li small { color: var(--muted); }
.suggest li.on, .suggest li:hover { background: var(--hover); }
.editor { flex: 1; overflow-y: auto; padding: 12px 16px; outline: none; word-wrap: break-word; min-height: 120px; }
.editor blockquote { margin: 0 0 0 .8ex; border-left: 2px solid var(--line-2); padding-left: 1ex; color: var(--ink-2); }
.editor img { max-width: 100%; }
.editor:empty::before { content: "Write your message…"; color: var(--muted); }
.c-atts { list-style: none; margin: 0; padding: 0 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.c-atts:not(:empty) { padding-bottom: 8px; }
.c-atts li { display: flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 4px 4px 10px; font-size: 12.5px; max-width: 100%; }
.c-atts li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.c-atts li.up { opacity: .6; }
.c-atts li button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; }
.compose-foot { display: flex; align-items: center; gap: 4px; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.compose-foot .btn.primary { border-radius: 20px; padding: 8px 22px; }
.fmt { display: flex; gap: 0; margin-left: 6px; }
.fmt button { border: 0; background: none; border-radius: 6px; cursor: pointer; padding: 4px 7px; min-width: 30px; color: var(--ink-2); font-size: 14px; }
.fmt button:hover { background: var(--hover); }
.drop-hint { display: none; position: absolute; inset: 40px 0 0; background: color-mix(in srgb, var(--accent) 12%, transparent); border: 2px dashed var(--accent); place-items: center; font-weight: 650; color: var(--accent); pointer-events: none; }
.compose.dragging .drop-hint { display: grid; }

/* settings */
dialog { border: 0; padding: 0; border-radius: 14px; box-shadow: var(--shadow); background: var(--panel); color: var(--ink); width: min(620px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); }
dialog::backdrop { background: rgba(10, 18, 34, .45); }
.settings-card { display: grid; }
.settings-card header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px 24px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.settings-card h2 { margin: 0; font-size: 19px; }
.settings-card section { padding: 6px 24px 18px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.settings-card section:last-child { border-bottom: 0; }
.settings-card h3 { margin: 8px 0 0; font-size: 14px; }
.settings-card .row { display: flex; align-items: center; gap: 12px; }
.editor.sig { border: 1px solid var(--line-2); border-radius: 8px; min-height: 90px; flex: none; }
.editor.sig:empty::before { content: "e.g. Seb Rounce · PrimePath Research"; }
.dns { display: grid; gap: 8px; font-size: 12.5px; }
.dns-row { display: grid; grid-template-columns: 22px 44px 1fr; gap: 8px; align-items: start; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.dns-row code { font: 12px ui-monospace, monospace; word-break: break-all; }
.dns-row .ok { color: var(--ok); } .dns-row .no { color: var(--danger); }
.dns-row svg { width: 18px; height: 18px; }
.kbd-list { line-height: 2; }

.toast { position: fixed; left: 24px; bottom: 24px; z-index: 100; background: #1d2433; color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: var(--shadow); display: flex; gap: 16px; align-items: center; max-width: calc(100vw - 48px); }
.toast .link-btn { color: #9cc0ff; }
.scrim { display: none; }
.only-mobile { display: none; }

/* phones + small tablets */
@media (max-width: 1100px) {
  #app { grid-template-columns: 210px 1fr; grid-template-areas: "top top" "side list"; }
  .brand { width: auto; }
  .reader { position: fixed; inset: 60px 0 0 210px; z-index: 20; margin: 0; }
  #app:not(.reading) .reader { display: none; }
}
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "top" "list"; grid-template-rows: 56px 1fr; }
  .topbar { padding: 0 8px; gap: 6px; }
  .brand span { display: none; }
  .only-mobile { display: inline-grid; }
  .hide-mobile { display: none !important; }
  #settings-btn { display: none; }
  .sidebar { position: fixed; z-index: 35; inset: 0 auto 0 0; width: 260px; background: var(--panel); transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); padding-top: 16px; }
  #app.nav-open .sidebar { transform: none; }
  #app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); }
  .list-pane { margin: 0; border-radius: 0; border-left: 0; }
  .reader { inset: 56px 0 0 0; }
  .subject-line { padding: 14px 16px 4px; }
  .subject-line h1 { font-size: 19px; }
  .tmsg { margin: 0 4px; }
  .tmsg-content { padding: 0 6px 14px; }
  .reply-row { padding: 6px 12px 0; }
  .compose, .compose.max { inset: 0; width: 100%; max-width: none; height: 100dvh; border-radius: 0; transform: none; }
  .compose-head { border-radius: 0; }
  .compose.min { inset: auto 0 0 0; height: auto; width: 100%; }
  .fmt { display: none; }
  .toast { left: 12px; right: 12px; bottom: 12px; }
  .pager { display: none; }
}
@media print {
  .topbar, .sidebar, .list-pane, .reader-bar, .reply-row, .compose { display: none !important; }
  #app { display: block; } .reader { position: static; display: block !important; }
}
@media (max-width: 760px) { .tmsg-who .addr { display: none; } .tmsg-head { gap: 10px; padding: 12px 4px 6px; } }
