/* keymail — looks, feels, smells like email. */

:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f4f2, #14161a);
  --panel: light-dark(#ffffff, #1c1f25);
  --panel-2: light-dark(#fafaf8, #22262d);
  --text: light-dark(#1b1d21, #e8e9eb);
  --muted: light-dark(#6b7280, #9aa1ab);
  --line: light-dark(#e4e4e0, #2c313a);
  --accent: light-dark(#3f51b5, #8c9eff);
  --accent-soft: light-dark(#eef0fb, #262c3f);
  --ok: light-dark(#1a7f37, #4ade80);
  --warn: light-dark(#b45309, #fbbf24);
  --bad: light-dark(#b91c1c, #f87171);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must win over author `display` rules. Elements like
   #locked and #app set `display:flex` via an ID selector, which outranks the
   UA sheet's `[hidden]{display:none}` — so without this, toggling `hidden` in
   JS does nothing and the locked card paints on top of a claimed inbox. */
[hidden] { display: none !important; }
html, body { height: 100%; }

/* --- icons (inline Lucide SVG) --- */
.icon { display: inline-flex; align-items: center; justify-content: center; vertical-align: -0.14em; line-height: 0; }
.icon svg { width: 1em; height: 1em; display: block; }
.icon.spin svg { animation: km-spin 0.7s linear infinite; }
@keyframes km-spin { to { transform: rotate(360deg); } }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* --- top bar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.wordmark { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.wordmark-accent { color: var(--accent); }
.search-wrap { position: relative; flex: 1; max-width: 560px; }
#search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#search:focus { outline: 2px solid var(--accent); border-color: transparent; }
.search-chip {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  z-index: 25;
}
.search-empty { padding: 10px 14px; color: var(--muted); font-size: 13px; }
.search-hit {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.search-hit:last-child { border-bottom: none; }
.search-hit:hover { background: var(--panel-2); }
.search-hit-when { color: var(--muted); font-size: 12px; flex-shrink: 0; width: 34px; }
.search-hit-from {
  font-weight: 600;
  flex-shrink: 0;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-hit-subject { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  position: relative;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  user-select: none;
}
.me:hover { background: var(--panel-2); }
.me-caret { font-size: 10px; }
.account-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  padding: 6px;
  z-index: 25;
}
.account-item, .account-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}
.account-item:hover, .account-action:hover { background: var(--panel-2); }
.account-item.current { font-weight: 600; cursor: default; }
.account-dot { color: var(--accent); font-size: 10px; }
.account-dot.on svg { fill: currentColor; }
.account-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.account-action { color: var(--muted); }
.account-action.danger { color: var(--bad); }

/* --- layout --- */
#app { display: flex; flex-direction: column; height: 100vh; }
.layout {
  display: grid;
  grid-template-columns: 180px minmax(280px, 420px) 1fr;
  flex: 1;
  min-height: 0;
}
.layout.wide { grid-template-columns: 180px 1fr 0; }
.layout.wide .reading { display: none; }

/* --- sidebar --- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
}
#compose-btn { margin-bottom: 12px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}
.nav-item .icon { font-size: 18px; flex-shrink: 0; }
.nav-item .nav-label { flex: 1; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--accent-soft); font-weight: 600; }
/* each section gets its own colour, so the sidebar is scannable at a glance */
.nav-item[data-view="in"] .icon       { color: #5b6cff; }
.nav-item[data-view="apps"] .icon     { color: #e64980; }
.nav-item[data-view="newsletters"] .icon { color: #74b816; }
.nav-item[data-view="all"] .icon      { color: #22b8cf; }
.nav-item[data-view="sent"] .icon     { color: #12b886; }
.nav-item[data-view="draft"] .icon    { color: #f59f00; }
.nav-item[data-view="outbox"] .icon   { color: #fd7e14; }
.nav-item[data-view="trashed"] .icon  { color: #adb5bd; }
.nav-item[data-view="contact"] .icon  { color: #7048e8; }
.nav-item[data-view="settings"] .icon { color: #868e96; }
.badge {
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 0 7px;
  font-size: 11px;
  line-height: 18px;
}
.badge.bad { background: var(--bad); }
.badge:empty { display: none; }
.sidebar-foot { margin-top: auto; padding: 10px 12px; font-size: 12px; color: var(--muted); }

/* --- avatars (coloured initial discs) --- */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  user-select: none;
}
.avatar.lg { width: 46px; height: 46px; font-size: 19px; }
/* a small verified check tucked into the corner of a reading-pane avatar */
.avatar-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.avatar-badge {
  position: absolute; right: -3px; bottom: -3px;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--panel);
  color: var(--ok);
  font-size: 13px;
}
.who-domain { color: var(--muted); font-weight: 400; }
/* the full muted address beside a display name: "Name <addr>" */
.who-addr { color: var(--muted); font-weight: 400; }

/* --- message list --- */
.list { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.list-total {
  padding: 6px 16px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  position: sticky; top: 0; z-index: 1;
}
.msg-row {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.msg-row:hover { background: var(--panel-2); }
/* Multi-select: the list header (select-all + count, or the bulk-action bar),
   and a per-row checkbox that reserves its slot but shows only on hover/select. */
.list-head {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 16px; min-height: 30px;
  border-bottom: 1px solid var(--line); background: var(--panel-2);
  position: sticky; top: 0; z-index: 2;
}
.list-head .list-total { padding: 0; border: 0; background: none; position: static; }
.sel-all { cursor: pointer; margin: 0; }
/* The read-state filter chip, right-aligned after the count. */
.unread-chip { margin-left: auto; color: var(--muted); }
.unread-chip.on { color: var(--accent); background: var(--accent-soft); }
.bulk-bar { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }
.bulk-count { font-size: 12px; color: var(--muted); }
.bulk-x { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; display: inline-flex; padding: 2px; }
.bulk-x:hover { color: var(--fg); }
.sel-box { display: inline-flex; align-items: center; visibility: hidden; }
.sel-box input { cursor: pointer; margin: 0; }
.msg-row:hover .sel-box, .msg-row.sel .sel-box { visibility: visible; }
.msg-row.sel, .msg-row.sel:hover { background: var(--accent-soft); }
.msg-row.selected { background: var(--accent-soft); }
.msg-row.unread::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.msg-main { flex: 1; min-width: 0; }
.msg-row-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.msg-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-who strong { font-weight: 600; }
.msg-row.unread .msg-who strong { font-weight: 700; }
.msg-date { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.msg-subject { margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row.unread .msg-subject { font-weight: 600; }
/* A row paints from its cleartext columns the moment the folder loads; its
   sealed subject arrives a beat later. Until then, a quiet bar — the row is
   already real and clickable, so this must read as "loading", not as damage.
   Deliberately understated: at 537k rows a shimmering list is a strobe. */
.msg-subject.sealed { display: flex; align-items: center; height: 1.2em; }
.msg-subject.sealed .skel {
  display: block; width: 46%; max-width: 240px; height: 9px; border-radius: 4px;
  background: light-dark(rgba(0,0,0,.09), rgba(255,255,255,.11));
  animation: skel-pulse 1.6s ease-in-out infinite;
}
@keyframes skel-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .msg-subject.sealed .skel { animation: none; } }
.msg-snippet { color: var(--muted); font-size: 12px; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Screener rows carry an inline Let in / Block decision, centered beside the
   message so the choice reads as part of the row. */
.screener-row { align-items: center; }
.screener-actions { display: flex; gap: 6px; flex-shrink: 0; }
/* Empty states: vertically centered in their column, so the two line up. */
.empty, .reading-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}
.empty .icon, .reading-empty .icon { font-size: 34px; opacity: 0.4; }

/* --- reading pane --- */
/* Same surface as the list — the reading pane is where you read, so it gets
   the clean panel background, not the app's grey chrome colour. */
.reading { overflow-y: auto; background: var(--panel); display: flex; flex-direction: column; }
/* A sticky action bar, Mimestream-style — actions stay reachable while reading. */
.read-toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 6px;
  padding: 10px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--panel); /* solid fallback where color-mix/backdrop aren't supported */
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  backdrop-filter: saturate(1.4) blur(8px);
}
.toolbar-spacer { flex: 1; }
.read-head { padding: 22px 26px 8px; }
/* subject left, trust pill top-right of the pane */
.read-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.read-top .trust-pill { flex-shrink: 0; margin-top: 3px; }
.read-subject { margin: 0; font-size: 23px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
.sender-row { display: flex; align-items: center; gap: 12px; }
.sender-meta { flex: 1; min-width: 0; }
.sender-line { display: flex; align-items: baseline; gap: 10px; }
.sender-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-name strong { font-weight: 600; }
.sender-date { margin-left: auto; color: var(--muted); font-size: 12px; flex-shrink: 0; }
.sender-sub { color: var(--muted); font-size: 13px; margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* keymail's signature: a calm trust badge in plain words, never "crypto". */
.trust-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.trust-pill.ok  { color: var(--ok);  background: color-mix(in srgb, var(--ok) 14%, transparent); }
.trust-pill.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
/* Imported mail: neutral — the owner vouched for the upload, nobody for the sender. */
.trust-pill.imported { color: var(--muted); background: color-mix(in srgb, var(--muted) 14%, transparent); }
.msg-more { display: block; width: 100%; text-align: center; padding: 10px; }

.read-body {
  padding: 8px 26px 40px;
  max-width: 720px;
  line-height: 1.6;
  font-size: 14.5px;
}
.read-body .body-line { white-space: pre-wrap; word-wrap: break-word; min-height: 1.6em; }
.body-link { color: var(--accent); text-decoration: none; word-break: break-word; }
.body-link:hover { text-decoration: underline; }
.body-quote {
  margin: 4px 0; padding: 2px 0 2px 14px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}
.body-quote .body-quote { border-left-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

/* --- outbox --- */
.outbox-row { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.outbox-state { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.state-mining .outbox-state { color: var(--warn); }
.state-failed .outbox-state { color: var(--bad); }
.mine-info { margin-top: 6px; font-size: 13px; }
.mine-bar {
  margin-top: 6px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.mine-fill {
  height: 100%;
  background: var(--warn);
  transition: width 0.5s linear;
}
.mine-note { font-size: 12px; margin-top: 4px; }
.outbox-error { color: var(--bad); font-size: 13px; margin-top: 6px; }

/* --- panels (senders, settings) --- */
.panel { max-width: 640px; padding: 24px; }
.panel h2 { margin-top: 0; }
.panel h3 { margin: 22px 0 6px; }
.senders-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.senders-table th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); padding: 6px 8px;
}
.senders-table td { padding: 8px; border-top: 1px solid var(--line); }
.sender-link { color: var(--accent); text-decoration: none; }
.sender-link:hover { text-decoration: underline; }
.btn.btn-icon { padding: 5px 9px; border: none; background: transparent; color: var(--muted); }
.btn.btn-icon:hover { background: var(--panel-2); color: var(--text); }

/* contact typeahead — appears only once you type */
.typeahead-wrap { position: relative; }
.typeahead {
  position: absolute; left: 0; right: 0; top: calc(100% + 3px); z-index: 6;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); overflow: hidden; max-height: 220px; overflow-y: auto;
}
.typeahead-item { padding: 8px 12px; cursor: pointer; font-size: 14px; }
.typeahead-item:hover, .typeahead-item.on { background: var(--accent-soft); color: var(--accent); }

/* keyboard shortcuts help (?) */
.shortcuts-modal { width: min(420px, 92vw); }
.shortcuts-grid { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; align-items: center; margin-top: 10px; }
kbd {
  font-family: var(--mono); font-size: 12px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px;
  justify-self: start; white-space: nowrap; color: var(--text);
}

/* --- contacts --- */
.contact-row { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.contact-row:hover { background: var(--panel-2); }
.contact-main { flex: 1; min-width: 0; }
.contact-addr { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-addr strong { font-weight: 600; }
.contact-count { font-size: 12px; }
.contact-write { color: var(--muted); opacity: 0; }
.contact-row:hover .contact-write { opacity: 1; }
.sender-actions { display: flex; gap: 6px; justify-content: flex-end; }
.state-pill {
  padding: 2px 10px; border-radius: 10px; font-size: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.state-pill.state-trusted { color: var(--ok); border-color: var(--ok); }
.state-pill.state-proven { color: var(--accent); border-color: var(--accent); }
.state-pill.state-blocked { color: var(--bad); border-color: var(--bad); }
.state-pill.state-screening { color: var(--muted); border-color: var(--muted); }
.pretrust { display: flex; gap: 8px; margin-top: 14px; }
.pow-slider { width: 100%; margin: 10px 0 6px; accent-color: var(--accent); }
.pow-readout { margin-bottom: 8px; }
.toggle-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; font-size: 14px; cursor: pointer; }
.toggle-row input { cursor: pointer; accent-color: var(--accent); flex-shrink: 0; }
select.text-input { max-width: 380px; cursor: pointer; }
.sub-setting { margin: 8px 0 4px; display: flex; flex-direction: column; gap: 4px; }
.sub-setting select { max-width: 300px; }
.sub-setting[hidden] { display: none; }
.dns-rec { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; overflow-x: auto; }

/* --- buttons, inputs --- */
.btn {
  font: inherit;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: var(--panel-2); }
/* Text flips dark on the light periwinkle accent used in dark mode — white on
   white-ish read as low-contrast on the Compose button. */
.btn.primary { background: var(--accent); border-color: var(--accent); color: light-dark(#fff, #16181d); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
/* ghost: a borderless toolbar button that only fills in on hover */
.btn.ghost { border-color: transparent; background: transparent; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.ghost.danger:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.text-input {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
.text-input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--bad); }

/* --- compose modal --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}
.modal {
  width: min(680px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  display: flex; flex-direction: column; gap: 6px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal label { font-size: 12px; color: var(--muted); margin-top: 6px; }
/* To-line: label left, the Cc/Bcc reveal right. The reveal is a real button
   (keyboard focusable), just styled down to a quiet text link. */
.to-row { display: flex; align-items: baseline; justify-content: space-between; }
.to-row .ccbcc-toggle { font-size: 12px; padding: 2px 6px; }
.compose-body { font: inherit; resize: vertical; }
textarea.compose-body {
  width: 100%; padding: 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
  line-height: 1.5;
}
.compose-price { font-size: 13px; min-height: 18px; margin-top: 6px; }
.compose-status { flex: 1; font-size: 13px; color: var(--warn); }
.modal-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.attach-btn { padding: 6px 9px; color: var(--muted); }
.attach-btn:hover { color: var(--text); }

/* --- attachments: compose chips --- */
.attach-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attach-chips:empty, .attach-chips[hidden] { display: none; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 8px 6px 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; font-size: 13px; max-width: 260px;
}
.attach-chip .icon { color: var(--accent); flex-shrink: 0; }
.attach-chip.uploading .icon { color: var(--muted); }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-size { flex-shrink: 0; font-size: 12px; }
.attach-x {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; padding: 2px; border-radius: 50%; font-size: 14px;
}
.attach-x:hover { background: var(--line); color: var(--text); }

/* --- attachments: reader gallery --- */
.attachments { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px 26px 32px; }
.att-figure {
  margin: 0; position: relative; cursor: pointer;
  border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); background: var(--panel-2);
  max-width: 320px;
}
.att-img { display: block; max-width: 100%; max-height: 320px; object-fit: cover; }
.att-img.att-blur { filter: blur(8px); transform: scale(1.04); }
.att-figure:hover { filter: brightness(0.97); }
.att-video .att-play {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-size: 34px; text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.att-video .att-dur {
  position: absolute; right: 8px; bottom: 8px;
  background: rgba(0,0,0,0.65); color: #fff;
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
}
.att-file {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2);
  text-decoration: none; color: var(--text); max-width: 320px;
}
.att-file:hover { background: var(--panel); border-color: var(--accent); }
.att-file-icon { color: var(--accent); font-size: 20px; flex-shrink: 0; }
.att-file-main { display: flex; flex-direction: column; min-width: 0; }
.att-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file-size { font-size: 12px; }
.att-dl { color: var(--muted); margin-left: auto; flex-shrink: 0; }
.att-file.loading .att-dl { animation: km-spin 0.7s linear infinite; }

/* --- lightbox --- */
.lightbox {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; cursor: zoom-out;
}
.lb-media { max-width: 96vw; max-height: 92vh; border-radius: 8px; }

/* --- rich-text editor (compose) --- */
.compose-editor { display: flex; flex-direction: column; }
.rt-toolbar {
  display: flex; flex-wrap: wrap; gap: 2px; align-items: center;
  padding: 4px; border: 1px solid var(--line); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0; background: var(--panel-2);
}
.rt-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 8px;
  border: none; background: transparent; color: var(--text);
  border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px;
}
.rt-btn .icon { font-size: 16px; }
.rt-btn:hover { background: var(--line); }
.rt-btn.on { background: var(--accent-soft); color: var(--accent); }
.rt-linkbar { display: inline-flex; gap: 4px; align-items: center; margin-left: 4px; }
.rt-linkinput {
  font: inherit; font-size: 13px; padding: 4px 8px; width: 200px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--text);
}
.rt-editor {
  border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius);
  background: var(--panel); padding: 10px 12px; min-height: 180px;
  max-height: 46vh; overflow-y: auto;
}
.rt-editor .ProseMirror { outline: none; min-height: 158px; line-height: 1.55; }

/* --- rendered Markdown prose (reader .md-body + the editor share these) --- */
.md-body h2, .rt-editor .ProseMirror h2 { font-size: 19px; margin: 16px 0 6px; font-weight: 650; }
.md-body h3, .rt-editor .ProseMirror h3 { font-size: 16px; margin: 12px 0 4px; font-weight: 650; }
.md-body p, .rt-editor .ProseMirror p { margin: 0 0 10px; }
.md-body ul, .md-body ol, .rt-editor .ProseMirror ul, .rt-editor .ProseMirror ol { margin: 0 0 10px; padding-left: 24px; }
.md-body li, .rt-editor .ProseMirror li { margin: 2px 0; }
.md-body blockquote, .rt-editor .ProseMirror blockquote {
  margin: 6px 0; padding: 0 0 0 14px; border-left: 3px solid var(--line); color: var(--muted);
}
/* Keep the left bar the height of the quoted text: the inner paragraphs' own
   margins would otherwise stretch the blockquote (and its border) past the line. */
.md-body blockquote p, .rt-editor .ProseMirror blockquote p { margin: 0; }
.md-body code, .rt-editor .ProseMirror code {
  font-family: var(--mono); font-size: 0.92em;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px;
}
.md-body pre, .rt-editor .ProseMirror pre {
  font-family: var(--mono); font-size: 13px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; line-height: 1.45;
}
.md-body pre code, .rt-editor .ProseMirror pre code { background: none; border: none; padding: 0; }
.md-body a { color: var(--accent); }

/* --- conversation (thread) view --- */
.thread-count {
  display: inline-block; margin-left: 6px;
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 0 6px; line-height: 16px;
}
.conversation { padding-bottom: 32px; }
.conv-msg { border-top: 1px solid var(--line); padding: 16px 26px 4px; }
.conv-msg:first-child { border-top: none; }
.conv-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.conv-head.open { cursor: pointer; }
.conv-head.open:hover .conv-name { color: var(--accent); }
.conv-meta { flex: 1; min-width: 0; }
.conv-line { display: flex; align-items: baseline; gap: 10px; }
.conv-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-name strong { font-weight: 600; }
.conv-date { margin-left: auto; color: var(--muted); font-size: 12px; flex-shrink: 0; }
.conv-sub { color: var(--muted); font-size: 12px; }
.conv-body .read-body, .conv-body .md-body { padding: 4px 0 6px; max-width: none; }
.conv-body .attachments { padding: 4px 0 8px; }
/* collapsed (older) messages: a one-line summary */
.conv-msg.collapsed { padding: 0; }
.conv-summary { display: flex; align-items: center; gap: 12px; padding: 10px 26px; cursor: pointer; }
.conv-summary:hover { background: var(--panel-2); }
.conv-summary .avatar { width: 28px; height: 28px; font-size: 12px; }
.conv-sum-main { flex: 1; min-width: 0; display: flex; gap: 8px; overflow: hidden; }
.conv-sum-who { font-weight: 600; flex-shrink: 0; }
.conv-sum-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-reply { padding: 12px 26px 28px; }

/* --- signature block (distinct, so it's clear where a message ends) --- */
.sig-block {
  margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px; white-space: pre-wrap; line-height: 1.5;
}
.sig-block-solo { margin: 0 26px 32px; }
.sig-input {
  font: inherit; width: 100%; padding: 8px 10px; resize: vertical;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
}

/* --- claim page / locked --- */
.claim-body, #locked {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.claim-card {
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px 38px;
  text-align: center;
}
.claim-card h1 { letter-spacing: -0.02em; }
.claim-note { color: var(--muted); font-size: 13px; line-height: 1.5; }
/* Doorbell knock: the three step buttons sit in a row, wrapping on narrow
   screens; a disabled step is dimmed until its turn. */
.doorbell-steps { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0 4px; }
.doorbell-steps .btn:disabled { opacity: 0.45; cursor: default; }
.db-done { color: var(--ok); font-weight: 600; }
.claim-detail { color: var(--warn); font-size: 13px; margin: 8px 0; }
#claim-go { margin: 12px 0 6px; }
.claim-alt { margin: 0 0 12px; }
.locked-actions { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; align-items: center; }
.locked-actions .btn { min-width: 220px; }

/* --- import page --- */
.import-card { max-width: 520px; }
.import-title { font-size: 17px; margin: 4px 0 14px; }
.import-sub { font-size: 14px; margin: 22px 0 4px; text-align: left; }
.import-sub:first-child { margin-top: 0; }
#gmail-client-id { width: 100%; }
.import-pick { margin: 16px 0 10px; }
.import-pick input[type="file"] { font: inherit; color: var(--text); max-width: 100%; }
.import-actions { margin: 6px 0 12px; }
.import-fine { color: var(--muted); font-size: 12px; line-height: 1.5; }
.import-line { font-variant-numeric: tabular-nums; margin: 14px 0 8px; }
.import-bar {
  position: relative;
  height: 8px; border-radius: 4px; background: var(--panel-2);
  border: 1px solid var(--line); overflow: hidden; margin-bottom: 16px;
}
.import-bar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }
.import-error { color: var(--bad); font-size: 13px; line-height: 1.5; }

/* --- the consolidated import progress card --- */
.imp-source { color: var(--muted); font-size: 13px; margin: 18px 0 4px; }
.imp-count { font-variant-numeric: tabular-nums; margin-bottom: 10px; }
.imp-big { font-size: 32px; font-weight: 650; letter-spacing: -0.01em; color: var(--accent); }
.imp-of { font-size: 15px; color: var(--muted); margin-left: 6px; }
.imp-bar-tall { height: 10px; margin-bottom: 12px; }
/* layered pipeline bar: pale = fetched from the source, solid = sealed here */
.import-bar-lead, .imp-bar-tall .import-bar-fill {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0;
  transition: width 0.25s linear;
}
.import-bar-lead { background: var(--accent-soft); }
.imp-bar-tall .import-bar-fill { background: var(--accent); }
.imp-forecast {
  display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
  color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums;
  min-height: 1.3em; margin-bottom: 12px;
}
.imp-breakdown {
  display: flex; flex-wrap: wrap; gap: 4px 18px; justify-content: center;
  font-size: 13px; font-variant-numeric: tabular-nums; margin-bottom: 4px;
}
.imp-fail { color: var(--bad); }
.imp-notice {
  text-align: left; font-size: 13px; line-height: 1.55;
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 10px 14px; margin-top: 18px;
}
.imp-offload { font-size: 13px; }
.imp-consent {
  text-align: left; font-size: 14px; line-height: 1.55;
  border: 1px solid var(--bad); border-radius: 8px;
  padding: 4px 16px 12px; margin-top: 12px;
}
.imp-consent .import-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- oauth consent (/oauth/authorize) --- */
.oauth-card { max-width: 430px; }
.oauth-grant { text-align: left; font-size: 14px; line-height: 1.55; }
.oauth-as { color: var(--muted); }
.oauth-scopes { margin: 10px 0; padding-left: 22px; }
.oauth-scopes li { margin: 6px 0; }
.oauth-cannot { color: var(--muted); font-size: 13px; }
.oauth-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.oauth-signin { display: inline-block; margin: 10px 8px 0 0; }

/* --- home / passkey sign-in --- */
.home-card { max-width: 430px; }
.home-tagline { color: var(--muted); margin: 8px 0 20px; line-height: 1.5; }
.home-name { display: flex; align-items: baseline; gap: 2px; justify-content: center; margin-bottom: 16px; }
.home-name .text-input { text-align: right; max-width: 170px; }
.home-at { color: var(--muted); }
.home-actions { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.home-btn { min-width: 260px; }
.home-status { min-height: 1.2em; color: var(--muted); font-size: 13px; margin: 14px 0 4px; }
.home-status.error { color: var(--bad); }
.home-hint { display: block; margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: left; }
.home-hint > span { display: block; margin-top: 6px; }
.home-switch { color: var(--muted); font-size: 13px; margin-top: 20px; }
.home-link { color: var(--accent); text-decoration: none; font-weight: 600; }
.home-link:hover { text-decoration: underline; }

/* --- toast --- */
#toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 30;
}

/* --- undo send bar (bottom-left) --- */
#undo-bar {
  position: fixed;
  left: 22px; bottom: 22px;
  display: flex; align-items: center; gap: 12px;
  background: var(--text); color: var(--bg);
  padding: 9px 10px 9px 14px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 30;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.28);
  animation: undo-in 0.24s ease-out;
}
@keyframes undo-in { from { transform: translateY(14px); opacity: 0; } }
#undo-bar .icon { font-size: 16px; opacity: 0.85; }
.undo-msg { white-space: nowrap; }
.undo-track { width: 84px; height: 4px; background: rgba(255, 255, 255, 0.22); border-radius: 2px; overflow: hidden; }
.undo-fill { height: 100%; width: 0; background: var(--bg); }
.undo-btn.btn { background: transparent; border: none; color: #a9b6ff; font-weight: 700; padding: 4px 8px; }
.undo-btn.btn:hover { background: rgba(255, 255, 255, 0.12); }

/* --- mobile controls (hidden on desktop; the media query below turns them on) --- */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: none; background: transparent;
  color: var(--text); border-radius: 8px; cursor: pointer; font-size: 20px;
}
.icon-btn:hover { background: var(--panel-2); }
/* .btn.read-back needs two classes: .btn.ghost's display would outrank a
   lone .read-back and leak the mobile back button onto desktop. */
.nav-toggle, .btn.read-back, .fab, .nav-backdrop { display: none; }

/* --- mobile: one pane at a time, a drawer for nav, a compose FAB --- */
@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .search-wrap { display: none; } /* reclaim width; a mobile search is a later pass */
  #me-addr { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-toggle { display: inline-flex; }

  .layout, .layout.wide { grid-template-columns: 1fr; position: relative; }

  /* sidebar → slide-in drawer */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: 264px; z-index: 45;
    background: var(--panel); border-right: 1px solid var(--line);
    transform: translateX(-100%); transition: transform 0.22s ease; padding-top: 14px;
  }
  .layout.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.3); }
  .layout.nav-open .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 44; background: rgba(0, 0, 0, 0.4);
  }
  .sidebar-foot { display: block; }
  .nav-item { font-size: 15px; padding: 10px 12px; }

  /* list fills the screen; the reading pane slides over it */
  .list { border-right: none; }
  .reading {
    position: absolute; inset: 0; z-index: 30; background: var(--panel);
    transform: translateX(100%); transition: transform 0.2s ease;
  }
  .layout.reading-open .reading { transform: none; }
  .btn.read-back { display: inline-flex; }
  .read-toolbar { padding: 8px 10px; }
  .read-head { padding: 16px 16px 6px; }
  .read-subject { font-size: 20px; }
  .read-body, .attachments { padding-left: 16px; padding-right: 16px; }
  .msg-row { padding: 12px 14px; }

  /* floating compose button */
  .fab {
    display: inline-flex; align-items: center; justify-content: center;
    position: fixed; right: 18px; bottom: 20px; z-index: 35;
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--accent); color: light-dark(#fff, #16181d); border: none;
    font-size: 22px; cursor: pointer; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.32);
  }
  .layout.reading-open ~ .fab, .layout.nav-open ~ .fab { display: none; }

  /* full-screen compose sheet — above the reading pane (30) and FAB (35),
     which otherwise paint over a Reply opened from a thread */
  .modal-backdrop { padding: 0; z-index: 38; }
  .modal { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  textarea.compose-body { flex: 1; min-height: 36vh; }
  /* iOS Safari auto-zooms (and stays zoomed) when a focused field is under
     16px — keep every text field at 16px so focus never zooms. The class
     selectors out-rank the fields' own `font: inherit` / sized rules. */
  input, textarea, .text-input, .compose-body, .rt-editor, .rt-linkinput,
  .sig-input { font-size: 16px; }
  .lb-media { max-width: 100vw; max-height: 100dvh; border-radius: 0; }

  /* undo-send bar: full width with a margin instead of running off-screen;
     the address and the word "send" drop so nothing wraps, the progress
     track stretches, and the FAB yields while the bar is up */
  #undo-bar { left: 14px; right: 14px; bottom: 14px; }
  .undo-track { flex: 1; width: auto; }
  .undo-addr, .undo-send-word { display: none; }
  body:has(#undo-bar:not([hidden])) .fab { display: none; }

  /* bulk-action bar: icon-only buttons (title tooltips keep the labels) and
     a bare count, so select-all + actions + × hold one row without wrapping */
  .bulk-bar { flex-wrap: nowrap; }
  .bulk-label, .bulk-count-word { display: none; }
}

/* --- docs page --- */
.doc-body { background: var(--bg); }
.doc-top {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.doc-top .wordmark { text-decoration: none; color: var(--text); }
.doc-top-label { color: var(--muted); font-weight: 600; }
.doc-top-link { margin-left: auto; color: var(--accent); text-decoration: none; font-weight: 600; }
.doc { max-width: 760px; margin: 0 auto; padding: 8px 24px 80px; line-height: 1.6; }
.doc-toc { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.doc-toc a { color: var(--muted); text-decoration: none; font-size: 13px; }
.doc-toc a:hover { color: var(--accent); }
.doc section { padding: 22px 0; border-bottom: 1px solid var(--line); }
.doc section:last-of-type { border-bottom: none; }
.doc h1 { font-size: 26px; letter-spacing: -0.02em; margin: 0 0 12px; }
.doc h2 { font-size: 19px; margin: 4px 0 10px; }
.doc-lead { font-size: 16px; }
.doc p { margin: 0 0 12px; }
.doc ul, .doc ol { margin: 0 0 12px; padding-left: 22px; }
.doc li { margin: 5px 0; }
.doc code { font-family: var(--mono); font-size: 0.9em; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.doc-dns { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; margin: 0 0 12px; }
.doc-dns code { background: none; border: none; padding: 0; font-size: 12.5px; line-height: 1.7; white-space: pre; color: var(--text); }
.doc-note { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; font-size: 14px; }
.doc-keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 16px; margin: 8px 0; font-size: 14px; }
.doc-keys kbd { margin-right: 4px; }
.doc-foot { padding: 24px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.doc-foot a { color: var(--accent); text-decoration: none; }

/* /link — device-link handoff page (linkdevice.js) */
.link-code-wrap { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 4px; }
.link-code { font-family: var(--mono); font-size: 11.5px; line-height: 1.5; word-break: break-all; resize: none; width: 100%; box-sizing: border-box; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
