/* SecureMail — design tokens and themes.
   app.js sets <html data-theme="adaptive|graphite|rail|terminal|panels" data-mode="auto|light|dark">.
   Every component reads the tokens below, so a theme restyles all pages, menus and dialogs.
   Theme-specific layout rules live at the end of this file. */
:root {
  --bg: #111214; --rail: #0d0e10; --panel: #17181b; --panel-2: #1c1d21; --raise: #26282d;
  --line: #2e3036; --line-soft: #232529; --text: #ececee; --muted: #a3a5ad; --faint: #777a83;
  --accent: #6ea8fe; --accent-ink: #0b1220; --accent-soft: #1a2638; --ok: #5fd39a; --ok-soft: #13291f;
  --warn: #e9be62; --warn-soft: #2e2512; --bad: #ff8189; --bad-soft: #351a1d; --focus: #9cc3ff;
  --shadow: 0 16px 48px rgb(0 0 0 / 45%); --backdrop: rgb(0 0 0 / 55%);
  --radius: 10px; --radius-sm: 6px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --fs: 14px; --title-track: -0.015em;
  --ctl: 32px; --ctl-sm: 28px; --nav-h: 30px; --bar-h: 48px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 28px; --s7: 40px;
  --card-pad: 16px; --content-pad: 20px;
  --rail-w: 216px; --folders-w: 196px; --list-w: 380px;
  --shell-gap: 0px; --mail-h: calc(100vh - var(--bar-h));
  color-scheme: dark;
}

/* Adaptive (default): neutral, follows the system light/dark setting unless the user picks one. */
:root[data-theme="adaptive"][data-mode="light"] {
  --bg: #ffffff; --rail: #f7f7f8; --panel: #ffffff; --panel-2: #f6f6f7; --raise: #ececef;
  --line: #dcdce1; --line-soft: #e9e9ec; --text: #17181b; --muted: #55575e; --faint: #7c7e86;
  --accent: #2f6fdb; --accent-ink: #ffffff; --accent-soft: #e8f0fd; --ok: #157a4a; --ok-soft: #e3f4ea;
  --warn: #8a5a00; --warn-soft: #fbf0d9; --bad: #b4232f; --bad-soft: #fbe5e7; --focus: #2f6fdb;
  --shadow: 0 14px 40px rgb(20 20 30 / 12%); --backdrop: rgb(20 20 30 / 35%);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:is(:not([data-theme]), [data-theme="adaptive"]):not([data-mode="dark"]) {
    --bg: #ffffff; --rail: #f7f7f8; --panel: #ffffff; --panel-2: #f6f6f7; --raise: #ececef;
    --line: #dcdce1; --line-soft: #e9e9ec; --text: #17181b; --muted: #55575e; --faint: #7c7e86;
    --accent: #2f6fdb; --accent-ink: #ffffff; --accent-soft: #e8f0fd; --ok: #157a4a; --ok-soft: #e3f4ea;
    --warn: #8a5a00; --warn-soft: #fbf0d9; --bad: #b4232f; --bad-soft: #fbe5e7; --focus: #2f6fdb;
    --shadow: 0 14px 40px rgb(20 20 30 / 12%); --backdrop: rgb(20 20 30 / 35%);
    color-scheme: light;
  }
}

/* Graphite: near-black, violet accent, one-line message rows. */
:root[data-theme="graphite"] {
  --bg: #09090b; --rail: #0c0c0e; --panel: #0f0f12; --panel-2: #141418; --raise: #1d1d23;
  --line: #26262d; --line-soft: #1b1b20; --text: #ededf0; --muted: #a1a1ac; --faint: #6f6f7a;
  --accent: #8b7cf6; --accent-ink: #ffffff; --accent-soft: #1e1a38; --focus: #b4aaff;
  --ok: #4ade80; --ok-soft: #11261a; --warn: #fbbf24; --warn-soft: #2a210c; --bad: #f87171; --bad-soft: #2d1416;
  --radius: 8px; --radius-sm: 5px; --nav-h: 28px; --list-w: 480px;
}

/* Icon rail: deep navy, sky accent, 56px icon-only sidebar. */
:root[data-theme="rail"] {
  --bg: #0b1220; --rail: #080e1a; --panel: #0e1627; --panel-2: #111b2e; --raise: #19253b;
  --line: #213049; --line-soft: #182439; --text: #e6edf7; --muted: #9fb0c6; --faint: #6f819b;
  --accent: #38bdf8; --accent-ink: #04121c; --accent-soft: #0c2a3d; --focus: #7dd3fc;
  --ok: #4ade80; --ok-soft: #0f2a1d; --warn: #fbbf24; --warn-soft: #2b230e; --bad: #fb7185; --bad-soft: #321520;
  --radius: 10px; --radius-sm: 7px; --rail-w: 56px; --folders-w: 184px;
}

/* Terminal: monospace, green on black, square corners, dense rows. */
:root[data-theme="terminal"] {
  --bg: #0a0d0a; --rail: #070907; --panel: #0c100c; --panel-2: #0f150f; --raise: #162016;
  --line: #1f2b1f; --line-soft: #162016; --text: #c9d6c9; --muted: #8fa38f; --faint: #61755f;
  --accent: #7ee787; --accent-ink: #04140a; --accent-soft: #11281a; --focus: #7ee787;
  --ok: #7ee787; --ok-soft: #11281a; --warn: #e3b341; --warn-soft: #2a2310; --bad: #ff7b72; --bad-soft: #2d1513;
  --font: var(--mono); --fs: 13px; --title-track: 0;
  --radius: 3px; --radius-sm: 2px; --ctl: 30px; --ctl-sm: 26px; --nav-h: 28px; --list-w: 500px;
}

/* Floating panels: rounded panels on black, teal accent, sender initials. */
:root[data-theme="panels"] {
  --bg: #050607; --rail: #0e1115; --panel: #0e1115; --panel-2: #13171c; --raise: #1b2027;
  --line: #242a33; --line-soft: #1a1f26; --text: #e7ebf0; --muted: #9aa4b1; --faint: #6b7480;
  --accent: #2dd4bf; --accent-ink: #022c26; --accent-soft: #0d2826; --focus: #5eead4;
  --ok: #4ade80; --ok-soft: #0f2a1d; --warn: #fbbf24; --warn-soft: #2b230e; --bad: #fb7185; --bad-soft: #321520;
  --radius: 12px; --radius-sm: 8px; --shell-gap: 8px; --mail-h: calc(100vh - var(--bar-h) - 24px);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--bg); font: var(--fs)/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: var(--s3); top: -60px; z-index: 50; padding: var(--s2) var(--s3); border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-ink); }
.skip:focus { top: var(--s3); }
.mono { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; letter-spacing: var(--title-track); line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }

/* buttons and fields */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--ctl); padding: 0 var(--s3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--raise); }
.btn.sm { min-height: var(--ctl-sm); padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: var(--ctl); padding: 0; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spread { display: flex; gap: var(--s3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.stack { display: grid; gap: var(--s3); }
.field { display: grid; gap: 4px; }
.field label, .field-legend { font-size: 12px; font-weight: 600; color: var(--muted); }
.input, .field input, .field select, .field textarea { width: 100%; min-height: 34px; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.field textarea { min-height: 200px; resize: vertical; line-height: 1.55; }
.hint { font-size: 12px; color: var(--faint); }
.inline-input { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.inline-input input { border: 0; background: transparent; min-height: 34px; padding: 6px 10px; flex: 1; min-width: 0; }
.inline-input span { display: flex; align-items: center; padding: 0 10px; color: var(--muted); border-left: 1px solid var(--line); font-size: 13px; }
.check { display: flex; gap: var(--s2); align-items: flex-start; font-size: 13px; }
.check input { width: 16px; height: 16px; margin-top: 2px; }
.notice { padding: var(--s2) var(--s3); border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel-2); font-size: 13px; }
.notice.ok { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: var(--ok-soft); }
.notice.warn { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: var(--warn-soft); }
.notice.bad { border-color: color-mix(in srgb, var(--bad) 45%, transparent); background: var(--bad-soft); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650; background: var(--raise); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }

/* auth */
.public { width: min(100% - 32px, 1080px); margin: auto; padding: var(--s5) 0 var(--s7); }
.brand { display: flex; gap: 9px; align-items: center; font-weight: 750; font-size: 15px; letter-spacing: var(--title-track); white-space: nowrap; }
.mark { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-size: 13px; }
.hero { display: grid; grid-template-columns: 1.1fr .85fr; gap: var(--s7); align-items: center; padding: 56px 0; }
.hero h1 { font-size: clamp(36px, 5.6vw, 60px); line-height: 1.04; letter-spacing: calc(var(--title-track) * 3); }
.hero .lede { margin-top: var(--s4); max-width: 520px; color: var(--muted); font-size: 16px; }
.facts { display: flex; flex-wrap: wrap; gap: var(--s5); margin-top: var(--s6); }
.fact { border-left: 2px solid var(--line); padding-left: var(--s3); font-size: 13px; color: var(--muted); }
.fact b { display: block; color: var(--text); }
.auth-card { padding: 6px; border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px); background: var(--panel); box-shadow: var(--shadow); }
.tabs { display: flex; gap: 4px; padding: 3px; border-radius: var(--radius); background: var(--panel-2); }
.tabs button { flex: 1; min-height: var(--ctl); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs button[aria-selected="true"] { background: var(--raise); color: var(--text); }
.auth-form { display: grid; gap: var(--s3); padding: var(--s5); }
.auth-form .btn { width: 100%; min-height: 38px; }

/* shell */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); gap: var(--shell-gap); padding: var(--shell-gap); min-height: 100vh; }
.rail { position: sticky; top: var(--shell-gap); height: calc(100vh - var(--shell-gap) * 2); display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3) var(--s2); border-right: 1px solid var(--line-soft); background: var(--rail); overflow-y: auto; }
.rail .brand { padding: 2px 6px 6px; }
.nav { display: grid; gap: 1px; }
.nav-title { margin: var(--s3) var(--s2) 2px; font-size: 11px; font-weight: 650; color: var(--faint); }
.nav a { display: flex; align-items: center; gap: 9px; min-height: var(--nav-h); padding: 0 var(--s2); border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; font-weight: 500; font-size: 13px; }
.nav a:hover { background: var(--raise); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav .ico { display: grid; place-items: center; flex: none; opacity: .85; }
.nav .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--raise); font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums; }
.account { margin-top: auto; display: grid; gap: var(--s2); padding: var(--s2) 4px 0; border-top: 1px solid var(--line-soft); }
.who { display: flex; gap: var(--s2); align-items: center; min-width: 0; }
.avatar { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--raise); font-weight: 700; font-size: 11.5px; }
.who div > b, .who div > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.bar { position: sticky; top: var(--shell-gap); z-index: 5; display: flex; align-items: center; gap: 10px; height: var(--bar-h); padding: 0 var(--s5); border-bottom: 1px solid var(--line-soft); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); }
.bar .menu { display: none; }
.crumb { font-weight: 650; font-size: 14px; }
.search { flex: 1; max-width: 460px; margin-left: auto; display: flex; align-items: center; gap: var(--s2); padding: 0 10px; min-height: var(--ctl); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); color: var(--faint); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--text); }
.search kbd { font: 11px var(--font); color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }
.toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.content { padding: var(--content-pad); max-width: 1320px; width: 100%; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s4); }
.view-head p { margin-top: 2px; color: var(--muted); max-width: 640px; font-size: 13px; }

/* cards and tables */
.grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid.wide { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.card { padding: var(--card-pad); border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel); min-width: 0; }
.card + .card { margin-top: var(--s3); }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
.metrics { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); margin-bottom: var(--s3); }
.metric { padding: var(--s3) 14px; border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel); }
.metric .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.metric b { display: block; margin: 2px 0 4px; font-size: 18px; letter-spacing: var(--title-track); }
.table-wrap { overflow-x: auto; margin: 0 calc(var(--card-pad) * -1); padding: 0 var(--card-pad); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11.5px; font-weight: 650; color: var(--faint); padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.steps { display: grid; gap: 6px; counter-reset: step; }
.step { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 10px; border-radius: var(--radius-sm); background: var(--panel-2); }
.step::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--raise); font-weight: 700; font-size: 12px; }
.step.done::before { content: "✓"; background: var(--ok-soft); color: var(--ok); }
.step p { color: var(--muted); font-size: 13px; margin-top: 1px; }
.empty { padding: var(--s5) var(--s4); text-align: center; color: var(--muted); }
.list { display: grid; gap: 6px; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: var(--panel-2); flex-wrap: wrap; }
.copy-value { display: flex; gap: 6px; align-items: flex-start; }
.copy-value code { flex: 1; min-width: 0; padding: 4px 6px; border-radius: var(--radius-sm); background: var(--bg); font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.dns-host { min-width: 240px; }
.btn.primary .count { background: rgb(255 255 255 / 28%); color: inherit; }
pre.raw { margin: 0; padding: var(--s3); border-radius: var(--radius-sm); background: var(--bg); font: 12px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow: auto; }
.expert-only { display: none; }
body.expert .expert-only { display: revert; }

/* settings: theme picker */
.theme-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); margin-top: 6px; }
.theme-card { position: relative; display: grid; gap: var(--s2); align-content: start; padding: var(--s2); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); cursor: pointer; }
.theme-card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.theme-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.theme-card:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.theme-card input { position: absolute; opacity: 0; pointer-events: none; }
.theme-card > span:last-child { display: grid; gap: 2px; padding: 0 2px 2px; }
.theme-card b { font-size: 13px; }
.theme-card:has(input:checked) > span:last-child > b::after { content: " · current"; color: var(--accent); font-weight: 600; }
.tp { display: grid; grid-template-columns: var(--p-cols, 24% 34% 1fr); gap: var(--p-gap, 0); padding: var(--p-gap, 0); height: 84px; border: 1px solid var(--line-soft); border-radius: calc(var(--radius) - 3px); background: var(--p-bg); overflow: hidden; font-family: var(--p-font, inherit); }
.tp i { display: grid; align-content: start; gap: 5px; padding: 8px 6px; background: var(--p-panel); border-radius: var(--p-r, 0); }
.tp .tp-side { background: var(--p-side); border-right: 1px solid var(--p-line); }
.tp .tp-list { border-right: 1px solid var(--p-line); }
.tp b { display: block; height: 5px; border-radius: var(--p-r, 3px); background: var(--p-line); }
.tp b.a { background: var(--p-acc); }
.tp b.w { width: 60%; }
.tp[data-preview="adaptive"] { --p-bg: #ffffff; --p-side: #f2f2f4; --p-panel: #ffffff; --p-line: #dcdce1; --p-acc: #2f6fdb; }
.tp[data-preview="graphite"] { --p-bg: #09090b; --p-side: #0c0c0e; --p-panel: #0f0f12; --p-line: #2c2c34; --p-acc: #8b7cf6; }
.tp[data-preview="rail"] { --p-bg: #0b1220; --p-side: #080e1a; --p-panel: #0e1627; --p-line: #24344f; --p-acc: #38bdf8; --p-cols: 10% 34% 1fr; }
.tp[data-preview="rail"] .tp-side { padding: 8px 3px; }
.tp[data-preview="terminal"] { --p-bg: #0a0d0a; --p-side: #070907; --p-panel: #0c100c; --p-line: #233223; --p-acc: #7ee787; --p-r: 0; }
.tp[data-preview="panels"] { --p-bg: #050607; --p-side: #0e1115; --p-panel: #0e1115; --p-line: #242a33; --p-acc: #2dd4bf; --p-gap: 3px; --p-r: 4px; }
.tp[data-preview="panels"] i { border: 0; }
.seg { display: inline-flex; gap: 2px; padding: 2px; margin-top: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel-2); }
.seg label { position: relative; display: flex; align-items: center; min-height: var(--ctl-sm); padding: 0 var(--s3); border-radius: calc(var(--radius-sm) - 1px); font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg label:has(input:checked) { background: var(--raise); color: var(--text); }
.seg label:has(input:focus-visible) { outline: 2px solid var(--focus); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }

/* webmail */
.mail { display: grid; grid-template-columns: var(--folders-w) minmax(260px, var(--list-w)) minmax(0, 1fr); height: var(--mail-h); }
.mail-content { padding: 0; max-width: none; }
.folders { display: flex; flex-direction: column; gap: 6px; padding: var(--s3) var(--s2); border-right: 1px solid var(--line-soft); overflow-y: auto; }
.folders select { min-height: 32px; }
.folders > .small { padding: 0 var(--s2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: var(--nav-h); padding: 0 var(--s2); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-weight: 500; font-size: 13px; text-align: left; }
.folder:hover { background: var(--raise); color: var(--text); }
.folder[aria-current="true"] { background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.messages { display: flex; flex-direction: column; border-right: 1px solid var(--line-soft); min-width: 0; min-height: 0; }
.messages-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s2) 0 14px; border-bottom: 1px solid var(--line-soft); }
.messages-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-list { flex: 1; overflow-y: auto; }
.msg { display: grid; gap: 1px; width: 100%; padding: var(--s2) 14px; border: 0; border-bottom: 1px solid var(--line-soft); background: transparent; color: var(--text); text-align: left; }
.msg:hover { background: var(--panel-2); }
.msg[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.msg-av { display: none; }
.msg .top { display: flex; justify-content: space-between; gap: var(--s2); font-size: 13px; }
.msg .from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .date { flex: none; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.msg .subject { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .preview { font-size: 12.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.unread .from, .msg.unread .subject { font-weight: 700; color: var(--text); }
.msg.unread .from::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--accent); vertical-align: 2px; }
.pager { display: flex; justify-content: space-between; align-items: center; min-height: 38px; padding: 0 var(--s2) 0 14px; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--muted); }
.reader { min-width: 0; overflow-y: auto; display: flex; flex-direction: column; }
.reader-head { padding: var(--s3) var(--s5) 14px; border-bottom: 1px solid var(--line-soft); display: grid; gap: 10px; }
.reader-head h2 { font-size: 19px; overflow-wrap: anywhere; }
.reader-meta { display: grid; gap: 1px; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.reader-body { padding: var(--s4) var(--s5); flex: 1; }
.reader-body pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.6 var(--font); }
.reader-body iframe { width: 100%; min-height: 60vh; border: 1px solid var(--line-soft); border-radius: var(--radius-sm); background: #fff; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 var(--s5) var(--s4); }
.back { display: none; }

/* dialogs */
dialog { width: min(100% - 24px, 600px); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line); border-radius: calc(var(--radius) + 4px); background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
dialog.wide { width: min(100% - 24px, 800px); }
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 10px var(--s2) 10px var(--s4); border-bottom: 1px solid var(--line-soft); }
.dialog-body { display: grid; gap: var(--s3); padding: var(--s4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: 10px var(--s4); border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.qr { display: grid; place-items: center; padding: var(--s3); border-radius: var(--radius-sm); background: #fff; width: 220px; }
.qr svg { width: 196px; height: 196px; }
.secret-reveal { padding: var(--s3); border-radius: var(--radius-sm); background: var(--bg); font: 600 17px/1.4 var(--mono); letter-spacing: .04em; text-align: center; overflow-wrap: anywhere; user-select: all; }
.toast { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 60; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); font-size: 13px; }
.toast.bad { border-color: var(--bad); }

/* ---------- theme layouts ---------- */

/* Graphite and Terminal: one-line message rows when the list is wide enough. */
@media (min-width: 821px) {
  :root:is([data-theme="graphite"], [data-theme="terminal"]) .msg { grid-template-columns: minmax(0, 150px) minmax(0, max-content) minmax(0, 1fr) auto; align-items: center; column-gap: 10px; min-height: 34px; padding: 0 14px; }
  :root:is([data-theme="graphite"], [data-theme="terminal"]) .msg .top { display: contents; }
  :root:is([data-theme="graphite"], [data-theme="terminal"]) .msg .from { order: 1; }
  :root:is([data-theme="graphite"], [data-theme="terminal"]) .msg .subject { order: 2; }
  :root:is([data-theme="graphite"], [data-theme="terminal"]) .msg .preview { order: 3; }
  :root:is([data-theme="graphite"], [data-theme="terminal"]) .msg .preview::before { content: "— "; }
  :root:is([data-theme="graphite"], [data-theme="terminal"]) .msg .date { order: 4; }
}
[data-theme="graphite"] .nav a[aria-current="page"], [data-theme="graphite"] .folder[aria-current="true"] { background: var(--raise); box-shadow: none; }
[data-theme="graphite"] .nav a[aria-current="page"] .ico { color: var(--accent); opacity: 1; }
[data-theme="graphite"] .card, [data-theme="graphite"] .metric { border-color: var(--line); }

/* Terminal: prompt-style markers instead of soft highlights. */
[data-theme="terminal"] .nav-title::before { content: "// "; }
[data-theme="terminal"] .nav a[aria-current="page"], [data-theme="terminal"] .folder[aria-current="true"] { background: var(--accent-soft); box-shadow: none; color: var(--accent); }
[data-theme="terminal"] .nav a[aria-current="page"] .label::before, [data-theme="terminal"] .folder[aria-current="true"] > span:first-child::before { content: "> "; }
[data-theme="terminal"] .view-head h1::before { content: "$ "; color: var(--accent); }
[data-theme="terminal"] .mark, [data-theme="terminal"] .avatar { border-radius: var(--radius-sm); }
[data-theme="terminal"] .pill, [data-theme="terminal"] .count { border-radius: var(--radius-sm); }
[data-theme="terminal"] .pill::before { border-radius: 0; }
[data-theme="terminal"] .msg.unread .from::before { content: "*"; width: auto; height: auto; margin-right: 4px; border-radius: 0; background: none; color: var(--accent); vertical-align: 0; }
[data-theme="terminal"] .btn.primary { text-transform: lowercase; }
[data-theme="terminal"] .card, [data-theme="terminal"] .metric, [data-theme="terminal"] .list-item { border-color: var(--line); }

/* Icon rail: sidebar collapses to icons on desktop; the mobile drawer keeps labels. */
@media (min-width: 821px) {
  [data-theme="rail"] .rail { align-items: center; padding: 10px 6px; }
  [data-theme="rail"] .rail .brand { padding: 0 0 6px; }
  [data-theme="rail"] :is(.brand-name, .nav .label, .account .label, .who > div) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  [data-theme="rail"] .nav { justify-items: center; gap: 2px; width: 100%; }
  [data-theme="rail"] .nav-title { width: 24px; height: 1px; margin: 8px auto; overflow: hidden; font-size: 0; background: var(--line); }
  [data-theme="rail"] .nav-title:first-child { display: none; }
  [data-theme="rail"] .nav a { position: relative; width: 40px; min-height: 40px; padding: 0; justify-content: center; }
  [data-theme="rail"] .nav a .ico svg { width: 19px; height: 19px; }
  [data-theme="rail"] .nav a[aria-current="page"] { box-shadow: none; color: var(--accent); }
  [data-theme="rail"] .nav a[aria-current="page"] .ico { opacity: 1; }
  [data-theme="rail"] .nav .count { position: absolute; top: 3px; right: 1px; min-width: 16px; padding: 0 4px; line-height: 16px; font-size: 10px; background: var(--accent); color: var(--accent-ink); }
  [data-theme="rail"] .account { justify-items: center; padding: var(--s2) 0 0; }
  [data-theme="rail"] .account .row { flex-direction: column; }
  [data-theme="rail"] .account .btn { width: 36px; padding: 0; }
}
[data-theme="rail"] .bar { background: var(--bg); backdrop-filter: none; }

/* Floating panels: every region is its own rounded panel separated by gaps. */
[data-theme="panels"] .rail { border: 1px solid var(--line-soft); border-radius: var(--radius); }
[data-theme="panels"] .bar { border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel); backdrop-filter: none; }
[data-theme="panels"] .content { padding: var(--s4) 2px; }
[data-theme="panels"] .mail-content { padding: var(--shell-gap) 0 0; }
[data-theme="panels"] .mail { gap: var(--shell-gap); }
[data-theme="panels"] :is(.folders, .messages, .reader) { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); }
[data-theme="panels"] .messages { overflow: hidden; }
[data-theme="panels"] .message-list { padding: 4px 0; }
[data-theme="panels"] .msg { grid-template-columns: 30px minmax(0, 1fr); column-gap: 10px; width: calc(100% - 12px); margin: 0 6px 2px; border-bottom: 0; border-radius: var(--radius-sm); }
[data-theme="panels"] .msg-av { display: grid; place-items: center; grid-row: 1 / span 3; width: 30px; height: 30px; margin-top: 2px; border-radius: 50%; background: var(--raise); color: var(--muted); font-size: 11px; font-weight: 700; }
[data-theme="panels"] .msg.unread .msg-av { background: var(--accent-soft); color: var(--accent); }
[data-theme="panels"] .msg[aria-current="true"] { box-shadow: none; }
[data-theme="panels"] :is(.nav a, .folder)[aria-current] { box-shadow: none; }
[data-theme="panels"] .card { border-color: var(--line-soft); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid.wide { grid-template-columns: 1fr; }
  .mail { grid-template-columns: var(--folders-w) minmax(0, 1fr); }
  .mail .reader { display: none; }
  .mail.reading .messages { display: none; }
  .mail.reading .reader { display: flex; }
  .back { display: inline-flex; }
}
@media (max-width: 820px) {
  :root, :root[data-theme] { --shell-gap: 0px; --content-pad: 14px; }
  .hero { grid-template-columns: 1fr; padding: var(--s6) 0; gap: var(--s6); }
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(84vw, 280px); height: 100vh; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.nav-open .rail { transform: none; }
  .bar { height: auto; padding: var(--s2) var(--s3); flex-wrap: wrap; }
  .bar .menu { display: inline-flex; }
  .bar .search { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  .bar .toggle { margin-left: auto; }
  .search kbd { display: none; }
  .mail { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 90px); gap: 0; }
  .folders { flex-direction: row; align-items: center; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line-soft); padding: var(--s2) var(--s3); }
  .folders .stack { display: flex; }
  .folders .folder { width: auto; flex: none; }
  .folders .folder-tools, .folders select, .folders > .small { flex: none; }
  .messages { border-right: 0; }
  [data-theme="panels"] :is(.rail, .bar, .folders, .messages, .reader) { border-radius: 0; border-width: 0 0 1px; }
  [data-theme="panels"] .rail { border-width: 0 1px 0 0; }
  .step { grid-template-columns: 26px minmax(0, 1fr); }
  .step > :last-child { grid-column: 2; justify-self: start; }
}
@media (pointer: coarse) {
  .btn, .nav a, .folder, .tabs button, .seg label { min-height: 44px; }
  .btn.sm { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .pill::before, .msg.unread .from::before { forced-color-adjust: none; }
  .nav a[aria-current="page"], .folder[aria-current="true"], .msg[aria-current="true"], .theme-card:has(input:checked) { outline: 2px solid CanvasText; }
}
