/* 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; }
/* min-width: 0 lets a long bold label ("Newsletters") shrink and ellipsize
   instead of shoving its badge out of line with the others. */
.nav-item .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .badge { flex-shrink: 0; min-width: 18px; text-align: center; }
.nav-item:hover { background: var(--panel-2); }
.nav-item.has-mail .nav-label { font-weight: 600; }
.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 (the count and its menu, or the bulk-action
   bar), and a per-row checkbox that borrows the avatar's slot instead of
   reserving one of its own. */
.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; }
/* The count doubles as a menu button — the only way into selecting on a touch
   screen, where no row is ever hovered. It has to still read as a quiet count,
   so: no border, no fill, just a caret and a hover tint. */
.count-menu-wrap { position: relative; display: inline-flex; }
/* Styled standalone rather than by borrowing .list-total: that class is reset
   inside .list-head at a specificity this rule can't beat, so sharing it would
   silently lose the padding the hover tint needs and the 11px count size. */
.count-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 5px; margin: -2px -5px;
  border: 0; border-radius: 5px;
  background: none;
  font-family: inherit; font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}
.count-btn:hover { background: var(--line); color: var(--text); }
.count-btn .icon svg { width: 12px; height: 12px; }
.count-menu {
  position: absolute;
  top: calc(100% + 6px); left: -4px;
  min-width: 170px;
  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;
}
/* 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); }
/* One line, always. The list pane is never wider than 420px, and four
   word-labelled buttons plus the count and the ✕ overflow that — which wrapped
   the bar onto a second row and grew the header by 30px the instant you started
   selecting, shoving every row down under the pointer. So the actions are
   icon-only here (aria-label + title carry the words) and the bar never wraps. */
.bulk-bar { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: nowrap; }
.bulk-label { display: none; }
/* Sits in the avatar column so it lines up with the row checkboxes below it:
   16px box, centred under the 36px disc by the extra 10px of left margin. */
.sel-all { width: 16px; height: 16px; margin: 0 2px 0 10px; cursor: pointer; }
.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); }
/* The avatar IS the checkbox. .pick-box stacks over the disc in the same 36px
   slot, so a list nobody is selecting reserves no gutter at all and revealing a
   checkbox moves nothing. It covers the disc rather than replacing it — swapping
   the node would reflow the row under the pointer mid-click. */
.row-pick { position: relative; display: inline-flex; flex-shrink: 0; }
.pick-box {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--line);
}
.pick-box input { cursor: pointer; margin: 0; width: 16px; height: 16px; }
/* A ticked row is tinted, so the disc-cover takes the tint too — left white it
   reads as a hole punched in the row rather than a checkbox sitting on it. */
.msg-row.sel .pick-box { background: var(--accent-soft); }
/* Shown while selecting, on a ticked row, and — pointers that hover only — on
   the row under the cursor. Touch has no hover to trust here: a sticky :hover
   would strand a checkbox over one avatar after a tap. */
.list.selecting .pick-box, .row-pick.on .pick-box { display: flex; }
@media (hover: hover) {
  .msg-row:hover .pick-box { display: flex; }
}
/* While selecting, a click is a tick — so don't let a quick double-click or a
   Shift-click drag a text selection across the rows. */
.list.selecting .msg-row { user-select: none; }
.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; }

/* "Let in" is a split button: the face is one click to the Inbox (today's
   behaviour), the caret opens the destinations and the domain-wide checkbox. */
.dest-split { position: relative; display: inline-flex; }
.dest-split .dest-main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.dest-split .dest-caret {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  margin-left: -1px; padding-inline: 8px;
}
.dest-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  min-width: 15rem; padding: 4px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.dest-item {
  text-align: left; padding: 7px 10px; background: none; border: 0;
  border-radius: calc(var(--radius) - 4px); color: var(--text);
  font: inherit; cursor: pointer;
}
.dest-item:hover { background: var(--panel-2); }
.dest-sep { height: 1px; margin: 4px 0; background: var(--line); }
.dest-wide {
  display: flex; align-items: center; gap: 6px; padding: 7px 10px;
  font-size: 0.85em; color: var(--muted); cursor: pointer;
}
/* The single-use-link offer, above the body it was detected in. Quiet: it is
   a suggestion, not a warning. */
/* The offer sits between the header and the body, so it lines up with them:
   the solo reading pane insets those with padding, a conversation card with
   .conv-msg's own padding — hence the margin here and the reset below. */
.onetime-offer {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 26px 14px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 0.9em;
}
.conv-body .onetime-offer { margin-left: 0; margin-right: 0; }
.onetime-text { flex: 1 1 12rem; color: var(--muted); }
.toast-undo { margin-left: 12px; }

/* The backlog sweep shows what it will bin before it bins it. */
.sweep-list {
  max-height: 40vh; overflow-y: auto; margin: 10px 0;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.sweep-item {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 14px; padding: 7px 10px; font-size: 0.9em;
}
.sweep-item + .sweep-item { border-top: 1px solid var(--line); }
.sweep-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sweep-from { color: var(--muted); flex-shrink: 0; font-size: 0.9em; }

.dest-select { font: inherit; font-size: 0.9em; padding: 2px 4px; }
.rule-scope { color: var(--muted); }
.domain-rule .rule-scope { font-style: italic; }
.state-pill.state-none { color: var(--muted); }
/* 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-sheet { 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; }
.contact-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.contact-help { font-size: 13px; margin: 0 0 12px; }
.contact-section { font-size: 13px; font-weight: 600; color: var(--muted); margin: 20px 0 4px; }
.contact-form { display: flex; flex-direction: column; gap: 10px; padding: 16px; margin: 8px 0 16px; border: 1px solid var(--line); border-radius: 10px; }
.contact-form h3 { margin: 0; }
.contact-field { display: flex; flex-direction: column; gap: 4px; }
.contact-field .text-input { max-width: none; }
.contact-field textarea { resize: vertical; font: inherit; }
.contact-actions { display: flex; gap: 8px; }
.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 sheet --- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}
.sheet {
  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;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet 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; }
/* The compose sheet gets room to write: wider, nearly full height, with the
   editor taking whatever the fields and footer leave rather than a fixed box. */
.sheet.compose-sheet {
  width: min(860px, 94vw); height: min(92vh, 1000px); max-height: 92vh;
  padding: 26px 32px 22px; gap: 4px;
}
.compose-sheet .sheet-head { margin-bottom: 6px; }
.compose-sheet .sheet-head h2 { font-size: 19px; }
.compose-sheet label { margin: 12px 0 4px; font-size: 12.5px; }
.compose-sheet .text-input { padding: 10px 14px; }
.compose-sheet .compose-editor { flex: 1; min-height: 240px; }
.compose-sheet .rt-toolbar { padding: 5px 8px; }
.compose-sheet .rt-editor { flex: 1; max-height: none; padding: 16px 20px; }
.compose-sheet .rt-editor .ProseMirror { font-size: 16px; line-height: 1.5; }
/* Enter is a new line and Enter twice a paragraph (linebreak.js), so a
   paragraph gap is exactly one blank line — what the second Enter looks like. */
.compose-sheet .rt-editor .ProseMirror > p { margin: 0 0 1.5em; }
.compose-sheet .rt-editor .ProseMirror > p:last-child { margin-bottom: 0; }
.compose-sheet textarea.compose-body { flex: 1; }
.compose-sheet .sheet-foot { margin-top: 14px; }
.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); }
.sheet-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; }
/* Pictures in the text are the message's own files (inlineimages.js). */
.md-body img.inline-img, .rt-editor .ProseMirror img.inline-img { max-width: 100%; max-height: 60vh; height: auto; border-radius: 8px; vertical-align: bottom; }
.md-body img.inline-img { cursor: zoom-in; }
.rt-editor .ProseMirror img.ProseMirror-selectednode { outline: 2px solid var(--accent); outline-offset: 2px; }
.inline-img-missing { color: var(--muted); font-style: italic; }
.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);
}

/* --- auth surfaces: sign in / sign up (#locked), consent, claim, link,
   import, doorbell ---
   One look for every screen you meet before (or instead of) the inbox: a
   light-blue page under a soft glow and faint guilloché linework, one big
   soft card, Figtree, and the app icon's blue as the accent. Everything is
   scoped to .claim-body and #locked, so the signed-in inbox never changes.
   (Design: proto/auth/a2-hybrid.html. The linework is a static mask made by
   tools/guilloche.mjs; the CSP forbids inline style, so no JS draws it.) */
@font-face {
  font-family: "Figtree";
  src: url("vendor/figtree/figtree-latin-var.woff2") format("woff2");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
.claim-body, #locked {
  /* the app-wide tokens, re-pointed for these screens */
  --accent: light-dark(#245cc4, #6aa5f5);
  --accent-soft: light-dark(#e8f0fc, #1e2a3e);
  --panel: light-dark(#ffffff, #181c24);
  --panel-2: light-dark(#f4f7fc, #1d222c);
  --text: light-dark(#161a22, #e6e9ef);
  --muted: light-dark(#566072, #a0a8b6);
  --line: light-dark(#d6dde9, #333b4a);
  /* auth-only */
  --auth-page: light-dark(#edf2f9, #0d1117);
  --auth-hair: light-dark(#e6ebf3, #272d39);
  --auth-accent-hi: light-dark(#1d4fae, #8ab9f8);
  --auth-on-accent: light-dark(#ffffff, #071a3d);
  --auth-accent-ink: light-dark(#1a4796, #bcd6fd);
  --auth-glow: light-dark(rgb(67 141 240 / 0.22), rgb(67 141 240 / 0.16));
  --auth-glow-2: light-dark(rgb(67 141 240 / 0.12), rgb(67 141 240 / 0.08));
  --auth-ink: light-dark(rgb(36 92 196 / 0.14), rgb(106 165 245 / 0.13));
  --auth-ink-soft: light-dark(rgb(36 92 196 / 0.08), rgb(106 165 245 / 0.07));
  --auth-gx: 24vw; /* where the glow and the rosette's centre sit */
  --auth-gy: 34vh;
  --auth-radius: 28px;
  display: flex;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 40px 24px;
  font-family: "Figtree", var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.claim-body { background: var(--auth-page); } /* the canvas, for overscroll */
/* The ground: glow (::before) and guilloché (::after), fixed to the viewport
   and painted under everything. The linework is a mask over a radial wash of
   ink, so it fades out from the rosette's centre — a texture you notice
   second, never under text. */
.claim-body::before, #locked::before, .claim-body::after, #locked::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
.claim-body::before, #locked::before {
  background:
    radial-gradient(760px 560px at var(--auth-gx) var(--auth-gy), var(--auth-glow), transparent 70%),
    radial-gradient(640px 480px at calc(100vw - var(--auth-gx)) 92vh, var(--auth-glow-2), transparent 70%),
    var(--auth-page);
}
.claim-body::after, #locked::after {
  background: radial-gradient(circle 950px at var(--auth-gx) var(--auth-gy),
    var(--auth-ink) 17%, color-mix(in srgb, var(--auth-ink) 55%, transparent) 52%, transparent 95%);
  -webkit-mask-image: url("guilloche.svg");
  mask-image: url("guilloche.svg");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 1900px 1900px;
  mask-size: 1900px 1900px;
  -webkit-mask-position: calc(var(--auth-gx) - 950px) calc(var(--auth-gy) - 950px);
  mask-position: calc(var(--auth-gx) - 950px) calc(var(--auth-gy) - 950px);
}

/* the card: one column by default (claim, link, import, locked, doorbell) */
.claim-card {
  position: relative;
  isolation: isolate;
  width: min(520px, 100%);
  margin: auto; /* centres, and never clips a card taller than the screen */
  padding: 40px 44px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--panel);
  border-radius: var(--auth-radius);
  box-shadow: 0 1px 2px light-dark(rgb(23 26 35 / 0.05), rgb(0 0 0 / 0.4)),
    0 18px 48px -12px light-dark(rgb(36 92 196 / 0.16), rgb(0 0 0 / 0.5));
  text-align: left;
}
.claim-card h1, .claim-card h2, .claim-card > p, .auth-lead p, .auth-side p { margin: 0; }
.claim-card a:not(.btn) { color: var(--accent); font-weight: 600; text-decoration: none; }
.claim-card a:not(.btn):hover { text-decoration: underline; text-underline-offset: 3px; }
.claim-card :focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
/* two columns on a desktop: headline block left, form right (sign-in, consent) */
.claim-card.auth-split {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 64px;
  row-gap: 32px;
  padding: 44px 48px 40px;
}
.auth-lead, .auth-side { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.auth-side { gap: 16px; justify-content: flex-end; }
.auth-split .auth-lead > .auth-brand { margin-bottom: auto; }
.oauth-card .auth-side { justify-content: flex-start; }

/* the brand lockup: logomark + wordmark. Go-templated pages (doorbell) still
   send a bare <h1>key<span>mail</span></h1> first; it gets the same look. */
.auth-brand, .claim-card > h1:first-child:not([class]) {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 40px;
  white-space: nowrap;
}
.claim-card > .auth-brand:first-child, .claim-card > h1:first-child:not([class]) { margin-bottom: 8px; }
/* the one place the logomark is referenced */
.auth-brand::before, .claim-card > h1:first-child:not([class])::before, .oauth-tile-km {
  content: "";
  width: 40px;
  height: 40px;
  flex: none;
  background: url("logomark.svg") center / contain no-repeat;
}
.auth-brand::before, .claim-card > h1:first-child:not([class])::before {
  display: inline-block;
  vertical-align: middle;
  margin: -4px 10px 0 0;
}
.claim-card .wordmark-accent { color: var(--accent); }

.auth-title { font-size: 44px; line-height: 1.08; font-weight: 600; letter-spacing: -0.035em; text-wrap: balance; }
.claim-card:not(.auth-split) .auth-title { font-size: 28px; line-height: 1.15; letter-spacing: -0.03em; }
.claim-card .auth-title.error { font-size: 18px; line-height: 1.45; font-weight: 500; letter-spacing: 0; }
.auth-sub { font-size: 17px; color: var(--muted); max-width: 34ch; text-wrap: balance; }
.auth-lead .auth-title + .auth-sub { margin-top: -6px; }
.auth-nb { white-space: nowrap; }
/* the first line after the brand reads as the card's headline */
.claim-card > .auth-brand:first-child + p, .claim-card > h1:first-child:not([class]) + p {
  font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: -0.015em;
}
.claim-note { color: var(--muted); font-size: 14px; line-height: 1.5; }
.claim-detail { color: var(--warn); font-size: 14px; }
.claim-detail:empty { display: none; }
/* The download page behind a private file link (filelink.js). */
.file-detail { font-size: 15px; overflow-wrap: anywhere; }
.file-detail:empty { display: none; }
.file-preview { display: block; max-width: 100%; max-height: 50vh; margin-top: 12px; border-radius: 10px; }

/* buttons: pills. Primary is the icon's blue; the rest a pale tint. */
.claim-card .btn {
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--auth-accent-ink);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: background-color 0.15s;
}
.claim-card .btn:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent)); }
.claim-card .btn.primary { background: var(--accent); color: var(--auth-on-accent); filter: none; }
.claim-card .btn.primary:hover { background: var(--auth-accent-hi); }
.claim-card .btn.ghost { background: transparent; }
.claim-card .btn.danger { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.claim-card .btn .icon { font-size: 20px; }
.claim-card .btn:disabled { opacity: 0.5; cursor: default; }
.claim-card .btn.is-busy:disabled {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 16%, var(--panel));
  color: var(--auth-accent-ink);
}
.auth-block { width: 100%; min-height: 52px; font-size: 16px; }
.claim-card .text-input { border-radius: 12px; padding: 10px 14px; }

/* the name field on sign-up: "you" grows as you type, "@host" follows it */
.auth-field {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 0 18px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  font-size: 17px;
  cursor: text;
}
.auth-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.auth-field input {
  flex: 0 1 auto;
  width: 3.2ch;
  min-width: 0;
  padding: 14px 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 17px; /* at least 16px, so iOS never zooms on focus */
  color: var(--text);
}
.auth-field input:focus-visible { outline: none; } /* the field's own ring shows focus */
.auth-field input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.auth-field .home-at { flex: 1; color: var(--muted); font-weight: 500; white-space: nowrap; }
.auth-field-mirror { position: absolute; visibility: hidden; white-space: pre; font: inherit; font-size: 17px; }

/* sign in / sign up (home.js) */
.home-status { margin: 0; color: var(--muted); font-size: 14px; }
.home-status:empty { display: none; }
.home-status.error { color: var(--bad); }
.home-hint { display: block; margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.home-hint > span { display: block; margin-top: 6px; }
.home-switch { margin: 0; text-align: center; color: var(--muted); }
.locked-actions { display: flex; flex-direction: column; gap: 8px; }
.locked-actions:empty { display: none; }

/* consent (/oauth/authorize: oauthpage.js + oauthcard.js) */
.oauth-connect { display: flex; align-items: center; }
.oauth-tile { width: 56px; height: 56px; border-radius: 22.5%; display: grid; place-items: center; flex: none; }
.oauth-tile-client {
  background: light-dark(#1d2230, #eceef5);
  color: light-dark(#ffffff, #1d2230);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.oauth-link { display: flex; align-items: center; gap: 6px; padding: 0 8px; }
.oauth-dots {
  width: 22px;
  height: 2px;
  background: radial-gradient(circle, var(--line) 1.2px, transparent 1.4px) center / 6px 2px repeat-x;
}
.oauth-lock {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 15px;
}
.oauth-as { display: flex; flex-direction: column; gap: 10px; }
.oauth-as-label { color: var(--muted); font-size: 14px; }
.oauth-as-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; }
/* "Use a different inbox" signs in right here (a button), but reads as a link */
.oauth-other {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--accent);
  background: none; border: 0; padding: 0; cursor: pointer;
}
.oauth-other:hover { text-decoration: underline; text-underline-offset: 3px; }
.oauth-other:disabled { opacity: 0.5; cursor: default; }
.oauth-chip {
  display: inline-flex; align-items: center; gap: 10px;
  max-width: 100%; min-width: 0;
  padding: 5px 16px 5px 5px;
  border: 1px solid var(--line); border-radius: 999px;
  font-weight: 600;
}
.oauth-chip strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.oauth-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: var(--auth-on-accent);
  font-size: 14px; font-weight: 700;
}
.oauth-account { min-width: 0; max-width: 100%; padding: 2px 0; border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.oauth-scopes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.oauth-scopes li { display: flex; align-items: flex-start; gap: 14px; font-size: 16px; line-height: 1.4; }
.oauth-scope-icon {
  width: 36px; height: 36px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 18px;
}
.oauth-scope-text { padding-top: 7px; }
.oauth-cannot {
  display: flex; align-items: flex-start; gap: 12px;
  margin: 0; padding: 14px 16px;
  border: 1px solid var(--auth-hair); border-radius: 16px;
  background: var(--panel-2);
  font-size: 14px; line-height: 1.45;
}
.oauth-cannot .icon { font-size: 20px; color: var(--ok); margin-top: 1px; }
.oauth-card .import-error { margin: 0; }
/* the footer row: the passkey line, then Cancel / Allow */
.auth-foot {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--auth-hair);
}
/* The step-up ask reads as a requirement, not a footnote: this card is about
   to demand a passkey touch, and burying it in muted grey would make the
   authenticator prompt look like it came from nowhere. */
.oauth-stepup { flex: 1; display: flex; align-items: center; gap: 10px; margin: 0; font-size: 14px; font-weight: 500; }
.oauth-stepup .icon { font-size: 18px; color: var(--accent); }
.oauth-actions { display: flex; gap: 12px; flex: none; }
.oauth-actions .btn { min-width: 132px; min-height: 52px; font-size: 16px; }
.oauth-actions .btn.primary { min-width: 164px; }
.oauth-card.is-grant > .claim-note { display: none; } /* the "cannot" note says it */
#oauth-consent:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  .claim-card .icon.spin svg { animation: auth-pulse 1.6s ease-in-out infinite; }
}
@keyframes auth-pulse { 50% { opacity: 0.35; } }

/* phone: the card fills the screen; the glow and linework show in the thin
   margin and, faintly, inside the card's top edge behind the logo. */
@media (max-width: 760px) {
  .claim-body, #locked { padding: 8px; --auth-gx: 18vw; --auth-gy: 6vh; }
  .claim-card, .claim-card.auth-split {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: calc(100dvh - 16px);
    margin: 0;
    padding: 28px 22px 22px;
    gap: 20px;
  }
  .claim-card::before, .claim-card::after {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 150px;
    z-index: -1;
    border-radius: var(--auth-radius) var(--auth-radius) 0 0;
    pointer-events: none;
  }
  .claim-card::before { height: 300px; background: radial-gradient(360px 240px at 48px 44px, var(--auth-glow-2), transparent 70%); }
  .claim-card::after {
    background: linear-gradient(var(--auth-ink-soft) 15%, transparent);
    -webkit-mask-image: url("guilloche.svg");
    mask-image: url("guilloche.svg");
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-size: 1100px 1100px;
    mask-size: 1100px 1100px;
    -webkit-mask-position: -502px -506px; /* rosette centre behind the logo */
    mask-position: -502px -506px;
  }
  .auth-title { font-size: 32px; }
  .home-card .auth-title { font-size: 42px; line-height: 1.04; }
  .home-card .auth-lead > .auth-brand { margin-bottom: 36px; }
  .home-card .auth-lead { gap: 14px; }
  .auth-side { flex: 1; }
  .auth-brand::before, .claim-card > h1:first-child:not([class])::before { width: 36px; height: 36px; }
  .auth-brand, .claim-card > h1:first-child:not([class]) { font-size: 21px; }

  .oauth-card.is-grant { gap: 22px; padding-top: 24px; }
  .oauth-card .auth-lead { gap: 18px; }
  .oauth-card .auth-title { font-size: 27px; line-height: 1.15; letter-spacing: -0.03em; }
  .oauth-card .auth-side { flex: none; gap: 18px; }
  .oauth-tile { width: 50px; height: 50px; }
  .oauth-tile-client { font-size: 19px; }
  .oauth-as { gap: 8px; }
  .oauth-scopes { gap: 12px; }
  .oauth-scopes li { font-size: 15px; gap: 12px; }
  .oauth-scope-icon { width: 32px; height: 32px; border-radius: 10px; font-size: 16px; }
  .oauth-scope-text { padding-top: 5px; }
  .oauth-cannot { font-size: 13.5px; padding: 12px 14px; gap: 10px; }
  .auth-foot {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 0 4px;
    background: var(--panel);
  }
  .oauth-stepup { font-size: 13px; align-items: flex-start; }
  .oauth-stepup .icon { margin-top: 1px; }
  .oauth-actions { flex-direction: column-reverse; gap: 8px; }
  .oauth-actions .btn { width: 100%; min-height: 50px; }
}


/* --- import page --- */
.import-card { width: min(560px, 100%); }
.import-title { font-size: 28px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.15; }
.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: flex-start; 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: flex-start;
  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-radius: 12px; padding: 12px 16px; 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; }



/* --- 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; }

  /* overflow: the reading pane waits off-screen right (translateX(100%)).
     Unclipped, it doubles the page width, and Android Chrome widens the
     layout viewport to match — carrying the fixed compose FAB off-screen on
     every view except Settings, where the pane is display:none. */
  .layout, .layout.wide { grid-template-columns: 1fr; position: relative; overflow: hidden; }

  /* 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; }
  .onetime-offer { margin-left: 16px; margin-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 */
  .sheet-backdrop { padding: 0; z-index: 38; }
  .sheet, .sheet.compose-sheet { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .sheet.compose-sheet { padding: 16px 16px 14px; }
  .compose-sheet .rt-editor { padding: 12px 14px; }
  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: the actions are already icon-only everywhere, so narrow
     screens only need to shed the word "selected" to hold one row */
  .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 h3 { font-size: 16px; margin: 18px 0 8px; }
.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; }

/* --- sorting from HEY (heysortpage.js) --- */
.hey-sorting { margin-top: 28px; }
.hey-map { border-collapse: collapse; margin: 8px 0 12px; }
.hey-map td { padding: 6px 12px 6px 0; vertical-align: middle; }
.hey-map select { max-width: 260px; }

/* The new-version bar sits above everything at the top so it is seen without covering the compose or toast spots at the bottom. */
.update-bar { position: fixed; z-index: 60; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); min-height: 40px; max-width: calc(100% - 24px); padding: 0 20px; border: 0; border-radius: 20px; background: var(--accent); color: #fff; font: inherit; font-weight: 500; cursor: pointer; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); }
