/* ============================================================
   DORIA – Design Tokens
   All visual constants live here. Edit once, apply everywhere.

   THE APP DEFAULT IS THE TACTICAL LOOK (2026-10-22). Pure black
   (white in light mode), neutral greys, JetBrains Mono throughout.
   These tokens used to carry the earlier corporate design (cool slate
   #07090e / #0d1117, Syne labels, DM Sans body) and each page painted
   the tactical look over them in its own stylesheet, so any page or
   shared component that didn't override them fell back to slate and
   Syne. The defaults now are the tactical look; a page needs no
   override to get it. tests/tacticalTheme.test.js loads every route
   and fails on a slate surface or Syne / DM Sans text.

   The public landing pages (doria.html, contact.html, systemaccess.html)
   and login.html don't load this file; they keep their own fonts.
   ============================================================ */

:root {
  /* ── Colour Palette ──────────────────────────────────────── */
  --clr-bg:        #000000;   /* Page: pure black               */
  --clr-surface:   #000000;   /* Card / panel: black, edged by --clr-border */
  --clr-surface-2: #111111;   /* Input / nested panel (= --surface-field) */
  --clr-surface-3: #1a1a1a;   /* Deeply nested / dropdown       */
  --clr-border:    rgba(255, 255, 255, 0.10); /* Hairline rule  */
  --clr-rule:      rgba(255, 255, 255, 0.10); /* Gap-trick alias */

  /* Brand: lime — used surgically on CTAs, active states, data accent */
  --clr-brand:      #b8f000;
  --clr-brand-dim:  #8ab800;
  --clr-brand-glow: rgba(184, 240, 0, 0.09);

  /* Supporting accents */
  --clr-accent:   #00c8e0;   /* Data highlight / info          */
  --clr-warning:  #d98c00;   /* Pending / caution              */
  --clr-danger:   #e03c3c;   /* Rejected / error               */
  --clr-success:  var(--clr-brand);

  /* Text — neutral greys (were cool blue-greys). Contrast on black:
     text 17.1:1, muted 8.3:1, dim 4.4:1 (dim was 4.2:1). */
  --clr-text:         #e8e8e8;  /* Primary                        */
  --clr-text-muted:   #a3a3a3;  /* Secondary                      */
  --clr-text-dim:     #727272;  /* Tertiary — disabled/captions   */
  --clr-text-inverse: #000000;  /* Text on bright surfaces        */

  /* ── Typography ─────────────────────────────────────────── */
  /* Display face for stat numbers and H1. Was Bebas Neue, a condensed
     caps-only display face; now JetBrains Mono so the headings sit in the
     same family as the rest of the data type. Every consumer routes through
     this token, so a future swap is a one-line change.
     NOTE: JetBrains Mono self-hosts 400 and 500 only (see fonts.css), and
     it is fixed-width at 0.6em per glyph against Bebas's ~0.42em, so it
     sets ~1.4x wider at the same font-size. */
  --font-display: 'JetBrains Mono', 'Fira Code', monospace;
  /* Labels and body copy were Syne and DM Sans, the marketing-site
     faces; the app is mono throughout. Kept as separate tokens so the
     roles stay visible at call sites. */
  --font-label:   'JetBrains Mono', 'Fira Code', monospace; /* Card titles / nav labels */
  --font-sans:    'JetBrains Mono', 'Fira Code', monospace; /* Body / UI copy */
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace; /* Data / IDs */

  /* Type scale — 4px step base */
  --text-2xs:  0.75rem;    /* 12px — badges, captions        */
  --text-xs:   0.8125rem;  /* 13px — labels, meta            */
  --text-sm:   0.875rem;   /* 14px — body default            */
  --text-base: 1rem;       /* 16px                           */
  --text-lg:   1.125rem;   /* 18px                           */
  --text-xl:   1.25rem;    /* 20px                           */
  --text-2xl:  1.5rem;     /* 24px                           */
  --text-3xl:  2rem;       /* 32px                           */

  --fw-light:    300;
  --fw-regular:  400;
  --fw-medium:   500;
  /* JetBrains Mono ships 400 and 500 only (fonts.css): 600/700 would be
     a browser-synthesised faux bold. Tactical type tops out at 500. */
  --fw-semibold: 500;
  --fw-bold:     500;

  /* ── Spacing (8px base grid) ─────────────────────────────── */
  --sp-1:  0.25rem;   /*  4px */
  --sp-2:  0.5rem;    /*  8px */
  --sp-3:  0.75rem;   /* 12px */
  --sp-4:  1rem;      /* 16px */
  --sp-5:  1.25rem;   /* 20px */
  --sp-6:  1.5rem;    /* 24px */
  --sp-8:  2rem;      /* 32px */
  --sp-10: 2.5rem;    /* 40px */
  --sp-12: 3rem;      /* 48px */
  --sp-16: 4rem;      /* 64px */
  --sp-20: 5rem;      /* 80px */

  /* ── Shape — sharp edges throughout ─────────────────────── */
  --radius-sm:   0px;
  --radius-md:   0px;
  --radius-lg:   0px;
  --radius-xl:   0px;
  --radius-full: 0px;

  /* Deliberate, narrow exception to the rule above: floating map chrome
     on mobile (Deploy Order / Submit Report / Report Detail — screens
     that are a full-bleed map with cards floating over it) reads as a
     paste-on box at true 0px radius the way it doesn't on the rest of
     the app's flat list/table surfaces. Soft, not round — nowhere close
     to --radius-full's pill shape. Not used outside those mobile map
     overlays; every other surface keeps the sharp corners above. */
  --radius-soft: 6px;

  /* ── Shadows — depth, not brand-colored ─────────────────── */
  --shadow-xs:   0 1px 2px rgba(0, 0, 0, 0.40);
  --shadow-sm:   0 2px 6px rgba(0, 0, 0, 0.50);
  --shadow-md:   0 4px 16px rgba(0, 0, 0, 0.55);
  --shadow-lg:   0 8px 32px rgba(0, 0, 0, 0.60);
  --shadow-glow: 0 0 20px rgba(184, 240, 0, 0.10);

  /* ── Easing ──────────────────────────────────────────────── */
  --ease:              cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast:   140ms var(--ease);
  --transition-normal: 260ms var(--ease);
  --transition-slow:   440ms var(--ease);

  /* ── Layout ──────────────────────────────────────────────── */
  --sidebar-w:     220px;
  --topbar-h:      56px;
  --content-max:   1200px;
  --content-pad:   clamp(1.25rem, 2.5vw, 2rem);
  --z-sidebar:     9800;
  --z-topbar:      9900;
  --z-modal:       10000;
  --z-toast:       10100;
  /* Shifted up from 100/200/300/400 (relative order unchanged) because
     several page-specific overlays built independently of this scale
     already use z-index values up to 9999 (.tb-notif-panel, login/reset
     page overlays) or 900 (Ops Console's .ts-dock) — a shared Modal opened
     on top of any of them (e.g. the camera-trap "Recent Captures" reel
     opened from Ops Console's sensor dock) rendered hidden behind them
     instead of on top, since 300 lost to all of those. See
     Documentation/28-camera-trap-alerts-and-recent-captures.md. */
}

/* ── Mobile scale ─────────────────────────────────────────────
   The desktop type/spacing scale above was eyeballed at desktop widths
   and then just clamp()'d narrower for mobile — clamp() shrinks a value
   toward its floor, it does not re-derive a scale meant for a 6" screen.
   Two symptoms of that gap, both visible on real phones: hero headings
   (--text-3xl, 32px) eating a third of the viewport height on pages like
   Species Intelligence and Flashpoints, and section gaps (--sp-8/10/12,
   32-48px) built for a 1200px-wide layout reading as dead air on a
   412px one. This block re-derives both scales for <=640px so every
   consumer that already routes through a token gets a real mobile
   scale for free, not a smaller version of the desktop one.
   Layout tokens (--sidebar-w, --topbar-h) are untouched: the sidebar is
   already off-canvas below this width and the topbar's own 44px
   touch-target rules live in layout.css's breakpoint. */
@media (max-width: 640px) {
  :root {
    --text-2xs:  0.6875rem; /* 11px */
    --text-xs:   0.75rem;   /* 12px */
    --text-sm:   0.8125rem; /* 13px */
    --text-base: 0.9375rem; /* 15px */
    --text-lg:   1.0625rem; /* 17px */
    --text-xl:   1.125rem;  /* 18px */
    --text-2xl:  1.25rem;   /* 20px */
    --text-3xl:  1.5rem;    /* 24px */

    --sp-4:  0.75rem;  /* 12px, was 16px */
    --sp-5:  1rem;     /* 16px, was 20px */
    --sp-6:  1.125rem; /* 18px, was 24px */
    --sp-8:  1.5rem;   /* 24px, was 32px */
    --sp-10: 1.75rem;  /* 28px, was 40px */
    --sp-12: 2rem;     /* 32px, was 48px */
    --sp-16: 2.5rem;   /* 40px, was 64px */
    --sp-20: 3rem;     /* 48px, was 80px */

    /* 16px is the conventional mobile side gutter (iOS HIG / Material);
       the desktop clamp floor of 1.25rem (20px) never reaches it. */
    --content-pad: clamp(1rem, 4vw, 2.5rem);
  }
}

/* ── Font Scale ─────────────────────────────────────────────
   Applied via data-font-size attribute on <html>.
   Targets .main-content with zoom so that all content scales
   uniformly — px values, rem values, spacing — regardless of
   how individual page CSS files declare their sizes.
   The shell (sidebar, topbar) is intentionally unaffected.
   ─────────────────────────────────────────────────────────── */
html[data-font-size="large"]  .main-content { zoom: 1.125; }
html[data-font-size="xlarge"] .main-content { zoom: 1.25;  }

/* ── Theme channels ─────────────────────────────────────────
   THE PROBLEM THESE SOLVE
   ───────────────────────
   The --clr-* tokens above flip correctly with the theme, so any rule
   that uses them adapts for free. But large parts of this codebase were
   written straight against hardcoded values — rgba(255,255,255,0.06)
   for a hairline, #c3ff00 for an accent — which bypass the token layer
   entirely and therefore do not flip. Light mode was then retrofitted by
   hand-writing `body.light .some-class { ... }` overrides one selector
   at a time, which is why coverage was partial: an audit found 124
   hardcoded sites across 20 files with no light counterpart.

   The failure is not cosmetic. `.sa-session-card` hardcoded
   `background: #000000` while its text used var(--clr-text), so in light
   mode the card stayed pure black and the text flipped to near-black:
   a measured contrast ratio of 1.27:1, against the 4.5:1 WCAG AA needs
   for body text. Only the :hover state had been patched, so the session
   list was legible only under the cursor.

   THE FIX
   ───────
   A neutral foreground channel, used as rgba(var(--ink), 0.06) instead
   of rgba(255,255,255,0.06). One token covers every alpha, rather than
   one token per alpha step — the 28 distinct white alphas in the list
   pages alone would otherwise need 28 tokens.

   Values are bare comma-separated RGB triples, not colours, because
   rgba() needs the components rather than a colour to apply an alpha to.

   IDENTITY IN DARK MODE IS THE POINT. Each :root value below is exactly
   the hardcoded value it replaces, so substituting rgba(255,255,255,0.06)
   with rgba(var(--ink), 0.06) produces a byte-identical computed colour
   in the dark theme. That makes converting a file a mechanical,
   zero-risk change to the default theme, and changes only light mode.
   ─────────────────────────────────────────────────────────── */
:root {
  /* Neutral foreground: text, hairlines, hover washes. */
  --ink:   255, 255, 255;

  /* Flat surfaces. Several pages sit on pure black rather than on the
     --clr-surface elevation ramp, so they need their own pair. Kept
     distinct from --clr-surface (#0d1117) rather than folded into it,
     because merging them would change the dark theme. */
  --surface-flat:        #000000;   /* card / panel base           */
  --surface-flat-raised: #0a0a0a;   /* hover, one step up          */
  --surface-field:       #111111;   /* inputs, selects, segmented  */
  --surface-field-hover: #1a1a1a;   /* field hover / pressed       */
  /* Two grounds that sit with the map. They were tinted cool (#0c1114,
     #0b0d0f) under the old design and are neutral now; kept as their
     own tokens so map chrome can be tuned without moving the greys. */
  --surface-menu:        #0d0d0d;   /* dropdown menu over the map  */
  --surface-map:         #0b0b0b;   /* leaflet canvas ground       */

  /* ── Map overlay channel ──────────────────────────────────
     Chrome that floats OVER a map (legends, tooltips, the zoom bar, the
     draw toolbar, attribution) must key off the BASEMAP's brightness,
     never the page theme. They are two different questions and
     conflating them is a real bug rather than a nicety:

     Fire Monitoring and Forest Monitoring are satellite-only (Esri World
     Imagery, no basemap toggle at all). Site Analysis defaults to
     satellite. Ops Console, Species Intel, Report Detail, Submit Report
     and the sandbox all pin CARTO dark_all. So every one of these maps
     is dark whatever the page theme is, and a legend that inverted with
     the page would put a white panel on a dark satellite photo.

     Driven by `body.map-light`, which basemapToggle sets when the
     effective basemap is a light schematic. Page theme influences that
     only by choosing the default schematic; picking satellite keeps the
     chrome dark in light mode, which is correct.

     These default to the same values the overlays were hardcoded with,
     so the dark case is unchanged. */
  --map-ink:   255, 255, 255;   /* label / hairline on map chrome  */
  --map-panel:   8, 12, 14;     /* the tinted panel itself         */
  --map-panel-plain: 0, 0, 0;   /* overlays that used flat black   */
  --map-panel-green: 11, 15, 12;/* testSite's green-tinted variant */
  /* The accent on map chrome (a lit map button). Like the map ink above it
     follows the map. The brand accent follows the page theme instead, and
     went dark green on the dark glass over satellite in light mode. Same
     two values as the brand accent in the two themes; keep the pair in sync. */
  --map-accent:     #c3ff00;
  --map-accent-rgb: 195, 255, 0;

  /* Chrome that is deliberately LIGHT inside a dark app: the Site Analysis
     frame, its buttons and its bottom analysis panel were all #fff. They are
     not a foreground colour and not map chrome, so neither --ink nor
     --map-ink describes them; both would turn them black in light mode,
     which is the opposite of the intent. Theme-invariant on purpose. */
  --paper-fixed: #ffffff;

  /* Accent lime, as used by the hardcoded rules.
     NOTE: this is #c3ff00, which is NOT --clr-brand (#b8f000). Two
     different limes coexist in this codebase — 73 hardcoded #c3ff00
     against 107 var(--clr-brand) references. They are deliberately kept
     apart here rather than unified, because unifying them would shift
     the dark theme's accent on every page that hardcodes it. Worth
     reconciling as its own change, with its own before/after review. */
  --brand-ink: #c3ff00;
  --brand-rgb: 195, 255, 0;

  /* Triple forms of the two palette colours above, for the call sites that
     need an alpha. rgb(184,240,0) IS --clr-brand and rgb(224,60,60) IS
     --clr-danger; they appear as raw rgba() in layout.css only because
     rgba() cannot take a hex. Values mirror --clr-brand / --clr-danger in
     both themes, so these stay in step with the palette rather than
     becoming a second source of truth. */
  --clr-brand-rgb:  184, 240, 0;
  --clr-danger-rgb: 224, 60, 60;

  /* Alert red, as used by the hardcoded rules (#ff5050). */
  --danger-ink: #ff5050;
  --danger-rgb: 255, 80, 80;
}

/* ── Light Mode ─────────────────────────────────────────────
   Applied via .light class on <body>.
   Brand lime is kept; surfaces flip to cool whites/grays.
   ─────────────────────────────────────────────────────────── */
body.light {
  /* Inverting --ink is what makes every rgba(var(--ink), α) rule in the
     converted files correct at once. It is the single highest-leverage
     declaration in this file. */
  --ink:   0, 0, 0;

  /* White page, white cards edged by their 1px border: the light
     mirror of black-on-black. Raised and field greys are neutral (they
     were cool blue-tinted). */
  --surface-flat:        #ffffff;
  --surface-flat-raised: #f5f5f5;
  --surface-field:       #efefef;
  --surface-field-hover: #e5e5e5;
  --surface-menu:        #ffffff;
  /* The map ground stays a shade darker than a card so tiles and vector
     overlays keep an edge against it, mirroring how --surface-map sits
     just off the page black in the dark theme. */
  --surface-map:         #e8e8e8;

  /* NOTE: the --map-* channel is deliberately NOT overridden here. Map
     chrome follows the basemap, not the page, so it is switched by
     body.map-light below rather than by body.light. Overriding it here
     would reintroduce exactly the bug this channel exists to fix. */

  /* #c3ff00 on white is roughly 1.1:1 — invisible. Darkened to clear
     WCAG AA as body text, which is how it is almost always used here
     (11 of the 12 call sites are `color` or `border-color`; the twelfth
     is a 6px status dot, a non-text component needing only 3:1).

     #477200 measures 5.71:1 on the white card and 5.10:1 on the #f0f2f5
     page. The obvious pick was --clr-brand-dim (#4e7e00), but that lands
     at 4.35:1 on the page background — under the 4.5:1 bar, and failing
     by a margin too small to notice by eye, which is exactly how an
     accessibility regression survives review. White on #477200 is also
     5.71:1, so it holds up as a filled chip if anyone uses it that way.

     KEEP --brand-ink AND --brand-rgb IN SYNC. They are the same colour
     in two notations because rgba() cannot take a hex, and nothing
     enforces their agreement. Same for the danger pair below. */
  --brand-ink: #477200;
  --brand-rgb: 71, 114, 0;

  /* Matching --clr-brand (#6aa800) and --clr-danger (#c0392b) above. */
  --clr-brand-rgb:  106, 168, 0;
  --clr-danger-rgb: 192, 57, 43;

  /* #c0392b: 5.05:1 on the white card, 4.51:1 on the page. */
  --danger-ink: #c0392b;
  --danger-rgb: 192, 57, 43;

  --clr-bg:        #ffffff;
  --clr-surface:   #ffffff;
  --clr-surface-2: #efefef;
  --clr-surface-3: #e5e5e5;
  --clr-border:    rgba(0, 0, 0, 0.10);
  --clr-rule:      rgba(0, 0, 0, 0.10);

  --clr-brand:      #6aa800;
  --clr-brand-dim:  #4e7e00;
  --clr-brand-glow: rgba(106, 168, 0, 0.12);

  --clr-accent:   #0099b0;
  --clr-warning:  #b36a00;
  --clr-danger:   #c0392b;
  --clr-success:  var(--clr-brand);

  --clr-text:         #141414;
  --clr-text-muted:   #4d4d4d;
  --clr-text-dim:     #6e6e6e;
  --clr-text-inverse: #ffffff;

  --shadow-xs:   0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-sm:   0 2px 6px rgba(0, 0, 0, 0.10);
  --shadow-md:   0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg:   0 8px 32px rgba(0, 0, 0, 0.15);
  --shadow-glow: 0 0 20px rgba(106, 168, 0, 0.12);
}

/* ── Light basemap ──────────────────────────────────────────
   Set by components/basemapToggle.js when the effective basemap is a
   light schematic. Deliberately NOT tied to body.light: satellite
   imagery is dark whatever the page theme is, and a page may pin a dark
   schematic, so map chrome has to follow the map.

   With this class absent (satellite, or a dark schematic) the :root
   values apply and the chrome is exactly what it was before the theme
   work, which is why the dark case is unchanged.
   ─────────────────────────────────────────────────────────── */
body.map-light {
  --map-ink:   0, 0, 0;
  --map-accent:     #477200;
  --map-accent-rgb: 71, 114, 0;
  --map-panel: 255, 255, 255;
  --map-panel-plain: 255, 255, 255;
  --map-panel-green: 255, 255, 255;
}
