/* FreelanceReach v2 — design tokens, app shell and the shared component vocabulary (SPEC §5).
   Tab modules use only the documented classes; shell- and tab-specific rules are grouped at the end.
   theme.css (loaded after this file) redefines the tokens for the green glass identity; the meanings below hold everywhere.

   ================= COLOUR CODING — one meaning per colour, on every screen =================
   The brand green is for ACTIONS and SELECTION only (primary buttons, the chip you picked, the active tab, links).
   It is never a status. Status is always one of these six, each with a text (--x), a tint (--x-soft), a border
   (--x-line) and a dot/bar colour (--x-dot). Use them through the shared classes, never by hand-picked colour:

     token    meaning                                           classes
     --ok     sent · done · healthy · allowed · connected        .badge.ok  .pill.ok  .callout.ok  .cf.hot  .stat.ok  .dot.ok  .bar-ok
     --warn   waiting · held · needs you · unknown · paused      .badge.warn .pill.warn .callout.warn .stat.warn .dot.warn .bar-warn
     --err    failed · banned · removed · blocked · stop         .badge.err .pill.err .callout.err .stat.err .dot.err .bar-err
     --info   scheduled · informational · running · in progress  .badge.info .pill.info .callout (default) .stat.info .dot.info .bar-info
     --ai     written or learned by the AI                       .badge.ai  .pill.ai  .callout.ai  .chip.idea.ai  .ai-panel  .stat.ai
     --muted  off · not enough data · archived · skipped         .badge.off .pill.off .stat.off .dot.off  (and plain .muted text)

   --ok is a leaf green (#15803d / #4ade80), on purpose a different hue from the teal-leaning brand emerald (#047857),
   so "healthy" never looks like "selected". White text sits only on --primary, --danger-bg and --toast-bg, all ≥ 4.5:1.
   Charts use the same dots: a sent bar is --ok-dot, a failed bar --err-dot, a plain count --info-dot. */

/* ================= tokens ================= */
:root {
  color-scheme: light dark;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #edf1f7;
  --line: #e3e8ef;
  --line-strong: #cfd7e3;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #5f6b7d;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-text: #1d4ed8;
  --primary-soft: #eaf1fe;
  --primary-line: #c9dafc;
  --ring: rgba(37, 99, 235, 0.28);
  --focus: #2563eb;
  --accent: #2563eb;                            /* brand colour for non-text marks: on-switch, progress, active icon */
  --ok: #166534;  --ok-soft: #e8f6ec;  --ok-line: #bfe3c9;  --ok-dot: #22c55e;
  --warn: #a15c07; --warn-soft: #fdf3e1; --warn-line: #f5d9a6; --warn-dot: #f59e0b;
  --err: #c81e1e;  --err-soft: #fdecec;  --err-line: #f6c7c7;  --err-dot: #ef4444;
  --info: #0369a1; --info-soft: #e8f4fc; --info-line: #bddcf3; --info-dot: #0ea5e9;
  --ai: #6d4fc2;   --ai-soft: #f1edfc;   --ai-line: #d9cff6;   --ai-dot: #8b5cf6;
  --muted-dot: #9aa3b2;
  --danger-bg: #dc2626;
  --switch-off: #8a94a6;
  --seg-on: #ffffff;
  --ai-bg: var(--ai-soft);
  --topbar-bg: rgba(244, 246, 250, 0.86);
  --backdrop: rgba(15, 23, 42, 0.45);
  --toast-bg: #111827;
  --toast-ink: #f8fafc;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow-2: 0 4px 14px rgba(16, 24, 40, 0.08), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-3: 0 18px 50px rgba(16, 24, 40, 0.2), 0 4px 12px rgba(16, 24, 40, 0.08);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5' fill='none' stroke='%235f6b7d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --gutter: 16px;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --bottombar-h: 0px;
  /* motion: one vocabulary — --dur-1 presses and small state changes, --dur-2 panels and tabs, --dur-3 big layout moves */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  /* White text sits on these (sent bubbles, count badges, the primary quick button): the palette's brand colour. */
  --on-primary-bg: var(--primary);
  --on-primary-hover: var(--primary-hover);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --dur-1: 120ms;
  --dur-2: 220ms;
  --dur-3: 360ms;
}

/* Light / Dark / Auto (js/theme-boot.js and js/theme.js set data-theme on <html>; no attribute = Auto).
   The dark tokens appear twice: for Auto on a device in dark appearance, and for Dark chosen in the app.
   Keep the two copies identical. Always anchor theme selectors on :root (Studio uses data-theme on its chips). */
:root[data-theme="light"] { color-scheme: light; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1120;
    --surface: #121a2b;
    --surface-2: #172135;
    --surface-3: #1f2a40;
    --line: #243049;
    --line-strong: #34425f;
    --text: #e7ecf4;
    --text-2: #c3cddc;
    --muted: #8f9bb0;
    --primary: #2563eb;
    --primary-hover: #3570f0;
    --primary-text: #8ab4ff;
    --primary-soft: rgba(59, 130, 246, 0.16);
    --primary-line: rgba(96, 150, 255, 0.35);
    --ring: rgba(138, 180, 255, 0.35);
    --focus: #8ab4ff;
    --accent: #60a5fa;
    --ok: #4ade80;  --ok-soft: rgba(34, 197, 94, 0.14);    --ok-line: rgba(34, 197, 94, 0.35);   --ok-dot: #4ade80;
    --warn: #fbbf24; --warn-soft: rgba(245, 158, 11, 0.14); --warn-line: rgba(245, 158, 11, 0.35); --warn-dot: #fbbf24;
    --err: #fca5a5;  --err-soft: rgba(239, 68, 68, 0.14);   --err-line: rgba(239, 68, 68, 0.38);  --err-dot: #f87171;
    --info: #7dd3fc; --info-soft: rgba(14, 165, 233, 0.14); --info-line: rgba(56, 189, 248, 0.35); --info-dot: #38bdf8;
    --ai: #c4b5fd;   --ai-soft: rgba(139, 92, 246, 0.16);   --ai-line: rgba(167, 139, 250, 0.38);  --ai-dot: #a78bfa;
    --muted-dot: #6b7a92;
    --danger-bg: #dc2626;
    --switch-off: #4b5870;
    --seg-on: #2a3754;
    --ai-bg: var(--ai-soft);
    --topbar-bg: rgba(11, 17, 32, 0.86);
    --backdrop: rgba(2, 6, 23, 0.62);
    --toast-bg: #e7ecf4;
    --toast-ink: #0b1120;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-3: 0 22px 60px rgba(0, 0, 0, 0.6), 0 4px 14px rgba(0, 0, 0, 0.35);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5' fill='none' stroke='%238f9bb0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #121a2b;
  --surface-2: #172135;
  --surface-3: #1f2a40;
  --line: #243049;
  --line-strong: #34425f;
  --text: #e7ecf4;
  --text-2: #c3cddc;
  --muted: #8f9bb0;
  --primary: #2563eb;
  --primary-hover: #3570f0;
  --primary-text: #8ab4ff;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --primary-line: rgba(96, 150, 255, 0.35);
  --ring: rgba(138, 180, 255, 0.35);
  --focus: #8ab4ff;
  --accent: #60a5fa;
  --ok: #4ade80;  --ok-soft: rgba(34, 197, 94, 0.14);    --ok-line: rgba(34, 197, 94, 0.35);   --ok-dot: #4ade80;
  --warn: #fbbf24; --warn-soft: rgba(245, 158, 11, 0.14); --warn-line: rgba(245, 158, 11, 0.35); --warn-dot: #fbbf24;
  --err: #fca5a5;  --err-soft: rgba(239, 68, 68, 0.14);   --err-line: rgba(239, 68, 68, 0.38);  --err-dot: #f87171;
  --info: #7dd3fc; --info-soft: rgba(14, 165, 233, 0.14); --info-line: rgba(56, 189, 248, 0.35); --info-dot: #38bdf8;
  --ai: #c4b5fd;   --ai-soft: rgba(139, 92, 246, 0.16);   --ai-line: rgba(167, 139, 250, 0.38);  --ai-dot: #a78bfa;
  --muted-dot: #6b7a92;
  --danger-bg: #dc2626;
  --switch-off: #4b5870;
  --seg-on: #2a3754;
  --ai-bg: var(--ai-soft);
  --topbar-bg: rgba(11, 17, 32, 0.86);
  --backdrop: rgba(2, 6, 23, 0.62);
  --toast-bg: #e7ecf4;
  --toast-ink: #0b1120;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-3: 0 22px 60px rgba(0, 0, 0, 0.6), 0 4px 14px rgba(0, 0, 0, 0.35);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5.5 7.5 10 12l4.5-4.5' fill='none' stroke='%238f9bb0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (max-width: 899.98px) {
  :root { --bottombar-h: 64px; }
}

/* ================= base ================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px); }
html.no-scroll, html.sheet-open { overflow: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 0.9375rem/1.5 var(--font); /* 15px by default; follows the user's text size */
  letter-spacing: 0; /* body text: no tracking; titles tighten, small text opens (see below) */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent; /* fine only because every control has an :active style (press feedback, below) */
}
img, video, canvas { max-width: 100%; height: auto; }
svg { max-width: 100%; }
/* type scale: 11 / 12 / 13 / 15 / 17 / 20 / 22 / 28 px written as rem; tracking -0.02em on display sizes, -0.01em at 17–22,
   0 on body, +0.01em on small text */
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 1.5rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 650; }
h4 { font-size: 0.875rem; font-weight: 650; margin-top: 16px; color: var(--text-2); letter-spacing: 0; }
small, .small, .badge, .hint, .card-sub, .page-sub, .stat span, .notif-time, .conv-time, .conv-meta, .log-meta, .lp-meta, th { letter-spacing: 0.01em; }
p { margin: 0 0 8px; }
p:last-child { margin-bottom: 0; }
a { color: var(--primary-text); text-underline-offset: 2px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
b, strong { font-weight: 650; }
small { font-size: 0.8125rem; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
pre { margin: 0; padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font: 0.8125rem/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
ul, ol { margin: 0 0 8px; padding-left: 22px; }
::selection { background: var(--primary-soft); }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; } /* outlines follow each element's own radius */
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

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

/* ================= form controls ================= */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
select,
textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 12px;
  font-size: 0.9375rem;
  line-height: 1.4;
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--dur-1), box-shadow var(--dur-1), background-color var(--dur-1);
}
select {
  padding-right: 36px;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px 18px;
  cursor: pointer;
  text-overflow: ellipsis;
}
select[multiple] { background-image: none; padding-right: 12px; }
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.85; }
input:hover:not(:disabled):not(:focus), select:hover:not(:disabled):not(:focus), textarea:hover:not(:disabled):not(:focus) { border-color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible,
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input[type="checkbox"]:focus, input[type="radio"]:focus { box-shadow: none; }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input:disabled, select:disabled, textarea:disabled { background-color: var(--surface-2); color: var(--muted); cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; cursor: pointer; vertical-align: middle; }
input[type="file"] { max-width: 100%; font-size: 0.875rem; }
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
input::-webkit-date-and-time-value { text-align: left; }
input[type="number"] { font-variant-numeric: tabular-nums; }

label { display: block; font-size: 0.8125rem; font-weight: 550; color: var(--text-2); }
label > input:not([type="checkbox"]):not([type="radio"]), label > select, label > textarea { margin-top: 6px; font-weight: 400; }
label.inline { display: inline-flex; align-items: center; gap: 8px; }
label.inline > select, label.inline > input { width: auto; margin-top: 0; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > span:first-child, .field > .field-label { font-size: 0.8125rem; font-weight: 600; color: var(--text-2); }
label.field > input, label.field > select, label.field > textarea { margin-top: 0; }
.field .hint, .field > small, .hint { font-size: 0.7813rem; font-weight: 400; color: var(--muted); line-height: 1.45; }

/* ================= buttons + links ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  max-width: 100%;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9063rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color var(--dur-1), border-color var(--dur-1), color var(--dur-1), box-shadow var(--dur-1), transform var(--dur-1) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--err); border-color: var(--err-line); }
.btn.danger:hover { background: var(--err-soft); border-color: var(--err); }
.btn.primary.danger, .modal-foot .btn.danger { background: var(--danger-bg); border-color: var(--danger-bg); color: #fff; box-shadow: none; }
.btn.primary.danger:hover, .modal-foot .btn.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); box-shadow: none; }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.ghost.danger { color: var(--err); }
.btn.ghost.danger:hover { background: var(--err-soft); }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: 0.8438rem; border-radius: 8px; gap: 6px; }
.btn.block { display: flex; width: 100%; white-space: normal; text-align: center; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn.is-busy { opacity: 0.85; cursor: progress; }
a.btn { color: var(--text); }
a.btn.primary { color: #fff; }
a.btn.danger { color: var(--err); }

.link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  padding: 4px 6px;
  margin: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--primary-text);
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
}
.link:hover { text-decoration: underline; text-underline-offset: 2px; }
.link:disabled { opacity: 0.55; cursor: not-allowed; text-decoration: none; }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

@media (max-width: 480px) {
  .btn { white-space: normal; text-align: center; }
}

/* ================= chips, badges, pills ================= */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  max-width: 100%;
  padding: 4px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.8438rem;
  font-weight: 550;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color var(--dur-1), border-color var(--dur-1), color var(--dur-1), transform var(--dur-1) var(--ease);
}
.chip:hover { border-color: var(--primary); color: var(--text); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.on:hover { background: var(--primary-hover); }
a.chip { color: var(--text-2); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge.err { background: var(--err-soft); color: var(--err); border-color: var(--err-line); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: var(--info-line); }
.badge.ai { background: var(--ai-soft); color: var(--ai); border-color: var(--ai-line); }
.badge.off, .badge.muted { background: var(--surface-3); color: var(--muted); border-color: transparent; }
/* status dots: <i class="dot ok"> — the same six meanings as badges */
.dot { display: inline-block; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted-dot); vertical-align: middle; }
.dot.ok { background: var(--ok-dot); }
.dot.warn { background: var(--warn-dot); }
.dot.err { background: var(--err-dot); }
.dot.info { background: var(--info-dot); }
.dot.ai { background: var(--ai-dot); }
.dot.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted-dot); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  max-width: 100%;
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.8125rem;
  font-weight: 550;
  line-height: 1.3;
  text-decoration: none;
  vertical-align: middle;
}
.pill.ok::before, .pill.warn::before, .pill.err::before, .pill.info::before, .pill.ai::before, .pill.off::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted-dot);
}
.pill.ok::before { background: var(--ok-dot); }
.pill.warn::before { background: var(--warn-dot); }
.pill.err::before { background: var(--err-dot); }
.pill.info::before { background: var(--info-dot); animation: pulse 1.4s ease-in-out infinite; } /* running */
.pill.ai::before { background: var(--ai-dot); }
.pill.off { color: var(--muted); }
button.pill, a.pill { min-height: 36px; padding: 4px 14px 4px 12px; background: var(--surface); cursor: pointer; transition: border-color var(--dur-1), box-shadow var(--dur-1), transform var(--dur-1) var(--ease); }
button.pill:hover, a.pill:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); }
.pill > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-2);
  font: 0.75rem/1.5 var(--mono);
  white-space: nowrap;
}

/* ================= layout helpers ================= */
.row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.row.gap-sm, .stack.gap-sm, .between.gap-sm, .gap-sm { gap: 6px; }
.row.wrap.gap-sm { gap: 6px 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.row > input:not([type="checkbox"]):not([type="radio"]), .row > select { width: auto; flex: 1 1 160px; }
.row > textarea { flex: 1 1 auto; }
.row > .btn, .row > .link, .row > .chip, .row > .badge, .row > .switch { flex: none; }
.row.wrap > .btn { flex: 0 1 auto; }

.grid2, .grid3, .grid4 { display: grid; gap: 14px 16px; min-width: 0; }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid2 > *, .grid3 > *, .grid4 > * { min-width: 0; }
.grid2 > .card + .card, .grid3 > .card + .card, .grid4 > .card + .card { margin-top: 0; }
@media (max-width: 1180px) { .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1080px) and (min-width: 900px) { .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 359.98px) { .grid4 { grid-template-columns: minmax(0, 1fr); } }

/* ================= cards ================= */
.card {
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 16px; }
.card[data-card] { padding: 0; }
.card-head { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 8px 12px 8px 8px; }
.card-toggle {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 42px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.card-toggle:hover { background: var(--surface-2); }
.card-h { display: flex; flex: 1 1 auto; min-width: 0; margin: 0; font: inherit; letter-spacing: inherit; line-height: inherit; color: inherit; } /* the h2 around the toggle: a heading for screen readers, invisible otherwise */
.card-toggle .chev { flex: none; color: var(--muted); transition: transform var(--dur-2) var(--ease); }
.card.collapsed .card-toggle .chev { transform: rotate(-90deg); }
.card-icon { flex: none; width: 24px; font-size: 1.125rem; text-align: center; line-height: 1; }
.card-titles { display: flex; flex-direction: column; min-width: 0; }
.card-title { font-size: 0.9688rem; font-weight: 650; line-height: 1.3; letter-spacing: -0.005em; }
.card-sub { font-size: 0.7813rem; font-weight: 400; color: var(--muted); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; }
.card-actions { display: flex; flex: none; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; max-width: 60%; }
.card-actions:empty { display: none; }
.card[data-card] > .card-body { padding: 4px 16px 18px; }
.card.collapsed > .card-body { display: none; }
.card:not(.collapsed) > .card-body { animation: fade-in var(--dur-2) var(--ease-out); }
.card-body > * + * { margin-top: 12px; }
.card-body > :is(h3, h4) + * { margin-top: 6px; }
.card-body h3 { font-size: 0.9375rem; margin: 18px 0 0; }
.card-body h4 { margin: 18px 0 0; }
.card-body > :first-child { margin-top: 0; }
@media (max-width: 520px) {
  .card-head { flex-wrap: wrap; padding: 8px 10px 8px 6px; }
  .card-actions { max-width: 100%; margin-left: 38px; justify-content: flex-start; }
  .card-actions:empty { display: none; }
  .card[data-card] > .card-body { padding: 2px 14px 16px; }
  .card { padding: 14px; }
}

/* ================= stats ================= */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  color: var(--text);
  text-align: left;
  text-decoration: none;
}
.stat b { display: block; font-size: 1.5rem; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat span { display: block; font-size: 0.7813rem; color: var(--muted); line-height: 1.35; }
/* tone on a tile colours the number only (the label stays muted): .stat.ok / .warn / .err / .info / .ai / .off */
.stat.ok b { color: var(--ok); }
.stat.warn b { color: var(--warn); }
.stat.err b { color: var(--err); }
.stat.info b { color: var(--info); }
.stat.ai b { color: var(--ai); }
.stat.off b { color: var(--muted); }
button.stat, a.stat { cursor: pointer; transition: border-color var(--dur-1), box-shadow var(--dur-1), transform var(--dur-1) var(--ease); }
button.stat:hover, a.stat:hover { border-color: var(--line-strong); box-shadow: var(--shadow-2); }
@media (max-width: 899.98px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .stat { padding: 12px 14px; } .stat b { font-size: 1.375rem; } }

/* ================= lists ================= */
.list { display: flex; flex-direction: column; min-width: 0; }
.list-item { display: block; min-width: 0; padding: 14px 0; border-bottom: 1px solid var(--line); }
.list-item:first-child { padding-top: 4px; }
.list-item:last-child { border-bottom: 0; padding-bottom: 2px; }

.checklist {
  max-height: 360px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}
.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 400;
  cursor: pointer;
}
.check-item:last-child { border-bottom: 0; }
.check-item:hover { background: var(--surface-2); }
.check-item .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { background: var(--surface-2); color: var(--muted); font-size: 0.75rem; font-weight: 650; letter-spacing: 0.02em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.table-wrap td { white-space: nowrap; }

/* Groups tab (public/js/groups.js): a group's badges (channel, its rules, members, last post) follow its name. On a phone
   the name keeps the line beside its checkbox and wraps instead of shrinking to nothing, the badges get a line of their
   own under it, and in the search-result and suggestion tables long names wrap and the cells sit closer, so a row's
   Ignore / Restore stays on screen — no sideways scrolling. */
.g-badges { display: contents; }
.table-wrap td .g-in { white-space: normal; min-width: 12em; } /* "Your accounts in it: …" under a search result wraps, never widens the table */
@media (max-width: 600px) {
  .check-item.g-row { flex-wrap: wrap; align-items: flex-start; row-gap: 4px; }
  .check-item.g-row > input[type="checkbox"] { margin-top: 2px; }
  .check-item.g-row > .grow { flex: 1 1 calc(100% - 40px); min-width: 0; white-space: normal; overflow-wrap: anywhere; }
  .check-item.g-row > .g-badges { display: flex; flex: 1 1 100%; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding-left: 28px; }
  .g-table th, .g-table td { padding: 8px 5px; }
  .table-wrap td.g-title { white-space: normal; overflow-wrap: anywhere; }
  .table-wrap td.g-title > div { min-width: 5.5em; }
}

.progress { height: 8px; overflow: hidden; border-radius: 999px; background: var(--surface-3); }
.progress > div { height: 100%; width: 0; border-radius: inherit; background: var(--info-dot); transition: width var(--dur-3) var(--ease); } /* a running job is --info */
.progress.ok > div { background: var(--ok-dot); }
.progress.warn > div { background: var(--warn-dot); }
.progress.err > div { background: var(--err-dot); }
.progress.ai > div { background: var(--ai-dot); }

.empty {
  padding: 26px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}
.empty > * + * { margin-top: 10px; }
.empty .spinner { margin-right: 6px; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.thumbs > .empty, .thumbs > .callout { grid-column: 1 / -1; }
.thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface-3);
  color: var(--muted);
  cursor: pointer;
  transition: border-color var(--dur-1), box-shadow var(--dur-1), transform var(--dur-1) var(--ease);
}
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb img:not([src]) { visibility: hidden; }
.thumb:hover { border-color: var(--primary); box-shadow: var(--shadow-2); }
.thumb.on, .thumb[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.thumb.broken::after { content: "⚠︎"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.375rem; }

/* ================= switch + segmented control ================= */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  max-width: 100%;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  vertical-align: middle;
}
.switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 42px;
  height: 24px;
  margin: 0;
  border: 0;
  border-radius: 999px;
  background-color: var(--switch-off);
  /* the knob: a white disc with a soft edge, like iOS, so it reads on the off track too */
  background-image: radial-gradient(circle at center, #fff 0, #fff 8.5px, rgba(255, 255, 255, 0) 9.5px), radial-gradient(circle at center, rgba(4, 40, 28, 0.25) 0, rgba(4, 40, 28, 0.25) 9.5px, rgba(4, 40, 28, 0) 11px);
  background-repeat: no-repeat;
  background-size: 24px 24px;
  background-position: 0 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  cursor: pointer;
  transition: background-color var(--dur-2), background-position var(--dur-2) var(--ease);
}
.switch input[type="checkbox"]:checked { background-color: var(--accent); background-position: 100% 50%; }
.switch input[type="checkbox"]:disabled { opacity: 0.5; cursor: not-allowed; }
.switch input[type="checkbox"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch-label:empty { display: none; }

.seg {
  display: inline-flex;
  max-width: 100%;
  gap: 2px;
  padding: 3px;
  overflow-x: auto;
  border-radius: 11px;
  background: var(--surface-3);
  scrollbar-width: none;
  vertical-align: middle;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none;
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.875rem;
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur-1), color var(--dur-1), box-shadow var(--dur-1), transform var(--dur-1) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--seg-on); color: var(--text); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line-strong); } /* a ring, not bold: bold would change the width and make the row jump */

/* ================= callouts, spinner ================= */
.callout {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--info-line);
  border-radius: var(--r);
  background: var(--info-soft);
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1.5;
}
.callout.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.callout.err { background: var(--err-soft); border-color: var(--err-line); }
.callout.ok { background: var(--ok-soft); border-color: var(--ok-line); }
.callout.ai { background: var(--ai-soft); border-color: var(--ai-line); }
.callout > * + * { margin-top: 8px; }
.callout p { margin: 0; }
.callout .row { margin-top: 10px; }

.spinner {
  display: inline-block;
  flex: none;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.15em;
  opacity: 0.85;
  animation: spin 0.7s linear infinite;
}

/* ================= AI panel ================= */
.ai-panel { overflow: hidden; border: 1px solid var(--ai-line); border-radius: var(--r); background: var(--ai-bg); }
.ai-head { display: flex; align-items: center; gap: 4px; padding: 4px; }
.ai-toggle {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 40px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}
.ai-toggle:hover { background: var(--ai-soft); }
.ai-toggle .chev { flex: none; color: var(--muted); transition: transform var(--dur-2) var(--ease); }
.ai-panel.collapsed .ai-toggle .chev { transform: rotate(-90deg); }
.ai-panel.collapsed .ai-body { display: none; }
.ai-body { display: flex; flex-direction: column; gap: 10px; padding: 0 12px 12px; }
.variant { padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 0.875rem; }
.variant-num { margin-bottom: 4px; color: var(--muted); font-size: 0.75rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.variant-subject { margin-bottom: 6px; font-weight: 600; }
.variant-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.variant-actions { margin-top: 10px; }
.ai-foot { padding: 0 2px; }

/* ================= utilities (last, so they win) ================= */
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.mt { margin-top: 12px !important; }
.mb { margin-bottom: 12px !important; }
.center { text-align: center; }
.row.center, .stack.center { justify-content: center; }
.hidden { display: none !important; }
.strong { font-weight: 650; }
.clamp1, .clamp2, .clamp3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.clamp1 { -webkit-line-clamp: 1; line-clamp: 1; }
.clamp2 { -webkit-line-clamp: 2; line-clamp: 2; }
.clamp3 { -webkit-line-clamp: 3; line-clamp: 3; }

/* ================= app shell ================= */
.noscript { padding: 24px; text-align: center; }
.splash, .login { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 24px 16px; }
.splash-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; max-width: 340px; }
.splash-slow { opacity: 0; animation: fade-in 0.4s ease 12s forwards; }
.login { background: radial-gradient(900px 480px at 50% -8%, var(--primary-soft), transparent 70%), var(--bg); }
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 32px 24px 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  text-align: center;
}
.login-card h1 { margin: 14px 0 4px; font-size: 1.375rem; }
.login-form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; text-align: left; }
.login-form input { text-align: center; font-size: 1.125rem; letter-spacing: 0.08em; }
.login-err { min-height: 1.4em; margin: 12px 0 0; color: var(--err); font-size: 0.875rem; }
.login-foot { margin-top: 14px; }

.skip-link { position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 8px; z-index: 200; padding: 8px 14px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 600; transform: translateY(-160%); transition: transform var(--dur-1); }
.skip-link:focus { transform: none; }

.app { min-height: 100vh; min-height: 100dvh; }
.app-main { min-width: 0; }

.sidebar { display: none; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--text); font-size: 1.0313rem; font-weight: 750; letter-spacing: -0.01em; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text-2);
  font-size: 0.9063rem;
  font-weight: 550;
  text-decoration: none;
  transition: background-color var(--dur-1), color var(--dur-1), transform var(--dur-1) var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-text); font-weight: 650; }
.nav-ico { display: inline-block; width: 22px; font-size: 1.0625rem; line-height: 1; text-align: center; }
.side-nav .nav-item:not(.active) .nav-ico { filter: saturate(0.55); opacity: 0.9; }
.nav-sep { height: 1px; margin: 10px 12px; background: var(--line); }
.sidebar-foot { margin: auto 0 0; padding: 14px 12px 0; line-height: 1.4; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .topbar { background: var(--topbar-bg); -webkit-backdrop-filter: saturate(1.5) blur(14px); backdrop-filter: saturate(1.5) blur(14px); }
}
.topbar-logo { flex: none; border-radius: 7px; }
.page-title { flex: 1 1 auto; min-width: 0; margin: 0; overflow: hidden; font-size: 1.125rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; flex: none; align-items: center; gap: 4px; }
.bell-count {
  position: absolute;
  top: -4px;
  right: -6px; /* on the button's corner, so even "99+" leaves the bell readable */
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border: 2px solid var(--bg);
  border-radius: 999px;
  background: var(--danger-bg);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.content {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px max(var(--gutter), env(safe-area-inset-right)) calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 32px) max(var(--gutter), env(safe-area-inset-left));
  overflow-x: clip;
}
.content:focus { outline: none; }

.tab { display: none; min-width: 0; }
.tab.active { display: block; animation: tab-in var(--dur-2) var(--ease); }
.tab > * + * { margin-top: 16px; }
.tab > div:empty { display: none; } /* placeholder slots (banners, setup steps) take no space until filled */
.tab > div:empty:first-child + * { margin-top: 0; }
.tab > h1:first-child, .tab > h2:first-child { /* the top bar already shows the page title */
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}
.tab-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px 0; color: var(--muted); }
.tab-error { max-width: 640px; }

/* phones: bottom bar + More sheet */
.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.05);
}
.bottombar .nav-item {
  flex: 1 1 0;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 0;
  padding: 6px 2px;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 600;
}
.bottombar .nav-item:hover { background: none; }
/* the active capsule: 30px tall around a 22px icon, so the icon has room on every side */
.bottombar .nav-ico { width: auto; height: 30px; min-width: 52px; padding: 0 16px; border-radius: 999px; font-size: 1.25rem; transition: background-color var(--dur-2), transform var(--dur-1) var(--ease); }
.bottombar .nav-ico svg { width: 22px; height: 22px; }
.bottombar .nav-item:not(.active) .nav-ico { filter: none; opacity: 1; } /* the SVG icons are already one colour; dimming dropped them under 3:1 */
.bottombar .nav-item.active { color: var(--primary-text); background: none; }
.bottombar .nav-item.active .nav-ico { background: var(--primary-soft); }
.bottombar .nav-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more-btn .nav-ico { color: inherit; }
/* new alerts while Alerts sits inside the closed More sheet */
.more-btn.has-new::after { content: ""; position: absolute; top: 7px; left: calc(50% + 10px); width: 9px; height: 9px; border-radius: 50%; background: var(--err-dot); box-shadow: 0 0 0 2px var(--bg); }
/* The on-screen keyboard is open (core.js sets html.kb-open on touch screens): the bottom bar steps aside and everything
   measured from it (the Settings save bar, Send's bar, the Inbox conversation, the pop-ups) moves down to the keyboard, so
   the field you type in keeps the room. The save bar stays — just above the keyboard. Settings' section menu stops
   sticking under the top bar, which would otherwise cover half of what is left. */
html.kb-open { --bottombar-h: 0px; }
html.kb-open .bottombar { display: none; }
html.kb-open .set-menu { position: static; }

.sheet { position: fixed; inset: 0; z-index: 25; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--backdrop); opacity: 0; transition: opacity var(--dur-2); }
.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
  max-height: 75vh;
  max-height: 75dvh;
  overflow-y: auto;
  padding: 0 max(14px, env(safe-area-inset-right)) 16px max(14px, env(safe-area-inset-left));
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform-origin: 50% 100%;
  transform: translateY(calc(100% + var(--bottombar-h) + 40px));
  transition: transform var(--dur-3) var(--ease);
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
/* the grab bar is a real handle (main.js: drag down to dismiss); the 22px strip is the touch area, the bar is drawn inside it */
.sheet-grab { position: relative; width: 100%; height: 22px; margin: 0 0 6px; background: none; touch-action: none; cursor: grab; }
.sheet-grab::before { content: ""; position: absolute; left: 50%; top: 9px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--line-strong); }
.sheet-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.sheet-grid .nav-item {
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-height: 86px;
  padding: 12px 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 0.8125rem;
  text-align: center;
}
.sheet-grid .nav-item.active { border-color: var(--primary-line); background: var(--primary-soft); }
.sheet-grid .nav-ico, .sheet-grid .nav-ico svg { width: 24px; height: 24px; font-size: 1.5625rem; }

@media (min-width: 900px) {
  :root { --topbar-h: 64px; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    padding: calc(20px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    overflow-y: auto;
    border-right: 1px solid var(--line);
    background: var(--surface);
  }
  .app-main { margin-left: var(--sidebar-w); }
  .topbar { padding: 0 32px; }
  .topbar-logo { display: none; }
  .page-title { font-size: 1.375rem; }
  .content { padding: 24px 32px 56px; }
  .bottombar, .sheet { display: none !important; }
}

/* notifications */
.notif-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: max(12px, env(safe-area-inset-right));
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 24px));
  max-height: min(72vh, 580px);
  max-height: min(72dvh, 580px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform-origin: top right; /* it hangs from the bell */
  animation: pop-in var(--dur-2) var(--ease) both;
}
.notif-panel.closing { animation: pop-out var(--dur-1) var(--ease) both; pointer-events: none; }
.notif-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 8px 16px; border-bottom: 1px solid var(--line); }
.notif-head h2 { margin: 0; font-size: 0.9375rem; }
.notif-list { overflow-y: auto; overscroll-behavior: contain; }
.notif-list > .empty, .notif-list > .callout { margin: 12px; }
.notif {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.notif:last-child { border-bottom: 0; }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: var(--primary-soft); }
.notif.unread:hover { background: var(--primary-soft); filter: brightness(0.98); }
.notif-ico { flex: none; width: 24px; font-size: 1.125rem; line-height: 1.3; text-align: center; }
.notif-main { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; }
.notif-title { font-size: 0.875rem; font-weight: 600; line-height: 1.35; }
.notif-body { color: var(--text-2); font-size: 0.8125rem; line-height: 1.4; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.notif-time { color: var(--muted); font-size: 0.75rem; }
.notif.unread .notif-title::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--accent); vertical-align: 2px; }

/* toasts */
/* Shown under the top bar, so they never cover the bottom bar or a sticky Save bar. */
.toasts {
  position: fixed;
  left: 50%;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  z-index: 960; /* above the lead pop-ups (950): a "Copied" or error toast must never hide behind a card */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  max-width: 100%;
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  box-shadow: var(--shadow-3);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  overflow-wrap: anywhere;
  opacity: 0;
  transform-origin: 50% 0;
  transform: translateY(-8px) scale(0.98);
  transition: opacity var(--dur-2), transform var(--dur-2) var(--ease);
  pointer-events: auto;
  cursor: pointer;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger-bg); color: #fff; }
/* an action inside a toast, e.g. Undo (core.toast's `action` option) */
.toast-act { margin-left: 10px; min-height: 32px; padding: 0 4px; border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; border-radius: 6px; }
.toast-act:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }

/* modal dialogs */
.modal-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: var(--backdrop); animation: fade-in var(--dur-2) var(--ease-out) both; }
.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform-origin: 50% 100%; /* grows up from where the sheet form comes from on phones */
  animation: modal-in var(--dur-2) var(--ease) both;
}
.modal:focus { outline: none; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 4px 20px; }
.modal-title { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 1.0625rem; font-weight: 700; }
.modal-body { flex: 1 1 auto; min-height: 0; padding: 8px 20px 18px; overflow-y: auto; overscroll-behavior: contain; }
.modal.untitled .modal-body { padding-top: 22px; }
.modal-body > * + * { margin-top: 12px; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.modal-wrap.closing { pointer-events: none; }
.modal-wrap.closing .modal { animation: modal-out var(--dur-1) var(--ease) both; } /* exits along the path it entered on */
.modal-wrap.closing .modal-backdrop { animation: fade-out var(--dur-1) var(--ease) both; }
.confirm-msg { font-size: 0.9375rem; line-height: 1.55; white-space: pre-line; }
.copy-box { font-family: var(--mono); font-size: 0.8125rem; }
@media (max-width: 640px) {
  .modal-wrap { align-items: flex-end; padding: 0; }
  .modal, .modal.wide {
    max-width: none;
    max-height: 92vh;
    max-height: 92dvh;
    border-width: 1px 0 0;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation-name: sheet-in;
  }
  .modal-wrap.closing .modal { animation-name: sheet-out; }
  .modal-foot .btn { flex: 1 1 120px; }
}

/* ================= Home ================= */
.home-hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; }
.home-hero h2 { margin: 0; font-size: 1.0625rem; font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; } /* page title 28 / greeting 17 / date 15 muted */
.home-hero p { margin: 4px 0 0; }
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.quick-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: var(--text);
  text-align: left;
  transition: border-color var(--dur-1), box-shadow var(--dur-1), transform var(--dur-1) var(--ease);
}
.quick-btn:hover { border-color: var(--primary-line); box-shadow: var(--shadow-2); }
.quick-btn.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.quick-btn.primary:hover { background: var(--primary-hover); }
.quick-ico { display: grid; flex: none; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--surface-3); font-size: 1.1875rem; }
.quick-btn.primary .quick-ico { background: rgba(255, 255, 255, 0.18); }
.quick-text { display: flex; flex-direction: column; min-width: 0; }
.quick-text b { font-size: 0.9063rem; line-height: 1.25; }
.quick-text span { font-size: 0.7813rem; opacity: 0.8; line-height: 1.3; }
@media (max-width: 1080px) { .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 420px) { .quick-btn { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; } .quick-ico { width: 34px; height: 34px; } }
.pills { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pills-label { margin-right: 2px; color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.setup-step { display: flex; align-items: center; gap: 12px; }
.setup-check { display: grid; flex: none; place-items: center; width: 24px; height: 24px; border: 2px solid var(--line-strong); border-radius: 50%; color: #fff; font-size: 0.8125rem; font-weight: 800; }
.setup-step.done .setup-check { border-color: var(--ok-dot); background: var(--ok-dot); }
.setup-step.done .setup-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
.ap-row, .lead-row, .note-row { display: flex; align-items: flex-start; gap: 12px; }
.ap-ico, .note-ico { display: grid; flex: none; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--surface-3); font-size: 1.0625rem; }
.ap-row .switch { margin-top: -4px; }
.sw-compact { flex: none; }
.sw-compact .switch-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.lead-text { margin-top: 4px; }
.lead-row .lead-acts { flex: none; }
.spend-line { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.spend-line b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) {
  .lead-row { flex-wrap: wrap; }
  .lead-row .lead-acts { width: 100%; }
}

/* ================= Accounts ================= */
.acc-list { display: flex; flex-direction: column; gap: 12px; }
.acc { padding: 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); }
.acc > * + * { margin-top: 10px; }
.acc-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.avatar { display: grid; flex: none; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-text); font-size: 1.0625rem; font-weight: 750; text-transform: uppercase; }
.acc.is-off .avatar { background: var(--surface-3); color: var(--muted); }
.acc-name { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 0.9375rem; font-weight: 650; }
.acc-name > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.acc-switches { display: flex; flex-wrap: wrap; gap: 0 20px; }
.acc details { border-top: 1px solid var(--line); padding-top: 10px; }
.acc details > summary { display: flex; align-items: center; gap: 6px; min-height: 36px; color: var(--primary-text); font-size: 0.875rem; font-weight: 600; cursor: pointer; list-style: none; }
.acc details > summary::-webkit-details-marker { display: none; }
.acc details > summary::before { content: "▸"; display: inline-block; width: 12px; color: var(--muted); transition: transform var(--dur-1); }
.acc details[open] > summary::before { transform: rotate(90deg); }
.acc details > div { padding-top: 10px; }
.acc details > div > * + * { margin-top: 12px; }
.net-table td:first-child { font-weight: 650; }
.login-flow > * + * { margin-top: 14px; }
.steps { margin: 0; padding-left: 20px; }
.steps li + li { margin-top: 4px; }
.qr-frame {
  display: grid;
  place-items: center;
  width: 260px;
  height: 260px;
  max-width: 100%;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  color: #475569;
  font-size: 0.875rem;
  overflow: hidden;
}
.qr-frame img { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.qr-frame .qr-done { font-size: 2.125rem; }
.qr-frame.scanned { width: 76px; height: 76px; border-radius: 50%; border-color: var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.flow-msg { min-height: 1.5em; text-align: center; }
.flow-msg.err { color: var(--err); }

/* ================= Settings ================= */
.sticky-save {
  position: sticky;
  bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 10px);
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bar-bg, var(--surface)); /* near-solid: settings scroll underneath (theme.css adds the blur) */
  box-shadow: var(--shadow-2);
}
.sticky-save.dirty { border-color: var(--primary-line); }
.sticky-save .save-state { min-width: 0; font-size: 0.8438rem; color: var(--muted); }
.sticky-save.dirty .save-state { color: var(--text); font-weight: 600; }
@media (min-width: 900px) { .sticky-save { bottom: 16px; } }
.subhead { margin: 22px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--text); font-size: 0.875rem; font-weight: 700; }
.card-body > .subhead:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.secret-state { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 0.7813rem; font-weight: 400; color: var(--muted); }
.secret-state .link { min-height: 0; padding: 0 2px; font-size: 0.7813rem; }
.secret-state.clearing { color: var(--err); }
.wh-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) auto auto; gap: 8px; align-items: center; }
@media (max-width: 720px) {
  .wh-row { grid-template-columns: minmax(0, 1fr) auto auto; }
  .wh-row .wh-url { grid-column: 1 / -1; grid-row: 2; }
}
.tpl-preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.tpl-acts { display: flex; flex: none; gap: 6px; }
.card-body h4.tpl-head { margin: 18px 0 2px; color: var(--muted); font-size: 0.8125rem; }
.card-body h4.tpl-head:first-child { margin-top: 0; }
.sticky-save .save-state.err { color: var(--err); font-weight: 600; }
@media (max-width: 520px) {
  .tpl-row { flex-wrap: wrap; }
  .tpl-acts { width: 100%; }
  .sticky-save { flex-wrap: wrap; }
  .sticky-save > .row { margin-left: auto; }
}

/* invalid fields (set by Settings and others via aria-invalid) */
[aria-invalid="true"]:not(:focus) { border-color: var(--err) !important; }
[aria-invalid="true"]:focus { border-color: var(--err) !important; box-shadow: 0 0 0 3px var(--err-soft) !important; }
.field > .switch { font-size: 0.875rem; font-weight: 500; color: var(--text); }

/* ================= motion ================= */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes tab-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
/* enter and exit share one path: a popover grows out of its trigger and shrinks back into it */
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes pop-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-4px) scale(0.96); } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes modal-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-out { from { transform: none; } to { transform: translateY(100%); } }

/* ================= press feedback: every control answers on pointer-down, before release =================
   (core.js registers an empty touchstart listener so iOS Safari applies :active at all) */
.btn:not(:disabled):active, .chip:active, .seg button:active, .icon-btn:active, button.pill:active, a.pill:active,
button.stat:active, a.stat:active, .thumb:active, .quick-btn:active, .bd-pcard:active, .vari-item:active,
.sheet-grid .nav-item:active, .bottombar .nav-item:active .nav-ico, .lp-x:active, .thumb-x:active, .toast-act:active {
  transform: scale(0.97);
  transition: transform 100ms var(--ease-out);
}
.btn:not(:disabled):active { transform: scale(0.97); }
.conv:active, .notif:active, .check-item:active, .card-toggle:active, .pp-toggle:active, .qr-item:active, .msel-opt:active,
.ai-toggle:active, .link:active, .bd-table tr[data-open]:active td, .acc details > summary:active {
  background: var(--surface-3);
  transition: background-color 0s;
}
.sidebar .nav-item:active { background: var(--side-active, var(--surface-3)); transform: scale(0.98); transition: transform 100ms var(--ease-out); }
.switch:active input[type="checkbox"]:not(:disabled) { background-size: 28px 24px; }

/* hover is a mouse thing: on touch screens a tap must not leave a "hovered" look behind */
@media (hover: none) {
  .chip:not(.on):hover { border-color: var(--line-strong); color: var(--text-2); }
  .chip.on:hover { background: var(--primary); }
  .btn:hover { background: var(--surface); border-color: var(--line-strong); }
  .btn.primary:hover { background: var(--primary); border-color: var(--primary); }
  .btn.ghost:hover { background: transparent; color: var(--text-2); }
  .btn.danger:hover { background: var(--surface); border-color: var(--err-line); }
  .btn.primary.danger:hover, .modal-foot .btn.danger:hover { background: var(--danger-bg); border-color: var(--danger-bg); }
  .thumb:not(.on):not([aria-pressed="true"]):hover { border-color: var(--line); box-shadow: none; }
  .vari-item:not(.on):hover, .bd-pcard:hover { border-color: var(--line); }
  .quick-btn:hover, button.stat:hover, a.stat:hover { border-color: var(--line); box-shadow: var(--shadow-1); }
  .icon-btn:hover { background: transparent; color: var(--text-2); }
  .card-toggle:hover, .ai-toggle:hover, .pp-toggle:hover, .conv:not(.active):hover, .notif:not(.unread):hover, .check-item:hover, .qr-item:not(.on):hover, .msel-opt:hover { background: transparent; }
  .nav-item:not(.active):hover { background: none; color: var(--text-2); }
  .seg button:not(.on):hover { color: var(--text-2); }
  .link:hover { text-decoration: none; }
  button.pill:hover, a.pill:hover { border-color: var(--line); box-shadow: none; }
  tbody tr:hover td, .bd-table tr[data-open]:hover td { background: transparent; }
  input:hover:not(:disabled):not(:focus), select:hover:not(:disabled):not(:focus), textarea:hover:not(:disabled):not(:focus) { border-color: var(--line-strong); }
}

/* Reduce Motion: everything still answers, but by cross-fading — nothing slides, scales or pulses */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
  .tab.active, .modal, .notif-panel, .card:not(.collapsed) > .card-body { animation-name: fade-in; animation-duration: var(--dur-2); }
  .modal-wrap.closing .modal, .notif-panel.closing { animation-name: fade-out; animation-duration: var(--dur-1); }
  .sheet-panel { transform: none; opacity: 0; transition: opacity var(--dur-2); }
  .sheet.open .sheet-panel { opacity: 1; }
  .toast, .lead-pop { transform: none !important; transition: opacity var(--dur-2); }
  .btn:active, .chip:active, .seg button:active, .icon-btn:active, button.pill:active, a.pill:active, button.stat:active, a.stat:active,
  .thumb:active, .quick-btn:active, .bd-pcard:active, .vari-item:active, .sheet-grid .nav-item:active, .bottombar .nav-item:active .nav-ico,
  .sidebar .nav-item:active, .lp-x:active, .thumb-x:active, .toast-act:active { transform: none; opacity: 0.7; transition: opacity 0s; }
  .skip-link { transition: none; }
  .pill.info::before, .bd-now .dot.live, .sw-dot.busy, .sw-busy .sw-dot { animation: none; }
  .progress > div, .card-toggle .chev, .ai-toggle .chev, .pp-chev, .switch input[type="checkbox"] { transition-duration: 0.01ms; }
  .spinner { animation-duration: 1.6s; }
  .splash-slow { animation-delay: 12s; }
}

/* ================= keyword ideas (core.suggestChips) ================= */
.kw-ideas { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.kw-ideas-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.kw-ideas-list { min-height: 24px; }
.kw-ideas-err { color: var(--warn); }
.chip.idea { border-style: dashed; background: var(--surface-2); }
.chip.idea:hover { background: var(--surface); }
.chip.idea.ai { border-color: var(--ai-line); background: var(--ai-soft); color: var(--ai); }
.chip.idea .idea-plus { margin-left: 2px; color: var(--primary-text); font-weight: 700; }
.chip.idea:disabled { opacity: 0.5; cursor: default; }

/* ================= Studio: Make several ================= */
.vari-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.vari-item { position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; transition: border-color var(--dur-1), box-shadow var(--dur-1), transform var(--dur-1) var(--ease); }
.vari-item:hover { border-color: var(--primary-line); }
.vari-item.on { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.vari-item canvas { display: block; width: 100%; height: auto; border-radius: 6px; background: var(--surface-3); }
.vari-item .vari-pick { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 0.7813rem; color: var(--text-2); cursor: pointer; }
.vari-item .vari-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vari-item .badge { position: absolute; top: 12px; right: 12px; }
.vari-status { min-height: 1.4em; }

/* ================= Home: rotation tile ================= */
.rot-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; margin-bottom: 10px; }
.rot-today { display: flex; flex: none; flex-direction: column; align-items: flex-end; text-align: right; }
.rot-today b { font-size: 1.375rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .rot-row { flex-wrap: wrap; } .rot-today { align-items: flex-start; text-align: left; } }

/* v2.3: multiple posters, problems & fixes */
.thumb { position: relative; }
.thumb-x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 1rem; line-height: 24px; cursor: pointer; padding: 0; }
.problems .problem-group { border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; margin-top: 8px; }
.problems .problem-group > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
ul.plain { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 4px; }
ul.plain li { padding: 2px 0; }

/* Activity log (Jobs): day headers, one tidy row per post */
.log-filters input[type="search"] { flex: 1 1 180px; min-width: 0; }
.log-list { display: grid; }
.log-day { position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top)); z-index: 1; padding: 8px 2px 4px; font-size: 0.75rem; font-weight: 600; color: var(--muted); background: var(--surface); }
.log-row { display: grid; grid-template-columns: 3.2em 1.4em minmax(0, 1fr) auto; gap: 4px 10px; align-items: baseline; padding: 7px 2px; border-top: 1px solid var(--line); font-size: 0.8125rem; }
.log-row.bad .log-main b { color: var(--text); }
.log-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.log-main { min-width: 0; overflow-wrap: anywhere; }
.log-acct { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--surface-3); font-size: 0.6875rem; color: var(--muted); }
.log-detail { display: block; color: var(--muted); font-size: 0.75rem; }
.log-meta { font-size: 0.6875rem; white-space: nowrap; }
@media (max-width: 520px) { .log-row { grid-template-columns: 3.2em 1.4em minmax(0, 1fr); } .log-meta { grid-column: 3; } }

/* Page intro line with an action on the right (Inbox, Analytics) */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 14px; }
.page-head > p { margin: 0; flex: 1 1 260px; }

/* Inbox: conversation list + thread (two panes on wide screens, one at a time on phones) */
/* height: 64 top bar + 24 padding + 62 title + 20 gap; the subtitle is hidden on this screen (a two-pane mail layout — the title is enough) */
.inbox-layout { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 14px; height: calc(100vh - 170px); height: calc(100dvh - 170px); min-height: 480px; }
.app:has(#tab-inbox.active) .page-sub { display: none; }
@media (min-width: 900px) { .app:has(#tab-inbox.active) .content { padding-bottom: 20px; } } /* the panes end at the window's edge: the page itself never scrolls */
.inbox-list-pane, .inbox-thread-pane { display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.inbox-tools { display: grid; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.inbox-tools .row > select, .inbox-tools .row > input { flex: 1 1 0; min-width: 0; }
.inbox-tools .seg { width: 100%; }
.inbox-tools .seg button { flex: 1 1 0; }
.inbox-list { overflow-y: auto; flex: 1; }
.inbox-count { padding: 8px 12px 2px; margin: 0; }
.conv { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; text-align: left; cursor: pointer; font: inherit; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--primary-soft, var(--surface-3)); }
.conv:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.conv-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.conv-top { display: flex; gap: 8px; align-items: baseline; }
.conv-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.conv.unread .conv-name { font-weight: 750; }
.conv-time { flex: none; font-size: 0.7188rem; color: var(--muted); }
.conv.unread .conv-time { color: var(--primary-text); font-weight: 600; }
.conv-meta { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview { font-size: 0.8125rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .conv-preview { color: var(--text); }
.conv-count { flex: none; align-self: center; min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 0.75rem; font-weight: 700; line-height: 22px; text-align: center; }
.inbox-layout .avatar, .lead-pops .avatar { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: hsl(var(--h, 210) 55% 45%); color: #fff; font-weight: 700; font-size: 0.875rem; letter-spacing: 0.02em; }
.thread-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.thread-head > .grow { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.thread-head .chip { white-space: nowrap; }
.thread-head a { color: inherit; }
.thread-name { text-decoration: none; }
.thread-name:hover, .thread-head a.small:hover { text-decoration: underline; }
.thread-actions { flex: none; }
.thread-back { display: none; }
.chip.static { cursor: default; }
a.chip { text-decoration: none; color: inherit; }
.thread { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.thread-empty { margin: auto; }
.thread-day { text-align: center; font-size: 0.7188rem; color: var(--muted); margin: 6px 0; }
.thread-day span { padding: 2px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.bubble { max-width: min(78%, 560px); padding: 8px 12px; border-radius: 14px 14px 14px 4px; background: var(--surface); border: 1px solid var(--line); align-self: flex-start; }
.bubble.out { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: var(--primary); border-color: var(--primary); color: #fff; }
.bubble.out a { color: #fff; }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.875rem; line-height: 1.45; }
.bubble-time { margin-top: 3px; font-size: 0.6875rem; color: var(--muted); text-align: right; }
.bubble.out .bubble-time { color: rgba(255, 255, 255, 0.8); }
.bubble-kind { margin-bottom: 2px; }
.composer { display: grid; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.composer textarea { resize: vertical; min-height: 64px; }
.nav-item .nav-badge { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 0.6875rem; font-weight: 700; line-height: 18px; text-align: center; }
.bottombar .nav-item, .sheet-grid .nav-item { position: relative; }
.bottombar .nav-badge, .sheet-grid .nav-badge { position: absolute; top: 4px; right: 18%; margin: 0; }
@media (max-width: 899.98px) {
  /* 56 bar + 16 padding + 50 title + 64 bottom bar + 14 gap, plus the phone's notch and home indicator */
  .inbox-layout { grid-template-columns: 1fr; height: calc(100vh - 200px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); height: calc(100dvh - 200px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 360px; }
  .inbox-layout .inbox-thread-pane { display: none; }
  .inbox-layout.has-open .inbox-list-pane { display: none; }
  .inbox-layout.has-open .inbox-thread-pane { display: flex; }
  .thread-back { display: inline-grid; }
  .thread-head > .grow { flex-basis: 0; flex-grow: 1; }
  .thread-actions { flex: 1 1 100%; flex-wrap: wrap; justify-content: flex-start; }
  .bubble { max-width: 88%; }
}

/* Analytics */
.an-section { margin-top: 22px; }
.an-section h3 { margin: 0 0 10px; font-size: 0.875rem; font-weight: 650; }
.chart-days { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding: 6px 2px 0; border-bottom: 1px solid var(--line); }
.chart-days.hours { height: 120px; }
.chart-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.chart-stack { width: 100%; max-width: 26px; height: calc(100% - 18px); display: flex; flex-direction: column; justify-content: flex-end; }
.chart-stack span { display: block; width: 100%; }
/* chart bars carry the status colours: sent = ok, failed = err, a plain count = info */
.bar-ok { background: var(--ok-dot); border-radius: 3px 3px 0 0; }
.bar-bad, .bar-err { background: var(--err-dot); opacity: 0.8; }
.bar-warn { background: var(--warn-dot); }
.bar-info { background: var(--info-dot); }
.chart-x { height: 18px; font-size: 0.6875rem; color: var(--muted); white-space: nowrap; }
.chart-dot { position: absolute; top: 0; width: 7px; height: 7px; border-radius: 50%; background: var(--ok-dot); }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; }
.key-ok { background: var(--ok-dot); }
.key-bad, .key-err { background: var(--err-dot); opacity: 0.8; }
.key-warn { background: var(--warn-dot); }
.key-info { background: var(--info-dot); }
/* not tried (the post never reached the group): the muted colour of "skipped" */
.bar-off, .key-off { background: var(--muted-dot); opacity: 0.55; }
/* Touch screens show no hover titles: every bar is a button, and a tap writes its numbers in the line under the chart */
button.chart-col { padding: 0; border: 0; border-radius: 4px; background: none; color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button.chart-col:hover { background: var(--surface-2); }
button.chart-col.on { background: var(--surface-3); }
.chart-cap { margin: 6px 0 8px; min-height: 1.45em; }
@media (max-width: 430px) {
  .chart-days { gap: 1px; } /* 30 bars and their gaps fit a phone: 3 px gaps alone took most of the width */
  .chart-x.minor { visibility: hidden; } /* every other date, so the dates never run into each other */
  .chart-cap { min-height: 2.9em; } /* room for a two-line caption: a tap doesn't push the page down */
}
/* Learning: a row's one-sentence reason opens under it on a tap (the same text is its hover title on a Mac) */
[data-why] { cursor: pointer; }
.table-wrap .why-line td { white-space: normal; background: var(--surface-2); }
.why-text { display: block; position: sticky; left: 12px; max-width: min(560px, calc(100vw - 80px)); }
.hbars { display: grid; gap: 8px; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: 0.8125rem; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--info-dot); border-radius: inherit; }
.hbar-val { font-variant-numeric: tabular-nums; color: var(--muted); }
@media (max-width: 430px) { .hbar-label { white-space: normal; overflow-wrap: anywhere; } } /* a long reason wraps instead of losing its end */

/* Send: message + groups on the left, a sticky Review & send panel on the right (one column on phones) */
.send-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); gap: 16px; align-items: start; }
.send-main { display: grid; gap: 16px; min-width: 0; }
.send-main > .card, .send-side > .card { margin: 0; }
.send-side { position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px); max-height: calc(100vh - var(--topbar-h) - env(safe-area-inset-top) - 24px); max-height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top) - 24px); overflow-y: auto; }
.composer-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.composer-tools select { flex: 1 1 200px; min-width: 0; }
.composer-box { border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); overflow: hidden; }
.composer-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.composer-box textarea { display: block; width: 100%; border: 0; border-radius: 0; background: transparent; box-shadow: none; resize: vertical; min-height: 200px; padding: 12px 14px; font-size: 0.9375rem; line-height: 1.5; }
.composer-box textarea:focus { outline: none; box-shadow: none; }
.composer-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--surface-2); }
.chip.sm { padding: 2px 8px; font-size: 0.75rem; }
.ai-box { padding: 12px; border: 1px solid var(--ai-line, var(--line)); border-radius: var(--r); background: var(--surface-2); }
.lists-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.side-section { display: grid; gap: 8px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.send-side .callout { margin: 0 0 12px; }
.send-side select.sm { padding: 4px 8px; font-size: 0.7813rem; max-width: 60%; }
.preview { padding: 10px 12px; border-radius: 14px 14px 14px 4px; border: 1px solid var(--line); background: var(--surface-2); max-height: 320px; overflow-y: auto; }
.preview-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.8438rem; line-height: 1.45; }
.preview-photo { margin: -2px -4px 8px; }
.preview-photo img { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 10px; }
.btn.lg { padding: 12px 18px; font-size: 0.9375rem; font-weight: 650; }
.side-more { margin-top: 14px; }
.side-more summary { cursor: pointer; padding: 6px 0; }
.send-bar { display: none; }
@media (max-width: 1099.98px) {
  .send-layout { grid-template-columns: 1fr; }
  .send-side { position: static; max-height: none; overflow: visible; }
  .send-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 8px);
    z-index: 5; margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bar-bg, var(--surface)); box-shadow: var(--shadow-2);
  }
}

/* "FreelanceReach was updated — Reload now" */
.update-banner { position: fixed; left: 50%; bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%); z-index: 1000;
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--primary-line, var(--line)); border-radius: var(--r);
  background: var(--bar-bg, var(--surface)); box-shadow: var(--shadow-2); font-size: 0.875rem; }

/* ---------- lead pop-ups (any tab) ---------- */
.lead-pops { position: fixed; top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px); right: max(16px, env(safe-area-inset-right)); z-index: 950; display: flex; flex-direction: column; gap: 10px;
  width: min(380px, calc(100vw - 32px)); pointer-events: none; }
html.no-scroll .lead-pops { z-index: 55; } /* a dialog is open (core.js sets .no-scroll): pop-ups wait under its backdrop */
.lead-pop { pointer-events: auto; background: var(--surface); border: 1px solid var(--line-strong); border-left: 4px solid var(--primary);
  border-radius: var(--r-lg); box-shadow: var(--shadow-3); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
  opacity: 0; transform: translateX(16px); transition: opacity var(--dur-2), transform var(--dur-2) var(--ease); }
.lead-pop.show { opacity: 1; transform: none; }
.lead-pop.lp-more { flex-direction: row; justify-content: space-between; align-items: center; border-left-width: 1px; padding: 8px 14px; font-size: 0.8125rem; }
.lp-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lp-badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); }
.lp-badge.hot { background: var(--warn-soft); color: var(--warn); } /* needs you */
.lp-badge.web { background: var(--info-soft); color: var(--info); }
.lp-badge.ai { background: var(--ai-soft); color: var(--ai); }
.lp-x { display: inline-grid; place-items: center; min-width: 32px; min-height: 32px; border: 0; background: none; color: var(--muted); font-size: 0.9375rem; cursor: pointer; padding: 2px 6px; border-radius: var(--r-sm); transition: background-color var(--dur-1), transform var(--dur-1) var(--ease); }
.lp-x:hover { background: var(--surface-2); color: var(--text); }
.lp-who { font-size: 0.875rem; overflow-wrap: anywhere; }
.lp-title { font-weight: 600; font-size: 0.875rem; }
.lp-text { margin: 0; font-size: 0.875rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.lp-meta { font-size: 0.75rem; color: var(--muted); }
.lp-meta.warn { color: var(--warn); }
.lp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
@media (max-width: 700px) { .lead-pops { right: max(16px, env(safe-area-inset-right)); left: max(16px, env(safe-area-inset-left)); width: auto; top: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px); } }

/* ================= touch: 44×44 targets and no iOS zoom on focus (coarse pointers only) ================= */
@media (pointer: coarse) {
  .btn, .btn.sm, button.link, a.link, button.pill, a.pill, .chip, .seg button, .msel-opt { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .lp-x { min-width: 44px; min-height: 44px; margin: -10px -12px -10px 0; } /* a bigger hit area; the pop-up header keeps its height */
  .thumb-x { width: 36px; height: 36px; line-height: 36px; top: 0; right: 0; }
  .bd-draft .bd-fold { min-width: 44px; min-height: 44px; }
  /* iOS Safari zooms the page into any field under 16px when it gets focus. #pin is already 18px. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not(#pin), select, textarea { font-size: max(16px, 1rem) !important; }
}

.between.wrap { flex-wrap: wrap; }
