/* ═══════════════════════════════════════════════════════════════════════════
 * The console, dark. Opt-in per browser: Theme at the foot of the sidebar
 * (theme.js) puts data-theme="dark" on <html>, and the one-line script at the
 * top of index.html puts it back before the first paint. Light stays the
 * default, and every rule in this file is behind that attribute, so a light
 * page is byte-for-byte what it was.
 *
 * NO SECOND DESIGN. These are MAGI's own dark values (magi/web/src/index.css,
 * prefers-color-scheme: dark), the half of the palette the console already
 * borrows for its rail. The rail itself does not change: it was always the
 * dark surface, and now the page meets it.
 *
 * Two parts:
 *   1. the tokens: the same names app.css declares, with dark values. That is
 *      almost all of it, because almost every colour in the console is a token.
 *   2. the exceptions: the rules that spell a colour out (a gold button with
 *      ink type, a syntax highlighter, a light tag on a light card), each
 *      given its dark value here rather than edited in place.
 *
 * Pages that stay light: the public ones (test links, status, cookbooks,
 * the share deck) never load this file. The campaign report inside the
 * console carries data-theme="light" because its charts are drawn in the
 * light palette (deck.py), so it sits on the dark page as a paper sheet. The
 * go-live and guest stages do too: they are dark scenes in both themes, lit
 * with the light palette's paper.
 * ═══════════════════════════════════════════════════════════════════════════ */

:root[data-theme="dark"] {
  color-scheme: dark;

  /* ── surfaces and ink · MAGI dark, value for value ── */
  --c-paper: #0d0d0c;
  --c-surface: #151513;
  --c-sunk: #1b1b18;
  --c-line: #272620;
  --c-line-strong: #3a3831;

  --c-ink: #f1efe9;            /* 16.9:1 on paper */
  --c-ink-2: #c4c0b6;          /* 10.1:1 on surface */
  --c-ink-3: #8b877d;          /*  5.1:1 on surface, 4.8:1 on sunk: text */
  --c-ink-4: #625f59;          /* decoration only, as in light */
  /* app.css asks for --c-ink-soft (the call player's labels) and falls back
   * to a light-only grey; here it is the ink it meant. */
  --c-ink-soft: var(--c-ink-3);

  --c-alarm: #ff8073;
  --c-alarm-ink: #ff9c91;      /* 8.7:1 on alarm-bg */
  --c-alarm-bg: #2b1310;
  --c-alarm-bg-hover: #361814;
  --c-alarm-line: rgba(255, 128, 115, 0.4);

  --c-open: #e5a83c;
  --c-open-ink: #f0bb5c;       /* 9.1:1 on open-bg */
  --c-open-bg: #2a2010;
  --c-open-line: rgba(229, 168, 60, 0.45);
  --c-open-hatch: rgba(229, 168, 60, 0.26);

  /* The brand green is the on-dark green the rail already uses. Following
   * --accent-on-dark rather than naming the hex keeps a brand skin's own
   * on-dark accent (Frequency's blue) without a rule of its own. */
  --accent: var(--accent-on-dark);
  --accent-bg: #11241a;
  --accent-line: #24513b;

  --c-scrim: rgba(0, 0, 0, 0.55);

  /* ── the Apple-grade layer, on dark ──
   * Fills are the on-dark ink at low alpha instead of the light ink, so a
   * track still reads as a tint of whatever it sits on. */
  --ui-fill: rgba(241, 239, 233, 0.07);
  --ui-fill-2: rgba(241, 239, 233, 0.05);
  --ui-fill-3: rgba(241, 239, 233, 0.13);
  --ui-sep: rgba(241, 239, 233, 0.08);
  --ui-edge: rgba(241, 239, 233, 0.16);
  --ui-edge-hover: rgba(241, 239, 233, 0.26);
  --ui-edge-focus: rgba(241, 239, 233, 0.38);
  --ui-glass: rgba(21, 21, 19, 0.86);
  /* THE SELECTION PILL. On paper it is a white pill lifted off a grey track.
   * On dark a shadow lifts nothing, so the pill is made lighter than its
   * track instead: the inset wash paints over the pill's own fill and under
   * its label. Every segmented control, tab strip and the open tool card get
   * it from this one token. */
  --ui-raise: 0 1px 2px rgba(0, 0, 0, 0.5), inset 0 0 0 0.5px rgba(241, 239, 233, 0.1),
              inset 0 0 0 999px rgba(241, 239, 233, 0.15);
  --ui-card: 0 0 0 1px rgba(241, 239, 233, 0.07), 0 1px 2px rgba(0, 0, 0, 0.3);
  --ui-float: 0 0 0 0.5px rgba(241, 239, 233, 0.12), 0 4px 12px rgba(0, 0, 0, 0.4),
              0 18px 44px rgba(0, 0, 0, 0.55);
  --ui-ring: 0 0 0 3.5px rgba(241, 239, 233, 0.12);
}

/* Frequency's accent tints, dark. Its blue for type and lines already comes
 * through --accent-on-dark (above); these are the fills behind it. */
:root[data-theme="dark"][data-brand="frequency"] {
  --accent-bg: #141b30;
  --accent-line: #2d3b66;
}

/* ══ the campaign report: a paper sheet on the dark page ══════════════════
 * The light palette comes from app.css's `:root, [data-theme="light"]` block;
 * the report's own names (--ink, --surface, --r-md …) still win on .ins
 * because /ui/insights.css loads after app.css, exactly as in light. */
:root[data-theme="dark"] .ins[data-theme="light"] {
  color-scheme: light;
  padding: 16px;
  border-radius: var(--ui-r-panel);
  background: var(--c-paper);
  /* The page strip's paper fade sits above the strip; clip, not hidden, so
   * the strip stays sticky to the page. */
  overflow: clip;
}
:root[data-theme="dark"] .ins[data-theme="light"]:empty { display: none; }

/* ══ exceptions: rules that spell a colour out ════════════════════════════ */

/* The cards that borrow the pill's lift (the test panel's cards, an open
 * tool) are cards, not selections: they keep the card edge, not the wash. */
:root[data-theme="dark"] :is(.rail .rail-card, .rail .pane, .tool-card.is-open) { box-shadow: var(--ui-card); }

/* Switches. On is an ink track; in dark the ink is light, so the knob that
 * rides on it turns dark instead of staying white. */
:root[data-theme="dark"] :is(.tool-summary > .tool-check input, #analysis-enabled, .workspace-switch input,
  .inbound-toggle input, .feature-switch input, .booking-check input):checked::before,
:root[data-theme="dark"] :is(.email-switch, .llm-switch) input:checked + span::after {
  background: var(--c-paper);
}
/* The featured (dark) plan card keeps its own on-dark switch. */
:root[data-theme="dark"] .bill-plan.is-t1 .workspace-switch input:checked::before { background: var(--c-dark); }

/* Gold and paper presses that sit on a surface which is dark in both themes:
 * their type stays dark, their fill stays light. */
/* Frequency paints this press Klein blue with white type: left alone. */
:root[data-theme="dark"]:not([data-brand="frequency"]) :is(.home-watch, .home-watch:hover) { color: var(--c-dark); }
:root[data-theme="dark"]:not([data-brand="frequency"]) .home-watch[data-guide-seen] { color: var(--c-on-dark); }
:root[data-theme="dark"] :is(.bill-cmp.is-featured :is(button.bill-upgrade-pay, a.bill-upgrade-talk), a.bill-connect-cta) {
  background: var(--c-on-dark); color: var(--c-dark); border-color: var(--c-on-dark);
}
@media (hover: hover) {
  :root[data-theme="dark"] :is(.bill-cmp.is-featured :is(button.bill-upgrade-pay, a.bill-upgrade-talk), a.bill-connect-cta):hover {
    background: #fff; border-color: #fff;
  }
}

/* Ink presses whose label was spelled as white or as on-dark ink. */
:root[data-theme="dark"] :is(.access-primary, .access-primary:hover, .access-go, .access-go:hover,
  .tour-end button) { color: var(--c-paper); }
:root[data-theme="dark"] .tour-play:hover { background: #fff; color: var(--c-paper); }
:root[data-theme="dark"] .tour-chap-n { color: var(--bill-gold); }

/* Fields whose edges were spelled out. */
:root[data-theme="dark"] :is(.tool-field input:hover, .tool-field textarea:hover, .tool-field select:hover) {
  border-color: var(--ui-edge-hover);
}
:root[data-theme="dark"] #numbers-sip-prefix-field[data-needed] input { border-color: rgba(241, 239, 233, 0.42); }

/* Admin: email states and the custom-pricing flag. */
:root[data-theme="dark"] .email-customer .email-unconfirmed p.email-unconfirmed-note { color: var(--c-open-ink); }
:root[data-theme="dark"] :is(.email-status[data-state=missing_email], .email-status[data-state=needs_review]) {
  color: var(--c-open-ink); background: rgba(229, 168, 60, 0.12);
}
:root[data-theme="dark"] :is(.email-status[data-state=sent], .email-status[data-state=production]) {
  color: #9cc58c; background: rgba(156, 197, 140, 0.1);
}
:root[data-theme="dark"] .cpadm-flag { color: var(--c-alarm-ink); }

/* Speech playground: the waveform well. */
:root[data-theme="dark"] .model-view #content :is(.tts-seek, #ttsempty) { background: var(--c-sunk); }

/* Agent Studio: the variable (green) and tool (blue) tags in the prompt, the
 * context legend, the logs and the flow. Same two hues, dark. */
:root[data-theme="dark"] :is(.prompt-reference-variable, .context-legend .legend-variable, .logs-part-variables) {
  background: #1f2617; color: #b9c98f; box-shadow: 0 0 0 1px #344026;
}
:root[data-theme="dark"] :is(.context-legend .legend-variable, .logs-part-variables) { box-shadow: none; }
:root[data-theme="dark"] :is(.prompt-reference-tool, .prompt-reference-result, .flow-transition-name,
  .var-bubble[aria-label*=" tool"] .vb-tag, .var-bubble .vb-tag[data-tone=tool], .context-legend .legend-tool,
  .logs-part-tools) {
  background: #18223a; color: #a3bce6; box-shadow: 0 0 0 1px #2b3c5e;
}
:root[data-theme="dark"] :is(.flow-transition-name, .var-bubble[aria-label*=" tool"] .vb-tag,
  .var-bubble .vb-tag[data-tone=tool], .context-legend .legend-tool, .logs-part-tools) { box-shadow: none; }
:root[data-theme="dark"] .flow-node-tool code { color: #a3bce6; }

/* The flow map: a dotted board of green-edged cards. */
:root[data-theme="dark"] .flow-map-viewport {
  background: radial-gradient(circle, #2e2d27 1px, transparent 1px) 0 0 / 18px 18px;
}
:root[data-theme="dark"] .flow-map-node { background: var(--c-surface); border-color: #36463b; }
:root[data-theme="dark"] :is(.flow-map-node:hover, .flow-map-node[aria-pressed=true]) {
  background: #14231a; border-color: #5f8b6d;
}
:root[data-theme="dark"] .flow-map-node:focus-visible { outline-color: #8fbf9f; }
:root[data-theme="dark"] :is(.flow-map-node small, .flow-transition-detail) { color: #8fb09a; }
:root[data-theme="dark"] .flow-edge-label { fill: #8fb09a; stroke: var(--c-paper); }

/* Cookbooks inside the console: the note, the live badge, and GitHub's own
 * dark syntax colours for the light ones the code blocks use. */
:root[data-theme="dark"] .cb-doc .cb-note { border-color: #23395a; background: #111b2b; color: #a9c7ef; }
:root[data-theme="dark"] .cb-doc .cb-note code { border-color: #23395a; background: rgba(241, 239, 233, 0.06); }
:root[data-theme="dark"] :is(.cb-sh-cmd, .cb-tok-kw) { color: #ff7b72; }
:root[data-theme="dark"] :is(.cb-sh-flag, .cb-tok-num) { color: #79c0ff; }
:root[data-theme="dark"] :is(.cb-sh-string, .cb-tok-string) { color: #a5d6ff; }
:root[data-theme="dark"] .cb-sh-var { color: #ffa657; }
:root[data-theme="dark"] :is(.cb-sh-comment, .cb-tok-comment) { color: #8b949e; }
:root[data-theme="dark"] .cb-tok-fn { color: #d2a8ff; }
:root[data-theme="dark"] .cb-live { background: #12261a; color: #6fdd8b; }
:root[data-theme="dark"] .cb-key.ready + .dev-cmd { border-color: #2f6b45; box-shadow: 0 0 0 3px rgba(79, 192, 138, 0.12); }
