/* ── Sown Mastercontrol · the colour tokens, BOTH themes ──────────────────
   The one place a colour is defined. Every page loads this FIRST (before
   sidebar.css / style.css / its own sheet), and every other stylesheet and
   inline <style> block refers to these tokens instead of spelling a hex value.

   TWO THEMES, selected by <html data-theme="dark|light">:
     dark   the default (nothing stored) — and byte-for-byte the palette
            MasterControl had before light mode existed: every value in the
            :root block below is the literal it replaced, so dark renders
            pixel-identical (scripts/live-theme.js diffs it).
     light  Amazon's palette, for direct sunlight (Jimmy, 2026-09-27): white
            content surfaces, #0F1111 text, and a NAVY header — every top bar
            (.topbar, .termbar, .rm-top) re-scopes the same tokens to navy + white,
            exactly like amazon.com's nav, so no top-bar rule needed changing.
   The attribute is written before first paint by a tiny inline script in each
   page's <head> (localStorage['mc.theme'], per device); public/theme.js owns
   the toggle buttons, cross-tab sync and the `mc:theme` event.

   ADDING A COLOUR: add a token to BOTH blocks below (dark = what you would
   have written; light = checked against its background with a contrast
   calculator: ≥4.5:1 for text, ≥3:1 for icons / UI boundaries), then use
   var(--token). Never add a hex literal to another stylesheet.

   Every light text/background pair used by the app is measured by
   scripts/live-theme.js (the contrast audit) — run it after touching this. */

:root {
  /* ── core ─────────────────────────────────────────────────────────── */
  --bg: #0a0d13;          /* page, chat pane, inputs                        */
  --panel: #121722;       /* bars, cards, sidebars, modals                  */
  --panel-2: #1a2130;     /* raised: pills, buttons, rows, code             */
  --border: #232b3d;
  --text: #e6ebf5;
  --dim: #8b96ab;
  --faint: #59637a;
  --teal: #5eead4;        /* the accent (links, active states)              */
  --amber: #fbbf24;       /* NEEDS YOU                                       */
  --green: #34d399;       /* WORKING / ok                                    */
  --blue: #60a5fa;        /* READY                                           */
  --red: #f87171;         /* danger / error                                  */

  /* ── surfaces with a job of their own ─────────────────────────────── */
  --hover: #232b3d;       /* pressed key-bar keys, menu rows                 */
  --selected: #1c2536;    /* the chosen sidebar row                          */
  --inset: #0e1320;       /* mastermind strip, an expanded worker card       */
  --code-bg: #0b0e14;     /* <pre> in a chat, the tool-trace body            */
  --peek-bg: #06080d;     /* a worker's screen peek                          */
  --needs-bg: #2a2314;    /* a row / card / banner that is waiting on you    */
  --user-bg: #1b3a37;     /* Jimmy's own chat bubble                         */
  --user-bd: #2dd4bf44;   /* … and its edge                                  */
  --page: transparent;    /* behind the dashboard's and meetings' cards      */
  --edge: #232b3d;        /* the edge of a card / row / bubble on its surface */
  --dot-gone: #59637a;    /* an ended worker's status dot                    */
  --tab-border: #1b2231;  /* an inactive terminal tab                        */
  --scrim: #000a;         /* modal / drawer / sheet backdrop                 */
  --drop-bg: #134e4acc;   /* the drag-a-file-here overlay                    */
  --glow: rgba(94,234,212,.08);  /* the login card's halo                    */

  /* ── the terminal (xterm's own palette lives in app.js TERM_THEMES) ─── */
  --term-bg: #0b0e14;     /* terminal view + the phone's peek                */
  --term-text: #cbd5e1;   /* plain-text screen captures (the phone's peek)   */
  --term-veil: #0b0e14cc; /* "reconnecting…" over a pane                     */
  --term-sel-bg: #6ee7b7; /* the house selection green (all three surfaces)  */
  --term-sel-fg: #0b0e14;

  /* ── accent tints (the teal at a fixed alpha, by strength) ─────────── */
  --teal-a05: #2dd4bf0d;
  --teal-a07: #2dd4bf12;
  --teal-a08: #2dd4bf14;
  --teal-a13: #2dd4bf22;
  --teal-a20: #2dd4bf33;
  --teal-a27: #2dd4bf44;
  --teal-a33: #2dd4bf55;
  --teal-a40: #2dd4bf66;  /* focus / active borders                          */
  --teal-a53: #5eead488;
  --latched-bg: #134e4a;  /* a latched key (Ctrl)                            */

  /* ── primary action (Send, Create, Approve) ────────────────────────── */
  --primary-bg: #0f766e;
  --primary-bg-active: #115e59;
  --primary-fg: #ccfbf1;
  --primary-fg-alt: #d9fff7;       /* the phone remote + the approve page  */
  --primary-bd: #2dd4bf66;
  --primary-bd-solid: #0f766e;     /* meetings' job actions                */
  --primary-ring: none;            /* the edge of a borderless primary (a whole box-shadow) */
  /* the lit segment of the workers-model toggle */
  --seg-on-bg: #0f766e;
  --seg-on-fg: #ccfbf1;
  --seg-on-bd: #2dd4bf66;
  /* a secondary button on the Tesla / login surfaces */
  --btn2-bg: #1a2130;
  --btn2-bd: #2f3a52;
  /* borders of things you type into or press (≥3:1 in light) */
  --control-border: #232b3d;
  --focus-ring: none;

  /* ── status pills ──────────────────────────────────────────────────── */
  --pill-needs-fg: #fbbf24;
  --pill-needs-bg: #78350f33;
  --pill-needs-bd: #b4530955;
  --pill-work-bg: #064e3b33;
  --pill-work-bd: #05966955;
  --pill-ready-bg: #1e3a8a2e;
  --pill-ready-bd: #3b82f655;
  --pill-shell-bg: #33415522;
  --pill-shell-bd: #47556955;
  --on-amber: #1a1204;    /* text on an amber badge                          */
  --on-proj: #0a0d13;     /* text on a project-coloured chip                 */
  --hit-bg: #fde68a;      /* a search hit (<mark>) in the chat list          */
  --hit-fg: #1a1204;      /* … and the text on it                            */
  /* an AGENT chip (A2): a session / chat / worker on another Claude account's
     box (docs/AGENTS.md). Violet, so it never reads as a status colour.
     #c4b5fd is 9.4:1 on --panel, 8.8:1 on its own tint. */
  --agent-fg: #c4b5fd;
  --agent-bg: #7c3aed24;
  --agent-bd: #a78bfa66;

  /* ── warnings, errors, success ─────────────────────────────────────── */
  --card-needs-bg: #451a030f;
  --card-needs-bd: #b4530999;
  --warn-bg: #78350f26;
  --warn-bd: #b4530966;
  --err-bg: #7f1d1d2e;
  --err-bg-soft: #7f1d1d22;
  --err-bg-strong: #7f1d1d33;
  --err-bd: #f8717166;
  --err-bd-deep: #b91c1c55;
  --err-bd-deep-strong: #b91c1c66;
  --danger-bd: #f8717155;
  --red-soft: #fca5a5;    /* error text on a dark surface                    */
  --err-text: #fecaca;
  --ok-text: #6ee7b7;
  --green-bd: #34d39955;
  --blue-bd: #60a5fa55;

  /* ── brand mark + login's Google button ────────────────────────────── */
  --mark-bg: linear-gradient(135deg, #0f766e, #134e4a);
  --mark-bd: #2dd4bf44;
  --mark-fg: #5eead4;     /* the login page's mark (the bars use --teal)     */
  --gbtn-bg: #e6ebf5;
  --gbtn-fg: #1a2130;
  --gbtn-ring: none;      /* its edge — a whole box-shadow, none in dark     */

  /* ── shadows ───────────────────────────────────────────────────────── */
  --shadow: #000a;
  --shadow-soft: #0008;
  --shadow-mid: #0009;
  --shadow-deep: #000b;
  --shadow-max: #000c;
  --tesla-badge-bg: #121722ee;
}

/* ════════════════════════════ LIGHT (Amazon) ════════════════════════════
   Measured on white unless noted (WCAG ratios):
     text #0F1111 18.9 · dim #565959 7.1 · faint #6B6F6F 5.1 (4.5 on #F0F2F2)
     teal #007185 5.7 · amber #B04A00 5.5 · green #007600 5.9 · blue #0066C0 5.7
     red #B12704 6.6 · control border #888C8C 3.4 · white on amber 5.5 */
:root[data-theme="light"] {
  --bg: #FFFFFF;
  --panel: #FFFFFF;
  --panel-2: #F7FAFA;
  --border: #D5D9D9;
  --text: #0F1111;
  --dim: #565959;
  --faint: #6B6F6F;
  --teal: #007185;
  --amber: #B04A00;
  --green: #007600;       /* Amazon's "In Stock" — a green, not a teal       */
  --blue: #0066C0;
  --red: #B12704;

  --hover: #E3E6E6;
  --selected: #E7F4F5;
  --inset: #F7FAFA;
  --code-bg: #F7FAFA;
  --peek-bg: #F7FAFA;
  --needs-bg: #FEF3E6;
  /* Jimmy's bubble must read as HIS against the white page: a deeper tint and a
     teal edge (1.24:1 fill, 3.05:1 edge) instead of 1.1 / 1.6 (review #5) */
  --user-bg: #D2EBEF;
  --user-bd: #4F9FAD;
  /* Amazon's page grey behind the dashboard's and meetings' white cards, and a
     stronger edge (1.9:1) wherever white sits on white — #D5D9D9 is 1.4:1,
     and outdoors the cards melted into the page (review #5) */
  --page: #EAEDED;
  --edge: #BBBFBF;
  /* ended: lighter than the shell grey, so the two dots separate (2.2:1, and
     still 3.2:1 on white) — they measured 1.36:1 apart (review #7) */
  --dot-gone: #8D9191;
  --tab-border: #D5D9D9;
  --scrim: #0f111166;
  --drop-bg: #E7F4F5e6;
  --glow: transparent;


  --teal-a05: #F0F8F9;
  --teal-a07: #EAF5F7;
  --teal-a08: #E4F2F4;
  --teal-a13: #D3EBEF;
  --teal-a20: #7FB8C2;
  --teal-a27: #A9D3DA;
  --teal-a33: #4F9FAD;
  --teal-a40: #007185;
  --teal-a53: #007185;
  --latched-bg: #E4F2F4;

  /* Amazon's "Add to Cart" — with a darker edge than Amazon's #FCD200
     (1.5:1 on white): a button's outline must be ≥3:1, and in sunlight a
     yellow shape on white otherwise disappears. #A08300 = 3.7 : 1. */
  --primary-bg: #FFD814;
  --primary-bg-active: #F7CA00;
  --primary-fg: #0F1111;
  --primary-fg-alt: #0F1111;
  --primary-bd: #A08300;
  --primary-bd-solid: #A08300;
  --primary-ring: inset 0 0 0 1px #A08300;
  --seg-on-bg: #007185;
  --seg-on-fg: #FFFFFF;
  --seg-on-bd: #007185;
  --btn2-bg: #FFFFFF;
  --btn2-bd: #888C8C;
  --control-border: #888C8C;
  /* Amazon's focus: teal border + a pale teal halo */
  --focus-ring: 0 0 0 3px #C8F3FA;

  /* NEEDS YOU is a FILLED pill in light — tinted text on white is too quiet
     next to a yellow Send button, and it must stay the loudest thing on screen */
  --pill-needs-fg: #FFFFFF;
  --pill-needs-bg: #B04A00;
  --pill-needs-bd: #B04A00;
  --pill-work-bg: #EAF6F1;
  --pill-work-bd: #9BD3C1;
  --pill-ready-bg: #EAF2FB;
  --pill-ready-bd: #A9C8EC;
  --pill-shell-bg: #F0F2F2;
  --pill-shell-bd: #BBBFBF;
  --on-amber: #FFFFFF;
  --on-proj: #0F1111;
  --hit-bg: #FFD814;
  --hit-fg: #0F1111;
  /* agent chip: #6D28D9 is 7.1:1 on white, 6.2:1 on its #F3EEFF tint; the
     #8B5CF6 edge is 4.2:1 on white */
  --agent-fg: #6D28D9;
  --agent-bg: #F3EEFF;
  --agent-bd: #8B5CF6;

  --card-needs-bg: #FEF3E6;
  --card-needs-bd: #E8A15C;
  --warn-bg: #FEF3E6;
  --warn-bd: #E8A15C;
  --err-bg: #FDECE8;
  --err-bg-soft: #FDECE8;
  --err-bg-strong: #FDECE8;
  --err-bd: #D9897A;
  --err-bd-deep: #D9897A;
  --err-bd-deep-strong: #D9897A;
  --danger-bd: #D9897A;
  --red-soft: #B12704;
  --err-text: #B12704;
  --ok-text: #007600;
  --green-bd: #9BD3C1;
  --blue-bd: #A9C8EC;

  --mark-bg: #232F3E;
  --mark-bd: #FF9900;
  --mark-fg: #FF9900;
  --gbtn-bg: #FFFFFF;
  --gbtn-fg: #0F1111;
  --gbtn-ring: inset 0 0 0 1px #888C8C;

  --shadow: #0f111129;
  --shadow-soft: #0f111126;
  --shadow-mid: #0f11112e;
  --shadow-deep: #0f111133;
  --shadow-max: #0f11113d;
  --tesla-badge-bg: #FFFFFFf2;
}

/* text that sits straight on the page grey (a section title, "no active
   sessions", an ssh chip) gets a darker faint: #6B6F6F is 4.3:1 on #EAEDED,
   #5F6363 is 5.2 (and 6.1 on white) */
:root[data-theme="light"] #dash-shell,
:root[data-theme="light"] .meetings-page #content,
:root[data-theme="light"] .meetings-page #det-content { --faint: #5F6363; }

/* ── project colours in light ──────────────────────────────────────────────
   projects.json's colours are pastels picked for a dark page — on white they
   are 1.4-3.0:1, and the row stripe, the card stripe and the project dot are
   the fastest way to scan for a project (review #4). Light mixes them 35%
   toward black (every current project lands at 3.4-6.2:1, ≥3 for a UI mark).
   The needs / active / hover states keep their own stripe colour. Dots carry
   their colour inline (JS), so a 35%-black inset shadow does the same mix.
   The terminal tabs sit on the navy bar, where the pastels already read. */
/* Inside @supports: a color-mix() the engine does not know is invalid at
   computed-value time, which falls back to currentColor — every stripe would
   turn the same near-black #0F1111 (review D2; the Tesla's Chromium version is
   unknown). Without support the stripes simply stay the pastel they were. */
@supports (color: color-mix(in srgb, red 50%, #000)) {
  :root[data-theme="light"] .sb-item:not(.needs):not(.active):not(:hover) { border-left-color: color-mix(in srgb, var(--c) 65%, #000); }
  :root[data-theme="light"] .card:not(.needs) { border-left-color: color-mix(in srgb, var(--card-color, var(--border)) 65%, #000); }
  /* project GROUPS (public/groups.css): the heading rule and the tree's guide
     line get the same 35% darkening as the project stripes */
  :root[data-theme="light"] .pg-chead { border-bottom-color: color-mix(in srgb, var(--g) 65%, #000); }
  :root[data-theme="light"] .pg-gbody::before { background: color-mix(in srgb, var(--g) 65%, #000); }
}
:root[data-theme="light"] .sb-proj-dot,
:root[data-theme="light"] .project-dot,
:root[data-theme="light"] .pg-gdot:not(.pg-gdot-arch),
:root[data-theme="light"] .mm-dot { box-shadow: inset 0 0 0 10px rgba(0, 0, 0, .35); }
:root[data-theme="light"] .pg-sw { box-shadow: inset 0 0 0 1px var(--control-border); }
:root[data-theme="light"] .sb-item.sb-all .sb-proj-dot { box-shadow: none; }

/* ── nothing is faded in light ───────────────────────────────────────────
   Dark mode de-emphasises a few things with opacity: an empty mastermind strip
   (.75), a card for a session outside mastercontrol (.82), an archived chat row
   (.5), an ended worker (.55), a queued message (.6). On white in sunlight that
   takes their text below 4.5:1 — faint text at 75% is 3.7:1 — so light mode
   drops the fade and each keeps the cue it already had: the strip's dashed
   border and italic label, the external card's dashed stripe, the Ended (n)
   group, the queued bubble's dashed border; an archived row gains one (its
   border goes dashed), since opacity was its only mark. */
:root[data-theme="light"] .mm-strip.empty,
:root[data-theme="light"] .card.external,
:root[data-theme="light"] .mm-ci-archived,
:root[data-theme="light"] .mm-crew-card.ended,
:root[data-theme="light"] .mm-msg.user.queued { opacity: 1; }
:root[data-theme="light"] .mm-ci-archived { border-style: dashed; }
/* a placeholder is text you have to read to know what goes there */
:root[data-theme="light"] ::placeholder { color: var(--faint); opacity: 1; }

/* ── the terminal pane in light mode ───────────────────────────────────
   A LIGHT terminal: public/app.js gives xterm a white palette (TERM_THEMES.light
   — Claude Code's ANSI colours inverted by role) plus minimumContrastRatio 7,
   and follows --term-scheme below. THE FALLBACK — the pane stays dark inside
   light chrome — is this block alone, swapped for:
       --term-scheme: dark; --term-bg: #0b0e14; --term-veil: #0b0e14cc;
       --term-text: #cbd5e1; --term-sel-fg: #0b0e14;
   (scripts/live-theme.js injects exactly that to screenshot both.) */
:root[data-theme="light"] {
  --term-scheme: light;
  --term-bg: #FFFFFF;
  --term-text: #0F1111;
  --term-veil: #FFFFFFd9;
  --term-sel-bg: #6ee7b7;
  --term-sel-fg: #0F1111;
}

/* ── the Amazon header ───────────────────────────────────────────────────
   Every top bar stays navy with white text in light mode. Custom properties
   inherit, so re-declaring the tokens on the bar re-colours its whole subtree —
   brand, usage pills, model chip, icon buttons, terminal tabs, the phone's
   header — with no top-bar rule changing. The usage pills' fill/percentage/
   border colours are set inline by app.js / mastermind.js (#f87171 / #fbbf24 /
   #34d399); on navy they measure 6.4 / 10.6 / 9.2 : 1, so they stay as they are.
   Measured on #131921 (bar) and #232F3E (pills, active tab): white 17.7 / 13.6,
   dim #D5D9D9 12.4 / 9.5, faint #AAB7B8 8.6 / 6.6, orange #FF9900 8.3 / 6.3. */
:root[data-theme="light"] .topbar,
:root[data-theme="light"] .termbar,
:root[data-theme="light"] .rm-top {
  --bg: #0B1017;          /* usage-bar track, inactive tabs                   */
  --panel: #131921;       /* Amazon nav navy                                  */
  --panel-2: #232F3E;     /* Amazon's secondary strip: pills, chip, active tab*/
  --border: #3A4553;
  --hover: #2E3B4C;
  --text: #FFFFFF;
  --dim: #D5D9D9;
  --faint: #AAB7B8;
  --teal: #FF9900;        /* the accent on navy is Amazon orange              */
  --amber: #FF9900;
  --green: #34d399;
  --blue: #60a5fa;
  --red: #f87171;
  --on-amber: #0F1111;
  --tab-border: #3A4553;
  --mark-bd: #FF9900;
  --teal-a40: #FF9900;
  --control-border: #7A8699;   /* 4.8 : 1 on the bar, 3.7 on a #232F3E button */
  /* the A2 mark in the usage pills / terminal tabs: 9.2 : 1 on the bar, 7.0 on #232F3E */
  --agent-fg: #C4B5FD;
  --agent-bg: #7c3aed33;
  --agent-bd: #A78BFA;
  color: var(--text);
}

/* ── the sun/moon toggle ─────────────────────────────────────────────────
   One button per page (two on /meetings, one per view), always visible: no
   responsive ladder may hide it. Both icons are in the markup and CSS shows
   the one for the CURRENT theme's destination — ☀ in dark ("switch to light"),
   ☾ in light — so it is right from the first frame, before theme.js runs. */
.mc-theme-btn { position: relative; flex: none; }
.mc-theme-btn svg { display: block; width: 18px; height: 18px; }
.mc-theme-btn .mc-moon { display: none; }
:root[data-theme="light"] .mc-theme-btn .mc-sun { display: none; }
:root[data-theme="light"] .mc-theme-btn .mc-moon { display: block; }
/* a ≥40px tap target without growing the 57px bar: the hit area reaches 4px
   past every edge — inside the bar's own padding vertically, and never further
   than the narrowest gap a ladder leaves beside it (4px), so it cannot reach a
   neighbouring button. The dashboard's 32px phone button is 40×40 this way. */
.mc-theme-btn::after { content: ''; position: absolute; inset: -4px; }
.mc-theme-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }

/* the login / approve / setup pages have no top bar: a corner button */
.mc-theme-corner {
  position: fixed; z-index: 20;
  top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px;
  width: 40px; height: 40px; border-radius: 10px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--dim);
  border: 1px solid var(--border); cursor: pointer;
}
.mc-theme-corner::after { inset: 0; }
