/* tokens.css — Stradl / ImpactForce application UI
 * Themeable: Light / Dark / Auto. Map-first. Brand values from the official guide.
 *
 * THEME RESOLUTION
 *   - Dark is the product default (declared in :root).
 *   - [data-theme="light"] / [data-theme="dark"] force a theme.
 *   - "Auto" is resolved in JS (matchMedia) by /theme-loader.js setting
 *     data-theme to light|dark and updating on change — see DESIGN.md §2A.
 *     (The no-JS @media fallback block was removed 2026-06-02.)
 *
 * Fonts (self-hosted in /fonts/, never a CDN):
 *   IBM Plex Sans  ONE face for everything since 2026-11-03 (the MediPet
 *                  look): UI, headings, numbers, the brand register, both
 *                  products. One variable woff2, weights 400 to 600, latin,
 *                  Google Fonts (OFL). Numbers line up by tabular figures,
 *                  not by a mono family.
 *   IBM Plex Mono  code, logs, connection strings and key hints only
 *                  (--font-code). woff2 400/500/600 latin, OFL.
 *   Satoshi and Poppins are retired (no @font-face). The Satoshi woff2
 *   files stay in /fonts/ only so an old cached page does not 404.
 */

@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/plexsans-var.woff2') format('woff2');
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/plexmono-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/plexmono-500.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/plexmono-600.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  /* ===== THEME-INVARIANT ===== */

  /* Brand palette (exact, from guide) */
  --brand-navy:  #0A2D4D;
  --brand-blue:  #0D6EFD;
  --brand-teal:  #00B2A9;
  --brand-green: #5CCB3B;
  --brand-light: #E6ECEF;

  /* Reserved brand gradient (logo / splash / app-icon ONLY) */
  --brand-gradient: linear-gradient(120deg, #0D6EFD, #00B2A9, #5CCB3B);

  /* LSM sequential ramp (1 low -> 10 high). Data fill — same in both themes;
     raise choropleth opacity slightly in light mode if it washes out. */
  --lsm-1:  #0A2D4D;  --lsm-2:  #0E3E63;  --lsm-3:  #11507A;  --lsm-4:  #126E9A;
  --lsm-5:  #0E8E96;  --lsm-6:  #00B2A9;  --lsm-7:  #1FBE8C;  --lsm-8:  #3DC76A;
  --lsm-9:  #5CCB3B;  --lsm-10: #8FD96A;

  /* Typography */
  --font-ui:    'IBM Plex Sans', 'Segoe UI', Arial, sans-serif;   /* the one face (2026-11-03) */
  --font-brand: var(--font-ui);                              /* brand register: same face, weight 600 */
  --font-data:  var(--font-ui);                              /* numbers, codes, IDs: same face, tabular figures */
  --font-code:  'IBM Plex Mono', Consolas, monospace;        /* code, logs, connection strings only */
  --text-2xs: 11px; --lh-2xs: 14px;  --text-xs:  12px; --lh-xs:  16px;
  --text-sm:  13px; --lh-sm:  18px;  --text-base:14px; --lh-base:20px;
  --text-lg:  16px; --lh-lg:  22px;  --text-xl:  20px; --lh-xl:  26px;
  --data-lg:  22px;   /* band figures (2026-11-03, board L01) */
  --data-xl:  28px; --lh-dxl: 32px;

  /* Spacing (4px base) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px;
  --space-4: 16px; --space-5: 24px; --space-6: 32px;

  /* Radius (nothing > 8px) */
  --radius-sm: 4px;  --radius-md: 6px;  --radius-lg: 8px;

  /* Layout dims */
  --topbar-h: 48px;  --rail-w: 56px;  --inspector-w: 360px;

  /* Row heights (2026-09-14, guide v2 §5): dense is the table default;
     comfortable for rows that carry a pill AND a second line. The 32px
     dense spec is retired — 36px is what a pill + mono ID at 13px needs. */
  --row-dense: 36px;  --row: 40px;

  /* Breakpoints (2026-09-14, guide v2 §5A). Three, nowhere else. Custom
     properties cannot be read inside @media, so the literals below are
     the ONLY widths allowed in a media query (stylelint enforces it):
       900px  = --bp-narrow  (sidebar → drawer, tables → card rows)
       1280px = --bp-laptop  (module tabs → icons, column budget applies)
       1480px = --bp-wide    (content max-width) */
  --bp-narrow: 900px;  --bp-laptop: 1280px;  --bp-wide: 1480px;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);  --dur-fast: 150ms;  --dur: 200ms;

  /* ===== DARK THEME (default) ===== */

  /* Surfaces */
  --surface-900: #06203A;   /* app background */
  --surface-800: #0A2D4D;   /* primary panel / sidebar (= brand navy) */
  --surface-700: #0F3A5E;   /* raised panel / popover */
  --surface-600: #16486F;   /* hover / input bg */
  --surface-500: #235680;   /* borders / dividers */

  /* Text */
  --text-primary:   #F0F4F7;
  --text-secondary: #9DB2C4;
  --text-muted:     #7F96AC;   /* 2026-08-09 contrast bump (was #5E7892 @ 3.06:1) — 4.57:1 on surface-800 */

  /* Interactive (brand blue) */
  --accent:        #0D6EFD;
  --accent-hover:  #3D8BFF;
  --accent-muted:  rgba(13, 110, 253, 0.16);
  --accent-text:   #4A92FE;   /* text links on dark surfaces — --accent itself is 3.1:1 as text; use for fills, this for copy */

  /* Status */
  --positive: #5CCB3B;
  --warning:  #E8A13A;
  --orange:   #E8763A;   /* functional, off-palette — sits between warning and negative for 4-tier expiry grading (permits) */
  --negative: #F06573;   /* 2026-08-09 contrast bump (was #EF5C6B @ 4.29:1) — 4.56:1 */

  /* Status tints — pill/badge backgrounds + borders (theme-aware; use with
     the matching status colour as text) */
  --positive-bg:     rgba(92, 203, 59, 0.14);
  --positive-border: rgba(92, 203, 59, 0.36);
  --warning-bg:      rgba(232, 161, 58, 0.14);
  --warning-border:  rgba(232, 161, 58, 0.36);
  --orange-bg:       rgba(232, 118, 58, 0.14);
  --orange-border:   rgba(232, 118, 58, 0.36);
  --negative-bg:     rgba(240, 101, 115, 0.12);
  --negative-border: rgba(240, 101, 115, 0.36);
  --neutral-bg:      rgba(157, 178, 196, 0.14);  /* muted/neutral pills (draft, inactive) */
  --neutral-border:  rgba(157, 178, 196, 0.32);

  /* Info tone (2026-09-14, guide v2 §2): in-progress / assigned / running /
     pending reply. Desaturated blue on dark so it never reads as a link. */
  --info:        #7FB2FF;   /* 6.9:1 on surface-800 */
  --info-bg:     rgba(127, 178, 255, 0.14);
  --info-border: rgba(127, 178, 255, 0.36);

  /* The one modal / drawer scrim */
  --overlay: rgba(0, 0, 0, 0.6);

  /* Skeleton block (§12) */
  --skel: var(--surface-600);

  /* Availability grid cells (§7 .grid-avail): free is the ABSENCE of colour;
     the eye lands on what is booked. */
  --grid-free:     var(--surface-700);
  --grid-weekend:  var(--surface-600);
  --grid-held:     var(--warning-bg);
  --grid-booked:   var(--accent-muted);
  --grid-conflict: var(--negative-bg);

  /* Map cluster bubbles (§3): site colour fill, mono count on it */
  --cluster-bg:   var(--map-site-ring);
  --cluster-text: #FFFFFF;

  /* Teal accent-as-text (data/connectivity states: completed, ready, approved) */
  --teal-text:   #00B2A9;   /* = brand teal; 5.3:1 on surface-800 */
  --teal-text-hover: #33C1BA; /* hover step for teal-as-accent (lighter on dark) */
  --teal-bg:     rgba(0, 178, 169, 0.13);
  --teal-border: rgba(0, 178, 169, 0.34);

  /* AI-agent identity gradient (avatars/chips for Sela/Annie/Liam/Terry etc.)
     — theme-invariant, distinct from the reserved --brand-gradient */
  --ai-gradient: linear-gradient(135deg, #0F766E, #06B6D4);

  /* Map semantics — canonical entity colours, validated against the LIVE
     streets-v12 basemap (2026-08-09). THEME-INVARIANT: the basemap does not
     flip with the app theme, so these live here in :root only. Mapbox paint
     properties can't consume var() — copy these literals into layer code
     (and keep them in sync), or resolve via getComputedStyle. */
  --map-site:        #0A2D4D;   /* navy pin on light streets land; tenant primary may override (white-label) */
  --map-site-ring:   #0D6EFD;
  --map-cone-fill:   rgba(0, 178, 169, 0.22);
  --map-cone-stroke: #008C85;   /* 3.6:1 on streets land */
  --map-worm:        #DA8420;   /* amber, off-palette */
  --map-worm-casing: #F2A93B;
  --map-taxi-rank:   #8E4FC4;   /* violet, off-palette */
  /* Muted framing values (map-page chrome, NOT the live basemap style) */
  --map-land:  #08263F;
  --map-water: #061B2E;
  --map-road:  #235680;

  /* Elevation */
  --border: 1px solid var(--surface-500);
  --shadow-panel:   none;
  --shadow-popover: 0 8px 24px rgba(0, 0, 0, 0.45);

  /* MediPet look, phase 1 (2026-11-03, board L01). A field's edge stays at
     3:1 against the panel while buttons drop to the hairline; the rest are
     declared now and first used in phases 2 and 3. */
  --field-border:  var(--text-muted);
  --divider-soft:  var(--surface-600);
  --note-bg:       #2D2611;   /* the analyst panel's paper: its own token, never --warning-bg */
  --note-border:   #5A4C24;
  /* Chart series, not tones: a line in --viz-3 does not mean "waiting". */
  --viz-1: #4A92FE;  --viz-2: #00B2A9;  --viz-3: #E8A13A;  --viz-4: #9DB2C4;  --viz-5: #E8763A;
}

/* ===== LIGHT THEME ===== */
:root[data-theme="light"] {
  /* Surfaces (roles preserved: 900 = canvas, 800 = panel, 500 = border) */
  /* 2026-11-03 (board L01): neutral greys from MediPet, so the data
     colours have something neutral to stand on. Were #EDF1F5 / #E7EDF3 /
     #D3DCE5, all faintly blue. */
  --surface-900: #F5F7F9;   /* app background (light grey canvas) */
  --surface-800: #FFFFFF;   /* primary panel / sidebar */
  --surface-700: #FFFFFF;   /* raised / popover — lifted by --shadow-popover */
  --surface-600: #EDF0F4;   /* hover / input bg / header fill */
  --surface-500: #DCE0E5;   /* borders / dividers */

  /* Text: neutral ink, off brand navy (was #0A2D4D / #44607C / #5A7085). */
  --text-primary:   #1B222B;   /* 15.9:1 on white */
  --text-secondary: #4E5661;   /* 7.4:1 on white */
  --text-muted:     #646A72;   /* 4.78:1 on --surface-600, 5.5:1 on white; MediPet's #6C727A is 4.25 on its nav grey */

  --field-border:  #8A939D;   /* 3.12:1 on white: the hairline (1.33:1) is too faint for a white field */
  --divider-soft:  #E8EBEF;
  --note-bg:       #FFFBD9;
  --note-border:   #E5D4A0;
  --viz-1: #0D6EFD;  --viz-2: #0F766E;  --viz-3: #A26917;  --viz-4: #6B7280;  --viz-5: #C2551B;

  /* Interactive */
  --accent:        #0D6EFD;
  --accent-hover:  #0B5ED7;    /* darker hover reads better on light */
  --accent-muted:  rgba(13, 110, 253, 0.10);
  --accent-text:   #0B5ED7;    /* text links — #0D6EFD is 4.50:1 (borderline); this is comfortably clear */

  /* Status (darkened for contrast on white; all ≥4.5:1 as text since 2026-08-09) */
  --positive: #2D860A;   /* was #36A30C @ 3.28:1 */
  --warning:  #A26917;   /* was #C9821C @ 3.14:1 */
  --orange:   #C2551B;   /* was #C9581C @ 4.29:1 */
  --negative: #DA3648;   /* was #DB3B4D @ 4.43:1 */

  /* Status tints — lighter alpha over white so pills stay pastel */
  --positive-bg:     rgba(45, 134, 10, 0.10);
  --positive-border: rgba(45, 134, 10, 0.30);
  --warning-bg:      rgba(162, 105, 23, 0.10);
  --warning-border:  rgba(162, 105, 23, 0.30);
  --orange-bg:       rgba(194, 85, 27, 0.10);
  --orange-border:   rgba(194, 85, 27, 0.30);
  --negative-bg:     rgba(218, 54, 72, 0.08);
  --negative-border: rgba(218, 54, 72, 0.30);
  --neutral-bg:      rgba(68, 96, 124, 0.08);
  --neutral-border:  rgba(68, 96, 124, 0.25);

  /* Info tone — derived from the accent, darkened to clear 4.5:1 on white */
  --info:        #0B5ED7;
  --info-bg:     rgba(13, 110, 253, 0.08);
  --info-border: rgba(13, 110, 253, 0.28);

  --overlay: rgba(6, 32, 58, 0.5);
  --skel:    var(--surface-600);
  /* grid + cluster tokens resolve through the theme-aware tokens above */

  /* Teal accent-as-text — darkened for white (brand teal is 2.9:1 there) */
  --teal-text:   #0F766E;   /* 5.5:1 on white */
  --teal-text-hover: #0C5F59; /* hover step for teal-as-accent (darker on light) */
  --teal-bg:     rgba(15, 118, 110, 0.09);
  --teal-border: rgba(15, 118, 110, 0.28);

  /* Map entity colours: no light-theme overrides — theme-invariant, see the
     canonical set in :root (the streets-v12 basemap never theme-flips). */

  /* Elevation — 2026-09-14 (guide v2 §5): no shadow on cards or tiles in
     either theme; borders carry the edge. Shadow is for popovers, menus and
     drawers only. */
  --shadow-panel:   none;
  --shadow-popover: 0 8px 24px rgba(10,45,77,0.14);
}

/* No-JS fallback removed 2026-06-02. Auto is resolved in JS via
   the theme provider in /theme-loader.js (see DESIGN.md §2A). */

body {
  background: var(--surface-900);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  font-weight: 400;
}

/* All numbers tabular mono so columns align. (.metric was narrowed to
   .metric-value 2026-08-13 — crm-dashboard uses .metric for a whole card
   link whose label must stay in the UI face.) */
.num, .metric-value, td.num, [data-numeric] {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
}
