/* Design system: fonts, tokens, type, layout, navigation and shared components. Every screen inherits this file.
   Owned by the shell (design foundation). DESIGN.md is the source: Asphalt / Concrete / Truck blue / Hi-vis, Barlow, the job ticket.
   Other areas add their own rules in their own css file and reuse these classes and tokens.
   Phone first: everything works at 320px wide with 44px tap targets; the desktop layout starts at 960px. */

/* ---------- Fonts: Barlow and Barlow Semi Condensed, self-hosted (web/fonts, SIL Open Font License in web/fonts/OFL.txt).
   Latin subset only. The file names carry the Google Fonts version: they are served with a year-long cache, so a new
   cut of a font gets a new name, never the same name. ---------- */
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 400; font-display: swap; src: url(/fonts/barlow-400-latin-v13.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 500; font-display: swap; src: url(/fonts/barlow-500-latin-v13.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 600; font-display: swap; src: url(/fonts/barlow-600-latin-v13.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Barlow'; font-style: normal; font-weight: 700; font-display: swap; src: url(/fonts/barlow-700-latin-v13.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Barlow Semi Condensed'; font-style: normal; font-weight: 600; font-display: swap; src: url(/fonts/barlow-semi-condensed-600-latin-v16.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Barlow Semi Condensed'; font-style: normal; font-weight: 700; font-display: swap; src: url(/fonts/barlow-semi-condensed-700-latin-v16.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  /* ----- Colour (DESIGN.md). Hi-vis is only for "needs action now"; text on it is ink. ----- */
  --ink: #1B2420; --ink-2: #46524D; --ink-3: #5F6B66;
  --ground: #EEF0EC; --surface: #FFFFFF; --surface-sunk: #F6F7F4; --surface-press: #E6E9E4;
  --line: #D5DAD5; --line-control: #8C968F; --line-firm: #AEB6B0;
  --blue: #1F48C4; --blue-ink: #FFFFFF; --blue-hover: #183A9E; --blue-soft: #E8EDFB; --blue-line: #B9C8F0;
  --hivis: #F26A1B; --hivis-ink: #1B2420; --hivis-hover: #E8600F; --hivis-soft: #FDE9DC;
  --done: #2F7A4F; --done-soft: #E5F2EA; --done-line: #B3D7C0;
  --warn: #9A6400; --warn-soft: #FFF3D6; --warn-line: #E8C77E;
  --danger: #B3261E; --danger-soft: #FCE9E7; --danger-line: #EFBCB7; --danger-hover: #93190F;
  /* The desktop rail is asphalt. */
  --rail: #1B2420; --rail-ink: #EEF0EC; --rail-ink-2: #C9D0CB; --rail-ink-3: #9AA49E; --rail-hover: #263029; --rail-line: #33403A;

  /* ----- Type ----- */
  --font-body: 'Barlow', system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: 'Barlow Semi Condensed', 'Barlow', system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs-13: .8125rem; --fs-15: .9375rem; --fs-16: 1rem; --fs-18: 1.125rem; --fs-22: 1.375rem; --fs-28: 1.75rem; --fs-36: 2.25rem; --fs-48: 3rem;

  /* ----- Shape, depth, space ----- */
  --radius-control: 6px; --radius-ticket: 10px; --radius-sheet: 10px; --radius-full: 999px;
  --shadow-float: 0 1px 0 rgba(27, 36, 32, .06), 0 6px 16px -8px rgba(27, 36, 32, .18);
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px; --space-7: 48px;
  --tap: 44px; --tap-crew: 56px;
  --ring: 0 0 0 3px rgba(31, 72, 196, .32);

  /* ----- Layout ----- */
  --rail-w: 248px; --topbar-h: 56px; --tabbar-h: 62px; --content-w: 1200px; --gutter: 16px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px); --safe-right: env(safe-area-inset-right, 0px);

  /* ----- Older names, kept as aliases so every area's CSS keeps working while it restyles. ----- */
  --bg: var(--ground); --text: var(--ink); --muted: #46524d; --subtle: var(--ink-3);
  --surface-2: var(--surface-sunk); --surface-3: var(--surface-press); --line-strong: var(--line-firm);
  --brand: var(--blue); --brand-hover: var(--blue-hover); --brand-ink: var(--blue-ink); --brand-soft: var(--blue-soft); --brand-line: var(--blue-line);
  --ok: var(--done); --ok-soft: var(--done-soft); --ok-line: var(--done-line);
  --info: var(--blue); --info-soft: var(--blue-soft); --info-line: var(--blue-line);
  --warn-text: var(--warn);
  --focus: var(--blue); --focus-ring: var(--ring);
  --radius: 10px; --radius-sm: 6px; --radius-lg: 10px; --radius-pill: 999px;
  /* Flat by default: only floating things (sheets, menus, the crew action bar, a dragged ticket) get a shadow. */
  --shadow-sm: 0 0 #0000; --shadow: 0 0 #0000; --shadow-lg: var(--shadow-float);
  --gap: 16px; --font: var(--font-body);
  --text-sm: .9375rem; --text-xs: .8125rem;
  --nav-w: var(--rail-w);
  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; font: 400 16px/1.45 var(--font-body); color: var(--ink); background: var(--ground); -webkit-font-smoothing: antialiased; overscroll-behavior-y: contain;
  font-synthesis-weight: none; text-rendering: optimizeLegibility; }
img, svg, video, canvas { max-width: 100%; }
img { height: auto; }
a { color: var(--blue); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--blue-hover); text-decoration-thickness: 2px; }
h1, h2, h3, h4 { font-weight: 700; line-height: 1.2; letter-spacing: -.01em; overflow-wrap: anywhere; color: var(--ink); }
h1 { font-size: var(--fs-22); margin: 0 0 12px; }
h2 { font-size: var(--fs-18); margin: 24px 0 8px; }
h3 { font-size: var(--fs-16); margin: 12px 0 6px; }
h4 { font-size: var(--fs-15); margin: 8px 0 4px; }
@media (min-width: 960px) { h1 { font-size: var(--fs-28); } }
p { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }
small, .small { font-size: var(--fs-15); }
.xsmall { font-size: var(--fs-13); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
code, kbd { font-family: var(--mono); font-size: .88em; background: var(--surface-press); padding: 1px 5px; border-radius: 4px; }
strong, b { font-weight: 600; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
/* Headings get focus after each navigation so screen readers announce the new page; no ring for that. */
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus, [tabindex="-1"]:focus:not(:focus-visible) { outline: none; }
h1[tabindex="-1"]:focus-visible, h2[tabindex="-1"]:focus-visible { outline: none; }
::selection { background: var(--blue-soft); }
.skip { position: absolute; left: -9999px; top: calc(8px + var(--safe-top)); z-index: 100; background: var(--surface); color: var(--blue); padding: 10px 14px; border-radius: var(--radius-control); box-shadow: var(--shadow-float); font-weight: 600; }
.skip:focus { left: 8px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* ---------- Utilities ---------- */
.muted { color: var(--ink-2); } .subtle { color: var(--ink-3); }
/* Numbers that order the day (times, amounts, counts): Barlow Semi Condensed, tabular. */
.money, .num { font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: 0; }
.nowrap { white-space: nowrap; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.wrap-anywhere { overflow-wrap: anywhere; }
.right { text-align: right; } .center { text-align: center; }
.strong { font-weight: 600; }
.stack { display: grid; gap: var(--space-3); align-content: start; } .stack-sm { display: grid; gap: var(--space-2); } .stack-lg { display: grid; gap: var(--space-5); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.spread { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; justify-content: space-between; }
.spread > * { min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 960px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.mt-0 { margin-top: 0 !important; } .mb-0 { margin-bottom: 0 !important; } .mt-2 { margin-top: var(--space-2); } .mt-4 { margin-top: var(--space-4); }

/* ---------- Page ---------- */
.page { width: 100%; max-width: var(--content-w); margin: 0 auto; padding: 20px calc(var(--gutter) + var(--safe-right)) 32px calc(var(--gutter) + var(--safe-left)); min-width: 0; }
.page-narrow { max-width: 720px; }
.page-wide { max-width: none; }
.page-head { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h1 { margin: 0; min-width: 0; }
.page-head .lede, .lede { color: var(--ink-2); margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: var(--fs-15); margin-bottom: 4px; }
.back-link:hover { color: var(--ink); }
.section { margin-top: var(--space-5); }
.section-title { font-size: var(--fs-15); font-weight: 700; color: var(--ink-2); margin: 24px 0 8px; letter-spacing: 0; }
@media (min-width: 960px) { .page { padding: 32px 32px 48px; } }
/* On phones the top bar already shows the screen's name: a heading that only repeats it is kept for screen readers. */
@media (max-width: 959px) {
  .is-title-echo { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .page-head:has(> .is-title-echo) > .page-actions { margin-left: auto; }
  .page-head:has(> .is-title-echo:only-child) { margin: 0; }
}

/* ---------- Panels (cards) ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; min-width: 0; }
.card > :first-child { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > .card-head { padding: 14px 16px 0; }
.card-foot { margin: 14px -16px -16px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-sunk); border-radius: 0 0 var(--radius) var(--radius); }
.card-link { display: block; color: inherit; text-decoration: none; transition: border-color .12s; }
.card-link:hover { color: inherit; border-color: var(--line-firm); }
.card-muted { background: var(--surface-sunk); }
@media (min-width: 960px) { .card { padding: 20px; } .card-foot { margin: 16px -20px -20px; padding: 12px 20px; } .card-flush > .card-head { padding: 16px 20px 0; } .card.card-flush { padding: 0; } }

/* ---------- Buttons: primary (blue), secondary (.btn), quiet, danger, hi-vis (needs action now), crew 56px ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: var(--radius-control);
  border: 1px solid var(--line-firm); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-16); font-weight: 600; line-height: 1.15;
  cursor: pointer; text-decoration: none; text-align: center; white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background-color .12s, border-color .12s, color .12s; }
.btn:hover { border-color: var(--line-control); background: var(--surface-sunk); color: var(--ink); text-decoration: none; }
.btn:active { transform: translateY(1px); background: var(--surface-press); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled=true] { opacity: .5; cursor: not-allowed; transform: none; }
.btn[aria-busy=true] { cursor: progress; }
.btn svg { flex: none; }
.btn-primary { background: var(--blue); color: var(--blue-ink); border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); color: var(--blue-ink); }
.btn-primary:active { background: var(--blue-hover); }
.btn-quiet, .btn-ghost { background: transparent; border-color: transparent; color: var(--blue); }
.btn-quiet:hover, .btn-ghost:hover { background: var(--blue-soft); border-color: transparent; color: var(--blue-hover); }
.btn-quiet:active, .btn-ghost:active { background: var(--blue-soft); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
.btn-danger-outline { color: var(--danger); border-color: var(--danger-line); }
.btn-danger-outline:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
/* Hi-vis: only for the thing that needs doing now (Start job, overdue, the Needs-you count). Never decorative. */
.btn-hivis { background: var(--hivis); color: var(--hivis-ink); border-color: var(--hivis); font-weight: 700; }
.btn-hivis:hover { background: var(--hivis-hover); border-color: var(--hivis-hover); color: var(--hivis-ink); }
.btn-hivis:active { background: var(--hivis-hover); }
.btn-link { background: none; border: none; padding: 0 4px; min-height: 44px; color: var(--blue); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.btn-link:hover { background: none; color: var(--blue-hover); }
/* A button that reads like a link inside a sentence. */
.link-button { display: inline; padding: 0; margin: 0; border: 0; background: none; color: var(--blue); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-button:hover { color: var(--blue-hover); }
.btn-small { min-height: 36px; padding: 0 12px; font-size: var(--fs-15); gap: 6px; }
.btn-large { min-height: 52px; padding: 0 22px; font-size: var(--fs-18); }
/* The crew's primary actions: 56px, one hand, gloves. */
.btn-crew, .btn-xl { min-height: 56px; padding: 0 24px; font-size: var(--fs-18); font-weight: 700; border-radius: var(--radius-control); }
.btn-block { display: flex; width: 100%; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-small { width: 36px; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }
/* On phones (and any touch screen) every button is at least 44px tall, the small ones too, and links that act as buttons. */
@media (max-width: 959px), (pointer: coarse) {
  .btn-small { min-height: 44px; }
  .btn-icon.btn-small { width: 44px; }
  .btn-link { min-height: 44px; display: inline-flex; align-items: center; }
  .link-button { display: inline-flex; align-items: center; min-height: 44px; vertical-align: middle; }
}
/* A bar of primary actions fixed above the tab bar on phones, in thumb reach (crew Start / Complete). In the page on desktop. */
.action-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.action-bar > .btn { flex: 1 1 0; }
@media (max-width: 959px) {
  .action-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; padding: 12px calc(16px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(16px + var(--safe-left));
    background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow-float); }
  .has-tabbar .action-bar { bottom: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: 12px; }
  .has-action-bar .main { padding-bottom: calc(var(--tabbar-h) + 84px + var(--safe-bottom)); }
}
/* "Still trying… Cancel": a request has waited 8 seconds (ui.js stillTrying). */
.still-trying { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; color: var(--ink-2); font-size: var(--fs-15); font-weight: 600; }
.still-trying .spin { width: 14px; height: 14px; border-width: 2px; }
.still-trying .btn-link { min-height: 44px; padding: 0 6px; font-size: inherit; }

/* ---------- Forms: inputs, selects, checkboxes, switches, segmented controls ---------- */
.form { display: grid; gap: 16px; min-width: 0; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-row { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } .form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.field { min-width: 0; }
.field label, .label { display: block; font-weight: 600; margin-bottom: 6px; font-size: var(--fs-15); color: var(--ink); }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea, .input {
  display: block; width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-control); border-radius: var(--radius-control);
  font: inherit; font-size: var(--fs-16); line-height: 1.35; background: var(--surface); color: var(--ink); transition: border-color .12s, box-shadow .12s; }
.field textarea { min-height: 88px; resize: vertical; }
.field select, select.input { appearance: none; -webkit-appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%231B2420' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
.field input::placeholder, .field textarea::placeholder, .input::placeholder { color: var(--ink-3); opacity: 1; }
.field input:hover:not(:disabled):not([readonly]), .field select:hover:not(:disabled), .field textarea:hover:not(:disabled) { border-color: var(--ink-2); }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: none; border-color: var(--blue); box-shadow: var(--ring); }
.field input:disabled, .field select:disabled, .field textarea:disabled, .field input[readonly] { background: var(--surface-sunk); color: var(--ink-2); border-color: var(--line-firm); cursor: not-allowed; }
.field input[readonly] { cursor: text; }
.field input[type=date], .field input[type=time], .field input[type=datetime-local] { min-width: 0; }
.field-check label { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; font-size: var(--fs-16); cursor: pointer; margin: 0; min-height: 44px; padding-top: 10px; }
.field-check input, .choice input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--blue); cursor: pointer; }
.field [aria-invalid], .input[aria-invalid] { border-color: var(--danger) !important; }
.field [aria-invalid]:focus { box-shadow: 0 0 0 3px rgba(179, 38, 30, .25); }
.hint { margin: 6px 0 0; color: var(--ink-2); font-size: var(--fs-15); }
.req { color: var(--danger); }
.field-msg, .form-error { margin: 6px 0 0; color: var(--danger); font-size: var(--fs-15); font-weight: 600; }
.form-error { padding: 10px 12px; background: var(--danger-soft); border: 1px solid var(--danger-line); border-radius: var(--radius-control); margin: 0; }
.field-msg:empty, .form-error:empty { display: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; font-size: var(--fs-15); }
/* Radio/checkbox cards: <label class="choice"><input type=radio> <span><strong>Title</strong><span class="hint">…</span></span></label> */
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line-firm); border-radius: var(--radius-control); background: var(--surface); cursor: pointer; transition: border-color .12s, background-color .12s; }
.choice:hover { border-color: var(--line-control); }
.choice:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue); }
.choice:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; }
.choice > span { display: grid; gap: 2px; min-width: 0; }
.field .choice, .choices .choice { display: flex; margin: 0; font-weight: 400; font-size: var(--fs-16); }
.choice strong { font-weight: 600; }
.choice .hint { margin-top: 0; }
.input-group { display: flex; gap: 8px; align-items: stretch; }
.input-group > :first-child { flex: 1 1 auto; min-width: 0; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 84px !important; }
.password-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); min-height: 44px; min-width: 44px; padding: 0 10px; border: 0; background: none; color: var(--blue); font: inherit; font-weight: 600; font-size: var(--fs-15); cursor: pointer; border-radius: var(--radius-control); }
.password-toggle:hover { background: var(--blue-soft); }
.password-toggle:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }

/* Switch: field({ type: 'switch' }) -> <label class="switch"><input type=checkbox role=switch><span class="switch-track"></span> Label</label> */
.switch, .field label.switch { position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; font-weight: 500; font-size: var(--fs-16); margin: 0; }
.switch input { position: absolute; left: 0; top: 50%; transform: translateY(-50%); opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.switch-track { position: relative; flex: none; width: 44px; height: 26px; border-radius: var(--radius-full); background: var(--line-firm); transition: background-color .15s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--blue); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--blue); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .5; }

/* Segmented control. Radios (ui.js segmented()): <fieldset class="seg"><legend>…</legend><div class="seg-track"><label><input type=radio><span>Day</span></label>…
   Or links/buttons in .segmented with aria-current / aria-pressed / aria-selected. */
.seg-track, .segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface-press); border-radius: calc(var(--radius-control) + 3px); max-width: 100%; }
.seg-track label { position: relative; display: inline-flex; margin: 0 !important; }
.seg-track input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-track span, .segmented > a, .segmented > button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: var(--radius-control);
  background: transparent; color: var(--ink-2); font: inherit; font-size: var(--fs-15); font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.seg-track span:hover, .segmented > a:hover, .segmented > button:hover { color: var(--ink); }
.seg-track input:checked + span, .segmented > [aria-current=page], .segmented > [aria-current=true], .segmented > [aria-pressed=true], .segmented > [aria-selected=true] {
  background: var(--surface); color: var(--ink); border-color: var(--line-firm); }
.seg-track input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 1px; }
@media (max-width: 959px), (pointer: coarse) { .seg-track span, .segmented > a, .segmented > button { min-height: 44px; } }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .field { flex: 1 1 220px; }
.search { position: relative; flex: 1 1 220px; min-width: 0; }
.search input { padding-left: 40px !important; }
.search > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }

/* ---------- Badges, status chips, avatars ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius-full); font-size: .85rem; font-weight: 600; line-height: 1.5;
  background: var(--surface-press); color: var(--ink-2); white-space: nowrap; vertical-align: middle; border: 1px solid transparent; }
.badge svg { flex: none; width: 14px; height: 14px; }
.badge-ok, .badge-done { background: var(--done-soft); color: var(--done); } .badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); } .badge-brand, .badge-blue, .badge-info { background: var(--blue-soft); color: var(--blue); }
.badge-hivis { background: var(--hivis); color: var(--hivis-ink); font-weight: 700; }
.badge-ink { background: var(--ink); color: #fff; }
.badge-outline { background: transparent; border-color: var(--line-firm); }
.badge-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
/* A count: "3" on Needs you. */
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 7px; border-radius: var(--radius-full);
  font-family: var(--font-num); font-weight: 700; font-size: var(--fs-15); font-variant-numeric: tabular-nums; background: var(--surface-press); color: var(--ink); }
.count-hivis { background: var(--hivis); color: var(--hivis-ink); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: var(--radius-full); border: 1px solid var(--line-firm); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs-15); font-weight: 600; cursor: pointer; text-decoration: none; }
.chip:hover { border-color: var(--line-control); color: var(--ink); }
.chip[aria-pressed=true], .chip[aria-current=true], .chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }
@media (max-width: 959px), (pointer: coarse) { .chip { min-height: 44px; } }
.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-weight: 700; font-size: var(--fs-15); letter-spacing: .01em; }
.avatar-sm { width: 30px; height: 30px; font-size: var(--fs-13); }
.avatar-lg { width: 52px; height: 52px; font-size: var(--fs-18); }
.color-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ink-2); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; min-width: 0; }
.list > li { min-width: 0; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; min-height: 56px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit; min-width: 0; }
a.row, button.row { cursor: pointer; transition: border-color .12s, background-color .12s; font: inherit; text-align: left; width: 100%; }
a.row:hover, button.row:hover { color: inherit; border-color: var(--line-firm); }
.row-main { flex: 1 1 auto; min-width: 0; display: grid; gap: 2px; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { color: var(--ink-2); font-size: var(--fs-15); overflow-wrap: anywhere; }
.row-end { flex: none; display: flex; align-items: center; gap: 8px; text-align: right; }
.row-lead { flex: none; }
.row .chev { color: var(--ink-3); flex: none; }
/* A list inside a card: rows separated by lines instead of boxes. */
.list-flush { gap: 0; }
.list-flush > li + li > .row, .list-flush > .row + .row { border-top: 1px solid var(--line); }
.list-flush .row { border: 0; border-radius: 0; box-shadow: none !important; }
.list-flush a.row:hover { background: var(--surface-sunk); }
@media (max-width: 559px) { .row-stack-phone { flex-wrap: wrap; } .row-stack-phone .row-main { flex: 1 1 0; } .row-stack-phone .row-end { width: 100%; justify-content: flex-start; text-align: left; } }

/* Key/value pairs: <dl class="kv"><div><dt>Phone</dt><dd>555-0100</dd></div></dl> */
.kv { display: grid; gap: 10px; margin: 0; }
.kv > div { display: grid; gap: 2px; min-width: 0; }
.kv dt { color: var(--ink-2); font-size: var(--fs-15); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (min-width: 640px) { .kv-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kv-inline > div { grid-template-columns: 160px minmax(0, 1fr); gap: 12px; } }

/* ---------- Stats ---------- */
.stats { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
@media (min-width: 960px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; } }
.stat { display: grid; gap: 2px; align-content: start; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: inherit; text-decoration: none; min-width: 0; }
a.stat { transition: border-color .12s; }
a.stat:hover { color: inherit; border-color: var(--line-firm); }
.stat-label { color: var(--ink-2); font-size: var(--fs-15); font-weight: 600; overflow-wrap: anywhere; }
.stat-value { font-family: var(--font-num); font-size: var(--fs-28); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; color: var(--ink); }
.stat-sub { color: var(--ink-2); font-size: var(--fs-13); }
.stat-warn .stat-value { color: var(--warn); } .stat-danger .stat-value { color: var(--danger); } .stat-ok .stat-value { color: var(--done); }

/* ---------- Tables (stacked rows below 640px) ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-15); background: var(--surface); }
.table th, .table td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table th { font-size: var(--fs-13); font-weight: 600; color: var(--ink-2); background: var(--surface-sunk); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-sunk); }
.table .num, .table .right, .table .money { text-align: right; }
.table a { font-weight: 600; }
.table tr[data-href] { cursor: pointer; }
@media (max-width: 639px) {
  .table-wrap:has(.table-collapse) { border: 0; background: none; overflow: visible; }
  .table-collapse, .table-collapse tbody, .table-collapse tr, .table-collapse td { display: block; width: 100%; }
  .table-collapse thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-collapse { background: none; }
  .table-collapse tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 0; margin-bottom: 8px; }
  .table-collapse td { display: flex; gap: 12px; justify-content: space-between; border: 0; padding: 6px 14px; text-align: right; overflow-wrap: anywhere; }
  .table-collapse td::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--ink-2); font-size: var(--fs-15); font-weight: 600; text-align: left; }
  .table-collapse td[data-label=""]::before, .table-collapse td:not([data-label])::before { display: none; }
  .table-collapse td.cell-title { font-weight: 600; font-size: var(--fs-16); text-align: left; justify-content: flex-start; }
  .table-collapse tbody tr:hover td { background: none; }
}

/* ---------- States: loading, empty, error, callouts ---------- */
.loading { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 32px 16px; color: var(--ink-2); font-weight: 500; }
.spin { width: 18px; height: 18px; border: 2.5px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: var(--surface-press); border-radius: var(--radius-control); min-height: 16px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.empty { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 32px 20px; color: var(--ink-2); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.empty h3 { margin: 0; color: var(--ink); font-size: var(--fs-18); }
.empty p { margin: 0; max-width: 46ch; }
.empty .btn, .empty .btn-group { margin-top: 10px; }
.empty-icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 50%; background: var(--surface-press); color: var(--ink-2); margin-bottom: 6px; }
.error-box { display: grid; gap: 10px; justify-items: start; padding: 16px; border-radius: var(--radius); background: var(--danger-soft); border: 1px solid var(--danger-line); color: var(--danger); }
.error-box p { margin: 0; font-weight: 600; }
.error-box .small { font-weight: 500; color: var(--ink); }
.error-box-missing { background: var(--surface); border-color: var(--line); color: var(--ink); }
.error-box-missing .small { color: var(--ink-2); font-weight: 400; }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-control); border: 1px solid var(--blue-line); background: var(--blue-soft); color: var(--ink); }
.callout > svg { flex: none; margin-top: 2px; color: var(--blue); }
.callout > div { min-width: 0; }
.callout p { margin: 0; }
.callout-ok { background: var(--done-soft); border-color: var(--done-line); } .callout-ok > svg { color: var(--done); }
.callout-warn { background: var(--warn-soft); border-color: var(--warn-line); } .callout-warn > svg { color: var(--warn); }
.callout-danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); } .callout-danger > svg { color: var(--danger); }
.callout-muted { background: var(--surface-sunk); border-color: var(--line); color: var(--ink-2); } .callout-muted > svg { color: var(--ink-3); }
.progress { height: 8px; border-radius: var(--radius-full); background: var(--surface-press); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--blue); border-radius: inherit; transition: width .3s; }

/* ---------- Tabs (ui.js tabs()): a tablist with an underline on the chosen tab ---------- */
.tabs-list { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs-list::-webkit-scrollbar { display: none; }
.tabs-tab { position: relative; flex: none; min-height: 44px; padding: 0 12px; border: 0; background: none; color: var(--ink-2); font: inherit; font-size: var(--fs-16); font-weight: 600; cursor: pointer; white-space: nowrap; border-radius: var(--radius-control) var(--radius-control) 0 0; }
.tabs-tab:hover { color: var(--ink); }
.tabs-tab[aria-selected=true] { color: var(--ink); }
.tabs-tab[aria-selected=true]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--blue); }
.tabs-tab:focus-visible { outline: 3px solid var(--blue); outline-offset: -3px; }
.tabs-panel:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }

/* ---------- The job ticket (ui.js ticket()) ----------
   A work-order slip: a time stub on the left (start big, window small; its colour carries status), a perforation (a
   dashed rule with two half-circle notches) and the body. Nothing else uses the perforation, so it always means a job.
   Inside a white panel set --notch-bg: var(--surface) so the notches match what is behind them. */
.ticket { --stub-w: 104px; --stub-bg: var(--blue-soft); --stub-ink: var(--ink); --stub-ink-2: var(--ink-2); --notch-bg: var(--ground); --crew: transparent;
  position: relative; display: grid; grid-template-columns: var(--stub-w) minmax(0, 1fr); min-height: 76px; margin: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-ticket); color: var(--ink); text-decoration: none; text-align: left;
  font: inherit; width: 100%; padding: 0; transition: border-color .12s; -webkit-tap-highlight-color: transparent; }
a.ticket, button.ticket { cursor: pointer; }
a.ticket:hover, button.ticket:hover { color: var(--ink); border-color: var(--line-control); }
.ticket:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: var(--radius-ticket); }
.card .ticket, .ticket-on-surface { --notch-bg: var(--surface); }
/* The notches sit on the perforation, cut into the top and bottom edges. */
.ticket::before, .ticket::after { content: ""; position: absolute; z-index: 1; left: calc(var(--stub-w) - 8px); width: 14px; height: 8px; background: var(--notch-bg); border: 1px solid var(--line); pointer-events: none; }
.ticket::before { top: -1px; border-top: 0; border-radius: 0 0 8px 8px; }
.ticket::after { bottom: -1px; border-bottom: 0; border-radius: 8px 8px 0 0; }
.ticket-stub { display: grid; align-content: center; justify-items: start; gap: 3px; padding: 12px 8px 12px 12px; min-width: 0;
  background: var(--stub-bg); color: var(--stub-ink); border-right: 2px dashed var(--line); border-radius: calc(var(--radius-ticket) - 1px) 0 0 calc(var(--radius-ticket) - 1px);
  font-family: var(--font-num); font-variant-numeric: proportional-nums; line-height: 1; }
.ticket-time { display: flex; align-items: baseline; gap: 3px; font-size: var(--fs-28); font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.ticket-mer { font-size: var(--fs-13); font-weight: 700; letter-spacing: 0; }
.ticket-window { font-size: var(--fs-13); font-weight: 600; color: var(--stub-ink-2); line-height: 1.2; overflow-wrap: anywhere; }
.ticket-notime { font-family: var(--font-body); font-size: var(--fs-15); font-weight: 700; line-height: 1.15; }
.ticket-body { display: grid; align-content: center; gap: 3px; padding: 12px 14px 12px 16px; min-width: 0; box-shadow: inset -5px 0 0 var(--crew); border-radius: 0 calc(var(--radius-ticket) - 1px) calc(var(--radius-ticket) - 1px) 0; }
.ticket-title { font-size: var(--fs-16); font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; color: var(--ink); }
.ticket-line { display: flex; gap: 6px; align-items: flex-start; font-size: var(--fs-15); color: var(--ink-2); line-height: 1.3; overflow-wrap: anywhere; min-width: 0; }
.ticket-line svg { flex: none; width: 16px; height: 16px; margin-top: 1px; color: var(--ink-3); }
.ticket-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
/* Status: the stub's colour, always with a word on the ticket (or the status chip). */
.ticket-in_progress { --stub-bg: var(--ink); --stub-ink: #FFFFFF; --stub-ink-2: #C9D0CB; }
.ticket-completed, .ticket-done { --stub-bg: var(--done-soft); --stub-ink: var(--done); --stub-ink-2: var(--done); }
.ticket-unscheduled, .ticket-needs_time, .ticket-waiting { --stub-bg: var(--warn-soft); --stub-ink: var(--warn); --stub-ink-2: var(--warn); }
.ticket-overdue, .ticket-late { --stub-bg: var(--hivis); --stub-ink: var(--hivis-ink); --stub-ink-2: var(--hivis-ink); }
.ticket-cancelled { --stub-bg: var(--surface-press); --stub-ink: var(--ink-2); --stub-ink-2: var(--ink-2); }
.ticket-cancelled .ticket-title { text-decoration: line-through; text-decoration-color: var(--ink-3); color: var(--ink-2); }
/* The crew's next job: the 48px time. */
.ticket-lg { --stub-w: 152px; min-height: 112px; }
.ticket-lg .ticket-time { font-size: var(--fs-48); }
.ticket-lg .ticket-mer { font-size: var(--fs-16); }
.ticket-lg .ticket-window { font-size: var(--fs-15); }
.ticket-lg .ticket-title { font-size: var(--fs-18); }
@media (max-width: 359px) { .ticket { --stub-w: 90px; } .ticket-time { font-size: var(--fs-22); } .ticket-body { padding-left: 14px; padding-right: 12px; } }
@media (max-width: 389px) { .ticket-lg { --stub-w: 124px; } .ticket-lg .ticket-time { font-size: var(--fs-36); } .ticket-lg .ticket-mer { font-size: var(--fs-15); } }
.tickets { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
/* A ticket settling into place when booked (add .is-settling once, in answer to the action). */
.ticket.is-settling { animation: ticket-settle .3s cubic-bezier(.2, .8, .3, 1); }
@keyframes ticket-settle { from { transform: translateY(-6px); border-color: var(--blue); } }
/* A check that draws itself on Complete: icon(..., { class: 'icon-draw' }). */
.icon-draw path { stroke-dasharray: 24; stroke-dashoffset: 24; animation: draw .3s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Status chips (ui.js statusChip()): colour plus a word plus an icon. */
.status { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px 2px 7px; border-radius: var(--radius-full); font-size: .85rem; font-weight: 600; line-height: 1.5; white-space: nowrap; vertical-align: middle;
  background: var(--surface-press); color: var(--ink-2); }
.status svg { flex: none; width: 14px; height: 14px; }
.status-blue { background: var(--blue-soft); color: var(--blue); }
.status-done { background: var(--done-soft); color: var(--done); }
.status-warn { background: var(--warn-soft); color: var(--warn); }
.status-danger { background: var(--danger-soft); color: var(--danger); }
.status-hivis { background: var(--hivis); color: var(--hivis-ink); font-weight: 700; }
.status-ink { background: var(--ink); color: #fff; }

/* ---------- Dialogs and sheets: a dialog on desktop, a sheet from the bottom on phones ---------- */
.dialog { border: 0; border-radius: var(--radius-sheet); padding: 20px 24px 24px; width: min(92vw, 480px); max-height: min(88vh, 760px); box-shadow: var(--shadow-float); color: var(--ink); background: var(--surface); overflow: auto; }
.dialog::backdrop { background: rgba(27, 36, 32, .5); }
.dialog > h2:first-child { margin: 0 0 8px; font-size: var(--fs-18); padding-right: 32px; }
.dialog > p { color: var(--ink-2); }
.dialog > .form-actions, .dialog-actions { margin-top: 20px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: var(--fs-18); padding-top: 8px; }
.dialog-close { margin: -4px -12px 0 0; color: var(--ink-2); }
.dialog-wide { width: min(94vw, 680px); }
.dialog.sheet { padding: 0; }
.dialog[open] { animation: dialog-in .16s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 559px) {
  .dialog { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--radius-sheet) var(--radius-sheet) 0 0; max-height: 92vh; max-height: 92dvh;
    padding: 20px calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left)); }
  .dialog:not(.sheet)::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line-firm); margin: -8px auto 12px; }
  .dialog.sheet { padding-bottom: var(--safe-bottom); }
  .dialog[open] { animation: sheet-up .24s cubic-bezier(.2, .8, .3, 1); }
  .dialog > .form-actions, .dialog-actions { flex-direction: column-reverse; align-items: stretch; }
}
@keyframes sheet-up { from { transform: translateY(100%); } }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: min(calc(100vw - 32px), 440px); pointer-events: none; }
.has-tabbar #toasts { bottom: calc(var(--tabbar-h) + 12px + var(--safe-bottom)); }
@media (min-width: 960px) { .has-tabbar #toasts { bottom: 24px; } #toasts { left: auto; right: 24px; transform: none; } }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: var(--radius-control); background: var(--ink); color: #fff; box-shadow: var(--shadow-float); pointer-events: auto; font-weight: 500; animation: toast-in .18s ease-out; }
.toast > svg { flex: none; margin-top: 1px; }
.toast-ok > svg { color: #8FD3A8; }
.toast-error { background: var(--danger); }
.toast-warn { background: #6B4100; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- App layout ---------- */
.bare { min-height: 100vh; min-height: 100dvh; }
.layout { min-height: 100vh; min-height: 100dvh; }
.main { display: block; min-width: 0; }
.main:focus { outline: none; }
.has-tabbar .main { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom)); }
/* The product's mark: a ticket stub in truck blue. */
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-control); background: var(--blue); color: #fff; flex: none; }
.brand-mark svg { width: 20px; height: 20px; }

/* Phone top bar: the screen's name and one action. */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; min-height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) calc(8px + var(--safe-right)) 0 calc(16px + var(--safe-left));
  background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar a { color: inherit; text-decoration: none; }
.topbar-titles { display: grid; min-width: 0; flex: 1 1 auto; line-height: 1.2; }
.topbar-company { font-size: var(--fs-13); font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title { font-size: var(--fs-18); font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.account-link { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; border-radius: 50%; flex: none; }
.account-link:focus-visible { outline-offset: -2px; }

/* Desktop rail (asphalt): company, the nav in its sections (Work, Customers, Money, Business), Settings, Help and
   Upgrade side by side, the account and Sign out at the bottom. */
.sidenav { display: none; }
.rail-head { flex: none; display: flex; align-items: center; gap: 12px; padding: calc(12px + var(--safe-top)) 16px 8px calc(20px + var(--safe-left)); color: var(--rail-ink); text-decoration: none; }
.rail-head:hover { color: var(--rail-ink); }
.rail-head .brand-text { display: grid; min-width: 0; line-height: 1.2; gap: 2px; }
.rail-head .company-name { font-size: var(--fs-16); letter-spacing: -.01em; white-space: normal; overflow-wrap: anywhere; color: var(--rail-ink); }
.rail-head .brand-name { font-size: var(--fs-13); font-weight: 600; color: var(--rail-ink-3); }
/* The nav scrolls between the company and the account when the screen is short; both stay put. */
.rail-nav { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--rail-line) transparent; }
.nav-list { list-style: none; margin: 0; padding: 4px 12px; display: grid; gap: 2px; }
.nav-list-slot { margin-top: auto; padding-top: 12px; padding-bottom: 12px; }
.nav-link { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-control); color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: var(--fs-16); }
.nav-link svg { color: var(--ink-3); flex: none; }
.nav-link:hover { background: var(--surface-press); color: var(--ink); }
.nav-link[aria-current=page] { background: var(--blue); color: #fff; }
.nav-link[aria-current=page] svg { color: #fff; }
/* A section's label: quiet, sentence case, never all caps. */
.nav-group-label { margin: 0; padding: 14px 24px 4px; font-size: var(--fs-13); font-weight: 600; line-height: 1.25; color: var(--ink-2); }
.sidenav .nav-group-label { color: var(--rail-ink-3); }
.sidenav .nav-link { color: var(--rail-ink-2); }
.sidenav .nav-link svg { color: var(--rail-ink-3); }
.sidenav .nav-link:hover { background: var(--rail-hover); color: #fff; }
.sidenav .nav-link:hover svg { color: var(--rail-ink-2); }
.sidenav .nav-link[aria-current=page], .sidenav .nav-link[aria-current=page]:hover { background: var(--blue); color: #fff; }
.sidenav .nav-link[aria-current=page] svg { color: #fff; }
.sidenav :focus-visible { outline-color: #9DB4F5; }
.sidenav-foot { flex: none; padding: 6px 8px calc(6px + var(--safe-bottom)) calc(12px + var(--safe-left)); border-top: 1px solid var(--rail-line); display: flex; align-items: center; gap: 4px; }
.me-link { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 10px; border-radius: var(--radius-control); color: inherit; text-decoration: none; min-width: 0; }
.sidenav .me-link { flex: 1 1 auto; min-height: 44px; padding: 4px 8px; }
/* Sign out beside the account: an icon button with its name for screen readers and as a tooltip. */
.sidenav .nav-signout { flex: none; width: 44px; min-height: 44px; padding: 0; justify-content: center; }
.me-link:hover, .me-link[aria-current=page] { background: var(--surface-press); color: inherit; }
.me-text { display: grid; min-width: 0; line-height: 1.25; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-role { font-size: var(--fs-13); color: var(--ink-2); }
.sidenav .me-link { color: var(--rail-ink); }
.sidenav .me-link:hover, .sidenav .me-link[aria-current=page] { background: var(--rail-hover); color: #fff; }
.sidenav .me-role { color: var(--rail-ink-3); }
.sidenav .avatar { background: var(--blue-soft); color: var(--blue); }
.nav-button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--radius-control); background: none; color: var(--ink-2); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.nav-button:hover { background: var(--surface-press); color: var(--ink); }
.sidenav .nav-button { color: var(--rail-ink-2); }
.sidenav .nav-button svg { color: var(--rail-ink-3); }
.sidenav .nav-button:hover { background: var(--rail-hover); color: #fff; }

/* Bottom tab bar (phones): four items and More. Labels are short enough to fit at 320px; they never truncate. */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; height: calc(var(--tabbar-h) + var(--safe-bottom)); padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--surface); border-top: 1px solid var(--line); }
.tab { position: relative; flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 0 5px;
  color: var(--ink-2); text-decoration: none; font: inherit; font-size: .8rem; font-weight: 600; line-height: 1.1; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tab span { white-space: nowrap; letter-spacing: -.005em; }
.tab svg { width: 24px; height: 24px; }
.tab:hover { color: var(--ink); }
.tab[aria-current=page], .tab[aria-expanded=true] { color: var(--blue); }
.tab[aria-current=page]::before { content: ""; position: absolute; top: -1px; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--blue); }
.tab[aria-current=page] svg { stroke-width: 2.25; }
.tab:focus-visible { outline-offset: -4px; }
.sheet-head { display: grid; gap: 2px; padding: 4px 24px 8px; line-height: 1.25; }
.sheet-head .company-name { font-size: var(--fs-18); white-space: normal; overflow-wrap: anywhere; }
.sheet-head .brand-name { font-size: var(--fs-13); font-weight: 600; color: var(--ink-2); }
.sheet-list { list-style: none; margin: 0; padding: 4px 12px 16px; display: grid; gap: 2px; }
.sheet-list .nav-link, .sheet-list .nav-button { min-height: 48px; font-size: var(--fs-16); }
/* The More sheet: the rail's sections as two columns of 48px rows, Settings, Help and Upgrade, then the account. */
.more-sheet .sheet-head { padding-bottom: 4px; }
.more-sheet .nav-group-label { padding: 10px 24px 2px; }
.sheet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 8px; padding: 0 12px; }
.sheet-grid .nav-link, .sheet-grid .nav-button { min-height: 48px; gap: 10px; padding: 0 10px; line-height: 1.2; }
.more-sheet .nav-group-end, .more-sheet .sheet-account { margin: 8px 12px 0; padding-top: 6px; border-top: 1px solid var(--line); }
.more-sheet .nav-group-end .sheet-grid, .more-sheet .sheet-account { padding-left: 0; padding-right: 0; }
.more-sheet .sheet-account { padding-bottom: 12px; }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line-firm); margin: 8px auto 4px; }

@media (min-width: 960px) {
  .layout { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .topbar, .tabbar { display: none; }
  .has-tabbar .main { padding-bottom: 0; }
  /* With a mouse the rail's rows are shorter, so an owner's whole nav (four sections of up to four items, Settings, Help
     and Upgrade) fits a 1280x720 window with nothing to scroll; touch screens keep 44px rows and scroll the list. */
  .sidenav .rail-nav { padding-top: 2px; }
  .sidenav .nav-list { padding: 0 12px; gap: 0; }
  .sidenav .nav-link { min-height: 28px; gap: 10px; font-size: var(--fs-15); }
  .sidenav .nav-link svg { width: 18px; height: 18px; }
  .sidenav .nav-group-label { padding: 8px 24px 2px; line-height: 16px; }
  .sidenav .nav-group:first-child .nav-group-label { padding-top: 2px; }
  /* Settings (and the operator console) at the bottom, Help and Upgrade side by side under it. */
  .sidenav .nav-group-end { margin-top: auto; padding-top: 8px; }
  .sidenav .nav-list-slot { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding-top: 2px; padding-bottom: 6px; }
  .sidenav .nav-group-end + .nav-list-slot { margin-top: 0; }
  @media (pointer: coarse) { .sidenav .nav-link { min-height: 44px; } }
  .sidenav { display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow: hidden; background: var(--rail); color: var(--rail-ink); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; scroll-behavior: auto !important; }
  .spin { animation: spin 1.6s linear infinite !important; }
  .icon-draw path { stroke-dashoffset: 0; }
}

@media print {
  .sidenav, .topbar, .tabbar, .action-bar, #toasts, .skip, .no-print { display: none !important; }
  body { background: #fff; }
  .layout { display: block; }
  .card { break-inside: avoid; }
  .has-tabbar .main { padding-bottom: 0; }
}
