/* MyMail Everywhere design system. Direction: DESIGN.md (instrument panel). */

/* ---------- Tokens ---------- */
:root {
    color-scheme: dark;
    --base: #121416;
    --panel: #1a1d20;
    --panel-2: #202428;
    --raised: #24282d;
    --hair: #2a2f34;
    --hair-strong: #3a4046;
    --text: #e6e4df;
    --text-2: #c5c3be;
    --muted: #9ba1a6;
    --signal: #f2a33a;
    --signal-ink: #1a1206;
    --signal-soft: rgba(242, 163, 58, 0.12);
    --signal-line: #f2a33a;
    --ok: #5fb57a;
    --warn: #f2a33a;
    --fault: #e5604e;
    --fault-soft: rgba(229, 96, 78, 0.12);
    --ok-soft: rgba(95, 181, 122, 0.12);
    --selection: rgba(242, 163, 58, 0.10);
    --hover: rgba(255, 255, 255, 0.035);
    --focus: #f2a33a;
    --shadow-float: 0 12px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--hair-strong);
    --reader-bg: #f7f6f2;

    --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

    --r-1: 3px;
    --r-2: 6px;
    --rail-w: 60px;
    --status-h: 26px;
    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;
    --fast: 120ms;
}

:root[data-theme="light"] {
    color-scheme: light;
    --base: #f3f2ee;
    --panel: #fbfaf7;
    --panel-2: #f6f5f1;
    --raised: #ffffff;
    --hair: #d9d6ce;
    --hair-strong: #c4c0b6;
    --text: #1c1c1a;
    --text-2: #34332f;
    --muted: #5e5c57;
    --signal: #9a5b00;
    --signal-ink: #ffffff;
    --signal-soft: rgba(154, 91, 0, 0.09);
    --signal-line: #c27406;
    --ok: #2f7d47;
    --warn: #9a5b00;
    --fault: #b33a2a;
    --fault-soft: rgba(179, 58, 42, 0.08);
    --ok-soft: rgba(47, 125, 71, 0.08);
    --selection: rgba(194, 116, 6, 0.08);
    --hover: rgba(0, 0, 0, 0.035);
    --focus: #9a5b00;
    --shadow-float: 0 12px 32px rgba(40, 35, 25, 0.16), 0 0 0 1px var(--hair-strong);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        color-scheme: light;
        --base: #f3f2ee;
        --panel: #fbfaf7;
        --panel-2: #f6f5f1;
        --raised: #ffffff;
        --hair: #d9d6ce;
        --hair-strong: #c4c0b6;
        --text: #1c1c1a;
        --text-2: #34332f;
        --muted: #5e5c57;
        --signal: #9a5b00;
        --signal-ink: #ffffff;
        --signal-soft: rgba(154, 91, 0, 0.09);
        --signal-line: #c27406;
        --ok: #2f7d47;
        --warn: #9a5b00;
        --fault: #b33a2a;
        --fault-soft: rgba(179, 58, 42, 0.08);
        --ok-soft: rgba(47, 125, 71, 0.08);
        --selection: rgba(194, 116, 6, 0.08);
        --hover: rgba(0, 0, 0, 0.035);
        --focus: #9a5b00;
        --shadow-float: 0 12px 32px rgba(40, 35, 25, 0.16), 0 0 0 1px var(--hair-strong);
    }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--base);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; }

a { color: var(--signal); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.005em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

p { margin: 0 0 var(--s-3); }

::selection { background: var(--signal); color: var(--signal-ink); }

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

button, input, select, textarea { font: inherit; color: inherit; }

.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s-2); }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.stack { display: flex; flex-direction: column; gap: var(--s-3); }
.stack-tight { display: flex; flex-direction: column; gap: var(--s-1); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.hide { display: none !important; }
.fault-text { color: var(--fault); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }

/* ---------- Motion (DESIGN.md: 120ms colour changes, panels slide in when the user opens them) ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-right { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: none; } }
@keyframes slide-left { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

.msg, .nav-item, .list-row, .doc-row, .queue-row, .palette-item, .menu button, .menu a,
.tabs button, .tabs a, .segmented button, .rail a, .rail button, .attach, .meter-tile, .files-table tbody tr {
    transition: background-color var(--fast), color var(--fast), border-color var(--fast);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Scroll panes stop at their own edge instead of dragging the page, and keep their gutter so rows never jump. */
.page, .list-scroll, .reader-scroll, .mail-nav, .docs-list, .doc-preview, .doc-source, .doc-aside, .tools-body, .tools-nav,
.settings-body, .menu, .palette-list, .dialog-body, .preview-body, .rich-editor, .backstage-main {
    overscroll-behavior: contain;
}
.list-scroll, .reader-scroll, .docs-list { scrollbar-gutter: stable; }

/* Shown by App.razor until the circuit connects and the first screen renders. */
#boot { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; }
body:has(.shell, .auth-wrap) #boot { display: none; }

/* ---------- Icon ---------- */
.ico {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.4;
    stroke-linecap: square;
    stroke-linejoin: miter;
    vertical-align: -3px;
}
.ico.lg { width: 20px; height: 20px; }
.ico.fill { fill: currentColor; stroke: none; }

/* ---------- Shell ---------- */
.shell {
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) var(--status-h);
    height: 100dvh;
}

.rail {
    grid-row: 1 / 2;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    background: var(--panel);
    border-right: 1px solid var(--hair);
    padding: var(--s-2) 0;
    gap: 2px;
    z-index: 20;
}

.rail-mark {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--signal);
    text-align: center;
    padding: var(--s-1) 0 var(--s-3);
    border-bottom: 1px solid var(--hair);
    margin-bottom: var(--s-2);
    letter-spacing: 0.04em;
}

.rail a, .rail button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 0 6px;
    color: var(--muted);
    background: none;
    border: 0;
    font-size: 10.5px;
    cursor: pointer;
    text-decoration: none;
    transition: color var(--fast);
}

.rail a:hover, .rail button:hover { color: var(--text); text-decoration: none; }
.rail a.active { color: var(--text); }
.rail a.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 2px;
    background: var(--signal-line);
}

.rail .rail-count {
    position: absolute;
    top: 3px;
    right: 9px;
    font-family: var(--font-mono);
    font-size: 9.5px;
    color: var(--signal);
}

.rail-spacer { flex: 1; }

.main {
    grid-row: 1 / 2;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.page {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

.page-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: var(--s-5) var(--s-5) var(--s-7);
}

.page-head {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    margin-bottom: var(--s-4);
    flex-wrap: wrap;
}

.page-head h1 { margin-right: auto; }

.statusbar {
    grid-column: 1 / 3;
    display: flex;
    align-items: center;
    gap: var(--s-4);
    padding: 0 var(--s-3);
    background: var(--panel);
    border-top: 1px solid var(--hair);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
}

.statusbar .status-item { display: inline-flex; align-items: center; gap: 6px; }
.statusbar button { background: none; border: 0; color: inherit; cursor: pointer; padding: 0; font: inherit; }
.statusbar button:hover { color: var(--text); }

.lamp {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    display: inline-block;
}
.lamp.ok { background: var(--ok); }
.lamp.busy { background: var(--signal); }
.lamp.fault { background: var(--fault); }

/* ---------- Panels & readouts ---------- */
.panel {
    background: var(--panel);
    border: 1px solid var(--hair);
    border-radius: var(--r-2);
}

.panel-head {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--hair);
    min-height: 38px;
}

.panel-body { padding: var(--s-3); }

.label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.readout {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    border: 1px solid var(--hair);
    border-radius: var(--r-1);
    padding: 1px 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
}

.readout b { color: var(--text); font-weight: 500; font-variant-numeric: tabular-nums; }
.readout.hot b { color: var(--signal); }

.meter {
    height: 4px;
    background: var(--hair);
    border-radius: 2px;
    overflow: hidden;
}
.meter > span { display: block; height: 100%; background: var(--signal); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-1);
    background: var(--panel-2);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background var(--fast), border-color var(--fast), color var(--fast);
}

.btn:hover { background: var(--raised); border-color: var(--muted); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
    background: var(--signal);
    border-color: var(--signal);
    color: var(--signal-ink);
}
.btn-primary:hover { background: var(--signal); border-color: var(--text); filter: brightness(1.06); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--hover); border-color: var(--hair); }

.btn-danger { color: var(--fault); }
.btn-danger:hover { border-color: var(--fault); background: var(--fault-soft); }

.btn-icon {
    width: 32px;
    padding: 0;
}

.btn-sm { min-height: 26px; padding: 0 8px; font-size: 12px; }
.btn-sm.btn-icon { width: 26px; padding: 0; }

.btn.on { color: var(--signal); border-color: var(--signal); background: var(--signal-soft); }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-1) 0 0 var(--r-1); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-1) var(--r-1) 0; }

.linklike {
    background: none;
    border: 0;
    padding: 0;
    color: var(--signal);
    cursor: pointer;
    font: inherit;
}
.linklike:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .field-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--fault); }

.input, .select, .textarea {
    width: 100%;
    min-height: 34px;
    padding: 6px 10px;
    background: var(--base);
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-1);
    color: var(--text);
    transition: border-color var(--fast);
}

.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--signal); outline: none; box-shadow: 0 0 0 1px var(--signal); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 0.85; }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.textarea.mono, .input.mono { font-size: 12.5px; }
.select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input-sm { min-height: 28px; padding: 3px 8px; font-size: 13px; }
.select.input-sm { padding-right: 26px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--s-3) var(--s-4);
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
}
.check input { width: 16px; height: 16px; accent-color: var(--signal); margin: 0; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 30px; height: 16px; border-radius: 8px; background: var(--hair-strong); position: relative; transition: background var(--fast); flex: 0 0 auto; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text); transition: transform var(--fast); }
.switch input:checked + .track { background: var(--signal); }
.switch input:checked + .track::after { transform: translateX(14px); background: var(--signal-ink); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}
.search-box .ico { position: absolute; left: 10px; color: var(--muted); pointer-events: none; }
.search-box .input { padding-left: 32px; }

/* ---------- Tabs / segmented ---------- */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--hair);
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs button, .tabs a {
    position: relative;
    background: none;
    border: 0;
    padding: 9px 12px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}

.tabs button:hover, .tabs a:hover { color: var(--text); text-decoration: none; }
.tabs .active { color: var(--text); }
.tabs .active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--signal-line); }

.segmented {
    display: inline-flex;
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-1);
    overflow: hidden;
}
.segmented button {
    background: transparent;
    border: 0;
    border-left: 1px solid var(--hair-strong);
    padding: 3px 10px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    gap: 6px;
    align-items: center;
    min-height: 28px;
}
.segmented button:first-child { border-left: 0; }
.segmented button:hover { color: var(--text); background: var(--hover); }
.segmented button.active { color: var(--text); background: var(--signal-soft); box-shadow: inset 0 -2px 0 var(--signal-line); }

/* ---------- Badges / chips ---------- */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
    min-height: 18px;
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-1);
    font-size: 11px;
    color: var(--text-2);
    white-space: nowrap;
    background: transparent;
}
.tag.ok { color: var(--ok); border-color: currentColor; }
.tag.fault { color: var(--fault); border-color: currentColor; }
.tag.warn { color: var(--warn); border-color: currentColor; }
button.tag { cursor: pointer; }
button.tag:hover { border-color: var(--muted); }

.kbd {
    display: inline-block;
    min-width: 18px;
    padding: 0 4px;
    border: 1px solid var(--hair-strong);
    border-bottom-width: 2px;
    border-radius: var(--r-1);
    font-family: var(--font-mono);
    font-size: 10.5px;
    line-height: 16px;
    text-align: center;
    color: var(--text-2);
}

.avatar {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: var(--r-1);
    border: 1px solid var(--hair-strong);
    display: grid;
    place-items: center;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-2);
    background: var(--panel-2);
}
.avatar.lg { width: 38px; height: 38px; flex-basis: 38px; font-size: 13px; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }

.list-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: 9px var(--s-3);
    border-bottom: 1px solid var(--hair);
    cursor: pointer;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    background: transparent;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    text-align: left;
    width: 100%;
}

.list-row:hover { background: var(--hover); text-decoration: none; }
.list-row.selected { background: var(--selection); }
.list-row.selected::before, .signal-marked::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--signal-line);
}

/* ---------- Empty / loading / error ---------- */
.state {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-2);
    padding: var(--s-6) var(--s-5);
    color: var(--muted);
    max-width: 460px;
}
.state.center { align-items: center; text-align: center; margin: 0 auto; }
.state h3 { color: var(--text); }
.state .ico { width: 22px; height: 22px; color: var(--muted); }
.state.error h3 { color: var(--fault); }

.loading-bar {
    height: 2px;
    width: 100%;
    background: var(--hair);
    overflow: hidden;
    position: relative;
}
.loading-bar::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 30%;
    background: var(--signal);
    animation: scan 1.1s linear infinite;
}
@keyframes scan { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

.loading-inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.loading-inline::before {
    content: "";
    width: 12px;
    height: 12px;
    border: 1.5px solid var(--hair-strong);
    border-top-color: var(--signal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Floating layers ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 9, 10, 0.55);
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 10vh var(--s-4) var(--s-4);
    animation: fade var(--fast) ease-out;
}

:root[data-theme="light"] .overlay { background: rgba(40, 36, 28, 0.25); }

.dialog {
    width: min(560px, 100%);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-float);
    overflow: hidden;
    animation: rise 160ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.dialog.wide { width: min(880px, 100%); }
.dialog-head { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--hair); }
.dialog-head h2 { margin-right: auto; }
.dialog-body { padding: var(--s-4); overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-top: 1px solid var(--hair); }

.menu {
    position: absolute;
    z-index: 60;
    min-width: 200px;
    max-height: 360px;
    overflow: auto;
    background: var(--panel);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-float);
    padding: 4px;
    animation: drop 100ms ease-out;
}
.menu button, .menu a {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    background: none;
    color: var(--text);
    text-align: left;
    border-radius: var(--r-1);
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
}
.menu button:hover, .menu a:hover, .menu .active { background: var(--hover); text-decoration: none; }
.menu hr { border: 0; border-top: 1px solid var(--hair); margin: 4px 0; }
.menu .menu-label { padding: 6px 10px 2px; }
.menu-anchor { position: relative; display: inline-flex; }

.toasts {
    position: fixed;
    bottom: calc(var(--status-h) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    width: min(520px, calc(100vw - 24px));
}
.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    background: var(--raised);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-float);
    font-size: 13px;
    animation: rise 160ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.toast.fault { box-shadow: 0 12px 32px rgba(0,0,0,.4), 0 0 0 1px var(--fault); }
.toast .grow { color: var(--text); }

/* ---------- Command palette ---------- */
.palette {
    width: min(640px, 100%);
    background: var(--panel);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-float);
    overflow: hidden;
    animation: rise 160ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.palette-input {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--hair);
    background: transparent;
    padding: 14px 16px;
    font-size: 15px;
    color: var(--text);
}
.palette-input:focus { outline: none; }
.palette-list { max-height: 50vh; overflow: auto; padding: 4px; }
.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: 0;
    color: var(--text);
    border-radius: var(--r-1);
    cursor: pointer;
    text-align: left;
    position: relative;
}
.palette-item:hover { background: var(--hover); }
.palette-item.active { background: var(--selection); }
.palette-item.active::before { content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 2px; background: var(--signal-line); }
.palette-group { padding: 8px 12px 4px; }

/* ---------- Mail ---------- */
.mail {
    display: grid;
    grid-template-columns: var(--mail-nav-w, 236px) 0 var(--mail-list-w, 380px) 0 minmax(0, 1fr);
    height: 100%;
    min-height: 0;
}

.mail-nav {
    background: var(--panel);
    border-right: 1px solid var(--hair);
    overflow: auto;
    padding: var(--s-2) 0 var(--s-5);
    min-height: 0;
}

.mail-nav .compose-btn { margin: var(--s-1) var(--s-3) var(--s-3); width: calc(100% - 24px); }

.nav-group { padding: var(--s-2) 0; }
.nav-group + .nav-group { border-top: 1px solid var(--hair); }
.nav-group-title { display: flex; align-items: center; gap: 6px; padding: 4px var(--s-3) 4px; }
.nav-group-title .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 5px var(--s-3);
    color: var(--text-2);
    font-size: 13px;
    text-decoration: none;
    background: none;
    border: 0;
    cursor: pointer;
    text-align: left;
}
.nav-item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-item.active { color: var(--text); background: var(--selection); }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 2px; bottom: 2px; width: 2px; background: var(--signal-line); }
.nav-item .count { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-item .count.hot { color: var(--signal); }
.nav-item .ico { color: var(--muted); }
.nav-item.active .ico { color: var(--text); }

.mail-list {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--hair);
    min-height: 0;
    min-width: 0;
    background: var(--base);
}

.list-toolbar {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--hair);
    min-height: 46px;
    flex-wrap: wrap;
}
.list-toolbar h2 { font-size: 14px; margin-right: auto; }

.list-scroll { flex: 1 1 auto; overflow: auto; min-height: 0; }

.msg {
    position: relative;
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) auto;
    column-gap: 8px;
    row-gap: 1px;
    padding: 9px var(--s-3) 10px 8px;
    border-bottom: 1px solid var(--hair);
    cursor: pointer;
    background: transparent;
    width: 100%;
    text-align: left;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    color: inherit;
}
.msg:hover { background: var(--hover); }
.msg { user-select: none; }
.msg.selected { background: var(--selection); }
.msg.selected::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--signal-line); }
.msg.checked { background: var(--signal-soft); }
.msg .pick { grid-column: 1; grid-row: 1 / span 3; display: flex; justify-content: center; padding-top: 2px; }
.msg .pick input { width: 15px; height: 15px; margin: 0; accent-color: var(--signal); cursor: pointer; }
.msg .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 6px; vertical-align: 2px; }
.msg:not(.unread) .dot { display: none; }
.msg.unread .dot { background: var(--signal); }
.msg .from { grid-column: 2; font-size: 13px; color: var(--text-2); }
.msg.unread .from { color: var(--text); font-weight: 600; }
.msg .when { grid-column: 3; font-family: var(--font-mono); font-size: 11px; color: var(--muted); text-align: right; }
.msg .subject { grid-column: 2 / 4; font-size: 13px; color: var(--text-2); }
.msg.unread .subject { color: var(--text); }
.msg .preview { grid-column: 2 / 4; font-size: 12.5px; color: var(--muted); }
.msg .meta { grid-column: 2 / 4; display: flex; gap: 6px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.msg .thread-count { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-left: 4px; }
.msg .flags { display: inline-flex; gap: 4px; color: var(--muted); margin-left: 6px; vertical-align: -2px; }
.msg .flags .starred { color: var(--signal); }

.reader {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--base);
}

.reader-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--hair);
    min-height: 46px;
    flex-wrap: wrap;
}
.reader-toolbar .sep { width: 1px; height: 18px; background: var(--hair); margin: 0 4px; }

.reader-scroll { flex: 1 1 auto; overflow: auto; min-height: 0; padding: var(--s-4) var(--s-5) var(--s-7); }

.thread-subject { font-size: 19px; font-weight: 600; margin: 0 0 var(--s-2); line-height: 1.3; overflow-wrap: anywhere; }

.letter {
    border: 1px solid var(--hair);
    border-radius: var(--r-2);
    background: var(--panel);
    margin-bottom: var(--s-3);
    overflow: hidden;
}
.letter.collapsed { cursor: pointer; }
.letter.collapsed:hover { border-color: var(--hair-strong); }
.letter-head { display: flex; gap: var(--s-3); padding: var(--s-3); align-items: flex-start; }
.letter-head .who { min-width: 0; flex: 1; }
.letter-head .who .name { font-weight: 600; }
.letter-head .who .addr { color: var(--muted); font-size: 12px; }
.letter-head .when { font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.letter-body { padding: 0 var(--s-3) var(--s-3); }
.letter-notice {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    flex-wrap: wrap;
    padding: 6px var(--s-3);
    margin: 0 var(--s-3) var(--s-3);
    border: 1px solid var(--hair);
    border-radius: var(--r-1);
    font-size: 12px;
    color: var(--muted);
}

.mail-frame {
    width: 100%;
    border: 0;
    display: block;
    background: var(--reader-bg);
    border-radius: var(--r-1);
    min-height: 60px;
}

.plain-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 14px;
    line-height: 1.55;
    margin: 0;
    font-family: var(--font-ui);
}

.attach-strip { display: flex; flex-wrap: wrap; gap: var(--s-2); padding: 0 var(--s-3) var(--s-3); }
.attach {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 280px;
    padding: 6px 10px;
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-1);
    background: var(--panel-2);
    color: var(--text);
    font-size: 12.5px;
    cursor: pointer;
    text-decoration: none;
}
.attach:hover { border-color: var(--muted); text-decoration: none; }
.attach .size { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

.quick-reply {
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-2);
    background: var(--panel);
    display: flex;
    gap: var(--s-2);
    padding: var(--s-2);
    align-items: center;
    flex-wrap: wrap;
}

.invite-card {
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-2);
    padding: var(--s-3);
    margin: 0 var(--s-3) var(--s-3);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px var(--s-3);
    font-size: 13px;
}
.invite-card .label { align-self: center; }

.ai-output {
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-2);
    background: var(--panel);
    margin-bottom: var(--s-3);
}
.ai-output .panel-head { gap: var(--s-2); }
.ai-output .ai-text { padding: var(--s-3) var(--s-4); }
.ai-output .ai-text :first-child { margin-top: 0; }

/* ---------- Compose ---------- */
.compose {
    position: fixed;
    right: var(--s-4);
    bottom: calc(var(--status-h) + var(--s-3));
    /* --compose-w and --compose-h come from dragging the top or left edge (js/splitters.js). */
    width: min(var(--compose-w, 720px), calc(100vw - var(--rail-w) - 32px));
    height: min(var(--compose-h, 680px), calc(100dvh - var(--status-h) - 40px));
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-radius: var(--r-2);
    box-shadow: var(--shadow-float);
    z-index: 90;
    overflow: hidden;
    animation: rise 180ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.compose.minimized { height: auto; width: 320px; }
.compose.maximized { left: calc(var(--rail-w) + 16px); width: auto; top: 16px; height: auto; }
.compose-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--hair); cursor: default; }
.compose-head h2 { font-size: 13px; font-weight: 600; margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-fields { border-bottom: 1px solid var(--hair); }
.compose-line { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--hair); min-height: 38px; }
.compose-line:last-child { border-bottom: 0; }
.compose-line > label { width: 52px; font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.compose-line input, .compose-line select { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 0; color: var(--text); }
.compose-line input:focus, .compose-line select:focus { outline: none; }
.compose-line:focus-within { box-shadow: inset 2px 0 0 var(--signal-line); }
.compose-foot { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--hair); flex-wrap: wrap; }
.compose-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--hair); }

.recipients { position: relative; flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 5px 0; }
.recipients input { flex: 1 1 140px; min-width: 120px; }
.recipient-chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 4px 1px 7px; border: 1px solid var(--hair-strong); border-radius: var(--r-1); font-size: 12.5px; max-width: 100%; }
.recipient-chip.invalid { border-color: var(--fault); color: var(--fault); }
.recipient-chip button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; display: inline-flex; }
.recipient-chip button:hover { color: var(--text); }
.suggest { position: absolute; top: 100%; left: 0; z-index: 70; }

.editor-toolbar { display: flex; gap: 2px; padding: 4px 8px; border-bottom: 1px solid var(--hair); flex-wrap: wrap; }
.editor-toolbar .sep { width: 1px; background: var(--hair); margin: 4px 4px; }
.rich-editor {
    flex: 1 1 auto;
    min-height: 120px;
    overflow: auto;
    padding: 12px 14px;
    outline: none;
    line-height: 1.55;
    font-size: 14px;
    overflow-wrap: anywhere;
}
.rich-editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.rich-editor blockquote { margin: 8px 0; padding-left: 12px; border-left: 2px solid var(--hair-strong); color: var(--text-2); }
.rich-editor img { max-width: 100%; }
.rich-editor a { color: var(--signal); }

/* ---------- Docs ---------- */
.docs {
    display: grid;
    grid-template-columns: var(--docs-side-w, 280px) 0 minmax(0, 1fr);
    height: 100%;
    min-height: 0;
}
.docs-side { background: var(--panel); border-right: 1px solid var(--hair); display: flex; flex-direction: column; min-height: 0; }
.docs-side-head { padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); border-bottom: 1px solid var(--hair); }
.docs-list { overflow: auto; flex: 1; }
.doc-row { display: block; padding: 9px var(--s-3); border-bottom: 1px solid var(--hair); color: inherit; position: relative; text-decoration: none; }
.doc-row:hover { background: var(--hover); text-decoration: none; }
.doc-row.selected { background: var(--selection); }
.doc-row.selected::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--signal-line); }
.doc-row .t { font-weight: 500; font-size: 13px; }
.doc-row .s { font-size: 12px; color: var(--muted); }

.doc-workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.doc-toolbar { display: flex; align-items: center; gap: 4px; padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--hair); flex-wrap: wrap; min-height: 46px; }
.doc-title-input { border: 0; background: transparent; font-size: 20px; font-weight: 600; padding: var(--s-3) var(--s-5) var(--s-1); width: 100%; color: var(--text); }
.doc-title-input:focus { outline: none; box-shadow: inset 0 -1px 0 var(--signal-line); }
.doc-panes { display: grid; grid-template-columns: minmax(0, 1fr) 0 var(--doc-preview-w, minmax(0, 1fr)); flex: 1; min-height: 0; }
.doc-panes.edit-only { grid-template-columns: minmax(0, 1fr); }
.doc-panes.preview-only { grid-template-columns: minmax(0, 1fr); }
.doc-source {
    width: 100%;
    height: 100%;
    border: 0;
    resize: none;
    background: var(--base);
    color: var(--text);
    padding: var(--s-4) var(--s-5);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.65;
    tab-size: 4;
}
.doc-source:focus { outline: none; }
.doc-preview { overflow: auto; padding: var(--s-4) var(--s-5) var(--s-7); border-left: 1px solid var(--hair); min-width: 0; }
.doc-meta { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; padding: 0 var(--s-5) var(--s-2); }
.doc-aside { border-left: 1px solid var(--hair); padding: var(--s-3); overflow: auto; width: var(--doc-aside-w, 260px); flex: 0 0 var(--doc-aside-w, 260px); }

.prose { line-height: 1.65; font-size: 14.5px; max-width: 760px; overflow-wrap: anywhere; }
.prose h1 { font-size: 22px; margin: 1.4em 0 0.5em; }
.prose h2 { font-size: 18px; margin: 1.4em 0 0.5em; padding-bottom: 4px; border-bottom: 1px solid var(--hair); }
.prose h3 { font-size: 15px; margin: 1.2em 0 0.4em; }
.prose p, .prose ul, .prose ol, .prose table, .prose pre, .prose blockquote { margin: 0 0 1em; }
.prose code { font-family: var(--font-mono); font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--hair); padding: 0 4px; border-radius: var(--r-1); }
.prose pre { background: var(--panel-2); border: 1px solid var(--hair); padding: var(--s-3); border-radius: var(--r-2); overflow: auto; }
.prose pre code { border: 0; padding: 0; background: none; }
.prose blockquote { border-left: 2px solid var(--hair-strong); padding-left: var(--s-3); color: var(--text-2); }
.prose table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--hair); padding: 6px 10px; text-align: left; }
.prose th { background: var(--panel-2); font-weight: 600; }
.prose hr { border: 0; border-top: 1px solid var(--hair); margin: 2em 0; }
.prose img { max-width: 100%; }
.prose a.wiki-missing { color: var(--muted); text-decoration: underline dashed; }
.prose ul.contains-task-list { list-style: none; padding-left: 4px; }
.prose input[type="checkbox"] { accent-color: var(--signal); margin-right: 6px; }

.toc a { display: block; padding: 2px 0; color: var(--text-2); font-size: 12.5px; }
.toc a:hover { color: var(--text); }

/* ---------- Files ---------- */
.files {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 0 var(--files-preview-w, 420px);
    height: 100%;
    min-height: 0;
}
.files.no-preview { grid-template-columns: minmax(0, 1fr); }
.files-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.files-filters { display: flex; gap: var(--s-2); padding: var(--s-3); border-bottom: 1px solid var(--hair); flex-wrap: wrap; align-items: center; }
.files-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.files-table th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--hair); z-index: 1; white-space: nowrap; }
.files-table td { padding: 7px 10px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
.files-table tr { cursor: pointer; position: relative; }
.files-table tbody tr:hover { background: var(--hover); }
.files-table tr.selected { background: var(--selection); }
.files-table tr.selected td:first-child { box-shadow: inset 2px 0 0 var(--signal-line); }
.files-table .num { text-align: right; white-space: nowrap; }
.file-kind { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.file-preview { border-left: 1px solid var(--hair); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.file-preview .preview-body { flex: 1; overflow: auto; padding: var(--s-3); min-height: 0; }
.file-preview img { max-width: 100%; display: block; margin: 0 auto; background: repeating-conic-gradient(var(--hair) 0 25%, transparent 0 50%) 50% / 16px 16px; }
.file-preview iframe { width: 100%; height: 100%; min-height: 480px; border: 0; background: #fff; }
.file-preview pre { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--font-mono); font-size: 12px; margin: 0; }
.sheet-table { border-collapse: collapse; font-size: 12px; }
.sheet-table td { border: 1px solid var(--hair); padding: 3px 6px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Deck ---------- */
.deck-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: var(--s-4);
    align-items: start;
}
.deck-main { display: flex; flex-direction: column; gap: var(--s-4); }
.deck-side { display: flex; flex-direction: column; gap: var(--s-4); }
.deck-hero {
    display: flex;
    gap: var(--s-5);
    align-items: flex-end;
    flex-wrap: wrap;
    padding-bottom: var(--s-4);
    margin-bottom: var(--s-4);
    border-bottom: 1px solid var(--hair);
}
.deck-hero .greeting { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.deck-hero .date { color: var(--muted); font-family: var(--font-mono); font-size: 12px; }
.deck-meters { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-left: auto; }
.meter-tile {
    min-width: 108px;
    padding: 8px 12px;
    border: 1px solid var(--hair);
    border-radius: var(--r-2);
    background: var(--panel);
    color: inherit;
    text-decoration: none;
}
.meter-tile:hover { border-color: var(--hair-strong); text-decoration: none; }
.meter-tile .v { font-family: var(--font-mono); font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.2; }
.meter-tile.hot .v { color: var(--signal); }
.meter-tile .k { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }

.queue-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 9px var(--s-3); border-bottom: 1px solid var(--hair); color: inherit; text-decoration: none; }
.queue-row:last-child { border-bottom: 0; }
.queue-row:hover { background: var(--hover); text-decoration: none; }

/* ---------- Tools ---------- */
.tools {
    display: grid;
    grid-template-columns: var(--tools-nav-w, 220px) 0 minmax(0, 1fr);
    height: 100%;
    min-height: 0;
}
.tools-nav { background: var(--panel); border-right: 1px solid var(--hair); overflow: auto; padding: var(--s-2) 0; }
.tools-body { overflow: auto; min-height: 0; }
.tool-pane { max-width: 1040px; padding: var(--s-5); }
.tool-head { margin-bottom: var(--s-4); }
.tool-head p { color: var(--muted); margin: 4px 0 0; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s-4); }
.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: var(--s-5);
    border: 1px dashed var(--hair-strong);
    border-radius: var(--r-2);
    color: var(--muted);
    text-align: center;
    position: relative;
}
.drop-zone:hover, .drop-zone:focus-within { border-color: var(--signal); color: var(--text); }
.drop-zone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.diff-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 12px; table-layout: fixed; }
.diff-table td { padding: 1px 6px; vertical-align: top; white-space: pre-wrap; overflow-wrap: anywhere; border-bottom: 1px solid transparent; }
.diff-table td.ln { width: 44px; color: var(--muted); text-align: right; user-select: none; border-right: 1px solid var(--hair); }
.diff-table .del { background: var(--fault-soft); }
.diff-table .ins { background: var(--ok-soft); }
.diff-table .mod { background: var(--signal-soft); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px var(--s-4); font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--hair); }
.data-table td { padding: 7px 10px; border-bottom: 1px solid var(--hair); vertical-align: top; }

.tz-grid { overflow-x: auto; }
.tz-grid table { border-collapse: collapse; font-family: var(--font-mono); font-size: 11.5px; }
.tz-grid th { text-align: left; padding: 4px 10px 4px 0; font-family: var(--font-ui); font-weight: 500; font-size: 12px; white-space: nowrap; position: sticky; left: 0; background: var(--base); }
.tz-grid td { width: 34px; min-width: 34px; text-align: center; padding: 5px 0; border: 1px solid var(--hair); color: var(--muted); }
.tz-grid td.work { color: var(--text); background: var(--ok-soft); }
.tz-grid td.overlap { background: var(--signal-soft); color: var(--text); }
.tz-grid td.now { box-shadow: inset 0 0 0 1px var(--signal); }

/* QRCoder emits fixed pixel sizes; let the container decide. */
.qr-box { background: #fff; padding: 10px; border-radius: var(--r-2); }
.qr-box svg { display: block; width: 100%; height: auto; }

/* ---------- Settings ---------- */
.settings {
    display: grid;
    grid-template-columns: var(--settings-nav-w, 220px) 0 minmax(0, 1fr);
    height: 100%;
    min-height: 0;
}
.settings-body { overflow: auto; }
.settings-pane { max-width: 860px; padding: var(--s-5); display: flex; flex-direction: column; gap: var(--s-4); }
.setting-row { display: flex; align-items: flex-start; gap: var(--s-4); padding: var(--s-3) 0; border-bottom: 1px solid var(--hair); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .desc { flex: 1; min-width: 0; }
.setting-row .desc .muted { font-size: 12.5px; }

.account-card { display: flex; gap: var(--s-3); align-items: center; padding: var(--s-3); border-bottom: 1px solid var(--hair); }
.account-card:last-child { border-bottom: 0; }
.account-card .grow { min-width: 0; overflow-wrap: anywhere; }

/* ---------- Auth ---------- */
.auth-wrap {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: var(--s-4);
    overflow: auto;
}
body:has(.auth-wrap) { overflow: auto; }
.auth-card {
    width: min(400px, 100%);
    background: var(--panel);
    border: 1px solid var(--hair);
    border-radius: var(--r-2);
    padding: var(--s-5);
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
}
.auth-card .wordmark { font-family: var(--font-mono); font-size: 12px; color: var(--signal); letter-spacing: 0.04em; }
.auth-card .btn { width: 100%; min-height: 38px; }
.auth-error { padding: 8px 10px; border: 1px solid var(--fault); border-radius: var(--r-1); color: var(--fault); background: var(--fault-soft); font-size: 13px; }

/* ---------- Mobile + tablet ---------- */
.only-mobile { display: none !important; }
.back-btn { display: none; }

@media (max-width: 1180px) {
    .mail { grid-template-columns: 64px min(var(--mail-list-w, 340px), 50vw) 0 minmax(0, 1fr); }
    .split-mail-nav { display: none; }
    .mail-nav .nav-item span.txt, .mail-nav .nav-item .count, .mail-nav .nav-group-title, .mail-nav .label-row { display: none; }
    .mail-nav .nav-item { justify-content: center; padding: 8px 0; }
    .mail-nav .compose-btn { width: 40px; margin: 4px auto 10px; display: flex; padding: 0; }
    .mail-nav .compose-btn .txt { display: none; }
    .mail-nav.open { position: absolute; z-index: 40; width: 260px; height: 100%; box-shadow: var(--shadow-float); animation: slide-right 160ms cubic-bezier(0.2, 0.7, 0.2, 1); }
    .mail-nav.open .nav-item span.txt, .mail-nav.open .nav-item .count, .mail-nav.open .nav-group-title, .mail-nav.open .label-row { display: revert; }
    .mail-nav.open .nav-item { justify-content: flex-start; padding: 5px 12px; }
    .files { grid-template-columns: minmax(0, 1fr) 0 min(var(--files-preview-w, 340px), 55vw); }
    .deck-grid { grid-template-columns: minmax(0, 1fr); }
    .doc-panes { grid-template-columns: minmax(0, 1fr); }
    .doc-panes .doc-preview { border-left: 0; border-top: 1px solid var(--hair); }
    .doc-panes.split .doc-preview, .split-doc-preview { display: none; }
}

@media (max-width: 760px) {
    :root { --rail-w: 0px; --status-h: 0px; }
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 58px; }
    .rail {
        grid-row: 2 / 3;
        flex-direction: row;
        border-right: 0;
        border-top: 1px solid var(--hair);
        padding: 0 4px;
        justify-content: space-around;
    }
    .rail-mark, .rail-spacer, .rail .desktop-only { display: none; }
    .rail a, .rail button { flex: 1; min-height: 44px; padding: 8px 0 4px; }
    .rail a.active::before { left: 18%; right: 18%; top: 0; bottom: auto; width: auto; height: 2px; }
    .main { grid-row: 1 / 2; }
    .statusbar { display: none; }
    .only-mobile { display: revert !important; }
    .no-mobile { display: none !important; }

    .splitter { display: none; }
    .mail { grid-template-columns: minmax(0, 1fr); position: relative; }
    .mail-nav { display: none; }
    .mail-nav.open { display: block; position: fixed; inset: 0 0 58px 0; width: 100%; z-index: 50; box-shadow: none; animation: slide-right 160ms cubic-bezier(0.2, 0.7, 0.2, 1); }
    .mail.reading .reader { animation: slide-left 160ms cubic-bezier(0.2, 0.7, 0.2, 1); }
    .mail-nav.open .nav-item { padding: 10px 16px; min-height: 44px; }
    .mail.reading .mail-list { display: none; }
    .mail:not(.reading) .reader { display: none; }
    .back-btn { display: inline-flex; }
    .reader-scroll { padding: var(--s-3) var(--s-3) var(--s-7); }
    .msg { padding: 11px 12px 12px 4px; grid-template-columns: 34px minmax(0, 1fr) auto; }
    .msg .pick input { width: 20px; height: 20px; }

    .compose { inset: 0 0 58px 0; width: 100%; height: auto; border-radius: 0; right: 0; bottom: 58px; }
    .compose.maximized { left: 0; top: 0; }

    .docs { grid-template-columns: minmax(0, 1fr); }
    .docs.has-doc .docs-side { display: none; }
    .docs:not(.has-doc) .doc-workspace { display: none; }
    .doc-title-input { padding: var(--s-3) var(--s-3) 0; }
    .doc-source { padding: var(--s-3); }
    .doc-preview { padding: var(--s-3); }
    .doc-meta { padding: 0 var(--s-3) var(--s-2); }

    .files { grid-template-columns: minmax(0, 1fr); }
    .files .file-preview { position: fixed; inset: 0 0 58px 0; z-index: 50; animation: slide-left 160ms cubic-bezier(0.2, 0.7, 0.2, 1); }
    .files-table .col-from, .files-table .col-date { display: none; }

    .tools, .settings { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
    .tools-nav, .settings .tools-nav { display: flex; overflow-x: auto; padding: 0; border-right: 0; border-bottom: 1px solid var(--hair); }
    .tools-nav .nav-group-title { display: none; }
    .tools-nav .nav-group { display: contents; }
    .tools-nav .nav-item { white-space: nowrap; width: auto; padding: 10px 12px; min-height: 44px; }
    .tools-nav .nav-item.active::before { left: 8px; right: 8px; top: auto; bottom: 0; width: auto; height: 2px; }
    .tool-pane, .settings-pane { padding: var(--s-3); }
    .two-col { grid-template-columns: minmax(0, 1fr); }
    .page-inner { padding: var(--s-3) var(--s-3) var(--s-6); }
    .deck-meters { margin-left: 0; }
    .toasts { bottom: 70px; }
    .btn { min-height: 40px; }
    .btn-icon { width: 40px; }
    .btn-sm { min-height: 34px; }
    .btn-sm.btn-icon { width: 34px; }
    .input, .select { min-height: 40px; font-size: 16px; }
    .overlay { padding: var(--s-3); }
    .setting-row { flex-direction: column; gap: var(--s-2); }
    .account-card { flex-wrap: wrap; }
    .account-card > .row-wrap { width: 100%; }
}

/* ---------- Print (docs) ---------- */
@media print {
    body { overflow: visible; background: #fff; color: #000; }
    .shell { display: block; height: auto; }
    .rail, .statusbar, .docs-side, .doc-toolbar, .doc-source, .doc-meta, .doc-aside, .toasts, .compose, .no-print { display: none !important; }
    .main, .page, .docs, .doc-workspace, .doc-panes, .doc-preview { display: block !important; overflow: visible !important; height: auto !important; border: 0 !important; }
    .doc-title-input { color: #000; padding: 0; }
    .prose { max-width: none; color: #000; }
}

/* ---------- Blazor plumbing ---------- */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    padding: 10px 14px;
    background: var(--raised);
    color: var(--text);
    border-radius: var(--r-2);
    box-shadow: 0 0 0 1px var(--fault), var(--shadow-float);
    font-size: 13px;
}
#blazor-error-ui .reload { color: var(--signal); margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; margin-left: 12px; color: var(--muted); }

.blazor-error-boundary { padding: var(--s-4); color: var(--fault); }
.blazor-error-boundary::after { content: "Something went wrong on this view. Reload the page to continue."; }

/* ---------- Signatures and PDF signing ---------- */
.sig-pad-wrap { position: relative; border: 1px solid var(--hair-strong); border-radius: var(--r-2); background: #fbfaf7; height: 220px; }
.sig-pad { width: 100%; height: 100%; display: block; cursor: crosshair; border-radius: var(--r-2); }
.sig-pad-line { position: absolute; left: 8%; right: 8%; bottom: 28%; border-bottom: 1px dashed #b8b4aa; pointer-events: none; }
.sig-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.sig-styles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.sig-style {
    min-height: 74px;
    padding: 8px 14px;
    border: 1px solid var(--hair-strong);
    border-radius: var(--r-2);
    background: #fbfaf7;
    color: #14143c;
    font-size: 30px;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.sig-style.active { border-color: var(--signal); box-shadow: 0 0 0 1px var(--signal); }

.sig-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; padding: var(--s-3); }
.sig-card { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--hair); border-radius: var(--r-2); }
/* Signatures are dark ink on transparent, so previews always sit on paper colour, in both themes. */
.sig-card-img { height: 90px; display: grid; place-items: center; background: #fbfaf7; border-radius: var(--r-1); padding: 6px; }
.sig-card-img img { max-width: 100%; max-height: 100%; }

.sign-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: var(--s-4); align-items: start; }
.sign-side { position: sticky; top: 0; display: flex; flex-direction: column; gap: 10px; padding: var(--s-3); border: 1px solid var(--hair); border-radius: var(--r-2); background: var(--panel); }
.sign-file { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--hair); min-width: 0; }
.sign-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sign-tool { height: 54px; border: 1px solid var(--hair-strong); border-radius: var(--r-1); background: #fbfaf7; padding: 4px; cursor: pointer; display: grid; place-items: center; }
.sign-tool img { max-width: 100%; max-height: 100%; }
.sign-tool.text { background: var(--panel-2); color: var(--text); font-weight: 500; }
.sign-tool.active { border-color: var(--signal); box-shadow: 0 0 0 1px var(--signal); }

.sign-pages { display: flex; flex-direction: column; gap: var(--s-4); align-items: center; padding-bottom: var(--s-7); }
.sign-page { position: relative; width: min(100%, 860px); background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); user-select: none; }
.sign-page.placing { cursor: copy; }
.sign-page > img { display: block; width: 100%; height: 100%; pointer-events: none; }
.sign-page-no { position: absolute; right: 8px; bottom: 6px; font-family: var(--font-mono); font-size: 11px; color: #6b675f; pointer-events: none; }

.stamp { position: absolute; container-type: size; cursor: move; outline: 1px dashed transparent; touch-action: none; }
.stamp:hover, .stamp.selected, .stamp:focus-visible { outline-color: var(--signal); }
.stamp img { width: 100%; height: 100%; object-fit: contain; object-position: left center; pointer-events: none; }
.stamp-text { display: block; font-family: "Segoe UI", system-ui, sans-serif; font-size: 72cqh; line-height: 100cqh; color: #1a1a2e; white-space: nowrap; pointer-events: none; }
.stamp-remove {
    position: absolute; top: -11px; right: -11px; width: 22px; height: 22px; padding: 0;
    display: none; place-items: center; border-radius: 50%; border: 0;
    background: var(--fault); color: #fff; cursor: pointer;
}
.stamp-remove .ico { width: 12px; height: 12px; }
.stamp.selected .stamp-remove, .stamp:hover .stamp-remove { display: grid; }
.stamp-handle { position: absolute; right: -6px; bottom: -6px; width: 12px; height: 12px; background: var(--signal); border: 2px solid #fff; cursor: nwse-resize; display: none; }
.stamp.selected .stamp-handle, .stamp:hover .stamp-handle { display: block; }

@media (max-width: 900px) {
    .sign-layout { grid-template-columns: minmax(0, 1fr); }
    .sign-side { position: static; }
    .stamp-remove, .stamp-handle { display: grid; }
    .stamp-handle { display: block; width: 18px; height: 18px; right: -9px; bottom: -9px; }
}

/* Google sign-in */
.setup-steps { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 8px; line-height: 1.5; }
.copy-field { display: block; padding: 6px 8px; border: 1px solid var(--hair); border-radius: var(--r-1); background: var(--base); min-width: 0; }
.oauth-btn { gap: 10px; }
.g-logo { width: 18px; height: 18px; flex: none; }
.oauth-box .g-logo { width: 22px; height: 22px; }
.oauth-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px; border: 1px solid var(--hair); border-radius: var(--r-1); background: var(--base); }

/* Unsubscribe bar */
.unsub-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 14px; border: 1px solid var(--hair); border-left: 3px solid var(--signal-line); border-radius: var(--r-1); background: var(--panel-2); font-size: 13px; }
.unsub-bar.done { border-left-color: var(--ok); }
.unsub-bar .grow { min-width: 220px; }

/* Rules */
.rule-block { border: 1px solid var(--hair); border-radius: var(--r-1); padding: 10px 12px 12px; margin: 0; display: grid; gap: 8px; }
.rule-block legend { padding: 0 6px; }
.rule-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rule-row > * { flex: none; }
.rule-row > .select:first-child { width: auto; min-width: 200px; }
.rule-row > .grow { flex: 1 1 180px; width: auto; min-width: 0; }
.rule-card.off { opacity: 0.6; }
.rule-order { min-width: 28px; justify-content: center; }
.rule-block > .btn, .rule-block > .switch { justify-self: start; }

/* Camera capture */
.camera-body { padding: var(--s-3); }
.camera-stage { position: relative; background: #000; border-radius: var(--r-1); aspect-ratio: 16 / 9; display: grid; place-items: center; overflow: hidden; }
.camera-stage video, .camera-stage img { width: 100%; height: 100%; object-fit: contain; display: block; }
.camera-stage video[hidden], .camera-stage img[hidden] { display: none; }
.camera-stage.mirror video { transform: scaleX(-1); }
.camera-note { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; padding: 24px; text-align: center; color: #e6e4df; background: rgba(0, 0, 0, 0.6); }
.camera-note p { max-width: 46ch; margin: 0 auto; }
@media (max-width: 640px) { .camera-stage { aspect-ratio: 3 / 4; } .camera-dialog .dialog-foot { flex-wrap: wrap; } }

/* ---------- Resizable panes (see js/splitters.js) ---------- */
.splitter {
    position: relative;
    z-index: 5;
    width: 0;
    min-height: 0;
    cursor: col-resize;
    touch-action: none;
    outline: none;
}
/* An 8px grab area centred on the pane border, with a signal-coloured line while hovered, focused or dragged. */
.splitter::before { content: ""; position: absolute; inset: 0 -4px; }
.splitter::after { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: transparent; transition: background var(--fast); }
.splitter:hover::after, .splitter.dragging::after { background: var(--signal-line); }
.splitter:focus-visible::after { background: var(--focus); }
html.resizing, html.resizing * { cursor: col-resize !important; user-select: none !important; }
/* Iframes (mail bodies, PDF previews) would swallow the pointer mid-drag. */
html.resizing iframe { pointer-events: none; }

/* ---------- Compose: resize grips ---------- */
.compose-grip { position: absolute; z-index: 3; touch-action: none; }
.compose-grip.top { top: -3px; left: 14px; right: 0; height: 7px; cursor: ns-resize; }
.compose-grip.left { left: -3px; top: 14px; bottom: 0; width: 7px; cursor: ew-resize; }
.compose-grip.corner { top: -3px; left: -3px; width: 16px; height: 16px; cursor: nwse-resize; outline: none; border-radius: var(--r-2) 0 0 0; }
.compose-grip.corner::after { content: ""; position: absolute; top: 5px; left: 5px; width: 7px; height: 7px; border-top: 2px solid var(--hair-strong); border-left: 2px solid var(--hair-strong); border-radius: 3px 0 0 0; }
.compose-grip.corner:hover::after, .compose-grip.corner:focus-visible::after { border-color: var(--signal-line); }
.compose-grip.top:hover, .compose-grip.left:hover { background: linear-gradient(var(--signal-line), var(--signal-line)) center / 100% 2px no-repeat; }
.compose-grip.left:hover { background-size: 2px 100%; }
html.resizing-compose, html.resizing-compose * { user-select: none !important; }
html.resizing-compose iframe { pointer-events: none; }
.compose-count { text-align: right; padding-right: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Editor: colours, highlight, coach ---------- */
.swatch-menu { padding-bottom: 8px; }
.swatches { display: grid; grid-template-columns: repeat(4, 28px); gap: 6px; padding: 4px 10px; }
.swatch { width: 28px; height: 28px; padding: 0; border-radius: var(--r-1); border: 1px solid var(--hair-strong); cursor: pointer; display: grid; place-items: center; }
.menu .swatch { width: 28px; min-height: 28px; }
.swatch:hover, .swatch:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.swatch.none { background: var(--base); color: var(--muted); }
/* Highlighted text is dark so it stays legible on the dark editor, as it will on the recipient's white page. */
.rich-editor [style*="background-color"] { color: #1d1d1f; }
.rich-editor hr { border: 0; border-top: 1px solid var(--hair-strong); margin: 12px 0; }
.rich-editor ul, .rich-editor ol { padding-left: 24px; }

.coach-panel { margin: 8px 12px; border-radius: var(--r-1); padding: 8px 10px; max-height: 40%; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.coach-stats { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.coach-notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.coach-notes li { display: flex; align-items: baseline; gap: 8px; font-size: 13px; padding: 4px 0; border-top: 1px solid var(--hair); }
.coach-notes li:first-child { border-top: 0; }
.coach-notes .tag { flex: none; min-width: 92px; justify-content: center; }
.coach-stats .readout.hot { color: var(--signal); }
@media (max-width: 760px) { .compose-grip { display: none; } .coach-notes .tag { min-width: 0; } }
/* Keep the compose footer on one line in a narrow window: the follow-up choice and the word count give way first. */
@media (min-width: 761px) {
    .compose-foot { flex-wrap: nowrap; }
    .compose-foot > select { min-width: 0; flex: 0 1 auto; max-width: 220px; }
    .compose-foot > * { flex-shrink: 0; }
    .compose-foot > .compose-count, .compose-foot > select { flex-shrink: 1; }
}

/* Settings › AI agents */
.radio-row { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.radio-row input { margin-top: 3px; accent-color: var(--signal); }
.secret-panel { border-color: var(--signal-line); }
.secret-panel .row > .grow { min-width: 0; }
.secret-panel .copy-field { overflow: auto; max-width: 100%; }
