/* QeyeT Classic — webmail.
 *
 * Tokens are Quantum's (fin mail/), not Classic's teal dashboard palette:
 * Steven's decision was "match Quantum's green EXACTLY". The values below are
 * copied from fin/mail/styles.css :root and brand-system.css, so the two
 * products are the same green rather than two greens that nearly match.
 *
 * Layout mirrors fin's mail shell: rail + sidebar (240) + list (368) + reader,
 * with fin's own 820px breakpoint where the sidebar becomes a drawer.
 */
:root {
  /* Quantum surface system (fin/mail/styles.css) */
  --canvas: #eef2f1;
  --surface: #ffffff;
  --surface-soft: #f6f8f7;
  --surface-hover: #eef2f0;
  --ink: #14201c;
  --ink-soft: #5e6b66;
  --ink-faint: #7d8a84;
  --line: #e2e8e5;
  --line-strong: #c9d4cf;
  --green: #0a6f50;
  --green-dark: #085c43;
  --green-soft: #e8f4ef;
  --red: #a53b3b;
  --red-soft: #f8ecec;
  --amber: #8f5a0a;
  --amber-soft: #faf3e6;
  --row-hover: #f5f8f6;
  --row-active: #e9f3ed;
  /* W3: every remaining literal colour is a token, so dark mode is one block. */
  --sidebar-bg: #f3f6f4;
  --folder-hover: #e9efec;
  --on-accent: #ffffff;
  --red-line: #e8cfcf;
  --amber-line: #f0e0c0;
  --toast-bg: #14201c;
  --toast-ink: #ffffff;
  --toast-link: #9fe3c6;
  --unread-card: #fafbfa;
  --skeleton: #e7ecea;
  --backdrop: rgba(16, 28, 24, 0.45);
  --mail-body-bg: #ffffff;
  color-scheme: light;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;
  --sidebar-width: 240px;
  --list-width: 368px;
  --control-h: 40px;
  --shadow-1: 0 1px 2px rgba(16, 28, 24, 0.06);
  --shadow-2: 0 8px 24px rgba(16, 28, 24, 0.08);
  --shadow-3: 0 18px 48px rgba(16, 28, 24, 0.14);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --duration: 140ms;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "cv11", "ss01", "tnum";
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--canvas);
  color: var(--ink);
  line-height: 1.5;
}
a { color: var(--green); }
button, input, select, textarea { font: inherit; color: inherit; }

/* --- app chrome --------------------------------------------------------- */
.mail-app {
  display: grid;
  grid-template-columns: var(--sidebar-width) var(--list-width) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}
/* The scrim only exists for the narrow-screen drawer. Without this it is a
 * normal grid child at desktop and steals a column, which pushed the reader
 * onto a second row (caught by looking at the 1280 screenshot). */
.drawer-scrim { display: none; }

/* Sidebar ---------------------------------------------------------------- */
.mail-sidebar {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: 18px 12px 14px;
}
.mail-brand {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 44px; padding: 0 7px 14px; color: var(--green-dark);
}
.mail-brand strong { font-size: 17px; letter-spacing: -0.01em; }
.mail-brand em {
  font-style: normal; font-size: 12px; font-weight: 700;
  color: var(--ink-soft); margin-left: 7px;
}
.compose-button {
  width: 100%; margin-bottom: 10px; flex: none;
  height: var(--control-h); border: 0; border-radius: var(--radius-md);
  background: var(--green); color: var(--on-accent); font-weight: 700; font-size: 14px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background-color var(--duration) var(--ease);
}
.compose-button:hover { background: var(--green-dark); }
.folder-section-header {
  min-height: 34px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 7px 4px 10px; color: var(--ink-soft);
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em;
}
.folder-nav { display: grid; gap: 3px; overflow-y: auto; min-height: 0; }
.folder-button {
  width: 100%; height: var(--control-h);
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 9px;
  padding: 0 10px; border: 0; border-radius: 6px; background: transparent;
  text-align: left; cursor: pointer; color: var(--ink-soft);
  transition: background-color var(--duration) var(--ease), color var(--duration) var(--ease);
}
.folder-button:hover { background: var(--folder-hover); color: var(--ink); }
.folder-button.active {
  background: var(--green-soft); color: var(--green-dark); font-weight: 750;
}
.folder-button .count { min-width: 22px; text-align: right; font-size: 12px; }
.sidebar-account {
  margin-top: 6px; flex: 0 0 auto; border-top: 1px solid var(--line);
  padding: 10px 4px 2px; display: grid; gap: 2px;
}
.sidebar-account strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.sidebar-account span { color: var(--ink-soft); font-size: 11px; }
.sidebar-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: 12px; }
.sidebar-links a { color: var(--ink-soft); text-decoration: none; }
.sidebar-links a:hover { color: var(--green); }

/* List pane -------------------------------------------------------------- */
.mail-list-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--line);
}
.list-header {
  flex: none; padding: 17px 16px 12px; border-bottom: 1px solid var(--line);
  position: relative; z-index: 2; background: inherit;
}
.list-title { height: 36px; display: flex; align-items: center; justify-content: space-between; }
.list-title h1 { margin: 0; font-size: 21px; letter-spacing: -0.01em; }
.list-actions { display: flex; gap: 4px; }
.icon-button {
  width: 38px; height: 38px; display: inline-grid; place-content: center;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer;
  color: var(--ink-soft);
}
.icon-button:hover { background: var(--surface-hover); color: var(--ink); }
.icon-button.active { color: var(--green-dark); background: var(--green-soft); }
.search-box {
  height: 38px; display: grid; grid-template-columns: 19px 1fr; align-items: center;
  gap: 8px; margin-top: 10px; padding: 0 11px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--surface-soft); color: var(--ink-soft);
}
.search-box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.search-box input { min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); }

.message-list { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
/* One compact row: [checkbox][avatar] sender … date / subject / preview.
   The checkbox is its own column, NOT a fourth child in a two-column grid --
   that pushed the avatar and the text onto extra lines and doubled every row. */
.mail-row {
  width: 100%; display: grid; grid-template-columns: 16px 34px minmax(0, 1fr);
  gap: 10px; align-items: start; padding: 12px 16px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent;
  text-align: left; cursor: pointer;
  transition: background-color var(--duration) var(--ease);
}
.mail-row:hover { background: var(--row-hover); }
.mail-row.active { background: var(--row-active); }
.mail-row.unread .row-sender,
.mail-row.unread .row-subject { font-weight: 750; color: var(--ink); }
.row-main { min-width: 0; display: grid; gap: 2px; }
.row-line { display: flex; align-items: baseline; gap: 8px; }
.row-sender {
  font-size: 13.5px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto;
}
.row-time { font-size: 11.5px; color: var(--ink-soft); flex: 0 0 auto; }
.row-subject {
  font-size: 13.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-preview {
  font-size: 12.5px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-content: center;
  background: var(--green-soft); color: var(--green-dark);
  font-size: 12px; font-weight: 800; text-transform: uppercase; flex: none;
}
.list-footer {
  flex: none; padding: 8px 12px; border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--ink-soft);
}
.text-button {
  border: 0; background: transparent; color: var(--green); font-weight: 650;
  cursor: pointer; padding: 4px 6px; border-radius: 6px;
}
.text-button:disabled { color: var(--ink-faint); cursor: default; }
.text-button:not(:disabled):hover { background: var(--green-soft); }

/* Reader ----------------------------------------------------------------- */
.reader-pane {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface); overflow: hidden;
}
/* The reader mounts here once a message is open. Styled by class, not an inline
 * style attribute, because mail.html runs under `style-src 'self'`. */
#reader {
  display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto;
}
#reader[hidden] { display: none; }
/* Message bodies render in a sandboxed iframe (no allow-scripts, no
 * allow-same-origin), so nothing in the body shares this document's origin. */
.mail-frame {
  display: block; width: 100%; border: 0; background: var(--mail-body-bg);
  min-height: 260px; flex: 0 0 auto;
}
.reader-empty {
  margin: auto; text-align: center; color: var(--ink-soft); padding: 32px;
}
.reader-empty strong { display: block; color: var(--ink); margin-bottom: 6px; font-size: 15px; }
.reader-header {
  flex: none; padding: 16px 22px 12px; border-bottom: 1px solid var(--line);
  position: relative; background: var(--surface); z-index: 2;
}
.reader-subject { margin: 0 0 8px; font-size: 19px; line-height: 1.3; letter-spacing: -0.01em; }
.reader-meta { display: grid; gap: 2px; font-size: 13px; color: var(--ink-soft); }
.reader-meta strong { color: var(--ink); font-weight: 650; }
.reader-toolbar {
  flex: none; display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  padding: 10px 22px; border-bottom: 1px solid var(--line); background: var(--surface-soft);
}
.reader-toolbar .spacer { flex: 1 1 auto; }
.btn {
  height: 34px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface-hover); }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--on-accent); }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--red); border-color: var(--red-line); }
.btn.danger:hover { background: var(--red-soft); }
.reader-body {
  flex: 1 1 auto; overflow-y: auto; min-height: 0;
  padding: 20px 22px 40px; font-size: 14.5px; line-height: 1.6;
  word-break: break-word;
}
.reader-body img { max-width: 100%; height: auto; }
.reader-body a { color: var(--green); }
.images-note {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 14px;
  background: var(--amber-soft); border: 1px solid var(--amber-line);
  border-radius: var(--radius-md); font-size: 13px; color: var(--amber);
}
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.attachment {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-soft); font-size: 13px; text-decoration: none; color: var(--ink);
}
.attachment:hover { border-color: var(--green); color: var(--green-dark); }
.attachment small { color: var(--ink-soft); }
.attachment-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.attachment-meta strong {
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.attachment-image { padding: 4px; gap: 10px; text-align: left; }
/* A thumbnail that could not be fetched degrades to this: an honest label and a
 * working download, never a broken-image glyph. */
.attachment-fallback { align-items: center; gap: 10px; }
.attachment-fallback-mark {
  width: 40px; height: 40px; display: flex; align-items: center;
  justify-content: center; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink-soft); font-size: 18px; flex: 0 0 auto;
}
.attachment-image:hover { border-color: var(--green); }
.attachment-thumb {
  width: 160px; height: 120px; object-fit: cover; flex: 0 0 auto;
  border-radius: var(--radius-sm); background: var(--surface);
  border: 1px solid var(--line);
}
/* Attachment viewer -------------------------------------------------------- */
.viewer-backdrop {
  position: fixed; inset: 0; z-index: 90; display: flex; align-items: center;
  justify-content: center; padding: 32px; background: rgba(20, 32, 28, 0.82);
}
.viewer-frame {
  display: flex; flex-direction: column; max-width: 100%; max-height: 100%;
  background: var(--surface); border-radius: var(--radius-md); overflow: hidden;
  box-shadow: 0 18px 48px rgba(20, 32, 28, 0.32);
}
.viewer-image { max-width: calc(100vw - 64px); max-height: calc(100vh - 132px); object-fit: contain; }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-top: 1px solid var(--line); background: var(--surface-soft);
}
.viewer-name {
  font-size: 13px; font-weight: 500; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.viewer-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.viewer-actions .button { padding: 6px 14px; font-size: 13px; }

/* Compose ---------------------------------------------------------------- */
.composer-backdrop {
  position: fixed; inset: 0; background: rgba(16, 28, 24, 0.28);
  display: grid; place-items: center; z-index: 60; padding: 24px;
}
.composer-backdrop[hidden] { display: none; }
.composer {
  width: min(680px, 100%); max-height: min(86vh, 760px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3); overflow: hidden;
}
.composer-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface-soft);
}
.composer-header h2 { margin: 0; font-size: 15px; }
.composer-body { padding: 14px 16px; overflow-y: auto; display: grid; gap: 10px; }
.compose-line { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; }
.compose-line label { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.compose-line input, .compose-line select, .composer textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface); font-size: 14px;
}
.composer textarea {
  height: auto; min-height: 220px; padding: 11px 12px; line-height: 1.55; resize: vertical;
}
.compose-line input:focus, .compose-line select:focus, .composer textarea:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft);
}
.composer-footer {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-top: 1px solid var(--line); background: var(--surface-soft);
}
.composer-footer .spacer { flex: 1 1 auto; }
.compose-status { font-size: 12.5px; color: var(--ink-soft); }

/* Messages / status ------------------------------------------------------ */
.toast-stack { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 80; }
.toast {
  padding: 10px 14px; border-radius: var(--radius-md); font-size: 13px;
  background: var(--toast-bg); color: var(--toast-ink); box-shadow: var(--shadow-2); max-width: 380px;
}
.toast.error { background: var(--red); }
.toast.ok { background: var(--green-dark); }
.empty-state { padding: 40px 24px; text-align: center; color: var(--ink-soft); font-size: 14px; }
.loading-row { padding: 18px 16px; color: var(--ink-soft); font-size: 13px; }
.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Phone / narrow --------------------------------------------------------- */
.mobile-only { display: none; }

@media (max-width: 1100px) {
  :root { --list-width: 310px; }
}
@media (max-width: 820px) {
  /* fin's own breakpoint: sidebar becomes a drawer, reader becomes a page. */
  .mail-app { grid-template-columns: minmax(0, 1fr); }
  .mail-sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(80vw, 300px); z-index: 70;
    transform: translateX(-102%); transition: transform var(--duration) var(--ease);
    box-shadow: var(--shadow-3);
  }
  .mail-app.drawer-open .mail-sidebar { transform: translateX(0); }
  .drawer-scrim {
    position: fixed; inset: 0; background: rgba(16, 28, 24, 0.35);
    z-index: 65; display: none;
  }
  .mail-app.drawer-open .drawer-scrim { display: block; }
  .mobile-only { display: inline-grid; }
  .mail-list-pane { border-right: 0; }
  /* Reader replaces the list on narrow screens instead of sharing the row. */
  .mail-app.reading .mail-list-pane { display: none; }
  .mail-app:not(.reading) .reader-pane { display: none; }
  .composer-backdrop { padding: 0; align-items: end; }
  .composer {
    width: 100%; max-height: 94dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .composer textarea { min-height: 180px; }
}
@media (max-width: 400px) {
  .list-header { padding: 12px 12px 10px; }
  .list-title h1 { font-size: 18px; }
  .mail-row { padding: 10px 12px; grid-template-columns: 13px 30px minmax(0, 1fr); gap: 8px; }
  .row-check { width: 13px; height: 13px; margin-top: 9px; }
  .avatar { width: 30px; height: 30px; font-size: 11px; }
  .reader-header { padding: 12px 14px 10px; }
  .reader-toolbar { padding: 8px 14px; }
  .reader-body { padding: 14px 14px 32px; }
  .attachment-thumb { width: 120px; height: 96px; }
  .attachment-meta strong { max-width: 120px; }
  .viewer-backdrop { padding: 0; }
  .viewer-image { max-width: 100vw; max-height: calc(100vh - 58px); margin: auto; }
  .viewer-frame { width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  .viewer-bar { padding: 8px 12px; }
  .compose-line { grid-template-columns: 54px minmax(0, 1fr); }
}

/* Print / dark are out of scope for the MVP; Quantum's dark theme is a
 * separate decision that needs its own pass, not a half-copy here. */

/* ---------------------------------------------------------------------------
   T1: menus, stars, FAB, signature block, shortcuts help
   Quantum's shapes: 10px radius, 1px hairline, soft shadow, 34px rows.
   --------------------------------------------------------------------------- */
.mail-row { scroll-margin-top: 8px; }
.mail-row.focused { outline: 2px solid var(--green); outline-offset: -2px; }

.row-star {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px; display: grid; place-items: center;
  border: 0; border-radius: var(--radius-pill); background: transparent;
  color: var(--ink-faint); font-size: 14px; cursor: pointer;
}
.row-star:hover { background: var(--surface-hover); color: var(--amber); }
.row-star.on { color: var(--amber); }
.mail-row { position: relative; }
.mail-row .row-line { padding-right: 26px; }

.menu-backdrop {
  position: fixed; inset: 0; z-index: 84; background: transparent;
}
.menu {
  position: fixed; z-index: 85; min-width: 210px; max-width: 280px;
  max-height: min(60vh, 420px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-md); box-shadow: var(--shadow-3);
  padding: 6px;
}
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink); font: inherit; font-size: 13.5px;
  text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); outline: none; }
.menu-item[aria-current="true"] { background: var(--green-soft); color: var(--green-dark); font-weight: 600; }
.menu-item.danger { color: var(--red); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }

.avatar-name { display: block; font-size: 12.5px; color: var(--ink-soft); }

.compose-fab {
  display: none;
  position: fixed; right: 18px; bottom: 18px; z-index: 30;
  width: 56px; height: 56px; border-radius: var(--radius-pill);
  border: 0; background: var(--green); color: var(--on-accent); font-size: 22px;
  box-shadow: var(--shadow-3); cursor: pointer;
}
.compose-fab:active { background: var(--green-dark); }

.compose-signature { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.compose-signature-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint);
}
.compose-signature textarea {
  width: 100%; margin-top: 6px; min-height: 64px; resize: vertical;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface-soft);
}

.shortcut-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(16, 28, 24, 0.45);
  display: grid; place-items: center; padding: 20px;
}
/* `hidden` is a UA-level display:none, and any author display rule beats it.
 * Without this the backdrop stayed on screen with the modal inside it, so the
 * dialog could not be dismissed and nothing under it could be clicked. */
[hidden] { display: none !important; }
.shortcut-dialog {
  width: min(440px, 100%); background: var(--surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3); padding: 18px 20px;
}
.shortcut-head { display: flex; align-items: center; justify-content: space-between; }
.shortcut-head h2 { margin: 0; font-size: 17px; }
.shortcut-list { display: grid; gap: 8px; margin: 14px 0 0; }
.shortcut-list > div { display: flex; justify-content: space-between; gap: 16px; font-size: 13.5px; }
.shortcut-list dt { font-weight: 650; color: var(--ink); }
.shortcut-list dd { margin: 0; color: var(--ink-soft); }

.images-note .note-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.images-note .text-button { color: var(--green); }

@media (max-width: 820px) {
  .compose-fab { display: grid; place-items: center; }
  /* A popover anchored to a control is wrong on a phone: the menu becomes a
     sheet at the bottom, which is where a thumb already is. */
  .menu {
    left: 0 !important; right: 0; bottom: 0; top: auto !important;
    width: 100%; max-width: none; max-height: 70vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-3);
  }
  .menu-item { padding: 13px 12px; font-size: 15px; }
}

/* ---------------------------------------------------------------------------
   T2: composer toolbar, rich text, attachment chips, saved indicator
   --------------------------------------------------------------------------- */
.compose-tools {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  padding: 6px 0 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
.compose-tools .tool {
  min-width: 30px; height: 28px; padding: 0 7px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-soft); color: var(--ink); font: inherit;
  font-size: 13px; cursor: pointer;
}
.compose-tools .tool:hover { background: var(--surface-hover); }
.compose-tools .tool[aria-pressed="true"] { background: var(--green-soft); border-color: var(--green); color: var(--green-dark); }
.compose-rich {
  min-height: 180px; max-height: 46vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px; line-height: 1.55; background: var(--surface);
  outline: none;
}
.compose-rich:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.compose-rich:empty::before {
  content: attr(data-placeholder); color: var(--ink-faint);
}
.compose-rich blockquote {
  margin: 8px 0; padding: 6px 10px; border-left: 3px solid var(--line-strong);
  color: var(--ink-soft);
}
#compose-text { width: 100%; min-height: 180px; resize: vertical; }

.attach-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 8px; border: 1px solid var(--line); border-radius: var(--radius-pill);
  background: var(--surface-soft); font-size: 12.5px; color: var(--ink);
}
.attach-chip button {
  border: 0; background: transparent; color: var(--red); cursor: pointer;
  font-size: 14px; line-height: 1; padding: 0 2px;
}
.attach-add {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  font-size: 13px; color: var(--green); cursor: pointer;
}
.compose-saved { margin-left: auto; font-size: 12px; color: var(--ink-faint); }

/* The `hidden` attribute is a UA-level `display:none`, which any author
 * `display` rule beats. Every overlay here sets display explicitly, so this has
 * to be explicit too or a hidden dialog swallows clicks. */

body.composing .compose-fab { display: none !important; }

/* ---------------------------------------------------------------------------
   Follow-up fixes: signature/quote layout and the reader loading state
   --------------------------------------------------------------------------- */
.signature-live {
  white-space: pre-wrap; color: var(--ink-soft);
  margin: 6px 0 0; padding-top: 6px; border-top: 1px solid var(--line);
}
.signature-gap { height: 6px; margin: 0; }
.compose-quote {
  white-space: pre-wrap; margin: 10px 0 0; padding: 8px 12px;
  border-left: 3px solid var(--line-strong); color: var(--ink-soft);
  font-size: 13.5px;
}
.reader-loading {
  padding: 18px 4px; color: var(--ink-faint); font-size: 13.5px;
}
.reader-loading::after {
  content: ""; display: inline-block; width: 12px; height: 12px;
  margin-left: 8px; border: 2px solid var(--line-strong);
  border-top-color: var(--green); border-radius: 50%;
  animation: reader-spin 0.9s linear infinite; vertical-align: -2px;
}
@keyframes reader-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .reader-loading::after { animation: none; }
}

/* ---------------------------------------------------------------------------
   T3: bulk selection, bulk bar, search hint
   --------------------------------------------------------------------------- */
.list-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.select-all { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.select-all input { width: 15px; height: 15px; accent-color: var(--green); }
.search-hint {
  margin: 0; font-size: 11px; color: var(--ink-faint);
  /* Wraps instead of being clipped: the old nowrap+ellipsis cut the operator
     list off mid-token ("…in:A…"). The full syntax lives in the title. */
  white-space: normal; line-height: 1.35; min-width: 0;
}
.row-check {
  flex: none; width: 15px; height: 15px; margin: 10px 0 0;
  border: 1.5px solid var(--line-strong); border-radius: 4px;
  background: var(--surface); position: relative; cursor: pointer;
}
.row-check.on { background: var(--green); border-color: var(--green); }
.row-check.on::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.mail-row.selected { background: var(--green-soft); }
.bulk-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 7px 10px; background: var(--green-soft);
  border-bottom: 1px solid var(--line); font-size: 12.5px;
}
.bulk-count { font-weight: 650; color: var(--green-dark); }
.bulk-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.bulk-actions button {
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); border-radius: var(--radius-sm); padding: 3px 8px;
  font: inherit; font-size: 12px; cursor: pointer;
}
.bulk-actions button:hover { background: var(--surface-hover); }
.bulk-actions button.danger { color: var(--red); border-color: var(--red-soft, #f0c2bd); }
.undo-bar {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; z-index: 80;
  background: var(--toast-bg); color: var(--toast-ink); padding: 10px 14px;
  border-radius: var(--radius-pill); box-shadow: var(--shadow-3); font-size: 13px;
}
.undo-bar button {
  border: 0; background: transparent; color: var(--toast-link); font: inherit;
  font-weight: 650; cursor: pointer; text-decoration: underline;
}
@media (max-width: 820px) {
  .search-hint { display: none; }
  .bulk-actions { margin-left: 0; }
  .bulk-bar { position: sticky; top: 0; z-index: 6; }
}

/* ---------------------------------------------------------------------------
   T4: settings view
   --------------------------------------------------------------------------- */
.settings-panel {
  position: fixed; inset: 0; z-index: 70; background: var(--canvas);
  display: flex; flex-direction: column;
}
.settings-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.settings-head h2 { margin: 0; font-size: 17px; }
.settings-body {
  padding: 16px; overflow: auto; display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-content: start;
}
.settings-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 14px 16px;
}
.settings-card h3 { margin: 0 0 10px; font-size: 14px; letter-spacing: 0.01em; }
.settings-note { margin: 8px 0 0; font-size: 12px; color: var(--ink-faint); }
.field { display: block; margin: 0 0 10px; }
.field > span { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; font: inherit; font-size: 13.5px; padding: 7px 9px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--canvas); color: var(--ink);
}
.field textarea { resize: vertical; }
.field-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px;
}
/* A date input carries a browser-defined intrinsic width; without min-width:0
   on the grid item the track refuses to shrink and the second field runs past
   the card's right edge. */
.field-row > .field { min-width: 0; }
.field-row input { min-width: 0; max-width: 100%; }
@media (max-width: 460px) {
  .field-row { grid-template-columns: minmax(0, 1fr); }
}
.switch { display: flex; align-items: center; gap: 8px; font-size: 13.5px; margin-bottom: 10px; }
.switch input { width: 16px; height: 16px; accent-color: var(--green); }
.settings-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.settings-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12.5px; padding: 5px 8px; background: var(--canvas);
  border-radius: var(--radius-sm);
}
.settings-list button {
  border: 0; background: transparent; color: var(--red); font: inherit;
  font-size: 12px; cursor: pointer; text-decoration: underline;
}
body.compact .mail-row { padding-top: 6px; padding-bottom: 6px; }
body.compact .row-preview { display: none; }
@media (max-width: 820px) {
  .settings-body { grid-template-columns: 1fr; padding: 12px; }
}

/* ---------------------------------------------------------------------------
   F2: inline search warning + styled confirm dialog
   --------------------------------------------------------------------------- */
.search-warning {
  margin: 0; font-size: 11.5px; line-height: 1.35;
  color: var(--amber); background: var(--amber-soft);
  border: 1px solid var(--amber-line); border-radius: var(--radius-sm);
  padding: 4px 7px;
}
.confirm-backdrop {
  position: fixed; inset: 0; z-index: 90; background: var(--backdrop);
  display: grid; place-items: center; padding: 20px;
}
.confirm-dialog {
  width: min(380px, 100%); background: var(--surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-3); padding: 18px 20px;
}
.confirm-dialog h2 { margin: 0 0 8px; font-size: 16px; }
.confirm-dialog p { margin: 0 0 16px; font-size: 13.5px; color: var(--ink-soft); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger:hover { filter: brightness(0.94); }
.btn.ghost { background: transparent; color: var(--ink-soft); }

/* ---------------------------------------------------------------------------
   W1 Gap #2: Threaded Conversation View
   --------------------------------------------------------------------------- */

/* Thread header in message list */
.thread-header {
  width: 100%; display: grid; grid-template-columns: 16px 34px minmax(0, 1fr);
  gap: 10px; align-items: center; padding: 10px 16px;
  border: 0; border-bottom: 1px solid var(--line); background: var(--surface-soft);
  text-align: left; cursor: pointer;
  transition: background-color var(--duration) var(--ease);
}
.thread-header:hover { background: var(--row-hover); }
.thread-header[aria-expanded="true"] { background: var(--green-soft); }
.thread-header .row-main { grid-column: 3; }
.thread-header .row-sender { font-weight: 750; }
.thread-header .row-subject { font-size: 13px; color: var(--ink-soft); }
.thread-header .thread-expand {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border: 0; background: transparent;
  color: var(--ink-soft); cursor: pointer; border-radius: var(--radius-sm);
  flex: 0 0 auto;
}
.thread-header .thread-expand:hover { background: var(--surface-hover); color: var(--ink); }
.thread-header .thread-expand:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.thread-header .unread-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 6px; font-size: 11px;
  font-weight: 700; color: var(--on-accent); background: var(--green);
  border-radius: var(--radius-pill); margin-left: 8px;
}

/* Thread messages in reader */
.thread-container { display: flex; flex-direction: column; gap: 0; }
.thread-message {
  border-top: 1px solid var(--line); background: var(--surface);
  transition: background-color var(--duration) var(--ease);
}
.thread-message:first-child { border-top: 0; }
.thread-message.active-message { background: var(--green-soft); }
.thread-message.unread { background: var(--unread-card); }
.thread-message-header {
  flex: none; padding: 14px 22px 8px; border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}
.thread-message-from { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.thread-message-from .avatar { width: 28px; height: 28px; font-size: 10px; }
.thread-message-from strong { font-size: 14px; color: var(--ink); }
.thread-message-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--ink-soft); }
.thread-message-body { padding: 12px 22px 20px; }
.thread-message-body .mail-frame { min-height: 200px; }
.thread-message-body .images-note { margin-bottom: 12px; }
.thread-message-body .attachment-list { margin-top: 12px; padding-top: 12px; }

/* Mobile adjustments */
@media (max-width: 820px) {
  .thread-header { grid-template-columns: 13px 30px minmax(0, 1fr); padding: 8px 12px; }
  .thread-header .row-subject { font-size: 12px; }
  .thread-message-header { padding: 10px 14px 6px; }
  .thread-message-body { padding: 10px 14px 16px; }
  .thread-message-body .mail-frame { min-height: 160px; }
}

/* ---------------------------------------------------------------------------
   W1 Gap #3: Recipient chips with autocomplete
   --------------------------------------------------------------------------- */

.chip-field {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
.chip-field:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}
.chip-field:not(:focus-within):hover {
  border-color: var(--ink-soft);
}

.chip-input-wrap {
  display: flex;
  flex: 1 1 auto;
  min-width: 120px;
  position: relative;
}
.chip-input-wrap input[type="text"] {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  color: var(--ink);
  padding: 4px 0;
  min-width: 80px;
  width: 100%;
}
.chip-input-wrap input[type="text"]::placeholder {
  color: var(--ink-soft);
  opacity: 0.7;
}

/* Chip styling */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 6px;
  background: var(--green-soft);
  color: var(--green-dark);
  border-radius: var(--radius-pill);
  font-size: 13px;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip[aria-selected="true"] {
  background: var(--green);
  color: var(--on-accent);
}
.chip .chip-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip .chip-email {
  font-size: 11px;
  opacity: 0.8;
  font-family: var(--font-mono, monospace);
}
.chip .chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--duration) var(--ease), background var(--duration) var(--ease);
  flex-shrink: 0;
}
.chip .chip-remove:hover {
  opacity: 1;
  background: var(--green-soft);
}
.chip .chip-remove:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -2px;
}
.chip[aria-selected="true"] .chip-remove:hover {
  background: rgba(255,255,255,0.2);
}

/* Autocomplete dropdown */
.chip-suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}
.chip-suggest[hidden] { display: none; }
.chip-suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}
.chip-suggest-item:hover,
.chip-suggest-item[aria-selected="true"] {
  background: var(--row-hover);
}
.chip-suggest-item .avatar {
  width: 24px;
  height: 24px;
  font-size: 9px;
  flex-shrink: 0;
}
.chip-suggest-item .name {
  font-weight: 500;
  color: var(--ink);
}
.chip-suggest-item .email {
  color: var(--ink-soft);
  font-size: 12px;
  font-family: var(--font-mono, monospace);
}
.chip-suggest-empty {
  padding: 12px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .chip-field {
    padding: 8px;
  }
  .chip {
    max-width: 200px;
  }
  .chip .chip-email {
    display: none;
  }
}
/* ---------------------------------------------------------------------------
   W1 Gap #4: Attachment drag-drop, paste images, per-file progress
   --------------------------------------------------------------------------- */

.attach-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--ink-soft);
  text-align: center;
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease);
  cursor: pointer;
}
.attach-dropzone:hover,
.attach-dropzone.drag-active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green-dark);
}
.attach-dropzone svg {
  opacity: 0.6;
}
.attach-dropzone-hint {
  font-size: 12px;
  opacity: 0.7;
}

.attach-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 0;
}
.attach-progress-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 13px;
}
.attach-progress-item .ap-info {
  flex: 1;
  min-width: 0;
}
.attach-progress-item .ap-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  color: var(--ink);
}
.attach-progress-item .ap-meta {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  font-family: var(--font-mono, monospace);
}
.attach-progress-item .ap-bar {
  flex: 0 0 120px;
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.attach-progress-item .ap-bar-fill {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.15s linear;
}
.attach-progress-item .ap-status {
  flex: 0 0 auto;
  width: 70px;
  text-align: right;
  font-size: 11px;
  color: var(--ink-soft);
  font-family: var(--font-mono, monospace);
}
.attach-progress-item.complete .ap-status {
  color: var(--green);
}
.attach-progress-item.error .ap-status {
  color: var(--red);
}
.attach-progress-item .ap-cancel {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--duration) var(--ease), background var(--duration) var(--ease);
  flex-shrink: 0;
}
.attach-progress-item .ap-cancel:hover {
  opacity: 1;
  background: var(--row-hover);
}
.attach-progress-item .ap-cancel:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}
.attach-progress-item.complete .ap-cancel,
.attach-progress-item.error .ap-cancel {
  display: none;
}

/* Ensure dropzone works on the whole composer area */
.composer-body.drag-over .attach-dropzone {
  display: flex;
}
/* ---------------------------------------------------------------------------
   W1 Gap #5: Search operators suggestions
   --------------------------------------------------------------------------- */

.search-suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  font-size: 13px;
}
.search-suggest[hidden] { display: none; }
.search-suggest-section {
  padding: 4px 0;
}
.search-suggest-section + .search-suggest-section {
  border-top: 1px solid var(--line);
}
.search-suggest-label {
  padding: 4px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  font-weight: 600;
}
.search-suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.search-suggest-item:hover,
.search-suggest-item[aria-selected="true"] {
  background: var(--row-hover);
}
.search-suggest-item kbd {
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  padding: 1px 6px;
  background: var(--line);
  border-radius: 3px;
  color: var(--ink);
  min-width: 80px;
  text-align: left;
}
.search-suggest-item .desc {
  flex: 1;
  color: var(--ink-soft);
  font-size: 12px;
}
.search-suggest-item .example {
  color: var(--green);
  font-family: var(--font-mono, monospace);
  font-size: 11px;
  opacity: 0.8;
}

/* ---------------------------------------------------------------------------
   W1 Gap #6: Mobile (<=600px) - full-screen compose, single-pane list/reader,
   44px touch targets, back button in reader
   --------------------------------------------------------------------------- */

@media (max-width: 600px) {
  /* Full-screen compose: modal becomes a full-screen sheet */
  .composer-backdrop {
    padding: 0;
    align-items: stretch;
  }
  .composer {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }
  .composer-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
    flex-shrink: 0;
  }
  .composer-header h2 {
    margin: 0;
    font-size: 17px;
  }
  .composer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .composer-footer {
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
  }
  .composer-footer .btn {
    min-height: 44px;
    min-width: 88px;
    padding: 0 20px;
    font-size: 16px;
  }

  /* 44px minimum touch targets for all interactive elements */
  button, [role="button"], input[type="button"], input[type="submit"],
  input[type="reset"], input[type="checkbox"], input[type="radio"],
  select, .tool, .icon-button, .text-button, .compose-button {
    min-height: 44px;
    min-width: 44px;
  }

  /* List row touch targets */
  .mail-row {
    min-height: 56px;
  }
  .row-check {
    width: 20px;
    height: 20px;
  }
  .row-star {
    width: 44px;
    height: 44px;
  }
  .avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }

  /* Reader toolbar buttons */
  .reader-toolbar .btn {
    min-height: 44px;
    padding: 0 16px;
    font-size: 15px;
  }

  /* Folder nav items */
  .folder-nav button,
  .folder-nav a {
    min-height: 44px;
    padding: 10px 12px;
  }

  /* Bulk bar buttons */
  .bulk-bar .bulk-actions button {
    min-height: 44px;
    padding: 0 16px;
    font-size: 14px;
  }

  /* Search input */
  .search-box input {
    min-height: 44px;
    font-size: 16px; /* prevents zoom on iOS */
  }

  /* Chip field inputs */
  .chip-field .chip-input-wrap input {
    min-height: 44px;
    font-size: 16px;
  }
  .chip {
    min-height: 36px;
  }
  .chip .chip-remove {
    min-width: 36px;
    min-height: 36px;
  }

  /* Attachment progress items */
  .attach-progress-item {
    min-height: 56px;
  }
  .attach-progress-item .ap-cancel {
    min-width: 44px;
    min-height: 44px;
  }

  /* Compose field labels and inputs */
  .compose-line {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 16px;
  }
  .compose-line > label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 4px;
  }
  .compose-line select,
  .compose-line input[type="text"],
  .compose-line input[type="search"],
  .compose-line textarea {
    min-height: 44px;
    font-size: 16px;
    padding: 10px 12px;
  }
  .compose-rich {
    min-height: 200px;
    font-size: 16px;
  }
  .compose-tools {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 0;
  }
  .compose-tools .tool {
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
    font-size: 15px;
  }

  /* Attachment dropzone */
  .attach-dropzone {
    min-height: 80px;
    padding: 24px 16px;
  }

  /* Sidebar drawer already handled at 820px */

  /* List header */
  .list-header {
    padding: 12px 16px 10px;
    position: sticky;
    top: 0;
    background: var(--canvas);
    z-index: 5;
    border-bottom: 1px solid var(--line);
  }
  .list-title h1 {
    font-size: 20px;
  }

  /* Message list */
  .message-list {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  /* Reader pane */
  .reader-pane {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: var(--canvas);
    display: flex;
    flex-direction: column;
  }
  .reader-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
    flex-shrink: 0;
  }
  .reader-toolbar {
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 8px 16px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
  }
  .reader-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* Thread message headers in reader */
  .thread-message-header {
    padding: 12px 0;
  }
  .thread-message-body {
    padding: 0 0 16px;
  }

  /* Confirm dialog */
  .confirm-dialog {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
  }
  .confirm-dialog .confirm-actions {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
  }
  .confirm-dialog .confirm-actions .btn {
    flex: 1;
    min-height: 44px;
    font-size: 16px;
  }

  /* Settings panel */
  .settings-panel {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .settings-head {
    position: sticky;
    top: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 10;
  }
  .settings-body {
    flex: 1;
    overflow-y: auto;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .settings-card .field input,
  .settings-card .field select,
  .settings-card .field textarea {
    min-height: 44px;
    font-size: 16px;
  }

  /* Shortcuts dialog */
  .shortcut-dialog {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }
  .shortcut-head {
    position: sticky;
    top: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 10;
  }
  .shortcut-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  /* FAB positioning */
  .compose-fab {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* Pagination */
  .list-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    background: var(--canvas);
    border-top: 1px solid var(--line);
  }
  .list-footer button {
    min-height: 44px;
    min-width: 88px;
    font-size: 15px;
  }

  /* Search suggestions */
  .search-suggest {
    left: 16px;
    right: 16px;
    max-height: 50vh;
  }
  .search-suggest-item {
    min-height: 44px;
  }
  .search-suggest-item kbd {
    font-size: 12px;
    padding: 2px 8px;
  }
}

@media (max-width: 600px) and (orientation: landscape) {
  .composer-body {
    max-height: calc(100dvh - 120px);
  }
  .reader-body {
    max-height: calc(100vh - 200px);
  }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
  @media (max-width: 600px) {
    .mail-app {
      padding-left: env(safe-area-inset-left);
      padding-right: env(safe-area-inset-right);
    }
    .mail-sidebar {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
    }
  }
}

/* ---------------------------------------------------------------------------
   W2 (Gmail feel): conversation rows, hover actions, skeleton, conversation
   cards, docked compose window.
   --------------------------------------------------------------------------- */
.desktop-only { display: inline-grid; }
.thread-header { background: transparent; align-items: start; padding: 12px 16px; }
.thread-header.unread { background: var(--surface); }
.thread-header:not(.unread) { background: var(--surface-soft); }
.thread-header:hover { background: var(--row-hover); box-shadow: inset 0 -1px 0 var(--line-strong); }
.thread-header.active { background: var(--row-active); }
.thread-header.selected { background: var(--green-soft); }
.thread-header .row-subject { font-size: 13.5px; color: var(--ink); }
.thread-header:not(.unread) .row-sender { font-weight: 600; }
.row-count { color: var(--ink-soft); font-weight: 500; font-size: 12px; }
.row-clip { font-size: 12px; flex: none; opacity: 0.7; }
.row-draft { color: var(--red); font-weight: 700; }
.row-actions {
  position: absolute; right: 38px; top: 6px; display: none; gap: 2px;
  background: inherit; padding-left: 6px;
}
.row-act {
  width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%;
  color: var(--ink-soft); font-size: 13px; cursor: pointer;
}
.row-act:hover { background: var(--line); color: var(--ink); }
@media (hover: hover) and (min-width: 821px) {
  .thread-header:hover .row-actions { display: flex; }
  .thread-header:hover .row-time { visibility: hidden; }
}

/* Skeleton list: shape of the real rows, so nothing jumps when they land. */
.skeleton-row { cursor: default; pointer-events: none; }
.sk { display: block; background: var(--skeleton); border-radius: 4px; }
.sk-check { width: 15px; height: 15px; margin-top: 10px; }
.sk-avatar { width: 34px; height: 34px; border-radius: 50%; }
.sk-line { height: 10px; margin: 4px 0; }
.sk-w40 { width: 40%; } .sk-w70 { width: 70%; } .sk-w90 { width: 90%; }
@media (prefers-reduced-motion: no-preference) {
  .sk { animation: sk-pulse 1.2s ease-in-out infinite; }
  @keyframes sk-pulse { 50% { opacity: 0.55; } }
}

/* Conversation cards */
.thread-message.active-message { background: var(--surface); }
.thread-message.is-collapsed { background: var(--surface-soft); }
.thread-message-header[role="button"] { cursor: pointer; }
.thread-message-header.collapsed { padding: 10px 22px; border-bottom: 0; }
.thread-message-header.collapsed:hover { background: var(--row-hover); }
.thread-message-from .from-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-message-from .from-email { color: var(--ink-soft); font-size: 12.5px; }
.card-time { flex: none; font-size: 12px; color: var(--ink-soft); }
.card-snippet {
  margin-left: 36px; font-size: 13px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-message.is-loading .thread-message-header { opacity: 0.6; }
.thread-message-body .mail-frame { min-height: 120px; }
.reply-bar { display: flex; gap: 8px; flex-wrap: wrap; padding: 16px 22px 28px; }
.reply-bar .btn { border-radius: var(--radius-pill); padding-left: 16px; padding-right: 16px; }
.star-btn { font-size: 16px; color: var(--ink-faint); }
.star-btn.on { color: var(--amber); }

/* Docked compose window (desktop): sits bottom-right over the mail instead
   of dimming it, so you can keep reading while you write; minimizes to its
   title bar. Phones keep the full-screen sheet. */
.composer-head-actions { display: flex; gap: 2px; }
@media (min-width: 821px) {
  .composer-backdrop {
    inset: auto 24px 0 auto; background: transparent; padding: 0;
    display: block; pointer-events: none;
  }
  .composer {
    pointer-events: auto; width: 560px; max-height: calc(100vh - 72px);
    border-radius: 10px 10px 0 0; box-shadow: 0 8px 28px rgba(16, 28, 24, 0.28);
  }
  .composer-header { padding: 8px 10px 8px 16px; background: var(--toast-bg); color: var(--toast-ink); cursor: default; }
  .composer-header .icon-button { width: 30px; height: 30px; color: #dfe7e3; }
  .composer-header .icon-button:hover { background: rgba(255,255,255,0.12); color: var(--toast-ink); }
  .composer-backdrop.minimized .composer { width: 300px; }
  .composer-backdrop.minimized .composer-header { cursor: pointer; }
  .composer-backdrop.minimized .composer-body,
  .composer-backdrop.minimized .composer-footer { display: none; }
  .composer .compose-rich { min-height: 220px; }
  .undo-bar.send-undo { left: 24px; transform: none; }
}
@media (max-width: 820px) {
  .desktop-only { display: none !important; }
}
/* W2 storage meter + upgrade entry */
#account-quota { display: grid; gap: 4px; }
.quota-meter { display: block; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.quota-fill { display: block; height: 100%; background: var(--green); }
.quota-meter.full .quota-fill { background: var(--red); }
.quota-upgrade { color: var(--green); font-weight: 650; font-size: 12px; text-decoration: none; }
.quota-upgrade:hover { text-decoration: underline; }


/* ---------------------------------------------------------------------------
   W3: dark theme. data-theme-effective is set by /theme.js before first paint
   (System follows the device; Light/Dark are explicit). Only tokens change.
   --------------------------------------------------------------------------- */
:root[data-theme-effective="dark"] {
  --canvas: #0f1513;
  --surface: #161e1b;
  --surface-soft: #1b2421;
  --surface-hover: #222d29;
  --ink: #e4ece8;
  --ink-soft: #a7b4ae;
  --ink-faint: #85928c;
  --line: #29342f;
  --line-strong: #3a4742;
  --green: #4cc79a;
  --green-dark: #6fd8b0;
  --green-soft: #173329;
  --red: #ef8a85;
  --red-soft: #3a1d1c;
  --amber: #e7b765;
  --amber-soft: #2f2616;
  --row-hover: #1b2420;
  --row-active: #1b3329;
  --sidebar-bg: #121a17;
  --folder-hover: #1d2824;
  --on-accent: #06281c;
  --red-line: #5a2b29;
  --amber-line: #5a4622;
  --toast-bg: #e4ece8;
  --toast-ink: #101815;
  --toast-link: #0a6f50;
  --unread-card: #19221f;
  --skeleton: #24302b;
  --backdrop: rgba(0, 0, 0, 0.6);
  --mail-body-bg: #ffffff;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 18px 48px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}
/* Accent buttons: light-on-dark green needs dark text for contrast. */
:root[data-theme-effective="dark"] .compose-button,
:root[data-theme-effective="dark"] .btn.primary,
:root[data-theme-effective="dark"] .compose-fab { color: var(--on-accent); }
:root[data-theme-effective="dark"] .btn.danger { color: #1d0b0a; }
/* Email bodies are designed for white paper (as Gmail shows them): keep the
   message on its own white sheet so senders' colours stay readable. */
:root[data-theme-effective="dark"] .thread-message-body iframe { border-radius: 8px; }
:root[data-theme-effective="dark"] input,
:root[data-theme-effective="dark"] select,
:root[data-theme-effective="dark"] textarea { background-color: var(--surface); color: var(--ink); }

/* W3: snooze / schedule send / unsubscribe ---------------------------------- */
.send-split { display: inline-flex; }
.send-split #compose-send { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.send-split .send-more {
  border-top-left-radius: 0; border-bottom-left-radius: 0; padding-left: 9px; padding-right: 9px;
  border-left: 1px solid rgba(255, 255, 255, 0.35); min-width: 0;
}
:root[data-theme-effective="dark"] .send-split .send-more { border-left-color: rgba(0, 0, 0, 0.3); }
.row-when { color: var(--green); font-weight: 600; }
.row-when.failed { color: var(--red); }
.job-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 10px 18px 0; padding: 10px 14px; border-radius: var(--radius-md);
  background: var(--green-soft); color: var(--ink); font-size: 13.5px;
}
.job-banner .job-text { flex: 1 1 auto; }
.job-banner .text-button { color: var(--green); font-weight: 600; }
.unsub-chip {
  flex: none; margin-left: 8px; padding: 2px 10px; border-radius: var(--radius-pill);
  border: 1px solid var(--line-strong); background: transparent; color: var(--ink-soft);
  font-size: 12px; font-weight: 600; cursor: pointer; line-height: 20px;
}
.unsub-chip:hover { background: var(--surface-hover); color: var(--ink); }
.unsub-chip.done { cursor: default; color: var(--green); border-color: var(--green-soft); }
.when-field { display: grid; gap: 6px; margin: 4px 0 6px; font-size: 13px; color: var(--ink-soft); }
.when-field input {
  height: var(--control-h); padding: 0 10px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.when-error { min-height: 1em; color: var(--red); font-size: 12.5px; margin: 0 0 10px; }
:root[data-theme-effective="dark"] .composer-header { background: #23302b; color: var(--ink); }
:root[data-theme-effective="dark"] .composer-header .icon-button { color: var(--ink-soft); }
:root[data-theme-effective="dark"] .composer-header .icon-button:hover { background: rgba(255,255,255,0.08); color: var(--ink); }
.menu { min-width: 230px; }
.menu-item.has-hint { display: flex; align-items: baseline; gap: 16px; }
.menu-hint { margin-left: auto; color: var(--ink-faint); font-size: 12px; white-space: nowrap; }
