/* Dark theme. One job: everything that changes when <html> gets the `.dark` class.
   Nothing here runs unless the class is present, so the light theme is untouched.

   Strategy
   ────────
   1. Flip the design-token channels (--c-*). Because tailwind-config.js builds every
      colour utility from these, one flip re-skins text-ink, bg-canvas, border-line,
      stroke-line, bg-ink/10, hover:bg-ink/90, bg-canvas/80 … and every other variant at
      once — the single biggest guard against a stray light surface.
   2. Explicitly retint the utilities Tailwind builds from its OWN palette (bg-white, the
      arbitrary bg-[#…] greys, and the coloured -50/-100 status tints), which the tokens
      can't reach. Selectors are scoped under `html.dark` (specificity 0,1,1) so they beat
      the plain utility (0,1,0) but still LOSE to hover/focus variants (0,2,0) — hover
      states keep working. Matching hover variants are handled explicitly below.
   No `!important` anywhere: correct cascade, no surprises. */

html.dark {
  color-scheme: dark;              /* native inputs, scrollbars, date pickers render dark */

  --c-ink:      231 231 239;       /* foreground: near-white primary text/border/stroke */
  --c-inksoft:  203 203 214;       /* body text */
  --c-muted:    150 150 166;       /* secondary text */
  --c-track:    46 46 58;          /* neutral fills / progress tracks */
  --c-bar:      76 76 94;          /* accent borders / hover rings */
  --c-line:     43 43 54;          /* borders, dividers, SVG strokes */
  --c-canvas:   15 15 20;          /* page background (darkest layer) */

  --c-surface:  26 26 34;          /* elevated panels: cards, menus, inputs */
}

/* ── Elevated surfaces (`bg-white`) ─────────────────────────────────────────────────── */
html.dark .bg-white { background-color: rgb(var(--c-surface)); }
/* The lone `hover:bg-white/90` (a light chip) must not flash near-white. */
html.dark .hover\:bg-white\/90:hover { background-color: rgb(var(--c-surface) / 0.9); }

/* ── Arbitrary light-grey surfaces the views hard-code ──────────────────────────────── */
html.dark .bg-\[\#F1F1F3\],
html.dark .bg-\[\#f1f1f3\],
html.dark .bg-\[\#F4F4F6\],
html.dark .bg-\[\#F7F7FA\],
html.dark .bg-\[\#F8F8FA\],
html.dark .bg-\[\#F9F9FB\],
html.dark .bg-\[\#FAFAFB\],
html.dark .bg-\[\#FAFAFF\],
html.dark .bg-\[\#FCFCFD\] { background-color: rgb(35 35 44); }
html.dark .ring-\[\#F1F1F3\] { --tw-ring-color: rgb(43 43 54); }

/* The HOVER variants of those same greys — the case the note above warns about, found the hard way.
   The plain utility is retinted six lines up, but a `hover:bg-[#FAFAFB]` beats it on specificity, so
   the series slider's tiles turned WHITE under the cursor in dark mode and took their text with them.
   Slightly lighter than the resting surface, which is what a hover is meant to say. */
html.dark .hover\:bg-\[\#F1F1F3\]:hover,
html.dark .hover\:bg-\[\#F4F4F6\]:hover,
html.dark .hover\:bg-\[\#F7F7FA\]:hover,
html.dark .hover\:bg-\[\#F8F8FA\]:hover,
html.dark .hover\:bg-\[\#F9F9FB\]:hover,
html.dark .hover\:bg-\[\#FAFAFB\]:hover,
html.dark .hover\:bg-\[\#FAFAFF\]:hover,
html.dark .hover\:bg-\[\#FCFCFD\]:hover { background-color: rgb(45 45 56); }

/* ── Primary button (`bg-ink text-white`) → light pill with dark text ───────────────────
   bg-ink now resolves to near-white (token flipped), so the hard-coded `text-white` would
   vanish. Re-ink the text on those elements only; icons follow via currentColor. The
   `.bg-ink.text-white` rule (0,2,1) outranks `.text-white` (0,1,0). Tinted `bg-ink/10`
   chips are a different class and are intentionally left to the token (light @10%). */
html.dark .bg-ink { color: rgb(23 23 28); }
html.dark .bg-ink.text-white,
html.dark .bg-ink .text-white { color: rgb(23 23 28); }

/* Same hazard, hand-written CSS instead of utilities — and the rules above cannot reach it.
 *
 * A component stylesheet that paints `background: rgb(var(--c-ink))` and then hard-codes
 * `color: #fff` is making exactly the mistake the comment above describes: the token flips to
 * near-white here and the text does not, so the element goes white-on-white. The selected library
 * topic pill did precisely that — the tab you had chosen was the one you could not read.
 *
 * Anything that fills with --c-ink must re-ink its text here too. Grep for `var(--c-ink)` beside a
 * literal white before adding another. */
html.dark .lib-tab.active,
html.dark .plan-btn-save { color: rgb(23 23 28); }

/* The count inside the selected pill was white-on-white twice over: a white-tinted fill AND white
 * text. Both invert. */
html.dark .lib-tab.active .lib-tab-count {
  background: rgb(23 23 28 / 0.18);
  color: rgb(23 23 28);
}

/* ── Status tints: darken the -50/-100 backgrounds, lighten the -600/-700 text ──────────
   The solid -400/-500/-600 fills (badges, dots) stay as-is: they read well on dark. */
html.dark .bg-red-50,     html.dark .bg-red-100,
html.dark .hover\:bg-red-50:hover     { background-color: rgb(239 68 68 / 0.14); }
html.dark .bg-amber-50    { background-color: rgb(245 158 11 / 0.15); }
html.dark .bg-green-50,
html.dark .hover\:bg-green-50:hover   { background-color: rgb(34 197 94 / 0.15); }
html.dark .bg-emerald-50  { background-color: rgb(16 185 129 / 0.15); }
html.dark .bg-blue-50,    html.dark .bg-blue-100,
html.dark .bg-\[\#e8f0fe\] { background-color: rgb(59 130 246 / 0.15); }
html.dark .bg-indigo-50   { background-color: rgb(99 102 241 / 0.15); }
html.dark .bg-orange-50   { background-color: rgb(249 115 22 / 0.15); }
html.dark .bg-teal-50     { background-color: rgb(20 184 166 / 0.15); }
html.dark .bg-cyan-50     { background-color: rgb(6 182 212 / 0.15); }
html.dark .bg-slate-50    { background-color: rgb(148 163 184 / 0.12); }
html.dark .bg-gray-100    { background-color: rgb(35 35 44); }

html.dark .text-red-500,  html.dark .text-red-600,  html.dark .text-red-700   { color: rgb(243 165 165); }
html.dark .text-amber-500, html.dark .text-amber-600,
html.dark .text-amber-700, html.dark .text-amber-800 { color: rgb(241 194 122); }
html.dark .text-green-600, html.dark .text-green-700 { color: rgb(134 217 166); }
html.dark .text-emerald-600, html.dark .text-emerald-700 { color: rgb(111 220 176); }
html.dark .text-blue-600, html.dark .text-blue-700,
html.dark .text-\[\#1a4fa0\] { color: rgb(147 187 245); }
html.dark .text-indigo-500, html.dark .text-indigo-600 { color: rgb(169 170 245); }
html.dark .text-orange-700 { color: rgb(244 177 131); }
html.dark .text-teal-700   { color: rgb(111 216 200); }
html.dark .text-cyan-600   { color: rgb(127 211 230); }
html.dark .text-slate-500  { color: rgb(166 176 192); }

/* Tinted BORDERS (-200) are pastel lines made for white; on dark they glow. Same hue, low alpha, like
   the -50 backgrounds they frame. */
html.dark .border-red-200    { border-color: rgb(239 68 68 / 0.35); }
html.dark .border-amber-200  { border-color: rgb(245 158 11 / 0.35); }
html.dark .border-green-200  { border-color: rgb(34 197 94 / 0.35); }
html.dark .border-indigo-200 { border-color: rgb(99 102 241 / 0.40); }
html.dark .border-blue-200   { border-color: rgb(59 130 246 / 0.35); }

/* Red destructive rows keep their soft hover; light red-50 would flash bright. */
html.dark .hover\:bg-red-50:hover { background-color: rgb(239 68 68 / 0.14); }

/* ── Form controls & misc component polish ──────────────────────────────────────────── */
html.dark input::placeholder,
html.dark textarea::placeholder { color: rgb(var(--c-muted)); }

/* record.css hard-codes a light meter track. */
html.dark .rec-meter { background: rgb(var(--c-track)); }

/* Give elevated cards a hairline instead of the (now invisible) light shadow. */
html.dark .card { box-shadow: 0 0 0 1px rgb(255 255 255 / 0.04); }

/* ── Theme-toggle glyph: show moon in light, sun in dark ─────────────────────────────── */
.theme-toggle .icon-sun  { display: none; }
html.dark .theme-toggle .icon-sun  { display: block; }
html.dark .theme-toggle .icon-moon { display: none; }

/* ── Billing & plan surfaces ─────────────────────────────────────────────────────────── */

/* The plan editor's save button is `background: rgb(var(--c-ink))` with hard-coded white
   text — the same hazard as `bg-ink text-white` above, and it loses the same way once the
   token flips to near-white: white on white. Re-ink it, exactly like the primary button. */
html.dark .plan-btn-save { color: rgb(23 23 28); }

/* The billing views hard-code a green "good" and a red "bad" tint that Tailwind's own
   palette rules can't reach. Same treatment as the -50/-700 pairs: translucent fill,
   lightened text — otherwise these read as bright light panels punched into a dark page. */
html.dark .bg-\[\#EDF5F1\] { background-color: rgb(31 89 70 / 0.22); }
html.dark .text-\[\#1F5946\] { color: rgb(134 217 166); }
html.dark .border-\[\#BFE0D2\] { border-color: rgb(31 89 70 / 0.45); }

/* "Near the limit" — the amber pill on a meter card. */
html.dark .bg-\[\#FBF4E7\] { background-color: rgb(245 158 11 / 0.15); }
html.dark .text-\[\#7A5310\] { color: rgb(241 194 122); }

html.dark .bg-\[\#FBEFF2\] { background-color: rgb(163 50 75 / 0.22); }
html.dark .text-\[\#8C2438\] { color: rgb(243 165 165); }
html.dark .border-\[\#E8B4BF\] { border-color: rgb(163 50 75 / 0.45); }

/* "Saving this cuts a new version" — an amber panel, built from raw hex in billing.css so
   the token flip cannot reach it. */
html.dark .plan-warning {
  background: rgb(245 158 11 / 0.15);
  border-color: rgb(245 158 11 / 0.35);
  color: rgb(241 194 122);
}

/* The free-plan price sits on an elevated card, so the light theme's deep green goes
   nearly invisible against it. */
html.dark .plan-option-free { color: rgb(134 217 166); }

/* Read-only inputs (the plan code, once created) need to read as disabled against the
   dark surface rather than merely a shade off it. */
html.dark .plan-input:read-only { background: rgb(var(--c-canvas)); color: rgb(var(--c-muted)); }

/* Extra-quota status pills. Everything else in that feature is built from tokens and needs no
   restatement; only these three hues are raw hex, so only these three appear here. */
html.dark .quota-pill-pending  { background: rgb(245 158 11 / 0.15); color: rgb(241 194 122); }
html.dark .quota-pill-approved { background: rgb(31 89 70 / 0.25);   color: rgb(134 217 166); }
html.dark .quota-pill-rejected { background: rgb(163 50 75 / 0.22);  color: rgb(243 165 165); }
