/* ============================================================================
   TI Supply — shared theme architecture (R1.3 + R1.4 whole-page theming)
   Sources: agent-planning/R1.1-theme-spec.md (tokens/palettes),
            agent-planning/R1.2-layout-merge-plan.md (shared chrome).

   State (set by app.js, mirrored in the head inline-script to avoid FOUC):
     <html>  data-theme="forge" | "workshop" | "blueprint"
             data-font-display="barlow-condensed" | "oswald" | "georgia"
             data-font-body="inter" | "roboto" | "system"
     <body>  data-family="dark" | "light"          (fixed per page)
             data-accent="miller-blue"|"house"|"light"   (millermatic only)
             data-accent="ap-teal"|"house"               (safetygrams only)

   Chrome (header/footer/dev panel) is styled by variable-driven classes so
   the SAME markup renders correctly on dark and light family pages.
   R1.4: page content re-themes too — each page's tailwind.config remaps its
   brand palettes + the slate light ramp onto the shared tokens below, so a
   palette choice re-skins the whole page (see §4b).
   ============================================================================ */

/* ---------- 1. Type tokens ------------------------------------------------ */
:root {
    --font-display: 'Barlow Condensed', 'Oswald', Georgia, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}
:root[data-font-display="barlow-condensed"] { --font-display: 'Barlow Condensed', sans-serif; }
:root[data-font-display="oswald"]           { --font-display: 'Oswald', sans-serif; }
:root[data-font-display="georgia"]          { --font-display: Georgia, 'Times New Roman', serif; }
:root[data-font-body="inter"]   { --font-body: 'Inter', system-ui, sans-serif; }
:root[data-font-body="roboto"]  { --font-body: 'Roboto', system-ui, sans-serif; }
:root[data-font-body="system"]  { --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; }

.font-display { font-family: var(--font-display) !important; }
.font-body    { font-family: var(--font-body) !important; }
/* Tailwind font-sans / font-mono resolve to the vars above (see per-page
   tailwind.config fontFamily). Millermatic is inline-CSS, so pin it too. */
body[data-page="millermatic"] { font-family: var(--font-body); }

/* ---------- 1b. Content token model (R1.4) -------------------------------
   The body content was authored with Tailwind's built-in neutrals (white /
   slate) and per-page brand palettes (charcoal / steel / industrial dark
   ramps + safety / amberforge accent, steelblue / ap-* info colors). Those
   are remapped — in each page's tailwind.config — onto shared CSS tokens so
   a palette choice re-skins the WHOLE page, not just the chrome. See §4b
   for the token definitions and the full model notes.
   */

/* ---------- 2. Palette P1 — Forge (default) ------------------------------- */
:root,
:root[data-theme="forge"] {
    --surface-bg: #0B0F15;
    --surface-subtle: #111827;
    --surface-card: #131A23;
    --surface-line: rgba(255, 255, 255, 0.07);
    --surface-inset: #070A0F;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --brand-accent: #F97316;
    --brand-accent-hover: #FB923C;
    --brand-accent-contrast: #FFFFFF;
    --brand-accent-soft: rgba(249, 115, 22, 0.12);
    --status-ok: #10B981;
    --status-warn: #F59E0B;
    --status-danger: #EF4444;
    --shadow-card: 0 18px 50px rgba(0, 0, 0, 0.45);
}

/* ---------- 3. Palette P2 — Workshop (light) ------------------------------ */
:root[data-theme="workshop"] {
    --surface-bg: #F8F9FB;
    --surface-subtle: #F1F4F8;
    --surface-card: #FFFFFF;
    --surface-line: rgba(15, 23, 42, 0.09);
    --surface-inset: #FFFFFF;
    --text-primary: #111827;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --brand-accent: #EA580C;
    --brand-accent-hover: #FB923C;
    --brand-accent-contrast: #0B0F15;   /* dark on orange → 5.4:1 (AA) */
    --brand-accent-soft: rgba(234, 88, 12, 0.10);
    --status-ok: #059669;
    --status-warn: #D97706;
    --status-danger: #DC2626;
    --shadow-card: 0 12px 32px rgba(15, 23, 42, 0.08);
}

/* ---------- 4. Palette P3 — Blueprint -------------------------------------- */
:root[data-theme="blueprint"] {
    --surface-bg: #0B1220;
    --surface-subtle: #0F1B2D;
    --surface-card: #12233A;
    --surface-line: rgba(148, 163, 184, 0.14);
    --surface-inset: #08101C;
    --text-primary: #E8EEF7;
    --text-secondary: #9FB4CC;
    --text-muted: #64748B;
    --brand-accent: #38BDF8;
    --brand-accent-hover: #7DD3FC;
    --brand-accent-contrast: #082032;
    --brand-accent-soft: rgba(56, 189, 248, 0.14);
    --hazard-signal: #F97316;           /* orange survives only as hazard   */
    --status-ok: #34D399;
    --status-warn: #FBBF24;
    --status-danger: #F87171;
    --shadow-card: 0 18px 50px rgba(2, 8, 20, 0.5);
}
:root[data-theme="blueprint"] {
    --hazard-signal: var(--hazard-signal, #F97316);
}

/* ---------- 4b. Content + brand token model (R1.4) ------------------------
   The body content was authored with Tailwind built-in neutrals (white /
   slate-*) and per-page brand palettes (charcoal/steel/industrial + safety/
   amberforge accent, plus steelblue / ap-* info colors). Those are remapped —
   in each page's tailwind.config — onto the tokens below so a palette choice
   re-skins the WHOLE page, not just the injected chrome.

   Two families of tokens:
     • Light content ramp (re-skins light section bands/borders per palette):
         --c-band-soft  slate-50   (page / soft band)
         --c-tile       slate-100  (section band / tile)
         --c-line       slate-200  (borders / dividers)
         --c-line-2     slate-300  (heavier line)
       Slate 400–950 (text) are LEFT as built-in fixed values so text contrast
       stays correct on both light sections and the dark brand surfaces.
     • Brand dark ramp + accent (re-skins heroes, top bars, dark cards, CTAs):
         --brand-950 / 900 / 850 / 800 / 700   dark surface ramp
         --brand-accent / accent-2 / accent-strong   primary accent + hovers
         --brand-info / info-deep              secondary "info" blue
   White (#fff) and the functional categorical colors (sky/emerald/cyan/rose/
   violet/indigo/teal/amber status + gas-identity colors) are left as fixed
   Tailwind values: they carry meaning and must not shift with the palette.
   ============================================================================ */

/* P1 — Forge (default): original live-site values (pixel-identical default) */
:root,
:root[data-theme="forge"] {
    --c-band-soft: #F8FAFC;
    --c-tile:      #F1F5F9;
    --c-line:      #E2E8F0;
    --c-line-2:    #CBD5E1;
    --brand-950: #0B0F15;
    --brand-900: #111827;
    --brand-850: #182232;
    --brand-800: #1F2937;
    --brand-700: #374151;
    --brand-info:      #1D4ED8;
    --brand-info-deep: #1E3A8A;
}
/* P2 — Workshop (light): cool near-gray brand ramp, burnt-orange accent */
:root[data-theme="workshop"] {
    --c-band-soft: #F9FAFB;
    --c-tile:      #F3F4F6;
    --c-line:      #E5E7EB;
    --c-line-2:    #D1D5DB;
    --brand-950: #10141A;
    --brand-900: #171D24;
    --brand-850: #202832;
    --brand-800: #2A333E;
    --brand-700: #3A4552;
    --brand-info:      #1D4ED8;
    --brand-info-deep: #1E3A8A;
}
/* P3 — Blueprint: steel-blue brand ramp, engineering-blue accent (deep enough
   for white CTA text). Orange survives only as --hazard-signal. */
:root[data-theme="blueprint"] {
    --c-band-soft: #F1F6FC;
    --c-tile:      #E6EEF8;
    --c-line:      #C2D2E6;
    --c-line-2:    #A9BED6;
    --brand-950: #081726;
    --brand-900: #0D2338;
    --brand-850: #123049;
    --brand-800: #1A3C5A;
    --brand-700: #265075;
    --brand-info:      #2563EB;
    --brand-info-deep: #1E40AF;
}

/* ---------- 5. Shared chrome (variable-driven; works dark + light) -------- */
.chrome-header {
    background: color-mix(in srgb, var(--surface-bg) 92%, transparent);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--surface-line);
}
.chrome-brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    height: 2.5rem; width: 2.5rem; border-radius: 0.5rem;
    background: var(--brand-accent);
    color: var(--brand-accent-contrast);
    font-family: var(--font-display);
    font-size: 1.125rem; font-weight: 700;
    transition: transform 0.15s ease;
}
a:hover .chrome-brand-mark { transform: scale(1.05); }
.chrome-headlogo {
    display: block; height: 3.75rem; width: auto; border-radius: 0.4rem;
    object-fit: contain; background: transparent;
    transition: transform 0.15s ease, filter 0.15s ease;
}
a:hover .chrome-headlogo { transform: scale(1.03); }
/* The supplied logo art is on a dark charcoal field; on light chrome a hard
   rectangle reads as a dark chip. Keep it, but soften the edge so it sits
   cleanly on the white header without a harsh seam. */
.chrome-headlogo { box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.chrome-drawerlogo { display: block; height: 2.75rem; width: auto; border-radius: 0.35rem; }
.chrome-brand-name {
    display: block; font-family: var(--font-display);
    font-size: 1.5rem; font-weight: 700; letter-spacing: 0.02em;
    color: var(--text-primary);
}
.chrome-brand-sub {
    display: block; font-size: 10px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.28em;
    color: var(--text-muted);
}
.chrome-navlink {
    font-size: 0.875rem; font-weight: 600;
    color: var(--text-muted);
    transition: color 0.15s ease;
}
.chrome-navlink:hover { color: var(--text-primary); }
.chrome-navlink[data-active="true"] { color: var(--text-primary); }
.chrome-phone { font-size: 0.875rem; font-weight: 700; color: var(--text-primary); }
.chrome-cta {
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 0.5rem; padding: 0.625rem 1.25rem;
    background: var(--brand-accent);
    color: var(--brand-accent-contrast);
    font-size: 0.875rem; font-weight: 700;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--brand-accent) 20%, transparent);
    transition: background 0.15s ease;
}
.chrome-cta:hover { background: var(--brand-accent-hover); }
.chrome-iconbtn {
    border-radius: 0.5rem; border: 1px solid var(--surface-line);
    padding: 0.625rem; color: var(--text-muted);
    transition: background 0.15s ease;
}
.chrome-iconbtn:hover { background: var(--brand-accent-soft); }

/* mobile drawer */
#app-mobile-menu, .chrome-drawer { background: rgba(0, 0, 0, 0.55); }
body[data-family="light"] .chrome-drawer,
body[data-page="millermatic"] .chrome-drawer { background: rgba(15, 23, 42, 0.45); }
.chrome-drawer-panel {
    background: var(--surface-subtle);
    border-left: 1px solid var(--surface-line);
}
.chrome-drawer a { color: var(--text-secondary); transition: background .15s, color .15s; }
.chrome-drawer a:hover { background: var(--brand-accent-soft); color: var(--text-primary); }
.chrome-input {
    background: var(--surface-bg);
    border: 1px solid var(--surface-line);
    color: var(--text-primary);
}
.chrome-input::placeholder { color: var(--text-muted); }
.chrome-input:focus { outline: none; border-color: var(--brand-accent); }

/* ---------- 5b. Utility fallbacks for the no-Tailwind page (millermatic) -- */
/* The canonical chrome relies on Tailwind utilities (hidden / lg:flex /
   lg:hidden / gap) which are inert on millermatic (inline CSS, no Tailwind).
   These global rules replicate them; on Tailwind pages they mirror the
   utilities, so they are a no-op there. */
/* Mirrors Tailwind's `hidden` utility (the drawer markup always carries the
   `hidden` class until a script removes it); inert on Tailwind pages. */
.chrome-drawer.hidden { display: none; }
/* header row layout (inert on millermatic, which has no Tailwind) */
.chrome-headrow {
    display: flex !important; align-items: center; justify-content: space-between;
    height: 5rem; max-width: 80rem; margin: 0 auto;
    gap: 1.5rem; padding: 0 1rem;
}
@media (min-width: 640px) { .chrome-headrow { padding: 0 1.5rem; } }
@media (min-width: 1024px) { .chrome-headrow { padding: 0 2rem; } }
/* footer grid layout */
.chrome-footgrid { display: grid !important; grid-template-columns: repeat(4, 1fr); gap: 2.5rem; }
@media (max-width: 1023.98px) { .chrome-footgrid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 767.98px)  { .chrome-footgrid { grid-template-columns: 1fr; } }
@media (min-width: 1024px) {
    .chrome-nav { display: flex !important; gap: 2rem; }
    .chrome-header-right { display: flex !important; gap: 0.75rem; }
    .chrome-header-hamb { display: none !important; }
}
@media (max-width: 1023.98px) {
    .chrome-nav { display: none !important; }
    .chrome-header-right { display: none !important; }
    .chrome-header-hamb { display: inline-flex !important; }
    .chrome-drawer.open { display: block !important; }
}

/* footer */
.chrome-footer {
    background: var(--surface-inset);
    border-top: 1px solid var(--surface-line);
}
.chrome-foot-title {
    font-family: var(--font-display);
    font-size: 1rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.2em;
    color: var(--text-muted);
}
.chrome-foot-link {
    font-size: 0.875rem; color: var(--text-muted);
    transition: color 0.15s ease;
}
.chrome-foot-link:hover { color: var(--text-primary); }
.chrome-foot-text { font-size: 0.875rem; line-height: 1.65; color: var(--text-secondary); }
.chrome-hazard {
    height: 4px; width: 100%;
    background: repeating-linear-gradient(45deg,
        var(--brand-accent) 0 14px,
        transparent 14px 28px);
    opacity: 0.9;
}

/* ---------- 6. Main wrap (sticky-header compensation) ---------------------- */
main.app-main { position: relative; }

/* ---------- 7. Per-page family overrides ----------------------------------- */
/* Light-family pages pin light surfaces regardless of the global palette.   */
body[data-family="light"] {
    --surface-bg: #FFFFFF;
    --surface-subtle: #F6F8FA;
    --surface-card: #FFFFFF;
    --surface-line: rgba(15, 23, 42, 0.09);
    --surface-inset: #F8F9FB;
    --text-primary: #0F172A;
    --text-secondary: #334155;
    --text-muted: #64748B;
    --shadow-card: 0 10px 30px rgba(15, 23, 42, 0.07);
}

/* Millermatic — default: house brand accent under the current palette */
body[data-page="millermatic"]:not([data-accent="light"]) {
    --brand-accent: #005596;
    --brand-accent-hover: #0074D9;
    --brand-accent-contrast: #FFFFFF;
    --brand-accent-soft: rgba(0, 85, 150, 0.12);
}
/* Millermatic — "house" accent option */
body[data-page="millermatic"][data-accent="house"] {
    --brand-accent: var(--brand-accent); /* no-op: use palette accent */
}
/* Millermatic — "light look": original light design, merged onto tokens */
body[data-page="millermatic"][data-accent="light"] {
    --surface-bg: #FFFFFF;
    --surface-subtle: #F8F9FB;
    --surface-card: #FFFFFF;
    --surface-line: rgba(15, 23, 42, 0.09);
    --surface-inset: #F8F9FB;
    --text-primary: #111827;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --brand-accent: #005596;
    --brand-accent-hover: #0074D9;
    --brand-accent-contrast: #FFFFFF;
    --brand-accent-soft: rgba(0, 85, 150, 0.10);
    --shadow-card: 0 10px 30px rgba(15, 23, 42, 0.08);
}
/* Millermatic inline-CSS token swaps (its custom classes reference vars) */
body[data-page="millermatic"] .mm-header { background: var(--surface-bg); border-color: var(--surface-line); }
body[data-page="millermatic"] .mm-card   { background: var(--surface-card); border-color: var(--surface-line); box-shadow: var(--shadow-card); }
body[data-page="millermatic"] .mm-accent { background: var(--brand-accent); color: var(--brand-accent-contrast); }
body[data-page="millermatic"] .mm-accent-text { color: var(--brand-accent); }
body[data-page="millermatic"] .mm-line   { border-color: var(--surface-line); }

/* Millermatic — "light look": original light design merged onto tokens.
   The millermatic page ships its own inline :root vars (it is the inline-CSS
   outlier, per AGENTS.md). These page vars win the cascade over the global
   palette, so for the "light" accent mode we override the page vars to the
   original light values AND pin light surfaces, giving the pre-existing light
   look but built on the shared token system. */
body[data-page="millermatic"][data-accent="light"] {
    /* page-var overrides (win over the global :root[data-theme]) */
    --miller-blue: #005596;
    --miller-blue-dark: #00416e;
    --slate-900: #111827;
    --slate-100: #f8fafc;
    --slate-200: #e2e8f0;
    --slate-800: #1e293b;
    /* global surface tokens (chrome + dev panel) */
    --surface-bg: #f8fafc;
    --surface-subtle: #ffffff;
    --surface-card: #ffffff;
    --surface-line: rgba(15, 23, 42, 0.09);
    --surface-inset: #f1f5f9;
    --text-primary: #111827;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --brand-accent: #005596;
    --brand-accent-contrast: #ffffff;
    --brand-accent-soft: rgba(0, 85, 150, 0.10);
}

/* Millermatic — its sticky filter bar sits below the canonical 80px nav, and
   the nav must overlay it (z-index). Only affects the millermatic page. */
body[data-page="millermatic"] .controls-wrap { top: 80px; z-index: 15; }
body[data-page="millermatic"] .chrome-header { z-index: 40; }

/* Safetygrams — AP brand accent */
body[data-page="safetygrams"][data-accent="ap-teal"] {
    --brand-accent: #007A53;
    --brand-accent-hover: #009E6B;
    --brand-accent-contrast: #FFFFFF;
    --brand-accent-soft: rgba(0, 122, 83, 0.12);
}
body[data-page="safetygrams"][data-accent="house"] {
    /* palette accent (already set) — no override needed; explicit for clarity */
}

/* ---------- 8. Dev panel ---------------------------------------------------- */
/* Fixed bottom-right drawer, keyboard-toggled (Backquote / Esc).
   Deliberately not discoverable from the UI; ~10 lines to strip before
   production (see R5 checklist). */
#tis-devpanel {
    position: fixed; bottom: 16px; right: 16px; z-index: 2147483000;
    width: 264px;
    background: #0D1117;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    font-family: 'Inter', system-ui, sans-serif;
    color: #E6EDF3;
    opacity: 0; transform: translateY(8px); pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
#tis-devpanel[data-open="true"] { opacity: 1; transform: none; pointer-events: auto; }
#tis-devpanel .tis-dp-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
#tis-devpanel .tis-dp-title {
    font-size: 11px; font-weight: 700; letter-spacing: 0.18em; color: #F97316;
}
#tis-devpanel .tis-dp-close {
    background: none; border: none; color: #8B949E; cursor: pointer; padding: 2px;
}
#tis-devpanel .tis-dp-body { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
#tis-devpanel .tis-dp-row { display: flex; flex-direction: column; gap: 5px; }
#tis-devpanel .tis-dp-label {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.14em; color: #8B949E;
}
#tis-devpanel select {
    width: 100%; appearance: none;
    background: #161B22 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238B949E'/%3E%3C/svg%3E") no-repeat right 10px center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    color: #E6EDF3;
    font: 500 12.5px/1.2 'Inter', system-ui, sans-serif;
    padding: 8px 26px 8px 10px;
    cursor: pointer;
}
#tis-devpanel select:focus { outline: 2px solid #F97316; outline-offset: 1px; }
#tis-devpanel .tis-dp-reset {
    margin-top: 2px; width: 100%;
    background: #161B22; border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px; color: #E6EDF3; cursor: pointer;
    font: 600 12px/1.2 'Inter', system-ui, sans-serif;
    padding: 8px 10px; transition: background 0.15s ease, border-color 0.15s ease;
}
#tis-devpanel .tis-dp-reset:hover { background: #1F2630; border-color: rgba(249, 115, 22, 0.5); }
#tis-devpanel .tis-dp-note {
    font-size: 10.5px; line-height: 1.5; color: #6E7681; margin-top: 2px;
}
#tis-devpanel .tis-dp-row[hidden] { display: none; }
