/* ════════════════════════════════════════════════════════════════
   EZBUILD UNIFIED THEME OVERLAY
   ────────────────────────────────────────────────────────────────
   Drop this AFTER all other stylesheets to align landing, auth,
   and the app on one token system. Supports light + dark via
   <html data-theme="light"> / <html data-theme="dark">.

   Goal: zero layout changes — only color / font / radii / focus
   styles are normalised through CSS variables.

   ════════════════════════════════════════════════════════════════ */


/* ════════════════════ 1. TOKEN ROOT (DARK DEFAULT) ════════════════════ */

:root,
:root[data-theme="dark"],
html.dark {
  /* Brand — invariant */
  --brand:           #1978E5;
  --brand-hover:     #1568CC;
  --brand-press:     #1259B0;
  --brand-on:        #FFFFFF;
  --blueprint:       #60B0FF;

  /* Status — invariant */
  --pass:            #10B981;
  --review:          #F59E0B;
  --fail:            #F43F5E;

  /* Surfaces — dark */
  --bg:              #0B111B;
  --bg-elevated:     #11192A;
  --surface:         #161C26;
  --surface-2:       #1B2433;
  --surface-3:       #232E3F;
  --sidebar-bg:      #080D14;

  --border:          #2A3441;
  --border-strong:   #3A4757;
  --hairline:        rgba(255,255,255,0.06);

  --text:            #F1F5F9;
  --text-2:          #94A3B8;
  --text-3:          #7C8CA3;   /* was #64748B (4.0:1 on --bg) — lifted to ~5.5:1 so muted text stays legible */
  --text-inv:        #0B111B;

  --brand-soft:      rgba(25,120,229,0.14);
  --brand-on-soft:   #60B0FF;

  --pass-soft:       rgba(16,185,129,0.12);
  --pass-on-soft:    #34D399;
  --review-soft:     rgba(245,158,11,0.12);
  --review-on-soft:  #FBBF24;
  --fail-soft:       rgba(244,63,94,0.12);
  --fail-on-soft:    #FB7185;

  --grid-line:       rgba(96,176,255,0.05);
  --blueprint-line:  rgba(96,176,255,0.40);

  --shadow-sm:       0 1px 2px rgba(0,0,0,0.30);
  --shadow:          0 2px 6px rgba(0,0,0,0.32), 0 1px 2px rgba(0,0,0,0.24);
  --shadow-lg:       0 20px 40px -12px rgba(0,0,0,0.55);
  --focus-ring:      0 0 0 3px rgba(25,120,229,0.30);

  /* Type */
  --font-sans:       'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:       'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  /* Radius */
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px; --r-2xl: 20px;

  /* Motion */
  --ease: cubic-bezier(.2,.7,.2,1);
  --dur:  200ms;

  /* ─── LEGACY ALIASES — theme.css uses these names ─── */
  --theme-primary:        var(--brand);
  --theme-bg:             var(--bg);
  --theme-panel:          var(--surface);
  --theme-panel-muted:    var(--surface-2);
  --theme-panel-subtle:   var(--surface-3);
  --theme-border:         var(--border);
  --theme-text:           var(--text);
  --theme-text-secondary: var(--text-2);
  --theme-text-muted:     var(--text-3);
  --theme-font:           var(--font-sans);
}

/* ════════════════════ 2. LIGHT MODE ════════════════════ */

:root[data-theme="light"],
html[data-theme="light"] {
  /* Surfaces — light */
  --bg:              #F7F9FB;
  --bg-elevated:     #FFFFFF;
  --surface:         #FFFFFF;
  --surface-2:       #F1F4F9;
  --surface-3:       #E8ECF2;
  --sidebar-bg:      #F1F4F9;

  --border:          #E2E8F0;
  --border-strong:   #CBD5E1;
  --hairline:        rgba(15,23,42,0.06);

  --text:            #0F172A;
  --text-2:          #475569;
  --text-3:          #64748B;   /* was #94A3B8 (2.5:1 on white) — darkened to ~4.8:1 for placeholders/labels */
  --text-inv:        #FFFFFF;

  --brand-soft:      rgba(25,120,229,0.08);
  --brand-on-soft:   #1259B0;

  --pass-soft:       #ECFDF5;
  --pass-on-soft:    #047857;
  --review-soft:     #FFFBEB;
  --review-on-soft:  #B45309;
  --fail-soft:       #FEF2F2;
  --fail-on-soft:    #BE123C;

  --grid-line:       rgba(25,120,229,0.06);
  --blueprint-line:  rgba(25,120,229,0.35);

  --shadow-sm:       0 1px 2px rgba(15,23,42,0.04);
  --shadow:          0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-lg:       0 12px 24px -8px rgba(15,23,42,0.10), 0 4px 8px -2px rgba(15,23,42,0.06);

  color-scheme: light;
}

html[data-theme="light"] {
  background: var(--bg);
  color: var(--text);
}


/* ════════════════════ 3. GLOBAL BASE ════════════════════ */

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

html, body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans) !important;
  transition: background-color var(--dur) var(--ease),
              color var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.011em;
}

/* Material Symbols — refine weight across all pages */
.material-symbols-outlined {
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24 !important;
}
.material-symbols-outlined[data-fill="1"],
.sidebar-active .material-symbols-outlined,
.tab-active .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24 !important;
}

::selection { background: var(--brand); color: white; }

/* ════════════════════ 4. LANDING PAGE OVERRIDES (index.html) ════════════════════ */

/* Background colors */
.bg-\[\#09090b\] { background-color: var(--bg) !important; }
.bg-\[\#18181b\] { background-color: var(--surface) !important; }

/* Text colors */
.text-\[\#F9FAFB\] { color: var(--text) !important; }
.text-\[\#A1A1AA\] { color: var(--text-2) !important; }
.text-\[\#92adc9\] { color: var(--text-2) !important; }
.text-\[\#8b949e\] { color: var(--text-3) !important; }
.text-\[\#6b8cae\] { color: var(--text-3) !important; }

/* Borders */
.border-\[\#30363d\] { border-color: var(--border) !important; }

/* Hero gradient — desaturate in light mode */
html[data-theme="light"] .hero-gradient {
  background: radial-gradient(ellipse at 50% 0%, rgba(25,120,229,0.10) 0%, var(--bg) 65%) !important;
}
:root[data-theme="dark"] .hero-gradient,
html.dark .hero-gradient {
  background: radial-gradient(ellipse at 50% 0%, rgba(25,120,229,0.18) 0%, var(--bg) 65%) !important;
}

/* glass-panel: re-tint per mode */
.glass-panel {
  background: color-mix(in srgb, var(--surface) 60%, transparent) !important;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--hairline) !important;
}

/* Card hover */
.card-hover { border: 1px solid var(--hairline) !important; }
.card-hover:hover {
  border-color: color-mix(in srgb, var(--brand) 35%, transparent) !important;
  box-shadow: 0 0 30px -8px rgba(25,120,229,0.20) !important;
}

/* Nav scrolled state */
.nav-scrolled {
  background: color-mix(in srgb, var(--bg) 95%, transparent) !important;
  border-bottom: 1px solid var(--hairline) !important;
}

/* Gradient text — darker stops in light mode so it stays readable on light bg.
   Use background-image (NOT background shorthand) so background-clip is preserved. */
.grad-text {
  background-color: transparent !important;
  background-image: linear-gradient(135deg, var(--brand) 0%, var(--blueprint) 100%) !important;
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  color: transparent !important;
}
html[data-theme="light"] .grad-text {
  background-image: linear-gradient(135deg, var(--brand-press) 0%, var(--brand) 100%) !important;
}

/* EZbuild "build" logo span (rendered by sidebar-render.js / new-audit.html with inline
   gradient style #1978e5→#60b0ff). In light mode the lighter half is invisible
   on light surfaces — re-tint to a darker gradient via attribute selector + !important. */
html[data-theme="light"] span[style*="linear-gradient(135deg,#1978e5"],
html[data-theme="light"] span[style*="linear-gradient(135deg, #1978e5"] {
  background-image: linear-gradient(135deg, var(--brand-press) 0%, var(--brand) 100%) !important;
}

/* Counters / stats / dividers */
.divide-white\/\[0\.06\] > * + *,
.divide-white\/\[0\.05\] > * + * { border-color: var(--hairline) !important; }

.border-white\/\[0\.06\],
.border-white\/\[0\.05\],
.border-white\/10 { border-color: var(--hairline) !important; }

.bg-white\/\[0\.03\],
.bg-white\/\[0\.05\] { background-color: var(--surface-2) !important; }


/* ════════════════════ 5. LOGIN / AUTH OVERRIDES ════════════════════ */
/* (login.html, signup.html, reset-password.html use a custom palette) */

/* Auth form panel — hardcoded #0b1018 must follow the theme bg in both modes */
.bg-\[\#0b1018\] { background-color: var(--bg) !important; }
.focus\:ring-offset-\[\#0b1018\]:focus { --tw-ring-offset-color: var(--bg) !important; }

/* Tailwind runtime classes from login.html config */
.bg-surface,
.bg-surface-low,
.bg-surface-dim     { background-color: var(--surface) !important; }
.bg-surface-high    { background-color: var(--surface-2) !important; }
.bg-surface-highest { background-color: var(--surface-3) !important; }
.text-on-surface    { color: var(--text) !important; }
.text-secondary     { color: var(--text-2) !important; }
.text-outline       { color: var(--text-3) !important; }
.text-outline-variant { color: var(--text-3) !important; }
.border-outline     { border-color: var(--border) !important; }
.border-outline-variant { border-color: var(--border) !important; }

/* Login primary — the inconsistent #4090fe → unify to brand */
.bg-primary-btn { background-color: var(--brand) !important; color: var(--brand-on) !important; }
.bg-primary-btn:hover { background-color: var(--brand-hover) !important; }
.text-on-primary { color: var(--brand-on) !important; }

/* Login uses .text-primary (#aac7ff). Replace with consistent brand-on-soft. */
.text-primary { color: var(--brand-on-soft) !important; }

/* Action gradient (login) */
.action-gradient {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-hover) 100%) !important;
}
.blueprint-gradient {
  background: linear-gradient(135deg, var(--bg) 0%, var(--surface) 100%) !important;
}

/* Field-wrap (login's custom input wrapper) */
.field-wrap {
  background: var(--bg-elevated) !important;
  border-color: var(--border) !important;
}
.field-wrap:focus-within {
  border-color: var(--brand) !important;
  box-shadow: var(--focus-ring) !important;
}
/* Higher-specificity selectors so they beat the page's local
   `.field-input { background-color:#0a1018 !important }` regardless of load order. */
.field-wrap input.field-input,
input.field-input {
  background-color: var(--bg-elevated) !important;
  color: var(--text) !important;
  -webkit-text-fill-color: var(--text) !important;
  /* The page delays background-color by 5000s (anti-autofill hack); that also
     freezes the theme switch. Transition the theme color quickly instead. */
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease) !important;
}
.field-wrap input.field-input:-webkit-autofill,
.field-wrap input.field-input:-webkit-autofill:hover,
.field-wrap input.field-input:-webkit-autofill:focus,
.field-wrap input.field-input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-elevated) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
}
.field-wrap input.field-input::placeholder { color: var(--text-3) !important; -webkit-text-fill-color: var(--text-3) !important; }
.field-icon { color: var(--text-3) !important; }
.field-wrap:focus-within .field-icon { color: var(--brand) !important; }
.field-label { color: var(--text-3) !important; }
.field-wrap:focus-within .field-label { color: var(--brand) !important; }


/* ════════════════════ 6. APP TAILWIND ARBITRARY CLASSES ════════════════════ */

/* Backgrounds */
.bg-\[\#0B111B\], .bg-\[\#0b111b\],
.bg-\[\#0d1117\], .bg-\[\#0b0f19\]   { background-color: var(--bg) !important; }
.bg-\[\#161C26\], .bg-\[\#161c26\]   { background-color: var(--surface) !important; }
.bg-\[\#111a22\]                     { background-color: var(--surface) !important; }
.bg-\[\#111827\]                     { background-color: var(--surface) !important; } /* project-detail modals */
.bg-\[\#1c2a38\], .bg-\[\#192633\]   { background-color: var(--surface-2) !important; }
.bg-\[\#152030\]                     { background-color: var(--surface-3) !important; }
.bg-\[\#1f6feb\], .bg-\[\#137fec\]\/90 { background-color: var(--brand) !important; }

/* Borders */
.border-\[\#2A3441\], .border-\[\#324d67\],
.border-\[\#3a5470\] { border-color: var(--border) !important; }
.border-\[\#137fec\]\/50 { border-color: color-mix(in srgb, var(--brand) 50%, transparent) !important; }

/* Background dark/sidebar */
.dark\:bg-background-dark    { background-color: var(--bg) !important; }
.dark\:bg-card-dark,
.dark\:bg-surface-dark,
.dark\:bg-sidebar-dark       { background-color: var(--surface) !important; }
.dark\:border-border-dark    { border-color: var(--border) !important; }
.dark\:text-text-secondary-dark { color: var(--text-2) !important; }

/* App sidebar — exact hex */
#app-sidebar {
  background-color: var(--sidebar-bg) !important;
  border-right: 1px solid var(--border) !important;
}

/* Sidebar active state */
.sidebar-active {
  color: var(--brand-on-soft) !important;
  border-right-color: var(--brand-on-soft) !important;
  background-color: var(--brand-soft) !important;
}
html[data-theme="light"] .sidebar-active {
  color: var(--brand) !important;
  border-right-color: var(--brand) !important;
}

/* New Audit button — in light mode the solid brand blue reads as a heavy dark
   slab against the pale sidebar. Lighten it with a subtle top-light gradient and
   trade the strong blue glow for a soft, integrated shadow. Dark mode keeps the
   original solid fill (it sits well on the near-black sidebar). */
html[data-theme="light"] #app-sidebar a.bg-primary {
  background-color: #2A8AEC !important;
  background-image: linear-gradient(180deg, #3A93EF 0%, #2480E8 100%) !important;
  box-shadow: 0 2px 8px rgba(25,120,229,0.22),
              0 1px 2px rgba(15,23,42,0.05) !important;
}
html[data-theme="light"] #app-sidebar a.bg-primary:hover {
  background-image: linear-gradient(180deg, #3088EC 0%, #1E78E2 100%) !important;
  box-shadow: 0 3px 12px rgba(25,120,229,0.30),
              0 1px 2px rgba(15,23,42,0.06) !important;
}


/* ════════════════════ 6b. CUSTOM TAILWIND COLORS WITH NO LIGHT VARIANT ════════════════════ */
/* project-detail.html / project-specs.html register an `app` color group in
   js/tailwind-config.js (app.bg, app.panel, app.border, app.textMuted) and
   tracking.html uses the bare `*-dark` custom colors (background-dark, card-dark,
   border-dark, text-secondary-dark). All are hardcoded DARK hex with no light
   pair, so `bg-app-bg` / `bg-card-dark` etc. stay dark in light mode — the page
   sidebar turns light while the main content stays dark. Map them to theme
   tokens so they follow both modes. Tailwind generates these utilities without
   !important, so these win regardless of stylesheet order. */

.bg-app-bg                  { background-color: var(--bg) !important; }
.bg-app-panel               { background-color: var(--surface) !important; }
.bg-app-panel\/50           { background-color: color-mix(in srgb, var(--surface) 60%, transparent) !important; }
.hover\:bg-app-bg\/50:hover { background-color: var(--surface-2) !important; }
.bg-app-border              { background-color: var(--border) !important; }
.border-app-border          { border-color: var(--border) !important; }
.divide-app-border > * + *  { border-color: var(--border) !important; }
.text-app-textMuted         { color: var(--text-2) !important; }

.bg-background-dark         { background-color: var(--bg) !important; }
.bg-card-dark,
.bg-surface-dark            { background-color: var(--surface) !important; }
.border-border-dark         { border-color: var(--border) !important; }
.text-text-secondary-dark   { color: var(--text-2) !important; }


/* ════════════════════ 6c. new-audit.html AUDIT-PROGRESS UI (dark-first) ════════════════════ */
/* The progress card (HTML container + the panels new-audit.js injects) was built
   dark-only with arbitrary-hex utilities. Map the surfaces/borders to tokens so
   the card follows light mode. Its text utilities (text-[#4b6080] / #2a3d52 /
   #94a3b8 and text-slate-*) are already handled by sections 7/8/8b. The blue
   progress gradient is brand-invariant and left as-is. */
.bg-\[\#141b2a\]            { background-color: var(--surface) !important; }   /* progress card */
.bg-\[\#0d1825\]            { background-color: var(--bg) !important; }        /* recessed inner panel */
.bg-\[\#1e2d3d\]            { background-color: var(--surface-2) !important; } /* elevated row */
.border-\[\#1e2d3d\],
.border-\[\#232F42\]        { border-color: var(--border) !important; }


/* ════════════════════ 6d. project-specs.html SPEC-EDITOR (inline-styled, dark-first) ════════════════════ */
/* The spec/stud/interior editor rows live in the page's own <style> block with
   hardcoded dark hex. unified-theme loads after that block, so these !important
   overrides win and make the editor follow both modes. Brand blue (#1978e5 /
   #1565c0) and status colors (#ef4444 / #22c55e) are theme-invariant and left
   untouched — including the white text on the brand .spec-save-btn. */

/* Panel / input surfaces */
.spec-input, .stud-input, .stud-chip, .stud-add-form,
.int-header                 { background-color: var(--surface-2) !important; }
.spec-edit-btn:hover        { background-color: var(--surface-2) !important; }

/* Borders */
.spec-row, .int-header, .int-header-cols, .int-col-hdr,
.int-cols, .int-col, .stud-chip { border-color: var(--border) !important; }
.stud-chip:hover, .stud-add-btn { border-color: var(--border-strong) !important; }
.stud-add-form input        { border-bottom-color: var(--border-strong) !important; }

/* Text — primary values */
.spec-value, .stud-val, .stud-chip-val, .spec-input, .stud-input,
.stud-chip-input, .stud-add-form input { color: var(--text) !important; }
/* Text — labels / secondary */
.spec-label, .stud-sublabel, .int-col-hdr, .stud-chip-label,
.spec-edit-btn, .spec-cancel-btn, .stud-add-btn { color: var(--text-2) !important; }
/* Text — muted / empty / placeholders */
.spec-value.empty, .stud-val.empty, .stud-chip-val.empty,
.stud-chip-remove, .stud-add-form-sep { color: var(--text-3) !important; }
.spec-input::placeholder    { color: var(--text-3) !important; }
/* Text — "active/hover white" → readable on light surfaces */
.tab-active, .spec-edit-btn:hover,
.spec-cancel-btn:hover       { color: var(--text) !important; }

/* Left section-nav + "Others" add-field row (custom .nav-* / .dynamic-* classes,
   project-specs only). The ACTIVE label was a near-white #f1f5f9 — invisible on a
   light background — and the idle labels/icons were a faint #8b96a5. Map to tokens;
   keep brand blue on the active icon. */
.nav-icon, .nav-label, .dynamic-add-trigger,
.nav-section-item.active .nav-count { color: var(--text-2) !important; }
.nav-count, .dynamic-row-remove     { color: var(--text-3) !important; }
.nav-section-item.active .nav-label { color: var(--text) !important; }
.nav-section-item.active .nav-icon  { color: var(--brand) !important; }
.nav-section-item:hover             { background-color: var(--surface-2) !important; }
.dynamic-add-bar                    { border-top-color: var(--border) !important; }


/* ════════════════════ 6e. settings.html — SELECTED ACCENT-SWATCH RING ════════════════════ */
/* The chosen colour swatch is marked with a white border ring (border-color:#fff),
   which is invisible on the light-mode page. Use --text so the ring is a dark
   outline in light mode and stays near-white in dark mode. The checkmark INSIDE
   the swatch sits on the saturated accent fill, so its white is left untouched. */
.accent-swatch.selected     { border-color: var(--text) !important; }


/* ════════════════════ 7. PRIMITIVE SLATE / GRAY MAPPINGS (LIGHT MODE) ════════════════════ */
/* Many app pages use bg-slate-50, text-slate-700 etc. for "default light" surfaces
   that should adapt to dark mode and back. In dark mode these are usually fine,
   but in light mode keep them as designed.

   These rules ONLY fire in dark mode to remap the *light* utility colors. */

html:not([data-theme="light"]) .bg-white            { background-color: var(--surface) !important; color: inherit; }
html:not([data-theme="light"]) .bg-slate-50         { background-color: var(--surface-2) !important; }
html:not([data-theme="light"]) .bg-slate-100        { background-color: var(--surface-2) !important; }
html:not([data-theme="light"]) .bg-gray-50          { background-color: var(--surface-2) !important; }
html:not([data-theme="light"]) .bg-gray-100         { background-color: var(--surface-2) !important; }

html:not([data-theme="light"]) .text-slate-900,
html:not([data-theme="light"]) .text-slate-800,
html:not([data-theme="light"]) .text-gray-900,
html:not([data-theme="light"]) .text-gray-800       { color: var(--text) !important; }
html:not([data-theme="light"]) .text-slate-700,
html:not([data-theme="light"]) .text-slate-600,
html:not([data-theme="light"]) .text-gray-700,
html:not([data-theme="light"]) .text-gray-600       { color: var(--text-2) !important; }
html:not([data-theme="light"]) .text-slate-500,
html:not([data-theme="light"]) .text-slate-400,
html:not([data-theme="light"]) .text-gray-500,
html:not([data-theme="light"]) .text-gray-400       { color: var(--text-3) !important; }

html:not([data-theme="light"]) .border-slate-200,
html:not([data-theme="light"]) .border-slate-300,
html:not([data-theme="light"]) .border-gray-200,
html:not([data-theme="light"]) .border-gray-300     { border-color: var(--border) !important; }

html:not([data-theme="light"]) .divide-slate-100 > * + *,
html:not([data-theme="light"]) .divide-slate-200 > * + *,
html:not([data-theme="light"]) .divide-gray-200 > * + * { border-color: var(--hairline) !important; }

/* Light-design status chips / text (bg-red-50 + text-red-700 etc.) — remap the
   PAIR in dark mode so chips become dark-tinted with light status text instead
   of pastel chips with dark text (or worse, dark status text on dark page bg). */
html:not([data-theme="light"]) .bg-red-50,
html:not([data-theme="light"]) .bg-red-100,
html:not([data-theme="light"]) .bg-rose-50          { background-color: var(--fail-soft) !important; }
html:not([data-theme="light"]) .text-red-500,
html:not([data-theme="light"]) .text-red-600,
html:not([data-theme="light"]) .text-red-700,
html:not([data-theme="light"]) .text-red-800        { color: var(--fail-on-soft) !important; }
html:not([data-theme="light"]) .border-red-100,
html:not([data-theme="light"]) .border-red-200      { border-color: color-mix(in srgb, var(--fail) 30%, transparent) !important; }

html:not([data-theme="light"]) .bg-green-50,
html:not([data-theme="light"]) .bg-green-100,
html:not([data-theme="light"]) .bg-emerald-50,
html:not([data-theme="light"]) .bg-emerald-100      { background-color: var(--pass-soft) !important; }
html:not([data-theme="light"]) .text-green-600,
html:not([data-theme="light"]) .text-green-700,
html:not([data-theme="light"]) .text-emerald-600,
html:not([data-theme="light"]) .text-emerald-700,
html:not([data-theme="light"]) .text-emerald-800    { color: var(--pass-on-soft) !important; }
html:not([data-theme="light"]) .border-green-200,
html:not([data-theme="light"]) .border-emerald-200  { border-color: color-mix(in srgb, var(--pass) 30%, transparent) !important; }

html:not([data-theme="light"]) .bg-amber-50,
html:not([data-theme="light"]) .bg-amber-100,
html:not([data-theme="light"]) .bg-yellow-50,
html:not([data-theme="light"]) .bg-orange-100       { background-color: var(--review-soft) !important; }
html:not([data-theme="light"]) .text-amber-600,
html:not([data-theme="light"]) .text-amber-700,
html:not([data-theme="light"]) .text-amber-800,
html:not([data-theme="light"]) .text-amber-900,
html:not([data-theme="light"]) .text-orange-800     { color: var(--review-on-soft) !important; }
html:not([data-theme="light"]) .border-amber-200,
html:not([data-theme="light"]) .border-orange-200   { border-color: color-mix(in srgb, var(--review) 30%, transparent) !important; }

html:not([data-theme="light"]) .bg-blue-50,
html:not([data-theme="light"]) .bg-indigo-50        { background-color: var(--brand-soft) !important; }
html:not([data-theme="light"]) .text-blue-600,
html:not([data-theme="light"]) .text-blue-700,
html:not([data-theme="light"]) .text-indigo-600     { color: var(--brand-on-soft) !important; }
html:not([data-theme="light"]) .border-blue-200,
html:not([data-theme="light"]) .border-indigo-200   { border-color: color-mix(in srgb, var(--brand) 30%, transparent) !important; }


/* ════════════════════ 8. LIGHT MODE — INVERT DARK UTILITIES ════════════════════ */

html[data-theme="light"] .dark\:bg-background-dark    { background-color: var(--bg) !important; }
html[data-theme="light"] .dark\:bg-card-dark,
html[data-theme="light"] .dark\:bg-surface-dark,
html[data-theme="light"] .dark\:bg-sidebar-dark       { background-color: var(--surface) !important; }
html[data-theme="light"] .dark\:bg-\[\#111a22\],
html[data-theme="light"] .dark\:bg-\[\#1c2a38\],
html[data-theme="light"] .dark\:bg-\[\#192633\]      { background-color: var(--surface) !important; }
html[data-theme="light"] .dark\:bg-\[\#192633\]\/50,
html[data-theme="light"] .dark\:bg-\[\#192633\]\/40,
html[data-theme="light"] .dark\:bg-\[\#192633\]\/30  { background-color: var(--surface-2) !important; }
html[data-theme="light"] .dark\:bg-\[\#152030\]      { background-color: var(--surface-3) !important; }
html[data-theme="light"] .dark\:border-border-dark   { border-color: var(--border) !important; }
html[data-theme="light"] .dark\:text-text-secondary-dark { color: var(--text-2) !important; }
html[data-theme="light"] .dark\:text-white,
html[data-theme="light"] .dark\:text-slate-100,
html[data-theme="light"] .dark\:text-slate-200      { color: var(--text) !important; }
html[data-theme="light"] .dark\:text-slate-300,
html[data-theme="light"] .dark\:text-slate-400      { color: var(--text-2) !important; }
html[data-theme="light"] .dark\:hover\:bg-slate-800:hover,
html[data-theme="light"] .dark\:hover\:bg-\[\#1c2a38\]:hover { background-color: var(--surface-2) !important; }

html[data-theme="light"] .text-white               { color: var(--text) !important; }
/* …but keep text-white WHITE when it sits on a SOLID saturated colored fill.
   IMPORTANT: match only the solid button shades (500/600/700) — NOT a wildcard
   like [class*="bg-blue-"], which also catches translucent / dark-tint panels
   (bg-blue-950/40, bg-indigo-950/70, bg-blue-900/30 …). Those tints turn LIGHT
   in light mode, so white text on them is invisible; they must fall through to
   the rule above and get dark --text. Real white-text buttons only ever use the
   solid shades enumerated here (verified across the codebase). */
html[data-theme="light"] .bg-primary.text-white,
html[data-theme="light"] .bg-primary .text-white,
html[data-theme="light"] .bg-\[\#1978e5\].text-white,
html[data-theme="light"] .bg-\[\#1978e5\] .text-white,
html[data-theme="light"] .bg-blue-500.text-white,    html[data-theme="light"] .bg-blue-500 .text-white,
html[data-theme="light"] .bg-blue-600.text-white,    html[data-theme="light"] .bg-blue-600 .text-white,
html[data-theme="light"] .bg-blue-700.text-white,    html[data-theme="light"] .bg-blue-700 .text-white,
html[data-theme="light"] .bg-indigo-600.text-white,  html[data-theme="light"] .bg-indigo-600 .text-white,
html[data-theme="light"] .bg-indigo-700.text-white,  html[data-theme="light"] .bg-indigo-700 .text-white,
html[data-theme="light"] .bg-emerald-500.text-white, html[data-theme="light"] .bg-emerald-500 .text-white,
html[data-theme="light"] .bg-emerald-600.text-white, html[data-theme="light"] .bg-emerald-600 .text-white,
html[data-theme="light"] .bg-green-500.text-white,   html[data-theme="light"] .bg-green-500 .text-white,
html[data-theme="light"] .bg-green-600.text-white,   html[data-theme="light"] .bg-green-600 .text-white,
html[data-theme="light"] .bg-green-700.text-white,   html[data-theme="light"] .bg-green-700 .text-white,
html[data-theme="light"] .bg-red-500.text-white,     html[data-theme="light"] .bg-red-500 .text-white,
html[data-theme="light"] .bg-red-600.text-white,     html[data-theme="light"] .bg-red-600 .text-white,
html[data-theme="light"] .bg-red-700.text-white,     html[data-theme="light"] .bg-red-700 .text-white,
html[data-theme="light"] .bg-amber-500.text-white,   html[data-theme="light"] .bg-amber-500 .text-white,
html[data-theme="light"] .bg-amber-600.text-white,   html[data-theme="light"] .bg-amber-600 .text-white { color: #fff !important; }
html[data-theme="light"] .bg-\[\#09090b\],
html[data-theme="light"] .bg-\[\#0B111B\],
html[data-theme="light"] .bg-\[\#0b111b\]          { background-color: var(--bg) !important; }
html[data-theme="light"] .bg-\[\#18181b\],
html[data-theme="light"] .bg-\[\#161C26\],
html[data-theme="light"] .bg-\[\#161c26\]          { background-color: var(--surface) !important; }
html[data-theme="light"] .text-\[\#F9FAFB\]        { color: var(--text) !important; }
html[data-theme="light"] .text-\[\#A1A1AA\]        { color: var(--text-2) !important; }

/* ── Bare (unprefixed) dark-design utilities → light equivalents ──
   Several app pages were authored dark-first and use bg-slate-800 /
   text-slate-300 etc. WITHOUT a light-mode pair. Remap background + text
   together so panels and their copy stay coherent in light mode. */

/* light gray text → dark text */
html[data-theme="light"] .text-slate-100,
html[data-theme="light"] .text-slate-200,
html[data-theme="light"] .text-gray-100,
html[data-theme="light"] .text-gray-200,
html[data-theme="light"] .text-zinc-200            { color: var(--text) !important; }
html[data-theme="light"] .text-slate-300,
html[data-theme="light"] .text-gray-300            { color: var(--text-2) !important; }
html[data-theme="light"] .text-slate-400,
html[data-theme="light"] .text-gray-400,
html[data-theme="light"] .text-zinc-400            { color: var(--text-3) !important; }

/* dark slate/gray panels → light surfaces */
html[data-theme="light"] .bg-slate-700,
html[data-theme="light"] .bg-gray-700              { background-color: var(--surface-3) !important; }
html[data-theme="light"] .bg-slate-800,
html[data-theme="light"] .bg-gray-800,
html[data-theme="light"] .bg-gray-900,
html[data-theme="light"] .bg-slate-800\/20,
html[data-theme="light"] .bg-slate-800\/30,
html[data-theme="light"] .bg-slate-800\/50,
html[data-theme="light"] .bg-slate-800\/70         { background-color: var(--surface-2) !important; }
html[data-theme="light"] .hover\:bg-slate-700:hover,
html[data-theme="light"] .hover\:bg-slate-800:hover,
html[data-theme="light"] .hover\:bg-gray-600:hover { background-color: var(--surface-3) !important; }
html[data-theme="light"] .border-slate-700,
html[data-theme="light"] .border-slate-800,
html[data-theme="light"] .border-gray-700,
html[data-theme="light"] .border-gray-800          { border-color: var(--border) !important; }

/* pale / mid status text (designed for dark bg) → darker status colors.
   -300/-400 fail badly on white (1.9–2.6:1); -500/-600 amber & green still
   miss 4.5:1 (e.g. amber-500 = 2.15:1, green-600 = 3.3:1). */
html[data-theme="light"] .text-emerald-300,
html[data-theme="light"] .text-emerald-400,
html[data-theme="light"] .text-emerald-500,
html[data-theme="light"] .text-emerald-600,
html[data-theme="light"] .text-green-400,
html[data-theme="light"] .text-green-500,
html[data-theme="light"] .text-green-600           { color: var(--pass-on-soft) !important; }
html[data-theme="light"] .text-amber-300,
html[data-theme="light"] .text-amber-400,
html[data-theme="light"] .text-amber-500,
html[data-theme="light"] .text-amber-600,
html[data-theme="light"] .text-yellow-300,
html[data-theme="light"] .text-yellow-400          { color: var(--review-on-soft) !important; }
html[data-theme="light"] .text-red-400,
html[data-theme="light"] .text-red-500,
html[data-theme="light"] .text-rose-400            { color: var(--fail-on-soft) !important; }
html[data-theme="light"] .text-blue-300,
html[data-theme="light"] .text-blue-400,
html[data-theme="light"] .text-blue-500,
html[data-theme="light"] .text-sky-400             { color: var(--brand) !important; }
html[data-theme="light"] .text-purple-400          { color: #7E22CE !important; }
html[data-theme="light"] .text-indigo-300,
html[data-theme="light"] .text-indigo-400          { color: #4338CA !important; }

/* dark status chips (bg-*-950 + pale text) → pastel chips */
html[data-theme="light"] .bg-emerald-950\/70       { background-color: var(--pass-soft) !important; }
html[data-theme="light"] .bg-indigo-950\/70        { background-color: #EEF2FF !important; }
html[data-theme="light"] .bg-blue-950\/40          { background-color: var(--brand-soft) !important; }
html[data-theme="light"] .border-emerald-800\/30   { border-color: #A7F3D0 !important; }
html[data-theme="light"] .border-indigo-800\/30    { border-color: #C7D2FE !important; }


/* ════════════════════ 8b. LOW-CONTRAST ARBITRARY HEX TEXT ════════════════════ */
/* Hardcoded hex text classes that fail contrast in one or both modes.
   #4b6080 / #2a3d52 (new-audit.js progress UI) are ~3:1 / ~1.9:1 on the dark bg;
   #001b3e (auth submit buttons) is ~4:1 on the brand-blue gradient. */
.text-\[\#4b6080\]  { color: var(--text-3) !important; }
.text-\[\#2a3d52\]  { color: var(--text-3) !important; }
.text-\[\#94a3b8\]  { color: var(--text-2) !important; }
.text-\[\#001b3e\]  { color: var(--brand-on) !important; }


/* ════════════════════ 8c. PRINT-STYLE REPORT SHEETS (.page) ════════════════════ */
/* report-viewer.html renders A4 "paper" sheets that are ALWAYS white (they get
   printed). The dark-mode remaps in section 7 must not touch them — otherwise
   text-gray-900 turns near-white on the white sheet. Restore the original
   Tailwind palette inside .page in both modes. Placed after sections 7/8 so
   equal-specificity ties resolve in favour of these rules. */

html .page { background-color: #ffffff !important; color: #111827; }

html .page .text-gray-900 { color: #111827 !important; }
html .page .text-gray-800 { color: #1F2937 !important; }
html .page .text-gray-700 { color: #374151 !important; }
html .page .text-gray-600 { color: #4B5563 !important; }
html .page .text-gray-500 { color: #6B7280 !important; }
html .page .text-gray-400 { color: #9CA3AF !important; }
html .page .text-red-500  { color: #EF4444 !important; }
html .page .text-red-600  { color: #DC2626 !important; }
html .page .text-red-800  { color: #991B1B !important; }
html .page .text-amber-900 { color: #78350F !important; }
html .page .text-orange-800 { color: #9A3412 !important; }
html .page .text-blue-600 { color: #2563EB !important; }
html .page .text-white    { color: #ffffff !important; }

html .page .bg-gray-50    { background-color: #F9FAFB !important; }
html .page .bg-gray-100   { background-color: #F3F4F6 !important; }
html .page .bg-gray-200   { background-color: #E5E7EB !important; }
html .page .bg-gray-800   { background-color: #1F2937 !important; }
html .page .bg-red-50     { background-color: #FEF2F2 !important; }
html .page .bg-red-100    { background-color: #FEE2E2 !important; }
html .page .bg-orange-100 { background-color: #FFEDD5 !important; }

html .page .border-gray-200 { border-color: #E5E7EB !important; }
html .page .border-gray-300 { border-color: #D1D5DB !important; }
html .page .border-gray-400 { border-color: #9CA3AF !important; }
html .page .border-red-100  { border-color: #FEE2E2 !important; }
html .page .border-red-200  { border-color: #FECACA !important; }
html .page .border-red-300  { border-color: #FCA5A5 !important; }
html .page .divide-gray-200 > * + * { border-color: #E5E7EB !important; }

html .page input::placeholder,
html .page textarea::placeholder { color: #9CA3AF !important; }


/* ════════════════════ 9. SCROLLBAR ════════════════════ */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

* { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }


/* ════════════════════ 10. FOCUS / FORM ════════════════════ */

:focus-visible {
  outline: 2px solid var(--brand) !important;
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.btn-primary:focus-visible, [class*="bg-primary"]:focus-visible { outline-offset: 3px; }

input, textarea, select { font-family: inherit; }
input::placeholder, textarea::placeholder { color: var(--text-3) !important; }


/* ════════════════════ 11. MONO TYPE OPT-IN ════════════════════ */
/* The mono font is loaded by theme-toggle.js. Use .mono-text or [data-mono]
   on element(s) you want to render with JetBrains Mono — clause codes,
   measurements, IDs, timestamps. Existing inline `font-mono` Tailwind class
   also picks it up. */
.mono-text, [data-mono], .font-mono {
  font-family: var(--font-mono) !important;
  font-feature-settings: 'ss01', 'ss03';
}


/* ════════════════════ 12. THEME-TOGGLE FLOATING BUTTON ════════════════════ */
/* Auto-injected by theme-toggle.js; styles live here so the button looks
   correct on EVERY page without per-page work. Single-icon CYCLE button:
   light (light_mode) → dark (dark_mode) → system (brightness_auto). The icon
   reflects the current preference, set via [data-pref] on the button. */

#ezbuild-theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background var(--dur) var(--ease),
              color var(--dur) var(--ease),
              transform var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
#ezbuild-theme-toggle:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
  transform: translateY(-1px);
}
#ezbuild-theme-toggle:active { transform: translateY(0); }
#ezbuild-theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--shadow), var(--focus-ring);
}
#ezbuild-theme-toggle .tt-ico {
  font-size: 20px !important;
  line-height: 1;
  pointer-events: none;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20 !important;
}
/* "System" preference → tint the auto icon with brand so it reads as automatic. */
#ezbuild-theme-toggle[data-pref="system"],
#ezbuild-theme-toggle[data-pref="system"]:hover { color: var(--brand); }


/* ════════════════════ 13. PRINT SAFE ════════════════════ */
@media print {
  html, body { background: white !important; color: black !important; }
  #ezbuild-theme-toggle { display: none !important; }
}
