:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --danger: #dc2626;
  --unread-bg: #eef2ff;
  --checked-bg: #e0e7ff;
  --focus-ring: rgba(79, 70, 229, 0.16);
  --md-code-bg: #f1f5f9;
  --md-code-text: #0f172a;
  --md-quote-border: #cbd5e1;
  --md-toolbar-active: #e0e7ff;
  --md-preview-bg: #ffffff;
  --md-preview-text: #1e293b;
  --md-preview-link: #4f46e5;
  --md-sig-divider: #cbd5e1;
  --warn: #d97706;
  --drop-overlay-bg: rgba(79, 70, 229, 0.08);
  --att-badge-bg: #eef2ff;
  --att-badge-text: #4338ca;
  --bcc-tint: #f8fafc;

  --toast-bg: #0f172a;          /* Inverted high-contrast dark surface in light mode */
  --toast-fg: #f8fafc;
  --toast-muted: #94a3b8;
  --toast-border: #1e293b;
  --toast-btn-bg: #4f46e5;
  --toast-btn-fg: #ffffff;
  --toast-btn-hover: #6366f1;
  --toast-track: rgba(255, 255, 255, 0.14);
  --toast-warn: #f59e0b;
  --toast-ok: #10b981;
  --toast-shadow: 0 14px 36px rgba(15, 23, 42, 0.28);
  --chip-op-bg: #eef2ff;
  --chip-op-border: #c7d2fe;
  --chip-op-key: #4338ca;
  --chip-op-val: #0f172a;
  --chip-neg-bg: #fef2f2;
  --chip-neg-border: #fecaca;
  --chip-neg-key: #b91c1c;
  --chip-date-bg: #f0fdfa;
  --chip-date-border: #99f6e4;
  --chip-date-key: #0f766e;
  --chip-warn-bg: #fffbeb;
  --chip-warn-border: #fde68a;
  --chip-warn-text: #92400e;
  --chip-rm-hover: rgba(15, 23, 42, 0.08);
  --popover-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);

  /* Plan 09: elevation, scrim, danger/warn surfaces, palette highlight */
  --scrim: rgba(15, 23, 42, 0.52);
  --surface-elevated: #ffffff;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #92400e;
  --kbd-bg: #f1f5f9;
  --kbd-border: #cbd5e1;
  --match-bg: rgba(79, 70, 229, 0.14);
  --match-text: #3730a3;
  --shadow-modal: 0 24px 64px -12px rgba(15, 23, 42, 0.28), 0 0 0 1px var(--border);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1f2937;
  --border: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --unread-bg: #1e1b4b;
  --checked-bg: #312e81;
  --focus-ring: rgba(99, 102, 241, 0.28);
  --md-code-bg: #1e293b;
  --md-code-text: #e2e8f0;
  --md-quote-border: #475569;
  --md-toolbar-active: #312e81;
  --md-preview-bg: #0f172a;
  --md-preview-text: #e2e8f0;
  --md-preview-link: #818cf8;
  --md-sig-divider: #334155;
  --warn: #f59e0b;
  --drop-overlay-bg: rgba(99, 102, 241, 0.16);
  --att-badge-bg: #1e1b4b;
  --att-badge-text: #a5b4fc;
  --bcc-tint: #0f172a;

  --toast-bg: #1e293b;          /* Elevated slate surface distinct from #0b1120 / #111827 */
  --toast-fg: #f8fafc;
  --toast-muted: #cbd5e1;
  --toast-border: #334155;
  --toast-btn-bg: #6366f1;
  --toast-btn-fg: #ffffff;
  --toast-btn-hover: #818cf8;
  --toast-track: rgba(255, 255, 255, 0.16);
  --toast-warn: #fbbf24;
  --toast-ok: #34d399;
  --toast-shadow: 0 18px 44px rgba(0, 0, 0, 0.65);
  --chip-op-bg: #1e1b4b;
  --chip-op-border: #3730a3;
  --chip-op-key: #a5b4fc;
  --chip-op-val: #f1f5f9;
  --chip-neg-bg: #450a0a;
  --chip-neg-border: #991b1b;
  --chip-neg-key: #fca5a5;
  --chip-date-bg: #042f2e;
  --chip-date-border: #115e59;
  --chip-date-key: #5eead4;
  --chip-warn-bg: #451a03;
  --chip-warn-border: #92400e;
  --chip-warn-text: #fcd34d;
  --chip-rm-hover: rgba(255, 255, 255, 0.12);
  --popover-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);

  /* Plan 09 */
  --scrim: rgba(2, 6, 23, 0.76);
  --surface-elevated: #111827;
  --danger-hover: #dc2626;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --danger-border: rgba(239, 68, 68, 0.35);
  --danger-text: #fca5a5;
  --warn-soft: rgba(245, 158, 11, 0.12);
  --warn-border: rgba(245, 158, 11, 0.35);
  --warn-text: #fcd34d;
  --kbd-bg: #1f2937;
  --kbd-border: #374151;
  --match-bg: rgba(129, 140, 248, 0.24);
  --match-text: #c7d2fe;
  --shadow-modal: 0 24px 64px -12px rgba(0, 0, 0, 0.65), 0 0 0 1px var(--border);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; text-decoration: none; }

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.shell-split { grid-template-columns: 230px minmax(360px, 1fr) minmax(420px, 1.15fr); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px 10px; gap: 8px; position: sticky; top: 0; height: 100vh; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px; }
.brand-link { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: -0.5px; }
.brand-icon-sm { width: 28px; height: 28px; border-radius: 7px; }
.brand-icon { width: 56px; height: 56px; border-radius: 14px; }

.nav-heading { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 6px 8px 0; }
.nav-section { display: flex; flex-direction: column; gap: 2px; }
.nav-domains { overflow-y: auto; flex: 1; }
.nav-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; border-radius: 8px; color: var(--text); font-weight: 500; font-size: 13px; }
.nav-item:hover { background: var(--surface-alt); }
.nav-item.active { background: var(--unread-bg); color: var(--accent); font-weight: 600; }
.domain-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.badge { background: var(--surface-alt); color: var(--text); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.nav-item.active .badge { background: var(--accent); color: #fff; }
.sidebar-footer { display: flex; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); flex-wrap: wrap; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.search-form { flex: 1; }
.search-input { width: 100%; max-width: 560px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px; outline: none; }
.search-input:focus { border-color: var(--accent); background: var(--surface); }

/* --- Plan 05: advanced search shell, chips, popover, summary bar --- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.search-shell { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 680px; min-height: 36px; padding: 3px 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); cursor: text; }
.search-shell:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.search-icon { font-size: 13px; opacity: 0.6; flex-shrink: 0; }
.search-chips-inline { display: contents; }
.search-shell .search-input { flex: 1 1 140px; min-width: 120px; max-width: none; padding: 4px 2px; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.search-shell .search-input:focus { border: 0; background: transparent; }
.search-shell .search-input::-webkit-search-cancel-button { display: none; }
.search-kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; font-weight: 700; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 2px 5px; background: var(--surface); flex-shrink: 0; }
.search-shell:focus-within .search-kbd { display: none; }
.search-clear { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 999px; color: var(--muted); font-size: 12px; flex-shrink: 0; }
.search-clear:hover { background: var(--chip-rm-hover); color: var(--text); }

.search-chip { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 6px 0 8px; border-radius: 6px; font-size: 12px; line-height: 1; white-space: nowrap; border: 1px solid var(--chip-op-border); background: var(--chip-op-bg); color: var(--chip-op-val); cursor: pointer; max-width: 100%; }
.search-chip .chip-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; font-size: 11px; color: var(--chip-op-key); }
.search-chip .chip-val { font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.search-chip .dot { width: 8px; height: 8px; }
.search-chip.is-neg { background: var(--chip-neg-bg); border-color: var(--chip-neg-border); }
.search-chip.is-neg .chip-key { color: var(--chip-neg-key); }
.search-chip.is-date { background: var(--chip-date-bg); border-color: var(--chip-date-border); }
.search-chip.is-date .chip-key { color: var(--chip-date-key); }
.search-chip.is-text { background: var(--surface-alt); border-color: var(--border); }
.search-chip.is-scope { border-style: solid; box-shadow: inset 0 0 0 1px var(--chip-op-border); }
.search-chip.is-invalid { background: var(--chip-warn-bg); border: 1px dashed var(--chip-warn-border); color: var(--chip-warn-text); }
.search-chip.is-invalid .chip-key, .search-chip.is-invalid .chip-val { color: var(--chip-warn-text); }
.search-chip.is-selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip-warn-icon { font-size: 11px; }
.chip-rm { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; padding: 0; margin-left: 1px; border: 0; border-radius: 999px; background: transparent; color: inherit; font-size: 14px; line-height: 1; cursor: pointer; flex-shrink: 0; }
.chip-rm:hover, .chip-rm:focus-visible { background: var(--chip-rm-hover); outline: none; }

.search-popover { position: absolute; top: calc(100% + 6px); left: 0; width: 100%; z-index: 40; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--popover-shadow); padding: 8px; max-height: min(70vh, 460px); overflow-y: auto; cursor: default; }
.search-popover[hidden] { display: none; }
.popover-heading { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 6px 6px 4px; }
.popover-pills { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.popover-pill { display: inline-flex; align-items: center; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--chip-op-border); background: var(--chip-op-bg); color: var(--chip-op-key); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; font-weight: 700; cursor: pointer; }
.popover-pill.is-date { border-color: var(--chip-date-border); background: var(--chip-date-bg); color: var(--chip-date-key); }
.popover-pill.is-on { background: var(--accent); border-color: var(--accent); color: #fff; }
.popover-pill.active { outline: 2px solid var(--accent); outline-offset: 2px; }
.popover-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; font-size: 12px; }
.popover-item { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 8px; border-radius: 8px; cursor: pointer; color: var(--text); min-width: 0; }
.popover-item:hover, .popover-item.active { background: var(--unread-bg); }
.popover-item.active { box-shadow: inset 2px 0 0 var(--accent); }
.popover-item .item-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; color: var(--chip-op-key); flex-shrink: 0; }
.popover-item .item-desc { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-item .item-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-item .badge { margin-left: auto; }
.popover-empty { padding: 10px 8px; color: var(--muted); font-size: 12px; }
.popover-date { display: flex; align-items: center; gap: 8px; padding: 8px; border-top: 1px solid var(--border); margin-top: 4px; font-size: 12px; color: var(--muted); }
.popover-date input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-family: inherit; font-size: 12px; }

.search-summary-bar { display: flex; flex-direction: column; gap: 6px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--border); font-size: 12px; }
.summary-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.summary-chips .chip-rm { text-decoration: none; }
.summary-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; color: var(--muted); }
.summary-count { color: var(--text); }
.summary-link { color: var(--accent); font-weight: 600; }
.summary-link:hover { text-decoration: underline; }
.summary-clear { margin-left: auto; }
.search-warn { padding: 6px 10px; border-radius: 8px; background: var(--chip-warn-bg); border: 1px solid var(--chip-warn-border); color: var(--chip-warn-text); }
.search-warn code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

.pivot-btn { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 6px; font-size: 13px; color: var(--muted); opacity: 0; transition: opacity 0.12s; vertical-align: middle; }
.reader-meta div:hover .pivot-btn, .reader-badges:hover .pivot-btn, .pivot-btn:focus-visible { opacity: 1; }
.pivot-btn:hover { background: var(--surface-alt); color: var(--accent); }
[data-pivot] { cursor: inherit; }

.mailbox-strip, .thread-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--border); font-size: 12px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

.triage-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 7px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 53px; z-index: 15; }
.triage-left, .triage-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sel-count { font-size: 12px; color: var(--muted); margin-left: 4px; font-weight: 600; }
.check-wrap { display: inline-flex; align-items: center; justify-content: center; padding: 2px; cursor: pointer; }
.check-wrap input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.msg-list { display: flex; flex-direction: column; }
.msg-row { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; padding: 7px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.msg-row:hover, .msg-row.selected { background: var(--surface-alt); }
.msg-row.checked { background: var(--checked-bg); }
.msg-row.unread { background: var(--unread-bg); }
.msg-row.unread .msg-sender, .msg-row.unread .msg-subject { font-weight: 700; }

.row-link { display: grid; grid-template-columns: 128px 175px 1fr; align-items: center; gap: 10px; min-width: 0; padding: 2px 0; }
.shell-split .row-link { grid-template-columns: 98px 1fr; }
.shell-split .msg-sender { display: none; }
.msg-subject { font-weight: 500; }
.msg-snippet { color: var(--muted); font-weight: 400; }
.att-icon { margin-right: 4px; font-size: 12px; }
.thread-badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 999px; background: var(--surface-alt); color: var(--muted); margin-left: 4px; }

.row-right { display: flex; align-items: center; gap: 8px; }
.row-actions { display: none; align-items: center; gap: 4px; }
.msg-row:hover .row-actions, .msg-row.selected .row-actions { display: flex; }
.msg-row:hover .msg-meta, .msg-row.selected .msg-meta { display: none; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 2px 7px; font-size: 12px; cursor: pointer; color: var(--text); }
.icon-btn:hover { background: var(--surface-alt); }
.icon-btn.starred { color: #f59e0b; border-color: #fcd34d; }
.icon-btn.danger:hover { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }

.msg-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.star { color: #f59e0b; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { padding: 48px 24px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; }
.pager-info { font-size: 12px; color: var(--muted); }

.split-reader { border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.split-reader-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.split-reader-content { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.split-reader-content h2 { margin: 8px 0; font-size: 18px; }
.split-reply { border-top: 1px solid var(--border); padding-top: 12px; }

.img-banner { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-radius: 8px; background: #fef3c7; color: #92400e; font-size: 12px; }

.pill { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff; }
.hue-0  { background: #4f46e5; }
.hue-1  { background: #0d9488; }
.hue-2  { background: #2563eb; }
.hue-3  { background: #7c3aed; }
.hue-4  { background: #db2777; }
.hue-5  { background: #d97706; }
.hue-6  { background: #059669; }
.hue-7  { background: #0284c7; }
.hue-8  { background: #dc2626; }
.hue-9  { background: #475569; }
.hue-10 { background: #9333ea; }
.hue-11 { background: #0891b2; }

.btn { display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font-weight: 600; font-size: 13px; cursor: pointer; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.btn-full { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-alt); }

.alert { margin: 12px 16px; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alert-err { background: #fee2e2; color: #991b1b; }
.alert-warn { background: #fef3c7; color: #92400e; }
.alert-ok { background: #dcfce7; color: #166534; }

.auth-body { display: grid; place-items: center; min-height: 100vh; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 20px; }
.auth-brand h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -1px; }
.auth-divider { text-align: center; margin: 14px 0; font-size: 12px; color: var(--muted); }
.auth-form, .compose-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label, .compose-form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12px; color: var(--muted); }
.compose-form label.toggle-row { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--text); font-weight: 500; }
.auth-form input, .compose-form input, .compose-form select, .compose-form textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; background: var(--bg); color: var(--text);
}

.reader-wrap { max-width: 1020px; margin: 0 auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.reader-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.reader-bar h1 { margin: 0; font-size: 20px; }
.reader-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.reader-card, .reply-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.reader-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.folder-tag { display: inline-flex; align-items: center; gap: 3px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-weight: 500; line-height: 1.4; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--muted); vertical-align: middle; }
.folder-tag::before { content: "▸"; font-size: 9px; opacity: 0.7; }
.msg-content .folder-tag { margin-right: 6px; }
.reader-head h1 { margin: 10px 0 12px; font-size: 20px; }
.reader-meta { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.att-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.att-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); font-size: 12px; font-weight: 600; }
.att-chip:hover { background: var(--unread-bg); border-color: var(--accent); color: var(--accent); }
.att-size { color: var(--muted); font-weight: 400; }
.reader-body { padding-top: 12px; }
.mail-frame { width: 100%; min-height: 460px; border: 0; background: #fff; border-radius: 8px; }
.mail-text { white-space: pre-wrap; font-family: inherit; line-height: 1.6; margin: 0; }
.reply-card h2, .reply-card h1 { margin: 0 0 14px; font-size: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rules-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.rule-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-size: 13px; }
.sig-list { display: flex; flex-direction: column; gap: 6px; }
.sig-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; background: var(--bg); }
.sig-item summary { cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sig-form { margin-top: 12px; }
.muted { color: var(--muted); }

/* --- Markdown compose editor (Plan 01) --- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.from-row { display: flex; align-items: center; gap: 8px; }
.from-row select { flex: 1; min-width: 0; }
.from-pill { flex-shrink: 0; max-width: 40%; }
.field-error { margin: -6px 0 0; font-size: 12px; font-weight: 600; color: var(--danger); }
.md-field { display: flex; flex-direction: column; gap: 5px; }
.md-field-label { font-weight: 600; font-size: 12px; color: var(--muted); }

.md-editor { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg); transition: border-color 0.12s ease, box-shadow 0.12s ease; }
.md-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.md-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px; min-height: 40px; padding: 6px 8px; background: var(--surface-alt); border-bottom: 1px solid var(--border); }
.md-tools, .md-toolbar-end { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.md-tool-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.md-tool-btn { min-width: 30px; height: 28px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; font-family: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; }
.md-tool-btn:hover { background: var(--surface); border-color: var(--border); }
.md-tool-btn:active, .md-tool-btn[aria-pressed="true"] { background: var(--md-toolbar-active); color: var(--accent); }
.md-tool-btn:focus-visible, .seg-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.md-tool-btn:disabled, .md-tool-btn.is-loading { opacity: 0.45; pointer-events: none; }

/* No-JS: toolbar + preview toggle stay hidden; the native radios and textarea still submit. */
.md-editor:not(.js-ready) .md-tools, .md-editor:not(.js-ready) .md-preview-toggle { display: none; }
.md-editor[data-format="plain"] .md-only { display: none; }

.seg-control { display: inline-flex; margin: 0; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-alt); gap: 2px; min-inline-size: 0; }
.compose-form .seg-control label.seg-btn { display: inline-flex; flex-direction: row; align-items: center; gap: 0; font-size: 12px; font-weight: 500; color: var(--muted); border-radius: 5px; cursor: pointer; }
.seg-btn input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg-btn span { padding: 3px 10px; border-radius: 5px; }
.compose-form .seg-control label.seg-btn:hover { color: var(--text); }
.seg-btn input:checked + span { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

.md-split { display: block; }
.compose-form textarea.md-textarea { display: block; width: 100%; min-height: 260px; border: 0; border-radius: 0; resize: vertical; padding: 12px 14px; background: var(--bg); color: var(--text); font-family: inherit; font-size: 14px; line-height: 1.6; outline: none; }
.md-editor[data-format="markdown"] .md-textarea { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 13.5px; line-height: 1.62; tab-size: 2; }

.md-preview-pane { position: relative; background: var(--md-preview-bg); color: var(--md-preview-text); padding: 12px 16px 16px; min-height: 260px; overflow: auto; outline: none; }
.md-preview-pane:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.md-preview-pane.is-loading::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 200% 100%; animation: md-shimmer 1s linear infinite; }
@keyframes md-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.md-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.md-preview-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.md-preview-empty { margin: 48px 0; text-align: center; color: var(--muted); font-style: italic; }
.md-preview-error { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; margin-bottom: 10px; border-radius: 8px; background: #fef3c7; color: #92400e; font-size: 12px; }
.md-preview-pane .md-prose { max-width: 68ch; }
.md-prose { font-size: 14px; line-height: 1.6; }

/* Preview open: split ≥ 960px, tabbed below. */
@media (min-width: 960px) {
  .md-editor.is-preview .md-split { display: grid; grid-template-columns: 1fr 1fr; }
  .md-editor.is-preview .md-preview-pane { border-left: 1px solid var(--border); max-height: 70vh; }
  .md-back-write { display: none; }
}
@media (max-width: 959.98px) {
  .md-editor.is-preview .md-textarea { display: none; }
}

.compose-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.compose-footer .reader-actions { gap: 8px; }
.btn-send { padding: 9px 18px; min-height: 36px; }
.md-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.reply-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.compose-form label.md-inline-toggle { font-size: 12px; color: var(--muted); font-weight: 600; }
.md-inline-toggle input { accent-color: var(--accent); }

@media (pointer: coarse) {
  .md-tool-btn { min-width: 40px; height: 40px; }
  .seg-btn span { padding: 10px 14px; }
}

/* --- Plan 04: Undo Send & Undo Triage --- */
.badge-err { background: var(--danger); color: #fff; }
.link-strong { font-weight: 700; text-decoration: underline; }
.send-hint { font-size: 12px; }

.pending-banner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 12px 16px; padding: 10px 14px; border-radius: 8px; border-left: 3px solid var(--accent); background: var(--unread-bg); color: var(--text); font-size: 13px; }
.reader-wrap .pending-banner { margin: 0; }
.pending-banner[hidden] { display: none; }
.pending-banner-triage { border-left-color: var(--muted); background: var(--surface-alt); }
.pending-banner-err { border-left-color: var(--danger); background: #fee2e2; color: #991b1b; }
.pending-banner-actions { display: flex; gap: 6px; align-items: center; }
.pill-mini { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 5px; color: #fff; vertical-align: baseline; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.outbox-row { grid-template-columns: 74px 1fr auto; }
.outbox-status { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.outbox-failed .outbox-status { color: var(--danger); }
.outbox-pending .outbox-status { color: var(--accent); }
.outbox-row .row-right form { display: inline-flex; }

/* Toast stack: bottom-left, clears the 248px sidebar and never covers the split reader reply box */
.toast-stack { position: fixed; left: 264px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; width: min(420px, calc(100vw - 284px)); pointer-events: none; }
.reader-wrap ~ .toast-stack { left: 20px; width: min(420px, calc(100vw - 40px)); }
.toast { position: relative; pointer-events: auto; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 12px 12px 15px 16px; border-radius: 10px; background: var(--toast-bg); color: var(--toast-fg); border: 1px solid var(--toast-border); box-shadow: var(--toast-shadow); overflow: hidden; font-size: 13px; line-height: 1.4; animation: toast-in 160ms cubic-bezier(0.16, 1, 0.3, 1) both; }
.toast::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--muted); }
.toast-send::before { background: var(--accent); }
.toast-triage::before { background: var(--muted); }
.toast-triage.toast-warn::before { background: var(--toast-warn); }
.toast-triage.toast-danger::before { background: var(--danger); }
.toast-ok::before { background: var(--toast-ok); }
.toast-err::before { background: var(--danger); }
.toast-overflow { display: none; }
.toast-leaving { animation: toast-out 140ms ease-in both; }
.toast-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toast-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-line-sub { color: var(--toast-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.toast-send .toast-line:first-child::before { content: "\27A4"; display: inline-block; margin-right: 6px; color: var(--toast-btn-hover); }
.toast-actions { display: flex; align-items: center; gap: 6px; }
.toast-undo-btn { min-height: 32px; padding: 6px 12px; border: 0; border-radius: 999px; background: var(--toast-btn-bg); color: var(--toast-btn-fg); font-weight: 700; font-size: 12px; cursor: pointer; white-space: nowrap; }
.toast-undo-btn:hover, .toast-undo-btn:focus-visible { background: var(--toast-btn-hover); }
.toast-link { border: 0; background: transparent; color: var(--toast-fg); text-decoration: underline; font-size: 12px; font-weight: 600; cursor: pointer; padding: 6px 4px; white-space: nowrap; }
.toast-link:hover { color: var(--toast-btn-hover); }
.toast-dismiss { border: 0; background: transparent; color: var(--toast-muted); font-size: 14px; line-height: 1; cursor: pointer; padding: 6px; border-radius: 6px; }
.toast-dismiss:hover, .toast-dismiss:focus-visible { color: var(--toast-fg); background: var(--toast-track); }
.toast button:focus-visible { outline: 2px solid var(--toast-btn-hover); outline-offset: 2px; }
.toast button[disabled] { opacity: 0.6; cursor: default; }

.toast-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--toast-track); }
.toast-progress-bar { height: 100%; background: var(--toast-btn-hover); transform-origin: left center; transform: scaleX(1); }
.toast-triage .toast-progress-bar { background: var(--toast-muted); }
.toast-triage.toast-warn .toast-progress-bar { background: var(--toast-warn); }
.toast-triage.toast-danger .toast-progress-bar { background: var(--danger); }
.toast-progress-bar.dur-5 { animation: toast-countdown 5s linear forwards; }
.toast-progress-bar.dur-10 { animation: toast-countdown 10s linear forwards; }
.toast-progress-bar.dur-15 { animation: toast-countdown 15s linear forwards; }
.toast-progress-bar.dur-30 { animation: toast-countdown 30s linear forwards; }
.toast-progress-bar.done { animation: none; transform: scaleX(0); }

@keyframes toast-countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(6px); } }

.msg-row.row-restored { animation: row-restored 600ms ease-out; }
@keyframes row-restored { from { background: var(--checked-bg); box-shadow: inset 3px 0 0 var(--accent); } to { box-shadow: inset 3px 0 0 transparent; } }

.modal { border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--toast-shadow); width: min(440px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(15, 23, 42, 0.45); }
.modal-form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-form h2 { margin: 0; font-size: 16px; }
.modal-form p { margin: 0; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  .toast { animation: toast-fade 120ms linear both; }
  .toast-leaving { animation: none; opacity: 0; }
  .toast-progress-bar.dur-5 { animation-timing-function: steps(5, end); }
  .toast-progress-bar.dur-10 { animation-timing-function: steps(10, end); }
  .toast-progress-bar.dur-15 { animation-timing-function: steps(15, end); }
  .toast-progress-bar.dur-30 { animation-timing-function: steps(30, end); }
  .msg-row.row-restored { animation: none; background: var(--checked-bg); }
  @keyframes toast-fade { from { opacity: 0; } to { opacity: 1; } }
}

@media (max-width: 1024px) {
  .shell-split { grid-template-columns: 220px 1fr; }
  .split-reader { position: static; height: auto; border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 820px) {
  .shell, .shell-split { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .row-link { grid-template-columns: 110px 1fr; }
  .msg-sender { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .toast-stack, .reader-wrap ~ .toast-stack { left: 16px; right: 16px; bottom: 16px; width: auto; }
  .outbox-row { grid-template-columns: 1fr; }
}

/* --- Plan 02: Bcc, inline cid: images, drag-and-drop attachments --- */
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.field-with-toggle { display: flex; align-items: flex-end; gap: 8px; }
.field-with-toggle .field-grow { flex: 1; min-width: 0; }
.pill-btn { flex-shrink: 0; margin-bottom: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; }
.pill-btn:hover, .pill-btn:focus-visible { color: var(--accent); border-color: var(--accent); }
.pill-btn[aria-expanded="true"] { background: var(--unread-bg); color: var(--accent); border-color: var(--accent); }
.compose-form .bcc-input { background: var(--bcc-tint); border-style: dashed; }
.bcc-lock { margin-left: 6px; font-size: 11px; font-weight: 500; color: var(--muted); }
.bcc-row.is-revealing { animation: bcc-reveal 150ms ease-out; }
@keyframes bcc-reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.meta-bcc { color: var(--muted); }

.compose-card { position: relative; }
.drop-overlay { position: absolute; inset: 6px; z-index: 30; display: flex; align-items: center; justify-content: center; border: 2px dashed var(--accent); border-radius: 10px; background: var(--drop-overlay-bg); pointer-events: none; }
.drop-overlay-msg { padding: 10px 16px; border-radius: 8px; background: var(--surface); color: var(--accent); font-weight: 700; font-size: 14px; box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12); }

.att-dropzone { display: flex; flex-direction: column; gap: 10px; border: 1.5px dashed var(--border); border-radius: 10px; padding: 12px 14px; background: var(--bg); transition: border-color 150ms, background 150ms; }
.att-dropzone.is-dragover { border-style: solid; border-color: var(--accent); background: var(--drop-overlay-bg); }
.att-dropzone.is-error { border-style: solid; border-color: var(--danger); }
.att-dropzone-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.att-dropzone.js-dnd .att-native-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.att-staged-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.att-staged-list:empty { display: none; }
.att-staged-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); max-width: 100%; position: relative; }
.att-staged-chip.is-uploading { opacity: 0.7; }
.att-staged-chip.is-error { border-color: var(--danger); }
.att-thumb { width: 32px; height: 32px; border-radius: 4px; object-fit: cover; flex-shrink: 0; background: var(--surface-alt); }
.att-badge { width: 32px; height: 32px; border-radius: 4px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; font-weight: 700; background: var(--att-badge-bg); color: var(--att-badge-text); }
.att-badge-pdf { background: #fee2e2; color: #b91c1c; }
.att-badge-zip { background: #fef3c7; color: #92400e; }
.att-badge-csv { background: #dcfce7; color: #166534; }
.att-badge-doc { background: #dbeafe; color: #1d4ed8; }
[data-theme="dark"] .att-badge-pdf { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .att-badge-zip { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .att-badge-csv { background: #052e16; color: #86efac; }
[data-theme="dark"] .att-badge-doc { background: #172554; color: #93c5fd; }
.att-info { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.att-name { font-size: 12px; font-weight: 600; color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-sub { font-size: 11px; color: var(--muted); }
.att-inline-pill { display: inline-block; padding: 0 6px; border-radius: 999px; background: var(--unread-bg); color: var(--accent); font-weight: 700; }
.att-error-text { color: var(--danger); font-weight: 600; }
.att-actions { display: inline-flex; align-items: center; gap: 4px; }
.att-act { border: 1px solid var(--border); background: transparent; color: var(--text); border-radius: 6px; padding: 2px 7px; font-size: 11px; font-weight: 600; cursor: pointer; }
.att-act:hover, .att-act:focus-visible { border-color: var(--accent); color: var(--accent); }
.att-remove { font-size: 14px; line-height: 1; padding: 2px 6px; }
.att-remove:hover, .att-remove:focus-visible { border-color: var(--danger); color: var(--danger); }
.att-progress { position: absolute; left: 6px; right: 6px; bottom: 2px; height: 2px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.att-progress-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width 150ms linear; }

.att-meter { height: 4px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.att-meter-fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width 150ms ease, background-color 150ms ease; }
.att-meter.is-warn .att-meter-fill { background: var(--warn); }
.att-meter.is-over .att-meter-fill { background: var(--danger); }
.att-meter-label { font-size: 11px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.att-meter-label.is-over { color: var(--danger); font-weight: 700; }
.att-alert { font-size: 12px; padding: 6px 10px; border-radius: 6px; background: #fee2e2; color: #991b1b; }
.att-alert.is-info { background: var(--unread-bg); color: var(--accent); }
.att-nudge { font-size: 12px; padding: 6px 10px; border-radius: 6px; background: #fef3c7; color: #92400e; }
[data-theme="dark"] .att-nudge { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .att-alert { background: #450a0a; color: #fca5a5; }

.inline-preview { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.inline-preview figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 140px; }
.inline-preview img { max-width: 140px; max-height: 96px; border-radius: 6px; object-fit: contain; background: var(--surface-alt); }
.inline-preview figcaption { font-size: 11px; color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.inline-att-footer { padding-top: 10px; font-size: 12px; color: var(--muted); }
.inline-att-footer summary { cursor: pointer; width: max-content; }
.att-bar-inline { border-bottom: 0; padding-bottom: 0; }

/* ===== Plan 03: Cross-domain tags & custom IMAP folders ===== */

/* Light theme tag tokens (WCAG AA >= 4.5:1 text-on-tint) */
:root {
  --tag-0-bg: #eef2ff;  --tag-0-fg: #3730a3;  --tag-0-bd: #c7d2fe;  /* Indigo */
  --tag-1-bg: #f0fdfa;  --tag-1-fg: #115e59;  --tag-1-bd: #99f6e4;  /* Teal */
  --tag-2-bg: #eff6ff;  --tag-2-fg: #1d4ed8;  --tag-2-bd: #bfdbfe;  /* Blue */
  --tag-3-bg: #f5f3ff;  --tag-3-fg: #5b21b6;  --tag-3-bd: #ddd6fe;  /* Violet */
  --tag-4-bg: #fdf2f8;  --tag-4-fg: #9d174d;  --tag-4-bd: #fbcfe8;  /* Pink */
  --tag-5-bg: #fffbeb;  --tag-5-fg: #92400e;  --tag-5-bd: #fde68a;  /* Amber */
  --tag-6-bg: #ecfdf5;  --tag-6-fg: #065f46;  --tag-6-bd: #a7f3d0;  /* Emerald */
  --tag-7-bg: #f0f9ff;  --tag-7-fg: #075985;  --tag-7-bd: #bae6fd;  /* Sky */
  --tag-8-bg: #fef2f2;  --tag-8-fg: #991b1b;  --tag-8-bd: #fecaca;  /* Crimson */
  --tag-9-bg: #f1f5f9;  --tag-9-fg: #334155;  --tag-9-bd: #cbd5e1;  /* Slate */
  --tag-10-bg: #faf5ff; --tag-10-fg: #6b21a8; --tag-10-bd: #e9d5ff; /* Purple */
  --tag-11-bg: #ecfeff; --tag-11-fg: #155e75; --tag-11-bd: #a5f3fc; /* Cyan */

  --popover-bg: #ffffff;
  --popover-shadow: 0 12px 32px rgba(15, 23, 42, 0.14), 0 2px 6px rgba(15, 23, 42, 0.06);
  --folder-tree-indent: 14px;
}

/* Dark theme tag tokens (WCAG AA >= 4.5:1 on #111827 / #1e1b4b) */
[data-theme="dark"] {
  --tag-0-bg: rgba(99, 102, 241, 0.18);  --tag-0-fg: #c7d2fe;  --tag-0-bd: rgba(129, 140, 248, 0.40);
  --tag-1-bg: rgba(20, 184, 166, 0.18);  --tag-1-fg: #99f6e4;  --tag-1-bd: rgba(45, 212, 191, 0.40);
  --tag-2-bg: rgba(59, 130, 246, 0.18);  --tag-2-fg: #bfdbfe;  --tag-2-bd: rgba(96, 165, 250, 0.40);
  --tag-3-bg: rgba(139, 92, 246, 0.18);  --tag-3-fg: #ddd6fe;  --tag-3-bd: rgba(167, 139, 250, 0.40);
  --tag-4-bg: rgba(236, 72, 153, 0.18);  --tag-4-fg: #fbcfe8;  --tag-4-bd: rgba(244, 114, 182, 0.40);
  --tag-5-bg: rgba(245, 158, 11, 0.18);  --tag-5-fg: #fde68a;  --tag-5-bd: rgba(251, 191, 36, 0.40);
  --tag-6-bg: rgba(16, 185, 129, 0.18);  --tag-6-fg: #a7f3d0;  --tag-6-bd: rgba(52, 211, 153, 0.40);
  --tag-7-bg: rgba(14, 165, 233, 0.18);  --tag-7-fg: #bae6fd;  --tag-7-bd: rgba(56, 189, 248, 0.40);
  --tag-8-bg: rgba(239, 68, 68, 0.18);   --tag-8-fg: #fecaca;  --tag-8-bd: rgba(248, 113, 113, 0.40);
  --tag-9-bg: rgba(148, 163, 184, 0.18); --tag-9-fg: #e2e8f0;  --tag-9-bd: rgba(148, 163, 184, 0.35);
  --tag-10-bg: rgba(168, 85, 247, 0.18); --tag-10-fg: #e9d5ff; --tag-10-bd: rgba(192, 132, 252, 0.40);
  --tag-11-bg: rgba(6, 182, 212, 0.18);  --tag-11-fg: #a5f3fc; --tag-11-bd: rgba(34, 211, 238, 0.40);

  --popover-bg: #111827;
  --popover-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px #1e293b;
}

/* Hue classes only set custom properties; chips, dots and swatches consume them. */
.tag-hue-0  { --tag-bg: var(--tag-0-bg);  --tag-fg: var(--tag-0-fg);  --tag-bd: var(--tag-0-bd); }
.tag-hue-1  { --tag-bg: var(--tag-1-bg);  --tag-fg: var(--tag-1-fg);  --tag-bd: var(--tag-1-bd); }
.tag-hue-2  { --tag-bg: var(--tag-2-bg);  --tag-fg: var(--tag-2-fg);  --tag-bd: var(--tag-2-bd); }
.tag-hue-3  { --tag-bg: var(--tag-3-bg);  --tag-fg: var(--tag-3-fg);  --tag-bd: var(--tag-3-bd); }
.tag-hue-4  { --tag-bg: var(--tag-4-bg);  --tag-fg: var(--tag-4-fg);  --tag-bd: var(--tag-4-bd); }
.tag-hue-5  { --tag-bg: var(--tag-5-bg);  --tag-fg: var(--tag-5-fg);  --tag-bd: var(--tag-5-bd); }
.tag-hue-6  { --tag-bg: var(--tag-6-bg);  --tag-fg: var(--tag-6-fg);  --tag-bd: var(--tag-6-bd); }
.tag-hue-7  { --tag-bg: var(--tag-7-bg);  --tag-fg: var(--tag-7-fg);  --tag-bd: var(--tag-7-bd); }
.tag-hue-8  { --tag-bg: var(--tag-8-bg);  --tag-fg: var(--tag-8-fg);  --tag-bd: var(--tag-8-bd); }
.tag-hue-9  { --tag-bg: var(--tag-9-bg);  --tag-fg: var(--tag-9-fg);  --tag-bd: var(--tag-9-bd); }
.tag-hue-10 { --tag-bg: var(--tag-10-bg); --tag-fg: var(--tag-10-fg); --tag-bd: var(--tag-10-bd); }
.tag-hue-11 { --tag-bg: var(--tag-11-bg); --tag-fg: var(--tag-11-fg); --tag-bd: var(--tag-11-bd); }

.tag-chip {
  display: inline-flex; align-items: center; gap: 5px; vertical-align: middle;
  font-size: 11px; font-weight: 600; line-height: 1.4; padding: 1px 7px; border-radius: 999px;
  background: var(--tag-bg, var(--surface-alt)); color: var(--tag-fg, var(--muted)); border: 1px solid var(--tag-bd, var(--border));
  white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
a.tag-chip:hover, .tag-chip[data-tag-slug]:hover { filter: brightness(0.96); text-decoration: underline; }
.tag-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--tag-fg, currentColor); }
.nav-item .tag-dot { width: 8px; height: 8px; }
.tag-overflow { --tag-bg: var(--surface-alt); --tag-fg: var(--muted); --tag-bd: var(--border); cursor: help; }
.row-tags { display: inline-flex; align-items: center; gap: 4px; margin-right: 6px; vertical-align: middle; }
.row-tags:empty { display: none; }
.reader-tags { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* Sidebar groups */
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 6px; padding-right: 6px; user-select: none; }
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::before { content: "▾"; font-size: 9px; margin-right: 4px; }
.nav-group:not([open]) > summary::before { content: "▸"; }
.nav-group-head > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-add { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 5px; border: 1px solid var(--border); color: var(--muted); font-size: 13px; line-height: 1; text-transform: none; }
.nav-add:hover { background: var(--unread-bg); color: var(--accent); border-color: var(--accent); }
.nav-scroll { max-height: 22vh; overflow-y: auto; }
.nav-empty { font-size: 12px; color: var(--muted); padding: 4px 10px; }
kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; padding: 0 4px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-alt); }
.badge-muted { background: transparent; color: var(--muted); font-weight: 500; }

.folder-tree-item { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.folder-glyph { color: var(--muted); font-size: 10px; flex-shrink: 0; }
.folder-group { color: var(--muted); cursor: default; }
.folder-group:hover { background: transparent; }
.depth-0 { padding-left: 10px; }
.depth-1 { padding-left: calc(10px + var(--folder-tree-indent) * 1); }
.depth-2 { padding-left: calc(10px + var(--folder-tree-indent) * 2); }
.depth-3 { padding-left: calc(10px + var(--folder-tree-indent) * 3); }
.depth-4 { padding-left: calc(10px + var(--folder-tree-indent) * 4); }
.depth-5 { padding-left: calc(10px + var(--folder-tree-indent) * 5); }

.folder-strip { padding-top: 6px; padding-bottom: 6px; }
.folder-strip-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.chip-folder { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; padding: 2px 8px; border-radius: 4px; }
.chip-group { color: var(--muted); border-style: dashed; cursor: default; }

.view-context { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 16px; font-size: 12px; background: var(--bg); border-bottom: 1px solid var(--border); }

/* Shared Tag / Move popover surface (native <dialog>: no inline styles, focus trapped) */
.action-popover {
  width: 280px; max-width: calc(100vw - 24px); padding: 0; border-radius: 12px;
  background: var(--popover-bg); color: var(--text); border: 1px solid var(--border); box-shadow: var(--popover-shadow);
  z-index: 60; overflow: hidden;
}
.action-popover[open] { display: flex; flex-direction: column; }
.action-popover::backdrop { background: rgba(15, 23, 42, 0.18); }
[data-theme="dark"] .action-popover::backdrop { background: rgba(0, 0, 0, 0.45); }
.popover-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; }
.popover-title { font-weight: 700; font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-sub { font-size: 11px; color: var(--muted); }
.popover-head .pill { max-width: 150px; font-size: 10px; padding: 2px 6px; }
.popover-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 4px; }
.popover-close:hover { background: var(--surface-alt); color: var(--text); }
.popover-search {
  position: sticky; top: 0; height: 36px; font-size: 13px; margin: 0 10px 6px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); outline: none; font-family: inherit;
}
.popover-search:focus { border-color: var(--accent); background: var(--surface); }
.popover-list { list-style: none; margin: 0; padding: 2px 6px; max-height: 260px; overflow-y: auto; }
.popover-item {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 4px 8px; border-radius: 6px;
  font-size: 13px; color: var(--text); background: transparent; border: 0; text-align: left; cursor: pointer; font-family: inherit;
}
.popover-item:hover { background: var(--surface-alt); }
.popover-item.active { background: var(--unread-bg); box-shadow: inset 0 0 0 2px var(--accent); }
.popover-item[aria-disabled="true"] { color: var(--muted); cursor: default; font-size: 12px; }
.popover-item[aria-disabled="true"]:hover { background: transparent; }
.popover-item.is-current { color: var(--muted); }
.popover-item .item-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover-item .item-count { font-size: 11px; color: var(--muted); font-weight: 600; }
.popover-item.folder-tree-item { font-size: 12px; }
.popover-item.depth-0 { padding-left: 8px; }
.popover-sep { height: 1px; margin: 4px 6px; background: var(--border); list-style: none; }
.popover-check {
  width: 15px; height: 15px; border-radius: 4px; border: 1.5px solid var(--muted); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; line-height: 1; color: #fff;
}
.popover-item[aria-checked="true"] .popover-check { background: var(--accent); border-color: var(--accent); }
.popover-item[aria-checked="true"] .popover-check::after { content: "✓"; }
.popover-item[aria-checked="mixed"] .popover-check { background: var(--accent); border-color: var(--accent); }
.popover-item[aria-checked="mixed"] .popover-check::after { content: "–"; }
.popover-footer { border-top: 1px solid var(--border); padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.popover-create { font-weight: 600; color: var(--accent); }
.popover-note { margin: 0 8px 4px; font-size: 11px; color: var(--muted); }
.popover-banner { margin: 0 10px 6px; padding: 6px 8px; border-radius: 6px; font-size: 12px; background: var(--surface-alt); color: var(--text); }
.popover-banner-warn { background: #fef3c7; color: #92400e; }
.popover-hint { font-size: 10px; color: var(--muted); padding: 4px 12px 2px; border-top: 1px solid var(--border); }
.popover-status { font-size: 12px; padding: 2px 12px 8px; min-height: 8px; color: var(--muted); }
.popover-status.is-error { color: var(--danger); }
.popover-status.is-ok { color: #15803d; }

.swatch-grid { display: grid; grid-template-columns: repeat(6, 22px); gap: 6px; padding: 2px 8px 4px; }
.swatch-grid-inline { display: inline-grid; grid-template-columns: repeat(12, 18px); gap: 4px; padding: 0; }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--surface); background: var(--tag-fg); box-shadow: 0 0 0 1px var(--tag-bd); cursor: pointer; padding: 0; }
button.swatch { width: 22px; height: 22px; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--accent); }
.swatch-radio { display: inline-flex; position: relative; cursor: pointer; }
.swatch-radio input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.swatch-radio input:checked + .swatch { box-shadow: 0 0 0 2px var(--accent); }
.swatch-radio input:focus-visible + .swatch { outline: 2px solid var(--accent); outline-offset: 2px; }

.move-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 12px; }
.move-form-label { font-weight: 600; color: var(--muted); }
.move-select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; max-width: 280px; }
.move-form-warn { color: #92400e; background: #fef3c7; padding: 3px 8px; border-radius: 6px; }

.rule-custom-folder input { max-width: 360px; }
.tag-manage-row { flex-wrap: wrap; }
.tag-edit-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; flex: 1; }
.tag-name-input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 13px; width: 160px; }
.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-weight: 600; font-size: 12px; color: var(--muted); }

@media (max-width: 820px) {
  .swatch-grid-inline { grid-template-columns: repeat(6, 18px); }
  .tag-chip { max-width: 110px; }
}
@media (hover: none) {
  .pivot-btn { opacity: 1; }
}

/* =====================================================================
   Plan 06: Snooze & Scheduled Send
   ===================================================================== */
:root {
  --snooze-bg: #fffbeb;
  --snooze-border: #fde68a;
  --snooze-text: #92400e;
  --sched-bg: #eff6ff;
  --sched-border: #bfdbfe;
  --sched-text: #1d4ed8;
  --wake-glow: #fef3c7;
  --popover-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
}
[data-theme="dark"] {
  --snooze-bg: #422006;
  --snooze-border: #854d0e;
  --snooze-text: #fde047;
  --sched-bg: #172554;
  --sched-border: #1d4ed8;
  --sched-text: #93c5fd;
  --wake-glow: #451a03;
  --popover-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
}

/* Sidebar counts */
.badge-snooze { background: var(--snooze-bg); color: var(--snooze-text); border: 1px solid var(--snooze-border); }
.badge-sched { background: var(--sched-bg); color: var(--sched-text); border: 1px solid var(--sched-border); }
.badge[hidden] { display: none; }
.nav-item.active .badge-snooze, .nav-item.active .badge-sched { border-color: transparent; }
.alert-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); vertical-align: middle; margin-left: 2px; }

/* Countdown / wake-up badges */
.time-badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; border: 1px solid transparent;
}
.time-badge.is-snooze { background: var(--snooze-bg); color: var(--snooze-text); border-color: var(--snooze-border); }
.time-badge.is-sched { background: var(--sched-bg); color: var(--sched-text); border-color: var(--sched-border); }
.time-badge.is-warn { background: var(--snooze-bg); color: var(--snooze-text); border-color: var(--snooze-border); }
.time-badge.is-err { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
[data-theme="dark"] .time-badge.is-err { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
.reader-badges .time-badge { font-size: 11px; }

.msg-row.is-snoozed { background: color-mix(in srgb, var(--snooze-bg) 45%, var(--surface)); }
.msg-row.is-woken { box-shadow: inset 3px 0 0 var(--snooze-border); background: color-mix(in srgb, var(--wake-glow) 40%, var(--unread-bg)); }
.woken-chip {
  display: inline-flex; align-items: center; padding: 0 6px; margin-right: 4px; border-radius: 999px; font-size: 10px; font-weight: 700;
  background: var(--snooze-bg); color: var(--snooze-text); border: 1px solid var(--snooze-border); white-space: nowrap; font-variant-numeric: tabular-nums;
}
.woken-chip[hidden] { display: none; }
.row-actions form[data-unsnooze] { display: inline-flex; }
.unsnooze-btn { color: var(--snooze-text); border-color: var(--snooze-border); background: var(--snooze-bg); }

/* Scheduled view rows */
.sched-row { grid-template-columns: 26px 1fr auto; }
.sched-icon { text-align: center; font-size: 14px; }
.sched-right { gap: 10px; }
.sched-actions { display: flex; align-items: center; gap: 4px; }
.sched-actions form { display: inline-flex; }
.sched-failed { background: color-mix(in srgb, #fee2e2 35%, var(--surface)); }
.sched-awaiting_vault { background: color-mix(in srgb, var(--snooze-bg) 40%, var(--surface)); }
[data-theme="dark"] .sched-failed { background: color-mix(in srgb, #450a0a 45%, var(--surface)); }
.pending-banner-sched { border-left-color: var(--sched-text); background: var(--sched-bg); color: var(--text); }
.alert-snooze { background: var(--snooze-bg); color: var(--snooze-text); border: 1px solid var(--snooze-border); }

/* Snooze & Schedule popover (native non-modal <dialog>; positioned via classes + WAAPI) */
.time-popover {
  width: 300px; max-width: calc(100vw - 32px); padding: 0; border-radius: 12px; z-index: 70;
  background: var(--popover-bg, var(--surface)); color: var(--text); border: 1px solid var(--border); box-shadow: var(--popover-shadow);
  overflow: hidden;
}
.time-popover[open] { display: flex; flex-direction: column; }
.time-popover.is-anchored { position: fixed; inset: 0 auto auto 0; margin: 0; }
.time-popover.is-centered { position: fixed; inset: 0; margin: auto; height: fit-content; }
.tz-pill {
  font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 999px; text-decoration: none;
  background: var(--surface-alt); color: var(--muted); border: 1px solid var(--border); font-variant-numeric: tabular-nums;
}
.tz-pill:hover, .tz-pill:focus-visible { color: var(--accent); border-color: var(--accent); }
.tz-nudge { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 10px 6px; padding: 6px 8px; border-radius: 8px; font-size: 12px; background: var(--sched-bg); color: var(--sched-text); }
.tz-nudge[hidden] { display: none; }
.time-presets { list-style: none; margin: 0; padding: 2px 6px 6px; }
.time-preset {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; height: 38px; padding: 0 12px;
  border-radius: 8px; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; cursor: pointer; text-align: left;
}
.time-preset:hover, .time-preset:focus-visible { background: var(--surface-alt); outline: none; }
.time-preset:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.time-popover[data-mode="snooze"] .time-preset:hover { background: var(--snooze-bg); }
.time-popover[data-mode="schedule"] .time-preset:hover { background: var(--sched-bg); }
.time-preset-main { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.time-preset-icon { width: 18px; text-align: center; }
.time-preset-when { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; white-space: nowrap; }
.time-keycap {
  display: none; width: 18px; height: 18px; align-items: center; justify-content: center; border-radius: 4px;
  border: 1px solid var(--border); border-bottom-width: 2px; background: var(--surface-alt); color: var(--muted);
  font-size: 10px; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.time-popover.via-keyboard .time-keycap { display: inline-flex; }
.time-custom { border-top: 1px solid var(--border); padding: 8px 12px 10px; }
.time-custom-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 6px; }
.time-custom-row { display: flex; gap: 6px; align-items: center; }
.time-input { height: 36px; min-width: 0; flex: 1; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; font-size: 12px; }
.time-input:focus { border-color: var(--accent); outline: none; }
.time-custom-row .btn { height: 36px; }

/* Split primary button: [ Send | ▾ Schedule ] */
.split-btn { display: inline-flex; align-items: stretch; }
.split-btn .split-main { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-btn .split-toggle { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255, 255, 255, 0.35); padding-left: 10px; padding-right: 10px; }
.split-btn .split-toggle[hidden] { display: none; }
.split-btn:has(.split-toggle[hidden]) .split-main { border-radius: 8px; }

/* No-JS fallbacks (hidden by app.js once the popover is available) */
.snooze-fallback, .schedule-fallback { margin: 8px 0; font-size: 13px; }
.snooze-fallback summary, .schedule-fallback summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.snooze-fallback-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.snooze-fallback-custom { display: inline-flex; align-items: center; gap: 6px; }
.schedule-fallback label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.tz-row { display: flex; gap: 8px; align-items: center; }
.tz-row input { flex: 1; }

@media (max-width: 640px) {
  .time-popover { width: calc(100vw - 32px); }
  .sched-actions { flex-wrap: wrap; justify-content: flex-end; }
}

/* ---------------------------------------------------------------------------
   Plan 07 — real-time IMAP IDLE push: status pill, health popover, live rows
   --------------------------------------------------------------------------- */
:root {
  --status-live-bg: #dcfce7;
  --status-live-fg: #166534;
  --status-live-dot: #16a34a;

  --status-degraded-bg: #fef3c7;
  --status-degraded-fg: #92400e;
  --status-degraded-dot: #d97706;

  --status-offline-bg: #fee2e2;
  --status-offline-fg: #991b1b;
  --status-offline-dot: #dc2626;

  --status-locked-bg: #f1f5f9;
  --status-locked-fg: #475569;
  --status-locked-dot: #64748b;

  --new-row-flash: #e0e7ff;
  --new-pill-bg: #4f46e5;
  --new-pill-fg: #ffffff;
}

[data-theme="dark"] {
  --status-live-bg: rgba(22, 163, 74, 0.16);
  --status-live-fg: #86efac;
  --status-live-dot: #22c55e;

  --status-degraded-bg: rgba(217, 119, 6, 0.18);
  --status-degraded-fg: #fcd34d;
  --status-degraded-dot: #f59e0b;

  --status-offline-bg: rgba(220, 38, 38, 0.18);
  --status-offline-fg: #fca5a5;
  --status-offline-dot: #ef4444;

  --status-locked-bg: #1f2937;
  --status-locked-fg: #94a3b8;
  --status-locked-dot: #64748b;

  --new-row-flash: rgba(99, 102, 241, 0.22);
  --new-pill-bg: #6366f1;
  --new-pill-fg: #ffffff;
}

.live-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; min-width: 84px; padding: 0 10px;
  margin-left: auto; border: 0; border-radius: 999px; justify-content: center; cursor: pointer; white-space: nowrap;
  font: inherit; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--status-live-bg); color: var(--status-live-fg);
}
.live-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.live-dot { position: relative; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--status-live-dot); }
.live-pill.is-live { background: var(--status-live-bg); color: var(--status-live-fg); }
.live-pill.is-live .live-dot { background: var(--status-live-dot); }
.live-pill.is-degraded { background: var(--status-degraded-bg); color: var(--status-degraded-fg); }
.live-pill.is-degraded .live-dot { background: var(--status-degraded-dot); }
.live-pill.is-offline { background: var(--status-offline-bg); color: var(--status-offline-fg); }
.live-pill.is-offline .live-dot { background: var(--status-offline-dot); }
.live-pill.is-locked { background: var(--status-locked-bg); color: var(--status-locked-fg); }
.live-pill.is-locked .live-dot { background: var(--status-locked-dot); }
.live-dot.ping::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit;
  animation: idle-ping 600ms ease-out 1 both;
}
@keyframes idle-ping {
  from { transform: scale(1); opacity: 0.7; }
  to { transform: scale(3); opacity: 0; }
}

.idle-popover {
  position: absolute; top: calc(100% + 6px); right: 16px; z-index: 30; width: 340px; max-width: calc(100vw - 32px);
  max-height: 360px; overflow-y: auto; padding: 10px 0; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--popover-shadow); font-size: 12px;
}
.idle-popover[hidden] { display: none; }
.idle-pop-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px 8px; border-bottom: 1px solid var(--border); }
.idle-pop-title { font-weight: 700; font-size: 12px; }
.idle-pop-note { padding: 8px 12px; color: var(--muted); }
.idle-pop-group { padding: 8px 12px 2px; font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.idle-pop-list { list-style: none; margin: 0; padding: 0 4px; }
.idle-pop-item { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; }
.idle-pop-item:hover { background: var(--surface-alt); }
.idle-pop-email { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.idle-pop-meta { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.idle-pop-error { grid-column: 2 / 4; color: var(--status-offline-fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.idle-pop-item.is-degraded .idle-pop-meta { color: var(--status-degraded-fg); font-weight: 600; }
.idle-pop-item.is-auth .idle-pop-meta { color: var(--status-offline-fg); font-weight: 600; }

.new-mail-banner {
  position: sticky; top: 96px; z-index: 18; display: block; width: max-content; min-width: 148px; height: 32px;
  margin: 8px auto 0; padding: 6px 14px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--new-pill-bg); color: var(--new-pill-fg); font: inherit; font-size: 12px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.18);
}
.new-mail-banner[hidden] { display: none; }
.new-mail-banner:focus-visible { outline: 2px solid var(--new-pill-fg); outline-offset: -4px; }

.msg-row.just-arrived { animation: row-arrive 1200ms ease-out 1 both; }
.msg-row.unread.just-arrived { animation-name: row-arrive-unread; }
@keyframes row-arrive { from { background-color: var(--new-row-flash); } to { background-color: var(--surface); } }
@keyframes row-arrive-unread { from { background-color: var(--new-row-flash); } to { background-color: var(--unread-bg); } }
.msg-row.just-flushed { animation: row-arrive-unread 1500ms ease-out 1 both; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: reduce) {
  .live-dot.ping::after { animation: none; display: none; }
  .msg-row.just-arrived, .msg-row.unread.just-arrived, .msg-row.just-flushed { animation: none; }
}

/* ==========================================================================
   Plan 08 — One-click unsubscribe, block sender, mute thread
   ========================================================================== */
:root {
  --banner-unsub-bg: #f1f5f9;
  --banner-unsub-border: #e2e8f0;
  --banner-unsub-fg: #334155;

  --banner-muted-bg: #eef2ff;
  --banner-muted-border: #c7d2fe;
  --banner-muted-fg: #3730a3;

  --banner-blocked-bg: #fef2f2;
  --banner-blocked-border: #fecaca;
  --banner-blocked-fg: #991b1b;

  --toast-action: #818cf8;
}

[data-theme="dark"] {
  --banner-unsub-bg: #1f2937;
  --banner-unsub-border: #334155;
  --banner-unsub-fg: #cbd5e1;

  --banner-muted-bg: rgba(99, 102, 241, 0.14);
  --banner-muted-border: rgba(99, 102, 241, 0.35);
  --banner-muted-fg: #c7d2fe;

  --banner-blocked-bg: rgba(220, 38, 38, 0.14);
  --banner-blocked-border: rgba(239, 68, 68, 0.35);
  --banner-blocked-fg: #fca5a5;

  --toast-action: #a5b4fc;
}

.unsub-banner,
.mute-banner,
.block-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  margin-top: 10px;
}
.unsub-banner { border: 1px solid var(--banner-unsub-border); background: var(--banner-unsub-bg); color: var(--banner-unsub-fg); }
.mute-banner { border: 1px solid var(--banner-muted-border); background: var(--banner-muted-bg); color: var(--banner-muted-fg); }
.block-banner { border: 1px solid var(--banner-blocked-border); background: var(--banner-blocked-bg); color: var(--banner-blocked-fg); }
.unsub-banner abbr { text-decoration: none; border-bottom: 1px dotted currentColor; cursor: help; }
.unsub-banner form, .mute-banner form, .block-banner form { margin: 0; flex-shrink: 0; }
.unsub-banner .btn, .mute-banner .btn, .block-banner .btn { color: inherit; }
.unsub-done { color: var(--muted); font-weight: 600; white-space: nowrap; }

.muted-badge { font-size: 11px; color: var(--muted); margin-left: 4px; }

/* Native <details> overflow menu (zero JS, strict CSP) */
.more-menu { position: relative; display: inline-block; }
.more-menu > summary { list-style: none; cursor: pointer; user-select: none; }
.more-menu > summary::-webkit-details-marker { display: none; }
.more-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
  min-width: 220px;
  max-width: 320px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--popover-shadow);
  display: flex;
  flex-direction: column;
}
.more-menu-item {
  display: block;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.more-menu-item:hover, .more-menu-item:focus-visible { background: var(--surface-alt); outline: none; }
.more-menu-item.is-disabled { color: var(--muted); cursor: not-allowed; }
.more-menu-item.is-disabled:hover { background: transparent; }

/* Confirmation dialogs + no-JS panels */
.hy-dialog { width: min(480px, calc(100vw - 32px)); }
.hy-panel { margin-bottom: 14px; }
.hy-panel .modal-form { padding: 0; }
.hy-fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.hy-fieldset legend { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0 4px; }
.hy-radio, .hy-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); font-weight: 500; cursor: pointer; }
.hy-radio.is-disabled { color: var(--muted); cursor: not-allowed; }
.hy-radio code { font-size: 12px; }
.modal-form .hy-warn { font-size: 12px; color: var(--muted); }
.modal-form .hy-error { font-size: 12px; color: var(--danger); font-weight: 600; }
.hy-highlight { box-shadow: 0 0 0 3px var(--focus-ring); }

/* Undo toast (#muddle-toast): bottom-left, 8 s, pauses on hover/focus */
.muddle-toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 50;
  max-width: 420px;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.muddle-toast-text { flex: 1; min-width: 0; }
.muddle-toast-undo {
  background: none;
  border: 0;
  padding: 2px 4px;
  color: var(--toast-action);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
}
.muddle-toast-undo:hover { text-decoration: underline; }
.muddle-toast-undo:focus-visible, .muddle-toast-close:focus-visible { outline: 2px solid var(--toast-action); outline-offset: 2px; }
.muddle-toast-close { background: none; border: 0; color: var(--toast-muted); cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 4px; }

.rule-source-badge { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 6px; border-radius: 999px; background: var(--banner-blocked-bg); color: var(--banner-blocked-fg); border: 1px solid var(--banner-blocked-border); }
.settings-hint { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.muted-meta { color: var(--muted); font-size: 12px; }

@media (max-width: 640px) {
  .muddle-toast { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .more-menu-panel { right: auto; left: 0; }
}

/* ---------------------------------------------------------------------------
   Plan 09: folder utilities, destructive confirmation dialog, Cmd+K palette
   --------------------------------------------------------------------------- */
.tabular { font-variant-numeric: tabular-nums; }
.triage-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.triage-sep { width: 1px; align-self: stretch; min-height: 20px; background: var(--border); }
.triage-utility { display: inline-flex; align-items: center; margin: 0; }
.btn-utility { font-size: 12px; font-weight: 600; }
.btn-danger-outline { background: transparent; border-color: var(--danger-border); color: var(--danger-text); }
.btn-danger-outline:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.folder-banner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; font-size: 13px; }
.folder-banner-danger { background: var(--danger-soft); border-bottom: 1px solid var(--danger-border); color: var(--danger-text); }
.folder-banner-warn { background: var(--warn-soft); border-bottom: 1px solid var(--warn-border); color: var(--warn-text); }
.folder-banner-text { margin: 0; line-height: 1.45; }
.folder-banner-text strong { font-weight: 700; }
.folder-banner-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Destructive confirmation dialog */
.muddle-dialog { width: min(440px, calc(100vw - 32px)); border: 0; border-radius: 14px; padding: 20px; background: var(--surface-elevated); color: var(--text); box-shadow: var(--shadow-modal); }
.muddle-dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.muddle-dialog[open] { animation: muddle-pop 0.14s ease-out; }
.muddle-dialog-form { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.muddle-dialog-head { display: flex; align-items: center; gap: 12px; }
.muddle-dialog-icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 36px; height: 36px; border-radius: 10px; font-size: 20px; background: var(--danger-soft); color: var(--danger); }
.muddle-dialog-icon.is-neutral { background: var(--unread-bg); color: var(--accent); }
.muddle-dialog-title { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.3; }
.muddle-dialog-callout { margin: 0; display: flex; flex-direction: column; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.callout-row { display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 8px; }
.callout-row dt { color: var(--muted); font-weight: 600; font-size: 12px; }
.callout-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.callout-row .pill { display: inline-block; max-width: 100%; }
#confirm-effect { color: var(--danger-text); font-weight: 600; }
.muddle-dialog-guard { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.muddle-dialog-guard label { font-weight: 600; }
.muddle-dialog-input { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; letter-spacing: 0.08em; text-transform: uppercase; outline: none; }
.muddle-dialog-input:focus { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.muddle-dialog-hint { color: var(--muted); font-size: 11px; }
.muddle-dialog-actions { display: flex; justify-content: flex-end; gap: 12px; }
.muddle-dialog-actions .btn { min-height: 36px; min-width: 88px; }

/* Cmd+K command palette */
.cmdk-trigger { gap: 6px; }
.cmdk-kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; font-weight: 700; line-height: 1; color: var(--muted); background: var(--kbd-bg); border: 1px solid var(--kbd-border); border-radius: 5px; padding: 3px 5px; }
.cmdk-kbd + .cmdk-kbd { margin-left: 2px; }
.cmdk-dialog { width: min(620px, calc(100vw - 24px)); max-height: 70vh; margin: min(14vh, 120px) auto auto; padding: 0; border: 0; border-radius: 14px; overflow: hidden; background: var(--surface-elevated); color: var(--text); box-shadow: var(--shadow-modal); }
.cmdk-dialog[open] { display: flex; flex-direction: column; animation: muddle-pop 0.12s ease-out; }
.cmdk-dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
.cmdk-head { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.cmdk-icon { font-size: 16px; color: var(--muted); }
.cmdk-input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font-family: inherit; font-size: 15px; font-weight: 500; }
.cmdk-input::placeholder { color: var(--muted); font-weight: 400; }
.cmdk-list { max-height: 380px; overflow-y: auto; padding: 6px; flex: 1 1 auto; }
.cmdk-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 8px 10px 4px; }
.cmdk-item { display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 10px; height: 38px; padding: 0 10px; border-radius: 8px; font-size: 13px; color: var(--text); cursor: pointer; user-select: none; }
.cmdk-item[aria-selected="true"] { background: var(--unread-bg); color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.cmdk-item[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.cmdk-item-icon { display: inline-flex; align-items: center; justify-content: center; width: 20px; font-size: 13px; color: var(--muted); }
.cmdk-item-icon .dot { width: 9px; height: 9px; }
.cmdk-item-main { display: flex; align-items: baseline; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; }
.cmdk-item-label { overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.cmdk-item-sub { overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 12px; }
.cmdk-item-danger .cmdk-item-label { color: var(--danger-text); }
.cmdk-item-right { display: inline-flex; align-items: center; gap: 6px; }
.cmdk-item-right .badge { font-variant-numeric: tabular-nums; }
.cmdk-mark { background: var(--match-bg); color: var(--match-text); font-weight: 700; border-radius: 3px; padding: 0 1px; margin: 0 -1px; }
.cmdk-item[aria-selected="true"] .cmdk-mark { color: var(--match-text); }
.cmdk-empty { padding: 18px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.cmdk-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border-top: 1px solid var(--border); background: var(--bg); font-size: 11px; color: var(--muted); flex-shrink: 0; }
.cmdk-foot span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

@keyframes muddle-pop {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 640px) {
  .cmdk-foot span:nth-child(3) { display: none; }
  .callout-row { grid-template-columns: 1fr; gap: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .muddle-dialog[open], .cmdk-dialog[open] { animation: none; }
  .muddle-dialog::backdrop, .cmdk-dialog::backdrop { backdrop-filter: none; }
}
#confirm-effect.is-neutral { color: var(--text); font-weight: 500; }

/* --- Plan 10: Account Manager + Mailcow auto-sync -------------------------------------- */
:root {
  --ok-soft: #dcfce7;
  --ok-text: #166534;
  --ok-dot: #16a34a;
  --warn-soft: #fef3c7;
  --warn-text: #92400e;
  --warn-dot: #d97706;
  --err-soft: #fee2e2;
  --err-text: #991b1b;
  --err-dot: #dc2626;
  --neutral-soft: #f1f5f9;
  --neutral-text: #475569;
  --neutral-dot: #94a3b8;
}

[data-theme="dark"] {
  --ok-soft: rgba(34, 197, 94, 0.14);
  --ok-text: #86efac;
  --ok-dot: #22c55e;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --warn-text: #fcd34d;
  --warn-dot: #f59e0b;
  --err-soft: rgba(239, 68, 68, 0.14);
  --err-text: #fca5a5;
  --err-dot: #ef4444;
  --neutral-soft: #1f2937;
  --neutral-text: #94a3b8;
  --neutral-dot: #64748b;
}

.health-badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-text);
}
.health-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--neutral-dot); flex-shrink: 0; }
.health-ok { background: var(--ok-soft); color: var(--ok-text); }
.health-ok .health-dot { background: var(--ok-dot); }
.health-err { background: var(--err-soft); color: var(--err-text); }
.health-err .health-dot { background: var(--err-dot); }
.health-warn { background: var(--warn-soft); color: var(--warn-text); }
.health-warn .health-dot { background: var(--warn-dot); }
.health-paused, .health-pending { background: var(--neutral-soft); color: var(--neutral-text); }
.health-paused .health-dot, .health-pending .health-dot { background: var(--neutral-dot); }
.health-testing .health-dot { animation: health-pulse 1s ease-in-out infinite; }
@keyframes health-pulse { 50% { opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .health-testing .health-dot { animation: none; } }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0 0 4px; }
.card-actions, .action-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.acc-summary { margin: 0; font-size: 12px; color: var(--muted); }
.link-btn { border: 0; background: transparent; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn.acc-summary-err { color: var(--err-text); font-weight: 700; }
.field-badge { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--ok-soft); color: var(--ok-text); }
.btn-danger-outline { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: var(--err-soft); }

.acc-filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.acc-filter-input {
  flex: 1 1 260px; min-width: 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; background: var(--bg); color: var(--text);
}
.acc-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.acc-chips .pill-btn { margin-bottom: 0; }
.acc-chips .pill-btn[aria-pressed="true"] { background: var(--unread-bg); color: var(--accent); border-color: var(--accent); }

.acc-list { display: flex; flex-direction: column; gap: 6px; }
.acc-item { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.acc-item[open] { border-color: var(--accent); }
.acc-item > summary {
  list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px;
  min-height: 42px; padding: 6px 12px; font-size: 13px; border-radius: 8px;
}
.acc-item > summary::-webkit-details-marker { display: none; }
.acc-item > summary::before { content: "▸"; color: var(--muted); font-size: 11px; transition: transform 0.12s ease; }
.acc-item[open] > summary::before { transform: rotate(90deg); }
.acc-ident { display: inline-flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 280px; }
.acc-ident .pill { max-width: 320px; }
.acc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-status { display: inline-flex; align-items: center; gap: 8px; flex: 0 1 auto; }
.acc-host { font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.acc-error-strip {
  flex-basis: 100%; display: block; background: var(--err-soft); color: var(--err-text); font-size: 12px;
  padding: 6px 10px; border-radius: 6px; margin-top: 6px; overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.acc-error-strip[hidden] { display: none; }
.acc-form { padding: 4px 12px 12px; border-top: 1px solid var(--border); margin-top: 0; }
.acc-form .acc-enabled { align-self: end; padding-bottom: 8px; }
.acc-meta { margin: 0; font-size: 12px; }
.acc-footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.acc-footer-left { display: flex; gap: 8px; flex-wrap: wrap; }

.test-result {
  flex-basis: 100%; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 6px;
  background: var(--surface-alt); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.test-result[hidden] { display: none; }
.test-line { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.test-line.is-ok { color: var(--ok-text); }
.test-line.is-err { color: var(--err-text); }
.test-line.is-pending { color: var(--muted); }
.test-proto { font-weight: 700; }

.acc-item:focus-within > summary:focus-visible,
.acc-item > summary:focus-visible,
.acc-filter-input:focus-visible,
.link-btn:focus-visible,
.acc-dialog .btn:focus-visible,
.mailcow-diff-table input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.acc-dialog {
  width: 560px; max-width: calc(100vw - 24px); padding: 20px; border-radius: 12px;
  background: var(--popover-bg); color: var(--text); border: 1px solid var(--border); box-shadow: var(--popover-shadow);
}
.acc-dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
[data-theme="dark"] .acc-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.dialog-head h2 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.remove-impact { margin: 0; font-size: 13px; line-height: 1.5; }

.mailcow-last { margin: 0; font-size: 12px; }
.mailcow-status { margin-top: 12px; padding: 8px 12px; border-radius: 8px; font-size: 13px; background: var(--neutral-soft); color: var(--neutral-text); }
.mailcow-status[hidden] { display: none; }
.mailcow-status.is-ok { background: var(--ok-soft); color: var(--ok-text); }
.mailcow-status.is-error { background: var(--err-soft); color: var(--err-text); }
.mailcow-diff { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.mailcow-diff[hidden] { display: none; }
.diff-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.diff-pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.diff-pill-add { background: var(--ok-soft); color: var(--ok-text); }
.diff-pill-update { background: var(--unread-bg); color: var(--accent); }
.diff-pill-pause { background: var(--warn-soft); color: var(--warn-text); }
.diff-pill-same { background: var(--neutral-soft); color: var(--neutral-text); }
.mailcow-diff-scroll { max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.mailcow-diff-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mailcow-diff-table th, .mailcow-diff-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.mailcow-diff-table th { position: sticky; top: 0; background: var(--surface-alt); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.mailcow-diff-table tr:last-child td { border-bottom: 0; }
.mailcow-diff-table .diff-email { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }
.diff-kind { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.diff-kind-add { background: var(--ok-soft); color: var(--ok-text); }
.diff-kind-update { background: var(--unread-bg); color: var(--accent); }
.diff-kind-pause { background: var(--warn-soft); color: var(--warn-text); }
.diff-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

@media (max-width: 640px) {
  .acc-ident { flex-basis: 100%; }
  .acc-dialog .grid-2, .acc-form .grid-2 { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
   Plan 11: raw MIME source, technical headers & SPF/DKIM/DMARC trust badges
   --------------------------------------------------------------------------- */
:root {
  /* Auth / Trust Badge Semantics (all text/bg pairs >= 7:1 WCAG AAA) */
  --trust-pass-bg: #ecfdf5;
  --trust-pass-border: #a7f3d0;
  --trust-pass-text: #065f46;      /* 7.3:1 on #ecfdf5 */

  --trust-warn-bg: #fffbeb;
  --trust-warn-border: #fde68a;
  --trust-warn-text: #78350f;      /* 9.2:1 on #fffbeb */

  --trust-fail-bg: #fef2f2;
  --trust-fail-border: #fecaca;
  --trust-fail-text: #991b1b;      /* 7.6:1 on #fef2f2 */

  --trust-neutral-bg: #f1f5f9;
  --trust-neutral-border: #cbd5e1;
  --trust-neutral-text: #334155;   /* 8.9:1 on #f1f5f9 */

  /* Monospace / Technical Inspector */
  --mono-font: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --code-bg: #f8fafc;
  --code-gutter: #94a3b8;
  --header-key: #4338ca;           /* 7.2:1 on #f8fafc */
}

[data-theme="dark"] {
  --trust-pass-bg: #064e3b;
  --trust-pass-border: #047857;
  --trust-pass-text: #6ee7b7;      /* 7.1:1 on #064e3b */

  --trust-warn-bg: #451a03;
  --trust-warn-border: #b45309;
  --trust-warn-text: #fcd34d;      /* 9.8:1 on #451a03 */

  --trust-fail-bg: #450a0a;
  --trust-fail-border: #b91c1c;
  --trust-fail-text: #fca5a5;      /* 7.8:1 on #450a0a */

  --trust-neutral-bg: #1f2937;
  --trust-neutral-border: #334155;
  --trust-neutral-text: #cbd5e1;   /* 9.8:1 on #1f2937 */

  --code-bg: #0b1120;
  --code-gutter: #64748b;
  --header-key: #a5b4fc;           /* 9.1:1 on #0b1120 */
}

/* Trust pills: color + glyph + text label (never hue alone). */
.trust-pill { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px; border: 1px solid; font-size: 11px; font-weight: 700; line-height: 1; white-space: nowrap; text-decoration: none; vertical-align: middle; }
a.trust-pill { cursor: pointer; }
a.trust-pill:hover { filter: brightness(0.97); }
a.trust-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.trust-pill-sm { height: 18px; padding: 0 6px; font-size: 10.5px; }
.trust-pass { background: var(--trust-pass-bg); border-color: var(--trust-pass-border); color: var(--trust-pass-text); }
.trust-warn { background: var(--trust-warn-bg); border-color: var(--trust-warn-border); color: var(--trust-warn-text); }
.trust-fail { background: var(--trust-fail-bg); border-color: var(--trust-fail-border); color: var(--trust-fail-text); }
.trust-neutral { background: var(--trust-neutral-bg); border-color: var(--trust-neutral-border); color: var(--trust-neutral-text); }

/* Hard-failure banner (styled like .img-banner), directly beneath .reader-head. */
.auth-alert-banner { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--trust-fail-border); background: var(--trust-fail-bg); color: var(--trust-fail-text); font-size: 12.5px; line-height: 1.45; }
.auth-alert-icon { font-weight: 800; flex-shrink: 0; }
.auth-alert-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.auth-alert-banner .btn { flex-shrink: 0; color: var(--trust-fail-text); border-color: var(--trust-fail-border); }

/* Tiny inbox-row indicator: only for `failed`. */
.auth-warn-icon { display: inline-block; width: 14px; margin-right: 4px; font-size: 12px; line-height: 1; color: var(--trust-fail-text); font-weight: 700; text-align: center; }

/* Reply-To divergence row inside .reader-meta. */
.meta-reply-to { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.meta-reply-to .reply-to-addr { color: var(--trust-warn-text); overflow-wrap: anywhere; }

/* Technical headers drawer (native <details>, zero-JS). */
.reader-head { container-type: inline-size; }
.tech-headers-wrap { position: relative; margin-top: 12px; }
.tech-headers { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.tech-headers > summary { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 6px 12px; padding-right: 330px; cursor: pointer; list-style: none; font-size: 12px; font-weight: 600; color: var(--muted); border-radius: 8px; }
.tech-headers > summary::-webkit-details-marker { display: none; }
.tech-headers > summary::before { content: "▸"; display: inline-block; width: 10px; color: var(--muted); transition: transform 0.12s ease; }
.tech-headers[open] > summary::before { transform: rotate(90deg); }
.tech-headers > summary:hover { color: var(--text); }
.tech-headers > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tech-headers[open] > summary { border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.tech-hint { font-weight: 500; font-size: 11px; color: var(--code-gutter); font-family: var(--mono-font); }
.tech-actions { position: absolute; top: 5px; right: 8px; display: flex; align-items: center; gap: 4px; }
.tech-body { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
@container (max-width: 640px) {
  .tech-headers > summary { padding-right: 12px; }
  .tech-actions { position: static; flex-wrap: wrap; margin-top: 6px; }
}

/* Auth breakdown grid: 3 cards, 4 with ARC; collapses to 2x2 in the split reader. */
.auth-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.auth-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@container (max-width: 640px) {
  .auth-grid, .auth-grid-4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
.auth-card { display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--code-bg); }
.auth-card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.auth-proto { font-size: 11px; font-weight: 800; letter-spacing: 0.04em; color: var(--text); }
.auth-detail { font-family: var(--mono-font); font-size: 11.5px; color: var(--muted); overflow-wrap: anywhere; background: none; padding: 0; }
.auth-detail-empty { color: var(--code-gutter); }
.auth-foot { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.auth-foot code { font-family: var(--mono-font); font-size: 11px; color: var(--text); }
.auth-reason { display: block; margin-top: 2px; color: var(--text); }
.auth-legacy { padding: 8px 10px; border: 1px dashed var(--trust-neutral-border); border-radius: 8px; background: var(--trust-neutral-bg); color: var(--trust-neutral-text); }

/* Routing & identity table. */
.hdr-table { display: grid; grid-template-columns: 150px 1fr; font-family: var(--mono-font); font-size: 12px; line-height: 1.5; border-top: 1px solid var(--border); }
.hdr-table:empty { display: none; }
.hdr-k, .hdr-v { padding: 5px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.hdr-k { color: var(--header-key); font-weight: 600; padding-right: 10px; }
.hdr-v { color: var(--text); overflow-wrap: anywhere; white-space: pre-wrap; }
.hdr-warn { color: var(--trust-warn-text); }
.hdr-muted { color: var(--muted); }
@container (max-width: 480px) {
  .hdr-table { grid-template-columns: 1fr; }
  .hdr-k { border-bottom: 0; padding-bottom: 0; }
}

/* Received hop trace: newest first with a subtle timeline connector. */
.hop-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.hop-trace { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.hop-trace li { position: relative; display: grid; grid-template-columns: 34px 1fr; gap: 6px; padding: 4px 0 4px 2px; font-family: var(--mono-font); font-size: 11.5px; line-height: 1.5; }
.hop-trace li::before { content: ""; position: absolute; left: 12px; top: 22px; bottom: -4px; width: 1px; background: var(--border); }
.hop-trace li:last-child::before { display: none; }
.hop-idx { display: inline-flex; align-items: center; justify-content: center; height: 18px; border-radius: 9px; background: var(--surface-alt); border: 1px solid var(--border); color: var(--header-key); font-size: 10.5px; font-weight: 700; }
.hop-text { color: var(--text); overflow-wrap: anywhere; }

/* Off-screen clipboard fallback buffer (no inline styles under CSP). */
.copy-buffer { position: fixed; top: 0; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* Styled raw MIME inspector (/msg/{id}/source). */
.source-wrap { max-width: 1280px; margin: 0 auto; padding: 0 18px 24px; display: flex; flex-direction: column; gap: 10px; }
.source-bar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--border); }
.source-bar-left { min-width: 0; flex: 1; }
.source-title { min-width: 0; max-width: 520px; font-size: 13px; font-weight: 600; color: var(--text); }
.source-meta { margin: 0; font-size: 12px; color: var(--muted); }
.source-meta code { font-family: var(--mono-font); }
.seg-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-btn { padding: 4px 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none; background: var(--surface); }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.active { background: var(--unread-bg); color: var(--accent); }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.raw-source { margin: 0; padding: 12px 0; border: 1px solid var(--border); border-radius: 8px; background: var(--code-bg); color: var(--text); font-family: var(--mono-font); font-size: 12.5px; line-height: 1.55; tab-size: 4; overflow-x: auto; white-space: pre; counter-reset: ln; }
.raw-source:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.raw-source .ln { display: block; padding: 0 14px 0 64px; position: relative; min-height: 1.55em; }
.raw-source .ln::before { counter-increment: ln; content: counter(ln); position: absolute; left: 0; width: 48px; text-align: right; color: var(--code-gutter); user-select: none; }
.raw-source .hk { color: var(--header-key); font-weight: 700; }
.source-trunc { margin: 0; }
@media (max-width: 640px) {
  .source-wrap { padding: 0 10px 16px; }
  .source-title { display: none; }
  .raw-source { font-size: 11.5px; }
  .raw-source .ln { padding-left: 50px; }
  .raw-source .ln::before { width: 38px; }
}

/* ---------------------------------------------------------------------------
   Plan 12: calendar invitation card (.cal-card) + iMIP RSVP
   --------------------------------------------------------------------------- */
:root {
  --cal-bg: #f8fafc;
  --cal-border: #cbd5e1;
  --cal-leaf-head: #4f46e5;       /* white text = 6.3:1 */
  --cal-leaf-bg: #ffffff;

  --rsvp-yes-bg: #ecfdf5;
  --rsvp-yes-border: #10b981;
  --rsvp-yes-text: #065f46;       /* 7.3:1 AAA */

  --rsvp-maybe-bg: #fffbeb;
  --rsvp-maybe-border: #f59e0b;
  --rsvp-maybe-text: #78350f;     /* 9.2:1 AAA */

  --rsvp-no-bg: #fef2f2;
  --rsvp-no-border: #ef4444;
  --rsvp-no-text: #991b1b;        /* 7.6:1 AAA */
}

[data-theme="dark"] {
  --cal-bg: #0f172a;
  --cal-border: #334155;
  --cal-leaf-head: #4f46e5;       /* keep #4f46e5 for >= 6.3:1 with #fff */
  --cal-leaf-bg: #1e293b;

  --rsvp-yes-bg: #064e3b;
  --rsvp-yes-border: #10b981;
  --rsvp-yes-text: #6ee7b7;       /* 7.1:1 AAA */

  --rsvp-maybe-bg: #451a03;
  --rsvp-maybe-border: #f59e0b;
  --rsvp-maybe-text: #fcd34d;     /* 9.8:1 AAA */

  --rsvp-no-bg: #450a0a;
  --rsvp-no-border: #ef4444;
  --rsvp-no-text: #fca5a5;        /* 7.8:1 AAA */
}

.cal-icon { margin-right: 4px; font-size: 12px; }

.cal-card {
  margin: 12px 0;
  background: var(--cal-bg);
  border: 1px solid var(--cal-border);
  border-radius: 10px;
  overflow: hidden;
  color: var(--text);
}
.cal-cancel-banner {
  padding: 8px 14px;
  background: var(--rsvp-no-bg);
  color: var(--rsvp-no-text);
  border-bottom: 2px solid var(--rsvp-no-border);
  font-size: 13px;
  font-weight: 600;
}
.cal-main { display: flex; gap: 14px; padding: 14px; align-items: flex-start; }

/* Tear-off date leaf */
.cal-leaf {
  flex: 0 0 56px;
  width: 56px;
  height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--cal-leaf-bg);
  border: 1px solid var(--cal-border);
  border-radius: 8px;
  overflow: hidden;
  text-align: center;
}
.cal-leaf-month {
  display: block;
  width: 100%;
  height: 18px;
  line-height: 18px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #ffffff;
  background: var(--cal-leaf-head);
}
.cal-leaf-day {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 28px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.cal-leaf-weekday { display: block; font-size: 10px; line-height: 14px; color: var(--muted); }
.cal-card.is-cancelled .cal-leaf-month { background: var(--danger); }
.cal-card.is-cancelled .cal-leaf-day { color: var(--muted); }

/* Event metadata */
.cal-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cal-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cal-title { margin: 0; font-size: 15px; font-weight: 700; color: var(--text); overflow-wrap: anywhere; }
.cal-card.is-cancelled .cal-title { text-decoration: line-through; color: var(--muted); }
.cal-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--cal-border);
  color: var(--muted);
  background: var(--surface);
  white-space: nowrap;
}
.cal-pill.is-invite, .cal-pill.is-update { color: #ffffff; background: var(--cal-leaf-head); border-color: var(--cal-leaf-head); }
.cal-pill.is-cancel { color: var(--rsvp-no-text); background: var(--rsvp-no-bg); border-color: var(--rsvp-no-border); }
.cal-pill.is-reply { color: var(--rsvp-yes-text); background: var(--rsvp-yes-bg); border-color: var(--rsvp-yes-border); }
.cal-pill.is-soon { color: var(--rsvp-maybe-text); background: var(--rsvp-maybe-bg); border-color: var(--rsvp-maybe-border); text-transform: none; }
.cal-pill.is-past { text-transform: none; }

.cal-when { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--text); }
.cal-dur { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-sub { font-size: 12px; color: var(--muted); }
.cal-sub > span:empty { display: none; }
.cal-sub > span:not(:empty) ~ span:not(:empty)::before { content: " · "; }
.cal-row { font-size: 13px; color: var(--text); overflow-wrap: anywhere; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cal-label { color: var(--muted); font-weight: 600; }
.cal-join {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.cal-join:hover { background: var(--accent); color: #ffffff; }
.cal-reply-note { color: var(--rsvp-yes-text); font-weight: 600; }

.cal-attendees, .cal-desc { font-size: 13px; }
.cal-attendees > summary, .cal-desc > summary { cursor: pointer; color: var(--text); }
.cal-att-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.cal-att { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; overflow-wrap: anywhere; }
.cal-att-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--cal-border);
  color: var(--muted);
}
.cal-att.is-yes .cal-att-dot { background: var(--rsvp-yes-bg); border-color: var(--rsvp-yes-border); color: var(--rsvp-yes-text); }
.cal-att.is-maybe .cal-att-dot { background: var(--rsvp-maybe-bg); border-color: var(--rsvp-maybe-border); color: var(--rsvp-maybe-text); }
.cal-att.is-no .cal-att-dot { background: var(--rsvp-no-bg); border-color: var(--rsvp-no-border); color: var(--rsvp-no-text); }
.cal-att-state { color: var(--muted); font-size: 11.5px; }
.cal-you { color: var(--accent); font-size: 11.5px; }
.cal-opt { color: var(--muted); font-size: 11px; font-style: italic; }
.cal-desc-body { margin-top: 6px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); max-height: 220px; overflow: auto; }

/* Footer action bar */
.cal-actions { border-top: 1px solid var(--cal-border); padding: 10px 14px; background: var(--surface); }
.rsvp-form { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.rsvp-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cal-respond-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.rsvp-group { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.rsvp-btn { border: 2px solid var(--cal-border); min-height: 30px; }
.rsvp-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rsvp-yes.is-active { background: var(--rsvp-yes-bg); border-color: var(--rsvp-yes-border); color: var(--rsvp-yes-text); }
.rsvp-maybe.is-active { background: var(--rsvp-maybe-bg); border-color: var(--rsvp-maybe-border); color: var(--rsvp-maybe-text); }
.rsvp-no.is-active { background: var(--rsvp-no-bg); border-color: var(--rsvp-no-border); color: var(--rsvp-no-text); }
.rsvp-form.is-sending .rsvp-btn { opacity: 0.6; cursor: progress; pointer-events: none; }
.cal-ics { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }
.cal-ics:hover { text-decoration: underline; }
.cal-ics:focus-visible, .cal-join:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rsvp-note { font-size: 12.5px; }
.rsvp-note > summary { cursor: pointer; color: var(--muted); width: max-content; }
.rsvp-note input { margin-top: 6px; width: 100%; max-width: 420px; }
.rsvp-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.rsvp-state { padding: 1px 8px; border-radius: 999px; font-weight: 700; border: 1px solid var(--cal-border); }
.rsvp-state.is-yes { background: var(--rsvp-yes-bg); border-color: var(--rsvp-yes-border); color: var(--rsvp-yes-text); }
.rsvp-state.is-maybe { background: var(--rsvp-maybe-bg); border-color: var(--rsvp-maybe-border); color: var(--rsvp-maybe-text); }
.rsvp-state.is-no { background: var(--rsvp-no-bg); border-color: var(--rsvp-no-border); color: var(--rsvp-no-text); }
.rsvp-hint { font-size: 12px; color: var(--muted); font-style: italic; }
.cal-card.is-past .cal-main { opacity: 0.85; }

/* Split pane (>= 420px) and phones (390px) */
@media (max-width: 640px) {
  .cal-main { gap: 10px; padding: 12px; }
  .cal-actions { padding: 10px 12px; }
  .cal-ics { margin-left: 0; }
}
.split-reader .cal-main { gap: 10px; }
@media (max-width: 420px) {
  .cal-leaf { flex-basis: 48px; width: 48px; height: 58px; }
  .cal-leaf-day { font-size: 19px; line-height: 24px; }
  .rsvp-group { width: 100%; }
  .rsvp-btn { flex: 1 1 0; justify-content: center; }
}

/* --- Plan 13: Contacts directory, vCard / CSV import & export --- */
:root {
  --avatar-ring: rgba(15, 23, 42, 0.08);
  --vip-bg: #fef3c7;
  --vip-fg: #92400e;
  --vip-border: #fcd34d;
  /* Named contact-tag-* so the Plan 03 `.tag-chip` fallbacks (var(--tag-bg, …)) are untouched. */
  --contact-tag-bg: #f1f5f9;
  --contact-tag-fg: #334155;
  --source-curated-bg: #eef2ff;
  --source-curated-fg: #3730a3;
  --diff-add-bg: #dcfce7;
  --diff-add-fg: #166534;
  --diff-warn-bg: #fef3c7;
  --diff-warn-fg: #92400e;
  --dropzone-bg: #f8fafc;
  --dropzone-active: #eef2ff;
}
[data-theme="dark"] {
  --avatar-ring: rgba(241, 245, 249, 0.12);
  --vip-bg: #451a03;
  --vip-fg: #fcd34d;
  --vip-border: #b45309;
  --contact-tag-bg: #1f2937;
  --contact-tag-fg: #cbd5e1;
  --source-curated-bg: #1e1b4b;
  --source-curated-fg: #a5b4fc;
  --diff-add-bg: #052e16;
  --diff-add-fg: #86efac;
  --diff-warn-bg: #451a03;
  --diff-warn-fg: #fcd34d;
  --dropzone-bg: #0f172a;
  --dropzone-active: #1e1b4b;
}

/* Sidebar entry */
.nav-rule { height: 1px; background: var(--border); margin: 6px 4px; }
.contact-chip { display: inline-flex; align-items: center; margin-left: 6px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--accent); font-size: 11px; font-weight: 600; vertical-align: middle; }
.contact-chip:hover { border-color: var(--accent); background: var(--unread-bg); }

/* Avatars: 12 hues, white initials ≥ 4.8:1 (hues 1/5/6/7/11 deepened for contrast) */
.avatar { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-size: 13px; font-weight: 700; letter-spacing: 0.02em; line-height: 1; box-shadow: inset 0 0 0 1px var(--avatar-ring); text-transform: uppercase; user-select: none; }
.avatar-md { width: 44px; height: 44px; font-size: 15px; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.hue-0  { background: #4f46e5; }
.avatar.hue-1  { background: #0f766e; }
.avatar.hue-2  { background: #2563eb; }
.avatar.hue-3  { background: #7c3aed; }
.avatar.hue-4  { background: #db2777; }
.avatar.hue-5  { background: #b45309; }
.avatar.hue-6  { background: #047857; }
.avatar.hue-7  { background: #0369a1; }
.avatar.hue-8  { background: #dc2626; }
.avatar.hue-9  { background: #475569; }
.avatar.hue-10 { background: #9333ea; }
.avatar.hue-11 { background: #0e7490; }

/* Topbar & filters */
.contacts-topbar { flex-wrap: wrap; }
.contacts-top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.export-menu { position: relative; }
.export-menu > summary { list-style: none; }
.export-menu > summary::-webkit-details-marker { display: none; }
.export-menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 200px; display: flex; flex-direction: column; padding: 6px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--popover-shadow, 0 10px 30px rgba(15, 23, 42, 0.12)); }
.export-menu-item { padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.export-menu-item:hover, .export-menu-item:focus-visible { background: var(--surface-alt); }
.contact-filters .chip { display: inline-flex; align-items: center; }
.chip-tag { background: var(--contact-tag-bg); color: var(--contact-tag-fg); }

/* Bulk bar */
.contact-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface); font-size: 12px; }
.contact-bulk select, .contact-bulk .bulk-input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.contact-bulk .sel-count { font-weight: 600; color: var(--muted); min-width: 72px; }
.bulk-confirm { display: inline-flex; align-items: center; gap: 4px; color: var(--danger); font-weight: 600; }

/* Desktop directory table */
.contact-table-wrap { overflow-x: auto; }
.contact-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.contact-table col.col-check { width: 28px; }
.contact-table col.col-name { width: 34%; }
.contact-table col.col-email { width: 30%; }
.contact-table col.col-from { width: 140px; }
.contact-table col.col-meta { width: 120px; }
.contact-table col.col-actions { width: 116px; }
.contact-table th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; }
.contact-table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-table .cell-check { padding-left: 12px; }
.contact-row:hover { background: var(--surface-alt); }
.contact-row.selected { background: var(--unread-bg); box-shadow: inset 3px 0 0 var(--accent); }
.contact-row.is-open { background: var(--checked-bg); }
.contact-row.is-checked { background: var(--checked-bg); }
.contact-ident { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; }
.contact-ident-text { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.contact-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-org { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-email { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.contact-phone { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.cell-meta { white-space: normal; }
.contact-tag { display: inline-block; margin: 1px 3px 1px 0; padding: 0 6px; border-radius: 999px; background: var(--contact-tag-bg); color: var(--contact-tag-fg); font-size: 11px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.vip-mark { color: var(--vip-fg); }
.source-badge { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-alt); color: var(--muted); vertical-align: middle; }
.source-manual, .source-vcard, .source-csv { background: var(--source-curated-bg); color: var(--source-curated-fg); }
.cell-actions { display: flex; align-items: center; gap: 4px; }
.inline-form { display: inline; margin: 0; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text); font-size: 15px; cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--surface-alt); border-color: var(--border); }
.star-btn.is-on { background: var(--vip-bg); color: var(--vip-fg); border-color: var(--vip-border); }
.contact-pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; }
.link { color: var(--accent); text-decoration: underline; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* Mobile cards (hidden on desktop) */
.contact-cards { display: none; list-style: none; margin: 0; padding: 10px 12px; flex-direction: column; gap: 10px; }
.contact-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.contact-card .card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.contact-card .contact-ident { flex: 1; }
.contact-card .contact-name { font-size: 15px; }
.contact-card .card-star { width: 44px; height: 44px; font-size: 18px; }
.contact-card .card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.contact-card .card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.contact-card .card-actions .btn { min-height: 44px; }

/* Edit / new pane */
.contact-pane-bar strong { font-size: 14px; }
.contact-pane-head { display: flex; align-items: center; gap: 14px; }
.contact-pane-head .contact-name { font-size: 17px; white-space: normal; }
.contact-pane-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.contact-form textarea { resize: vertical; min-height: 96px; }
.contact-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 4px 0 0; padding: 12px 0; border-top: 1px solid var(--border); font-size: 12px; }
.contact-facts dt { color: var(--muted); font-weight: 600; }
.contact-facts dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.contact-delete { margin-top: 24px; padding-top: 16px; border-top: 1px dashed var(--border); }

/* Duplicate clusters */
.dup-list { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; }
.dup-cluster { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.dup-cluster fieldset { border: 0; margin: 0; padding: 0; }
.dup-cluster legend { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.dup-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.dup-card { display: flex; align-items: flex-start; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--bg); min-height: 44px; }
.dup-card:has(input:checked) { border-color: var(--accent); background: var(--unread-bg); }
.dup-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 12px; }

/* Import panel */
.import-card { margin: 12px 16px; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 120px; padding: 18px; border: 2px dashed var(--border); border-radius: 12px; background: var(--dropzone-bg); text-align: center; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.dropzone.is-active, .dropzone:focus-within { background: var(--dropzone-active); border-color: var(--accent); }
.dropzone-input { max-width: 100%; font-size: 12px; }
.dropzone-title { font-weight: 700; }
.dropzone-hint { font-size: 12px; color: var(--muted); }
.dropzone-file { font-size: 12px; font-weight: 600; color: var(--accent); }
.import-upload { display: flex; flex-direction: column; gap: 10px; }
.import-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.diff-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; background: var(--surface-alt); color: var(--muted); }
.diff-add, .diff-new { background: var(--diff-add-bg); color: var(--diff-add-fg); }
.diff-warn, .diff-conflict { background: var(--diff-warn-bg); color: var(--diff-warn-fg); }
.diff-enrich { background: var(--source-curated-bg); color: var(--source-curated-fg); }
.diff-same, .diff-unchanged { background: var(--surface-alt); color: var(--muted); }
.policy-group { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.policy-group legend { font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 4px; }
.policy-option { display: flex; align-items: center; gap: 8px; font-size: 13px; min-height: 32px; cursor: pointer; }
.preview-scroll { max-height: 420px; overflow: auto; margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; }
.preview-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.preview-table th { position: sticky; top: 0; background: var(--bg); text-align: left; padding: 6px 8px; font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--border); }
.preview-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }

/* Compose: preferred From suggestion */
.from-hint-row { margin: -6px 0 0; }
.from-hint { border-style: dashed; color: var(--accent); }

/* Focus visibility for every contacts control */
.contacts-shell a:focus-visible, .contacts-shell button:focus-visible, .contacts-shell input:focus-visible,
.contacts-shell select:focus-visible, .contacts-shell textarea:focus-visible, .contacts-shell summary:focus-visible,
.contact-chip:focus-visible, .from-hint:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 820px) {
  .contact-table-wrap, .contact-bulk { display: none; }
  .contact-cards { display: flex; }
  .contacts-topbar .search-form { flex-basis: 100%; }
  .contacts-shell .chip, .contact-pager .btn, .contacts-top-actions .btn, .export-menu > summary { min-height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .contact-filters { gap: 8px; }
  .contacts-shell.shell-split .contacts-main { display: none; }
  .contact-pane { position: fixed; inset: 0; z-index: 50; height: 100vh; border: 0; }
  .contact-pane-bar { min-height: 56px; }
  .contact-pane-bar .btn { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .policy-option { min-height: 44px; }
}

/* ==========================================================================
   Plan 14 — Offline / PWA read cache & mobile touch ergonomics
   ========================================================================== */
:root {
  --live-bg: #dcfce7;
  --live-fg: #166534;
  --reconn-bg: #fef3c7;
  --reconn-fg: #92400e;
  --reconn-border: #fcd34d;
  --offline-bg: #1e293b;
  --offline-fg: #f8fafc;
  --offline-border: #334155;
  --scrim: rgba(15, 23, 42, 0.52);
  --touch-min: 44px;
  --drawer-w: min(86vw, 304px);
  --topbar-h: 53px;
  --icon-cloud-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3l18 18'/%3E%3Cpath d='M6.3 6.3A6.5 6.5 0 0 0 7 19h10.5a3.5 3.5 0 0 0 1.4-.3'/%3E%3Cpath d='M21.4 15.6A4.5 4.5 0 0 0 17.5 10.5h-.6A6.5 6.5 0 0 0 10.2 5.2'/%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --live-bg: #052e16;
  --live-fg: #86efac;
  --reconn-bg: #451a03;
  --reconn-fg: #fde68a;
  --reconn-border: #b45309;
  --offline-bg: #0f172a;
  --offline-fg: #f1f5f9;
  --offline-border: #475569;
  --scrim: rgba(2, 6, 23, 0.72);
}

.mobile-only { display: none; }
.sidebar-top-actions { display: inline-flex; align-items: center; gap: 6px; }
.btn-touch { min-height: var(--touch-min); }

/* --- Connectivity banner (#conn-banner) --- */
.conn-banner {
  position: sticky; top: var(--topbar-h); z-index: 25;
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 16px;
  font-size: 13px; font-weight: 600; border-bottom: 1px solid transparent;
}
body > .conn-banner { top: 0; }
.offline-body > .conn-banner { position: fixed; top: 0; left: 0; right: 0; }
.conn-banner-text { flex: 1; min-width: 0; }
.conn-banner-actions { display: inline-flex; align-items: center; gap: 10px; flex: none; }
.conn-banner-icon { flex: none; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.conn-banner-btn { background: transparent; color: inherit; border-color: currentColor; }
.conn-banner-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.conn-banner.is-reconnecting { background: var(--reconn-bg); color: var(--reconn-fg); border-bottom-color: var(--reconn-border); }
.conn-banner.is-reconnecting .conn-banner-icon { animation: conn-dot-pulse 1.2s ease-in-out infinite; }
.conn-banner.is-offline { min-height: 44px; background: var(--offline-bg); color: var(--offline-fg); border-bottom-color: var(--offline-border); }
.conn-banner.is-offline .conn-banner-icon {
  width: 18px; height: 18px; border-radius: 0;
  -webkit-mask: var(--icon-cloud-off) center / contain no-repeat; mask: var(--icon-cloud-off) center / contain no-repeat;
}
.conn-banner.is-back-online { background: var(--live-bg); color: var(--live-fg); }
.conn-banner.is-pulse { animation: conn-banner-pulse 700ms ease-out 2; }
.has-conn-banner .triage-bar { top: calc(var(--topbar-h) + 36px); }
.has-conn-banner.is-offline .triage-bar { top: calc(var(--topbar-h) + 44px); }

@keyframes conn-dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.7); }
}
@keyframes conn-banner-pulse {
  0% { box-shadow: inset 0 0 0 0 transparent; }
  40% { box-shadow: inset 0 0 0 2px var(--reconn-border); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}

/* --- Status pill: offline (cached read mode) & reconnecting --- */
.live-pill.is-cached { background: var(--offline-bg); color: var(--offline-fg); }
.live-pill.is-cached .live-dot {
  width: 14px; height: 14px; border-radius: 0; background: currentColor;
  -webkit-mask: var(--icon-cloud-off) center / contain no-repeat; mask: var(--icon-cloud-off) center / contain no-repeat;
}
.live-pill.is-reconnecting .live-dot { animation: conn-dot-pulse 1.2s ease-in-out infinite; }

/* --- Read-only guardrails while offline --- */
.is-offline [data-offline-disabled] { opacity: 0.55; cursor: not-allowed; }

/* --- Offline fallback page --- */
.offline-body { padding: max(56px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.offline-card {
  width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 28px; text-align: center; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
.offline-title { margin: 4px 0 0; font-size: 22px; letter-spacing: -0.3px; }
.offline-lead { margin: 0; color: var(--muted); line-height: 1.5; }
.offline-cached { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.offline-cached-title { margin: 0; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.offline-cached-empty { margin: 0; font-size: 13px; line-height: 1.45; }
.offline-cached-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 50vh; overflow-y: auto; }
.offline-cached-link {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  min-height: var(--touch-min); padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.offline-cached-link:hover, .offline-cached-link:focus-visible { border-color: var(--accent); background: var(--unread-bg); }
.offline-cached-kind { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 4px; background: var(--surface-alt); color: var(--muted); }
.offline-cached-text { font-size: 13px; font-weight: 600; }
.offline-cached-time { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* --- Drawer scaffolding & thumb-zone bulk bar (hidden on desktop) --- */
.drawer-scrim { position: fixed; inset: 0; z-index: 50; background: var(--scrim); }
.mobile-bulk-bar { display: none; }

/* --- Touch targets: phones and any coarse pointer (tablets) --- */
@media (max-width: 820px), (pointer: coarse) {
  .btn-xs, .btn-sm, .reader-actions .btn, .att-chip, .pager a, .pager .btn { min-height: var(--touch-min); padding: 10px 14px; }
  .chip { display: inline-flex; align-items: center; min-height: 40px; padding: 10px 14px; }
  .icon-btn { min-width: var(--touch-min); min-height: var(--touch-min); }
  .nav-item { min-height: var(--touch-min); }
  .check-wrap { min-width: var(--touch-min); min-height: var(--touch-min); }
  .check-wrap input { width: 20px; height: 20px; }
  .triage-left, .triage-actions, .reader-actions { gap: 8px; }
}

/* Touch screens have no hover: keep the row Star toggle visible next to the date. */
@media (hover: none) {
  .msg-row[data-id] .row-actions { display: flex; }
  .msg-row[data-id] .row-actions > :not(.row-star-form) { display: none; }
  .msg-row[data-id]:hover .msg-meta, .msg-row[data-id].selected .msg-meta { display: flex; }
}

/* --- Phone layout (≤ 820px) --- */
@media (max-width: 820px) {
  :root { --topbar-h: 56px; }
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }

  /* Sticky 56px topbar: drawer · search · status dot · compose */
  .topbar {
    min-height: 56px; gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }
  .topbar-icon { width: var(--touch-min); height: var(--touch-min); flex: none; padding: 0; font-size: 20px; line-height: 1; border-radius: 10px; }
  .topbar .cmdk-trigger, .topbar #notif-btn, .search-kbd { display: none; }
  .search-form { min-width: 0; }
  .search-shell { min-height: var(--touch-min); }
  .live-pill { flex: none; width: var(--touch-min); min-width: var(--touch-min); height: var(--touch-min); padding: 0; margin-left: 0; }
  .live-pill .live-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .live-pill .live-dot { width: 10px; height: 10px; }
  .live-pill.is-cached .live-dot { width: 18px; height: 18px; }
  .conn-banner { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

  /* Off-canvas navigation drawer */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--drawer-w); height: 100%; z-index: 60; overflow-y: auto;
    padding: max(12px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    transform: translateX(-100%); visibility: hidden;
    transition: transform 200ms cubic-bezier(0.2, 0, 0, 1), visibility 0s linear 200ms;
  }
  .drawer-open .sidebar {
    transform: translateX(0); visibility: visible; box-shadow: 8px 0 32px rgba(0, 0, 0, 0.28);
    transition: transform 200ms cubic-bezier(0.2, 0, 0, 1);
  }
  body.drawer-open { overflow: hidden; }
  .sidebar .nav-section { gap: 4px; }
  .sidebar .nav-item { min-height: var(--touch-min); padding: 10px 12px; font-size: 15px; }
  .nav-domains { flex: none; overflow: visible; }
  .sidebar-top .btn, .sidebar-footer .btn { min-height: var(--touch-min); padding: 10px 14px; }
  .drawer-close { width: var(--touch-min); height: var(--touch-min); font-size: 16px; padding: 0; }

  /* Two-line touch message rows: [check] [pill sender · date / subject snippet] [star] */
  .msg-row[data-id] {
    grid-template-columns: var(--touch-min) minmax(0, 1fr) var(--touch-min); align-items: center; gap: 10px; min-height: 76px;
    padding: 10px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  }
  .msg-row[data-id] .check-wrap { grid-column: 1; grid-row: 1; width: var(--touch-min); height: var(--touch-min); }
  .msg-row[data-id] .row-link {
    grid-column: 2; grid-row: 1; display: grid; grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "pill sender" "content content"; column-gap: 8px; row-gap: 4px; padding: 0;
  }
  .msg-row[data-id] .row-link .pill { grid-area: pill; max-width: 112px; justify-self: start; }
  .msg-row[data-id] .msg-sender { grid-area: sender; display: block; padding-right: 64px; font-size: 15px; }
  .msg-row[data-id] .msg-content { grid-area: content; font-size: 14px; }
  .msg-row[data-id] .row-right { display: contents; }
  .msg-row[data-id] .msg-meta,
  .msg-row[data-id]:hover .msg-meta,
  .msg-row[data-id].selected .msg-meta { display: flex; grid-column: 2; grid-row: 1; justify-self: end; align-self: start; margin-top: 2px; pointer-events: none; }
  .msg-row[data-id] .msg-meta .star { display: none; }
  .msg-row[data-id] .row-actions,
  .msg-row[data-id]:hover .row-actions,
  .msg-row[data-id].selected .row-actions { display: flex; grid-column: 3; grid-row: 1; justify-content: center; }
  .msg-row[data-id] .row-actions > :not(.row-star-form) { display: none; }
  .row-star-form { display: inline-flex; }
  .row-star-btn { width: var(--touch-min); height: var(--touch-min); padding: 0; font-size: 18px; border-color: transparent; background: transparent; color: var(--muted); }
  .row-star-btn.starred { color: #f59e0b; border-color: transparent; }

  /* Triage: actions move to the thumb-zone bar once something is selected */
  .triage-bar { padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); }
  .triage-right { display: none; }
  .has-selection .triage-right { display: flex; flex-wrap: wrap; gap: 8px; }
  .mobile-bulk-bar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.12);
    transform: translateY(110%); visibility: hidden;
    transition: transform 200ms cubic-bezier(0.2, 0, 0, 1), visibility 0s linear 200ms;
  }
  .has-selection .mobile-bulk-bar { transform: translateY(0); visibility: visible; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); }
  .mobile-bulk-count { min-width: 0; font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }
  .mobile-bulk-btn {
    display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-width: var(--touch-min); min-height: var(--touch-min); padding: 4px 6px; border: 0; border-radius: 10px;
    background: transparent; color: var(--text); font: inherit; font-size: 17px; line-height: 1; cursor: pointer;
  }
  .mobile-bulk-btn:active, .mobile-bulk-btn:focus-visible { background: var(--surface-alt); }
  .mobile-bulk-btn.danger { color: var(--danger); }
  .mobile-bulk-label { font-size: 10px; font-weight: 600; }
  .has-selection .main { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .has-selection .toast-stack { bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Reader & compose spacing; 16px fields stop iOS Safari focus auto-zoom */
  .reader-wrap { padding: 12px max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea { font-size: 16px !important; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .drawer-open .sidebar, .mobile-bulk-bar, .has-selection .mobile-bulk-bar { transition: none; }
  .live-pill.is-reconnecting .live-dot, .conn-banner.is-reconnecting .conn-banner-icon, .conn-banner.is-pulse { animation: none; }
}

/* ---------------------------------------------------------------------------------------
   Settings → Hosted Mail Server (unified muddle-box mode only)
   --------------------------------------------------------------------------------------- */
.hosted-server { margin: 18px 0 8px; padding: 18px; border: 1px solid var(--border); border-radius: 16px; background: linear-gradient(180deg, var(--surface-alt), transparent 220px); }
.hosted-server > .reply-card { margin-bottom: 14px; }
.hosted-server > .reply-card:last-child { margin-bottom: 0; }
.hosted-intro { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.hosted-intro h2 { margin: 0 0 4px; font-size: 20px; }
.hosted-intro p { margin: 0; max-width: 62ch; }
.hosted-stats { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; }
.hosted-stat { display: inline-flex; align-items: baseline; gap: 5px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 13px; text-decoration: none; }
.hosted-stat strong { color: var(--text); font-size: 15px; }
.hosted-stat:hover { border-color: var(--accent); color: var(--text); }
.hosted-domain-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.hosted-domain { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: hidden; }
.hosted-domain > summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; cursor: pointer; list-style: none; }
.hosted-domain > summary::-webkit-details-marker { display: none; }
.hosted-domain > summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s ease; }
.hosted-domain[open] > summary::before { transform: rotate(90deg); }
.hosted-domain[open] > summary { border-bottom: 1px solid var(--border); }
.hosted-domain-name { font-weight: 700; font-size: 15px; }
.hosted-domain-meta { font-size: 12px; }
.hosted-domain > summary .health-badge { margin-left: auto; }
.dns-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dns-table, .hosted-token-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dns-table th, .dns-table td, .hosted-token-table th, .hosted-token-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.dns-table thead th, .hosted-token-table thead th { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); background: var(--surface-alt); }
.dns-table tbody th { white-space: nowrap; font-weight: 600; }
.dns-table tbody tr:last-child > *, .hosted-token-table tbody tr:last-child > * { border-bottom: 0; }
.dns-type { display: inline-block; padding: 1px 7px; border-radius: 6px; font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--chip-op-bg); color: var(--chip-op-key); }
.dns-cell { min-width: 160px; }
.dns-value-cell { min-width: 260px; max-width: 520px; }
.dns-code { display: block; padding: 6px 8px; border-radius: 6px; background: var(--md-code-bg); color: var(--md-code-text); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; white-space: pre-wrap; user-select: all; }
.dns-value { max-height: 7.5em; overflow-y: auto; }
.dns-copy { margin-top: 4px; }
.dns-note { display: block; margin-top: 4px; font-size: 11px; }
.dns-status-cell { min-width: 150px; }
.dns-detail { display: block; margin-top: 4px; font-size: 11px; line-height: 1.4; word-break: break-word; }
.dns-detail:empty { display: none; }
.hosted-domain-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 14px; border-top: 1px solid var(--border); background: var(--surface-alt); }
.hosted-domain-actions-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dns-status { font-size: 12px; }
.hosted-add-form { margin-top: 6px; padding-top: 14px; border-top: 1px dashed var(--border); }
.hosted-add-form h3 { margin: 0 0 8px; font-size: 14px; }
.hosted-inline-fields { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.hosted-grow { flex: 1 1 260px; }
.hosted-hint { margin: 6px 0 0; font-size: 12px; }
.hosted-mailbox-list { list-style: none; margin: 0 0 14px; padding: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.hosted-mailbox { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.hosted-mailbox:last-child { border-bottom: 0; }
.hosted-mailbox-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.hosted-mailbox-email { font-weight: 600; word-break: break-all; }
.hosted-mailbox-meta { font-size: 12px; }
.hosted-mailbox-actions { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.kind-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: 0.02em; }
.kind-human { background: var(--chip-op-bg); color: var(--chip-op-key); }
.kind-agent { background: var(--warn-soft); color: var(--warn-text); }
.hosted-reset > summary { list-style: none; cursor: pointer; }
.hosted-reset > summary::-webkit-details-marker { display: none; }
.hosted-reset[open] > summary { background: var(--surface-alt); }
.hosted-reset-form { margin-top: 8px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-alt); min-width: 240px; }
.addr-combo { display: flex; align-items: center; gap: 6px; }
.addr-combo input { flex: 1 1 40%; min-width: 0; }
.addr-combo select { flex: 1 1 55%; min-width: 0; }
.addr-at { color: var(--muted); font-weight: 700; }
.scope-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin: 10px 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.scope-grid legend { padding: 0 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.scope-option { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; cursor: pointer; }
.scope-option input { margin-top: 2px; }
.scope-option code, .scope-pill { font: 600 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.scope-pill { display: inline-block; margin: 0 4px 4px 0; padding: 1px 7px; border-radius: 999px; background: var(--chip-op-bg); color: var(--chip-op-key); }
.token-label { font-weight: 600; word-break: break-word; }
.secret-reveal { margin: 0 0 14px; padding: 12px 14px; border: 1px solid var(--ok-dot); border-radius: 12px; background: var(--ok-soft); color: var(--ok-text); }
.secret-reveal[hidden] { display: none; }
.secret-reveal-title { margin: 0 0 8px; font-weight: 700; }
.secret-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.secret-value { flex: 1 1 320px; padding: 8px 10px; border-radius: 8px; background: var(--surface); color: var(--text); font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; user-select: all; }
.secret-reveal .muted { margin: 8px 0; }
@media (max-width: 640px) {
  .hosted-server { padding: 12px; border-radius: 12px; }
  .hosted-domain > summary .health-badge { margin-left: 0; }
  .dns-table thead { display: none; }
  .dns-table, .dns-table tbody, .dns-table tr, .dns-table th, .dns-table td { display: block; width: 100%; }
  .dns-table tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  .dns-table th, .dns-table td { border-bottom: 0; padding: 4px 12px; max-width: none; min-width: 0; }
}
