/* Aesthetic direction — Test Document Studio (studio-library-first T-E)
 * Precise / calm / trustworthy: a well-made internal tool from a fintech or utilities company.
 * - Type: the platform UI stack (-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui).
 *   Deliberate and constraint-driven: the CSP is self-only, so no web fonts and no CDN.
 *   ui-monospace for codes, counts and values. Scale 12 / 13 / 14 / 16 / 20 / 24 px;
 *   weights 400 / 500 / 600. Hints never below 12px, labels never below 13px (U42).
 * - Colour: cool neutral. A 9-step slate scale in oklch; one brand colour, deep teal
 *   oklch(52% 0.09 200), with hover / press / soft / ink variants. Teal is action, focus,
 *   selection and the test version's identity. Semantic ok / warn / bad for outcomes;
 *   highlighter amber on paper ONLY marks changed content and never changes with the theme
 *   (U02). Toned whites and blacks: no pure #fff or #000. Full dark mode with its own tokens.
 *   Every text pair meets WCAG AA in both themes.
 * - Density: normal, on a 4px base. Spacing 4 / 8 / 12 / 16 / 24 / 32 / 48.
 * - Radius: 6px for controls, 10px for panels and cards, 2px for paper. One subtle elevation
 *   level (--shadow-sm); hairline borders do most of the work. Overlays (dialogs, popovers)
 *   get the one deeper shadow so they read as above the page.
 * - Components: a filled primary button for Generate only; outlined secondary buttons; ghost
 *   buttons in toolbars. Library items are compact cards (supplier, kind tag, pages and
 *   period); the selected card gets a brand ring.
 * - Header: the mark (a page on a teal tile), the wordmark, the permanent "For testing only"
 *   badge with an info button that reopens the first-open notice; status, theme and shortcuts
 *   on the right.
 * - Icons: the Lucide sprite only (ISC). No illustrations.
 * - Motion: quiet. 150–200ms on state changes, nothing on entry; prefers-reduced-motion keeps
 *   only opacity fades, and every busy state also has text.
 * - CSP: every value lives here as a token on :root; no inline styles anywhere.
 */
:root {
  color-scheme: light;
  /* slate neutral scale */
  --slate-0: oklch(99.2% 0.002 250);
  --slate-50: oklch(97.6% 0.004 250);
  --slate-100: oklch(95.6% 0.006 250);
  --slate-150: oklch(93.4% 0.008 250);
  --slate-200: oklch(90.5% 0.009 250);
  --slate-300: oklch(83% 0.011 250);
  --slate-500: oklch(60% 0.015 252);
  --slate-600: oklch(49% 0.017 255);
  --slate-700: oklch(40% 0.019 255);
  --slate-900: oklch(22.5% 0.02 258);
  --bg: var(--slate-50);
  --surface: var(--slate-0);
  --raised: var(--slate-0);
  --sunken: var(--slate-100);
  --canvas: var(--slate-150);
  --line: var(--slate-200);
  --line-strong: var(--slate-300);
  --field: var(--slate-500); /* 3:1 on surface for control borders */
  --ink: var(--slate-900);
  --ink-2: var(--slate-700);
  --ink-3: var(--slate-600);
  /* brand: deep teal */
  --brand: oklch(52% 0.09 200);
  --brand-hover: oklch(47% 0.09 200);
  --brand-press: oklch(43% 0.085 200);
  --brand-soft: oklch(95.2% 0.022 200);
  --brand-line: oklch(80% 0.06 200);
  --brand-ink: oklch(44% 0.085 200);
  --on-brand: oklch(99% 0.004 200);
  --test: var(--brand);
  --test-ink: var(--brand-ink);
  --test-soft: var(--brand-soft);
  /* semantic */
  --ok: oklch(47% 0.12 155);
  --ok-soft: oklch(95.5% 0.035 155);
  --warn: oklch(50% 0.13 62);
  --warn-soft: oklch(96% 0.04 80);
  --warn-line: oklch(84% 0.08 75);
  --bad: oklch(50% 0.17 25);
  --bad-soft: oklch(96% 0.025 25);
  --focus: oklch(55% 0.1 200);
  --disabled-ink: oklch(60% 0.01 255);
  --disabled-bg: oklch(95% 0.004 255);
  --backdrop: oklch(22% 0.02 255 / 0.45);
  --shadow-sm: 0 1px 2px oklch(25% 0.02 255 / 0.08);
  --shadow-page: 0 1px 2px oklch(25% 0.02 255 / 0.08), 0 6px 20px oklch(25% 0.02 255 / 0.08);
  --shadow-pop: 0 1px 2px oklch(25% 0.02 255 / 0.08), 0 12px 32px oklch(25% 0.02 255 / 0.16);
  /* on paper: the same in light and dark themes (U02) */
  --paper: oklch(99.3% 0.002 90);
  --paper-mark-fill: oklch(83% 0.16 85 / 0.24);
  --paper-mark-ink: oklch(45% 0.11 70);
  --paper-mark-flash: oklch(78% 0.17 85 / 0.5);
  --paper-handle: oklch(52% 0.09 200);
  --paper-focus-a: oklch(25% 0.02 255);
  --paper-focus-b: oklch(98% 0.01 90);
  --r-sm: 4px;
  --r: 6px;
  --r-lg: 10px;
  --r-paper: 2px;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.875rem;
  --fs-lg: 1rem;
  --fs-xl: 1.25rem;
  --fs-2xl: 1.5rem;
  --lh-tight: 1.25;
  --lh: 1.45;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --t-fast: 150ms var(--ease);
  --t: 200ms var(--ease);
  --panel-w: 440px;
  --inspector-w: 340px;
}
/* One dark token block, applied for the system setting and for the explicit switch (U40). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --slate-0: oklch(21.5% 0.01 255); --slate-50: oklch(17.5% 0.009 255); --slate-100: oklch(19% 0.009 255);
    --slate-150: oklch(15% 0.008 255); --slate-200: oklch(29% 0.011 255); --slate-300: oklch(38% 0.013 255);
    --slate-500: oklch(57% 0.014 255); --slate-600: oklch(72% 0.012 255); --slate-700: oklch(81% 0.01 255);
    --slate-900: oklch(94% 0.006 255);
    --raised: oklch(24% 0.011 255);
    --brand: oklch(54% 0.09 200); --brand-hover: oklch(49% 0.09 200); --brand-press: oklch(45% 0.085 200);
    --brand-soft: oklch(27% 0.035 200); --brand-line: oklch(48% 0.07 200); --brand-ink: oklch(80% 0.085 200);
    --on-brand: oklch(99% 0.004 200);
    --ok: oklch(77% 0.12 155); --ok-soft: oklch(27% 0.04 155);
    --warn: oklch(82% 0.12 75); --warn-soft: oklch(28% 0.045 70); --warn-line: oklch(46% 0.07 70);
    --bad: oklch(75% 0.14 25); --bad-soft: oklch(28% 0.05 25);
    --focus: oklch(74% 0.1 200); --disabled-ink: oklch(52% 0.008 255); --disabled-bg: oklch(22% 0.006 255);
    --backdrop: oklch(8% 0.01 255 / 0.6);
    --shadow-sm: 0 1px 2px oklch(5% 0.01 255 / 0.4);
    --shadow-page: 0 0 0 1px oklch(98% 0.005 255 / 0.06), 0 8px 24px oklch(5% 0.01 255 / 0.4);
    --shadow-pop: 0 0 0 1px oklch(98% 0.005 255 / 0.08), 0 16px 40px oklch(5% 0.01 255 / 0.5);
    --paper: oklch(96% 0.004 90);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --slate-0: oklch(21.5% 0.01 255); --slate-50: oklch(17.5% 0.009 255); --slate-100: oklch(19% 0.009 255);
  --slate-150: oklch(15% 0.008 255); --slate-200: oklch(29% 0.011 255); --slate-300: oklch(38% 0.013 255);
  --slate-500: oklch(57% 0.014 255); --slate-600: oklch(72% 0.012 255); --slate-700: oklch(81% 0.01 255);
  --slate-900: oklch(94% 0.006 255);
  --raised: oklch(24% 0.011 255);
  --brand: oklch(54% 0.09 200); --brand-hover: oklch(49% 0.09 200); --brand-press: oklch(45% 0.085 200);
  --brand-soft: oklch(27% 0.035 200); --brand-line: oklch(48% 0.07 200); --brand-ink: oklch(80% 0.085 200);
  --on-brand: oklch(99% 0.004 200);
  --ok: oklch(77% 0.12 155); --ok-soft: oklch(27% 0.04 155);
  --warn: oklch(82% 0.12 75); --warn-soft: oklch(28% 0.045 70); --warn-line: oklch(46% 0.07 70);
  --bad: oklch(75% 0.14 25); --bad-soft: oklch(28% 0.05 25);
  --focus: oklch(74% 0.1 200); --disabled-ink: oklch(52% 0.008 255); --disabled-bg: oklch(22% 0.006 255);
  --backdrop: oklch(8% 0.01 255 / 0.6);
  --shadow-sm: 0 1px 2px oklch(5% 0.01 255 / 0.4);
  --shadow-page: 0 0 0 1px oklch(98% 0.005 255 / 0.06), 0 8px 24px oklch(5% 0.01 255 / 0.4);
  --shadow-pop: 0 0 0 1px oklch(98% 0.005 255 / 0.08), 0 16px 40px oklch(5% 0.01 255 / 0.5);
  --paper: oklch(96% 0.004 90);
}
/* Increase Contrast (U52) */
@media (prefers-contrast: more) {
  :root { --line: var(--line-strong); --field: var(--ink-2); --ink-2: var(--ink); --ink-3: var(--ink-2); }
  .marks polygon { stroke-width: 2.5 !important; }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: var(--fs-md) / var(--lh) var(--sans);
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column;
}
.sprite { display: none; }
.sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important;
  margin: -1px !important; border: 0 !important; overflow: hidden !important; clip-path: inset(50%) !important;
  white-space: nowrap !important;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; line-height: var(--lh-tight); }
p { margin: 0; }
code { font: 0.95em var(--mono); background: var(--sunken); padding: 1px 4px; border-radius: var(--r-sm); }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.xs { width: 12px; height: 12px; stroke-width: 2.25; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 24px; height: 24px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.count, .kbd, .row-page, .stepper-label, .chip-n { font-variant-numeric: tabular-nums; }
.skip { position: absolute; left: 8px; top: -48px; z-index: 50; padding: 8px 12px; border-radius: var(--r); background: var(--brand); color: var(--on-brand); font-weight: 600; text-decoration: none; }
.skip:focus { top: 8px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.fine { font-size: var(--fs-sm); color: var(--ink-2); }
.link {
  all: unset; color: var(--brand-ink); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; font-weight: 500; border-radius: 2px;
}
.link:hover { color: var(--brand-hover); }
.link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.test-ink { color: var(--test-ink); }
.kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 4px;
  border-radius: var(--r-sm); border: 1px solid var(--line-strong); border-bottom-width: 2px;
  font: 500 var(--fs-xs) / 1 var(--mono); color: var(--ink-2); background: var(--surface);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-property: opacity !important; }
}

/* --- app bar ------------------------------------------------------------------------------ */
.appbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 56px; padding: 0 16px 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.local, .pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--sunken); color: var(--ink-2); font: 500 var(--fs-xs) / 1 var(--sans);
  cursor: pointer; white-space: nowrap; transition: background var(--t-fast), border-color var(--t-fast);
}
.local:hover, .pill:hover { border-color: var(--field); color: var(--ink); }
.pill { height: 28px; font-size: var(--fs-sm); }
.appbar-end { display: flex; align-items: center; gap: 8px; }
.signout { text-decoration: none; }
.signout[hidden] { display: none; }
/* hosted mode: why a call was stopped by the sign-in (aws ticket 06) */
.signin-msg {
  display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 20px; flex: none;
  background: var(--bad-soft); color: var(--bad); border-bottom: 1px solid color-mix(in oklch, var(--bad) 40%, transparent);
  font: 500 var(--fs-sm) / 1.4 var(--sans);
}
.signin-msg[hidden] { display: none; }
.signin-msg .icon { flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--field); flex: none; }
.pill[data-state="ok"] .dot { background: var(--ok); }
.pill[data-state="busy"] .dot { background: var(--brand); animation: pulse 1s ease-in-out infinite; }
.pill[data-state="bad"] { color: var(--bad); border-color: color-mix(in oklch, var(--bad) 40%, transparent); background: var(--bad-soft); }
.pill[data-state="bad"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: 0.3; } }
.seg.theme { padding: 2px; }
.seg.theme button { width: 28px; height: 24px; padding: 0; justify-content: center; }

.popover {
  position: fixed; inset: auto; top: 60px; right: 16px; margin: 0; width: min(360px, calc(100vw - 32px));
  padding: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--raised); color: var(--ink);
  box-shadow: var(--shadow-pop); display: none; gap: 12px;
}
.popover:popover-open { display: grid; }
.popover h2 { font-size: var(--fs-md); font-weight: 600; }
.plain { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: var(--fs-sm); color: var(--ink-2); }
.health { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: var(--fs-sm); }
.health dt { color: var(--ink-3); }
.health dd { margin: 0; }

/* --- controls ---------------------------------------------------------------------------- */
input, select, textarea {
  font: inherit; font-size: var(--fs-md); color: var(--ink); background: var(--surface);
  border: 1px solid var(--field); border-radius: var(--r);
  padding: 4px 8px; min-width: 0; width: 100%; min-height: 32px;
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
input::placeholder { color: var(--ink-3); opacity: 1; }
input:hover, select:hover { border-color: var(--ink-2); }
input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
input[aria-invalid="true"] { border-color: var(--bad); box-shadow: inset 3px 0 0 var(--bad); }
input:disabled, select:disabled { background: var(--disabled-bg); color: var(--disabled-ink); border-color: var(--line); cursor: not-allowed; }
input[type="range"] { padding: 0; border: 0; background: none; min-height: 24px; accent-color: var(--brand); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 32px; padding: 0 12px; border-radius: var(--r);
  font: 500 var(--fs-sm) / 1 var(--sans); color: var(--ink); text-decoration: none; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--field); cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.btn:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--sunken); border-color: var(--ink-2); }
.btn:active:not(:disabled):not([aria-disabled="true"]) { background: var(--line); transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--disabled-bg); color: var(--disabled-ink); border-color: var(--line); cursor: not-allowed; }
.btn.primary:not(:disabled):not([aria-disabled="true"]) { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 600; }
.btn.primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.primary:active:not(:disabled):not([aria-disabled="true"]) { background: var(--brand-press); border-color: var(--brand-press); }
.btn.ghost:not(:disabled):not([aria-disabled="true"]) { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--sunken); color: var(--ink); }
.btn.ghost:disabled { background: transparent; border-color: transparent; }
.btn.danger:hover:not(:disabled) { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.btn.danger-fill { background: var(--bad) !important; border-color: var(--bad) !important; color: var(--on-brand) !important; }
.btn.sm { min-height: 28px; padding: 0 8px; font-size: var(--fs-sm); gap: 6px; }
.btn.done { background: var(--ok-soft) !important; border-color: transparent !important; color: var(--ok) !important; }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 32px; padding: 0; }
.icon-btn.sm { width: 28px; padding: 0; }
.text-btn { min-width: 52px; padding: 0 8px; font: 500 var(--fs-sm) / 1 var(--sans); }
.block-btn { width: 100%; min-height: 40px; font-size: var(--fs-md); position: relative; }
.block-btn .kbd { position: absolute; right: 10px; background: transparent; color: inherit; opacity: 0.75; border-color: currentColor; }
.btn.cancel { background: var(--surface); color: var(--ink); border-color: var(--field); }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 32px; font-size: var(--fs-sm); color: var(--ink-2); cursor: pointer; font-weight: 500; position: relative; }
.toggle.sm { min-height: 28px; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.toggle:has(input:disabled) { color: var(--disabled-ink); cursor: not-allowed; }
.track { width: 28px; height: 16px; border-radius: 999px; background: transparent; border: 1.5px solid var(--field); position: relative; transition: background var(--t-fast), border-color var(--t-fast); flex: none; }
.track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); transition: transform var(--t-fast), background var(--t-fast); }
.toggle:hover .track { border-color: var(--ink-2); }
.toggle input:checked + .track { background: var(--brand); border-color: var(--brand); }
.toggle input:checked + .track::after { transform: translateX(12px); background: var(--on-brand); }
.toggle input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }
.toggle input:disabled + .track { border-color: var(--line); background: var(--disabled-bg); }
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--r); background: var(--sunken); border: 1px solid var(--line); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 10px; border: 0; border-radius: var(--r-sm);
  font: 500 var(--fs-sm) / 1 var(--sans); color: var(--ink-2); background: transparent; cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.seg button:hover { color: var(--ink); background: var(--line); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: inset 0 0 0 1px var(--field), var(--shadow-sm); }
.seg.solo { display: none; }

/* --- shell + panel ------------------------------------------------------------------------- */
.shell { flex: 1; display: grid; grid-template-columns: var(--panel-w) 1fr; min-height: 0; transition: grid-template-columns var(--t); }
.shell.collapsed { grid-template-columns: 72px 1fr; }
.shell.wide-form:not(.collapsed) { --panel-w: min(880px, 72vw); }
.panel { position: relative; background: var(--surface); border-right: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
.panel-body { position: relative; flex: 1; overflow-y: auto; min-height: 0; scroll-padding-bottom: 160px; }
.rail { display: none; padding: 12px 8px; gap: 4px; flex-direction: column; align-items: stretch; }
.shell.collapsed .rail { display: flex; }
.shell.collapsed .panel-body { display: none; }
.rail-btn { flex-direction: column; gap: 4px; min-height: 56px; padding: 8px 4px; font-size: var(--fs-xs); }
.panel form { display: flex; flex-direction: column; min-height: 100%; }
.block { padding: 20px; }
.block + .block { border-top: 1px solid var(--line); }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; min-height: 28px; flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 4px; }
.block h2 { display: flex; align-items: center; gap: 8px; font-size: var(--fs-lg); font-weight: 600; }
.num {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid var(--ink-2); color: var(--ink-2); font: 600 var(--fs-xs) / 1 var(--mono);
}
.help { margin: 0 0 16px; color: var(--ink-2); font-size: var(--fs-sm); line-height: var(--lh); }
.split-btn { display: inline-flex; }
.split-btn .btn:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.persona { width: 28px; padding: 0 4px; color: transparent !important; text-shadow: none; border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; appearance: none; color: transparent; text-align: center;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: 10px 12px, 14px 12px; background-size: 4px 4px; background-repeat: no-repeat; }
.persona option { color: var(--ink); }

.drop {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 20px 16px; min-height: 96px;
  border: 1.5px dashed var(--field); border-radius: var(--r-lg); background: var(--sunken);
  color: var(--ink); cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast);
}
.drop:hover, body.dropping .drop { border-color: var(--brand); background: var(--brand-soft); }
.drop:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; min-height: 0; }
.drop-thumb { display: grid; place-items: center; width: 44px; height: 56px; flex: none; border-radius: var(--r-sm); color: var(--ink-2); overflow: hidden; }
.drop-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; background: var(--paper); box-shadow: var(--shadow-sm); }
.drop-text { display: grid; min-width: 0; flex: 1; gap: 2px; }
.drop-title { font-weight: 600; overflow-wrap: anywhere; }
.drop-sub { font-size: var(--fs-sm); color: var(--ink-2); }
.drop-change { display: none; font-size: var(--fs-sm); font-weight: 500; color: var(--brand-ink); }
.drop.has-file { border-style: solid; border-color: var(--line); background: var(--surface); padding: 12px; min-height: 0; }
.drop.has-file:hover { border-color: var(--field); background: var(--sunken); }
.drop.has-file .drop-change { display: block; }
.drop.checking .drop-thumb::after { content: ""; position: absolute; }
.drop.error { border-color: var(--bad); }
.field-err { margin: 4px 0 0; color: var(--bad); font-size: var(--fs-sm); font-weight: 500; }
.field-err::before { content: "! " / ""; font-weight: 700; }

.reqs:empty { display: none; }
.reqs { margin-top: 12px; display: grid; gap: 8px; font-size: var(--fs-sm); }
.req-summary { color: var(--ink); font-weight: 500; }
.req-list { margin: 0; display: grid; gap: 8px; }
.req { display: grid; grid-template-columns: 112px 1fr; gap: 8px; align-items: start; }
.req dt { color: var(--ink-2); font-size: var(--fs-sm); line-height: 24px; }
.req dd { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 0 8px; border-radius: var(--r-sm);
  background: var(--sunken); border: 1px solid var(--line); font: 500 var(--fs-xs) / 1 var(--sans); color: var(--ink-2); white-space: nowrap; cursor: pointer;
}
button.chip:hover { border-color: var(--field); color: var(--ink); }
.chip.need { background: var(--brand-soft); border-color: transparent; color: var(--brand-ink); font-weight: 600; }
.chip.kept { background: transparent; border-style: dashed; color: var(--ink-2); }
.chip.erased { background: transparent; color: var(--ink-2); }
.chip.erased::before { content: ""; width: 8px; height: 8px; border: 1.5px dashed currentColor; border-radius: 2px; }
.chip.toggle-chip[aria-pressed="false"] { background: transparent; color: var(--ink-3); text-decoration: line-through; }
.chip-n { font-family: var(--mono); color: var(--ink-3); }
.note { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 8px 12px; border-radius: var(--r); background: var(--sunken); color: var(--ink-2); font-size: var(--fs-sm); }
.note .icon { margin-top: 1px; }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.skeleton-row { display: grid; grid-template-columns: 112px 1fr; gap: 8px; }
.skeleton { height: 20px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--sunken), var(--line), var(--sunken)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

fieldset { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
.type-row { margin: 0 0 20px; }
.fields > .note { margin-bottom: 20px; }
legend, .table-head h3 { padding: 0; margin-bottom: 8px; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.shell.wide-form .grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.span2 { grid-column: span 2; }
.f { display: grid; gap: 4px; font-size: var(--fs-sm); color: var(--ink-2); font-weight: 500; align-content: start; border-radius: var(--r); }
.lbl { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 6px; min-height: 18px; color: var(--ink); }
.req-mark { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; color: var(--brand-ink); }
.req-mark::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.src { margin-left: auto; padding: 0 6px; border-radius: var(--r-sm); font-size: var(--fs-xs); font-weight: 500; line-height: 18px; background: var(--sunken); color: var(--ink-2); }
.src[data-src="previous"] { background: var(--warn-soft); color: var(--warn); }
.f.invalid .lbl-text { color: var(--bad); }
.f.flash input { animation: fill-flash 900ms var(--ease); }
@keyframes fill-flash { from { background: var(--brand-soft); } }
.hint { font-size: var(--fs-xs); color: var(--ink-2); font-weight: 400; line-height: var(--lh); }
.more { margin: 0 0 12px; }
.more summary {
  cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--ink); min-height: 32px;
  list-style: none; display: flex; align-items: center; gap: 8px; border-radius: var(--r-sm);
}
.more summary:hover { color: var(--brand-ink); }
.more summary::before {
  content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform var(--t-fast); flex: none; margin: 0 2px;
}
.more[open] > summary::before { transform: rotate(45deg); }
.more summary::-webkit-details-marker { display: none; }
.more[open] > summary { margin-bottom: 8px; }
.more .toggle { margin-top: 12px; }
.makeup { margin-top: 4px; }
.rules { display: grid; gap: 8px; margin: 0; }
.rule-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px; align-items: center; font-size: var(--fs-sm); }
.rule-row label { color: var(--ink); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.rule-row.changed label::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.count { font: 500 var(--fs-xs) / 1 var(--mono); color: var(--ink-2); padding: 3px 6px; border-radius: var(--r-sm); background: var(--sunken); }

/* tables (U84) */
.tables:empty { display: none; }
.table-editor { margin: 0 0 20px; display: grid; gap: 8px; }
.table-head { display: flex; align-items: center; gap: 8px; }
.table-head h3 { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.row-count { margin-left: auto; font-size: var(--fs-xs); color: var(--ink-2); }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
.grid-table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
.grid-table th { text-align: left; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); padding: 6px 4px; background: var(--sunken); border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid-table th.money { text-align: right; }
.grid-table td { padding: 2px; border-bottom: 1px solid var(--line); }
.grid-table tr:last-child td { border-bottom: 0; }
.grid-table input { min-height: 28px; border-color: transparent; background: transparent; padding: 2px 6px; min-width: 96px; }
.grid-table input:hover { border-color: var(--field); }
.grid-table input.money { text-align: right; font-family: var(--mono); min-width: 84px; }
.grid-table input[type="date"] { min-width: 128px; }
.grid-table .rn { width: 28px; text-align: right; color: var(--ink-3); font: var(--fs-xs) var(--mono); padding-right: 6px; }
.grid-table .ra { width: 1%; }
.row-actions { display: flex; gap: 0; opacity: 0.55; transition: opacity var(--t-fast); }
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }
.table-summary { margin-top: 4px; }
input.money { font-family: var(--mono); text-align: right; }
input.money::placeholder { font-family: var(--sans); }

.actions {
  position: sticky; bottom: 0; margin-top: auto; padding: 12px 20px 16px; display: grid; gap: 8px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.actions-hint { margin: 0; font-size: var(--fs-sm); color: var(--ink-2); text-align: center; }
.actions-hint:empty { display: none; }
.progress-line { font-size: var(--fs-xs); color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.progress-line::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.progress-line.done::before { background: var(--ok); }
.form-msg { margin: 0; padding: 8px 12px; border-radius: var(--r); background: var(--bad-soft); color: var(--bad); font-size: var(--fs-sm); display: grid; gap: 4px; }
.form-msg ul { margin: 0; padding-left: 16px; }
.form-msg .link { color: var(--bad); }

/* --- workspace ----------------------------------------------------------------------------- */
.workspace { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--canvas); outline: none; }
.empty > p { margin: 0 0 20px; font-size: var(--fs-md); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.steps li { display: flex; align-items: flex-start; gap: 12px; padding: 12px; border-radius: var(--r-lg); font-size: var(--fs-md); color: var(--ink-2); }
.step-body { display: grid; gap: 4px; min-width: 0; flex: 1; }
.step-sub { font-size: var(--fs-sm); color: var(--ink-2); }
.steps strong { color: var(--ink); font-weight: 600; }
.step-n { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--field); font: 600 var(--fs-xs) / 1 var(--mono); flex: none; }
.step-n .icon { display: none; }
.steps li.current { background: var(--surface); box-shadow: var(--shadow-sm); }
.steps li.current .step-n { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.steps li.done .step-n { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.steps li.done .step-n .n { display: none; }
.steps li.done .step-n .icon { display: block; }
.steps li:not(.current) .conn-form, .steps li:not(.current) #emptyChoose { display: none; }
.conn-form { display: grid; gap: 4px; margin-top: 8px; }
.conn-form .row { flex-wrap: nowrap; }
.conn-form input { flex: 1; font-family: var(--mono); }
#emptyChoose { justify-self: start; margin-top: 8px; }

.result { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.banner {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex: none; flex-wrap: wrap;
}
.banner-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r); flex: none; background: var(--sunken); color: var(--ink-2); transition: background var(--t), color var(--t); }
.banner[data-tone="ok"] .banner-icon { background: var(--ok-soft); color: var(--ok); }
.banner[data-tone="warn"] .banner-icon { background: var(--warn-soft); color: var(--warn); }
.banner[data-tone="bad"] .banner-icon { background: var(--bad-soft); color: var(--bad); }
.banner[data-tone="busy"] .banner-icon { background: var(--brand-soft); color: var(--brand); }
.banner[data-tone="busy"] .banner-icon svg { animation: spin 1s linear infinite; }
.banner[data-tone="warn"], .banner[data-tone="bad"] { box-shadow: inset 2px 0 0 var(--warn); }
.banner[data-tone="bad"] { box-shadow: inset 2px 0 0 var(--bad); }
.banner-text { display: grid; gap: 2px; min-width: 0; flex: 1 1 280px; }
.banner-text h2 { font-size: var(--fs-lg); font-weight: 600; outline: none; }
.banner-text h2:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.banner-text p { color: var(--ink-2); font-size: var(--fs-sm); }
.evidence-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.sm-link { font-size: var(--fs-xs); }
.evidence { font: var(--fs-xs) / var(--lh) var(--mono); color: var(--ink-2) !important; }
.checks-box summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; font-size: var(--fs-xs); font-weight: 600; color: var(--ok); border-radius: var(--r-sm); }
.checks-box summary::-webkit-details-marker { display: none; }
.checks-box summary::before { content: "✓" / ""; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--ok-soft); font-size: 10px; }
.checks-box.has-fail summary { color: var(--warn); }
.checks-box.has-fail summary::before { content: "!" / ""; background: var(--warn-soft); }
.checks-box summary::after { content: "Show" / ""; font-weight: 500; color: var(--ink-2); text-decoration: underline; text-underline-offset: 2px; }
.checks-box[open] summary::after { content: "Hide" / ""; }
.stage.no-result { grid-template-columns: auto minmax(0, 1fr) 0 0; }
.stage.no-result .inspector, .stage.no-result .resizer { display: none; }
.checks { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 0; padding: 0; list-style: none; }
.check { display: inline-flex; align-items: center; gap: 4px; min-height: 20px; padding: 0 6px; border-radius: var(--r-sm); font-size: var(--fs-xs); background: var(--ok-soft); color: var(--ok); }
.check.fail { background: var(--warn-soft); color: var(--warn); }
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.bar { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; overflow: hidden; opacity: 0; transition: opacity var(--t); }
.banner[data-tone="busy"] .bar { opacity: 1; }
.bar::before { content: ""; position: absolute; inset: 0; width: 30%; background: var(--brand); animation: indeterminate 1.4s var(--ease) infinite; }
@keyframes indeterminate { from { transform: translateX(-100%); } to { transform: translateX(400%); } }
.retention, .reconnect, .review-steps {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 20px; font-size: var(--fs-sm); color: var(--ink-2);
  background: var(--surface); border-bottom: 1px solid var(--line); flex: none;
}
.retention.warn { color: var(--warn); background: var(--warn-soft); }
.reconnect { background: var(--bad-soft); color: var(--ink); padding: 10px 20px; }
.reconnect .conn-form { margin: 0; flex: 1 1 320px; }
.reconnect-text { flex: 1 1 240px; }
.review-steps ol { display: flex; gap: 20px; margin: 0; padding: 0; list-style: none; counter-reset: rs; flex-wrap: wrap; }
.review-steps li { counter-increment: rs; display: inline-flex; align-items: center; gap: 6px; }
.review-steps li::before { content: counter(rs); display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--field); font: 600 10px/1 var(--mono); }
.review-steps li.done { color: var(--ok); }
.review-steps li.done::before { content: "✓" / ""; background: var(--ok-soft); border-color: transparent; }
.result.running.has-previous .stage { opacity: 0.55; transition: opacity var(--t); }
.result.running.has-previous #paneResult::after, .result.running.has-previous #paneStack::after {
  content: "Previous version · generating…"; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 3;
  padding: 2px 8px; border-radius: 999px; font-size: var(--fs-xs); background: var(--raised); color: var(--ink-2); box-shadow: var(--shadow-sm);
}

.toolbar {
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; flex: none;
  padding: 6px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.spacer { flex: 1; }
.overlay-ctl { display: inline-flex; align-items: center; gap: 8px; }
.overlay-ctl input[type="range"] { width: 96px; }
.stepper, .pager { display: inline-flex; align-items: center; gap: 2px; }
.stepper-label { min-width: 96px; text-align: center; font-size: var(--fs-xs); color: var(--ink-2); }
.pager + .pager { padding-left: 8px; border-left: 1px solid var(--line); }

/* --- stage: viewer + inspector --------------------------------------------------------------- */
.stage { flex: 1; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) 6px var(--inspector-w); transition: opacity var(--t); }
.stage > .viewer { grid-column: 2; grid-row: 1; }
.stage > .resizer { grid-column: 3; grid-row: 1; }
.stage > .inspector { grid-column: 4; grid-row: 1; }
.stage.no-inspector { grid-template-columns: auto minmax(0, 1fr) 0 0; }
.stage.no-inspector .inspector, .stage.no-inspector .resizer { display: none; }
.viewer { position: relative; min-height: 240px; display: grid; gap: 1px; background: var(--line); min-width: 0; }
.viewer[data-mode="split"] { grid-template-columns: 1fr 1fr; }
.viewer[data-mode="split"] #paneStack,
.viewer[data-mode="swipe"] #paneOriginal, .viewer[data-mode="swipe"] #paneResult,
.viewer[data-mode="overlay"] #paneOriginal, .viewer[data-mode="overlay"] #paneResult,
.viewer[data-mode="original"] #paneResult, .viewer[data-mode="original"] #paneStack,
.viewer[data-mode="result"] #paneOriginal, .viewer[data-mode="result"] #paneStack { display: none; }
.pane { position: relative; min-width: 0; min-height: 0; background: var(--canvas); display: flex; flex-direction: column; }
.pane-tag {
  position: absolute; z-index: 2; top: 8px; left: 12px; display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 8px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; pointer-events: none;
  background: color-mix(in oklch, var(--raised) 92%, transparent); color: var(--ink-2); box-shadow: var(--shadow-sm);
}
.pane-tag.test { color: var(--test-ink); }
.pane-tag.test::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--test); }
.pane-tag.right { left: auto; right: 12px; }
.pane-tag.outdated { left: auto; right: 12px; color: var(--warn); }
.scroller { flex: 1; overflow: auto; padding: 40px 20px 24px; min-height: 0; scrollbar-width: thin; outline: none; }
.scroller:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.scroller.pannable { cursor: grab; }
.scroller.panning { cursor: grabbing; user-select: none; }
.page {
  position: relative; margin: 0 auto; width: 100%;
  background: var(--paper); box-shadow: var(--shadow-page); border-radius: var(--r-paper); line-height: 0;
}
.page img { display: block; width: 100%; height: auto; border-radius: var(--r-paper); user-select: none; -webkit-user-drag: none; }
.page img.in { animation: fade-in var(--t); }
@keyframes fade-in { from { opacity: 0.4; } }
.page.loading img { opacity: 0.5; transition: opacity var(--t); }
.page .placeholder {
  display: grid; place-items: center; align-content: center; gap: 12px; aspect-ratio: 1 / 1.414; line-height: var(--lh); padding: 16px;
  text-align: center; color: oklch(45% 0.012 255); font-size: var(--fs-sm); background: var(--paper);
}
.page .placeholder.busy { background: linear-gradient(90deg, var(--paper), oklch(93% 0.004 255), var(--paper)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.marks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.marks polygon { pointer-events: visiblePainted; cursor: pointer; fill: var(--paper-mark-fill); stroke: var(--paper-mark-ink); stroke-width: 1.5; stroke-opacity: 0.85; vector-effect: non-scaling-stroke; transition: fill var(--t-fast), opacity var(--t-fast); }
.marks polygon.erase { fill: none; stroke-dasharray: 4 4; }
.marks polygon.hover { fill: var(--paper-mark-flash); stroke-width: 2.5; }
.marks.has-selection polygon:not(.selected) { opacity: 0.35; }
.marks polygon.selected { fill: var(--paper-mark-flash); stroke-width: 3; stroke-opacity: 1; }
.marks polygon.pulse { animation: pulse-mark 1.2s var(--ease) 2; }
@keyframes pulse-mark { 50% { stroke-width: 6; } }
.viewer.no-marks .marks { display: none; }
/* Flags (design-flag-not-block D7): drawn on paper, so the same in both themes;
   red / orange / blue, never the amber that means "changed". */
.marks polygon.flag { fill: oklch(60% 0.2 25 / 0.14); stroke: oklch(52% 0.21 25); stroke-width: 2; stroke-dasharray: 6 3; stroke-opacity: 1; }
.marks polygon.flag.warning { fill: oklch(70% 0.17 50 / 0.16); stroke: oklch(58% 0.17 50); }
.marks polygon.flag.info { fill: oklch(65% 0.13 250 / 0.12); stroke: oklch(52% 0.15 250); }
.marks polygon.flag.selected { stroke-width: 4; fill-opacity: 0.4; }
.tip {
  position: absolute; z-index: 5; left: var(--x, 0); top: var(--y, 0); max-width: 280px; display: grid; gap: 2px;
  padding: 6px 10px; border-radius: var(--r); background: var(--raised); color: var(--ink); box-shadow: var(--shadow-pop);
  font-size: var(--fs-xs); line-height: 1.4; pointer-events: none;
}
.tip span { font-family: var(--mono); color: var(--ink-2); overflow-wrap: anywhere; }

.stack { display: grid; touch-action: none; }
.stack .layer { grid-area: 1 / 1; position: relative; }
.stack.swipe .top { clip-path: inset(0 0 0 var(--split, 50%)); }
.stack.swipe.vertical .top { clip-path: inset(var(--split, 50%) 0 0 0); }
.stack.overlay .top { opacity: var(--opacity, 0.5); }
.viewer.difference .stack.overlay .top { opacity: 1; mix-blend-mode: difference; }
.stack.flicker .top { clip-path: none; opacity: 1; mix-blend-mode: normal; }
.stack.swipe.near, .stack.swipe.dragging { cursor: ew-resize; }
.stack.swipe.vertical.near, .stack.swipe.vertical.dragging { cursor: ns-resize; }
.handle { grid-area: 1 / 1; position: relative; z-index: 2; left: var(--split, 50%); width: 0; outline: none; }
.handle::before { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: var(--paper-handle); box-shadow: 0 0 0 1px var(--paper); }
.stack.vertical .handle { left: 0; top: var(--split, 50%); width: 100%; height: 0; }
.stack.vertical .handle::before { top: -1px; bottom: auto; left: 0; right: 0; width: auto; height: 2px; }
.knob {
  position: sticky; top: calc(50% - 16px); display: block; width: 32px; height: 32px; margin: 0 0 0 -16px;
  border-radius: 50%; background: var(--paper-handle); border: 2px solid var(--paper); box-shadow: var(--shadow-sm); transition: transform var(--t-fast);
}
.stack.vertical .knob { position: absolute; left: 50%; top: -16px; margin: 0; }
.knob::before, .knob::after { content: ""; position: absolute; top: 11px; width: 6px; height: 6px; border-left: 2px solid var(--paper); border-bottom: 2px solid var(--paper); }
.knob::before { left: 7px; transform: rotate(45deg); }
.knob::after { right: 7px; transform: rotate(-135deg); }
.stack.near .knob, .stack.dragging .knob { transform: scale(1.12); }
.handle:focus-visible .knob { outline: 2px solid var(--paper-focus-a); outline-offset: 2px; box-shadow: 0 0 0 6px var(--paper-focus-b); }

.resizer { cursor: col-resize; background: var(--line); position: relative; outline: none; }
.resizer::after { content: ""; position: absolute; inset: 0 -3px; }
.resizer:hover, .resizer.dragging, .resizer:focus-visible { background: var(--brand); }
.inspector { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.tabs { display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--line); flex: none; }
.tabs [role="tab"] {
  all: unset; display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; border-radius: var(--r-sm) var(--r-sm) 0 0;
}
.tabs [role="tab"]:hover { color: var(--ink); background: var(--sunken); }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--brand); }
.tabs [role="tab"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tabpanel { flex: 1; overflow: auto; min-height: 0; padding: 12px 12px 20px; display: flex; flex-direction: column; gap: 8px; outline: none; }
.tabpanel:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.panel-note { font-size: var(--fs-xs); color: var(--ink-2); }
.panel-note:empty { display: none; }
.filter { position: relative; }
.filter .icon { position: absolute; left: 8px; top: 8px; color: var(--ink-3); }
.filter input { padding-left: 28px; min-height: 30px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; }
.group-head { position: sticky; top: -12px; z-index: 1; padding: 8px 4px 4px; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); background: var(--surface); text-transform: uppercase; letter-spacing: 0.06em; }
.rows .row {
  all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 8px;
  border-radius: var(--r); cursor: pointer; transition: background var(--t-fast);
}
.rows .row:hover, .rows .row.hover { background: var(--sunken); }
.rows .row[aria-current="true"] { background: var(--brand-soft); box-shadow: inset 2px 0 0 var(--brand); }
.rows .row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.swatch { width: 12px; height: 12px; border-radius: 2px; flex: none; background: var(--paper-mark-fill); box-shadow: inset 0 0 0 1.5px var(--paper-mark-ink); }
.row.erase .swatch { background: transparent; box-shadow: none; border: 1.5px dashed var(--ink-3); }
.row.flag .swatch { border-radius: 50%; background: oklch(52% 0.21 25); box-shadow: none; }
.row.flag.warning .swatch { background: oklch(58% 0.17 50); }
.row.flag.info .swatch { background: oklch(52% 0.15 250); }
.row-main { display: grid; min-width: 0; flex: 1; gap: 1px; }
.row-name { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.row-value { font: var(--fs-xs) / 1.4 var(--mono); color: var(--ink-2); overflow-wrap: anywhere; }
.row.flag .row-value { font-family: var(--sans); font-size: var(--fs-sm); }
.row-value.muted { font-family: var(--sans); font-style: italic; }
.row-page { font: var(--fs-xs) var(--mono); color: var(--ink-3); }
.empty-row { padding: 12px 8px; color: var(--ink-2); font-size: var(--fs-sm); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crop { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r); background: var(--sunken); }
.crop figure { margin: 0; display: grid; gap: 4px; }
.crop figcaption { font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); }
.crop canvas { width: 100%; height: auto; background: var(--paper); border-radius: var(--r-sm); box-shadow: var(--shadow-sm); }
.tech-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.tech pre { margin: 0; padding: 8px 12px; max-height: 360px; overflow: auto; background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r); font: var(--fs-xs) / 1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* --- toasts, dialogs ------------------------------------------------------------------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; border-radius: var(--r-lg);
  background: var(--ink); color: var(--surface); box-shadow: var(--shadow-pop); font-size: var(--fs-sm); animation: rise var(--t);
}
.toast .btn:not(.ghost) { background: transparent; color: inherit; border-color: color-mix(in oklch, currentColor 45%, transparent); }
.toast .btn.ghost { color: inherit !important; opacity: 0.8; }
.toast-text { flex: 1; }
.toast.leaving { opacity: 0; transition: opacity var(--t); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.dialog {
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; width: min(440px, calc(100vw - 32px));
  background: var(--raised); color: var(--ink); box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: var(--backdrop); }
.dialog form { display: grid; gap: 12px; }
.dialog h2 { font-size: var(--fs-lg); font-weight: 600; }
.dialog p { color: var(--ink-2); font-size: var(--fs-sm); }
.dialog.wide { width: min(640px, calc(100vw - 32px)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.keys-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.keys-list h3 { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); margin-bottom: 6px; }
.keys-list dl { display: grid; grid-template-columns: 56px 1fr; gap: 6px 8px; margin: 0; font-size: var(--fs-sm); align-items: center; }
.keys-list dd { margin: 0; }
.palette { padding: 0; width: min(560px, calc(100vw - 32px)); margin-top: 12vh; }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; min-height: 48px; padding: 0 16px; font-size: var(--fs-lg); background: transparent; }
.palette input:focus-visible { outline: none; }
.palette ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.palette li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: var(--r); cursor: pointer; font-size: var(--fs-sm); }
.palette li[aria-selected="true"] { background: var(--brand-soft); color: var(--brand-ink); }

/* drop anywhere (U37) */
body.dropping::after {
  content: "Drop to use this document"; position: fixed; inset: 12px; z-index: 60; display: grid; place-items: center;
  border: 2px dashed var(--brand); border-radius: 12px; background: color-mix(in oklch, var(--brand-soft) 85%, transparent);
  color: var(--brand-ink); font-size: var(--fs-xl); font-weight: 600; pointer-events: none;
}

/* focus view (U49) */
body.focus-mode .appbar, body.focus-mode .panel, body.focus-mode .banner-text p,
body.focus-mode .checks-box, body.focus-mode .retention, body.focus-mode .review-steps { display: none !important; }
body.focus-mode .shell, body.focus-mode .shell.collapsed { grid-template-columns: 1fr; }
body.focus-mode .banner { min-height: 0; padding: 6px 16px; }

@media (forced-colors: active) {
  .seg button[aria-checked="true"], .tabs [role="tab"][aria-selected="true"] { outline: 2px solid CanvasText; }
  .track, .dot, .swatch { border: 1px solid CanvasText; forced-color-adjust: none; }
  .toggle input:checked + .track { background: Highlight; }
  .track::after { background: CanvasText; }
  .marks polygon { stroke: Highlight; forced-color-adjust: none; }
  .marks polygon.erase { stroke: CanvasText; stroke-dasharray: 4 4; }
  .marks polygon.selected { stroke-width: 5; }
  .handle::before, .knob { background: Highlight; forced-color-adjust: none; }
  .rows .row[aria-current="true"] { outline: 2px solid Highlight; }
  .btn:disabled, .btn[aria-disabled="true"] { color: GrayText; border-color: GrayText; }
}

/* --- narrow -------------------------------------------------------------------------------- */
@media (max-width: 1180px) {
  .stage, .stage.no-inspector, .stage.no-result { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(360px, 1fr) auto; }
  .stage > .inspector { grid-column: 1 / -1; grid-row: 2; }
  .stage .resizer { display: none; }
  .inspector { border-top: 1px solid var(--line); max-height: 45vh; }
  .stage.no-inspector, .stage.no-result { grid-template-rows: 1fr 0; }
}
@media (max-width: 960px) {
  body { display: block; height: auto; }
  .shell, .shell.collapsed, .shell.wide-form { display: block; }
  .shell.collapsed .panel-body { display: block; }
  .rail, #collapse { display: none !important; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .panel-body { overflow: visible; }
  .viewer { min-height: 70vh; }
  .viewer[data-mode="split"] { grid-template-columns: 1fr; }
  .appbar { min-height: 48px; flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .appbar-end { flex-wrap: wrap; row-gap: 6px; }
  #keysBtn { display: none; } /* shortcuts need a keyboard; the ? key still opens the list */
  .local span { display: none; }
  .local { padding: 0 8px; }
  .block, .actions { padding-left: 16px; padding-right: 16px; }
  .banner, .toolbar, .retention, .reconnect, .review-steps { padding-left: 16px; padding-right: 16px; }
  .seg-text { display: none; }
  .seg.view button { padding: 0 8px; }
  .req { grid-template-columns: 1fr; gap: 4px; }
  .scroller { padding: 36px 12px 16px; }
  .toolbar .stepper-label { min-width: 72px; }
}
@media (max-width: 520px) {
  .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .brand h1 { font-size: var(--fs-sm); }
  .rule-row { grid-template-columns: 1fr; }
  .banner-actions { width: 100%; justify-content: flex-start; }
}

/* --- UI round 3 ------------------------------------------------------------------------------ */


/* minimap (U62) */
.minimap { position: absolute; right: 12px; bottom: 12px; z-index: 3; width: 120px; padding: 0; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--paper); box-shadow: var(--shadow-pop); overflow: hidden; cursor: crosshair; touch-action: none; }
.minimap img { display: block; width: 100%; height: auto; }
.minimap svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.minimap .view { fill: oklch(52% 0.1 185 / 0.12); stroke: var(--paper-handle); stroke-width: 2; vector-effect: non-scaling-stroke; }
.minimap .dot { fill: var(--paper-mark-ink); }
.minimap .dot.erase { fill: oklch(55% 0.01 255); }
.minimap .dot.flag { fill: oklch(55% 0.17 40); }
.viewer.no-marks .minimap .dot { display: none; }

/* relevance sections and field search (U86) */
.field-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 8px 0 12px; }
.field-tools .filter { flex: 1 1 180px; }
.field-tools .filter input { width: 100%; }
.rel { margin: 0 0 16px; }
.rel-head, details.rel > summary { display: flex; align-items: baseline; gap: 4px; margin: 0 0 8px; font-size: var(--fs-md); font-weight: 600; color: var(--ink); }
details.rel > summary { cursor: pointer; }
.rel-progress { font-weight: 400; font-size: var(--fs-xs); color: var(--ink-2); font-family: var(--mono); }
.rel[data-rel="needed"] > .rel-head { color: var(--brand-ink); }
.rel[data-rel="other"] { color: var(--ink-2); }
.unused-note { display: block; font-size: var(--fs-xs); color: var(--warn); line-height: var(--lh); }

/* grouped requirements (U87) */
.req-set { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-right: 8px; }
.req-group { font-size: var(--fs-xs); color: var(--ink-2); font-weight: 600; }
.chip.more { background: transparent; border-style: dashed; color: var(--brand-ink); cursor: pointer; }

/* resume card (U69) */
.resume { max-width: 520px; margin: 0 auto 20px; padding: 12px 16px; border: 1px solid var(--test); border-radius: var(--r-lg); background: var(--test-soft); color: var(--ink); text-align: left; }
.resume p { margin: 0 0 8px; }

/* not used (unused_reasons) */
.unused { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.unused h3 { margin: 0 0 4px; font-size: var(--fs-sm); }
.unused ul { margin: 4px 0 0; display: grid; gap: 6px; font-size: var(--fs-sm); }
.unused-why { color: var(--ink-2); }

/* variants dialog (U70) */
.variant-fields { border: 0; padding: 0; margin: 12px 0; display: grid; gap: 6px; }
.variant-fields legend { font-size: var(--fs-sm); font-weight: 600; margin-bottom: 4px; }
.check-row { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); }
#notifyBtn[aria-pressed="true"] { color: var(--brand-ink); background: var(--brand-soft); }

.lib-banner { align-items: flex-start; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.lib-reasons { margin-top: 6px; color: var(--ink); }
.lib-result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-notes { font-size: var(--fs-sm); color: var(--ink-2); }
.lib-notes summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; color: var(--ink); }
.lib-notes ul { margin-top: 8px; }

/* --- studio-library-first: header, tabs, library, notice (T-C, T-D, T-E) -------------------- */
.mark { width: 28px; height: 28px; flex: none; }
.mark-bg { fill: var(--brand); }
.mark-page { fill: var(--on-brand); stroke: none; }
.mark-line { fill: none; stroke: var(--brand); stroke-width: 1.5; stroke-linecap: round; }
.brand h1 { font-size: var(--fs-lg); font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
.test-badge {
  display: inline-flex; align-items: center; gap: 2px; height: 28px; padding: 0 2px 0 10px; border-radius: 999px;
  border: 1px solid var(--warn-line); background: var(--warn-soft); color: var(--warn);
  font: 600 var(--fs-xs) / 1 var(--sans); letter-spacing: 0.01em; white-space: nowrap;
}
.test-badge-info {
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: inherit; cursor: pointer; transition: background var(--t-fast);
}
.test-badge-info:hover { background: color-mix(in oklch, var(--warn) 16%, transparent); }
.test-badge-info .icon { width: 14px; height: 14px; stroke-width: 2; }
.appbar-sep { width: 1px; height: 20px; background: var(--line); }

/* set-up tabs: Bill library first (WAI-ARIA tabs) */
.setup-tabs {
  position: sticky; top: 0; z-index: 3; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 8px 12px 0; background: var(--surface); border-bottom: 1px solid var(--line);
}
.setup-tabs [role="tab"] {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 6px; white-space: nowrap;
  border: 0; border-bottom: 2px solid transparent; border-radius: var(--r) var(--r) 0 0; margin-bottom: -1px;
  background: transparent; color: var(--ink-2); font: 500 var(--fs-md) / 1.2 var(--sans); cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.setup-tabs [role="tab"]:hover { color: var(--ink); background: var(--sunken); }
.setup-tabs [role="tab"][aria-selected="true"] { color: var(--brand-ink); font-weight: 600; border-bottom-color: var(--brand); }
.setup-tabs [role="tab"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.setup-tabs .icon { opacity: 0.85; }
.tabpanel-setup { display: flex; flex-direction: column; min-height: calc(100% - 53px); }
.tabpanel-setup > form { flex: 1; }

/* library list: compact cards */
.lib-pick { display: grid; gap: 12px; }
.lib-pick .help { margin: -4px 0 0; }
.filter { position: relative; }
.filter .filter-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.filter-icon + input { padding-left: 32px; }
.lib-list { display: grid; align-content: start; gap: 12px; max-height: 360px; overflow: auto; margin: 0 -4px; padding: 2px 4px; }
.lib-loading { color: var(--ink-2); font-size: var(--fs-sm); padding: 8px 0; }
.lib-group { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.lib-group .group-head { display: flex; align-items: center; gap: 6px; margin: 0 0 2px; }
.lib-item {
  position: relative; display: grid; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); cursor: pointer; color: var(--ink);
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
.lib-item:hover { border-color: var(--line-strong); background: var(--sunken); }
.lib-item input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.lib-item:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 1px var(--brand); }
.lib-item:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.lib-item-name { min-width: 0; font-size: var(--fs-md); font-weight: 600; line-height: var(--lh-tight); }
.lib-item-meta { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tag {
  display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--sunken); color: var(--ink-2); font-weight: 600; font-size: var(--fs-xs);
}
.lib-item:has(input:checked) .tag { border-color: var(--brand-line); background: var(--surface); color: var(--brand-ink); }
.lib-empty { display: grid; gap: 6px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: var(--r); font-size: var(--fs-sm); color: var(--ink-2); }
.lib-empty strong { color: var(--ink); }
.lib-down { display: grid; gap: 8px; justify-items: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--bad-soft); font-size: var(--fs-sm); color: var(--ink); }
.lib-down-title { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--bad); }

/* library form */
.lib-form { display: flex; flex-direction: column; }
.lib-form .block { display: grid; gap: 16px; }
.lib-form .block .help { margin: 0; }
.lib-chosen { display: grid; gap: 2px; padding: 10px 12px; border-radius: var(--r); background: var(--sunken); }
.lib-chosen-name { font-size: var(--fs-lg); font-weight: 600; color: var(--ink); line-height: var(--lh-tight); }
.lib-grid { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lib-grid legend { padding: 0; margin-bottom: 8px; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.lib-span { grid-column: 1 / -1; margin: -4px 0 0; }
.lib-more { margin: 0; border: 1px solid var(--line); border-radius: var(--r-lg); padding: 0 12px; background: var(--surface); }
.lib-more[open] { padding-bottom: 12px; }
.lib-more summary { min-height: 44px; }
.lib-more > .hint { display: block; margin: -4px 0 12px; }
.lib-err { padding: 10px 12px; border-radius: var(--r); background: var(--bad-soft); border: 1px solid color-mix(in oklch, var(--bad) 35%, transparent); }
.lib-err-title { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; font-size: var(--fs-sm); font-weight: 600; color: var(--bad); }
.lib-err .plain { color: var(--ink); }
.lib-err .link { color: var(--ink); }

/* workspace: empty states and the library outcome */
.empty { margin: auto; width: min(520px, 100%); padding: 32px 24px; color: var(--ink-2); }
.lib-start { text-align: center; display: grid; justify-items: center; gap: 8px; }
.empty-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 8px; border-radius: 50%; background: var(--sunken); border: 1px solid var(--line); color: var(--ink-3); }
.empty h2 { font-size: var(--fs-lg); font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.lib-start p { max-width: 36ch; }
.lib-result { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 24px; outline: none; overflow: auto; }
.lib-result[hidden] { display: none; }
.lib-result[aria-busy="true"] > * { opacity: 0.5; transition: opacity var(--t); }
.lib-banner { align-items: flex-start; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.lib-banner .banner-text h2 { font-size: var(--fs-lg); }
.lib-reasons { margin-top: 6px; color: var(--ink); }
.lib-notes { margin: 0; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); font-size: var(--fs-sm); color: var(--ink-2); }
.lib-notes[open] { padding-bottom: 12px; }
.lib-preview { flex: 1; width: 100%; min-height: 520px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--paper); box-shadow: var(--shadow-page); }

/* first-open notice: only "Got it" closes it */
.notice { width: min(460px, calc(100vw - 32px)); padding: 24px; gap: 12px; }
.notice[open] { display: grid; }
.notice-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--warn-soft); border: 1px solid var(--warn-line); color: var(--warn); }
.notice h2 { font-size: var(--fs-xl); font-weight: 600; }
.notice-body { display: grid; gap: 8px; }
.notice-body p { color: var(--ink-2); font-size: var(--fs-md); }
.notice-body p:first-child { color: var(--ink); font-weight: 500; }
.notice .row { margin-top: 8px; }
.notice .btn.primary { min-width: 112px; min-height: 36px; }

@media (max-width: 960px) {
  .setup-tabs { position: static; }
  .lib-list { max-height: 300px; }
  .lib-result { padding: 16px; }
  .lib-preview { min-height: 420px; }
  .appbar-sep, .local { display: none; }
}
@media (max-width: 520px) {
  .brand { flex-wrap: wrap; row-gap: 4px; }
  .brand h1 { font-size: var(--fs-md); }
  .setup-tabs [role="tab"] { font-size: var(--fs-sm); gap: 6px; }
  .lib-grid { grid-template-columns: 1fr; }
  .lib-banner { flex-direction: column; }
}

/* --- the phone layout (mobile spec, layout C) ------------------------------------------------
 * The mobile tokens, then the one phone block. Nothing above this line changes for the phone:
 * desktop and tablet pages stay pixel for pixel as they were. The block's query is the layout
 * module's PHONE_QUERY character for character (a static test checks): a narrow window, or a
 * large phone held sideways. Sheets are native modal dialogs (the top layer), so the z-index
 * tokens are only for the home's own layers.
 */
:root {
  --tap: 44px; /* the smallest tappable control, both ways */
  --tap-lg: 48px; /* the one primary action per screen */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --sheet-gap: 48px; /* the page left showing above a sheet */
  --bar: 56px; /* the header, a sheet's head (mobile 12, P11) */
  --row: 72px; /* a summary card row */
  --tile: 36px; /* an icon tile */
  --tile-sm: 32px; /* a small icon tile: the result's outcome, the last bill */
  --icon-md: 20px;
  --icon-lg: 24px;
  --t-sheet: 300ms var(--ease); /* a sheet rising and leaving (mobile 12; ADR 0006) */
  --z-bar: 20;
  --go: var(--brand); /* the phone's filled action, resting and under a mouse (mobile 12, P21) */
  --go-hover: var(--brand-hover);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --go: var(--brand-hover); --go-hover: var(--brand-press); }
}
:root[data-theme="dark"] { --go: var(--brand-hover); --go-hover: var(--brand-press); }
.toast-ico { display: none; } /* a bad toast's icon shows on phones only (mobile 12, P2) */
.lib-item-tick { display: none; } /* the chosen bill's check icon shows on phones only (mobile 12, P10) */
.about-label { display: none; }
.err-phone { display: none; } /* the error box's phone title (mobile 06) */
.go-busy { display: none; } /* the phone Generate's busy words (mobile 07) */

@media (max-width: 600px), (pointer: coarse) and (max-height: 500px) {
  /* 16 px field text: iOS Safari zooms the page into anything smaller */
  input, select, textarea, select.btn { font-size: var(--fs-lg); }

  /* the "For testing only · About" strip, then the short header: mark, title, menu */
  .appbar { flex-wrap: wrap; justify-content: flex-start; gap: 0; min-height: 0; padding: var(--safe-t) 0 0; }
  .brand { display: contents; }
  .test-badge {
    order: -1; flex: 1 0 100%; justify-content: center; gap: var(--s-1); height: auto; min-height: var(--tap);
    padding: 0 calc(var(--s-4) + var(--safe-r)) 0 calc(var(--s-4) + var(--safe-l));
    border-width: 0 0 1px; border-radius: 0; font-size: var(--fs-sm);
  }
  .test-badge-text::after { content: "\00a0·"; content: "\00a0·" / ""; } /* silent (mobile 12, P13) */
  .test-badge-info {
    width: auto; min-width: var(--tap); height: var(--tap); padding: 0 var(--s-2); border-radius: var(--r);
    color: var(--ink); font: 500 var(--fs-sm) / 1 var(--sans); text-decoration: underline; text-underline-offset: 2px;
  }
  .test-badge-info .icon { display: none; }
  .about-label { display: inline; }
  .appbar .mark { margin: 0 0 0 calc(var(--s-4) + var(--safe-l)); }
  .brand h1 {
    flex: 1 1 0; min-width: 0; margin-left: var(--s-3); font-size: var(--fs-lg);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .appbar-end { flex: none; flex-wrap: nowrap; gap: var(--s-1); min-height: var(--bar); padding-right: calc(var(--s-1) + var(--safe-r)); }
  #privacyBtn, #connPill, .appbar-sep, #keysBtn { display: none; }
  .menu-btn { width: var(--tap); min-height: var(--tap); }
  .menu-btn .icon { width: var(--icon-lg); height: var(--icon-lg); }
  /* hosted mode: Sign out stays in the header, a full-size button beside the menu */
  #signOut:not([hidden]) {
    display: inline-flex; flex: none; justify-content: center; height: auto; min-width: var(--tap); min-height: var(--tap);
    padding: 0 var(--s-3); border: 1px solid var(--field); border-radius: var(--r); background: transparent; color: var(--ink); font-size: var(--fs-md);
  }
  @media (hover: none) { #signOut:hover { border-color: var(--field); color: var(--ink); } }

  /* hosted mode: the sign-in message full width under the header, Sign in again across it */
  .signin-msg {
    flex-wrap: wrap; gap: var(--s-2) var(--s-3); font-size: var(--fs-md);
    padding: var(--s-3) calc(var(--s-4) + var(--safe-r)) var(--s-3) calc(var(--s-4) + var(--safe-l));
  }
  .signin-msg .signin-text { flex: 1 1 0; min-width: 0; }
  .signin-msg .btn { flex: 1 0 100%; justify-content: center; min-height: var(--tap); font-size: var(--fs-lg); }

  /* the status line: only while the connection is not fine */
  .phone-status {
    display: flex; align-items: center; gap: var(--s-2); margin: 0;
    padding: var(--s-2) calc(var(--s-4) + var(--safe-r)) var(--s-2) calc(var(--s-4) + var(--safe-l));
    background: var(--sunken); color: var(--ink-2); border-bottom: 1px solid var(--line); font: 500 var(--fs-sm) / 1.4 var(--sans);
  }
  .phone-status[data-state="ok"] { display: none; }
  .phone-status[data-state="busy"] .dot { background: var(--brand); animation: pulse 1s ease-in-out infinite; }
  .phone-status[data-state="bad"] { background: var(--bad-soft); color: var(--bad); }
  .phone-status[data-state="bad"] .dot { background: var(--bad); }

  /* toasts sit just above the Generate area (the layout module moves them into it), so they
     never cover Generate or the home indicator */
  .toasts { left: var(--s-4); right: var(--s-4); bottom: calc(var(--s-4) + var(--safe-b)); width: auto; }
  .go .toasts { position: absolute; bottom: calc(100% + var(--s-2)); left: calc(var(--s-4) + var(--safe-l)); right: calc(var(--s-4) + var(--safe-r)); }
  .toast .btn { min-width: var(--tap); min-height: var(--tap); } /* the action and Dismiss (mobile 12, Q6) */
  /* a button in a toast keeps the toast's own ink under a mouse (mobile 12, P3) */
  .toast .btn:hover:not(:disabled):not([aria-disabled="true"]) {
    background: color-mix(in oklch, currentColor 16%, transparent); border-color: color-mix(in oklch, currentColor 45%, transparent); color: inherit;
  }
  /* a failure toast: a bad bar on its edge and the alert icon (mobile 12, P2) */
  .toast.bad { box-shadow: inset var(--s-1) 0 0 var(--bad), var(--shadow-pop); }
  .toast.bad .toast-ico { display: block; color: var(--bad); }

  /* the filled action (mobile 12, P21, Q12): the phone's fill, and a busy one stays filled with
     the pressed shade (its words say it is busy) instead of the disabled grey */
  .btn.primary:not(:disabled):not([aria-disabled="true"]) { background: var(--go); border-color: var(--go); }
  .btn.primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--go-hover); border-color: var(--go-hover); }
  .btn.primary:active:not(:disabled):not([aria-disabled="true"]) { background: var(--brand-press); border-color: var(--brand-press); }
  .btn.primary[aria-busy="true"] { background: var(--brand-press); border-color: var(--brand-press); color: var(--on-brand); font-weight: 600; }

  /* pressed states, and no grey flash on a tap (mobile 12, P4) */
  .btn, .local, .link, .lib-item, .job-row, .test-badge-info, .seg button { -webkit-tap-highlight-color: transparent; }
  .job-row { transition: background var(--t-fast); }
  @media (hover: hover) { .job-row:hover { background: var(--sunken); } }

  /* a finger leaves no hover colour behind (mobile 12, Q10): on touch screens a tapped control
     keeps its resting look (pressed states above still show while the finger is down) */
  @media (hover: none) {
    .btn:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--surface); border-color: var(--field); }
    .btn.primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--go); border-color: var(--go); }
    .btn.ghost:hover:not(:disabled):not([aria-disabled="true"]) { background: transparent; border-color: transparent; color: var(--ink-2); }
    .lib-item:hover { border-color: var(--line); background: var(--surface); }
    .lib-item:has(input:checked):hover { border-color: var(--brand); background: var(--brand-soft); }
    .local:hover { border-color: var(--line); color: var(--ink-2); }
    .seg button:hover { color: var(--ink-2); background: transparent; }
    .test-badge-info:hover { background: transparent; }
    .link:hover { color: var(--brand-ink); }
  }
  /* pressed (after the resting rules above, so a press still shows on a touch screen) */
  .lib-item:active { border-color: var(--line-strong); background: var(--sunken); }
  .link:active { color: var(--brand-press); }
  .test-badge-info:active { background: color-mix(in oklch, var(--warn) 24%, transparent); }
  .seg button:active { background: var(--line); }

  /* group labels in the sheets (Dates, the bill groups) at label size, not hint size */
  dialog.sheet legend, dialog.sheet .group-head { font-size: var(--fs-sm); }

  /* bottom sheets: the sheet dialogs and the first-open notice rise from the bottom edge */
  dialog.sheet, dialog.notice {
    inset: auto 0 var(--vvb, 0px); margin: 0; width: 100%; max-width: 100%; max-height: calc(var(--vvh, 100dvh) - var(--sheet-gap));
    border: 0; border-top: 1px solid var(--line); border-radius: var(--r-lg) var(--r-lg) 0 0;
    background: var(--raised); color: var(--ink); box-shadow: var(--shadow-pop);
    overflow: auto; overscroll-behavior: contain;
    transition: transform var(--t-sheet), opacity var(--t-sheet); /* reduced motion keeps only the fade */
  }
  @starting-style {
    dialog.sheet[open], dialog.notice[open] { transform: translateY(100%); opacity: 0; }
    dialog.sheet[open]::backdrop, dialog.notice[open]::backdrop { opacity: 0; }
  }
  dialog.sheet::backdrop, dialog.notice::backdrop { background: var(--backdrop); transition: opacity var(--t-sheet); }
  /* leaving (mobile 12, Q11): where a closing dialog can stay on top while it goes (the overlay
     transition), the sheet slides back down and the backdrop fades, and taps already pass through
     to the page; elsewhere (Safari today) it closes at once, as before */
  @supports (overlay: auto) {
    dialog.sheet, dialog.notice {
      transition: transform var(--t-sheet), opacity var(--t-sheet),
        overlay var(--t-sheet) allow-discrete, display var(--t-sheet) allow-discrete;
    }
    dialog.sheet:not([open]), dialog.notice:not([open]) { transform: translateY(100%); opacity: 0; pointer-events: none; }
    dialog.sheet::backdrop, dialog.notice::backdrop {
      transition: opacity var(--t-sheet), overlay var(--t-sheet) allow-discrete, display var(--t-sheet) allow-discrete;
    }
    dialog.sheet:not([open])::backdrop, dialog.notice:not([open])::backdrop { opacity: 0; }
  }
  /* reduced motion: no sliding either way, only the fade (and no spinners: the words say it) */
  @media (prefers-reduced-motion: reduce) {
    dialog.sheet, dialog.notice { transition-property: opacity, overlay, display !important; }
    dialog.sheet:not([open]), dialog.notice:not([open]) { transform: none; }
    .home-progress-spin, .btn[aria-busy="true"]::before { display: none; }
  }
  dialog.sheet { padding: 0 0 var(--safe-b); }
  dialog.sheet[open] { display: flex; flex-direction: column; }
  #billSheet, #detailsSheet { height: calc(var(--vvh, 100dvh) - var(--sheet-gap)); }
  /* the page behind an open sheet stays still */
  :root:has(dialog.sheet[open], dialog.notice[open]) { overflow: hidden; }

  dialog.notice { padding: var(--s-5) calc(var(--s-4) + var(--safe-r)) calc(var(--s-4) + var(--safe-b)) calc(var(--s-4) + var(--safe-l)); }
  .notice .btn.primary { width: 100%; min-height: var(--tap-lg); font-size: var(--fs-lg); }

  .sheet-head {
    display: flex; align-items: center; gap: var(--s-2); flex: none; min-height: var(--bar);
    padding: 0 calc(var(--s-1) + var(--safe-r)) 0 calc(var(--s-4) + var(--safe-l)); border-bottom: 1px solid var(--line);
  }
  .sheet-head h2 { flex: 1; font-size: var(--fs-lg); font-weight: 600; }
  .sheet-head .icon-btn { width: var(--tap); min-height: var(--tap); }
  .sheet-body {
    flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: var(--s-5);
    padding: var(--s-4) calc(var(--s-4) + var(--safe-r)) var(--s-4) calc(var(--s-4) + var(--safe-l));
  }

  /* the menu sheet: the theme control (moved in), the privacy and connection copies, About */
  .menu-part { display: grid; gap: var(--s-2); }
  .menu-part h3 { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
  .menu-lead { font-size: var(--fs-md); font-weight: 600; color: var(--ink); }
  .menu-theme .seg.theme { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
  .menu-theme .seg.theme button { width: auto; height: auto; min-height: var(--tap); gap: var(--s-2); font-size: var(--fs-md); }
  .menu-theme .seg.theme .sr-only { /* the option names show here */
    position: static !important; width: auto !important; height: auto !important; margin: 0 !important;
    overflow: visible !important; clip-path: none !important;
  }
  .menu-theme .seg.theme button[aria-checked="true"] { background: var(--brand-soft); color: var(--brand-ink); box-shadow: inset 0 0 0 1px var(--brand-line); } /* mobile 12, P19 */
  #menuAbout { min-height: var(--tap); justify-content: flex-start; padding: 0; color: var(--brand-ink); } /* a link row (mobile 12, P20) */

  /* the home: the title, the red box, the summary card, then Generate held at the bottom. The
     desktop set-up panel and workspace (and the skip link to it) are not part of the phone page.
     Only the home's middle scrolls, and only when it must; it ends above the Generate area. */
  .skip, #shell { display: none; }
  body { display: flex; flex-direction: column; height: 100%; }
  .home { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .home-main {
    flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain;
    display: grid; grid-auto-rows: max-content; align-content: start; gap: var(--s-4); /* rows never squeeze */
    padding: var(--s-4) calc(var(--s-4) + var(--safe-r)) var(--s-4) calc(var(--s-4) + var(--safe-l));
  }
  .home-head { display: grid; gap: var(--s-1); } /* the title, and in hosted mode the note under it (mobile 12, P12) */
  .home-title { font-size: var(--fs-xl); font-weight: 600; }
  .home-note { font-size: var(--fs-sm); color: var(--ink-2); }
  .home-err { display: contents; }
  .home .lib-err { padding: var(--s-3) var(--s-4) var(--s-1); }
  .home .lib-err-title { margin: 0; font-size: var(--fs-md); }
  .lib-err-title .err-wide { display: none; }
  .lib-err-title .err-phone { display: inline; }
  .home .lib-err .plain { padding: 0; list-style: none; gap: 0; font-size: var(--fs-md); }
  .home .lib-err .link { display: flex; align-items: center; min-height: var(--tap); }

  .job { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
  .job-row {
    display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: var(--row); margin: 0;
    padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4); border: 0; background: transparent;
    color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  }
  .job-row + .job-row { border-top: 1px solid var(--line); }
  .job-row:active { background: var(--sunken); }
  .job-row.picked { animation: fill-flash 600ms var(--ease) 300ms backwards; } /* a bill was just picked (mobile 12, P5) */
  .job-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
  .icon.md { width: var(--icon-md); height: var(--icon-md); }
  .job-ico { display: grid; place-items: center; width: var(--tile); height: var(--tile); flex: none; border-radius: var(--r); background: var(--sunken); color: var(--ink-2); }
  .job-alert { display: none; }
  .job-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
  .job-k { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
  .job-v { font-size: var(--fs-lg); font-weight: 600; line-height: var(--lh-tight); overflow-wrap: anywhere; }
  .job-s { font-size: var(--fs-sm); color: var(--ink-2); overflow-wrap: anywhere; }
  .job-s:empty { display: none; }
  .job-go { color: var(--ink-3); }
  .job-row[data-state="empty"] .job-v { color: var(--ink-2); font-weight: 500; }
  #rowDetails[data-state="empty"] .job-v { color: var(--brand-ink); font-weight: 600; } /* the next step (mobile 12, Q17) */
  .job-row[data-state="set"] .job-ico { background: var(--brand-soft); color: var(--brand-ink); }
  .job-row[data-state="bad"] { box-shadow: inset 3px 0 0 var(--bad); }
  .job-row[data-state="bad"] .job-ico { background: var(--bad-soft); color: var(--bad); }
  .job-row[data-state="bad"] .job-icon { display: none; }
  .job-row[data-state="bad"] .job-alert { display: block; }
  .job-row[data-state="bad"] .job-s { color: var(--bad); font-weight: 500; }
  .home-retry { justify-self: start; min-height: var(--tap); font-size: var(--fs-md); }

  .go {
    flex: none; display: grid; gap: var(--s-2); z-index: var(--z-bar); background: var(--bg); border-top: 1px solid var(--line);
    padding: var(--s-3) calc(var(--s-4) + var(--safe-r)) calc(var(--s-3) + var(--safe-b)) calc(var(--s-4) + var(--safe-l));
  }
  .go { position: relative; }
  .go-btn { width: 100%; min-height: var(--tap-lg); font-size: var(--fs-lg); }

  /* generating (mobile 07): the button keeps its place and says so (the spinner is the busy
     button's own), the card dims, and the progress card names the bill */
  .go-btn[aria-busy="true"] > .icon, .go-btn[aria-busy="true"] .go-idle { display: none; }
  .go-btn[aria-busy="true"] .go-busy { display: inline; }
  .home[data-busy="true"] .job { opacity: 0.5; transition: opacity var(--t); }
  .home-progress {
    display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4);
    border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  }
  .home-progress-spin {
    flex: none; width: var(--icon-md); height: var(--icon-md); border-radius: 50%;
    border: 2px solid var(--brand); border-right-color: transparent; animation: spin 0.7s linear infinite;
  }
  .home-progress-text { display: grid; gap: 2px; min-width: 0; }
  .home-progress-title { font-size: var(--fs-md); font-weight: 600; overflow-wrap: anywhere; }
  .home-progress-sub { font-size: var(--fs-sm); color: var(--ink-2); }
  /* the last bill, offered after the layout changed (it reopens the same result) */
  .home-last { min-height: var(--tap); padding: var(--s-1) var(--s-3); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
  .home-last .job-ico { width: var(--tile-sm); height: var(--tile-sm); background: var(--brand-soft); color: var(--brand-ink); }
  .home-last .job-v { font-size: var(--fs-md); }

  /* the result sheet: the outcome is its title, coloured by the tone */
  .res-ico { display: grid; place-items: center; flex: none; width: var(--tile-sm); height: var(--tile-sm); border-radius: 50%; background: var(--ok-soft); color: var(--ok); }
  .res-bad { display: none; }
  #resultSheet[data-tone="bad"] .res-ico { background: var(--bad-soft); color: var(--bad); }
  #resultSheet[data-tone="bad"] .res-ok { display: none; }
  #resultSheet[data-tone="bad"] .res-bad { display: block; }
  #resultSheet[data-tone="bad"] #resTitle { color: var(--bad); }
  #resTitle:focus { outline: none; }
  #resTitle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .res-body { gap: var(--s-4); }
  .res-lines { display: grid; gap: var(--s-1); }
  #resTitle { font-size: var(--fs-xl); } /* the outcome leads (mobile 12, Q8) */
  .res-who { font-size: var(--fs-md); font-weight: 600; color: var(--ink-2); overflow-wrap: anywhere; }
  .res-code { font-family: var(--mono); white-space: nowrap; }
  .res-text { font-size: var(--fs-md); color: var(--ink-2); }
  .res-reasons { display: grid; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-radius: var(--r); background: var(--bad-soft); color: var(--bad); font-size: var(--fs-md); }
  .res-notes { display: grid; gap: var(--s-2); }
  .res-notes h3 { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
  .res-notes .plain { display: grid; gap: var(--s-1); font-size: var(--fs-md); }
  .file-card { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
  .file-ico { display: grid; place-items: center; flex: none; width: var(--tile); height: var(--tile); border-radius: var(--r); background: var(--sunken); color: var(--ink-2); }
  .file-text { display: grid; gap: 2px; min-width: 0; }
  .file-name { font: 500 var(--fs-md) / var(--lh-tight) var(--mono, var(--sans)); overflow-wrap: anywhere; }
  .file-meta { font-size: var(--fs-sm); color: var(--ink-2); }
  .res-actions { display: grid; gap: var(--s-2); }
  .res-actions .btn { width: 100%; min-height: var(--tap); font-size: var(--fs-lg); }
  .res-actions .btn.primary { min-height: var(--tap-lg); }
  .go-hint { font-size: var(--fs-sm); color: var(--ink-2); text-align: center; }
  /* the hint has nothing to add while a bill is being made or problems show (mobile 12, P1) */
  .home[data-busy="true"] .go-hint, .home:has(#libErr:not([hidden])) .go-hint { display: none; }

  /* the tall sheets: the moved section's own heading is the sheet's head, with Close or Done
     held in its corner; the head and foot stay put and only the body scrolls */
  .sheet-x { position: absolute; z-index: 2; top: calc((var(--bar) - var(--tap)) / 2); right: calc(var(--s-1) + var(--safe-r)); min-width: var(--tap); min-height: var(--tap); }
  .btn.ghost.sheet-done:not(:disabled) { padding: 0 var(--s-3); color: var(--brand-ink); font-size: var(--fs-lg); font-weight: 600; }
  .sheet .block-head {
    flex: none; min-height: var(--bar); margin: 0; background: var(--raised); border-bottom: 1px solid var(--line);
    padding: 0 calc(var(--tap) + var(--s-6) + var(--safe-r)) 0 calc(var(--s-4) + var(--safe-l));
  }
  .sheet .block h2 { font-size: var(--fs-lg); }
  /* the sheet heading takes focus when the sheet opens (mobile 12, Q1): a ring only for keys */
  .sheet .block-head h2:focus { outline: none; }
  .sheet .block-head h2:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .sheet-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
  .sheet-foot { flex: none; padding: var(--s-3) calc(var(--s-4) + var(--safe-r)) var(--s-3) calc(var(--s-4) + var(--safe-l)); border-top: 1px solid var(--line); background: var(--raised); }
  .sheet-foot .btn { min-height: var(--tap); font-size: var(--fs-lg); }
  .sheet input, .sheet select { min-height: var(--tap); }

  /* the bill sheet: the search stays at the top, only the list scrolls, its group headings stick */
  #billSheet .lib-pick { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--s-3); padding: 0 0 var(--s-3); }
  #billSheet .lib-pick > :not(.block-head, .lib-list) { margin: 0 calc(var(--s-4) + var(--safe-r)) 0 calc(var(--s-4) + var(--safe-l)); }
  #billSheet .lib-list {
    flex: 0 1 auto; min-height: 0; max-height: none; overflow: auto; overscroll-behavior: contain; gap: var(--s-4);
    margin: 0; padding: 0 calc(var(--s-4) + var(--safe-r)) var(--s-2) calc(var(--s-4) + var(--safe-l));
  }
  #billSheet .lib-group .group-head { position: sticky; top: 0; z-index: 1; margin: 0; padding: var(--s-2) 0; background: var(--raised); }
  #billSheet .lib-item { min-height: var(--bar); align-content: center; padding: var(--s-2) calc(var(--s-3) * 2 + var(--icon-md)) var(--s-2) var(--s-3); }
  #billSheet .lib-item { scroll-margin-top: calc(var(--s-6) + var(--s-2)); } /* clear of the sticky group heading (mobile 12, P23) */
  #billSheet .lib-item-name { font-size: var(--fs-lg); }
  /* the chosen bill (mobile 12, P10): brand border, soft fill and the check icon; no outer ring
     and no recoloured tag */
  #billSheet .lib-item:has(input:checked) { box-shadow: none; }
  #billSheet .lib-item:has(input:checked) .tag { border-color: var(--line); background: var(--surface); color: var(--ink-2); }
  #billSheet .lib-item:has(input:checked) .lib-item-tick {
    display: block; position: absolute; right: var(--s-3); top: 50%; margin-top: calc(var(--icon-md) / -2); color: var(--brand-ink);
  }
  #libClearSearch { min-height: var(--tap); padding: 0 var(--s-2); }
  .lib-down .btn { min-height: var(--tap); }

  /* the details sheet: one field per line */
  #detailsSheet .block { display: grid; gap: var(--s-4); padding: 0 0 var(--s-5); }
  #detailsSheet .block > :not(.block-head) { margin-left: calc(var(--s-4) + var(--safe-l)); margin-right: calc(var(--s-4) + var(--safe-r)); }
  #detailsSheet .block-head { position: sticky; top: 0; z-index: 1; }
  #detailsSheet .help { margin-bottom: 0; }
  /* the bill named in one quiet line, not a second card: the home shows the card, but the tall
     sheet covers it (mobile 12, P17; story 32, mobile 13) */
  #detailsSheet .lib-chosen { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s-2); padding: 0; background: none; }
  #detailsSheet .lib-chosen-name { font-size: var(--fs-md); }
  .req-mark { color: var(--ink-2); } /* quieter than the field's own label (mobile 12, P18) */
  .req-mark::before { background: var(--ink-3); }
  #detailsSheet .lib-grid { grid-template-columns: 1fr; }
  #detailsSheet input, #detailsSheet select { scroll-margin: calc(var(--bar) + var(--s-4)) 0 var(--s-4); } /* clear of the held head */

  /* a phone held sideways, or any short window (mobile 12, Q7, Q9, P1): the strip joins the
     header row, the hint goes, a sheet leaves only a sliver of page above it, and the result's
     actions share one row so its reasons and file card stay in view */
  @media (max-height: 500px) {
    :root { --sheet-gap: var(--s-5); } /* still a strip of backdrop to tap */
    .test-badge {
      order: 0; flex: none; min-height: var(--tap); margin: 0 var(--s-1) 0 var(--s-2); padding: 0 0 0 var(--s-3);
      border-width: 1px; border-radius: var(--r);
    }
    .go-hint { display: none; }
    .res-actions { grid-auto-flow: column; grid-auto-columns: 1fr; align-items: stretch; }
  }
}
