/* ── Light mode (default) ── */
:root {
  /* Surfaces */
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f2f1ee;
  --surface-3: #eceae6;

  /* Borders */
  --border: #e0ddd8;
  --border-light: #eeece9;
  --border-subtle: var(--border-light);

  /* Text */
  --text-primary: #1a1917;
  --text-secondary: #6b6760;
  --text-muted: #a09d98;

  /* Status colors */
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;

  /* Brand accent — fallback default. _base.html (V2) overrides at runtime
     from companies.primary_brand_color. */
  --accent: #c41e3a;
  --accent-light: color-mix(in srgb, var(--accent) 8%, transparent);
  --accent-hover: color-mix(in srgb, var(--accent) 90%, black);
  /* Brand red used as TEXT. Light = the accent itself. Dark lightens it (T-234). Fills and borders stay on --accent. */
  --accent-text: var(--accent);
  /* Text and icons on a brand-red fill. White in both themes (the fill does not flip). */
  --on-accent: #ffffff;

  /* === T-234 Kit palette: --kb-/--kt-/--kd- = background / text / border. The name is the light hex the
     Kit files used to hard-code; the light value is that exact color, the dark value is new. --k-on-ink is the
     text on an ink-colored fill (the fill flips to light in dark, so its text flips to dark). === */
  --k-on-ink: #ffffff;
  --k-on-ink-soft: #e6ddd4;
  --kb-1d1a17: #1d1a17;
  --kb-d9cec4: #d9cec4;
  --kb-e3f1e7: #e3f1e7;
  --kb-e3f4df: #e3f4df;
  --kb-e6f2ea: #e6f2ea;
  --kb-e6f4ea: #e6f4ea;
  --kb-e8e8e6: #e8e8e6;
  --kb-e8f1fb: #e8f1fb;
  --kb-e8f4fd: #e8f4fd;
  --kb-e9e0d8: #e9e0d8;
  --kb-eaf1fd: #eaf1fd;
  --kb-ececea: #ececea;
  --kb-efe7e0: #efe7e0;
  --kb-efe9e1: #efe9e1;
  --kb-efebe7: #efebe7;
  --kb-f0f0ee: #f0f0ee;
  --kb-f0f7e8: #f0f7e8;
  --kb-f1ebe4: #f1ebe4;
  --kb-f3ede7: #f3ede7;
  --kb-f4efe9: #f4efe9;
  --kb-f5efe9: #f5efe9;
  --kb-f6f1ec: #f6f1ec;
  --kb-f8f4ef: #f8f4ef;
  --kb-faf6f2: #faf6f2;
  --kb-faf9f5: #faf9f5;
  --kb-fafaf9: #fafaf9;
  --kb-fbe4e7: #fbe4e7;
  --kb-fbe9ec: #fbe9ec;
  --kb-fbefd6: #fbefd6;
  --kb-fbf1dc: #fbf1dc;
  --kb-fbf8f4: #fbf8f4;
  --kb-fde8e8: #fde8e8;
  --kb-fdf3dc: #fdf3dc;
  --kb-fdf6ec: #fdf6ec;
  --kb-fdf9f7: #fdf9f7;
  --kb-ffffff: #ffffff;
  --kd-1d4ed8: #1d4ed8;
  --kd-c3d6ef: #c3d6ef;
  --kd-d9cec4: #d9cec4;
  --kd-d9d0c7: #d9d0c7;
  --kd-e3d9d0: #e3d9d0;
  --kd-e9e0d8: #e9e0d8;
  --kd-ecc3cb: #ecc3cb;
  --kd-ecd7a8: #ecd7a8;
  --kd-efe7e0: #efe7e0;
  --kd-efe8e1: #efe8e1;
  --kd-ffffff: #ffffff;
  --kt-1b7f4c: #1b7f4c;
  --kt-1d1a17: #1d1a17;
  --kt-1d4ed8: #1d4ed8;
  --kt-1d6b12: #1d6b12;
  --kt-1f5c38: #1f5c38;
  --kt-1f6b3a: #1f6b3a;
  --kt-244b8f: #244b8f;
  --kt-2980b9: #2980b9;
  --kt-2f7d4f: #2f7d4f;
  --kt-3a332a: #3a332a;
  --kt-3b6d11: #3b6d11;
  --kt-4a433d: #4a433d;
  --kt-5b544d: #5b544d;
  --kt-666666: #666666;
  --kt-6a5f55: #6a5f55;
  --kt-6fcf97: #6fcf97;
  --kt-7a4f00: #7a4f00;
  --kt-7a5410: #7a5410;
  --kt-7a7068: #7a7068;
  --kt-8a1226: #8a1226;
  --kt-8a5a00: #8a5a00;
  --kt-8b5a00: #8b5a00;
  --kt-8f1428: #8f1428;
  --kt-8f867d: #8f867d;
  --kt-8f877e: #8f877e;
  --kt-92400e: #92400e;
  --kt-9a7a3a: #9a7a3a;
  --kt-9b8f84: #9b8f84;
  --kt-a30f26: #a30f26;
  --kt-a3182f: #a3182f;
  --kt-aaaaaa: #aaaaaa;
  --kt-b3122b: #b3122b;
  --kt-b8ada2: #b8ada2;
  --kt-b91c1c: #b91c1c;
  --kt-b9b1a8: #b9b1a8;
  --kt-bbbbbb: #bbbbbb;
  --kt-c0392b: #c0392b;
  --kt-c41e3a: #c41e3a;
  --kt-c8102e: #c8102e;
  --kt-cccccc: #cccccc;
  --kt-e8586f: #e8586f;
  --kt-f87171: #f87171;

  /* Layout */
  --sidebar-w: 210px;
  --rail-w: 260px;
  --rail-w-collapsed: 48px;
  --radius: 10px;
  --radius-sm: 6px;

  /* Shadows */
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.06);

  /* === Sprint 3.10 shell tokens === */
  --font-display: 'Archivo Expanded', 'Archivo', system-ui, sans-serif;

  /* Rail */
  --rail-bg: #17130e;
  --rail-border: #2b2418;
  --rail-hover: rgba(255,255,255,0.05);
  --rail-fg: #efe8dc;
  --rail-fg-dim: #948a79;
  --rail-active-bg: var(--accent);
  --rail-active-fg: #ffffff;
  --brass: #b08d57;

  /* App surfaces (shell-specific - do not replace --bg or --surface-2) */
  --app-bg: #efeae2;
  --topbar-bg: rgba(239,234,226,0.82);
  --border-strong: #d6ccbb;
  --divider: #ece4d8;

  /* Text aliases (shell uses --fg / --fg-2 / --fg-3) */
  --fg: #211d17;
  --fg-2: #6a6256;
  --fg-3: #a3998a;

  /* Positive indicator */
  --pos: #3fae6b;

  --green-deep: #15803d;
  --amber-fg: #b45309;

  /* Card shadows */
  --shadow-card: 0 2px 4px rgba(45,32,18,0.05), 0 12px 30px rgba(45,32,18,0.06);
  --shadow-card-hover: 0 10px 34px rgba(45,32,18,0.14);

  /* === Sprint 3.23 — TD13: --color-* alias layer ===
     12 templates reference these. Only 6 of 160 references carry a fallback,
     so the rest were resolving to an invalid value, not to a fallback.
     Defined as aliases (not literals) so dark mode inherits automatically. */
  --color-surface: var(--surface);
  --color-surface-2: var(--surface-2);
  --color-background-secondary: var(--surface-2);
  --color-input-bg: var(--surface);

  /* Bare --text: 86 refs with no fallback across the app (39 in
     job_detail.html alone), never defined. Not part of the --color-*
     family TD13 names, but the same defect. See TD13-phase-2 finding for
     the remaining 29 undefined tokens. */
  --text: var(--text-primary);

  --color-text: var(--text-primary);
  --color-text-primary: var(--text-primary);
  --color-text-secondary: var(--text-secondary);
  --color-text-muted: var(--text-muted);

  --color-border: var(--border);
  --color-border-secondary: var(--border-light);
  --color-border-tertiary: var(--border-light);

  --color-accent: var(--accent);
  --color-primary: var(--accent);
  --color-monarch-red: #c41e3a;   /* literal brand red, NOT --accent (tenant-overridable) */

  --color-danger: var(--red);
  --color-text-error: var(--red);
  --color-success: var(--green);
  --color-warning: var(--amber);
  --color-warning-bg: var(--amber-bg);

  /* Info triad — no existing base token; added to back --color-*-info */
  --info: #1e40af;
  --info-bg: #dbeafe;
  --info-border: #bfdbfe;
  --color-text-info: var(--info);
  --color-background-info: var(--info-bg);
  --color-border-info: var(--info-border);

  /* === Client portal palette (--cp-*) — DELIBERATELY NOT DEFINED HERE ===
     The client portal owns its own --cp-* palette in `client_portal.css`
     (:root, ~127 refs) and does NOT load this file. That isolation is
     intentional: Sprint 3.22 spec D14 keeps the portal off the internal
     tokens so its Shepherd theme cannot inherit unresolved custom
     properties. See the note in client_portal/_base.html.

     A --cp-* block was briefly added here in Sprint 3.23 Chunk A and then
     removed: it was unreachable from the only surface it described, and it
     collided on --cp-accent / --cp-border / --cp-surface with DIFFERENT
     values than the shipped palette (e.g. accent #a97e3f here vs #7A6440
     live) - which would have misled the next reader.

     The shipped palette and the HANDOFF-NOTES palette genuinely differ.
     Reconciling them belongs to the portal-alignment cleanup, together with
     the TD13-phase-2 token work - NOT to this sprint. Edit
     `client_portal.css` for client portal colour, never this file. */

  /* === Sprint 3.23 — Vendor portal palette (--vp-*), slate/blue ===
     Unlike the client portal, the vendor portal (app/templates/portal/*)
     DOES load tokens.css, and no competing --vp-* definition exists
     (vendor_panel.css is the internal Vendor Hub panel and has none).
     So these are reachable. Nothing consumes them yet - the vendor portal
     is still on generic grays; that adoption is portal-alignment work. */
  --vp-bg: #eef1f6;
  --vp-surface: #ffffff;
  --vp-border: #dbe1ec;
  --vp-border-strong: #c4cddd;
  --vp-fg: #1c2536;
  --vp-fg-2: #55617a;
  --vp-fg-3: #8e99b0;
  --vp-accent: #2f5fb0;
  --vp-accent-light: #3f74cc;
  --vp-accent-soft: #e6edf9;
  --vp-topbar: #182338;

  /* === Sprint 3.23 — QuickBooks green (QB-only status; never a general accent) === */
  --qb-green: #2CA01C;

  /* === Sprint 3.23 — Record-level Messages visibility banners ===
     Distinct from the red active-tab underline. Values from the
     "Record Level Messages Tab" design handoff. */
  --client-banner-bg: #eaf1fb;
  --client-banner-fg: #2f5c9e;
  --client-banner-bd: #c9dcf5;
  --vendor-banner-bg: #f0ecf9;
  --vendor-banner-fg: #6a4fb0;
  --vendor-banner-bd: #dcd2f0;

  /* === Sprint Staff Invite - Role palette ===
     Group/role identity colours: brass Owner, violet Superintendent, blue
     Director of Construction, teal Purchasing, terracotta Monarch Design.
     Values from docs/design-handoffs/Settings - Staff Invite.html. Consumed
     by the group pills on Settings > Staff and the role pill on the claim
     page; nothing else references them yet.

     Owner is var(--brass), not a literal, so it tracks the app's brass and
     needs no dark counterpart. The other four are literals and are flipped
     in the dark block below.

     The Superintendent violet duplicates --vendor-banner-bg/-fg by value.
     Deliberately independent: that pair styles the record-Messages vendor
     banner, an unrelated surface, and aliasing would couple the two. */
  --role-owner-bg: color-mix(in srgb, var(--brass) 16%, transparent);
  --role-owner-fg: var(--brass);
  --role-super-bg: #f0ecf9;
  --role-super-fg: #6a4fb0;
  --role-doc-bg: #e9edf5;
  --role-doc-fg: #455a86;
  --role-purch-bg: #dcebe8;
  --role-purch-fg: #2f6f66;
  --role-design-bg: #fbeae4;
  --role-design-fg: #b5613a;

  /* Draw requests -- prior-draw column warm parchment tint */
  --draw-col: #f4efe6;

  /* === Sprint 2A Bids/PO fidelity - authored-text tokens ===
     High-contrast foreground values for text on tinted amber/green backgrounds.
     --brass-ink: cost-code monospace (.cc .code), darker than --brass.
     --amber-authored: pending_award/pending_approval badge text, sel locked badge.
     --green-authored: acknowledged PO badge, approved selection badge. */
  --brass-ink: #785c2d;
  --amber-authored: #7d5400;
  --green-authored: #146c34;

  /* T3-16: undefined-var fixes. Aliases to existing tokens so dark mode
     inherits automatically; only shadow-pop needs a dark override. */
  --card-bg: var(--surface);
  --surface-1: var(--surface);
  --hover-bg: var(--surface-2);
  --border-radius-lg: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  --shadow-pop: 0 24px 48px rgba(0,0,0,.14), 0 8px 24px rgba(0,0,0,.10);
}

/* ── Dark mode ── */
[data-theme="dark"] {
  --bg: #111110;
  /* Warm-charcoal re-tune (D13a part 2). These three are app-wide, not
     shell-only -- every card, table, input and modal in dark mode shifts
     with them. See BACKLOG TD15. */
  --surface: #1e1a15;
  --surface-2: #252017;
  --surface-3: #2a2825;

  --border: #4a4234;
  --border-light: #252321;

  --text-primary: #f5f4f0;
  --text-secondary: #a19c94;
  --text-muted: #938e86;

  --green: #4ade80;
  --green-bg: rgba(74,222,128,.10);
  --red: #f87171;
  --red-bg: rgba(248,113,113,.10);
  --amber: #fbbf24;
  --amber-bg: rgba(251,191,36,.10);

  /* Dark-mode accent: auto-lighten the brand color so it works on dark surfaces. */
  --accent-light: color-mix(in srgb, var(--accent) 15%, transparent);
  --accent-hover: color-mix(in srgb, var(--accent) 80%, white);
  --accent-text: color-mix(in srgb, var(--accent) 50%, white);

  --shadow: 0 1px 3px rgba(0,0,0,.30), 0 1px 2px rgba(0,0,0,.20);
  --shadow-md: 0 4px 20px rgba(0,0,0,.40), 0 2px 6px rgba(0,0,0,.30);
  --shadow-lg: 0 10px 50px rgba(0,0,0,.50), 0 4px 16px rgba(0,0,0,.30);

  /* === Sprint 3.23 dark overrides ===
     The --color-* alias layer needs no entries here: each alias points at a
     base token that is already redefined above, so they re-resolve for free.
     Only tokens whose VALUES are literals need a dark counterpart. */
  --info: #93b4f8;
  --info-bg: rgba(147,180,248,.12);
  --info-border: rgba(147,180,248,.28);

  --client-banner-bg: #182635;
  --client-banner-fg: #8fb6e8;
  --client-banner-bd: #274058;
  --vendor-banner-bg: #221d33;
  --vendor-banner-fg: #b9a5e6;
  --vendor-banner-bd: #3a3055;

  /* === D13(a) shell-chrome dark values (BACKLOG TD15, part 1) ===
     These ten were literal light hex in :root with no dark counterpart,
     so the shell rendered half-dark in dark mode. Values locked by CD in
     docs/design-handoffs/Design-Decisions-2026-07-18 (D13 D10).md.
     The right rail is the first surface to consume --fg-3 / --divider /
     --pos / --brass heavily, which is why it surfaced here. */
  --fg: #f0e9dc;
  --fg-2: #b3a891;
  --fg-3: #a1957f;

  --divider: #2c261d;
  --border-strong: #5a5040;
  --brass: #c2a06a;

  --app-bg: #141311;
  --topbar-bg: rgba(20,19,17,0.82);

  --shadow-card: 0 2px 4px rgba(0,0,0,.30), 0 12px 30px rgba(0,0,0,.35);
  --shadow-card-hover: 0 10px 34px rgba(0,0,0,.45);

  --pos: #6cc78d;
  --green-deep: #4ade80;
  --amber-fg: #fbbf24;

  /* Role palette dark flip. --role-owner-* is absent by design: it resolves
     through var(--brass), which is already redefined above. */
  --role-super-bg: #221d33;
  --role-super-fg: #b9a5e6;
  --role-doc-bg: #1c2434;
  --role-doc-fg: #9db4dd;
  --role-purch-bg: #182624;
  --role-purch-fg: #7cc0b5;
  --role-design-bg: #2f211b;
  --role-design-fg: #dd9c78;

  --draw-col: #221d16;

  /* Sprint 2A authored-text dark flip */
  --brass-ink: #c9a978;
  --amber-authored: #fbbf24;
  --green-authored: #4ade80;

  /* T3-16 shadow-pop dark override */
  --shadow-pop: 0 24px 48px rgba(0,0,0,.50), 0 8px 24px rgba(0,0,0,.40);

  /* === T-240 dark-only tokens. Defined ONLY in this dark block (a guard test enforces it). Light mode never
     sees them: every use is var(--token, <the original light literal>), so light renders the literal. === */
  --red-fill: #dc2626;   /* white text 4.83:1 */
  --green-fill: #15803d; /* white text 5.02:1 */
  --amber-fill: #b45309; /* white text 5.02:1 */
  --d-panel: #211d19;
  --d-on-ink-blue: #1d4ed8; /* blue / green / red text on a fill that is light in dark mode (--kit-ink) */
  --d-on-ink-pos: #1f6b3a;
  --d-on-ink-neg: #a3172e;
  --d-dot-neutral: #8a8073; /* neutral status dot (draft) */
  --d-clear: rgba(33, 29, 25, 0); /* transparent version of --d-panel, for fade gradients */
  --d-on-ink: #16130f;   /* text on a fill that is ink in light and flips light in dark (--kit-ink) */
  --d-on-ink-2: #4a433d; /* secondary text on the same fill */
  --d-on-ink-amber: #8a5a00;
  --d-sunk: #2a2520;
  --d-raised: #332d28;
  --d-red-bg: #3a1a20;
  --d-amber-bg: #3a2d14;
  --d-green-bg: #173323;
  --d-blue-bg: #1b2a3b;
  --d-purple-bg: #221d33;
  --d-ink: #f1ebe4;
  --d-ink-2: #e0d8cd;
  --d-text2: #cfc5ba;
  --d-muted: #b3a99e;
  --d-red-t: #ff8a9a;
  --d-amber-t: #e2b356;
  --d-green-t: #6fd39a;
  --d-blue-t: #8cb8e8;
  --d-purple-t: #b9a5e6;
  --d-line: #2e2924;
  --d-line2: #3a332d;
  --d-line3: #463e37;
  --d-red-bd: #6a2a35;
  --d-amber-bd: #5a4520;
  --d-green-bd: #2a5a3c;
  --d-blue-bd: #274058;
  --d-purple-bd: #3a3055;
  --chip-red-bg: #3a1a20;
  --chip-red-fg: #ff8a9a;
  --chip-amber-bg: #3a2d14;
  --chip-amber-fg: #e2b356;
  --chip-green-bg: #173323;
  --chip-green-fg: #6fd39a;
  --chip-blue-bg: #1b2a3b;
  --chip-blue-fg: #8cb8e8;
  --chip-purple-bg: #221d33;
  --chip-purple-fg: #b9a5e6;
  --chip-neutral-bg: #332d28;
  --chip-neutral-fg: #cfc5ba;

  /* T-234 Kit palette, dark values */
  --k-on-ink: #16130f;
  --k-on-ink-soft: #3a332d;
  --kb-1d1a17: #f1ebe4;
  --kb-d9cec4: #332d28;
  --kb-e3f1e7: #173323;
  --kb-e3f4df: #173323;
  --kb-e6f2ea: #173323;
  --kb-e6f4ea: #173323;
  --kb-e8e8e6: #332d28;
  --kb-e8f1fb: #1b2a3b;
  --kb-e8f4fd: #1b2a3b;
  --kb-e9e0d8: #332d28;
  --kb-eaf1fd: #1b2a3b;
  --kb-ececea: #332d28;
  --kb-efe7e0: #332d28;
  --kb-efe9e1: #332d28;
  --kb-efebe7: #332d28;
  --kb-f0f0ee: #332d28;
  --kb-f0f7e8: #173323;
  --kb-f1ebe4: #332d28;
  --kb-f3ede7: #332d28;
  --kb-f4efe9: #332d28;
  --kb-f5efe9: #332d28;
  --kb-f6f1ec: #2a2520;
  --kb-f8f4ef: #2a2520;
  --kb-faf6f2: #2a2520;
  --kb-faf9f5: #2a2520;
  --kb-fafaf9: #2a2520;
  --kb-fbe4e7: #3a1a20;
  --kb-fbe9ec: #3a1a20;
  --kb-fbefd6: #3a2d14;
  --kb-fbf1dc: #3a2d14;
  --kb-fbf8f4: #2a2520;
  --kb-fde8e8: #3a1a20;
  --kb-fdf3dc: #3a2d14;
  --kb-fdf6ec: #2a2520;
  --kb-fdf9f7: #2a2520;
  --kb-ffffff: #211d19;
  --kd-1d4ed8: #274058;
  --kd-c3d6ef: #274058;
  --kd-d9cec4: #463e37;
  --kd-d9d0c7: #463e37;
  --kd-e3d9d0: #3a332d;
  --kd-e9e0d8: #3a332d;
  --kd-ecc3cb: #6a2a35;
  --kd-ecd7a8: #5a4520;
  --kd-efe7e0: #2e2924;
  --kd-efe8e1: #2e2924;
  --kd-ffffff: #2e2924;
  --kt-1b7f4c: #6fd39a;
  --kt-1d1a17: #f1ebe4;
  --kt-1d4ed8: #8cb8e8;
  --kt-1d6b12: #6fd39a;
  --kt-1f5c38: #6fd39a;
  --kt-1f6b3a: #6fd39a;
  --kt-244b8f: #8cb8e8;
  --kt-2980b9: #8cb8e8;
  --kt-2f7d4f: #6fd39a;
  --kt-3a332a: #e0d8cd;
  --kt-3b6d11: #6fd39a;
  --kt-4a433d: #e0d8cd;
  --kt-5b544d: #cfc5ba;
  --kt-666666: #cfc5ba;
  --kt-6a5f55: #cfc5ba;
  --kt-6fcf97: #6fd39a;
  --kt-7a4f00: #e2b356;
  --kt-7a5410: #e2b356;
  --kt-7a7068: #b3a99e;
  --kt-8a1226: #ff8a9a;
  --kt-8a5a00: #e2b356;
  --kt-8b5a00: #e2b356;
  --kt-8f1428: #ff8a9a;
  --kt-8f867d: #b3a99e;
  --kt-8f877e: #b3a99e;
  --kt-92400e: #e2b356;
  --kt-9a7a3a: #e2b356;
  --kt-9b8f84: #e2b356;
  --kt-a30f26: #ff8a9a;
  --kt-a3182f: #ff8a9a;
  --kt-aaaaaa: #b3a99e;
  --kt-b3122b: #ff8a9a;
  --kt-b8ada2: #b3a99e;
  --kt-b91c1c: #ff8a9a;
  --kt-b9b1a8: #b3a99e;
  --kt-bbbbbb: #b3a99e;
  --kt-c0392b: #ff8a9a;
  --kt-c41e3a: #ff8a9a;
  --kt-c8102e: #ff8a9a;
  --kt-cccccc: #b3a99e;
  --kt-e8586f: #ff8a9a;
  --kt-f87171: #ff8a9a;
}
