/* Fratco App v6.10 - base.css: the one stylesheet of the redesign ("Painted plant sign", docs/redesign/DIRECTION.md).
   Sections: 1 fonts, 2 tokens (light, dark, text size, phone), 3 reset and browser surfaces, 4 type,
   5 layout helpers, 6 components, 7 motion (only under prefers-reduced-motion: no-preference).
   Rules: no zoom, no gradients, no shadows except .dialog/.sheet (and the sticky Save bar later), brand red only on .sign, .btn-primary
   and .btn-danger. Theme: html[data-theme="light|dark"], or the device setting when the attribute is absent.
   Text size: html[data-textsize="smaller|small|large|xlarge"] (the attribute js/prefs-init.js sets; Normal sets none).
   Kit of every component in every state: tests/kit.html (dev only). Contrast and token checks:
   node tests/design-tokens-test.mjs */

/* ---------- 1. Fonts (self-hosted, latin subsets) ---------- */
@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("../fonts/atkinson-hyperlegible-next-400-800.woff2") format("woff2"); font-weight: 400 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("../fonts/atkinson-hyperlegible-next-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("../fonts/barlow-condensed-700.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

/* ---------- 2. Tokens ---------- */
/* Light: galvanized zinc ground, white surfaces, charcoal ink (the default). */
:root {
  color-scheme: light;
  --bg: #EEF0F1;              /* page ground (galvanized zinc) */
  --surface: #FFFFFF;         /* panels, fields, tables */
  --surface-2: #F5F6F7;       /* hover rows, read-only fields, quiet fills */
  --raised: #FFFFFF;          /* dialogs and sheets */
  --ink: #1C2024;             /* main text */
  --ink-2: #4A535C;           /* secondary text, hints, placeholders */
  --line: #D5DADE;            /* hairline rules */
  --line-strong: #A9B1B8;     /* table head rule, empty borders */
  --line-control: #737D86;    /* field and button borders (3:1 on surface and ground) */
  --brand: #BE1E2D;           /* Fratco red: sign band, the one primary action, destructive confirms */
  --brand-hover: #A31A27;
  --brand-ink: #FFFFFF;       /* text on brand red */
  --ok: #21663A;  --ok-bg: #E5F1E9;       /* won, saved */
  --warn: #8A5300; --warn-bg: #FBF0DC;    /* needs attention */
  --danger: #9E1B26; --danger-bg: #FAE6E7; /* errors, lost */
  --info: #38556E; --info-bg: #E6EDF3;    /* open, neutral notices */
  --ok-solid: #21663A; --danger-solid: #9E1B26; --solid-ink: #FFFFFF; /* filled toasts, same in both themes */
  --inverse: #262B30; --inverse-ink: #FFFFFF;  /* plain toast */
  --rail: #262B30; --rail-ink: #FFFFFF; --rail-ink-2: #C2C9CF; /* shell rail, steel charcoal in both themes */
  --focus: #1C2024;           /* focus ring on light surfaces */
  --focus-on-dark: #FFFFFF;   /* focus ring on the rail and the sign band */
  --disabled-bg: #E3E6E9; --disabled-ink: #5A636B;
  --skeleton: #DDE1E5;
  --select-bg: #C9D3DB;       /* text selection */
  --scrim: rgb(20 23 26 / 0.55);
  --shadow-lift: 0 16px 40px rgb(20 23 26 / 0.22), 0 2px 8px rgb(20 23 26 / 0.12);

  --font-ui: "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;  /* everything people read and type */
  --font-sign: "Barlow Condensed", "Arial Narrow", sans-serif-condensed, sans-serif; /* painted signs and stamps, capitals */
  --font-num: "Barlow Condensed", "Arial Narrow", sans-serif-condensed, sans-serif;  /* painted numerals (the one number) */

  --text-scale: 1;            /* 0.8 (smaller), 0.9 (small), 1, 1.15 (large), 1.3 (xlarge) */
  --fs-1: calc(0.875rem * var(--text-scale));   /* 14px  smallest: captions, table notes */
  --fs-2: calc(0.9375rem * var(--text-scale));  /* 15px  labels, meta, hints */
  --fs-3: calc(1.0625rem * var(--text-scale));  /* 17px  body (16px on phones) */
  --fs-4: calc(1.25rem * var(--text-scale));    /* 20px  panel titles */
  --fs-5: calc(1.5rem * var(--text-scale));     /* 24px  page headings */
  --fs-6: calc(2.5rem * var(--text-scale));     /* 40px  sign title */
  --fs-7: calc(3.5rem * var(--text-scale));     /* 56px  painted total */

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --r-1: 4px;                 /* controls */
  --r-2: 8px;                 /* panels, dialogs */
  --tap: 44px;                /* minimum touch target */
  --sign-h: 72px;             /* sign band height */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --dur-1: 120ms;             /* press, hover */
  --dur-2: 200ms;             /* enter */
}

/* Light, chosen in the app on a dark device: the device-dark block below skips it, so only the scheme is set here.
   (Kept apart from :root so html[data-theme] never outranks the phone type sizes.) */
html[data-theme="light"] { color-scheme: light; }

/* Dark, chosen in the app (data-theme="dark"). Keep identical to the device-dark block below. */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15181B; --surface: #1D2125; --surface-2: #252A2F; --raised: #252A2F;
  --ink: #ECEEF0; --ink-2: #AEB6BD;
  --line: #343A40; --line-strong: #4A525A; --line-control: #78828B;
  --brand: #BE1E2D; --brand-hover: #A31A27; --brand-ink: #FFFFFF;
  --ok: #7CC793; --ok-bg: #16301F;
  --warn: #E5A957; --warn-bg: #33260F;
  --danger: #F28B92; --danger-bg: #3A1B1F;
  --info: #9DBAD3; --info-bg: #1A2836;
  --inverse: #ECEEF0; --inverse-ink: #1C2024;
  --focus: #ECEEF0;
  --disabled-bg: #2A2F34; --disabled-ink: #98A0A7;
  --skeleton: #2C3237;
  --select-bg: #3D4954;
  --scrim: rgb(0 0 0 / 0.6);
  --shadow-lift: 0 16px 40px rgb(0 0 0 / 0.5), 0 2px 8px rgb(0 0 0 / 0.35);
}
/* Dark, from the device setting when no theme is chosen. Keep identical to the block above. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15181B; --surface: #1D2125; --surface-2: #252A2F; --raised: #252A2F;
    --ink: #ECEEF0; --ink-2: #AEB6BD;
    --line: #343A40; --line-strong: #4A525A; --line-control: #78828B;
    --brand: #BE1E2D; --brand-hover: #A31A27; --brand-ink: #FFFFFF;
    --ok: #7CC793; --ok-bg: #16301F;
    --warn: #E5A957; --warn-bg: #33260F;
    --danger: #F28B92; --danger-bg: #3A1B1F;
    --info: #9DBAD3; --info-bg: #1A2836;
    --inverse: #ECEEF0; --inverse-ink: #1C2024;
    --focus: #ECEEF0;
    --disabled-bg: #2A2F34; --disabled-ink: #98A0A7;
    --skeleton: #2C3237;
    --select-bg: #3D4954;
    --scrim: rgb(0 0 0 / 0.6);
    --shadow-lift: 0 16px 40px rgb(0 0 0 / 0.5), 0 2px 8px rgb(0 0 0 / 0.35);
  }
}

/* Text size (Account > Text size). Type tokens multiply by --text-scale; spacing and the 44px --tap do not,
   so touch targets stay 44px at every size. Smaller and Small are for big desktop screens (Derek, 2026-10-12). */
html[data-textsize="smaller"] { --text-scale: 0.8; }
html[data-textsize="small"] { --text-scale: 0.9; }
html[data-textsize="large"] { --text-scale: 1.15; }
html[data-textsize="xlarge"] { --text-scale: 1.3; }

/* Phones: 16px body, smaller sign and total. */
@media (max-width: 599.98px) {
  :root {
    --fs-3: calc(1rem * var(--text-scale));
    --fs-5: calc(1.375rem * var(--text-scale));
    --fs-6: calc(1.75rem * var(--text-scale));
    --fs-7: calc(2.75rem * var(--text-scale));
    --sign-h: 56px;
  }
  /* Smaller and Small text on a phone: fields stay at 16px, so the phone does not zoom in when one is tapped. */
  html[data-textsize="small"] :is(input:not([type=checkbox]):not([type=radio]), select, textarea),
  html[data-textsize="smaller"] :is(input:not([type=checkbox]):not([type=radio]), select, textarea) { font-size: 1rem; }
}

/* ---------- 3. Reset and browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); accent-color: var(--ink); scrollbar-color: var(--line-strong) var(--bg); }
body {
  margin: 0; min-height: 100dvh;
  font-family: var(--font-ui); font-size: var(--fs-3); line-height: 1.5; font-weight: 400;
  color: var(--ink); background: var(--bg);
  font-kerning: normal; font-synthesis-weight: none; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, ul, ol, dl, figure { margin: 0; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; }
img, svg, video, canvas { display: block; max-width: 100%; }
svg { flex: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
button, a, label, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* The one !important: hidden must beat every component display (.field, .stack, .btn...), since folded-away parts rely on it. */
[hidden] { display: none !important; }
::selection { background: var(--select-bg); color: var(--ink); }
input, textarea { caret-color: var(--ink); }
a { color: var(--ink); text-decoration-line: underline; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
@media (hover: hover) { a:hover { text-decoration-thickness: 2px; } }
/* Focus: one visible ring on every control, 3px, at least 3:1 in both themes. */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------- 4. Type ---------- */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.25; text-wrap: balance; }
h1 { font-size: var(--fs-5); font-weight: 800; }
h2 { font-size: var(--fs-5); }
h3 { font-size: var(--fs-4); }
h4 { font-size: var(--fs-3); }
p { text-wrap: pretty; }
small { font-size: var(--fs-2); }
/* .muted: secondary text colour. */
.muted { color: var(--ink-2); }
/* .num: tabular figures, for money and quantities that line up and update in place. */
.num { font-variant-numeric: tabular-nums lining-nums; }
/* .prose: running text held to a readable measure. */
.prose { max-width: 68ch; }
/* .sr-only: text for screen readers only. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---------- 5. Layout helpers ---------- */
/* .page: the main column, centred, 16px gutter on phones. */
.page { width: 100%; max-width: 80rem; margin-inline: auto; padding: var(--sp-5) var(--sp-5) var(--sp-7); }
/* .stack: vertical rhythm (.stack-sm 8px, .stack 16px, .stack-lg 32px). */
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--sp-6); }
/* .cluster: a wrapping row of things (buttons, stamps), 12px apart. */
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
/* .grid: columns that fall to one on narrow screens. */
.grid { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fit, minmax(min(20rem, 100%), 1fr)); }

/* ---------- 6. Components ---------- */

/* .sign: the painted red sign band, one per screen, carrying its title. */
.sign {
  --focus: var(--focus-on-dark);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3) var(--sp-4);
  min-height: var(--sign-h); padding: var(--sp-3) var(--sp-5);
  background: var(--brand); color: var(--brand-ink);
}
/* .sign-title: the painted words, condensed capitals. */
.sign-title {
  flex: 1 1 auto; min-width: 0; margin: 0;
  font-family: var(--font-sign); font-weight: 700; font-size: var(--fs-6); line-height: 1.05;
  text-transform: uppercase; letter-spacing: 0.02em; overflow-wrap: break-word; text-wrap: balance;
  padding-top: 0.06em;
}
/* .sign-actions: the sign's own buttons (Search, Help), right side. */
.sign-actions { flex: none; display: flex; gap: var(--sp-2); margin-left: auto; }
.sign .btn { background: transparent; color: var(--brand-ink); border-color: rgb(255 255 255 / 0.85); }
.sign .btn-quiet { border-color: transparent; }
@media (hover: hover) { .sign .btn:hover { background: var(--brand-hover); border-color: var(--brand-ink); } }

/* .sign-num: painted numerals, for the one number that matters on a screen (the total). */
.sign-num {
  display: block; font-family: var(--font-num); font-weight: 700; font-size: min(var(--fs-7), 14vw); line-height: 1;
  font-variant-numeric: tabular-nums lining-nums; letter-spacing: 0.01em; white-space: nowrap; color: var(--ink);
}

/* .btn: a button (plain, outlined). Labels are plain verbs. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); min-width: var(--tap); padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--line-control); border-radius: var(--r-1);
  background: var(--surface); color: var(--ink);
  font-family: var(--font-ui); font-size: var(--fs-3); font-weight: 700; line-height: 1.2; text-align: center; text-decoration: none;
  text-wrap: balance; user-select: none; cursor: pointer;
}
.btn svg { width: 1.25em; height: 1.25em; }
@media (hover: hover) { .btn:hover { background: var(--surface-2); border-color: var(--ink-2); } }
/* .btn-primary: the one red action per screen. .btn-danger: a destructive confirm (Delete), brand red like the primary, used in its place. */
.btn-primary, .btn-danger { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
@media (hover: hover) { .btn-primary:hover, .btn-danger:hover { background: var(--brand-hover); border-color: var(--brand-hover); } }
/* .btn-quiet: a text button with no box until hovered (Cancel, Help, Undo). */
.btn-quiet { background: transparent; border-color: transparent; }
@media (hover: hover) { .btn-quiet:hover { background: var(--surface-2); border-color: transparent; } }
/* .btn-icon: a square icon button; always give it aria-label. */
.btn-icon { padding: 0; width: var(--tap); }
/* .btn-block: a full-width button (phone footers, sheets). */
.btn-block { display: flex; width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--disabled-bg); border-color: var(--disabled-bg); color: var(--disabled-ink); cursor: not-allowed; }
.btn-quiet:disabled, .btn-quiet[aria-disabled="true"] { background: transparent; border-color: transparent; }
/* Loading: <button class="btn" aria-busy="true" disabled><span class="spinner"></span>Saving...</button>; keeps its colour. */
.btn-primary[aria-busy="true"], .btn-danger[aria-busy="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); cursor: progress; }
.btn[aria-busy="true"]:not(.btn-primary):not(.btn-danger) { background: var(--surface); border-color: var(--line-control); color: var(--ink); cursor: progress; }

/* .spinner: a small turning ring for work in progress (static ring when motion is off). */
.spinner { display: inline-block; flex: none; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; }

/* .field: label + control + hint or error, stacked. Mark errors with aria-invalid="true" on the control. */
.field { display: grid; gap: var(--sp-2); align-content: start; min-width: 0; }
/* .label: a field's name, bold. .label .opt marks "(optional)". */
.label { font-size: var(--fs-2); font-weight: 700; line-height: 1.3; color: var(--ink); }
.label .opt { font-weight: 400; color: var(--ink-2); }
/* .hint: help under a field. */
.hint { font-size: var(--fs-2); line-height: 1.4; color: var(--ink-2); }
/* .field-error: what is wrong and how to fix it, under the field. */
.field-error { display: flex; gap: var(--sp-2); align-items: flex-start; font-size: var(--fs-2); font-weight: 700; line-height: 1.4; color: var(--danger); }
.field-error svg { width: 1.2em; height: 1.2em; margin-top: 0.05em; }
/* .input: text, number, search and textarea fields. */
.input, .select > select {
  width: 100%; min-height: var(--tap); padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line-control); border-radius: var(--r-1);
  background: var(--surface); color: var(--ink);
  font-size: var(--fs-3); line-height: 1.4;
}
textarea.input { min-height: 7rem; resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--ink-2); opacity: 1; }
.input.num { text-align: right; }
@media (hover: hover) { .input:hover, .select > select:hover { border-color: var(--ink-2); } }
.input:focus-visible, .select > select:focus-visible { border-color: var(--ink); }
.input[readonly] { background: var(--surface-2); }
.input:disabled, .select > select:disabled { background: var(--disabled-bg); border-color: var(--disabled-bg); color: var(--disabled-ink); cursor: not-allowed; }
.input[aria-invalid="true"], .select > select[aria-invalid="true"] { border: 2px solid var(--danger); padding-left: calc(var(--sp-3) - 1px); }

/* .select: wraps a native <select> and draws its chevron. */
.select { position: relative; display: block; min-width: 0; font-size: var(--fs-3); }
.select > select { appearance: none; padding-right: calc(var(--sp-3) + 2em); cursor: pointer; }
.select::after {
  content: ""; position: absolute; right: var(--sp-4); top: 50%; width: 0.55em; height: 0.55em; pointer-events: none;
  border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: translateY(-70%) rotate(45deg);
}
.select:has(select:disabled)::after { border-color: var(--disabled-ink); }

/* .check: a checkbox or radio with its label: <label class="check"><input type="checkbox"><span>Text</span></label>. */
.check { display: flex; align-items: flex-start; gap: var(--sp-3); min-height: var(--tap); padding: 10px 0; line-height: 1.5; cursor: pointer; }
.check > input {
  appearance: none; flex: none; display: grid; place-content: center;
  width: 24px; height: 24px; margin: max(0px, calc((1lh - 24px) / 2)) 0 0;
  border: 2px solid var(--line-control); border-radius: var(--r-1); background: var(--surface); cursor: pointer;
}
.check > input::after { content: ""; width: 7px; height: 13px; border: solid var(--surface); border-width: 0 3px 3px 0; transform: translateY(-1px) rotate(45deg); opacity: 0; }
.check > input:checked { background: var(--ink); border-color: var(--ink); }
.check > input:checked::after { opacity: 1; }
.check > input[type="radio"] { border-radius: 50%; }
.check > input[type="radio"]::after { width: 10px; height: 10px; border: 0; border-radius: 50%; background: var(--surface); transform: none; }
.check > input[aria-invalid="true"] { border-color: var(--danger); }
.check:has(input:disabled) { color: var(--disabled-ink); cursor: not-allowed; }
.check > input:disabled { background: var(--disabled-bg); border-color: var(--disabled-ink); cursor: not-allowed; }
.check > input:disabled:checked { background: var(--disabled-ink); }

/* .seg: a segmented control, one choice of a few: buttons with aria-pressed="true" on the chosen one. */
.seg { display: inline-flex; flex-wrap: wrap; gap: 1px; align-self: flex-start; justify-self: start; max-width: 100%; overflow: hidden; border: 1px solid var(--line-control); border-radius: var(--r-1); background: var(--line); }
.seg > button {
  position: relative; flex: 1 1 auto; min-height: var(--tap); min-width: var(--tap); padding: var(--sp-2) var(--sp-4);
  border: 0; background: var(--surface); color: var(--ink);
  font-size: var(--fs-3); font-weight: 700; line-height: 1.2;
}
.seg > button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.seg > button:focus-visible { outline-offset: -5px; }   /* inside: the group clips its corners */
.seg > button[aria-pressed="true"]:focus-visible { outline-color: var(--surface); }
.seg > button:disabled { color: var(--disabled-ink); cursor: not-allowed; }
@media (hover: hover) { .seg > button:not([aria-pressed="true"]):not(:disabled):hover { background: var(--surface-2); } }
/* .seg-block: a segmented control as wide as its column. */
.seg-block { display: flex; align-self: stretch; justify-self: stretch; width: 100%; }

/* .tabs: tab buttons over a view (role="tablist", buttons role="tab" with aria-selected). */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs > [role="tab"] {
  flex: none; min-height: var(--tap); padding: var(--sp-2) var(--sp-4); margin-bottom: -1px;
  border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--ink-2);
  font-size: var(--fs-3); font-weight: 700; line-height: 1.2; white-space: nowrap;
}
.tabs > [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs > [role="tab"]:focus-visible { outline-offset: -3px; }
@media (hover: hover) { .tabs > [role="tab"]:hover { color: var(--ink); } }

/* .table: a ruled data table; cells with .num line up money to the right. Wrap in .table-wrap to scroll on phones. */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-3); line-height: 1.4; }
.table caption { text-align: left; font-weight: 700; padding-bottom: var(--sp-2); }
.table th { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--line-strong); text-align: left; vertical-align: bottom; font-size: var(--fs-2); font-weight: 700; color: var(--ink-2); }
.table td { padding: var(--sp-3); border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: break-word; }
.table td:first-child { min-width: 9em; }   /* the name column never crushes to a word a line; the wrap scrolls instead */
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums lining-nums; }
.table tfoot td { border-top: 2px solid var(--ink); border-bottom: 0; font-weight: 700; }
@media (hover: hover) { .table tbody tr:hover { background: var(--surface-2); } }
/* .table-stack: on phones each row becomes a block, the first cell as its title and every other cell as
   "label ... value" from its data-label attribute, so money never scrolls off screen. */
@media (max-width: 599.98px) {
  .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table-stack, .table-stack tbody, .table-stack tfoot, .table-stack tr, .table-stack td { display: block; }
  .table-stack tbody { border-top: 1px solid var(--line-strong); }
  .table-stack tbody tr { padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
  .table-stack td { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 2px 0; border: 0; text-align: right; }
  .table-stack td::before { content: attr(data-label); flex: none; text-align: left; font-size: var(--fs-2); font-weight: 700; color: var(--ink-2); }
  .table-stack td:first-child { display: block; min-width: 0; padding-bottom: var(--sp-1); text-align: left; font-weight: 700; }
  .table-stack td:first-child::before, .table-stack td:not([data-label])::before { content: none; }
  .table-stack td:empty { display: none; }
  .table-stack tfoot tr { display: flex; justify-content: space-between; gap: var(--sp-3); padding-top: var(--sp-3); border-top: 2px solid var(--ink); }
  .table-stack tfoot td { display: block; padding: 0; border: 0; }
}

/* .panel: a white surface for one group (customer, lines, totals). Never put a panel in a panel. */
.panel { min-width: 0; padding: var(--sp-5); border: 1px solid var(--line); border-radius: var(--r-2); background: var(--surface); }
/* .panel-head: title on the left, a quiet action on the right. */
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-4); }
/* .panel-title: the panel's heading. */
.panel-title { font-size: var(--fs-4); font-weight: 700; line-height: 1.25; }

/* .list: a ruled list of .row items (no bullets). Rows hang 12px into the container padding so their text lines up with it. */
.list { list-style: none; margin: 0 calc(-1 * var(--sp-3)); padding: 0; }   /* the -12px margin needs a container with at least 12px inline padding (.panel, .page, .dialog-body), or it overflows */
.list > li:first-child > .row, .list > .row:first-child { border-top: 1px solid var(--line); }
/* .row: one line of a list (an order, a load): main text, then the value or stamp at the end. a.row and button.row are clickable. */
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3) var(--sp-4); min-height: var(--tap); padding: var(--sp-3); border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
a.row, button.row { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; font: inherit; cursor: pointer; }
a.row:focus-visible, button.row:focus-visible { outline-offset: -3px; }
@media (hover: hover) { a.row:hover, button.row:hover { background: var(--surface-2); } }
/* .row-main: the growing middle (title over meta). Under about 10rem the end drops to its own line. */
.row-main { flex: 1 1 calc(10rem * var(--text-scale)); min-width: 0; }
/* .row-title: the row's name, bold, wraps rather than clips. */
.row-title { display: block; font-weight: 700; overflow-wrap: break-word; }
/* .row-meta: second line (job, date, plant). */
.row-meta { display: block; font-size: var(--fs-2); color: var(--ink-2); overflow-wrap: break-word; }
/* .row-end: the trailing value, stamp or button. */
.row-end { flex: none; margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2) var(--sp-3); text-align: right; }

/* .stamp: a state stamped in condensed capitals (OPEN, WON, LOST, VOID). Default is neutral (VOID, DRAFT). */
.stamp {
  display: inline-flex; align-items: center; padding: 0.2em 0.5em 0.12em; border: 2px solid currentColor; border-radius: var(--r-1);
  font-family: var(--font-sign); font-weight: 700; font-size: var(--fs-3); line-height: 1.1; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
  color: var(--ink-2);
}
/* .stamp-ok (WON), .stamp-warn (DUE), .stamp-danger (LOST), .stamp-info (OPEN): the state colours. */
.stamp-ok { color: var(--ok); }
.stamp-warn { color: var(--warn); }
.stamp-danger { color: var(--danger); }
.stamp-info { color: var(--info); }

/* .note: a message in the page (saved, check this, could not save). .note-ok, .note-warn, .note-danger, .note-info. */
.note { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line-strong); border-radius: var(--r-1); background: var(--surface-2); color: var(--ink); line-height: 1.45; }
.note > svg { width: 1.3em; height: 1.3em; margin-top: 0.05em; }
.note-title { font-weight: 700; }
.note-ok { background: var(--ok-bg); border-color: var(--ok); } .note-ok > svg { color: var(--ok); }
.note-warn { background: var(--warn-bg); border-color: var(--warn); } .note-warn > svg { color: var(--warn); }
.note-danger { background: var(--danger-bg); border-color: var(--danger); } .note-danger > svg { color: var(--danger); }
.note-info { background: var(--info-bg); border-color: var(--info); } .note-info > svg { color: var(--info); }

/* .dialog: a modal on a native <dialog> placed directly in <body> and opened with showModal(); centred on screen, a bottom sheet on phones.
   Parts: .dialog-head (title + close), .dialog-body (scrolls), .dialog-foot (actions, always visible).
   Put autofocus on the first field, or on the safe button of a confirm, so focus does not land on Close. */
.dialog {
  position: fixed; inset: 0; margin: auto; padding: 0;
  width: min(36rem, calc(100vw - 2 * var(--sp-4))); max-width: none; max-height: min(90dvh, 48rem);
  border: 0; border-radius: var(--r-2);
  background: var(--raised); color: var(--ink); box-shadow: var(--shadow-lift);
  overflow: hidden;
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog::backdrop { background: var(--scrim); }
/* .dialog-wide: a wider dialog for tables (48rem). */
.dialog-wide { width: min(48rem, calc(100vw - 2 * var(--sp-4))); }
/* .sheet: a dialog that rises from the bottom at every width (pickers, phone menus). */
.sheet { margin: auto auto 0; width: min(40rem, 100vw); max-height: 90dvh; border-radius: var(--r-2) var(--r-2) 0 0; }
.dialog-head { flex: none; display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--line); }
.dialog-title { flex: 1 1 auto; min-width: 0; font-size: var(--fs-4); font-weight: 700; line-height: 1.25; overflow-wrap: break-word; }
.dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-5); }
.dialog-foot { flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5) calc(var(--sp-3) + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--raised); }

/* .toast-region: where toasts appear (bottom centre), placed directly in <body>; give it role="status". */
.toast-region { position: fixed; z-index: 60; left: 0; right: 0; bottom: calc(var(--sp-5) + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-4); pointer-events: none; }
/* .toast: a short message after an action; plain, .toast-ok (saved) or .toast-danger (failed). */
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--sp-3); width: 100%; max-width: 32rem; min-height: var(--tap);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4); border-radius: var(--r-2);
  background: var(--inverse); color: var(--inverse-ink);
  font-weight: 700; line-height: 1.35;
}
.toast > span { flex: 1 1 auto; min-width: 0; overflow-wrap: break-word; padding-block: var(--sp-1); }
.toast > svg { width: 1.3em; height: 1.3em; }
.toast .btn { padding-block: var(--sp-1); background: transparent; border-color: transparent; color: inherit; text-decoration: underline; text-underline-offset: 0.2em; }
.toast { --focus: currentColor; }
.toast-ok { background: var(--ok-solid); color: var(--solid-ink); }
.toast-danger { background: var(--danger-solid); color: var(--solid-ink); }

/* .empty: nothing here yet; says what goes here and offers the next step. */
.empty { display: grid; justify-items: center; gap: var(--sp-3); padding: var(--sp-7) var(--sp-4); text-align: center; }
.empty > svg { width: 40px; height: 40px; color: var(--ink-2); }
.empty-title { font-size: var(--fs-4); font-weight: 700; }
.empty-text { max-width: 44ch; color: var(--ink-2); }

/* .skeleton: grey bars that hold the shape of content while it loads (static; the container carries aria-busy="true"). */
.skeleton { display: block; height: 1em; margin-block: 0.3em; border-radius: var(--r-1); background: var(--skeleton); }
/* .skeleton-short / .skeleton-mid: shorter bars; .skeleton-block: a tall box. */
.skeleton-short { width: 40%; }
.skeleton-mid { width: 70%; }
.skeleton-block { height: 6rem; }

/* ---------- Phones ---------- */
@media (max-width: 599.98px) {
  .page { padding: var(--sp-4) var(--sp-4) var(--sp-7); }
  .sign { padding: var(--sp-2) var(--sp-4); }
  .panel { padding: var(--sp-4); }
  .dialog { margin: auto 0 0; width: 100vw; max-height: 90dvh; border-radius: var(--r-2) var(--r-2) 0 0; }
  .dialog-head { padding-left: var(--sp-4); }
  .dialog-body { padding: var(--sp-4); }
  .dialog-foot { padding-inline: var(--sp-4); }
  .dialog-foot > .btn { flex: 1 1 auto; }
  .toast-region { bottom: calc(var(--sp-4) + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- 7. Motion: transform and opacity only, under 250 ms, nothing when motion is off ---------- */
@keyframes base-rise { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes base-sheet { from { opacity: 0.6; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes base-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes base-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: no-preference) {
  html:not([data-motion="reduced"]) .btn,
  html:not([data-motion="reduced"]) .seg > button { transition: transform var(--dur-1) var(--ease-out);   /* transform only: a colour fade left the pressed text on its own colour for a moment */ }
  html:not([data-motion="reduced"]) .btn:active:not(:disabled):not([aria-busy="true"]) { transform: scale(0.97); }
  html:not([data-motion="reduced"]) .dialog[open] { animation: base-rise var(--dur-2) var(--ease-out); }
  html:not([data-motion="reduced"]) .sheet[open] { animation: base-sheet var(--dur-2) var(--ease-out); }
  html:not([data-motion="reduced"]) .dialog[open]::backdrop { animation: base-fade var(--dur-2) var(--ease-out); }
  html:not([data-motion="reduced"]) .toast { animation: base-rise var(--dur-2) var(--ease-out); }
  html:not([data-motion="reduced"]) .spinner { animation: base-spin 800ms linear infinite; }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 599.98px) {
  html:not([data-motion="reduced"]) .dialog[open] { animation: base-sheet var(--dur-2) var(--ease-out); }
}

/* .stamp-expired (EXPIRED): still Open after 10 days with no Won or Lost. Muted and dashed, never red. */
.stamp-expired { color: var(--ink-2); border-style: dashed; }
