/* Astertek Mail. Tokens follow the marketing site (astertek.com): ink green-black, amber accent,
   Instrument Sans + IBM Plex Mono (self-hosted so CSP stays 'self'). */
@font-face { font-family: "Instrument Sans"; src: url(/fonts/instrument-sans.woff2) format("woff2"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url(/fonts/plex-mono-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url(/fonts/plex-mono-500.woff2) format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --amber: #ffb224;
  --amber-ink: #2a1c00;
  --ink: #0e1210;
  --grid: rgba(164, 175, 166, .07);

  --bg: #f3f2ec;
  --rail: #ebeae2;
  --panel: #ffffff;
  --panel-2: #f8f7f2;
  --line: #dddbd0;
  --line-2: #ebe9e0;
  --text: #151916;
  --muted: #5f6861;
  --faint: #6b736c;
  --link: #8a5600;
  --hover: rgba(14, 18, 16, .045);
  --sel: rgba(255, 178, 36, .17);
  --active: rgba(255, 178, 36, .26);
  --focus: #c98200;
  --danger: #c4372f;
  --ok: #23824b;
  --shadow: 0 1px 2px rgba(14,18,16,.06), 0 12px 32px -12px rgba(14,18,16,.22);
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1210; --rail: #0a0d0b; --panel: #151a17; --panel-2: #1a201c; --line: #2c3530; --line-2: #222a25;
    --text: #eaede6; --muted: #a4afa6; --faint: #78837a; --link: #ffc65c; --hover: rgba(234, 237, 230, .05);
    --sel: rgba(255, 178, 36, .12); --active: rgba(255, 178, 36, .2); --focus: #ffb224; --danger: #ff7b72; --ok: #7be0a1;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 16px 40px -12px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1210; --rail: #0a0d0b; --panel: #151a17; --panel-2: #1a201c; --line: #2c3530; --line-2: #222a25;
  --text: #eaede6; --muted: #a4afa6; --faint: #78837a; --link: #ffc65c; --hover: rgba(234, 237, 230, .05);
  --sel: rgba(255, 178, 36, .12); --active: rgba(255, 178, 36, .2); --focus: #ffb224; --danger: #ff7b72; --ok: #7be0a1;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 16px 40px -12px rgba(0,0,0,.7);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; overflow: hidden; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }
kbd { font: 500 11px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; background: var(--panel-2); }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mark { width: 22px; height: 22px; color: var(--amber); flex: none; }
.mark.big { width: 56px; height: 56px; opacity: .5; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 6px; border: 1px solid transparent; background: none; font-weight: 600; white-space: nowrap; transition: background .12s, border-color .12s, transform .06s; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: var(--amber); color: var(--amber-ink); }
.btn-primary:hover:not(:disabled) { background: #ffbf47; }
.btn-ghost { border-color: var(--line); background: var(--panel); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); }
.btn-danger-ghost { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn-block { width: 100%; height: 42px; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 6px; background: none; color: var(--muted); flex: none; }
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .ic { width: 16px; height: 16px; }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 4px; }
.link-btn:hover { color: var(--text); background: var(--hover); }
.tbtn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border: 0; border-radius: 6px; background: none; color: var(--text); font-size: 13px; font-weight: 500; white-space: nowrap; }
.tbtn:hover:not(:disabled) { background: var(--hover); }
.tbtn .ic { width: 17px; height: 17px; color: var(--muted); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; overflow: auto; height: 100%;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(255,178,36,.14), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 32px 32px, linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 32px 32px, var(--ink);
  color: #eaede6; }
.login-card { width: min(400px, 100%); background: #151a17; border: 1px solid #2c3530; border-radius: 12px; padding: 32px 28px 24px; box-shadow: 0 30px 80px -30px rgba(0,0,0,.8); animation: rise .4s ease-out both; --line: #2c3530; --panel: #0e1210; --muted: #a4afa6; --text: #eaede6; --danger: #ff7b72; color-scheme: dark; }
.login-brand { display: flex; align-items: center; gap: 10px; font: 500 13px var(--mono); letter-spacing: .14em; }
.login-sub { color: #a4afa6; letter-spacing: .04em; }
.login-card h1 { font-size: 24px; font-weight: 600; letter-spacing: -.01em; margin: 28px 0 22px; }
.login-foot { color: #78837a; font-size: 12px; text-align: center; margin: 18px 0 0; font-family: var(--mono); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.field > span, .field legend { font-size: 13px; font-weight: 600; padding: 0; }
.field small { font-weight: 400; margin-left: 6px; }
.field input:not([type=radio]):not([type=color]), .field textarea { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text); }
.field textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.field-row { flex-direction: row; align-items: center; justify-content: space-between; }
.field input[type=color] { width: 56px; height: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 2px; }
.field-inline { display: flex; gap: 8px; }
.form-error { color: var(--danger); font-size: 13px; margin: -4px 0 14px; }

/* ---------- app shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { flex: none; height: calc(52px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); display: flex; align-items: center; gap: 10px; color: #eaede6;
  background: linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 26px 26px, linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 26px 26px, var(--ink); border-bottom: 1px solid #2c3530; }
.topbar .icon-btn { color: #a4afa6; }
.topbar .icon-btn:hover { color: #eaede6; background: rgba(234,237,230,.08); }
.tb-menu { display: none; }
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; color: inherit; padding-right: 8px; width: 214px; flex: none; }
.brand .mark { align-self: center; }
.brand-word { font: 500 13px var(--mono); letter-spacing: .16em; }
.brand-sub { font: 400 13px var(--mono); color: var(--amber); }
.search { flex: 1; min-width: 0; max-width: 640px; display: flex; align-items: center; height: 36px; border-radius: 6px; background: rgba(234,237,230,.07); border: 1px solid rgba(234,237,230,.1); padding: 0 4px 0 10px; transition: background .15s, border-color .15s; }
.search:focus-within { background: #eaede6; border-color: var(--amber); color: #0e1210; }
.search:focus-within .icon-btn { color: #0e1210; }
.search-ic { color: #a4afa6; }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; padding: 0 8px; color: inherit; }
.search input::placeholder { color: #a4afa6; }
.search input::-webkit-search-cancel-button { display: none; }
.tb-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; }
.avatar-btn { border: 0; background: none; padding: 4px; border-radius: 50%; margin-left: 4px; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--amber); color: var(--amber-ink); font-weight: 700; font-size: 13px; flex: none; text-transform: uppercase; }
.acct-menu { inset: auto; top: calc(56px + env(safe-area-inset-top)); right: 12px; left: auto; margin: 0; min-width: 240px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); padding: 6px; }
.acct-who { display: flex; flex-direction: column; padding: 10px 10px 12px; border-bottom: 1px solid var(--line-2); margin-bottom: 6px; }
.acct-who span { font-size: 12px; color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 38px; padding: 0 10px; border: 0; background: none; border-radius: 6px; text-align: left; }
.menu-item:hover { background: var(--hover); }
.menu-item .ic { color: var(--muted); }

.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px minmax(300px, 400px) 1fr; }

/* ---------- rail ---------- */
.rail { background: var(--rail); border-right: 1px solid var(--line); padding: 14px 10px 10px; overflow-y: auto; display: flex; flex-direction: column; }
.compose-btn { width: 100%; height: 40px; margin-bottom: 14px; justify-content: flex-start; padding: 0 14px; box-shadow: 0 1px 0 rgba(0,0,0,.08); }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px; border: 0; border-radius: 6px; background: none; text-align: left; color: var(--text); position: relative; }
.nav-item:hover { background: var(--hover); }
.nav-item[aria-current="page"] { background: var(--active); font-weight: 600; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--amber); }
.nav-item .ic { color: var(--muted); }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .badge { font: 500 12px var(--mono); color: var(--muted); }
.nav-item .badge.strong { color: var(--text); font-weight: 600; }
.label-row { display: flex; align-items: center; }
.label-row .nav-item { flex: 1; min-width: 0; }
.label-row .icon-btn { opacity: 0; }
.label-row:hover .icon-btn, .label-row .icon-btn:focus-visible { opacity: 1; }
.dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--faint)); flex: none; margin: 0 4px; }
.rail-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 4px; padding: 0 2px 0 10px; font: 500 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--faint); }
.rail-empty { color: var(--faint); font-size: 12px; padding: 4px 10px; }
.rail-foot { margin-top: auto; padding: 16px 10px 4px; font-size: 11px; color: var(--faint); line-height: 1.5; overflow-wrap: anywhere; }
.scrim { display: none; }

/* ---------- list ---------- */
.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.list-head { display: flex; align-items: center; gap: 6px; height: 48px; padding: 0 14px 0 6px; border-bottom: 1px solid var(--line-2); flex: none; }
.list-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-head .mono { font-size: 12px; margin-left: auto; white-space: nowrap; }
.chk { display: grid; place-items: center; width: 34px; height: 34px; flex: none; cursor: pointer; border-radius: 6px; }
.chk:hover { background: var(--hover); }
.chk input { width: 16px; height: 16px; margin: 0; accent-color: var(--amber); cursor: pointer; }
.bulk-bar { display: flex; align-items: center; gap: 2px; padding: 4px 8px; border-bottom: 1px solid var(--line-2); background: var(--panel-2); flex-wrap: wrap; flex: none; }
.bulk-bar .count { font: 500 12px var(--mono); color: var(--muted); padding: 0 8px 0 4px; }
.list-note { padding: 8px 14px; font-size: 12px; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line-2); flex: none; }
.thread-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.row { display: flex; align-items: flex-start; border-bottom: 1px solid var(--line-2); position: relative; }
.row .chk { margin: 8px 0 0 6px; }
.row:hover { background: var(--hover); }
.row.sel { background: var(--sel); }
.row.active { background: var(--active); }
.row.unread::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--amber); }
.row-main { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 10px; padding: 10px 14px 10px 4px; border: 0; background: none; text-align: left; color: inherit; }
.row-from { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.row-date { font: 12px var(--mono); color: var(--muted); white-space: nowrap; align-self: center; }
.row-subj { grid-column: 1 / -1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.row-prev { grid-column: 1 / -1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 0; }
.row-meta:empty { display: none; }
.row.unread .row-from, .row.unread .row-subj { font-weight: 600; }
.row.unread .row-date { color: var(--text); font-weight: 500; }
.count-pill { font: 500 11px var(--mono); color: var(--muted); margin-left: 4px; }
.chip-label { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 4px; font-size: 11.5px; font-weight: 500; color: var(--text); background: color-mix(in srgb, var(--c, #888) 16%, transparent); border: 1px solid color-mix(in srgb, var(--c, #888) 40%, transparent); max-width: 160px; }
.chip-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-label::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--c, #888); flex: none; }
.chip-label button { border: 0; background: none; padding: 0; margin-right: -3px; display: grid; place-items: center; color: var(--muted); }
.chip-label button .ic { width: 12px; height: 12px; }
.tag { font: 500 11px var(--mono); padding: 1px 6px; border-radius: 4px; }
.tag-draft { color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }
.tag-folder { color: var(--muted); border: 1px solid var(--line); text-transform: lowercase; }
.att-ic { width: 14px; height: 14px; color: var(--muted); }
.list-foot { flex: none; display: flex; justify-content: center; }
.list-foot .btn { margin: 10px; }
.state { padding: 48px 24px; text-align: center; color: var(--muted); }
.state strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.state .btn { margin-top: 14px; }
.skel { padding: 14px 14px 14px 44px; border-bottom: 1px solid var(--line-2); }
.skel i { display: block; height: 10px; border-radius: 4px; background: var(--line-2); margin: 6px 0; animation: pulse 1.2s ease-in-out infinite; }
.skel i:nth-child(1) { width: 40%; } .skel i:nth-child(2) { width: 75%; } .skel i:nth-child(3) { width: 55%; }
@keyframes pulse { 50% { opacity: .45; } }

/* ---------- reading pane ---------- */
.read-pane { background: var(--bg); min-width: 0; min-height: 0; display: flex; flex-direction: column; container-type: inline-size; }
@container (max-width: 1000px) { .thread-bar .tbtn { padding: 0 7px; } .thread-bar .tbtn.ico .lbl { display: none; } }
@container (max-width: 800px) { .thread-bar .tbtn.sec .lbl { display: none; } .thread-bar .tbtn.sec { padding: 0 8px; } }
@container (max-width: 700px) { .thread-bar .tbtn .lbl { display: none; } }
.read-empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.read-empty p { margin: 10px 0 0; }
.thread-bar { flex: none; display: flex; align-items: center; gap: 2px; height: 48px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line-2); overflow-x: auto; scrollbar-width: none; }
.thread-bar::-webkit-scrollbar { display: none; }
.thread-bar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; flex: none; }
.thread-bar .back, .thread-bar .more { display: none; }
.msg-print { display: none; }
.thread-scroll { flex: 1; overflow-y: auto; padding: 20px 24px 40px; overscroll-behavior: contain; }
.thread-title { margin: 0 0 6px; font-size: 21px; font-weight: 600; letter-spacing: -.015em; line-height: 1.25; overflow-wrap: anywhere; }
.thread-labels { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.thread-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; font-size: 12px; color: var(--muted); }
.msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.msg-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; width: 100%; padding: 12px 14px; border: 0; background: none; text-align: left; color: inherit; }
.msg-head .avatar { grid-row: span 2; width: 34px; height: 34px; }
.msg-head .avatar.out { background: var(--ink); color: var(--amber); }
.msg-from { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-from b { font-weight: 600; }
.msg-from .addr { color: var(--muted); font-size: 12.5px; margin-left: 4px; }
.msg-date { font: 12px var(--mono); color: var(--muted); white-space: nowrap; }
.msg-snip { grid-column: 2 / -1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-rcpt { grid-column: 2 / -1; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.msg-tools { display: flex; gap: 2px; padding: 0 10px 6px 60px; }
.msg-body { padding: 4px 14px 14px 60px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.55; margin: 0; font-family: var(--sans); }
.frame-wrap { background: #fff; border-radius: 6px; }
.frame-wrap iframe { display: block; width: 100%; border: 0; background: #fff; color-scheme: light; border-radius: 6px; }
.img-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; margin: 0 0 10px; border-radius: 6px; background: var(--panel-2); border: 1px dashed var(--line); font-size: 12.5px; color: var(--muted); }
.img-bar .ic { width: 16px; height: 16px; }
.img-bar button { margin-left: auto; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding: 0; list-style: none; }
.att { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--text); text-decoration: none; font-size: 13px; }
a.att:hover, button.att:hover { border-color: var(--focus); }
.att .ic { width: 16px; height: 16px; color: var(--muted); }
.att .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.att .sz { font: 11px var(--mono); color: var(--muted); }
.thread-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.trash-note { font-size: 12px; color: var(--muted); padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 14px; background: var(--panel); }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); padding: 0; max-width: calc(100vw - 24px); }
dialog::backdrop { background: rgba(8, 10, 9, .45); }
.sheet { width: 420px; }
.sheet.wide { width: 520px; }
.sheet form { padding: 22px 22px 18px; }
.sheet h2 { margin: 0 0 18px; font-size: 18px; font-weight: 600; }
.dlg-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.pick-body { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; margin: 0 -8px 8px; }
.pick-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border-radius: 6px; cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.pick-item:hover { background: var(--hover); }
.pick-item input { accent-color: var(--amber); width: 16px; height: 16px; margin: 0; }
.pick-item .ic { color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; padding: 3px; gap: 2px; background: var(--panel-2); flex-wrap: wrap; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 6px 14px; border-radius: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg input:checked + span { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; margin: 0 0 12px; align-items: center; }
.keys dt { text-align: right; white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }

/* ---------- compose ---------- */
.compose { width: min(760px, calc(100vw - 32px)); height: min(680px, calc(100vh - 48px)); overflow: hidden; }
.compose[open] { display: flex; }
.compose form { display: flex; flex-direction: column; width: 100%; height: 100%; position: relative; }
.compose-head { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 8px 0 18px; border-bottom: 1px solid var(--line-2); background: var(--panel-2); flex: none; }
.compose-head h2 { margin: 0; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose-status { font-size: 11.5px; margin-left: auto; white-space: nowrap; }
.compose-fields { flex: none; padding: 0 18px; }
.addr-row { display: flex; align-items: center; gap: 10px; min-height: 42px; border-bottom: 1px solid var(--line-2); }
.addr-row > label { width: 52px; flex: none; color: var(--muted); font-size: 13px; }
.chips { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 5px 0; cursor: text; }
.chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; height: 26px; padding: 0 4px 0 10px; border-radius: 13px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.bad { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.chip button { display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: none; color: var(--muted); padding: 0; }
.chip button:hover { background: var(--hover); color: var(--text); }
.chip button .ic { width: 12px; height: 12px; }
.chip-input, .subject-input { flex: 1; min-width: 120px; height: 30px; border: 0; background: none; outline: none; padding: 0; }
.subject-input { font-weight: 500; }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--line-2); flex: none; overflow-x: auto; }
.fmt { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 5px; background: none; color: var(--muted); font-size: 15px; flex: none; }
.fmt:hover { background: var(--hover); color: var(--text); }
.fmt .ic { width: 17px; height: 17px; }
.toolbar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; flex: none; }
.compose-note { margin: 0; padding: 8px 18px; font-size: 12.5px; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line-2); flex: none; }
.editor { flex: 1; min-height: 120px; overflow-y: auto; padding: 14px 18px; outline: none; line-height: 1.55; overflow-wrap: anywhere; }
.editor:empty::before { content: "Write your message…"; color: var(--faint); }
.editor blockquote { margin: 0 0 0 .8ex; border-left: 2px solid var(--line); padding-left: 1ex; color: var(--muted); }
.editor p { margin: 0; }
.att-list { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0 18px; flex: none; max-height: 96px; overflow-y: auto; }
.att-list:not(:empty) { padding-top: 8px; padding-bottom: 4px; }
.att-list .att { height: 32px; padding-right: 4px; }
.att-list .att.saved { border-style: dashed; }
.compose .form-error { margin: 6px 18px 0; }
.compose-foot { display: flex; align-items: center; gap: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) 18px; border-top: 1px solid var(--line-2); flex: none; }
.compose-foot .btn-primary { padding: 0 18px; }
.file-btn { position: relative; cursor: pointer; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file-btn:focus-within { outline: 2px solid var(--focus); }
.drop-hint { display: none; position: absolute; inset: 8px; border: 2px dashed var(--amber); border-radius: 10px; background: color-mix(in srgb, var(--panel) 88%, transparent); place-items: center; font-weight: 600; pointer-events: none; }
.compose.dragging .drop-hint { display: grid; }

/* ---------- toasts / fab ---------- */
.toasts { position: fixed; inset: auto; margin: 0; padding: 0; border: 0; background: none; color: inherit; overflow: visible; height: auto; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 50; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 14px; min-height: 44px; padding: 8px 8px 8px 16px; border-radius: 8px; background: #1c221e; color: #eaede6; border: 1px solid #2c3530; box-shadow: 0 12px 30px -10px rgba(0,0,0,.6); font-size: 13.5px; animation: rise .2s ease-out both; max-width: 100%; }
.toast.err { border-color: #ff7b72; }
.toast.err::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #ff7b72; flex: none; }
.toast button { border: 0; background: none; color: var(--amber); font-weight: 600; padding: 6px 10px; border-radius: 5px; }
.toast button:hover { background: rgba(255,178,36,.12); }
.fab { display: none; place-items: center; position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 16px; border: 0; background: var(--amber); color: var(--amber-ink); box-shadow: 0 10px 24px -8px rgba(0,0,0,.45); z-index: 15; }
.fab .ic { width: 22px; height: 22px; stroke-width: 2; }
.spin .ic, .spin.ic { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- medium: rail becomes a drawer ---------- */
@media (max-width: 1100px) {
  .panes { grid-template-columns: minmax(300px, 380px) 1fr; }
  .tb-menu { display: inline-grid; }
  .brand { width: auto; }
  .rail { position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(290px, 84vw); padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(12px + env(safe-area-inset-bottom)); padding-left: max(10px, env(safe-area-inset-left)); transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow); }
  body.drawer-open .rail { transform: none; }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(8,10,9,.5); }
  .label-row .icon-btn { opacity: 1; }
  .fab { display: grid; }
  .list-foot { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ---------- phone: single pane ---------- */
@media (max-width: 760px) {
  .hide-mobile { display: none !important; }
  .topbar { gap: 4px; }
  .brand-word { display: none; }
  .brand { padding-right: 4px; }
  .search { max-width: none; }
  .panes { grid-template-columns: 100%; position: relative; }
  .list-pane { border-right: 0; }
  .read-pane { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .22s ease, visibility .22s; visibility: hidden; padding-top: env(safe-area-inset-top); }
  body.reading .read-pane { transform: none; visibility: visible; }
  .thread-bar { height: 52px; padding: 0 max(4px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left)); }
  .thread-bar .back { display: inline-flex; }
  .thread-bar .tbtn .lbl { display: none; }
  .thread-bar .tbtn { min-width: 44px; height: 44px; justify-content: center; padding: 0; }
  .thread-bar .tbtn.sec { display: none; }
  .thread-bar .more { display: inline-flex; margin-left: auto; }
  /* touch targets >= 44px */
  .msg-tools .tbtn, .att, .link-btn, .seg span, .menu-item, .toast button { min-height: 44px; }
  .link-btn, .seg span { display: inline-flex; align-items: center; }
  .icon-btn.sm, .fmt, .avatar-btn { width: 44px; height: 44px; }
  .avatar-btn { display: grid; place-items: center; }
  .chip button { width: 32px; height: 32px; margin: -3px -4px -3px 0; position: relative; }
  .chip button::after { content: ""; position: absolute; inset: -6px; } /* 44px hit area inside a 26px chip */
  .chip { padding-right: 2px; }
  /* To row: label stays on the first line; the input fits beside a chip */
  .chip-input { min-width: 60px; }
  .addr-row { align-items: flex-start; }
  .addr-row > label { padding-top: 12px; }
  .chip-input::-webkit-calendar-picker-indicator { display: none !important; }
  .thread-scroll { padding: 16px max(12px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .thread-title { font-size: 19px; }
  .msg-body { padding: 4px 12px 12px; }
  .msg-tools { padding: 0 6px 6px; }
  .msg-head { padding: 12px; }
  .row-main { padding: 12px 12px 12px 2px; }
  .row .chk { width: 44px; height: 44px; margin: 2px 0 0 0; }
  .chk { width: 44px; height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .nav-item { height: 44px; }
  .bulk-bar .tbtn { min-width: 44px; height: 44px; justify-content: center; padding: 0 8px; }
  .bulk-bar .tbtn .lbl { display: none; }
  body.reading .fab { display: none; }
  .compose { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; padding-top: env(safe-area-inset-top); }
  .compose-head { padding-left: 12px; }
  .compose-fields { padding: 0 12px; }
  .addr-row > label { width: 44px; }
  .chip-input, .subject-input { height: 36px; font-size: 16px; }
  .editor { padding: 12px; font-size: 16px; }
  .compose-foot { padding-left: 12px; }
  .compose-foot .btn { height: 44px; }
  .sheet, .sheet.wide { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 14px 14px 0 0; border-bottom: 0; }
  .sheet form { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .field input:not([type=radio]):not([type=color]), .field textarea { font-size: 16px; height: 44px; }
  .field textarea { height: auto; }
  .pick-item { min-height: 48px; }
  .btn { height: 44px; }
  .toasts { bottom: calc(86px + env(safe-area-inset-bottom)); }
  .acct-menu { right: 8px; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- print: only the open conversation ---------- */
@media print {
  body { overflow: visible; background: #fff; color: #000; }
  .topbar, .rail, .list-pane, .thread-bar, .msg-tools, .thread-foot, .fab, .toasts, .img-bar, .scrim { display: none !important; }
  .app, .panes, .read-pane, .thread-scroll { display: block; height: auto; overflow: visible; position: static; transform: none; visibility: visible; }
  .msg { border: 0; border-top: 1px solid #ccc; border-radius: 0; break-inside: avoid-page; }
  .msg-body, .msg-snip, .msg-rcpt { display: none !important; }
  .msg-print { display: block; padding: 0 14px 14px; }
}
