/* ══════════════════════════════════════════════════════════════════
   Patriot War Map — unified theme tokens (light default / dark toggle)
   One source of truth for every surface: map app, CRM, admin, auth pages.
   Applied via  data-theme="light|dark"  on <html>.
   NOTE: this controls app CHROME only — the Mapbox canvas, its fills, and
   the bottom-right color panel are untouched.
   ══════════════════════════════════════════════════════════════════ */

:root,
:root[data-theme="dark"] {
  /* ── map-app token family ─────────────────────────────── */
  --bg-deep:        #0e1014;
  --bg-surface:     #1a1d24;
  --bg-elevated:    #262b35;
  --bg-hover:       #333a47;
  --border:         #353b47;
  --border-light:   #49515f;
  --text-primary:   #f3f5f9;
  --text-secondary: #aeb6c4;
  --text-muted:     #79828f;
  --glass:          rgba(26, 29, 36, 0.90);
  --glass-strong:   rgba(26, 29, 36, 0.96);
  --shadow-lg:      0 8px 40px rgba(0, 0, 0, 0.6);
  --shadow-panel:   6px 0 30px rgba(0, 0, 0, 0.45);

  /* ── CRM / admin token family ─────────────────────────── */
  --bg:   #0e1013;
  --bg2:  #151920;
  --bg3:  #1c222b;
  --line: #2a323d;
  --tx:   #e7ebf0;
  --mut:  #93a0b0;

  /* ── shared accent + status (identical in both themes) ── */
  --accent:       #C8102E;
  --accent-dim:   rgba(200, 16, 46, 0.16);
  --accent-glow:  rgba(200, 16, 46, 0.38);
  --accent-light: #e8304e;
  --red:  #C8102E;
  --redd: #9e0c24;
  --blue: #2563eb;
  --ok:   #16a34a;
  --warn: #facc15;
  --green:      #2dba72;
  --green-dim:  rgba(45, 186, 114, 0.15);
  --yellow:     #f0a840;
  --yellow-dim: rgba(240, 168, 64, 0.15);

  /* ── legible status pills (theme-aware text) ──────────── */
  --pill-ok-bg:   rgba(45, 186, 114, 0.15);
  --pill-ok-tx:   #4ade80;
  --pill-warn-bg: rgba(240, 168, 64, 0.15);
  --pill-warn-tx: #facc15;

  /* ── record-page scales (crm-record.css; theme-independent) ── */
  --s1: 4px;  --s2: 8px;  --s3: 12px;
  --s4: 16px; --s5: 24px; --s6: 32px;
  --r1: 6px;  --r2: 8px;  --r3: 12px; --r4: 16px;

  /* ── ink tiers: hierarchy by opacity, per theme ─────────── */
  --ink-1: rgba(243, 245, 249, 0.95);   /* values / primary   */
  --ink-2: rgba(174, 182, 196, 0.80);   /* secondary          */
  --ink-3: rgba(121, 130, 143, 0.85);   /* labels / muted     */
  --veil:  rgba(255, 255, 255, 0.05);   /* hover tint         */
  --skel:  rgba(255, 255, 255, 0.07);   /* skeleton shimmer   */
}

:root[data-theme="light"] {
  /* Cool near-white surfaces, hairline borders, high-contrast ink.
     Sleek/technical, not flat-white — subtle blue-grey tint reads premium. */
  --bg-deep:        #e9edf3;
  --bg-surface:     #ffffff;
  --bg-elevated:    #f5f7fb;
  --bg-hover:       #e7ecf4;
  --border:         #aebaca;
  --border-light:   #97a3b6;
  --text-primary:   #0f141c;
  --text-secondary: #47515f;
  --text-muted:     #79828f;
  --glass:          rgba(255, 255, 255, 0.80);
  --glass-strong:   rgba(255, 255, 255, 0.94);
  --shadow-lg:      0 10px 34px rgba(15, 23, 42, 0.13);
  --shadow-panel:   6px 0 30px rgba(15, 23, 42, 0.10);

  --bg:   #e9edf3;
  --bg2:  #ffffff;
  --bg3:  #f4f6fa;
  --line: #c0c8d5;
  --tx:   #0f141c;
  --mut:  #5d6875;

  /* status pills tuned for legibility on light surfaces */
  --pill-ok-bg:   rgba(22, 163, 74, 0.13);
  --pill-ok-tx:   #15803d;
  --pill-warn-bg: rgba(217, 119, 6, 0.14);
  --pill-warn-tx: #b45309;

  /* ── ink tiers on light surfaces ────────────────────────── */
  --ink-1: rgba(15, 20, 28, 0.92);
  --ink-2: rgba(0, 0, 0, 0.62);
  --ink-3: rgba(0, 0, 0, 0.45);
  --veil:  rgba(0, 0, 0, 0.04);
  --skel:  rgba(15, 23, 42, 0.08);
}

/* Smooth cross-fade when switching themes (chrome only) */
body { transition: background-color var(--o-med, 200ms) var(--o-ease, ease), color var(--o-med, 200ms) var(--o-ease, ease); }

/* ── Theme toggle control (shared across all surfaces) ──── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg, 10px);
  background: var(--glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--o-med, 200ms) var(--o-ease, ease), border-color var(--o-med, 200ms) var(--o-ease, ease), background var(--o-med, 200ms) var(--o-ease, ease);
  flex: none;
}
.theme-toggle:hover { color: var(--accent-text, var(--accent)); border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; display: block; }

/* ══════════════════════════════════════════════════════════════════
   UI_THEME_V2 — off unless <html class="ui-theme-v2">.
   The class is absent by default, so the tokens above are what ships.
   Inter 400/600 is a separate family name so these files are not used
   while the flag is off (pages already ask for Inter from Google).
   font-display: optional — if the file is not cached yet, the page
   keeps the fallback and does not swap mid-paint.
   ══════════════════════════════════════════════════════════════════ */
@font-face {
  font-family: "War Map Inter";
  font-style: normal;
  font-weight: 400;
  font-display: optional;
  src: url("/src/fonts/roboto-400.woff2") format("woff2"); /* OPDEG 2: Roboto */
}
@font-face {
  font-family: "War Map Inter";
  font-style: normal;
  font-weight: 600;
  font-display: optional;
  src: url("/src/fonts/roboto-500.woff2") format("woff2"); /* OPDEG 2: Roboto */
}

html.ui-theme-v2 {
  --font-body: "War Map Inter", Inter, system-ui, sans-serif;
  --ms-font: "War Map Inter";
  --s1: 4px;
  --s2: 8px;
  --r3: 12px;
  --d-r: 12px;
  --radius-lg: 12px;
}
html.ui-theme-v2 body,
html.ui-theme-v2 #pwm-rail,
html.ui-theme-v2 #pwm-fly,
html.ui-theme-v2 #sg {
  font-family: "War Map Inter", Inter, system-ui, sans-serif;
}

/* Light. Campaign red is the only accent. Status green/amber stay,
   because they mean something other than the brand. */
html.ui-theme-v2:not([data-theme="dark"]) {
  color-scheme: light;
  --bg-deep: #f5f6f8;
  --bg-surface: #ffffff;
  --bg-elevated: #f6f7f9;
  --bg-hover: #f6f7f9;
  --border: #e6e8ec;
  --border-light: #f0f1f4;
  --text-primary: #1c1f26;
  --text-secondary: #5c6570;
  --text-muted: #656c75;
  --glass: rgba(255, 255, 255, 0.92);
  --glass-strong: rgba(255, 255, 255, 0.97);
  --shadow-lg: 0 1px 2px rgba(22, 27, 34, 0.04), 0 8px 24px rgba(22, 27, 34, 0.04);
  --shadow-panel: 0 1px 2px rgba(22, 27, 34, 0.04), 0 8px 24px rgba(22, 27, 34, 0.06);

  --bg: #f5f6f8;
  --bg2: #ffffff;
  --bg3: #f6f7f9;
  --line: #e6e8ec;
  --tx: #1c1f26;
  --mut: #5c6570;

  --accent: #c8102e;
  --accent-dim: #fdecee;
  --accent-glow: rgba(200, 16, 46, 0.22);
  --accent-light: #a30d26;
  --red: #c8102e;
  --redd: #a30d26;
  --blue: #c8102e;
  --ok: #157a45;
  --green: #157a45;
  --green-dim: #e7f6ee;

  --pill-ok-bg: #e7f6ee;
  --pill-ok-tx: #157a45;
  --pill-warn-bg: #fbf3e4;
  --pill-warn-tx: #8a5a12;

  --ink-1: #1c1f26;
  --ink-2: #5c6570;
  --ink-3: #656c75;
  --veil: rgba(22, 27, 34, 0.04);
  --skel: #eceef2;

  --d-bg: #f5f6f8;
  --d-bg-soft: #ffffff;
  --d-card: #ffffff;
  --d-card-2: #f6f7f9;
  --d-line: #e6e8ec;
  --d-line-2: #f0f1f4;
  --d-tx: #1c1f26;
  --d-tx-2: #5c6570;
  --d-tx-3: #656c75;
  --d-accent: #c8102e;
  --d-accent-2: #a30d26;
  --d-accent-dim: #fdecee;
  --d-on-accent: #ffffff;
  --d-r: 12px;
  --d-c1: #c8102e;
  --d-bar: rgba(200, 16, 46, 0.18);
  --d-card-bd: 1px solid #e6e8ec;
  --d-card-sh: 0 1px 2px rgba(22, 27, 34, 0.04), 0 8px 24px rgba(22, 27, 34, 0.04);
  --d-menu-sh: 0 12px 40px rgba(22, 27, 34, 0.12);

  --sg-bg: #ffffff;
  --sg-list: #f6f7f9;
  --sg-pane: #ffffff;
  --sg-line: #e6e8ec;
  --sg-tx: #1c1f26;
  --sg-tx-2: #5c6570;
  --sg-hover: #f6f7f9;
  --sg-active: #f0f1f4;
  --sg-in: #f6f7f9;
  --sg-in-tx: #1c1f26;
  --sg-out: #c8102e;
  --sg-out-tx: #ffffff;
  --sg-input: #f5f6f8;
  --sg-badge: #c8102e;

  --ms-bg: #ffffff;
  --ms-bg-2: #f6f7f9;
  --ms-line: #e6e8ec;
  --ms-line-2: #f0f1f4;
  --ms-tx: #1c1f26;
  --ms-tx-2: #5c6570;
  --ms-red: #c8102e;
}

html.ui-theme-v2[data-theme="dark"] {
  color-scheme: dark;
  --bg-deep: #121417;
  --bg-surface: #1a1d22;
  --bg-elevated: #22262d;
  --bg-hover: #22262d;
  --border: #2c313a;
  --border-light: #343a44;
  --text-primary: #f3f4f6;
  --text-secondary: #b7bec7;
  --text-muted: #9aa3ad;
  --glass: rgba(26, 29, 34, 0.94);
  --glass-strong: rgba(26, 29, 34, 0.98);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.30), 0 8px 24px rgba(0, 0, 0, 0.25);
  --shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.30), 0 8px 24px rgba(0, 0, 0, 0.28);

  --bg: #121417;
  --bg2: #1a1d22;
  --bg3: #22262d;
  --line: #2c313a;
  --tx: #f3f4f6;
  --mut: #b7bec7;

  --accent: #c8102e;
  /* Text and icons only. #C8102E stays the fill behind white labels.
     #ff5c72 is about 5.1:1 on the darkest elevated surface. */
  --accent-text: #ff5c72;
  --accent-dim: rgba(200, 16, 46, 0.18);
  --accent-glow: rgba(200, 16, 46, 0.32);
  --accent-light: #e11d3a;
  --red: #c8102e;
  --redd: #a30d26;
  --blue: #c8102e;
  --ok: #8ed4ae;
  --green: #157a45;
  --green-dim: rgba(21, 122, 69, 0.22);

  --pill-ok-bg: rgba(21, 122, 69, 0.22);
  --pill-ok-tx: #8ed4ae;
  --pill-warn-bg: rgba(138, 90, 18, 0.24);
  --pill-warn-tx: #e6c48a;

  --ink-1: #f3f4f6;
  --ink-2: #b7bec7;
  --ink-3: #9aa3ad;
  --veil: rgba(255, 255, 255, 0.05);
  --skel: #2a2f37;

  --d-bg: #121417;
  --d-bg-soft: #1a1d22;
  --d-card: #1a1d22;
  --d-card-2: #22262d;
  --d-line: #2c313a;
  --d-line-2: #343a44;
  --d-tx: #f3f4f6;
  --d-tx-2: #b7bec7;
  --d-tx-3: #9aa3ad;
  --d-accent: #c8102e;
  --d-accent-2: #a30d26;
  --d-accent-dim: rgba(200, 16, 46, 0.18);
  --d-on-accent: #ffffff;
  --d-r: 12px;
  --d-c1: #c8102e;
  --d-bar: rgba(200, 16, 46, 0.28);
  --d-grid: rgba(255, 255, 255, 0.06);
  --d-card-bd: 1px solid #2c313a;
  --d-card-sh: 0 1px 2px rgba(0, 0, 0, 0.30), 0 8px 24px rgba(0, 0, 0, 0.25);
  --d-menu-sh: 0 12px 40px rgba(0, 0, 0, 0.45);

  --sg-bg: #121417;
  --sg-list: #1a1d22;
  --sg-pane: #121417;
  --sg-line: #2c313a;
  --sg-tx: #f3f4f6;
  --sg-tx-2: #b7bec7;
  --sg-hover: #22262d;
  --sg-active: #2c313a;
  --sg-in: #22262d;
  --sg-in-tx: #f3f4f6;
  --sg-out: #c8102e;
  --sg-out-tx: #ffffff;
  --sg-input: #22262d;
  --sg-badge: #c8102e;

  --ms-bg: #1a1d22;
  --ms-bg-2: #22262d;
  --ms-line: #2c313a;
  --ms-line-2: #343a44;
  --ms-tx: #f3f4f6;
  --ms-tx-2: #b7bec7;
  --ms-red: #c8102e;
}

html.ui-theme-v2 #pwm-rail {
  --rail-bg: #ffffff;
  --rail-line: #e6e8ec;
  --rail-mut: #5c6570;
  --rail-tx: #1c1f26;
  --rail-hover: #f6f7f9;
  --rail-blue: #c8102e;
}
html.ui-theme-v2[data-theme="dark"] #pwm-rail {
  --rail-bg: #1a1d22;
  --rail-line: #2c313a;
  --rail-mut: #b7bec7;
  --rail-tx: #f3f4f6;
  --rail-hover: #22262d;
  --rail-blue: #ff5c72;
}
html.ui-theme-v2[data-theme="dark"] #pwm-rail .rail-item[aria-current="page"] {
  color: var(--accent-text);
}
html.ui-theme-v2 #pwm-fly {
  --rail-bg: #ffffff;
  --rail-line: #e6e8ec;
  --rail-mut: #5c6570;
  --rail-tx: #1c1f26;
  --rail-hover: #f6f7f9;
}
html.ui-theme-v2[data-theme="dark"] #pwm-fly {
  --rail-bg: #1a1d22;
  --rail-line: #2c313a;
  --rail-mut: #b7bec7;
  --rail-tx: #f3f4f6;
  --rail-hover: #22262d;
}

/* Cards that hardcode 16px. Radius only — padding and grid stay put. */
html.ui-theme-v2 .cc-card,
html.ui-theme-v2 .card,
html.ui-theme-v2 .lt-table-wrap,
html.ui-theme-v2 .lt-card,
html.ui-theme-v2 .lt-empty,
html.ui-theme-v2 .lt-detail-body,
html.ui-theme-v2 .ms-panel {
  border-radius: 12px;
}
html.ui-theme-v2[data-theme="dark"] .cc-card,
html.ui-theme-v2[data-theme="dark"] .lt-table-wrap,
html.ui-theme-v2[data-theme="dark"] .lt-card {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.30), 0 8px 24px rgba(0, 0, 0, 0.25);
}
html.ui-theme-v2 .ms-panel {
  box-shadow: 0 1px 2px rgba(22, 27, 34, 0.04), 0 8px 24px rgba(22, 27, 34, 0.08);
}
html.ui-theme-v2[data-theme="dark"] .ms-panel {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.30), 0 8px 24px rgba(0, 0, 0, 0.25);
}
html.ui-theme-v2 .ms-panel .ms-f input::placeholder { color: #656c75; }
html.ui-theme-v2[data-theme="dark"] .ms-panel .ms-f input::placeholder { color: #9aa3ad; }

/* Command Center headings. Flag off keeps Barlow Condensed and the uppercase title. */
html.ui-theme-v2 .cc-title,
html.ui-theme-v2 .cc-h h2,
html.ui-theme-v2 .cc-drawer-h h3,
html.ui-theme-v2 #cc-soon-title {
  font-family: "War Map Inter", Inter, system-ui, sans-serif;
  font-weight: 600;
  text-transform: none;
}
html.ui-theme-v2 .cc-title {
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: -0.03em;
}
html.ui-theme-v2 .cc-h h2,
html.ui-theme-v2 .cc-drawer-h h3,
html.ui-theme-v2 #cc-soon-title {
  letter-spacing: -0.02em;
}
html.ui-theme-v2 .cc-top > div:first-child { min-width: 0; }
html.ui-theme-v2 .cc-title,
html.ui-theme-v2 .cc-h h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== OPDEG 2: one primary colour (docs/opdeg2/OPDEG-2.md 2.1) =====
   --accent and --red are the accent every screen shares, so they become
   Outrider blue here. Red for errors and destructive actions comes from
   --o-bad / --o-bad-fill (src/opdeg2.css). The :not(#o2) only raises
   specificity past the UI_THEME_V2 blocks above.
   Dark uses #3E6CC4 rather than the OPDEG 2 dark primary (#9DB8E8): the
   legacy screens put white text on --accent, and white on #9DB8E8 is
   unreadable. Each screen switches to --o-primary when it moves to OPDEG 2. */
html:not(#o2) {
  --accent: #082C5F;
  --accent-dim: rgba(8, 44, 95, 0.12);
  --accent-text: #082C5F;
  --accent-light: rgba(8, 44, 95, 0.12);
  --red: #082C5F;
}
html[data-theme="dark"]:not(#o2) {
  --accent: #3E6CC4;
  --accent-dim: rgba(62, 108, 196, 0.22);
  --accent-text: #9DB8E8;
  --accent-light: rgba(62, 108, 196, 0.22);
  --red: #3E6CC4;
}
