/* ═══ Components (docs/UI_CONTROL_TOWER.md section 4, in the brand of docs/UI_BRAND.md) ═══════════════════════════
   Plain HTML strings built with esc() (helpers in js/core/ui.js: money, chip, prov, plate, tile, pageHead, kpiStrip,
   jumpTiles, cardHead, kv, miniTiles, sidePanel; the chart kit is js/core/charts.js), tokens only.
   Every control: hover --surface-2, focus-visible --focus-ring, active --surface-3, disabled .5 with aria-disabled.
   1. the desk components (buttons, status pills, chips, provenance, plates, tasks, strip, preview pane, sheet, banner,
      checks, fields, receipt, empty states, skeletons, toast, bulk bar, menu) on the dense control-tower scale;
   2. the newer control-tower primitives (segmented note, filter chips, live pill, mini tiles, side panel, stacks);
   3. the chart kit's marks (.ck);
   4. the feature sheets' controls brought onto the same scale (structure unchanged). Loaded after modern.css. */

/* ─── Type helpers ─── */
.money, .num { font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.money.loss { color: var(--money-loss); }
.money.in { color: var(--money-in); }
.money.zero, .money.none { color: var(--muted); }
.money.l { font: 600 var(--fs-money-l)/var(--lh-money-l) var(--font-head); letter-spacing: -.01em; }
.money.xl { font: 600 var(--fs-money-xl)/var(--lh-money-xl) var(--font-head); letter-spacing: -.01em; }
.id-no { font: 600 var(--fs-small)/var(--lh-small) var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ─── Kbd ─── */
kbd.kbd, .btn kbd {
  display: inline-block; min-width: 16px; padding: 0 4px; border-radius: var(--r-xs); text-align: center;
  font: 500 var(--fs-xs)/14px var(--font-mono); background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2);
}

/* ─── Buttons: btn-primary | btn-secondary | btn-ghost | btn-danger (+ btn-ai), one primary per region ─── */
.btn.btn-primary, .btn.btn-secondary, .btn.btn-ghost, .btn.btn-danger, .btn.btn-ai {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--control-h); padding: 0 10px;
  border-radius: var(--r-sm); border: 1px solid transparent; font: 500 var(--fs-small)/16px var(--font-ui); cursor: pointer;
  white-space: nowrap; text-decoration: none; box-shadow: none; filter: none;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.btn.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: var(--accent-shadow); font-weight: 600; }
.btn.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.btn-primary:active { box-shadow: none; }
.btn.btn-secondary { background: var(--surface); border-color: var(--line-2); color: var(--ink); }
.btn.btn-secondary:hover { background: var(--surface-2); border-color: var(--accent-line); }
.btn.btn-ghost { background: transparent; color: var(--ink-2); }
.btn.btn-ghost:hover { background: var(--surface-2); color: var(--accent-text); }
.btn.btn-danger { background: var(--surface); border-color: var(--crit-line); color: var(--crit-text); }
.btn.btn-danger:hover { background: var(--crit-soft); }
.btn.btn-ai { background: var(--ai-soft); border-color: var(--ai-line); color: var(--ai-text); }
.btn.btn-ai:hover { border-color: var(--ai); }
.btn.btn-secondary:active, .btn.btn-ghost:active, .btn.btn-danger:active { background: var(--surface-3); }
.btn.btn-sm { height: var(--control-h-sm); padding: 0 8px; font-size: var(--fs-note); }
.btn[aria-disabled="true"], .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.is-loading { position: relative; overflow: hidden; }
.btn.is-loading::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--accent); animation: aw-load 1s var(--ease) infinite; }
.btn kbd { display: none; margin-left: 2px; }
.btn.btn-primary kbd, .btn.primary kbd { background: color-mix(in srgb, var(--accent-ink) 18%, transparent); border-color: transparent; color: inherit; }
@media (hover: hover) and (min-width: 1024px) { .btn:hover kbd, .btn:focus-visible kbd { display: inline-block; } }
.link { background: none; border: 0; padding: 0; color: var(--accent-text); cursor: pointer; font-weight: 500; text-decoration: none; }
.link:hover { text-decoration: underline; }
.btn:focus-visible, .link:focus-visible, .prov:focus-visible, .tile:focus-visible, .task:focus-visible,
.jump:focus-visible, a.kpi:focus-visible, .chip:focus-visible, .ex-i:focus-visible { outline: none; box-shadow: var(--focus-ring); }
/* a segmented control and a tab strip clip their overflow (hidden, or auto to scroll on a phone), which cuts an outer ring
   to a sliver: their buttons draw the ring inside themselves */
.seg button:focus-visible, .views a:focus-visible, .views button:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }

/* ─── Status pill (core/status.js): five words, never colour alone; the same shape as .pill ─── */
.st {
  display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 7px; border-radius: var(--r-pill);
  font: 600 var(--fs-cap)/1 var(--font-ui); letter-spacing: .01em; white-space: nowrap; border: 1px solid transparent; vertical-align: middle;
}
.st > i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.st > svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; flex: none; }
.st-done { background: var(--good-soft); color: var(--good-text); }
.st-due { background: var(--warn-soft); color: var(--warn-text); }
.st-late { background: var(--crit-soft); color: var(--crit-text); }
.st-blocked { background: var(--block); color: var(--block-ink); }
.st-draft { background: transparent; color: var(--ink-2); border: 1px dashed var(--draft-line); }
.st-draft > i { display: none; }
.st-void { background: transparent; color: var(--muted); text-decoration: line-through; border-color: var(--line); }
.st-void > i { display: none; }
.st-info { background: var(--info-soft); color: var(--info-text); }
.st-sub { margin-left: 6px; font-size: var(--fs-meta); line-height: 15px; color: var(--muted); white-space: nowrap; }
/* tone bars: list rows and tasks carry a 3 px left bar in the same tone */
.tone-done, .tone-good { background: var(--good); }
.tone-due, .tone-warn { background: var(--warn); }
.tone-late, .tone-crit { background: var(--crit); }
.tone-blocked, .tone-block { background: var(--block); }
.tone-draft { background: var(--draft-line); }
.tone-void, .tone-none { background: transparent; }
.tone-info { background: var(--info); }
.tone-ai { background: var(--ai); }

/* ─── Word chips (chip()): "loss", "short", "owed", agent and info notes ─── */
.chip.chip-good, .chip.chip-done { background: var(--good-soft); color: var(--good-text); border-color: var(--good-line); }
.chip.chip-warn, .chip.chip-due { background: var(--warn-soft); color: var(--warn-text); border-color: var(--warn-line); }
.chip.chip-crit, .chip.chip-late, .chip.chip-loss { background: var(--crit-soft); color: var(--crit-text); border-color: var(--crit-line); }
.chip.chip-info { background: var(--info-soft); color: var(--info-text); border-color: transparent; }
.chip.chip-ai { background: var(--ai-soft); color: var(--ai-text); border-color: var(--ai-line); }
.chip.chip-neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }

/* ─── Provenance chip: every agent- or autofill-set value says where it came from ─── */
.prov {
  display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 7px; border-radius: var(--r-pill);
  border: 1px solid var(--ai-line); background: var(--ai-soft); color: var(--ai-text); font: 500 var(--fs-cap)/16px var(--font-ui);
  cursor: pointer; white-space: nowrap; vertical-align: middle; text-decoration: none;
}
.prov:hover { border-color: var(--ai); }

/* ─── Count chip ─── */
.cnt {
  display: inline-block; min-width: 16px; padding: 0 5px; border-radius: var(--r-pill); background: var(--surface-3);
  color: var(--ink-2); font: 600 var(--fs-xs)/16px var(--font-ui); text-align: center;
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
}
.cnt.crit { background: var(--crit); border-color: var(--crit); color: var(--crit-ink); }

/* ─── Plate: vehicle numbers ─── */
.plate {
  display: inline-block; padding: 0 4px; border: 1px solid var(--line-2); border-radius: var(--r-xs); background: var(--surface);
  color: var(--ink); font: 600 var(--fs-note)/16px var(--font-mono); letter-spacing: .04em; white-space: nowrap; vertical-align: baseline;
}
.plate-in { display: inline-flex; align-items: stretch; height: var(--control-h); border: 1px solid var(--line-2); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.plate-in > span { display: inline-grid; place-items: center; padding: 0 7px; background: var(--info); color: var(--info-ink); font: 600 var(--fs-note) var(--font-mono); letter-spacing: .06em; }
.plate-in > input { border: 0; outline: 0; min-width: 0; padding: 0 9px; background: transparent; color: var(--ink); font: 600 var(--fs-body) var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
.plate-in:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ─── Saved-view tabs ─── */
.views { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.views a, .views button {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--ink-2); font: 500 var(--fs-small)/16px var(--font-ui); white-space: nowrap; cursor: pointer; text-decoration: none; margin-bottom: -1px;
}
.views a:hover, .views button:hover { color: var(--ink); }
.views [aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent); font-weight: 600; }

/* ─── Group header: caps eyebrow, the count and the ₹ beside it ─── */
.grp {
  display: flex; align-items: center; gap: 8px; margin: 14px 0 5px; padding: 0 2px; min-height: 24px;
  font: 600 var(--fs-xs)/14px var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.grp .money { letter-spacing: 0; color: var(--ink); font-size: var(--fs-small); text-transform: none; }
.grp .gbtn { margin-left: auto; text-transform: none; letter-spacing: 0; }

/* ─── Task rows and job cards ─── */
.tasks { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--e1), var(--highlight); overflow: hidden; }
.task {
  position: relative; display: grid; grid-template-columns: 84px minmax(0, 1fr) 52px auto; align-items: center; gap: 10px;
  min-height: var(--row-h); padding: 5px 9px 5px 12px; border-top: 1px solid var(--line); cursor: pointer; list-style: none;
  transition: background var(--t-fast), transform var(--t-exit) var(--ease), opacity var(--t-exit);
}
.tasks > .task:first-child { border-top: 0; }
.task:hover { background: var(--surface-2); }
.task[aria-selected="true"] { background: var(--sel); }
.task > .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; height: auto; border-radius: 0; }
.t-money { text-align: right; font-weight: 600; font-size: var(--fs-body); line-height: 18px; align-self: start; padding-top: 1px; font-variant-numeric: tabular-nums; }
.t-main { min-width: 0; display: flex; flex-direction: column; }
.t-title { font-size: var(--fs-title-row); line-height: 18px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-why { font-size: var(--fs-note); line-height: 16px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-ai { font-size: var(--fs-note); line-height: 16px; color: var(--ai-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-clock { text-align: right; font: 500 var(--fs-note)/16px var(--font-mono); color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.t-clock.late { color: var(--crit-text); font-weight: 600; }
.t-clock.due { color: var(--warn-text); }
.t-act { display: flex; gap: 4px; align-items: center; justify-content: flex-end; }
.task.leaving { opacity: 0; transform: translateX(16px); }
.job { list-style: none; border-top: 1px solid var(--line); }
.job > header { display: flex; align-items: center; gap: 8px; min-height: var(--row-h); padding: 5px 9px 5px 12px; font-weight: 500; }
.job-rows { list-style: none; margin: 0; padding: 0; background: var(--bg); }
.job-rows .task { padding-left: 26px; }
body.density-cozy .task { min-height: var(--row-h-cozy); padding-top: 8px; padding-bottom: 8px; }
@media (max-width: 767px) {
  .task { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main money" "main clock" "act act"; gap: 2px 12px; padding: 10px 12px 10px 16px; }
  .t-main { grid-area: main; } .t-money { grid-area: money; } .t-clock { grid-area: clock; align-self: start; }
  .t-act { grid-area: act; justify-content: flex-start; margin-top: 8px; } .t-act:empty { display: none; }
  .t-title, .t-why, .t-ai { white-space: normal; }
}

/* ─── Number tile (strip): KPI cells; no tile without a link; a 3 px tone edge only when the number is bad ─── */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(max(128px, (100% - 56px) / 8), 1fr)); gap: 8px; }
a.tile, .strip .tile {
  position: relative; display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 8px 10px 7px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--ice-1), var(--surface) 36px), var(--surface); /* the KPI cell's quiet top light */
  color: var(--ink); text-decoration: none; text-align: left; box-shadow: var(--e1), var(--highlight); font: inherit;
  transition: border-color var(--t-fast), background var(--t-fast);
}
/* the KPI cell's turquoise hairline, once a strip: on its first tile (a tile wrapped in a list item counts as its wrapper) */
a.tile::before, .strip .tile::before { content: ""; position: absolute; left: 10px; top: 0; width: 28px; height: 2px; border-radius: 0 0 2px 2px; background: var(--rule); opacity: .75; pointer-events: none; display: none; }
.strip > .tile:first-child::before, .strip > :first-child > .tile::before { display: block; }
a.tile:hover, button.tile:hover { border-color: var(--accent-line); }
button.tile { cursor: pointer; }
.tile[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.tile-l { font-size: var(--fs-cap); line-height: 15px; font-weight: 600; letter-spacing: var(--ls-cap); text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile > b.money, .tile > b.num { font: 600 var(--fs-kpi)/var(--lh-kpi) var(--font-head); letter-spacing: -.01em; margin-top: 2px; }
.tile > b.money.xl { font-size: var(--fs-money-xl); line-height: var(--lh-money-xl); }
.tile > b small { font: 500 var(--fs-small)/1 var(--font-ui); color: var(--muted); }
.tile-sub { font-size: var(--fs-meta); line-height: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.bad, .tile.tone-bad-crit { border-left: 3px solid var(--crit); }
.tile.tone-bad-warn { border-left: 3px solid var(--warn); }
@media (max-width: 767px) {
  .strip { display: flex; overflow-x: auto; gap: 8px; margin: 0 calc(-1 * var(--gutter)) 4px; padding: 0 var(--gutter) 4px; scrollbar-width: none; }
  .strip .tile { flex: 0 0 auto; min-width: 140px; max-width: 220px; }
}

/* ─── Preview pane shell ─── */
.pv { position: sticky; top: 12px; max-height: calc(100vh - 88px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--e1), var(--highlight); padding: 12px 14px 14px; overscroll-behavior: contain; }
.pv > * + * { margin-top: 10px; }
.pv .grab, .sheet .grab { display: none; width: 40px; height: 4px; border-radius: 2px; background: var(--line-2); margin: 0 auto 10px; }
@media (max-width: 1023px) {
  .pv { position: fixed; left: 0; right: 0; bottom: 0; top: auto; max-height: 88vh; border-radius: var(--r-lg) var(--r-lg) 0 0; z-index: 75; transform: translateY(105%); transition: transform var(--t-sheet) var(--ease); box-shadow: var(--e3); padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); visibility: hidden; }
  .pv.open { transform: none; visibility: visible; }
  .pv .grab { display: block; }
}

/* ─── Sheet: a centred dialog on desktop, rising from the bottom on phones ─── */
.sheet {
  position: fixed; z-index: 80; left: 50%; top: 12vh; width: min(560px, calc(100vw - 32px)); max-height: 76vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--e3), var(--highlight); padding: 16px;
  transform: translateX(-50%);
}
.sheet[hidden] { display: none; }
@media (max-width: 767px) {
  .sheet { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 90vh; border-radius: var(--r-lg) var(--r-lg) 0 0; transform: none; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); }
  .sheet .grab { display: block; }
}

/* ─── Banner: ai | warn | crit | info | practice ─── */
.banner { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; padding: 7px 10px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font-size: var(--fs-small); line-height: var(--lh-small); }
.banner-ai { background: var(--ai-soft); border-color: var(--ai-line); color: var(--ai-text); }
.banner-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn-text); }
.banner-crit { background: var(--crit-soft); border-color: var(--crit-line); color: var(--crit-text); }
.banner-info { background: var(--info-soft); border-color: transparent; color: var(--info-text); }
.banner-practice {
  background: repeating-linear-gradient(135deg, var(--warn-soft) 0 12px, color-mix(in srgb, var(--warn-soft) 85%, var(--warn-line)) 12px 24px);
  border-color: var(--warn-line); color: var(--warn-text); font-weight: 500;
}

/* ─── Checks line ─── */
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: var(--fs-small); line-height: var(--lh-small); }
.checks li { display: flex; gap: 7px; align-items: flex-start; flex-wrap: wrap; }
.checks li::before { flex: none; width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 700; line-height: 1; }
.checks .ok::before { content: "✓"; background: var(--good-soft); color: var(--good-text); }
.checks .warn::before { content: "!"; background: var(--warn-soft); color: var(--warn-text); }
.checks .block::before { content: "■"; background: var(--block); color: var(--block-ink); border-radius: var(--r-xs); font-size: 8px; }
.checks .block { color: var(--crit-text); font-weight: 500; }

/* ─── Field (new forms; the generic form keeps its own .fld rules in forms.css) ─── */
.fld .ctl { min-width: 0; }
.fld .ctl input, .fld .ctl select, .fld .ctl textarea { width: 100%; min-width: 0; height: var(--control-h); padding: 0 9px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font-size: var(--fs-body); }
.fld .ctl textarea { height: auto; min-height: 56px; padding: 6px 9px; resize: vertical; line-height: var(--lh-body); }
.fld .req { color: var(--crit-text); }
.fld-help { margin: 0; font-size: var(--fs-meta); line-height: var(--lh-meta); color: var(--muted); }
.fld-err { margin: 0; font-size: var(--fs-small); line-height: var(--lh-small); color: var(--crit-text); }
.fld-err:empty { display: none; }
/* phones: 16 px text in every text control (iOS zooms into anything smaller on focus) and touch-height fields */
@media (max-width: 767px) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]), select, textarea { font-size: 16px !important; }
  .fld input:not([type=checkbox]):not([type=file]):not([type=radio]), .fld select, .auth-form .fld input { min-height: var(--control-h); }
}

/* ─── Receipt (computed values, live) ─── */
.rcpt { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 11px; background: var(--surface); }
.rcpt h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: var(--fs-cap); letter-spacing: var(--ls-cap); text-transform: uppercase; color: var(--muted); font-weight: 600; }
.rcpt dl { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 12px; margin: 0; font-size: var(--fs-small); }
.rcpt dt { color: var(--ink-2); }
.rcpt dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.rcpt-total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 6px 0 0; padding-top: 8px; border-top: 1px solid var(--line-2); font-weight: 500; }
.rcpt-total b { font: 600 var(--fs-money-l)/var(--lh-money-l) var(--font-head); font-variant-numeric: tabular-nums; }

/* ─── Empty state: one sentence of good news plus the next thing; an ice wash and a turquoise dashed edge, and room for
   the brand motif (an .eyebrow above, .h-rule on the heading: emptyState() in ui.js writes both) ─── */
.empty { padding: 20px 16px; text-align: center; background: linear-gradient(180deg, var(--ice-1), var(--surface) 70%), var(--surface); border: 1px dashed var(--accent-line); border-radius: var(--r-md); font-size: var(--fs-small); color: var(--ink-2); }
.empty-h { margin: 0 0 3px; font: 600 var(--fs-body)/var(--lh-body) var(--font-head); color: var(--ink); }
.empty .eyebrow { justify-content: center; }
.empty .h-rule::after { margin: 6px auto 8px; }
.empty p { margin: 0; }
.empty p + p { color: var(--ink-2); }
.empty .btn { margin-top: 10px; }

/* ─── Skeletons and the progress line ─── */
.skel, .skel-row, .skel-kpi, .skel-card { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-sm); }
.skel-row { height: var(--row-h-dense); margin: 4px 0; }
.skel-kpi { height: 76px; border-radius: var(--r-md); }
.skel-card { min-height: 180px; border-radius: var(--r-md); }
.skel-line { display: block; height: 10px; margin: 4px 0; border-radius: var(--r-xs); background: var(--surface-3); }
.skel::after, .skel-row::after, .skel-kpi::after, .skel-card::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent); animation: aw-shimmer 600ms var(--ease) 1; }
.progress { position: relative; height: 2px; overflow: hidden; background: transparent; }
.progress::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 40%; background: var(--accent); animation: aw-load 1.2s var(--ease) infinite; }
.progress.ai::before { background: var(--ai); }
.progress .progress-label { display: none; }
@keyframes aw-shimmer { to { transform: translateX(100%); } }
@keyframes aw-load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) {
  .skel::after, .skel-row::after, .skel-kpi::after, .skel-card::after, .progress::before, .btn.is-loading::after { animation: none; }
  .progress { height: auto; }
  .progress::before { display: none; }
  .progress .progress-label { display: inline; font-size: var(--fs-meta); color: var(--muted); }
}

/* ─── Toast (the shell's #toast keeps its .show / .on switch) ─── */
.toast {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--ink); color: var(--bg);
  box-shadow: var(--e2); font-size: var(--fs-small); line-height: var(--lh-body); max-width: calc(100vw - 32px);
}
.toast button { background: transparent; border: 0; color: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; padding: 4px; }
@media (max-width: 767px) { .toast { bottom: 84px; } }

/* ─── Bulk bar ─── */
.bulk {
  position: sticky; bottom: 12px; z-index: 45; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; width: max-content; max-width: 100%;
  margin: 10px auto 0; padding: 6px 6px 6px 12px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--e2), var(--highlight);
  font-size: var(--fs-small);
}
.bulk[hidden] { display: none; }

/* ─── Menu / popover ─── */
.menu { position: fixed; z-index: 88; min-width: 240px; max-width: calc(100vw - 16px); padding: 4px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-tile); box-shadow: var(--e2), var(--highlight); }
.menu[hidden] { display: none; }
.menu .mi { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: var(--nav-item-h); padding: 5px 9px; border: 0; background: none; border-radius: var(--r-nav); text-align: left; cursor: pointer; color: var(--ink); text-decoration: none; font: 400 var(--fs-body)/18px var(--font-ui); }
.menu .mi:hover { background: var(--surface-2); }
.menu .mi:focus-visible { background: var(--surface-2); outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.menu .mi kbd { margin-left: auto; }
.menu .ml { padding: 7px 9px 2px; font-size: var(--fs-xs); line-height: 14px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.menu .mrow { padding: 4px 9px 6px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ─── Density ─── */
body.density-cozy { --row-h: var(--row-h-cozy); }
@media (pointer: coarse) { body.density-cozy, body.density-compact { --row-h: var(--row-h-touch); } }

/* ═══ 2. Control-tower primitives (docs/UI_CONTROL_TOWER.md section 4) ═════════════════════════════════════ */
/* a page's sections, 10 px apart */
.ct-stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.ct-stack > * { margin-top: 0; margin-bottom: 0; }
/* segmented control + its muted count: "74 vehicles · click a row" */
.seg-wrap { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; vertical-align: middle; max-width: 100%; }
.seg-note { font-size: var(--fs-note); color: var(--muted); white-space: nowrap; }
/* a segmented control wider than its box (a phone, a narrow card) scrolls inside itself, never the page */
.seg-wrap > .seg, .toolbar .seg, .card-h .actions .seg, .ewb2-bar .seg { max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
/* filter chips: a row of toggles (aria-pressed), each with an optional count */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
button.chip { cursor: pointer; font: inherit; font-size: var(--fs-note); line-height: 16px; }
button.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip.on, .chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 600; } /* the teal edge: 4.2:1 on the soft fill */
.chip .n { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.chip.on .n, .chip[aria-pressed="true"] .n { color: inherit; }
/* the top bar's "Live · 14:32 IST" pill */
.live { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border: 1px solid var(--line-2); border-radius: var(--r-pill); background: var(--surface); font-size: var(--fs-note); color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.live > i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); flex: none; }
.live.off > i { background: var(--faint); box-shadow: none; }
/* status dot + word (never colour alone) */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); vertical-align: 1px; }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.serious { background: var(--serious); } .dot.crit { background: var(--crit); } .dot.accent { background: var(--accent); }
/* a delta: ▲ 1.3 pts / ▼ 4.1% */
.delta { font-size: var(--fs-meta); font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--good-text); } .delta.down { color: var(--crit-text); } .delta.flat { color: var(--muted); }
/* mini status tiles: two a row, a coloured left edge, a caps label, a 600 tabular value */
.mini-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.mini { min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-left: 3px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface-2); }
.mini .l { display: block; font-size: var(--fs-xs); line-height: 14px; font-weight: 600; letter-spacing: var(--ls-cap); text-transform: uppercase; color: var(--muted); }
.mini b { display: block; font: 600 var(--fs-mini)/var(--lh-mini) var(--font-head); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mini i { display: block; font-style: normal; font-size: var(--fs-meta); line-height: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini.good { border-left-color: var(--good); } .mini.warn { border-left-color: var(--warn); } .mini.serious { border-left-color: var(--serious); }
.mini.crit { border-left-color: var(--crit); } .mini.accent { border-left-color: var(--accent); } .mini.ai { border-left-color: var(--ai); }
/* detail side panel: a mono id title, pills, key/value rows, mini tiles, a row of small buttons */
.with-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); align-items: start; }
@media (min-width: 1100px) { .with-panel { grid-template-columns: minmax(0, 1fr) minmax(280px, 340px); } }
.side-panel { position: sticky; top: 0; min-width: 0; display: flex; flex-direction: column; gap: 9px; padding: 10px 11px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--e1), var(--highlight); }
.side-panel[hidden] { display: none; }
.sp-h { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sp-id { flex: 1; min-width: 0; margin: 0; font: 600 var(--fs-body)/var(--lh-body) var(--font-mono); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-sub { margin: -6px 0 0; font-size: var(--fs-note); color: var(--muted); }
.sp-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.side-panel .kv { grid-template-columns: minmax(84px, auto) 1fr; gap: 3px 10px; }
.sp-acts { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
.sp-acts .btn { height: var(--control-h-sm); padding: 0 8px; font-size: var(--fs-note); }
@media (max-width: 1099px) { .side-panel { position: static; } }
/* phones: touch heights for the small controls */
@media (max-width: 767px) {
  .page-h .actions .btn, .page-head .ph-actions .btn, .sp-acts .btn, .card-h .actions .btn { min-height: 36px; }
  .seg button { min-height: 36px; }
  button.chip { min-height: 32px; }
  .ex-i { position: relative; }
  .ex-i::after { content: ""; position: absolute; inset: -6px; } /* a 26 px hit area round the 14 px dot */
}

/* ═══ 3. The chart kit (js/core/charts.js): recessive turquoise-tinted grid and axes, 2 px lines, values in text tokens,
   the brand series (--s1 turquoise first) ═════ */
.ck { display: block; width: 100%; height: auto; margin: 0 auto; overflow: visible; font-family: var(--font-ui); }
.ck text { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.ck .ck-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.ck .ck-axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.ck .ck-ref { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 3; opacity: .6; }
.ck .ck-lbl { fill: var(--ink-2); font-size: var(--fs-meta); }
.ck .ck-val { fill: var(--ink-2); font-size: var(--fs-meta); font-weight: 600; font-variant-numeric: tabular-nums; }
.ck .ck-halo { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
/* a label on a mark of any shade (both sunburst rings, every heatmap value): ink with a surface halo, legible in both
   themes (surface-coloured text on a series fill falls below 4.5:1 on most of --s1…--s8, so the kit draws none). The
   halo is the same 3 px as .ck-halo (1.5 px round each glyph): at 2.5 px the arc still showed through, 2.8:1 in dark */
.ck .ck-tag { fill: var(--ink); font-size: 9.5px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.ck .ck-note { font-size: 9px; }
.ck .ck-centre { fill: var(--ink); font: 600 20px var(--font-head); letter-spacing: -.01em; }
.ck .ck-centre-sub { fill: var(--muted); font-size: 9.5px; }
.ck .ck-mark { fill: var(--c, var(--s1)); stroke: var(--surface); stroke-width: 1; transition: opacity var(--t-fast); }
.ck .ck-line { fill: none; stroke: var(--c, var(--s1)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ck .ck-line.dash { stroke-dasharray: 4 3; }
.ck .ck-area { fill: var(--c, var(--s1)); fill-opacity: .85; stroke: var(--surface); stroke-width: 1; }
/* a single series (charts.js adds .solo): a pale fill with a 1.5 px edge along its top only (.ck-edge, 3.3:1 on white),
   so a line on the second axis (OTIF --s3 over the dispatches) stays 3:1 over it (4.9:1 light, 3.2:1 dark; at .85 it
   was 2.1 and 1.1, at .22 still 2.8 in dark) and the block no longer dominates the card; two or more stacked series
   keep the .85 fill */
.ck .ck-area.solo { fill-opacity: .14; stroke: none; }
.ck .ck-edge { fill: none; stroke: var(--c, var(--s1)); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.ck .ck-dot { fill: var(--c, var(--s1)); stroke: var(--surface); stroke-width: 1.5; }
.ck .ck-stem { stroke: var(--c, var(--s1)); stroke-width: 2; stroke-linecap: round; }
.ck .ck-web { fill: none; stroke: var(--grid); }
.ck .ck-shape { fill: var(--c, var(--s1)); fill-opacity: .18; stroke: var(--c, var(--s1)); stroke-width: 2; stroke-linejoin: round; }
.ck .ck-cell { stroke: var(--surface); stroke-width: 2; }
.ck .ck-med { stroke: var(--ink-2); stroke-width: 1; }
.ck .ck-hit { fill: transparent; }
.ck g.ck-g:hover .ck-mark, .ck .ck-mark:hover, .ck .ck-dot:hover { opacity: .78; }
.ck-fig { margin: 0; min-width: 0; }
/* a wide chart (stacked area, heatmap) keeps readable text on a phone: it scrolls sideways inside its own box */
.ck-x { min-width: 0; overflow-x: auto; scrollbar-width: thin; }
@media (max-width: 767px) {
  .ck-x > .ck-stacked, .ck-x > .ck-heatmap { min-width: calc(var(--ck-w, 580px) * .9); } /* 90 % of the drawn width: text ≥ 9 px */
  .card-h { flex-wrap: wrap; } .card-h .actions { margin-left: 0; flex-basis: 100%; flex-wrap: wrap; }
}
.ck-fig figcaption, .ck-cap { margin: 6px 0 0; font-size: var(--fs-meta); line-height: var(--lh-meta); color: var(--muted); }
.ck-spark { display: inline-block; vertical-align: middle; overflow: visible; }
/* a sparkline also stands alone (a KPI cell, a table row): its marks are styled without a .ck parent */
.ck-spark .ck-line { fill: none; stroke: var(--c, var(--s1)); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.ck-spark .ck-area { fill: var(--c, var(--s1)); fill-opacity: .12; stroke: none; }
.ck-spark .ck-dot { fill: var(--c, var(--s1)); stroke: var(--surface); stroke-width: 1.5; }
/* donut / sunburst: the ring beside its legend (counts and %) */
.ck-pie { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; }
.ck-pie > svg { flex: 0 1 auto; width: 100%; max-width: 200px; margin: 0; }
.ck-pie > svg.ck-sunburst { max-width: 264px; }
.ck-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; min-width: 150px; font-size: var(--fs-note); color: var(--ink-2); }
.ck-legend li { display: grid; grid-template-columns: 9px minmax(0, 1fr) auto; align-items: center; gap: 6px; }
.ck-legend li > i { width: 9px; height: 9px; border-radius: 2px; background: var(--c, var(--s1)); }
.ck-legend li > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ck-legend li > b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ck-legend li > b small { font-weight: 400; color: var(--muted); margin-left: 3px; }
.ck-keys { display: flex; flex-wrap: wrap; gap: 3px 12px; margin-top: 6px; font-size: var(--fs-meta); color: var(--ink-2); }
.ck-keys span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.ck-keys i { width: 9px; height: 9px; border-radius: 2px; background: var(--c, var(--s1)); flex: none; }
.ck-keys i.ln { height: 2px; width: 14px; border-radius: 1px; }
.ck-keys i.ln.dash { background: repeating-linear-gradient(90deg, var(--c, var(--s1)) 0 4px, transparent 4px 7px); }
.ck-empty { padding: 18px 10px; text-align: center; font-size: var(--fs-small); color: var(--muted); }

/* ═══ 4. The feature sheets' controls on the dense scale (structure unchanged) ═══════════════════════════════ */
.toolbar input[type=search], .toolbar select, .toolbar input[type=date], .toolbar input[type=number], select.sel, input.inp { height: var(--control-h); font-size: var(--fs-small); border-radius: var(--r-sm); }
.detail-grid dt { font-size: var(--fs-meta); color: var(--muted); }
.pager { font-size: var(--fs-small); }
.nav-count { font-size: var(--fs-xs); }
.tooltip { font-size: var(--fs-note); }
.modal { border-radius: var(--r-lg); box-shadow: var(--e3), var(--highlight); }
.modal-h h3 { font-size: var(--fs-h3); line-height: var(--lh-h3); }
.palette { border-radius: var(--r-lg); box-shadow: var(--e3), var(--highlight); }
.pal-group { font-size: var(--fs-xs); }
.pal-sub, .pal-foot { font-size: var(--fs-note); }
#toast.toast { position: fixed; display: block; width: max-content; }
/* modules.js toast() switches .show (base.css only knew .on, so the message never became visible) */
.toast.show { opacity: 1; transform: translateX(-50%); }
