/* =========================================================================
 * PIT-MODE STATUS COLOURS — ONE SET PER THEME
 * =========================================================================
 * Pit Mode raises the contrast of the status colours. It cannot do that by
 * lightening them, which was the first thing tried: on Daylight and Sepia
 * the panel behind them is nearly white, so a lighter TI or IC moves
 * TOWARDS the background and the badge gets harder to read, not easier.
 * Higher contrast means further from the panel, and which direction that is
 * depends on the theme.
 *
 * So every theme declares its own pit variants and Pit Mode simply points
 * the live tokens at them. Measured against each theme's own --panel, worst
 * token in the set:
 *
 *   dark       5.72 : 1  ->  8.53 : 1   (weakest was "bad")
 *   daylight   4.52 : 1  ->  7.29 : 1   (weakest was TI)
 *
 * The FLOOR is the number that matters, not the average: a badge is only as
 * readable as the least readable one on the screen, and in bright light
 * through a scratched tablet screen the weak one is the one that disappears.
 * On dark the two weakest were IC and "bad" — an IC falling due and an
 * overdue or safety-critical fault, which are the two things a technician
 * most needs to pick out across a shed.
 *
 * The default (dark) set is declared on :root so a theme that forgets to
 * define its own still gets a sensible answer rather than an empty custom
 * property, which would render the badge with no colour at all.
 * ========================================================================= */
:root {
  --ti-pit:   #9adcf0;
  --ia-pit:   #ffc766;
  --ic-pit:   #e0aef0;
  --ok-pit:   #6ee7a0;
  --warn-pit: #ffc766;
  --bad-pit:  #ff9a9a;
}

/* Light panels: contrast comes from going DARKER, not lighter. */
[data-theme="light"] {
  --ti-pit:   #0b5e77;
  --ia-pit:   #7a4a00;
  --ic-pit:   #5f1d78;
  --ok-pit:   #0b5c2e;
  --warn-pit: #7a4a00;
  --bad-pit:  #8c1414;
}

[data-theme="sepia"] {
  --ti-pit:   #14536b;
  --ia-pit:   #6d3f00;
  --ic-pit:   #5c2247;
  --ok-pit:   #0d5230;
  --warn-pit: #6d3f00;
  --bad-pit:  #8a3300;
}

/* Night is deliberately dim — a technician on a night shift keeps their
   dark adaptation. Pit Mode lifts it, but only to the point where the badge
   reads; pushing it to the daylight figures would cost them their night
   vision for the walk back down the pit. */
[data-theme="night"] {
  --ti-pit:   #ffcf9a;
  --ia-pit:   #ffc98a;
  --ic-pit:   #ffd2a3;
  --ok-pit:   #ffc98a;
  --warn-pit: #ffc98a;
  --bad-pit:  #ff8a5c;
}

/* High contrast is already at the ceiling, so its pit variants are the same
   colours the theme already uses.

   WRITTEN OUT RATHER THAN `var(--ti)`, WHICH IS NOT THE SAME THING.
   These used to read `--ti-pit: var(--ti)`. That was harmless while the only
   consumer was Pit Mode, which declares `--ti: var(--ti-pit)` on <body> — a
   different element, so the reference resolved against the value inherited
   from <html> and there was no loop.

   The contrast PRESETS broke that. They declare `--ti: var(--ti-pit)` on
   <html>, which is the same element that declares `--ti-pit: var(--ti)`.
   Each then refers to the other, and CSS resolves a custom-property cycle by
   making both invalid at computed-value time — so on this theme, and only
   this theme, choosing High Contrast or Bright Sun would have unset every
   status colour on the dashboard. Literal values cannot cycle. */
[data-theme="contrast"] {
  --ti-pit:   #7fdcf5;
  --ia-pit:   #ffc23d;
  --ic-pit:   #e0a3f5;
  --ok-pit:   #55e88d;
  --warn-pit: #ffc23d;
  --bad-pit:  #ff8080;
}

/* =========================================================================
 * THE TWO THEMES THAT WERE INHERITING THE WRONG PIT SET
 * =========================================================================
 * The :root fallback above is the DARK theme's palette. That is a sensible
 * default for a theme that forgets to define its own — as long as the theme
 * is dark and has no opinion about hue. Two of them are neither, and both
 * were silently broken in Pit Mode:
 *
 * HIGH-VIS OUTDOOR is white. It inherited pale cyan, pale amber and pale
 * pink meant for a near-black panel and rendered them on #ffffff, measured
 * at 1.51 - 2.03:1. WCAG's floor for non-text UI is 3:1 and for text 4.5:1,
 * so every status badge was below the point where it can be relied on —
 * on the theme built for sunlight, in the mode built for standing at a pit.
 * That is the exact combination a technician outside the shed would choose.
 *
 * COLOUR-BLIND SAFE is dark, so it cleared the ratios and looked fine. What
 * it lost was the entire point of the theme. Its palette is Okabe-Ito with
 * warn moved onto yellow so that warn and bad separate by LUMINANCE rather
 * than hue; the :root pit set replaces them with amber #ffc766 and pink-red
 * #ff9a9a, which are a deuteranope-confusable pair. Pit Mode quietly turned
 * the colour-blind-safe theme back into a colour-blind-unsafe one, and
 * nothing about the screen said so.
 * ========================================================================= */

/* White panel: contrast comes from going DARKER, same rule as Daylight. */
[data-theme="hivis"] {
  --ti-pit:   #003d4a;
  --ia-pit:   #573400;
  --ic-pit:   #4a1d5c;
  --ok-pit:   #05432a;
  --warn-pit: #573400;
  --bad-pit:  #7d0f0f;
}

/* Okabe-Ito hues KEPT and lifted, not replaced. warn stays on yellow and
   bad on vermillion so the two remain separated by luminance; the shape
   markers carry the rest. */
[data-theme="cvd"] {
  --ti-pit:   #6ec8ff;
  --ia-pit:   #ffb92e;
  --ic-pit:   #eaa9cd;
  --ok-pit:   #35e3ae;
  --warn-pit: #f7ef7a;
  --bad-pit:  #ff9440;
}

/* =========================================================================
   MEMU DASHBOARD — APPEARANCE THEMES
   =========================================================================
   Loaded AFTER styles.css. The default (dark) theme lives entirely in
   styles.css and is deliberately not touched here, so nothing that
   currently works can regress.

   Themes are applied as data-theme on <html> by theme.js:
     (none / "dark")  Dark          — the existing depot-shed default
     "light"          Daylight      — bright ambient / outdoor tablet use
     "night"          Night amber   — low-blue, preserves dark adaptation
     "contrast"       High contrast — heavier borders, maximum legibility
     "cvd"            Colour-blind safe — Okabe-Ito palette + shape cues

   Anything colour-critical is expressed through the existing token set,
   so most of the UI re-themes for free. The blocks after the tokens only
   exist to fix places where the base CSS baked in a dark assumption
   (opaque near-black fills, white headings, white overlay washes).
   ========================================================================= */

/* Semantic tokens the base sheet had hard-coded. Defaults below reproduce
   the current dark appearance exactly. */
:root {
  --heading: #ffffff;          /* headings / emphasised text */
  --topbar-bg: rgba(7, 13, 22, 0.72);
  --dropdown-bg: rgba(18, 28, 41, 0.97);
  --scrim: rgba(4, 8, 14, 0.82);
  --thead-bg: rgba(14, 22, 33, 0.92);
  --sink: rgba(0, 0, 0, 0.16);        /* recessed panels (rake body, tabs) */
  --zebra: rgba(255, 255, 255, 0.014);
  --hover-wash: rgba(255, 255, 255, 0.03);
  --pane-bg: #0f1822;                 /* --scroll-bg for .pane fades */
  --pill-alpha: 0.10;
}

/* =========================================================================
   1. DAYLIGHT
   ========================================================================= */
[data-theme="light"] {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel2: #f5f8fc;
  --panel3: #e6edf5;
  --border: #c6d2e0;
  --border-light: rgba(0, 0, 0, 0.08);
  --text: #10202f;
  --text2: #33475c;
  --muted: #5a6d80;
  --accent: #0b6fc4;
  --accent2: #5a44d6;
  --accent-hover: #0959a0;
  --accent-soft: rgba(11, 111, 196, 0.14);
  --accent-rgb: 11, 111, 196;
  --accent2-rgb: 90, 68, 214;
  /* darkened until each clears 4.5:1 against its own pale pill tint —
     mid-tone status colours wash out badly on a near-white panel */
  --ti: #0b6d85;   --ti-rgb: 11, 109, 133;
  --ia: #8d5909;   --ia-rgb: 141, 89, 9;
  --ic: #8b3fa8;   --ic-rgb: 139, 63, 168;
  --ok: #117146;   --ok-rgb: 17, 113, 70;
  --warn: #8d5909; --warn-rgb: 141, 89, 9;
  --bad: #bc2525;  --bad-rgb: 188, 37, 37;

  --shadow: 0 8px 24px rgba(16, 32, 47, 0.12);
  --shadow-sm: 0 1px 4px rgba(16, 32, 47, 0.10);
  --shadow-lg: 0 16px 36px rgba(16, 32, 47, 0.16);
  --shadow-glow: 0 0 0 1px rgba(11, 111, 196, 0.3), 0 8px 24px rgba(11, 111, 196, 0.14);
  --shadow-inset: inset 0 1px 3px rgba(16, 32, 47, 0.08);

  --heading: #0b1a27;
  --topbar-bg: rgba(255, 255, 255, 0.82);
  --dropdown-bg: rgba(255, 255, 255, 0.98);
  --scrim: rgba(28, 42, 58, 0.55);
  --thead-bg: rgba(226, 234, 244, 0.95);
  --sink: rgba(16, 32, 47, 0.045);
  --zebra: rgba(16, 32, 47, 0.028);
  --hover-wash: rgba(16, 32, 47, 0.045);
  --pane-bg: #f3f7fb;
  --pill-alpha: 0.13;
}

/* the page background is a dark radial stack in the base sheet */
[data-theme="light"] body {
  background:
    radial-gradient(1200px 560px at 10% -10%, rgba(11, 111, 196, 0.10), transparent 60%),
    radial-gradient(1000px 520px at 105% 0%, rgba(90, 68, 214, 0.07), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

/* =========================================================================
   2. NIGHT AMBER
   Low blue-light so dark adaptation survives moving tablet -> pit.
   Hue range is deliberately narrow, so status leans on the shape cues
   enabled further down rather than on colour alone.
   ========================================================================= */
[data-theme="night"] {
  --bg: #0a0603;
  --panel: #17100a;
  --panel2: #1f160d;
  --panel3: #2b1f12;
  --border: #4a3720;
  --border-light: rgba(255, 176, 0, 0.10);
  --text: #ffcf87;
  --text2: #e0ac5f;
  --muted: #b58749;
  --accent: #ffb000;
  --accent2: #ff8c1a;
  --accent-hover: #ffc44d;
  --accent-soft: rgba(255, 176, 0, 0.16);
  --accent-rgb: 255, 176, 0;
  --accent2-rgb: 255, 140, 26;
  --ti: #ffcf6b;   --ti-rgb: 255, 207, 107;
  --ia: #ff9500;   --ia-rgb: 255, 149, 0;
  --ic: #ffb870;   --ic-rgb: 255, 184, 112;
  --ok: #d9a441;   --ok-rgb: 217, 164, 65;
  --warn: #ff9500; --warn-rgb: 255, 149, 0;
  --bad: #ff5722;  --bad-rgb: 255, 87, 34;

  --heading: #ffd79a;
  --topbar-bg: rgba(10, 6, 3, 0.86);
  --dropdown-bg: rgba(23, 16, 10, 0.98);
  --scrim: rgba(6, 3, 1, 0.9);
  --thead-bg: rgba(20, 13, 7, 0.95);
  --sink: rgba(0, 0, 0, 0.3);
  --zebra: rgba(255, 176, 0, 0.03);
  --hover-wash: rgba(255, 176, 0, 0.06);
  --pane-bg: #140d07;
  --pill-alpha: 0.14;
}

/* strip the blue/violet ambience from the page background */
[data-theme="night"] body {
  background:
    radial-gradient(1200px 560px at 10% -10%, rgba(255, 176, 0, 0.07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

/* =========================================================================
   3. HIGH CONTRAST
   ========================================================================= */
[data-theme="contrast"] {
  --bg: #000000;
  --panel: #0d1117;
  --panel2: #151b23;
  --panel3: #21272f;
  --border: #7d93ab;
  --border-light: rgba(255, 255, 255, 0.22);
  --text: #ffffff;
  --muted: #c3d0dd;
  --accent: #6cc0ff;
  --accent-hover: #9ad4ff;
  --accent-soft: rgba(108, 192, 255, 0.22);
  --accent-rgb: 108, 192, 255;
  --accent2: #a99cff; --accent2-rgb: 169, 156, 255;
  --ti: #7fdcf5;   --ti-rgb: 127, 220, 245;
  --ia: #ffc23d;   --ia-rgb: 255, 194, 61;
  --ic: #e0a3f5;   --ic-rgb: 224, 163, 245;
  --ok: #55e88d;   --ok-rgb: 85, 232, 141;
  --warn: #ffc23d; --warn-rgb: 255, 194, 61;
  --bad: #ff8080;  --bad-rgb: 255, 128, 128;

  --heading: #ffffff;
  --topbar-bg: rgba(0, 0, 0, 0.94);
  --dropdown-bg: rgba(13, 17, 23, 0.99);
  --scrim: rgba(0, 0, 0, 0.92);
  --thead-bg: #000000;
  --sink: rgba(0, 0, 0, 0.5);
  --zebra: rgba(255, 255, 255, 0.05);
  --hover-wash: rgba(255, 255, 255, 0.1);
  --pane-bg: #0d1117;
  --pill-alpha: 0.2;
}

/* flat, glare-free surfaces and unmistakable edges */
[data-theme="contrast"] body { background: var(--bg); }
[data-theme="contrast"] .card,
[data-theme="contrast"] .rake,
[data-theme="contrast"] .box,
[data-theme="contrast"] .rulebar,
[data-theme="contrast"] .toast { background: var(--panel); border-width: 2px; }
[data-theme="contrast"] .card,
[data-theme="contrast"] .rake { box-shadow: none; }
[data-theme="contrast"] .card::after,
[data-theme="contrast"] .topbar::before,
[data-theme="contrast"] .nav button.active::after,
[data-theme="contrast"] .tab.active::after { display: none; }
[data-theme="contrast"] .pill,
[data-theme="contrast"] .tag,
[data-theme="contrast"] .slot { border-width: 2px; font-weight: 800; }
[data-theme="contrast"] tbody td { border-bottom-color: var(--border); }
[data-theme="contrast"] .nav button.active { border-bottom-width: 4px; }
[data-theme="contrast"] :focus-visible { outline-width: 3px; }

/* =========================================================================
   4. COLOUR-BLIND SAFE
   Palette is Okabe-Ito, which is engineered to stay separable under
   deuteranopia, protanopia and tritanopia. The critical pair for this
   dashboard is overdue-red vs healthy-green, so those two are pushed
   onto the vermillion/bluish-green axis and backed by shape markers.
   ========================================================================= */
[data-theme="cvd"] {
  /* Okabe-Ito hues, lifted in lightness. The published palette is tuned
     for ink on white; several of its entries are far too dark to clear
     4.5:1 on this dark UI, so each is raised while its hue is kept.
     warn is moved onto the yellow entry so that warn and bad separate by
     LUMINANCE, not hue — red vs orange is exactly the pair deuteranopes
     cannot split, and shape markers below carry the rest of the load. */
  --accent: #56b4e9;   --accent-rgb: 86, 180, 233;
  --accent2: #0072B2;  --accent2-rgb: 0, 114, 178;
  --accent-hover: #7cc6ee;
  --accent-soft: rgba(86, 180, 233, 0.16);
  --ti: #11aaff;   --ti-rgb: 17, 170, 255;     /* TI  — blue         */
  --ia: #e69f00;   --ia-rgb: 230, 159, 0;      /* IA  — orange       */
  --ic: #d38bb3;   --ic-rgb: 211, 139, 179;    /* IC  — purple       */
  --ok: #00b886;   --ok-rgb: 0, 184, 134;      /* bluish green       */
  --warn: #f0e442; --warn-rgb: 240, 228, 66;   /* yellow (high lum.) */
  --bad: #ff7304;  --bad-rgb: 255, 115, 4;     /* vermillion         */
  --pill-alpha: 0.16;
}

/* =========================================================================
 * SHAPE REDUNDANCY — ON EVERY THEME, NOT ON SIX OF THIRTEEN
 * =========================================================================
 * This block used to read `[data-theme="cvd"] .pill.ok::before` and list the
 * themes it applied to. Six of the thirteen got shapes; Dark, Daylight,
 * High-vis, High contrast, Sepia, Slate and SWR livery got hue and nothing
 * else. Which means the safeguard was reachable only by a technician who
 * already knew they needed it AND knew which entry in a 13-item dropdown
 * provided it — and it evaporated the moment they picked a different one.
 *
 * Colour vision does not change when the theme does. The shapes are
 * unconditional now.
 *
 * WHY IT MATTERS MORE THAN IT LOOKS
 * Simulating deuteranopia over the palette Pit Mode used to fall back to,
 * OK (#6ee7a0) and BAD (#ff9a9a) came out 16 units apart in RGB at a
 * contrast ratio of 1.10 — the same colour, to that eye. "Nothing wrong"
 * and "safety fault" were indistinguishable. That specific pair is fixed
 * above; the shapes are what make it not matter again.
 *
 * DRAWN, NOT TYPED. The old marks were text glyphs — U+25CF, U+25B2,
 * U+25A0 — which depend on the tablet having them in a font, render at
 * whatever size and baseline that font chose, and go missing entirely on a
 * device with a thin font stack. These are geometry: a box with a
 * clip-path, sized in ems so it tracks the type scale and therefore Pit
 * Mode, filled with currentColor so it needs no palette of its own.
 *
 * PRINTED, TOO. print-color-adjust keeps the fill when the page is printed;
 * the print stylesheet forces everything to black, so on paper all six
 * marks are black and the SHAPE is the only thing distinguishing them.
 * That is the correct end state for a photocopied register, and it is worth
 * stating plainly because it is also the strongest test of the design: if
 * the shapes do not carry the meaning with every colour removed, they are
 * decoration.
 * ========================================================================= */

:root {
  --shape-circle:   circle(50% at 50% 50%);
  --shape-triangle: polygon(50% 4%, 96% 92%, 4% 92%);
  --shape-square:   inset(4%);
  --shape-diamond:  polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.pill.ok::before,
.pill.warn::before,
.pill.bad::before,
.due.overdue::before,
.due.soon::before {
  content: "";
  display: inline-block;
  width: 0.72em;
  height: 0.72em;
  margin-right: 0.34em;
  vertical-align: -0.06em;
  background: currentColor;
  flex: none;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* OK is a circle, warn a triangle, bad a square. Chosen so they differ in
   SILHOUETTE rather than in detail — at 0.72em on a dusty screen at arm's
   length, "circle vs hexagon" is not a distinction, and "round vs pointed
   vs blocky" is. The triangle points up, which is the near-universal
   warning silhouette and needs no learning. */
.pill.ok::before   { clip-path: var(--shape-circle); }
.pill.warn::before { clip-path: var(--shape-triangle); }
.pill.bad::before  { clip-path: var(--shape-square); }
.due.soon::before    { clip-path: var(--shape-triangle); }
.due.overdue::before { clip-path: var(--shape-square); }

/* .pill.mut is deliberately unmarked. It means "no status" — a neutral
   grey chip on a coach number or a source label — and giving it a shape
   would put a mark on the one thing that is not a status. */

/* The rake status chip already had a ::before, and it was the same filled
   dot for all three states: colour-only on every theme, including the
   colour-blind one. It now takes the same three silhouettes. */
.status-chip::before {
  border-radius: 0;
  box-shadow: none;
  width: 7px;
  height: 7px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.status-chip.ok::before      { clip-path: var(--shape-circle); }
.status-chip.soon::before    { clip-path: var(--shape-triangle); }
.status-chip.overdue::before { clip-path: var(--shape-square); }

/* -------------------------------------------------------------------------
 * TI / IA / IC — PATTERN, AND ONLY WHERE THE LETTERS ARE NOT ALREADY THERE
 * -------------------------------------------------------------------------
 * A .tag.IA contains the text "IA". Its colour is already redundant with a
 * label a technician can read, and hanging a diamond off it would add
 * clutter to the densest tables on the dashboard without adding one bit of
 * information. Those are left alone on purpose.
 *
 * What is NOT labelled is the geometry: the schedule progress bar under
 * each rake's next-due readout, and the IA/IC cycle pips. Those encode
 * which schedule they refer to in hue alone, and a 6px bar is too small for
 * a shape — so they take a hatch instead, at three angles far enough apart
 * to be told apart at a glance and at any size.
 * ----------------------------------------------------------------------- */
.sched-progress.ti::after,
.sched-progress.ia::after,
.sched-progress.ic::after {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
/* TI: no hatch — it is the common case and the plain bar is its signature. */
.sched-progress.ia::after {
  background-image: repeating-linear-gradient(45deg,
    rgba(0, 0, 0, 0.34) 0 3px, transparent 3px 7px);
}
.sched-progress.ic::after {
  background-image: repeating-linear-gradient(-45deg,
    rgba(0, 0, 0, 0.34) 0 2px, transparent 2px 5px);
}

/* The pips pulse to say "this one is next". Under prefers-reduced-motion
   the pulse is switched off, at which point the ONLY thing separating the
   IA pip from the IC pip is hue — so the hatch is what that reader is left
   with, and it has to be there whether the animation runs or not. */
.pip.next,
.pip.nextIC {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.pip.next {
  background-image: repeating-linear-gradient(45deg,
    rgba(0, 0, 0, 0.38) 0 2px, transparent 2px 4px);
}
.pip.nextIC {
  background-image: repeating-linear-gradient(-45deg,
    rgba(0, 0, 0, 0.38) 0 1.5px, transparent 1.5px 3.5px);
}

/* An overdue rake keeps its hatched left edge — now on every theme, for the
   same reason as everything else in this block. */
.rake.state-overdue {
  border-left-style: solid;
  background-image:
    repeating-linear-gradient(135deg,
      rgba(var(--bad-rgb), 0.16) 0 6px,
      transparent 6px 12px),
    linear-gradient(160deg, var(--panel) 0%, var(--panel2) 220%);
  background-size: 78px 100%, auto;
  background-repeat: no-repeat, no-repeat;
}

/* =========================================================================
   5. SEPIA / PAPER
   Warm off-white, low glare. Closest on-screen match to the printed
   checklist, and easier than pure white for long register sessions.
   ========================================================================= */
[data-theme="sepia"] {
  --bg: #ece0c8;
  --panel: #faf4e6;
  --panel2: #f2e9d8;
  --panel3: #e6d9bf;
  --border: #c9b894;
  --border-light: rgba(80, 60, 30, 0.10);
  --text: #2e2415;
  --text2: #4d3f28;
  --muted: #6b5940;
  --accent: #8a5a12;
  --accent2: #7d3f92;
  --accent-hover: #6f4708;
  --accent-soft: rgba(138, 90, 18, 0.16);
  --accent-rgb: 138, 90, 18;
  --accent2-rgb: 125, 63, 146;
  --ti: #0c6577;   --ti-rgb: 12, 101, 119;
  --ia: #7f5311;   --ia-rgb: 127, 83, 17;
  --ic: #7d3f92;   --ic-rgb: 125, 63, 146;
  --ok: #146944;   --ok-rgb: 20, 105, 68;
  --warn: #7f5311; --warn-rgb: 127, 83, 17;
  --bad: #ac291e;  --bad-rgb: 172, 41, 30;

  --shadow: 0 8px 24px rgba(80, 60, 30, 0.14);
  --shadow-sm: 0 1px 4px rgba(80, 60, 30, 0.12);
  --shadow-lg: 0 16px 36px rgba(80, 60, 30, 0.18);
  --shadow-inset: inset 0 1px 3px rgba(80, 60, 30, 0.10);
  --heading: #241b0e;
  --topbar-bg: rgba(250, 244, 230, 0.86);
  --dropdown-bg: rgba(250, 244, 230, 0.98);
  --scrim: rgba(60, 46, 24, 0.6);
  --thead-bg: rgba(230, 217, 191, 0.95);
  --sink: rgba(80, 60, 30, 0.05);
  --zebra: rgba(80, 60, 30, 0.032);
  --hover-wash: rgba(80, 60, 30, 0.055);
  --pane-bg: #f6efdf;
  --pill-alpha: 0.13;
}
[data-theme="sepia"] body {
  background: radial-gradient(1200px 560px at 10% -10%, rgba(138, 90, 18, 0.07), transparent 60%), var(--bg);
  background-attachment: fixed;
}

/* =========================================================================
   6. SLATE — a softer dark. Desaturated blue-grey rather than near-black,
   for less contrast fatigue on a bright tablet panel.
   ========================================================================= */
[data-theme="slate"] {
  --bg: #1b212a;
  --panel: #232b36;
  --panel2: #2a323d;
  --panel3: #343d4a;
  --border: #46515f;
  --border-light: rgba(255, 255, 255, 0.09);
  --text: #e8edf3;
  --muted: #9dabbb;
  --accent: #6cb6ff;
  --accent2: #9d8dfb;
  --accent-hover: #8ac6ff;
  --accent-soft: rgba(108, 182, 255, 0.14);
  --accent-rgb: 108, 182, 255;
  --accent2-rgb: 157, 141, 251;
  --ti: #6fd0e8;   --ti-rgb: 111, 208, 232;
  --ia: #f0b64a;   --ia-rgb: 240, 182, 74;
  --ic: #d199e1;   --ic-rgb: 209, 153, 225;
  --ok: #4dd48a;   --ok-rgb: 77, 212, 138;
  --warn: #f0b64a; --warn-rgb: 240, 182, 74;
  --bad: #ff8a8a;  --bad-rgb: 255, 138, 138;

  --heading: #f4f8fc;
  --topbar-bg: rgba(27, 33, 42, 0.78);
  --dropdown-bg: rgba(35, 43, 54, 0.97);
  --scrim: rgba(15, 19, 25, 0.8);
  --thead-bg: rgba(30, 37, 47, 0.94);
  --sink: rgba(0, 0, 0, 0.12);
  --zebra: rgba(255, 255, 255, 0.018);
  --hover-wash: rgba(255, 255, 255, 0.04);
  --pane-bg: #1f2731;
  --pill-alpha: 0.12;
}
[data-theme="slate"] body {
  background:
    radial-gradient(1200px 560px at 10% -10%, rgba(108, 182, 255, 0.09), transparent 60%),
    radial-gradient(1000px 520px at 105% 0%, rgba(157, 141, 251, 0.07), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

/* =========================================================================
   7. SWR LIVERY — South Western Railway / Indian Railways presentation.
   Deep railway blue with the IR maroon reserved for chrome only; the
   status palette stays independent so red/amber/green keep their meaning.
   ========================================================================= */
[data-theme="swr"] {
  --bg: #071722;
  --panel: #0e1e2a;
  --panel2: #12232e;
  --panel3: #1b3040;
  --border: #2c4a5e;
  --border-light: rgba(255, 255, 255, 0.09);
  --text: #eef6fb;
  --muted: #8fabbe;
  --accent: #f0a500;          /* IR signal-amber chrome */
  --accent2: #8a1538;         /* IR maroon             */
  --accent-hover: #ffc033;
  --accent-soft: rgba(240, 165, 0, 0.16);
  --accent-rgb: 240, 165, 0;
  --accent2-rgb: 138, 21, 56;
  --ti: #5bc0de;   --ti-rgb: 91, 192, 222;
  --ia: #f5a623;   --ia-rgb: 245, 166, 35;
  --ic: #c678dd;   --ic-rgb: 198, 120, 221;
  --ok: #3fd18a;   --ok-rgb: 63, 209, 138;
  --warn: #f5a623; --warn-rgb: 245, 166, 35;
  --bad: #ff6b6b;  --bad-rgb: 255, 107, 107;

  --heading: #ffffff;
  --topbar-bg: rgba(7, 23, 34, 0.82);
  --dropdown-bg: rgba(14, 30, 42, 0.97);
  --scrim: rgba(4, 12, 18, 0.85);
  --thead-bg: rgba(11, 26, 37, 0.94);
  --sink: rgba(0, 0, 0, 0.2);
  --zebra: rgba(255, 255, 255, 0.016);
  --hover-wash: rgba(240, 165, 0, 0.05);
  --pane-bg: #0d1d28;
  --pill-alpha: 0.12;
}
[data-theme="swr"] body {
  background:
    radial-gradient(1200px 560px at 10% -10%, rgba(240, 165, 0, 0.10), transparent 60%),
    radial-gradient(1000px 520px at 105% 0%, rgba(138, 21, 56, 0.14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
/* maroon header band, amber rule — the livery cue */
[data-theme="swr"] .topbar::before {
  background: linear-gradient(90deg, #8a1538 0%, #b01c46 26%, var(--accent) 62%, transparent 100%);
  height: 3px;
}
[data-theme="swr"] .badge-rail {
  background: linear-gradient(135deg, #8a1538 0%, #b01c46 100%);
  box-shadow: 0 2px 10px rgba(138, 21, 56, 0.6);
}
[data-theme="swr"] .btn.primary,
[data-theme="swr"] .seg button.active,
[data-theme="swr"] .ep-btn.active { color: #241000; }

/* =========================================================================
   8. HIGH-VIS OUTDOOR — maximum brightness and weight, for direct
   sunlight at the shed door where Daylight still washes out.
   ========================================================================= */
[data-theme="hivis"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel2: #ffffff;
  --panel3: #eef2f6;
  --border: #4a5866;
  --border-light: rgba(0, 0, 0, 0.2);
  --text: #000000;
  --text2: #16202a;
  --muted: #3d4a57;
  --accent: #0a4fa0;
  --accent2: #5a2ea6;
  --accent-hover: #073e80;
  --accent-soft: rgba(10, 79, 160, 0.18);
  --accent-rgb: 10, 79, 160;
  --accent2-rgb: 90, 46, 166;
  --ti: #005f73;   --ti-rgb: 0, 95, 115;
  --ia: #7a4a00;   --ia-rgb: 122, 74, 0;
  --ic: #6b2d85;   --ic-rgb: 107, 45, 133;
  --ok: #0a5c38;   --ok-rgb: 10, 92, 56;
  --warn: #7a4a00; --warn-rgb: 122, 74, 0;
  --bad: #a81414;  --bad-rgb: 168, 20, 20;

  --shadow: none; --shadow-sm: none; --shadow-lg: none; --shadow-inset: none;
  --shadow-glow: 0 0 0 2px rgba(10, 79, 160, 0.5);
  --heading: #000000;
  --topbar-bg: #ffffff;
  --dropdown-bg: #ffffff;
  --scrim: rgba(0, 0, 0, 0.55);
  --thead-bg: #dfe6ed;
  --sink: rgba(0, 0, 0, 0.05);
  --zebra: rgba(0, 0, 0, 0.05);
  --hover-wash: rgba(0, 0, 0, 0.09);
  --pane-bg: #ffffff;
  --pill-alpha: 0.16;
}
/* flat white, no gradients or glow to compete with sunlight; heavy edges */
[data-theme="hivis"] body { background: #ffffff; }
[data-theme="hivis"] .card,
[data-theme="hivis"] .rake,
[data-theme="hivis"] .box,
[data-theme="hivis"] .rulebar,
[data-theme="hivis"] .toast { background: #ffffff; border-width: 2px; box-shadow: none; }
[data-theme="hivis"] .card::after,
[data-theme="hivis"] .topbar::before,
[data-theme="hivis"] .nav button.active::after,
[data-theme="hivis"] .tab.active::after { display: none; }
[data-theme="hivis"] .pill,
[data-theme="hivis"] .tag,
[data-theme="hivis"] .slot { border-width: 2px; font-weight: 800; }
[data-theme="hivis"] .nav button.active { border-bottom-width: 4px; }
[data-theme="hivis"] tbody td { border-bottom-color: #9aa7b4; }
[data-theme="hivis"] body,
[data-theme="hivis"] .card .foot,
[data-theme="hivis"] .rk-route { font-weight: 600; }
[data-theme="hivis"] :focus-visible { outline-width: 3px; }

/* =========================================================================
   VIBRANT SET — saturated chrome, loud status colours.

   Hue choice is constrained, not arbitrary: the page chrome deliberately
   avoids red-dominant and green-dominant schemes, because red already
   means "overdue" and green means "healthy" on every rake card. A crimson
   dashboard would camouflage exactly the thing a supervisor must spot
   first. Indigo, violet, teal and plum leave the status palette free to
   shout. All status colours here still clear WCAG AA on their own tint.
   ========================================================================= */

/* --- NEON — electric indigo with cyan/magenta chrome --- */
[data-theme="neon"] {
  --bg: #0b0620;
  --panel: #150c33;
  --panel2: #1c1142;
  --panel3: #2a1a5e;
  --border: #4a2f8f;
  --border-light: rgba(0, 229, 255, 0.16);
  --text: #f0ebff;
  --text2: #d6ccff;
  --muted: #a99ad6;
  --accent: #00e5ff;   --accent-rgb: 0, 229, 255;
  --accent2: #ff2fd0;  --accent2-rgb: 255, 47, 208;
  --accent-hover: #6df0ff;
  --accent-soft: rgba(0, 229, 255, 0.18);
  --ti: #00e5ff;   --ti-rgb: 0, 229, 255;
  --ia: #ffb300;   --ia-rgb: 255, 179, 0;
  --ic: #ff31d0;   --ic-rgb: 255, 49, 208;
  --ok: #00ffa3;   --ok-rgb: 0, 255, 163;
  --warn: #ffb300; --warn-rgb: 255, 179, 0;
  --bad: #ff4e7b;  --bad-rgb: 255, 78, 123;

  --heading: #ffffff;
  --topbar-bg: rgba(11, 6, 32, 0.8);
  --dropdown-bg: rgba(21, 12, 51, 0.97);
  --scrim: rgba(6, 3, 18, 0.86);
  --thead-bg: rgba(16, 9, 38, 0.94);
  --sink: rgba(0, 0, 0, 0.26);
  --zebra: rgba(0, 229, 255, 0.028);
  --hover-wash: rgba(0, 229, 255, 0.07);
  --pane-bg: #120a2b;
  --pill-alpha: 0.14;
  --shadow-glow: 0 0 0 1px rgba(0, 229, 255, 0.35), 0 8px 28px rgba(0, 229, 255, 0.22);
}
[data-theme="neon"] body {
  background:
    radial-gradient(1200px 560px at 8% -12%, rgba(0, 229, 255, 0.16), transparent 58%),
    radial-gradient(1000px 520px at 104% 2%, rgba(255, 47, 208, 0.15), transparent 55%),
    radial-gradient(900px 500px at 50% 112%, rgba(124, 107, 255, 0.14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
[data-theme="neon"] .topbar::before {
  background: linear-gradient(90deg, #00e5ff 0%, #7c6bff 42%, #ff2fd0 74%, transparent 100%);
  height: 2px;
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.6);
}
[data-theme="neon"] .btn.primary,
[data-theme="neon"] .seg button.active,
[data-theme="neon"] .ep-btn.active { color: #04121c; }

/* --- ORCHID — vivid violet/pink --- */
[data-theme="orchid"] {
  --bg: #1a0726;
  --panel: #260f38;
  --panel2: #301345;
  --panel3: #421a5e;
  --border: #6b2a94;
  --border-light: rgba(224, 92, 255, 0.16);
  --text: #fceaff;
  --text2: #edd2f7;
  --muted: #c79ad9;
  --accent: #e05cff;   --accent-rgb: 224, 92, 255;
  --accent2: #ff7ab8;  --accent2-rgb: 255, 122, 184;
  --accent-hover: #ec8bff;
  --accent-soft: rgba(224, 92, 255, 0.18);
  --ti: #4fd8ff;   --ti-rgb: 79, 216, 255;
  --ia: #ffab2e;   --ia-rgb: 255, 171, 46;
  --ic: #e265ff;   --ic-rgb: 226, 101, 255;
  --ok: #3ff0a8;   --ok-rgb: 63, 240, 168;
  --warn: #ffab2e; --warn-rgb: 255, 171, 46;
  --bad: #ff658e;  --bad-rgb: 255, 101, 142;

  --heading: #ffffff;
  --topbar-bg: rgba(26, 7, 38, 0.82);
  --dropdown-bg: rgba(38, 15, 56, 0.97);
  --scrim: rgba(14, 4, 21, 0.86);
  --thead-bg: rgba(30, 11, 44, 0.94);
  --sink: rgba(0, 0, 0, 0.24);
  --zebra: rgba(224, 92, 255, 0.03);
  --hover-wash: rgba(224, 92, 255, 0.07);
  --pane-bg: #220c32;
  --pill-alpha: 0.14;
}
[data-theme="orchid"] body {
  background:
    radial-gradient(1200px 560px at 8% -12%, rgba(224, 92, 255, 0.17), transparent 58%),
    radial-gradient(1000px 520px at 104% 2%, rgba(255, 122, 184, 0.14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
[data-theme="orchid"] .btn.primary,
[data-theme="orchid"] .seg button.active,
[data-theme="orchid"] .ep-btn.active { color: #1b0526; }

/* --- LAGOON — vivid teal / aqua --- */
[data-theme="lagoon"] {
  --bg: #04181f;
  --panel: #07242e;
  --panel2: #0a2d39;
  --panel3: #0f3f4f;
  --border: #1a6478;
  --border-light: rgba(0, 217, 192, 0.16);
  --text: #e6fbff;
  --text2: #c4eef5;
  --muted: #8fc4d1;
  --accent: #00d9c0;   --accent-rgb: 0, 217, 192;
  --accent2: #3ea6ff;  --accent2-rgb: 62, 166, 255;
  --accent-hover: #4ee9d6;
  --accent-soft: rgba(0, 217, 192, 0.18);
  --ti: #5fe0ff;   --ti-rgb: 95, 224, 255;
  --ia: #ffbb33;   --ia-rgb: 255, 187, 51;
  --ic: #c98cff;   --ic-rgb: 201, 140, 255;
  --ok: #00f0a8;   --ok-rgb: 0, 240, 168;
  --warn: #ffbb33; --warn-rgb: 255, 187, 51;
  --bad: #ff7285;  --bad-rgb: 255, 114, 133;

  --heading: #ffffff;
  --topbar-bg: rgba(4, 24, 31, 0.82);
  --dropdown-bg: rgba(7, 36, 46, 0.97);
  --scrim: rgba(2, 14, 18, 0.86);
  --thead-bg: rgba(6, 30, 38, 0.94);
  --sink: rgba(0, 0, 0, 0.24);
  --zebra: rgba(0, 217, 192, 0.03);
  --hover-wash: rgba(0, 217, 192, 0.07);
  --pane-bg: #06202a;
  --pill-alpha: 0.14;
}
[data-theme="lagoon"] body {
  background:
    radial-gradient(1200px 560px at 8% -12%, rgba(0, 217, 192, 0.16), transparent 58%),
    radial-gradient(1000px 520px at 104% 2%, rgba(62, 166, 255, 0.14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
[data-theme="lagoon"] .btn.primary,
[data-theme="lagoon"] .seg button.active,
[data-theme="lagoon"] .ep-btn.active { color: #03211c; }

/* --- EMBER — deep plum with warm orange chrome.
   Plum rather than crimson on purpose: a red page would swallow the
   overdue signal it is meant to make obvious. --- */
[data-theme="ember"] {
  --bg: #1c0a14;
  --panel: #2a0f1e;
  --panel2: #341326;
  --panel3: #4a1c36;
  --border: #7a2e54;
  --border-light: rgba(255, 138, 61, 0.16);
  --text: #ffeaf2;
  --text2: #f7d3e0;
  --muted: #d49bb4;
  --accent: #ff8a3d;   --accent-rgb: 255, 138, 61;
  --accent2: #ff3d8a;  --accent2-rgb: 255, 61, 138;
  --accent-hover: #ffa869;
  --accent-soft: rgba(255, 138, 61, 0.18);
  --ti: #4fd0ff;   --ti-rgb: 79, 208, 255;
  --ia: #ffc233;   --ia-rgb: 255, 194, 51;
  --ic: #e08cff;   --ic-rgb: 224, 140, 255;
  --ok: #3fe89a;   --ok-rgb: 63, 232, 154;
  --warn: #ffc233; --warn-rgb: 255, 194, 51;
  --bad: #ff627b;  --bad-rgb: 255, 98, 123;

  --heading: #ffffff;
  --topbar-bg: rgba(28, 10, 20, 0.82);
  --dropdown-bg: rgba(42, 15, 30, 0.97);
  --scrim: rgba(16, 5, 11, 0.86);
  --thead-bg: rgba(34, 12, 24, 0.94);
  --sink: rgba(0, 0, 0, 0.24);
  --zebra: rgba(255, 138, 61, 0.028);
  --hover-wash: rgba(255, 138, 61, 0.07);
  --pane-bg: #250d1a;
  --pill-alpha: 0.14;
}
[data-theme="ember"] body {
  background:
    radial-gradient(1200px 560px at 8% -12%, rgba(255, 138, 61, 0.15), transparent 58%),
    radial-gradient(1000px 520px at 104% 2%, rgba(255, 61, 138, 0.14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}
[data-theme="ember"] .btn.primary,
[data-theme="ember"] .seg button.active,
[data-theme="ember"] .ep-btn.active { color: #230c05; }

/* Vibrant themes carry the shape markers too — saturated chrome makes the
   amber/red status pair harder to separate at a glance, not easier. */
/* The four vivid themes (Neon, Orchid, Lagoon, Ember) carried their own
   copy of the glyph markers here. They are gone: the universal block above
   marks every theme, and leaving these would have re-set `content` to a
   text glyph on the same ::before that now draws a clipped shape — putting
   a half-cropped ■ inside a square on four themes. Deleting a rule that
   duplicates a general one is not tidying; keeping it was the bug. */

/* =========================================================================
   9. Shared fixes — places the base sheet baked in a dark assumption.
   These read from the tokens above, so they are correct in every theme.
   ========================================================================= */
.topbar { background: var(--topbar-bg); }
#globalSearchResults,
.gsearch-head { background: var(--dropdown-bg); }
.auth-overlay { background: var(--scrim); }
thead th { background: var(--thead-bg); }
.rake-body,
.tabs { background: var(--sink); }
tbody tr:nth-child(even) { background: var(--zebra); }
.pane { --scroll-bg: var(--pane-bg); }

/* headings and emphasised text that were literal white */
.topbar h1,
.rk-title,
.box h3,
.card .cno,
.coach-chip .cno,
.auth-head h2,
.nav button.active,
.tab.active,
#eqModalTabs .tab-btn.btn.active { color: var(--heading); }

/* the title gradient only makes sense on a dark field */
[data-theme="light"] .topbar h1,
[data-theme="sepia"] .topbar h1,
[data-theme="hivis"] .topbar h1,
[data-theme="contrast"] .topbar h1 {
  background: none;
  -webkit-text-fill-color: var(--heading);
  color: var(--heading);
}

/* hover washes were white-on-dark */
[data-theme="light"] .rake-top:hover,
[data-theme="sepia"] .rake-top:hover,
[data-theme="hivis"] .rake-top:hover,
[data-theme="light"] .act:hover,
[data-theme="sepia"] .act:hover,
[data-theme="hivis"] .act:hover,
[data-theme="light"] .nav button:hover:not(.active),
[data-theme="sepia"] .nav button:hover:not(.active),
[data-theme="hivis"] .nav button:hover:not(.active),
[data-theme="light"] .nav a.eqlib-link:hover,
[data-theme="sepia"] .nav a.eqlib-link:hover,
[data-theme="hivis"] .nav a.eqlib-link:hover,
[data-theme="light"] .tab:hover:not(.active),
[data-theme="sepia"] .tab:hover:not(.active),
[data-theme="hivis"] .tab:hover:not(.active) { background: var(--hover-wash); }

/* light theme: solid accent buttons need light text, not the dark ink
   that reads correctly on the brighter dark-theme accent */
[data-theme="light"] .btn.primary,
[data-theme="sepia"] .btn.primary,
[data-theme="hivis"] .btn.primary,
[data-theme="light"] .seg button.active,
[data-theme="sepia"] .seg button.active,
[data-theme="hivis"] .seg button.active,
[data-theme="light"] .ep-btn.active,
[data-theme="sepia"] .ep-btn.active,
[data-theme="hivis"] .ep-btn.active,
[data-theme="light"] .ep-play,
[data-theme="sepia"] .ep-play,
[data-theme="hivis"] .ep-play,
[data-theme="light"] .lang-btn.active,
[data-theme="sepia"] .lang-btn.active,
[data-theme="hivis"] .lang-btn.active { color: #ffffff; }

/* pill/tag fills scale with the theme so they stay visible on paper-white */
.pill.ok   { background: rgba(var(--ok-rgb), var(--pill-alpha)); }
.pill.warn { background: rgba(var(--warn-rgb), var(--pill-alpha)); }
.pill.bad  { background: rgba(var(--bad-rgb), var(--pill-alpha)); }
.tag.TI    { background: rgba(var(--ti-rgb), var(--pill-alpha)); }
.tag.IA    { background: rgba(var(--ia-rgb), var(--pill-alpha)); }
.tag.IC    { background: rgba(var(--ic-rgb), var(--pill-alpha)); }

/* EP diagram canvas follows the theme instead of staying near-black */
[data-theme="light"] #sec-airbrake { --ep-canvas: #eaf0f7; --ep-metal: #7b8b9c; --ep-wheel: #94a6b8; }
[data-theme="night"] #sec-airbrake { --ep-canvas: #0d0803; --ep-metal: #6b5535; --ep-wheel: #4a3720; }
[data-theme="contrast"] #sec-airbrake { --ep-canvas: #000000; }
[data-theme="sepia"] #sec-airbrake { --ep-canvas: #f6efdf; --ep-metal: #8a795c; --ep-wheel: #a0906f; }
[data-theme="hivis"] #sec-airbrake { --ep-canvas: #ffffff; --ep-metal: #5a6673; --ep-wheel: #7a8794; }
[data-theme="slate"] #sec-airbrake { --ep-canvas: #161c24; }
[data-theme="swr"]   #sec-airbrake { --ep-canvas: #06141e; }

/* diagram wells stay dark in light mode — line drawings need the contrast,
   and inverting them would misrepresent the scanned originals */
[data-theme="light"] .diagram-img-wrap,
[data-theme="sepia"] .diagram-img-wrap,
[data-theme="hivis"] .diagram-img-wrap { background: #0b1119; }

/* =========================================================================
   6. Theme switcher control (topbar)
   ========================================================================= */
.theme-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 5px 26px 5px 10px;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 0;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) center, calc(100% - 9px) center;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  transition: color .18s var(--ease), border-color .18s var(--ease), background-color .18s var(--ease);
}
.theme-select:hover {
  color: var(--accent);
  border-color: rgba(var(--accent-rgb), 0.55);
}
.theme-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-select option {
  background: var(--panel);
  color: var(--text);
  text-transform: none;
  font-weight: 600;
}
[data-theme="light"] .theme-select,
[data-theme="sepia"] .theme-select,
[data-theme="hivis"] .theme-select { background-color: rgba(16, 32, 47, 0.05); }

/* the switcher itself must stay finger-sized on tablets */
@media (pointer: coarse) {
  .theme-select { min-height: 40px; font-size: var(--text-sm); }
}

/* printing always uses the light rendering defined in styles.css */
@media print {
  .theme-select { display: none !important; }
}

/* =========================================================================
 * CONTRAST PRESETS — A SECOND AXIS, NOT SEVEN MORE THEMES
 * =========================================================================
 * Keyed off data-contrast on <html>: absent | "high" | "sun". It composes
 * with data-theme rather than replacing it, so "Sepia + Bright Sun" and
 * "Night amber + High Contrast" are both reachable — which is the point.
 * High-vis outdoor and High contrast stay in the theme list; this is a
 * different control, not a replacement for them.
 *
 * WHY THIS IS NOT A NEW COLOUR TABLE
 * The obvious build is 13 themes x 2 presets = 26 new palettes, every one
 * of which has to be measured and none of which anybody will maintain.
 * Instead each preset reuses what is already per-theme and already
 * measured:
 *
 *   status inks   -> the --*-pit variants at the head of this file, which
 *                    exist for exactly this purpose and are verified by
 *                    tests/contrast.test.js at 7.03:1 or better on all 13
 *   borders       -> neutral white/black overlays, which are correct on any
 *                    hue because they are not a hue
 *   shadows       -> off, which needs no palette at all
 *
 * So a new theme added tomorrow gets both presets for free, and gets them
 * right, without anybody choosing six more hex values.
 *
 * THE --*-rgb TINTS ARE DELIBERATELY LEFT ALONE. They drive 10-16% alpha
 * backgrounds behind the badges. The ink moves to the high-contrast variant
 * and the wash behind it stays on the base hue, which is the same thing Pit
 * Mode has always done — the ink is what has to be read, and a tint that
 * shifted with it would only reduce the ink's contrast against its own
 * background.
 * ========================================================================= */

/* ------------------------------------------------------------ HIGH CONTRAST */
html[data-contrast="high"] {
  --ti: var(--ti-pit);
  --ia: var(--ia-pit);
  --ic: var(--ic-pit);
  --ok: var(--ok-pit);
  --warn: var(--warn-pit);
  --bad: var(--bad-pit);

  /* Secondary text stops being secondary. --muted is the token on route
     numbers, "projected from register", table footnotes — legible at a desk
     and the first thing to go on a scratched screen. */
  --muted: var(--text2);

  --pill-alpha: 0.22;

  /* Depth is a luxury of good lighting. Every shadow in this UI exists to
     separate a card from a background that, at high contrast, is already
     separated by a 2px border. */
  --shadow: none;
  --shadow-sm: none;
  --shadow-lg: none;
  --shadow-inset: none;
  --shadow-glow: 0 0 0 2px var(--border);

  /* Neutral overlays: correct against any hue, because they are not one. */
  --border: rgba(255, 255, 255, 0.46);
  --border-light: rgba(255, 255, 255, 0.28);
  --zebra: rgba(255, 255, 255, 0.07);
  --hover-wash: rgba(255, 255, 255, 0.13);
}

/* The three light-panel themes need the overlays inverted. This is the same
   theme list themes.css already uses everywhere else for this purpose. */
html[data-contrast="high"][data-theme="light"],
html[data-contrast="high"][data-theme="sepia"],
html[data-contrast="high"][data-theme="hivis"] {
  --border: rgba(0, 0, 0, 0.58);
  --border-light: rgba(0, 0, 0, 0.34);
  --zebra: rgba(0, 0, 0, 0.06);
  --hover-wash: rgba(0, 0, 0, 0.11);
  --shadow-glow: 0 0 0 2px var(--border);
}

/* ---------------------------------------------------------------- BRIGHT SUN */
/* Everything High Contrast does, and then the things that only matter with
   the sun on the screen: no gradient or glow anywhere, flat panels, neutral
   washes, heavier edges, slightly larger type. */
html[data-contrast="sun"] {
  --ti: var(--ti-pit);
  --ia: var(--ia-pit);
  --ic: var(--ic-pit);
  --ok: var(--ok-pit);
  --warn: var(--warn-pit);
  --bad: var(--bad-pit);

  --muted: var(--text2);
  --pill-alpha: 0.26;

  --shadow: none;
  --shadow-sm: none;
  --shadow-lg: none;
  --shadow-inset: none;
  --shadow-glow: 0 0 0 3px var(--border);

  --border: rgba(255, 255, 255, 0.62);
  --border-light: rgba(255, 255, 255, 0.4);

  /* DESATURATED BACKGROUNDS.
     Saturation in this UI does not live in --bg; it lives in the tinted
     layers stacked on top of it — the accent wash behind a focused row, the
     zebra striping, the hover state, the recessed panel. In direct sun a
     tinted layer is the first thing that stops reading as a layer and starts
     reading as a smear, because the tint and the panel converge as ambient
     light floods the display. Every one of them becomes neutral grey, which
     keeps the LAYERING (still visible as a lightness step) and drops the
     HUE (which was not carrying information anyway).
     The panel itself keeps the theme's colour: this is a preset, not a
     thirteenth theme, and somebody who chose Sepia should still see Sepia. */
  --accent-soft: rgba(128, 128, 128, 0.16);
  --zebra: rgba(128, 128, 128, 0.11);
  --hover-wash: rgba(128, 128, 128, 0.18);
  --sink: rgba(128, 128, 128, 0.12);
  --thead-bg: rgba(128, 128, 128, 0.18);
  --panel2: var(--panel);
  --panel3: var(--panel);
  --pane-bg: var(--panel);
}

html[data-contrast="sun"][data-theme="light"],
html[data-contrast="sun"][data-theme="sepia"],
html[data-contrast="sun"][data-theme="hivis"] {
  --border: rgba(0, 0, 0, 0.72);
  --border-light: rgba(0, 0, 0, 0.45);
}

/* SLIGHTLY LARGER TYPE — and only when Pit Mode is not already doing it.
   Pit Mode sets these same tokens about a third larger; without the :not()
   the two rules have identical specificity and whichever file loads second
   wins, which would mean Bright Sun quietly SHRINKING the text of somebody
   standing at a pit. Pit is the bigger of the two in every case, so it takes
   precedence and this fills in everywhere else. */
html[data-contrast="sun"] body:not([data-density="pit"]) {
  --text-xs: 12px;
  --text-sm: 13.5px;
  --text-base: 14.5px;
  --text-md: 16px;
  --text-lg: 20px;
  --text-xl: 24px;
}

/* Flat, hard-edged chrome under both presets. Same selector list the
   contrast and hivis THEMES already use — those two remain in the theme
   list, and a technician on hivis + Bright Sun simply gets both, which
   composes correctly because every rule here is idempotent. */
html[data-contrast="high"] .card,
html[data-contrast="high"] .rake,
html[data-contrast="high"] .box,
html[data-contrast="high"] .rulebar,
html[data-contrast="high"] .toast,
html[data-contrast="sun"] .card,
html[data-contrast="sun"] .rake,
html[data-contrast="sun"] .box,
html[data-contrast="sun"] .rulebar,
html[data-contrast="sun"] .toast {
  border-width: 2px;
  box-shadow: none;
}

html[data-contrast="high"] .pill,
html[data-contrast="high"] .tag,
html[data-contrast="high"] .slot,
html[data-contrast="high"] .status-chip,
html[data-contrast="sun"] .pill,
html[data-contrast="sun"] .tag,
html[data-contrast="sun"] .slot,
html[data-contrast="sun"] .status-chip {
  border-width: 2px;
  font-weight: 800;
}

/* Decorative gradients and glows. Each of these is a ::after or ::before
   that paints a soft edge — invisible indoors when it works, and a grey
   haze over the thing underneath it when the sun is on the screen. */
html[data-contrast="high"] .card::after,
html[data-contrast="high"] .topbar::before,
html[data-contrast="high"] .nav button.active::after,
html[data-contrast="high"] .tab.active::after,
html[data-contrast="sun"] .card::after,
html[data-contrast="sun"] .topbar::before,
html[data-contrast="sun"] .nav button.active::after,
html[data-contrast="sun"] .tab.active::after {
  display: none;
}

html[data-contrast="high"] .nav button.active,
html[data-contrast="sun"] .nav button.active { border-bottom-width: 4px; }

html[data-contrast="high"] :focus-visible,
html[data-contrast="sun"] :focus-visible { outline-width: 3px; }

/* Bright Sun only: the backdrop blur behind the sticky topbar costs GPU and
   buys nothing once the panel is opaque, and on a mid-range tablet in the
   sun it is a visible scroll stutter. */
html[data-contrast="sun"] .topbar {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: var(--topbar-bg);
}

html[data-contrast="sun"] body,
html[data-contrast="sun"] .card .foot,
html[data-contrast="sun"] .rk-route { font-weight: 600; }

/* Printing has its own contrast model — black ink on white paper — and the
   preset must not reach into it. */
@media print {
  html[data-contrast="high"] .card,
  html[data-contrast="high"] .rake,
  html[data-contrast="sun"] .card,
  html[data-contrast="sun"] .rake { border-width: 1px; }
}
