/* =============================================================================
   Reel Manager: app.css
   Hand-written token CSS, no build step.
   Visual reference: docs/ui_mockup.html.

   RULES FOR EDITING
   - Components never use literal colours: only the tokens in :root.
   - Every colour token exists three times: light (:root), dark under
     prefers-color-scheme (guarded by :root:not([data-theme="light"])), and
     dark again under :root[data-theme="dark"]. Change all three together.
   - Text-on-background pairs are checked to >= 4.5:1 in both themes.
   - The server sets data-theme="light|dark" on <html> from the "theme"
     cookie; no attribute means "follow the device".
   - sw.js serves /static/* stale-while-revalidate, so a change here shows on
     the next load. If you add or rename a precached file, update
     STATIC_ASSETS and bump CACHE_NAME in sw.js.

   COMPONENT INDEX (use only these classes when restyling a page)

   Layout and text
     .container                 centred max-width wrapper with 16px gutters
     .page                      <main> padding (base.html already sets it)
     .stack / .stack.tight / .stack.loose
                                vertical rhythm: <div class="stack">…</div>
     .cluster                   wrapping row with gap: buttons, chips, meta
     .page-head                 <header class="page-head"><h1>…</h1><p class="muted">…</p></header>
     .section-label             small caps label: <h2 class="section-label">Ingredients</h2>
     .muted .small .xsmall .fine .num (tabular figures) .sr-only .skip-link
     .icon / .icon.sm / .icon.lg
                                inline SVG: <svg class="icon" aria-hidden="true"><use href="#i-plus"/></svg>
                                (symbols live in base.html: logo, i-plus, i-reels,
                                i-user, i-map, i-check, i-x, i-alert, i-chev,
                                i-back, i-ext, i-trash, i-search)
     .panel                     bordered surface box for forms / states:
                                <section class="panel"><h2>…</h2>…</section>
     .table-wrap                horizontal scroller around a <table>

   Shell (base.html only)
     .topbar > .topbar-inner.container > .logo(.logo-mark) .topnav(a[aria-current]) .topbar-spacer .topbar-add.btn.primary .avatar
     .tabbar > a(.tab-add)[aria-current]   phone-only bottom tab bar

   Buttons
     <a|button class="btn">Secondary</a>        default = secondary
     .btn.primary  .btn.quiet  .btn.danger  .btn.danger.solid
     .btn.sm  .btn.block      <div class="actions">…buttons…</div>
     .toggle[aria-pressed]    mark toggle (Visited/Cooked/Done):
                              <button class="toggle" aria-pressed="true"><span class="tick"><svg class="icon"><use href="#i-check"/></svg></span>Cooked</button>
     .seg > button[aria-pressed]   segmented control (Grid / List, Keyword / Smart)
     .badge                   small count pill inside a button

   Forms
     <div class="field"><label for="x">Label</label><input class="input" id="x"><p class="hint">…</p></div>
     .input  .select  .textarea  (plain input/select/textarea get a usable base too)
     <label class="check"><input type="checkbox"> Text</label>
     <div class="radios" role="radiogroup"><label><input type="radio" name="theme" value="light"> Light</label>…</div>
     <form class="search" role="search"><svg class="icon">…</svg><input class="input" type="search"></form>
     .toolbar                 wrapping row for search + buttons

   Chips
     <div class="chip-row" role="group" aria-label="Show"><a class="chip" aria-pressed="true">All</a>…</div>
     <a class="chip" data-kind="place"><span class="key" aria-hidden="true"></span>Places</a>
     removable: <span class="chip removable">Lisbon <button class="chip-x" aria-label="Remove filter Lisbon"><svg class="icon sm"><use href="#i-x"/></svg></button></span>
     .chip-sep                vertical divider inside a chip row

   Kind key (place / recipe / product / other)
     <span class="key" data-kind="recipe">Recipe</span>
     [data-kind] on any ancestor sets --kind / --kind-soft for .key, .facet, .steps

   Frame (9:16 reel card) inside a sheet
     <div class="sheet"> (add .compact for the List view)
       <a class="frame" href="/reels/1" data-kind="place">
         <div class="thumb th-place"><img src="…" alt="" loading="lazy">
           <div class="overlay">                         (processing)
             <strong><span class="dot pulse" aria-hidden="true"></span>Processing…</strong></div>
           <div class="overlay failed"><strong>Couldn’t save</strong><button class="btn sm">Try again</button></div>
         </div>
         <div class="cap"><span class="key">Place</span><h3 class="frame-title">…</h3>
           <p class="yield">Pastry shop · Lisbon</p>
           <div class="marks"><span class="mark"><svg class="icon sm">…</svg>Visited</span></div></div>
       </a>
     .th-place .th-recipe .th-product .th-other .th-muted   placeholder gradients when no image
     search snippet in .cap: <p class="snip"><span class="snip-label">Transcript:</span> …<mark>carbonara</mark>…</p>

   Content blocks (detail page)
     .facet[data-kind] > .facet-head(h3, .sub) .facts(dl > div > dt+dd) .cols > .blk(.section-label …)
     ol.steps  ul.ingredients(li > label.check)  ul.list-plain  .procon  .translated

   Disclosure
     <details class="disc"><summary><svg class="icon sm chev"><use href="#i-chev"/></svg>From the reel<span class="hint">…</span></summary>
       <div class="disc-body">…</div></details>

   Inline confirm (replaces confirm()/alert())
     <div class="confirm" hidden><p>Delete this reel?</p><div class="actions"><button class="btn sm">Cancel</button><button class="btn danger solid sm">Delete</button></div></div>
     .confirm.danger          red-tinted variant

   Notice / banner
     <div class="notice" role="status">…</div>   .notice.warn .notice.bad .notice.good

   Meter (quota bar) and progress
     <div class="meter" role="img" aria-label="7 of 20 reels used today"><span style="width:35%"></span></div>
     .meter.full              red bar at the limit
     <div class="progress" role="progressbar" aria-label="Processing"><span></span></div>  indeterminate

   Settings (account)
     <div class="settings-row"><h2>Theme</h2><div class="settings-body">…</div></div>
     .admin-box               dashed box for admin-only links
   ========================================================================== */

/* ---------- fonts (option A, self-hosted, latin + latin-ext) ---------- */
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/static/fonts/atkinson-hyperlegible-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  src: url("/static/fonts/atkinson-hyperlegible-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/static/fonts/bricolage-grotesque-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- tokens: light ---------- */
:root {
  color-scheme: light;

  --bg: #f2f5f1;
  --surface: #fbfcfa;
  --surface-2: #e8ede7;
  --ink: #16201b;
  --ink-2: #47534d;
  --ink-3: #5f6b64;
  --line: #d2d9d2;
  --line-strong: #7b8880;
  --accent: #0d6a61;
  --accent-hover: #0a564f;
  --on-accent: #f2fbf9;
  --accent-soft: #d4e9e4;
  --focus: #0d6a61;

  --place: #2d6a44;
  --place-soft: #dbeadf;
  --recipe: #8a5608;
  --recipe-soft: #f4e5c6;
  --product: #2e4fa0;
  --product-soft: #dbe2f3;
  --other: #5c6660;
  --other-soft: #e2e7e2;

  --warn: #7f4b00;
  --warn-soft: #fbeac6;
  --bad: #b0261e;
  --bad-soft: #f7ddd9;
  --good: #23703f;
  --good-soft: #d9ecdd;

  --th-place-a: #9cc3a5;
  --th-place-b: #3f7a57;
  --th-recipe-a: #f0c97e;
  --th-recipe-b: #b36d1c;
  --th-product-a: #aebde3;
  --th-product-b: #3d5a9e;
  --th-other-a: #c3cbc5;
  --th-other-b: #67736c;
  --th-muted-a: #dfe4df;
  --th-muted-b: #b9c2bb;
  --scrim: rgba(12, 20, 16, 0.78);
  --on-scrim: #f3f7f4;
  --motif: rgba(255, 255, 255, 0.55);

  --font-display: "Bricolage Grotesque", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Atkinson Hyperlegible", -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --display-weight: 700;
  --display-tracking: -0.01em;

  --radius: 6px;
  --radius-lg: 10px;
  --gutter: 16px;
  --max-width: 1240px;
  --topbar-h: 58px;
  --tabbar-h: 60px;
}

/* ---------- tokens: dark (device preference, unless forced light) ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1412;
    --surface: #151d1a;
    --surface-2: #1d2723;
    --ink: #e3e9e5;
    --ink-2: #b0bbb4;
    --ink-3: #8f9b94;
    --line: #29352f;
    --line-strong: #66766d;
    --accent: #52bbae;
    --accent-hover: #6ccabe;
    --on-accent: #062220;
    --accent-soft: #163a35;
    --focus: #7fd6cb;
    --place: #80c79a;
    --place-soft: #1a3226;
    --recipe: #e4b25b;
    --recipe-soft: #3a2b11;
    --product: #97b0f0;
    --product-soft: #1d2742;
    --other: #a6b0aa;
    --other-soft: #252e29;
    --warn: #e9b860;
    --warn-soft: #3a2c10;
    --bad: #f28d83;
    --bad-soft: #3e1c19;
    --good: #80c79a;
    --good-soft: #1a3226;
    --th-place-a: #31523d;
    --th-place-b: #142a1d;
    --th-recipe-a: #6b4a17;
    --th-recipe-b: #2c1d08;
    --th-product-a: #34477a;
    --th-product-b: #141c33;
    --th-other-a: #3b4540;
    --th-other-b: #1a201d;
    --th-muted-a: #262f2b;
    --th-muted-b: #1a211e;
    --scrim: rgba(4, 8, 6, 0.8);
    --on-scrim: #eef3f0;
    --motif: rgba(255, 255, 255, 0.32);
  }
}

/* ---------- tokens: dark (forced by the theme cookie) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1412;
  --surface: #151d1a;
  --surface-2: #1d2723;
  --ink: #e3e9e5;
  --ink-2: #b0bbb4;
  --ink-3: #8f9b94;
  --line: #29352f;
  --line-strong: #66766d;
  --accent: #52bbae;
  --accent-hover: #6ccabe;
  --on-accent: #062220;
  --accent-soft: #163a35;
  --focus: #7fd6cb;
  --place: #80c79a;
  --place-soft: #1a3226;
  --recipe: #e4b25b;
  --recipe-soft: #3a2b11;
  --product: #97b0f0;
  --product-soft: #1d2742;
  --other: #a6b0aa;
  --other-soft: #252e29;
  --warn: #e9b860;
  --warn-soft: #3a2c10;
  --bad: #f28d83;
  --bad-soft: #3e1c19;
  --good: #80c79a;
  --good-soft: #1a3226;
  --th-place-a: #31523d;
  --th-place-b: #142a1d;
  --th-recipe-a: #6b4a17;
  --th-recipe-b: #2c1d08;
  --th-product-a: #34477a;
  --th-product-b: #141c33;
  --th-other-a: #3b4540;
  --th-other-b: #1a201d;
  --th-muted-a: #262f2b;
  --th-muted-b: #1a211e;
  --scrim: rgba(4, 8, 6, 0.8);
  --on-scrim: #eef3f0;
  --motif: rgba(255, 255, 255, 0.32);
}

/* ---------- base: plain elements stay usable on unstyled pages ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  /* "anywhere" (not "break-word") also lowers min-content, so a long link
     wraps instead of widening the grid or flex box around it. */
  overflow-wrap: anywhere;
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  letter-spacing: var(--display-tracking);
  line-height: 1.2;
  margin: 0 0 0.5em;
  text-wrap: balance;
  color: var(--ink);
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }
p, ul, ol, dl, pre, table, form, fieldset, blockquote { margin: 0 0 1rem; }
ul, ol { padding-left: 1.4em; }
dt { font-weight: 700; }
dd { margin: 0 0 0.5rem; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
strong, b { font-weight: 700; }
small { font-size: 0.875rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.5rem 0; }
img, svg, video { max-width: 100%; }
img { height: auto; }
code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.9em; }
code { padding: 0.1em 0.3em; border-radius: 4px; background: var(--surface-2); }
pre {
  padding: 12px; overflow-x: auto; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
}
pre code { padding: 0; background: none; }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { padding: 8px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); overflow-wrap: break-word; }
th { font-size: 0.8125rem; font-weight: 700; color: var(--ink-2); }
caption { text-align: left; color: var(--ink-2); padding-bottom: 6px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
legend { padding: 0 4px; font-weight: 700; }
label { cursor: pointer; }
button, input, select, textarea { font: inherit; color: inherit; }
/* iOS zooms into a text field under 16px on focus: never smaller, even
   inside a table or a small-text block. */
input:where(:not([type="checkbox"], [type="radio"], [type="hidden"], [type="submit"], [type="button"], [type="reset"])),
select, textarea { font-size: max(16px, 1em); }
button { cursor: pointer; }
/* :where() keeps these at zero specificity so any component class wins. */
:where(input:not([type]), input[type="text"], input[type="email"], input[type="url"],
input[type="search"], input[type="number"], input[type="password"], input[type="date"],
select, textarea) {
  max-width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
textarea { min-height: 76px; resize: vertical; }
:where(input[type="checkbox"], input[type="radio"]) { accent-color: var(--accent); width: 18px; height: 18px; }
:where(button, input[type="submit"], input[type="button"], input[type="reset"]) {
  min-height: 40px; padding: 8px 14px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--ink); font-weight: 700;
}
:where(button, input[type="submit"], input[type="button"], input[type="reset"]):hover { background: var(--surface-2); }
::placeholder { color: var(--ink-3); opacity: 1; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--accent-soft); color: var(--ink); }

/* ---------- utilities ---------- */
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 0.875rem; }
.xsmall { font-size: 0.8125rem; }
.fine { font-size: 0.8125rem; color: var(--ink-3); max-width: 70ch; }
.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;
}
.skip-link {
  position: absolute; left: 8px; top: -100px; z-index: 100;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--ink); color: var(--bg); font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 8px; color: var(--bg); }
.icon {
  width: 18px; height: 18px; flex: none; vertical-align: middle;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 22px; height: 22px; }

/* ---------- layout ---------- */
.container { width: 100%; max-width: var(--max-width); margin-inline: auto; padding-inline: var(--gutter); }
.page { padding-top: 24px; padding-bottom: 48px; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; min-width: 0; }
.stack > * { margin: 0; }
.stack.tight { gap: 8px; }
.stack.loose { gap: 32px; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-width: 0; }
.page-head { display: grid; gap: 4px; margin-bottom: 20px; }
.page-head > * { margin: 0; }
.section-label {
  margin: 0; font-family: var(--font-body); font-size: 0.8125rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3);
}
.panel {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 22px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface);
}
.panel > * { margin: 0; }
.panel h2 { font-size: 1.5rem; }
.table-wrap { overflow-x: auto; max-width: 100%; }
.table-wrap table { margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner { display: flex; align-items: center; gap: 20px; min-height: var(--topbar-h); }
.logo {
  display: inline-flex; align-items: center; gap: 9px; min-height: 44px;
  font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.0625rem;
  letter-spacing: var(--display-tracking); color: var(--ink); text-decoration: none; white-space: nowrap;
}
.logo:hover { color: var(--ink); }
.logo-mark { width: 22px; height: 30px; flex: none; color: var(--accent); }
.topnav { display: flex; gap: 2px; min-width: 0; }
.topnav a {
  display: inline-flex; align-items: center; min-height: 40px; padding: 6px 10px;
  border-radius: var(--radius); color: var(--ink-2); text-decoration: none; font-size: 0.9375rem;
}
.topnav a:hover { color: var(--ink); background: var(--surface-2); }
.topnav a[aria-current] { color: var(--ink); font-weight: 700; box-shadow: inset 0 -2px 0 var(--accent); }
.topbar-spacer { flex: 1; }
.avatar {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface-2);
  color: var(--ink); font-size: 0.875rem; font-weight: 700; text-decoration: none;
}
.avatar:hover { color: var(--ink); border-color: var(--ink-2); }
.avatar[aria-current] { border: 2px solid var(--accent); }

/* ---------- bottom tab bar (phone only) ---------- */
.tabbar { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 0.9375rem; line-height: 1.2; text-decoration: none;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger { border-color: var(--bad); background: var(--surface); color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: var(--surface); }
.btn.danger.solid:hover { background: var(--bad); color: var(--surface); filter: brightness(0.92); }
.btn.quiet.danger { border-color: transparent; background: transparent; }
.btn.quiet.danger:hover { background: var(--bad-soft); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 0.875rem; }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions > * { margin: 0; }

.toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px;
  border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-2); font-size: 0.875rem; font-weight: 400; cursor: pointer; white-space: nowrap;
}
.toggle .tick {
  width: 14px; height: 14px; display: grid; place-items: center;
  border: 1.5px solid currentColor; border-radius: 3px;
}
.toggle .tick .icon { width: 11px; height: 11px; stroke-width: 3; }
.toggle[aria-pressed="false"] .tick .icon { visibility: hidden; }
.toggle[aria-pressed="true"] { background: var(--good-soft); border-color: var(--good); color: var(--good); font-weight: 700; }
.toggle[aria-pressed="true"] .tick { background: var(--good); border-color: var(--good); }
.toggle[aria-pressed="true"] .tick .icon { color: var(--surface); }

.seg { display: inline-flex; flex: none; border: 1px solid var(--line-strong); border-radius: var(--radius); }
.seg > button, .seg > a {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 7px 11px;
  border: 0; border-radius: 0; background: var(--surface); color: var(--ink-2); font-size: 0.875rem; font-weight: 400; text-decoration: none; cursor: pointer;
}
.seg > * + * { border-left: 1px solid var(--line-strong); }
/* Round the ends (no overflow: hidden, which clipped the focus ring). */
.seg > :first-child { border-start-start-radius: calc(var(--radius) - 1px); border-end-start-radius: calc(var(--radius) - 1px); }
.seg > :last-child { border-start-end-radius: calc(var(--radius) - 1px); border-end-end-radius: calc(var(--radius) - 1px); }
.seg > [aria-pressed="true"], .seg > [aria-current] { background: var(--ink); color: var(--bg); }
.badge {
  display: inline-block; padding: 0 7px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent); font-size: 0.75rem; font-variant-numeric: tabular-nums;
}

/* ---------- forms ---------- */
.field { display: grid; gap: 4px; min-width: 0; }
.field > * { margin: 0; }
.field label, .field .label { font-size: 0.8125rem; font-weight: 700; color: var(--ink-2); }
.hint { font-size: 0.8125rem; color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.textarea { min-height: 76px; resize: vertical; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.check { display: inline-flex; align-items: flex-start; gap: 10px; min-height: 40px; padding: 8px 0; cursor: pointer; }
.check input { flex: none; margin: 2px 0 0; }
.radios { display: flex; flex-wrap: wrap; gap: 6px; }
.radios label {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface);
  font-size: 0.9375rem; cursor: pointer;
}
.radios label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.search { position: relative; display: flex; align-items: center; flex: 1 1 260px; min-width: 0; margin: 0; }
.search .icon { position: absolute; left: 11px; color: var(--ink-3); pointer-events: none; }
.search .input { padding-left: 36px; }

/* ---------- chips ---------- */
/* 4px padding (cancelled by the margin) keeps chip focus rings inside the scroller. */
.chip-row { display: flex; gap: 6px; min-width: 0; overflow-x: auto; margin: -4px; padding: 4px 4px 8px; scrollbar-width: thin; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none; white-space: nowrap;
  min-height: 36px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-size: 0.875rem; font-weight: 400; text-decoration: none; cursor: pointer;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip[aria-pressed="true"], .chip[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip .key { font-size: 0; gap: 0; }
.chip.removable { gap: 2px; padding: 2px 4px 2px 12px; border-radius: var(--radius); border-color: transparent; background: var(--accent-soft); color: var(--ink); cursor: default; }
.chip-x {
  display: grid; place-items: center; width: 28px; height: 28px; min-height: 0; padding: 0;
  border: 0; border-radius: 4px; background: transparent; color: var(--ink-2); cursor: pointer;
}
.chip-x:hover { background: var(--surface); color: var(--ink); }
.chip-sep { flex: none; width: 1px; margin: 4px; background: var(--line); }

/* ---------- kind key ---------- */
[data-kind="place"] { --kind: var(--place); --kind-soft: var(--place-soft); }
[data-kind="recipe"] { --kind: var(--recipe); --kind-soft: var(--recipe-soft); }
[data-kind="product"] { --kind: var(--product); --kind-soft: var(--product-soft); }
[data-kind="other"] { --kind: var(--other); --kind-soft: var(--other-soft); }
.key {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2);
}
.key::before { content: ""; width: 9px; height: 9px; flex: none; border-radius: 2px; background: var(--kind, var(--other)); }
.translated { display: inline-flex; align-items: center; gap: 5px; font-size: 0.8125rem; color: var(--ink-3); }

/* ---------- frame (9:16 reel card) ---------- */
.sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 22px 16px; margin: 0; padding: 0; list-style: none; }
.frame { display: grid; gap: 8px; align-content: start; min-width: 0; color: var(--ink); text-decoration: none; }
.frame:hover { color: var(--ink); }
a.frame:hover .thumb { outline: 2px solid var(--line-strong); outline-offset: 2px; }
.thumb {
  position: relative; aspect-ratio: 9 / 16; max-width: 100%; overflow: hidden;
  border-radius: var(--radius); background: var(--surface-2);
}
.thumb > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.th-place, .th-recipe, .th-product, .th-other, .th-muted { background: linear-gradient(var(--ang, 165deg), var(--ta), var(--tb)); }
.th-place { --ta: var(--th-place-a); --tb: var(--th-place-b); }
.th-recipe { --ta: var(--th-recipe-a); --tb: var(--th-recipe-b); }
.th-product { --ta: var(--th-product-a); --tb: var(--th-product-b); }
.th-other { --ta: var(--th-other-a); --tb: var(--th-other-b); }
.th-muted { --ta: var(--th-muted-a); --tb: var(--th-muted-b); }
.thumb .motif { position: absolute; left: 50%; top: 44%; width: 46%; height: auto; transform: translate(-50%, -50%); color: var(--motif); stroke-width: 1.2; }
.overlay {
  position: absolute; inset: auto 0 0 0; z-index: 2; display: grid; gap: 6px; padding: 10px;
  background: var(--scrim); color: var(--on-scrim); font-size: 0.8125rem;
}
.overlay strong { display: flex; align-items: center; gap: 6px; font-size: 0.875rem; }
.overlay.failed { border-top: 3px solid var(--bad); }
.overlay .btn { justify-self: start; min-height: 32px; padding: 2px 10px; font-size: 0.8125rem; }
.cap { display: grid; gap: 3px; min-width: 0; }
.cap > * { margin: 0; }
.frame-title, .cap h3 { margin: 0; font-size: 1rem; line-height: 1.25; overflow-wrap: anywhere; }
/* A failed frame is a <div> whose title is the link: look like every other title. */
.frame-title a { color: inherit; text-decoration: none; }
.frame-title a:hover { color: inherit; text-decoration: underline; }
.yield { margin: 0; font-size: 0.875rem; color: var(--ink-2); }
/* Search snippet: where the words matched, clamped to a few lines. */
.snip {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
  margin: 0; font-size: 0.8125rem; line-height: 1.35; color: var(--ink-2); overflow-wrap: anywhere;
}
.snip-label { font-weight: 700; color: var(--ink-3); }
.snip mark { padding: 0 1px; border-radius: 2px; background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.sheet.compact .snip { -webkit-line-clamp: 2; line-clamp: 2; }
.marks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.mark { display: inline-flex; align-items: center; gap: 3px; font-size: 0.75rem; font-weight: 700; color: var(--good); }
.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: currentColor; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.status-processing { color: var(--warn); }
.status-failed { color: var(--bad); }

/* List view: same markup, one row per reel */
.sheet.compact { grid-template-columns: 1fr; gap: 0; border-top: 1px solid var(--line); }
.sheet.compact .frame { grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 12px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.sheet.compact .thumb .motif, .sheet.compact .overlay { display: none; }

/* ---------- content blocks (detail) ---------- */
.facet { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; padding-top: 16px; border-top: 3px solid var(--kind, var(--other)); }
.facet > * { margin: 0; }
.facet-head { display: grid; gap: 4px; }
.facet-head > * { margin: 0; }
.facet-head h3 { font-size: 1.5rem; }
.facet-head .sub { color: var(--ink-2); }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; }
.facts > div { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.facts dt { flex: none; font-size: 0.875rem; font-weight: 400; color: var(--ink-3); }
.facts dd { min-width: 0; margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 24px 36px; }
.blk { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-content: start; min-width: 0; }
.blk > * { margin: 0; }
.list-plain { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.ingredients { margin: 0; padding: 0; list-style: none; display: grid; }
.ingredients li { border-bottom: 1px solid var(--line); }
.ingredients .check { display: flex; width: 100%; }
.ingredients input { accent-color: var(--kind, var(--accent)); width: 20px; height: 20px; }
.ingredients input:checked ~ span { text-decoration: line-through; color: var(--ink-3); }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 12px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 1.8em minmax(0, 1fr); gap: 8px; }
.steps li::before { content: counter(step) "."; font-weight: 700; color: var(--kind, var(--ink-2)); }
.procon { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ---------- disclosure ---------- */
details.disc { min-width: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
details.disc + details.disc { border-top: 0; }
/* Same summary for the folds inside a notice ("See what") and a fix field
   ("Show the original"). */
details.disc > summary, .notice details > summary, .fix-original > summary {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 10px 0;
  font-weight: 700; list-style: none; cursor: pointer;
}
details.disc > summary::-webkit-details-marker, .notice details > summary::-webkit-details-marker,
.fix-original > summary::-webkit-details-marker { display: none; }
:is(details.disc, .notice details, .fix-original) > summary .chev { color: var(--ink-3); transition: transform 0.15s; }
:is(details.disc, .notice details, .fix-original)[open] > summary .chev { transform: rotate(90deg); }
details.disc > summary .hint { margin-left: auto; text-align: right; font-weight: 400; }
.disc-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; max-width: 72ch; padding: 0 0 16px 28px; color: var(--ink-2); }
.disc-body > * { margin: 0; }

/* ---------- inline confirm ---------- */
.confirm {
  display: grid; gap: 10px; padding: 12px 14px; border-radius: var(--radius);
  border-left: 3px solid var(--warn); background: var(--warn-soft); color: var(--ink);
}
.confirm > * { margin: 0; }
.confirm.danger { border-left-color: var(--bad); background: var(--bad-soft); }

/* ---------- notice / banner ---------- */
.notice {
  display: flex; align-items: flex-start; gap: 10px; max-width: 72ch; padding: 10px 12px;
  border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-soft); color: var(--ink); font-size: 0.9375rem;
}
.notice > * { min-width: 0; margin: 0; }
.notice > .icon { margin-top: 3px; color: var(--accent); }
.notice.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.notice.warn > .icon { color: var(--warn); }
.notice.bad { border-left-color: var(--bad); background: var(--bad-soft); }
.notice.bad > .icon { color: var(--bad); }
.notice.good { border-left-color: var(--good); background: var(--good-soft); }
.notice.good > .icon { color: var(--good); }

/* ---------- meter / progress ---------- */
.meter, .progress { position: relative; height: 6px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.meter > span { display: block; height: 100%; max-width: 100%; border-radius: 999px; background: var(--accent); }
.meter.full > span { background: var(--bad); }
.progress > span { position: absolute; top: 0; bottom: 0; width: 40%; border-radius: 999px; background: var(--accent); animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { left: -40%; } to { left: 100%; } }

/* ---------- settings (account) ---------- */
.settings-row { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; padding: 24px 0; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.settings-row > h2, .settings-row > h3 { margin: 0; font-size: 1.0625rem; }
.settings-body { display: grid; gap: 12px; min-width: 0; }
.settings-body > * { margin: 0; }
.admin-box { display: grid; gap: 8px; margin-top: 8px; padding: 14px 16px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.admin-box > * { margin: 0; }

/* ---------- phone ---------- */
@media (max-width: 680px) {
  .topbar-inner { gap: 12px; min-height: 52px; }
  .topnav, .topbar-add, .topbar .avatar { display: none; }
  .page { padding-top: 16px; padding-bottom: calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom, 0px)); }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: grid; grid-template-columns: repeat(3, 1fr);
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
  .tabbar a {
    display: grid; justify-items: center; align-content: center; gap: 2px;
    min-height: var(--tabbar-h); padding: 6px 4px 8px;
    color: var(--ink-2); font-size: 0.75rem; text-decoration: none;
  }
  .tabbar a[aria-current] { color: var(--ink); font-weight: 700; }
  .tabbar .tab-add .icon { width: 28px; height: 28px; padding: 4px; border-radius: 50%; background: var(--accent); color: var(--on-accent); }
  h1 { font-size: 1.5rem; }
  .sheet { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 12px; }
  .procon { grid-template-columns: 1fr; }
  .settings-row { grid-template-columns: 1fr; gap: 10px; }
  .disc-body { padding-left: 0; }
  /* Keyword / Smart, Filters and Grid / List share one row at 360px:
     narrower segments, and the layout icons give way to their labels. */
  .toolbar .seg > a { padding-left: 8px; padding-right: 8px; }
  .toolbar .seg .icon { display: none; }
  /* The hint goes on its own line under the label, so "From the reel"
     never wraps (25px = chevron + gap). */
  details.disc > summary { flex-wrap: wrap; row-gap: 0; }
  details.disc > summary .hint { flex-basis: calc(100% - 25px); margin-left: 25px; text-align: left; }
  /* 44px touch targets */
  .btn, .btn.sm, .toggle, .chip, .input, .select, .seg > button, .seg > a, .radios label,
  .topnav a, .chip-x, .check { min-height: 44px; }
  :where(input:not([type]), input[type="text"], input[type="email"], input[type="url"],
  input[type="search"], input[type="number"], input[type="password"], select,
  button, input[type="submit"]) { min-height: 44px; }
  .chip-x { min-width: 44px; }
}

/* ---------- motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .progress > span { left: 0; width: 100%; opacity: 0.5; }
}

/* ---------- account page additions (P1.10) ---------- */
/* A freshly made API key is one long token: let it wrap on a phone. */
#raw-api-key { overflow-wrap: anywhere; }
/* The typed-email field does not need the full row width on desktop. */
#account-delete .field { max-width: 360px; }

/* ---------- add page (ui/add: add_confirm.html, add_result.html) ---------- */
.panel.narrow { max-width: 34rem; margin-inline: auto; }

/* ---------- list page (P1.5) ---------- */
/* Leaflet map canvas on /?view=map. */
.map-canvas {
  height: 70vh; min-height: 320px; border: 1px solid var(--line);
  border-radius: var(--radius-lg); background: var(--surface-2);
}
/* Try again is a <form> inside a frame overlay / caption: no form margin. */
.frame form { margin: 0; }

/* =============================================================================
   Reel detail page (P1.6) - added by the detail-page change.
   Layout only (mirrors the #detail screen of docs/ui_mockup.html); every
   colour comes from the tokens above.
   ========================================================================== */
.crumb { display: inline-flex; align-items: center; gap: 6px; justify-self: start; min-height: 40px; font-size: 0.9375rem; text-decoration: none; }
@media (max-width: 680px) { .crumb { min-height: 44px; } }
.detail { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 44px; align-items: start; }
.d-aside { display: grid; gap: 14px; align-content: start; min-width: 0; }
.d-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; align-content: start; min-width: 0; }
.d-main > * { margin: 0; }
.d-head h1 { font-size: clamp(1.625rem, 3.2vw, 2.375rem); }
.summary { font-size: 1.0625rem; line-height: 1.6; max-width: 65ch; }
.prewrap { white-space: pre-wrap; }
/* A long unbroken word in a note must not widen the page on a phone. */
#notes .prewrap { overflow-wrap: anywhere; }
/* "Add a note" refused (empty or too long): same red edge as .input. */
.textarea[aria-invalid="true"] { border-color: var(--bad); }
@media (max-width: 680px) {
  .detail { grid-template-columns: 1fr; gap: 24px; }
  /* Phone: thumbnail with Open in Instagram and Delete beside it, then the
     marks as one full-width row below (they wrapped awkwardly beside the
     thumbnail). The middle row is 1fr so it soaks up the thumbnail's height
     and Delete sits right under Open in Instagram. */
  .d-aside { grid-template-columns: 112px minmax(0, 1fr); grid-template-rows: auto 1fr auto; align-items: start; }
  .d-side { display: contents; }
  .d-aside > .thumb { grid-column: 1; grid-row: 1 / 3; }
  .d-side > .actions { grid-column: 2; grid-row: 1; }
  .d-side > .stack { grid-column: 2; grid-row: 2; }
  .d-side > #flags { grid-column: 1 / -1; grid-row: 3; }
  .d-side > #flags { gap: 8px; }
  .d-side > #flags > .toggle { flex: 1 1 0; justify-content: center; padding-inline: 8px; }
  /* "Open in Instagram" wraps beside the thumbnail on a 320px screen. */
  .d-side > .actions .btn { white-space: normal; text-align: center; }
}

/* ---- P2 sign-in & setup ---- */
/* Sign in: pitch + three example frames beside one panel; stacked on a phone. */
.login { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 40px; align-items: start; }
.login .panel { display: grid; gap: 16px; align-content: start; }
.login-pitch h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
.login-examples { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 30rem; gap: 12px; }
.login-examples .cap h3 { font-size: 0.9375rem; }
@media (max-width: 680px) {
  /* Heading and one line of pitch, then the sign-in panel, then the
     examples, so the panel is near the top of a short screen. */
  .login { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .login-pitch { display: contents; }
  .login-examples { order: 1; gap: 8px; }
}
/* Setup: device switch, hidden sections stay hidden even under .panel. */
.setup-switch { justify-self: start; max-width: 100%; }
section[data-platform][hidden] { display: none; }
/* A web address to read or copy: its own line, wrapping anywhere so a
   long host never makes a phone scroll sideways. */
.setup-url { display: block; padding: 8px 10px; overflow-wrap: anywhere; }
li .setup-url { margin-top: 4px; }
/* Code blocks scroll inside their own box instead of clipping the card. */
.stack > pre { min-width: 0; max-width: 100%; overflow-x: auto; }
@media (max-width: 680px) {
  section[data-platform] .btn.sm { min-height: 44px; }
}

/* ---- P2 map & P3 bulk select ---- */
/* Map markers: a kind is its shape + glyph, the colour only
   repeats it. Place = circle, recipe = square, product = diamond,
   other = rounded square with a dashed edge. 44px hit area, ~30px shape. */
.map-marker { display: grid; place-items: center; background: transparent; border: 0; }
.map-pin {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border: 2px solid var(--surface); background: var(--kind, var(--other)); color: var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.map-pin .icon { width: 16px; height: 16px; stroke-width: 2; }
.map-pin[data-kind="place"], [data-kind="place"] > .map-pin { border-radius: 50%; }
.map-pin[data-kind="recipe"], [data-kind="recipe"] > .map-pin { border-radius: 3px; }
.map-pin[data-kind="product"], [data-kind="product"] > .map-pin { width: 26px; height: 26px; border-radius: 3px; transform: rotate(45deg); }
.map-pin[data-kind="product"] .icon, [data-kind="product"] > .map-pin .icon { transform: rotate(-45deg); }
.map-pin[data-kind="other"], [data-kind="other"] > .map-pin { border-radius: 9px; border-style: dashed; }
.map-marker:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 50%; }

.map-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 0; padding: 0; list-style: none; font-size: 0.875rem; color: var(--ink-2); }
.map-legend li { display: inline-flex; align-items: center; gap: 8px; }
.map-legend .map-pin { width: 22px; height: 22px; }
.map-legend [data-kind="product"] > .map-pin { width: 18px; height: 18px; }
.map-legend .map-pin .icon { width: 12px; height: 12px; }

/* Popup: a small frame (thumbnail, kind key, title, one line). Leaflet's
   own popup chrome is re-skinned with tokens so it follows the theme. */
.map-popup .leaflet-popup-content-wrapper, .map-popup .leaflet-popup-tip {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: none;
}
.map-popup .leaflet-popup-content-wrapper { border-radius: var(--radius); }
.map-popup .leaflet-popup-content { margin: 10px; font: inherit; line-height: 1.35; }
/* .leaflet-container in front: Leaflet's own rule (loaded later) has the
   same specificity as .map-popup a.leaflet-popup-close-button. */
.leaflet-container .map-popup a.leaflet-popup-close-button { width: 32px; height: 32px; font: 400 1.25rem/32px var(--font-body); color: var(--ink-2); }
.leaflet-container .map-popup a.leaflet-popup-close-button:hover,
.leaflet-container .map-popup a.leaflet-popup-close-button:focus { color: var(--ink); }
.map-pop { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; align-items: start; color: var(--ink); text-decoration: none; }
/* .leaflet-container a (Leaflet's link blue) would otherwise win. */
.leaflet-container a.map-pop, .leaflet-container a.map-pop:hover { color: var(--ink); }
.map-pop:hover .frame-title { text-decoration: underline; }
.map-pop .thumb { display: block; width: 64px; }
.map-pop .cap { padding-right: 22px; }
.map-pop .frame-title { display: block; font-size: 0.9375rem; }
.map-pop .yield { font-size: 0.8125rem; }
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-container .leaflet-control-attribution { background: var(--surface); color: var(--ink-2); }
.leaflet-container .leaflet-control-attribution a { color: var(--accent); }
/* Zoom buttons follow the theme. */
.leaflet-container .leaflet-bar, .leaflet-touch .leaflet-bar { border: 1px solid var(--line-strong); box-shadow: none; }
.leaflet-container .leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--line); }
.leaflet-container .leaflet-bar a:hover, .leaflet-container .leaflet-bar a:focus { background: var(--surface-2); color: var(--ink); }
.leaflet-container .leaflet-bar a.leaflet-disabled { background: var(--surface-2); color: var(--ink-3); }
/* Dark theme: dim the OSM tiles only, not markers, popups or controls. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: brightness(0.7) contrast(1.1) saturate(0.8); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: brightness(0.7) contrast(1.1) saturate(0.8); }
/* Phone: 44px zoom buttons and popup close button. */
@media (max-width: 680px) {
  .leaflet-container .leaflet-bar.leaflet-control-zoom a { width: 44px; height: 44px; line-height: 44px; }
  .leaflet-container .map-popup a.leaflet-popup-close-button { width: 44px; height: 44px; line-height: 44px; }
  .map-pop .cap { padding-right: 34px; }
}

/* Bulk select, List view only. */
.select-toggle { justify-content: flex-end; }
.sheet.compact.selecting .pick {
  display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center;
  border-bottom: 1px solid var(--line);
}
.sheet.compact.selecting .pick .frame { border-bottom: 0; }
.pick-hit { display: grid; place-items: center; width: 44px; height: 44px; cursor: pointer; }
.pick-hit input { width: 20px; height: 20px; margin: 0; cursor: pointer; }
span.pick-hit { cursor: default; }
.pick:has(input:checked) { background: var(--accent-soft); }
.bulk-bar {
  position: sticky; bottom: 0; z-index: 15;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  margin: 0; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.bulk-text > * { margin: 0; }
.bulk-count { font-weight: 700; }
.bulk-bar .actions { align-items: flex-start; }
.bulk-bar .btn.sm, .bulk-delete > summary { min-height: 44px; }
.bulk-delete > summary { list-style: none; }
.bulk-delete > summary::-webkit-details-marker { display: none; }
.bulk-delete[open] > summary { display: none; }
.bulk-delete .confirm { max-width: 32rem; }
@media (max-width: 680px) {
  /* Right on top of the phone tab bar: no gap for rows to show through. */
  .bulk-bar { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); border-radius: var(--radius) var(--radius) 0 0; }
  /* Delete confirm open: drop the hint and Mark done, and keep the confirm
     small, so the bar does not cover half the screen. */
  .bulk-bar:has(.bulk-delete[open]) .bulk-text .xsmall,
  .bulk-bar:has(.bulk-delete[open]) > .actions > .btn { display: none; }
  .bulk-bar:has(.bulk-delete[open]) { gap: 6px; padding-block: 8px; }
  .bulk-delete .confirm { gap: 6px; padding: 8px 10px; font-size: 0.9375rem; }
}

/* ---- P2 fix details & P3 cooking mode ---- */
/* Fix details (P2.3): partials/detail_fix_form.html, inline in #fix-details
   on the detail page or alone on /reels/{id}/fix. Tokens only. */
.fix-slot:empty { display: none; }
.fix-form h1 { font-size: 1.5rem; }
.fix-group {
  display: grid; gap: 12px; min-width: 0; margin: 0; padding: 14px 0 0;
  border: 0; border-top: 3px solid var(--kind, var(--other));
}
.fix-group > legend { float: left; width: 100%; padding: 0; margin: 0; }
.fix-fields { clear: both; display: grid; align-items: start; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 12px 16px; }
.fix-fields .field.wide { grid-column: 1 / -1; }
.fix-error { color: var(--bad); font-weight: 700; }
.fix-form .textarea[aria-invalid="true"] { border-color: var(--bad); }
.fix-original > summary { font-size: 0.875rem; color: var(--ink-2); }
.fix-original > p { margin: 4px 0 0; padding: 8px 10px; border-left: 3px solid var(--line-strong); color: var(--ink-2); overflow-wrap: anywhere; }
.fix-restore { font-size: 0.875rem; }

/* Cooking mode (P3): cook.html. Large text; without JS every step shows,
   with JS (.is-stepping) one step at a time. */
.cook { max-width: 46rem; }
.cook h1 { font-size: clamp(1.75rem, 5vw, 2.5rem); }
.cook .facts dd { font-size: 1.125rem; }
.cook .ingredients { font-size: 1.125rem; }
.cook .disc-body { padding-left: 0; color: var(--ink); }
.cook-list { gap: 28px; }
.cook-list li { font-size: clamp(1.375rem, 4.6vw, 1.875rem); line-height: 1.45; grid-template-columns: 1.6em minmax(0, 1fr); }
.cook-steps.is-stepping .cook-list li { grid-template-columns: minmax(0, 1fr); min-height: 8em; font-size: clamp(1.5rem, 5.4vw, 2.25rem); }
/* Hidden steps do not count, so the list number would always read "1.";
   the "Step 3 of 8" line carries the number instead. */
.cook-steps.is-stepping .cook-list li::before { content: none; }
.cook-progress { display: grid; gap: 8px; }
.cook-progress p { margin: 0; font-weight: 700; font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.cook-progress .meter > span { background: var(--kind, var(--accent)); }
/* Previous / Next stay on screen while a long step scrolls under them. */
.cook-nav {
  position: sticky; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding-block: 12px; background: var(--bg);
}
.cook-nav .btn { min-height: 56px; font-size: 1.125rem; }
.cook-nav .btn[disabled] { opacity: 0.4; }
@media (max-width: 680px) {
  /* Above the phone tab bar, like .bulk-bar. */
  .cook-nav { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); }
  .cook-nav .btn { min-height: 56px; }
  .cook-keys { display: none; }
}

/* ---- P2 offline & PWA ---- */
/* Offline indicator and "Added N reels you saved offline" (base.html). Sits
   above the phone tab bar; on desktop, at the bottom of the window. */
.sw-status {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 30;
  transform: translateX(-50%); max-width: min(34rem, calc(100vw - 32px)); margin: 0;
  padding: 8px 14px; border-radius: var(--radius); background: var(--ink); color: var(--bg);
  font-size: 0.875rem; font-weight: 700; text-align: center;
}
.sw-status a { color: inherit; text-decoration: underline; }
@media (max-width: 680px) {
  .sw-status { bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom, 0px)); }
}
/* offline.html: the stacked panels and the list of reels saved here. */
.offline-page {
  display: grid; gap: 16px; align-content: start;
  /* No top bar or tab bar here, and the viewport is viewport-fit=cover:
     keep clear of the notch and the home indicator. */
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}
.offline-page > .panel { width: 100%; }
.offline-list { display: grid; gap: 8px; margin: 0; padding-left: 1.2em; }
.offline-list a { overflow-wrap: anywhere; }

/* ---- P2 admin & P3 dashboard charts ---- */
/* Admin users (P2.5), admin pipeline details (P2.5) and the admin dashboard
   charts (P3). Tokens only; every colour below is a var(). */

/* Users: search row, inline quota form, role tags. */
.users-search { gap: 8px; flex: none; max-width: 40rem; }
.users-search .input { flex: 1 1 auto; min-width: 0; }
.users-table td { vertical-align: middle; }
.users-table .user-id { min-width: 12rem; }
.users-table .nowrap { white-space: nowrap; }
.quota-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 0; min-width: 12rem; }
.quota-input { width: 7.5rem; }
.quota-msg { min-width: 0; color: var(--good); }
.quota-msg.bad { color: var(--bad); }
.role-tag { display: inline-block; padding: 1px 8px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: 0.8125rem; color: var(--ink-2); }
.role-tag.admin { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 700; }
.role-cell { min-width: 12rem; }
.role-cell .confirm { margin-top: 0; }
/* The confirm names the user's email: let a long one wrap. */
.users-table .confirm p { overflow-wrap: anywhere; }
.role-cell > .small { display: block; margin-top: 4px; }

/* Phone: each user is a stacked card, label left / value right, no
   horizontal scroll at 400px. */
@media (max-width: 680px) {
  .users-search { max-width: none; }
  .users-table thead {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); white-space: nowrap;
  }
  .users-table, .users-table tbody, .users-table tr, .users-table td { display: block; width: 100%; }
  /* 4px sides: room for focus rings inside the .table-wrap scroller. */
  .users-table tr { padding: 12px 4px; border-bottom: 1px solid var(--line); }
  .users-table td { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: 8px; align-items: center; padding: 6px 0; border: 0; }
  .users-table td::before { content: attr(data-label); font-size: 0.8125rem; font-weight: 700; color: var(--ink-3); }
  .users-table td.role-cell { min-width: 0; }
  .users-table td.role-cell::before { content: none; }
  .users-table td.role-cell { grid-template-columns: minmax(0, 1fr); }
  .users-table td > * { min-width: 0; }
  .users-table .user-id { min-width: 0; }
  .users-table .user-email { overflow-wrap: anywhere; }
  .users-table .role-tag { justify-self: start; }
  .quota-form { min-width: 0; }
  .quota-input { width: 6.5rem; }
}

/* Pipeline details: wide tables scroll in their own container. */
.pipeline .glance { gap: 8px 24px; }
.pipe-table th[scope="row"] { color: var(--ink); font-size: 0.9375rem; white-space: nowrap; }
.pipe-table .nowrap, .pipe-table td:first-child { white-space: nowrap; }
.pipe-table .cell-wide { min-width: 14rem; max-width: 28rem; overflow-wrap: anywhere; }
.pipe-table tfoot th, .pipe-table tfoot td { border-bottom: 0; font-weight: 700; color: var(--ink); }
.pipe-table details.fold > summary { cursor: pointer; color: var(--accent); min-height: 32px; }
.pipe-table details.fold pre { max-width: 28rem; margin: 6px 0 0; }
.pipe-table td.dur { min-width: 6.5rem; }
/* Edge shadows (background-attachment: local) show which side still scrolls. */
.pipeline .table-wrap {
  background:
    linear-gradient(to right, var(--bg), var(--bg)) left center / 24px 100% no-repeat local,
    linear-gradient(to left, var(--bg), var(--bg)) right center / 24px 100% no-repeat local,
    linear-gradient(to right, var(--line-strong), transparent) left center / 10px 100% no-repeat scroll,
    linear-gradient(to left, var(--line-strong), transparent) right center / 10px 100% no-repeat scroll;
}
.scroll-hint { display: none; margin: 0; }
@media (max-width: 680px) {
  .scroll-hint { display: block; }
  .pipe-table th, .pipe-table td { padding: 6px 8px; }
  .pipe-table .nowrap, .pipe-table td:first-child { white-space: normal; }
  .pipe-table th[scope="row"] { white-space: normal; }
  .pipe-table td.started { white-space: nowrap; }
  .pipe-table .cell-wide { min-width: 9rem; max-width: 14rem; }
  .pipe-table td.dur { min-width: 4.5rem; }
  .pipe-table details.fold > summary { min-height: 44px; display: flex; align-items: center; }
  .pipe-table details.fold pre { max-width: 14rem; }
}
.dur-bar { display: block; height: 4px; margin-top: 4px; border-radius: 2px; background: var(--surface-2); }
.dur-bar > span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.verdict { font-weight: 700; }
.verdict[data-verdict="disputed"], .verdict[data-verdict="false"] { color: var(--bad); }
.verdict[data-verdict="supported"] { color: var(--good); }
.run-block + .run-block { margin-top: 12px; }
.notice pre { margin: 0; padding: 0; border: 0; background: transparent; }

/* Dashboard charts: inline SVG, one hue (accent) per single-series chart,
   recessive grid, text in ink tokens. */
.dash-totals { gap: 10px 28px; }
.dash-totals dd { font-size: 1.25rem; }
.dash-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.chart { display: grid; gap: 12px; margin: 0; min-width: 0; container-type: inline-size; }
.chart > * { margin: 0; }
.chart-cap { display: grid; gap: 2px; }
.chart-cap > * { margin: 0; }
.chart-cap h2 { font-size: 1.25rem; }
.chart-scroll { overflow-x: auto; max-width: 100%; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
/* Narrow containers (phone, split panel) get the compact drawing, which fits
   without scrolling; wide ones keep the full one. */
.chart-compact { display: none; }
@container (max-width: 560px) {
  .chart-full { display: none; }
  .chart-compact { display: block; }
}
.chart-meter { min-width: 0; height: 24px; }
.chart-wide { max-width: 640px; }
.chart-wide.chart-full .chart-label, .chart-wide.chart-full .chart-value, .chart-wide.chart-full .chart-tick { font-size: 17px; }
.chart-compact .chart-value { font-size: 12px; }
.chart-compact .chart-label { font-size: 13px; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { stroke: var(--line-strong); }
.chart-tick { fill: var(--ink-3); font-size: 13px; font-family: var(--font-body); font-variant-numeric: tabular-nums; }
.chart-label { fill: var(--ink-2); font-size: 14px; font-family: var(--font-body); }
.chart-value { fill: var(--ink); font-size: 13px; font-weight: 700; font-family: var(--font-body); font-variant-numeric: tabular-nums; }
.chart-bar { fill: var(--accent); }
.chart-bar.p95 { fill: var(--line-strong); }
.chart-rest { fill: var(--surface-2); stroke: var(--line); }
g:hover > .chart-bar { fill: var(--accent-hover); }
g:hover > .chart-bar.p95 { fill: var(--ink-3); }
.chart-empty { padding: 24px 0; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; padding: 0; list-style: none; font-size: 0.875rem; color: var(--ink-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.chart-swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); }
.chart-swatch.p50 { background: var(--accent); }
.chart-swatch.p95 { background: var(--line-strong); }
.chart-swatch.rest { background: var(--surface-2); border: 1px solid var(--line); }
@media (forced-colors: active) {
  .snip mark { background: Mark; color: MarkText; }
  .chart-bar, .chart-swatch { fill: CanvasText; background: CanvasText; }
  .chart-bar.p95, .chart-swatch.p95 { fill: GrayText; background: GrayText; }
}
