/*
 * InfoDasher dashboard theme: the one place for dashboard colours, in light and dark.
 *
 * Every public dashboard (GDP, Cost of Travel, Crash Watch, Rand Tracker, Joburg Watch, Coming soon) and the
 * dashboard shell read these tokens. Pages must not hard-code colours: use var(--id-...). Charts read the
 * --id-series-* slots in order (never cycled) and --id-grid / --id-axis; they re-draw on the
 * `id:themechange` event (see assets/js/dashboard-space.js).
 *
 * How the theme is chosen: an inline script in src/includes/header.php sets <html data-theme="light|dark">
 * before the CSS loads (from the visitor's choice in localStorage 'id-theme', else the system setting), so
 * there is no flash. Without JavaScript the prefers-color-scheme block below applies.
 *
 * Brand: navy #043450, orange #f6943b / #f1731f, blue #1d5e84 / #86bdde, light #f2f3f5, dark #00131f
 * (assets/css/custom-theme.css, the Bootstrap build, and the logo).
 * Chart slots: the dataviz reference palette (blue, orange, aqua, yellow, magenta, violet), validated
 * 8 Nov 2026 with validate_palette.js: light on #ffffff passes lightness, chroma, CVD (worst 9.1) and
 * normal-vision (19.6); slots 3-5 are under 3:1 on white, so charts with three or more series need direct
 * labels or a table. Dark on #0b1f2c passes all checks (CVD worst 8.4).
 */
:root {
  color-scheme: light;
  /* surfaces */
  --id-bg: #f2f3f5;
  --id-surface: #ffffff;
  --id-surface-2: #f4f7f9;
  --id-surface-3: #eaf1f6;
  --id-line: #d5dce1;
  --id-line-strong: #c5ced4;
  /* text */
  --id-heading: #043450;
  --id-text: #153b53;
  --id-text-2: #345d73;
  --id-mute: #52717f;   /* 4.57:1 or more on every light surface */
  --id-faint: #5a6e7a;  /* small print; 4.67:1 or more */
  /* shared hover/help surfaces */
  --id-tooltip-bg: var(--id-surface-2);
  --id-tooltip-text: var(--id-text);
  --id-tooltip-muted: var(--id-text-2);
  --id-tooltip-border: var(--id-line-strong);
  /* brand and interaction */
  --id-primary: #043450;
  --id-primary-ui: #2d6180;
  --id-primary-ui-hover: #234f69;
  --id-on-primary: #ffffff;
  --id-control-highlight-bg: var(--bs-info);
  --id-control-highlight-text: var(--bs-primary);
  --id-control-highlight-border: var(--bs-success);
  --id-link: #1d5e84;
  --id-accent: #f6943b;
  --id-accent-strong: #f1731f;
  --id-focus: #2d6180;
  --id-current: #245b7c;
  --id-backdrop: rgba(21, 59, 83, 0.3);
  --id-shadow: rgba(21, 59, 83, 0.06);
  /* badges and notices */
  --id-badge-bg: #eef2f5;
  --id-badge-text: #52717f;
  --id-beta-bg: #fdf0d5;
  --id-beta-text: #8a5300;
  --id-notice-bg: #fffaf0;
  --id-notice-line: #f1d9a6;
  --id-notice-text: #5c4a2a;
  /* meaning: up/down, good/bad (text-safe on the surface) */
  --id-good: #12733c;
  --id-bad: #c0312b;
  --id-warn: #a35400;
  --id-good-bg: #e6f4ec;
  --id-bad-bg: #fbe9e7;
  /* charts */
  --id-bar-positive: #1d5e84;
  --id-series-1: #2a78d6;
  --id-treemap-lead: #267d93;
  --id-treemap-tile: #4b5666;
  --id-series-2: #eb6834;
  --id-series-3: #1baf7a;
  --id-series-4: #eda100;
  --id-series-5: #e87ba4;
  --id-series-6: #6250d6;
  --id-grid: #e3e8ec;
  --id-axis: #597a8a;
  --id-chart-neutral: #8c9aa3;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --id-bg: #00131f;
  --id-surface: #0b1f2c;
  --id-surface-2: #10293a;
  --id-surface-3: #153449;
  --id-line: #1e3a4d;
  --id-line-strong: #2c4b60;
  --id-heading: #f2f6f8;
  --id-text: #dbe5ec;
  --id-text-2: #b9cbd7;
  --id-mute: #93abba;
  --id-faint: #7d93a1;
  --id-tooltip-bg: #244357;
  --id-tooltip-border: #456478;
  --id-primary: #86bdde;
  --id-primary-ui: #1d5e84;
  --id-primary-ui-hover: #24709c;
  --id-on-primary: #ffffff;
  --id-link: #86bdde;
  --id-accent: #f6943b;
  --id-accent-strong: #f6943b;
  --id-focus: #86bdde;
  --id-current: #cfe6f5;
  --id-backdrop: rgba(0, 0, 0, 0.55);
  --id-shadow: rgba(0, 0, 0, 0.3);
  --id-badge-bg: #173246;
  --id-badge-text: #b9cbd7;
  --id-beta-bg: #3a2a0c;
  --id-beta-text: #f3c06b;
  --id-notice-bg: #1d1910;
  --id-notice-line: #5a4318;
  --id-notice-text: #ecd9b4;
  --id-good: #4cc38a;
  --id-bad: #ff7a70;
  --id-warn: #f0a24a;
  --id-good-bg: #0f3324;
  --id-bad-bg: #3a1614;
  --id-bar-positive: #86bdde;
  --id-series-1: #3987e5;
  --id-series-2: #d95926;
  --id-series-3: #199e70;
  --id-series-4: #c98500;
  --id-series-5: #d55181;
  --id-series-6: #9085e9;
  --id-grid: #183245;
  --id-axis: #93abba;
  --id-chart-neutral: #6f8696;
}

/* No JavaScript: follow the system. (With JavaScript, data-theme is always set.) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --id-bg: #00131f; --id-surface: #0b1f2c; --id-surface-2: #10293a; --id-surface-3: #153449;
    --id-line: #1e3a4d; --id-line-strong: #2c4b60;
    --id-heading: #f2f6f8; --id-text: #dbe5ec; --id-text-2: #b9cbd7; --id-mute: #93abba; --id-faint: #7d93a1;
    --id-tooltip-bg: #244357; --id-tooltip-border: #456478;
    --id-primary: #86bdde; --id-primary-ui: #1d5e84; --id-primary-ui-hover: #24709c; --id-link: #86bdde;
    --id-accent-strong: #f6943b; --id-focus: #86bdde; --id-current: #cfe6f5;
    --id-backdrop: rgba(0, 0, 0, 0.55); --id-shadow: rgba(0, 0, 0, 0.3);
    --id-badge-bg: #173246; --id-badge-text: #b9cbd7; --id-beta-bg: #3a2a0c; --id-beta-text: #f3c06b;
    --id-notice-bg: #1d1910; --id-notice-line: #5a4318; --id-notice-text: #ecd9b4;
    --id-good: #4cc38a; --id-bad: #ff7a70; --id-warn: #f0a24a; --id-good-bg: #0f3324; --id-bad-bg: #3a1614;
    --id-bar-positive: #86bdde;
    --id-series-1: #3987e5; --id-series-2: #d95926; --id-series-3: #199e70; --id-series-4: #c98500;
    --id-series-5: #d55181; --id-series-6: #9085e9; --id-grid: #183245; --id-axis: #93abba; --id-chart-neutral: #6f8696;
  }
}

/* The logo: navy wordmark in light, a light wordmark in dark. */
.id-logo-dark { display: none; }
:root[data-theme="dark"] .id-logo-light { display: none; }
:root[data-theme="dark"] .id-logo-dark { display: inline-block; }

/* The theme switch in the dashboard top bar. */
.dashboard-theme { margin-left: auto; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 42px; height: 42px; padding: 0; border: 1px solid var(--id-line-strong); border-radius: 50%; background: transparent; color: var(--id-heading); cursor: pointer; }
.dashboard-theme:hover { background: var(--id-surface-2); }
.dashboard-theme svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dashboard-theme .dashboard-theme-sun { display: none; }
:root[data-theme="dark"] .dashboard-theme-moon { display: none; }
:root[data-theme="dark"] .dashboard-theme-sun { display: block; }
.dashboard-theme:focus-visible { outline: 2px solid var(--id-focus); outline-offset: 3px; }
.dashboard-theme + .dashboard-account { margin-left: 0; }

/* All Bootstrap help bubbles in the public dashboard shell share a softer surface. */
body.dashboard-space .tooltip { --bs-tooltip-bg: var(--id-tooltip-bg); --bs-tooltip-color: var(--id-tooltip-text); --bs-tooltip-opacity: 1; }
body.dashboard-space .tooltip .tooltip-inner { border: 1px solid var(--id-tooltip-border); border-radius: 8px; box-shadow: 0 4px 14px var(--id-shadow); }
body.dashboard-space .popover { --bs-popover-bg: var(--id-tooltip-bg); --bs-popover-body-color: var(--id-tooltip-text); --bs-popover-header-bg: var(--id-tooltip-bg); --bs-popover-header-color: var(--id-tooltip-text); --bs-popover-border-color: var(--id-tooltip-border); border-radius: 8px; box-shadow: 0 4px 14px var(--id-shadow); }

/* KPI strips remain swipeable in the mobile shell without displaying a scroll track. */
@media (max-width: 991.98px) {
  body.dashboard-space main :is(.production-headlines, .rt-kpis, .yi-kpis, .cw-rings, .cot-stats) { scrollbar-width: none; }
  body.dashboard-space main :is(.production-headlines, .rt-kpis, .yi-kpis, .cw-rings, .cot-stats)::-webkit-scrollbar { display: none; }
}

/* Bootstrap in dark: brand its stock dark colours (custom-theme.css ships Bootstrap's grey #212529 set). */
:root[data-theme="dark"] {
  --bs-body-bg: var(--id-surface);
  --bs-body-color: var(--id-text);
  --bs-emphasis-color: var(--id-heading);
  --bs-secondary-color: var(--id-mute);
  --bs-secondary-bg: var(--id-surface-2);
  --bs-tertiary-bg: var(--id-surface-2);
  --bs-border-color: var(--id-line);
  --bs-heading-color: var(--id-heading);
  --bs-link-color: var(--id-link);
  --bs-link-hover-color: var(--id-heading);
  --bs-link-color-rgb: 134, 189, 222;
}
/* style.css colours every h1-h3 navy; in dark they follow the theme. :where keeps this at element weight,
   so any page class that colours a heading still wins. */
:where(:root[data-theme="dark"]) :is(h1, h2, h3) { color: var(--id-heading); }
