/* ==========================================================================
   Atlas Foundry — SATaxCalc
   themes.css — light/dark mode variable overrides

   Only the theme-dependent tokens from Design Spec §1 are overridden here
   (surface-canvas, surface-card, text-primary, text-secondary,
   border-hairline). Accent colours (navy/teal/coral/gold) are identical in
   both themes per the spec and stay defined once in styles.css.

   Theme is toggled by setting data-theme="dark" on #app-root (see
   Settings screen, Milestone 10, and the toggle control, Milestone 4).
   ========================================================================== */

[data-theme="dark"] {
  --surface-canvas: #12141C;
  --surface-card: #1B1E29;
  --text-primary: #F5F6F8;
  --text-secondary: #9CA3AF;
  --border-hairline: #2A2E3B;

  /* Shadows read as too heavy on dark surfaces at the same opacity used for
     light mode — softened here rather than overriding shadow tokens
     unconditionally in styles.css. */
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.24), 0 4px 12px rgba(0, 0, 0, 0.28);
  --shadow-dialog: 0 8px 24px rgba(0, 0, 0, 0.48), 0 2px 6px rgba(0, 0, 0, 0.32);

  /* [V18 — Final Pre-Destruction Audit, F-017] --accent-teal-text
     (styles.css) is darkened for light-mode contrast against light
     surfaces — that darker value would under-contrast against these
     dark surfaces instead, so dark mode reverts to the base, brighter
     --accent-teal here. */
  --accent-teal-text: var(--accent-teal);

  /* The loss colour, same reasoning: the darkened coral is chosen for a light
     ground and under-contrasts on a dark one. */
  --accent-coral-text: var(--accent-coral);

  /* [V2.0 feedback, Finding 01] Base --accent-navy is effectively
     invisible against the dark card (1.15:1) — same reason
     --chart-series-blue exists in styles.css. Reuse that already
     contrast-checked blue for the elected-column outline. */
  /* [C-2, 8 September 2026] The chart series in dark. These are CHOSEN, not
     flipped — each was validated against the dark card (#1B1E29) in its own
     right. Before this, themes.css overrode no chart token at all, so one set
     of values was asked to work on a white card and a near-black one. */
  --chart-series-1: #5B93D9;
  --chart-series-2: #C9647F;
  --chart-series-3: #B8862C;
  --chart-series-4: #1FA79A;
  --chart-series-5: #8E76C4;

  /* The legacy aliases have to be re-declared HERE, not only in core.css.
     `var()` inside a custom property is substituted where that property is
     DECLARED — so an alias written once on :root freezes to the light value and
     stays light in dark mode, however the slot is overridden further down. That
     would have left --elected-border and the paid-vs-due swatches on a colour
     chosen for a white card while sitting on a near-black one. */
  --chart-series-blue: var(--chart-series-1);
  --chart-series-rose: var(--chart-series-2);
  --chart-series-purple: var(--chart-series-5);

  --elected-border: var(--chart-series-blue);
  --badge-teal-text: var(--accent-teal);

  /* [13 September 2026] Status ink on a dark ground: the base accents, which
     are bright enough to read on their own tint over the dark card and canvas.
     Worked out before choosing (tint composited over #1B1E29): teal 5.3:1,
     gold 6.1:1, coral 4.9:1, and coral as a plain link on the card 6.0:1.
     Re-measured with axe afterwards, not assumed. See core.css. */
  --status-positive-text: var(--accent-teal);
  --status-caution-text: var(--accent-gold);
  --status-attention-text: var(--accent-coral);
}

/* Respect the OS-level preference on first load, before the user has made
   an explicit choice. Settings/persistence (Milestone 7 & 10) is the
   source of truth once a preference is saved; this is only the zero-state
   fallback so first paint isn't jarring for dark-mode users. */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --surface-canvas: #12141C;
    --surface-card: #1B1E29;
    --text-primary: #F5F6F8;
    --text-secondary: #9CA3AF;
    --border-hairline: #2A2E3B;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.24), 0 4px 12px rgba(0, 0, 0, 0.28);
    --shadow-dialog: 0 8px 24px rgba(0, 0, 0, 0.48), 0 2px 6px rgba(0, 0, 0, 0.32);
    --accent-teal-text: var(--accent-teal);

  /* [V2.0 feedback, Finding 01] Base --accent-navy is effectively
     invisible against the dark card (1.15:1) — same reason
     --chart-series-blue exists in styles.css. Reuse that already
     contrast-checked blue for the elected-column outline. */
  /* [C-2, 8 September 2026] The chart series in dark. These are CHOSEN, not
     flipped — each was validated against the dark card (#1B1E29) in its own
     right. Before this, themes.css overrode no chart token at all, so one set
     of values was asked to work on a white card and a near-black one. */
  --chart-series-1: #5B93D9;
  --chart-series-2: #C9647F;
  --chart-series-3: #B8862C;
  --chart-series-4: #1FA79A;
  --chart-series-5: #8E76C4;

  /* The legacy aliases have to be re-declared HERE, not only in core.css.
     `var()` inside a custom property is substituted where that property is
     DECLARED — so an alias written once on :root freezes to the light value and
     stays light in dark mode, however the slot is overridden further down. That
     would have left --elected-border and the paid-vs-due swatches on a colour
     chosen for a white card while sitting on a near-black one. */
  --chart-series-blue: var(--chart-series-1);
  --chart-series-rose: var(--chart-series-2);
  --chart-series-purple: var(--chart-series-5);

  --elected-border: var(--chart-series-blue);
  --badge-teal-text: var(--accent-teal);

  /* [13 September 2026] Status ink, as in the explicit dark block above. */
  --status-positive-text: var(--accent-teal);
  --status-caution-text: var(--accent-gold);
  --status-attention-text: var(--accent-coral);
  }
}
