/* Forge Light V1 — semantic theme tokens.
 *
 * Presentation only. Light is the default (forge-theme-v1.js sets
 * html[data-forge-theme] before first paint); Dark is the explicit opt-in and is
 * the existing Gen3 Cinematic design, retuned only where it failed contrast.
 *
 * Light is not an inversion. Hierarchy comes from a neutral plane ramp
 * (canvas < surface < raised wells), hairline borders, spacing and type —
 * never from dark boxes. Ink is the accent; crimson stays the single, scarce
 * consequence channel (irreversible commitment, selected object, true fault).
 *
 * Every literal colour in the staff surfaces is mapped onto these tokens by the
 * generated forge-theme-map-v1.css. Contrast of every declared pair is proven
 * from THIS built file by tools/forge_theme_contrast.py; do not keep a palette
 * anywhere else.
 */

/* ------------------------------------------------------------ Light tokens */
html[data-forge-theme="light"] {
  /* planes */
  --fx-canvas: #F2F4F6;        /* page ground */
  --fx-surface: #FFFFFF;       /* cards, panels, rails, inputs */
  --fx-raised: #F7F8FA;        /* wells and secondary panels inside a surface */
  --fx-raised-2: #EBEEF2;      /* selection, hover, active row */
  --fx-fill-strong: #DCE1E7;   /* strongest neutral fill (pressed, meters) */
  /* edges */
  --fx-line: #E1E5EA;          /* hairline dividers (decorative) */
  --fx-line-2: #C9CFD6;        /* card and group outlines */
  --fx-line-strong: #737D89;   /* control boundaries: inputs, buttons, toggles */
  --fx-focus: #2553C2;         /* focus ring */
  /* text */
  --fx-text: #111418;
  --fx-text-2: #3F4751;
  --fx-text-3: #58616C;        /* muted: labels, eyebrows, meta */
  /* accent: ink-steel, not a hue */
  --fx-accent: #1B2430;
  --fx-accent-2: #3A4553;
  --fx-inverse: #161A1F;       /* inverted fill: selected segment, DECLARED primary only */
  --fx-on-inverse: #FFFFFF;
  /* secondary action. Rule (Mission Control, 29 Sep 2026): in Light, cards and
     secondary actions never use dark/graphite surfaces; only declared primary /
     brand elements may stay dark. The dark design's silver brand fills (the
     --molten/--ember gradients, white pills) land here: a light steel fill, ink
     label, and a control boundary -- never an ink slab. */
  --fx-action: #E8ECF1;
  --fx-action-2: #DCE2E9;
  --fx-on-action: #111418;
  --fx-action-line: #737D89;
  /* consequence channel */
  --fx-crimson: #C8261C;       /* fill/mark: commitment, selected-nav bar */
  --fx-on-crimson: #FFFFFF;
  /* status: text / line / tint / fill */
  --fx-danger: #B42318;   --fx-danger-line: #D9493D;  --fx-danger-tint: #FDECEA;  --fx-danger-fill: #C8261C;
  --fx-warning: #8A4F00;  --fx-warning-line: #B7790B; --fx-warning-tint: #FFF3D6; --fx-warning-fill: #F2B233;
  --fx-success: #18703D;  --fx-success-line: #3F9A63; --fx-success-tint: #E6F3EB; --fx-success-fill: #18703D;
  --fx-info: #2553C2;     --fx-info-line: #5B82DB;    --fx-info-tint: #E8EEFB;    --fx-info-fill: #2553C2;
  --fx-purple: #6E35B5;   --fx-purple-line: #9A6BD6;  --fx-purple-tint: #F1EAFB;  --fx-purple-fill: #6E35B5;
  --fx-shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}

/* ------------------------------------------------------------ Dark retune
 * Dark = the shipped Gen3 Cinematic tokens (forge-cinematic-v1.css) and the
 * legacy chrome tokens (_nav.html). Built-CSS proof found three pairs under
 * threshold; only those tokens move, by the smallest step that passes:
 *   cinematic --fg-3 #949aa1 on --bg-3 #373f48     3.76 -> >= 4.5
 *   cinematic --line-3 #687787 on --bg-2 #292f36   2.95 -> >= 3.0
 *   legacy    --fg-3 rgba(245,245,247,.42) on #000 3.72 -> >= 4.5
 *   cinematic --danger #ff7a6b on --bg-3           4.19 -> >= 4.5
 *   cinematic --ok #70a67d on --bg-3               3.78 -> >= 4.5
 * and route/shell literals dimmer than the muted floor (founder shell
 * #565660 / #686872 / #74747e, 2.6-4.3:1) are lifted to --fx-dk-muted by the
 * generated DARK layer of forge-theme-map-v1.css.
 */
html[data-forge-theme="dark"] {
  --fx-dk-muted: #A9AFB6;      /* >= 4.5:1 on every dark plane incl. bg-3 */
}
html[data-forge-theme="dark"] body.forge-cinematic-v1 {
  --fg-3: #A9AFB6;
  --line-3: #76848F;
  --danger: #FF9486;
  --ok: #88BF95;
  --success: #88BF95;
}
:root[data-forge-theme="dark"] {
  --fg-3: rgba(245,245,247,.58);
  color-scheme: dark;
}
/* Two shipped Dark components failed in the rendered audit:
 *   avatar initials: #fff on the #5b8aff -> #c084fc gradient      2.64 -> ink 6.15
 *   founder-shell commit: #fff on --forge-crimson #ff1738          3.87 -> 5.26
 *     (crimson deepened one step; label stays white, hue unchanged) */
html[data-forge-theme="dark"] .avatar,
html[data-forge-theme="dark"] #fnav-avatar.avatar { color: #0B0A09; }
html[data-forge-theme="dark"].forge-founder-shell-v1 .btn-commit { background: #D70F2C !important; }

/* ------------------------------------------------------------ Light chrome
 * Hand layer: the few places where a faithful literal mapping is not enough to
 * read as designed-for-light.
 */
html[data-forge-theme="light"] body { background: var(--fx-canvas); color: var(--fx-text); }
html[data-forge-theme="light"] ::selection { background: #CFDBF6; color: var(--fx-text); }
html[data-forge-theme="light"] :focus-visible { outline-color: var(--fx-focus); }
/* Active Loads cards are selectable physical objects. In dark they are a lifted
   graphite plane; the light idiom for the same thing is a white card with an
   outline and a soft shadow, not a grey slab. */
html[data-forge-theme="light"].forge-founder-shell-v1 body[data-active="weighbridge"] .active-load-card {
  background: var(--fx-surface); border-color: var(--fx-line-2); box-shadow: var(--fx-shadow);
}
html[data-forge-theme="light"].forge-founder-shell-v1 body[data-active="weighbridge"] .active-load-card:hover {
  background: var(--fx-raised); border-color: var(--fx-line-strong);
}
/* Schedule's completed-history card is de-emphasised with opacity .72 on black.
   On a light ground that drops muted text under 4.5:1; recede it with the
   raised plane instead, at full opacity. */
html[data-forge-theme="light"].forge-founder-shell-v1 body[data-active="schedule"] #sched-sections > .sched-card:nth-child(2) {
  opacity: 1; background: var(--fx-raised);
}

/* ------------------------------------------------------------ Toggle
 * 44px tap target (glove-friendly); no hover-only affordance; text label, not
 * an icon, so the state is readable on a cheap screen in daylight.
 */
/* Anchored on the id: route pages carry bare `button{}` rules that must not
   restyle the toggle. */
#forge-theme-toggle.forge-theme-toggle {
  appearance: none; -webkit-appearance: none;
  min-height: 44px; min-width: 64px; padding: 0 14px;
  border-radius: 999px; cursor: pointer;
  font: 600 12px/1 "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  letter-spacing: .02em;
  background: transparent;
  color: var(--fg, #F2F4F6);
  border: 1px solid var(--line-3, #76848F);
}
#forge-theme-toggle.forge-theme-toggle:focus-visible { outline: 2px solid var(--fx-focus, #8FB0FF); outline-offset: 2px; }
#forge-theme-toggle.forge-theme-toggle--float { position: fixed; right: 16px; bottom: 16px; z-index: 2147483000; background: var(--bg-2, #131316); }
html[data-forge-theme="light"] #forge-theme-toggle.forge-theme-toggle { color: var(--fx-text); border-color: var(--fx-line-strong); background: var(--fx-surface); box-shadow: none; }
@media print { .forge-theme-toggle { display: none !important; } }

/* Brief interaction feedback only. No entry animations, layout movement or timers. */
@media screen and (prefers-reduced-motion: no-preference) {
  html[data-forge-theme] :is(.btn, .btn2, .dq, .forge-theme-toggle, .gbar a, #fnav a) {
    transition: background-color 120ms ease-out, border-color 120ms ease-out, box-shadow 120ms ease-out;
  }
}
@media (prefers-reduced-motion: reduce) {
  html[data-forge-theme] :is(.btn, .btn2, .dq, .forge-theme-toggle, .gbar a, #fnav a) {
    transition: none !important;
  }
}
@media print {
  html[data-forge-theme] :is(.btn, .btn2, .dq, .forge-theme-toggle, .gbar a, #fnav a) {
    transition: none !important;
  }
}
