/* dark.css: class-based dark mode (body.dark-mode, set pre-paint by
 * theme-boot.js / theme-body.js). Dark mode IS the palette card's gradient:
 * green-700 at the top falling to green-950 at the bottom, a soft sage glow
 * from above, and glass panels floating on it.
 *
 * Almost everything flips through the token block below. The few component
 * rules after it exist only where a token flip can't express the change.
 * Load order: after every content sheet, before bottom-nav.css / mobile.css.
 */

/* ═══════════════════════ Anti-flash ═══════════════════════
   theme-boot.js adds .dark-mode-pending to <html> before the stylesheets
   load. The ground's base colour paints on that first render-blocking paint,
   so the page never flashes white while theme-body.js promotes the class. */
html.dark-mode-pending,
html:has(> body.dark-mode) {
  background: #0b2b26;
  color-scheme: dark;
}

/* Animate the flip only when the user toggles (the first theme is set before
   paint). prefers-reduced-motion is neutralised globally in tokens.css. */
body {
  transition: background-color var(--transition), color var(--transition);
}

/* ═══════════════════════ Token flip ═══════════════════════ */
body.dark-mode {
  color-scheme: dark;

  /* ground: the brand gradient */
  --ground: #0b2b26;
  --ground-art:
    radial-gradient(110% 55% at 50% 0%, rgb(var(--cyan-rgb) / 0.16), transparent 65%),
    radial-gradient(80% 50% at 100% 100%, rgb(35 83 71 / 0.35), transparent 62%),
    linear-gradient(180deg, #235347 0%, #163832 28%, #0b2b26 62%, #051f20 100%);

  /* glass */
  --glass: rgb(35 83 71 / 0.38);
  --glass-lit: linear-gradient(180deg, rgb(218 241 222 / 0.06), rgb(218 241 222 / 0) 45%);
  --glass-strong: #163832;
  --glass-edge: rgb(218 241 222 / 0.10);
  --glass-shadow: 0 1px 2px rgb(0 0 0 / 0.28), 0 12px 32px rgb(0 0 0 / 0.3);
  --scrim: rgb(2 12 12 / 0.6);

  /* text painted on the ground */
  --canvas-text: #daf1de;
  --canvas-text-muted: #a3bdae;
  --canvas-text-subtle: #8ca799;

  /* surfaces (solid: tables, inputs, menus) */
  --bg: var(--ground);
  --surface: #163832;
  --surface-2: #1f403a;
  --surface-3: #294842;
  --surface-raised: #1a3c36;
  --border: #2b5046;
  --border-strong: #3a6556;

  /* the page card: glass over the gradient, flat panels inside it */
  --page-card: var(--glass-lit), rgb(var(--storm-rgb) / 0.62);
  --page-card-edge: var(--glass-edge);
  --page-card-shadow: var(--glass-shadow);
  --page-panel: rgb(218 241 222 / 0.03);
  --page-rule: var(--brand-cyan);
  --page-badge: linear-gradient(135deg, var(--cyan-75) 0%, var(--brand-cyan) 100%);
  --page-badge-ink: var(--brand-storm);
  --table-head: rgb(218 241 222 / 0.07);
  --table-head-ink: var(--text);
  --table-head-edge: var(--border-strong);
  --field-soft: rgb(218 241 222 / 0.05);

  /* text: white over storm. Contrast on #1d353b: 13.0 · 7.6 · 5.7 */
  --text: #daf1de;
  --text-muted: #a3bdae;
  --text-subtle: #8ca799;
  --text-invert: #051f20;

  /* brand roles */
  --primary: #daf1de;
  --primary-hover: #ffffff;
  --primary-soft: rgb(var(--cyan-rgb) / 0.14);
  --accent: #8eb69b;
  --accent-light: #c6dacd;
  --link: #8eb69b;
  --link-hover: #daf1de;
  --focus: #8eb69b;
  --focus-ring: 0 0 0 3px rgb(var(--cyan-rgb) / 0.35);
  --highlight: #8eb69b;
  --highlight-ink: #051f20;

  /* actions: the primary glows cyan, like EUDR's lime button on dark */
  --action: #8eb69b;
  --action-ink: #051f20;
  --action-hover: #aac8b4;
  --action-glow: inset 0 1px 0 rgb(255 255 255 / 0.3), 0 8px 20px rgb(var(--cyan-rgb) / 0.22);
  --action-2: rgb(218 241 222 / 0.06);
  --action-2-ink: #daf1de;
  --action-2-edge: rgb(218 241 222 / 0.18);
  --action-2-hover: rgb(218 241 222 / 0.10);
  --danger-hover-bg: rgb(176 68 58 / 0.18);

  /* status (0.18 tint / light text / 0.45 edge) */
  --confirmed: #f1948a;      --confirmed-tint: rgb(176 68 58 / 0.18);  --confirmed-edge: rgb(176 68 58 / 0.45);
  --potential: #e8c076;      --potential-tint: rgb(154 107 0 / 0.2);   --potential-edge: rgb(154 107 0 / 0.45);
  --indeterminate: #b5c3c7;  --indeterminate-tint: rgb(255 255 255 / 0.07); --indeterminate-edge: rgb(255 255 255 / 0.18);
  --clear: #8fd3ae;          --clear-tint: rgb(31 122 77 / 0.2);       --clear-edge: rgb(31 122 77 / 0.45);
  --neutral-status: #a9b6ba; --neutral-tint: rgb(255 255 255 / 0.06);

  /* elevation: black-based */
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3), 0 1px 3px rgb(0 0 0 / 0.25);
  --shadow-md: 0 2px 6px rgb(0 0 0 / 0.25), 0 10px 24px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.5);
}

/* ═══════════════════════ Component rules ═══════════════════════ */

/* Toasts are solid status fills with white text in both themes: the status
   tokens above flip to light text tones, so the fills are pinned here. */
body.dark-mode .ct-toast { background: var(--storm-lift-3); color: #ffffff; }
body.dark-mode .ct-toast-error { background: #b0443a; }
body.dark-mode .ct-toast-success { background: #1f7a4d; }
body.dark-mode .ct-toast-info { background: var(--storm-lift-3); }

/* Native controls: draw UA glyphs (select chevron, number spinners, date
   picker icon) in the dark scheme so they stay visible. */
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  color-scheme: dark;
}

/* Tables: a gentle zebra + hover keeps the flat dark sheet scannable. */
body.dark-mode .ct-table tbody tr:nth-child(even) td {
  background: rgb(255 255 255 / 0.02);
}
body.dark-mode .ct-table tbody tr:hover td {
  background: rgb(255 255 255 / 0.05);
}

/* ═══════════════════════ Theme toggle icon (CSS only) ═══════════════════════
   Moon in light mode (click → dark), sun in dark mode (click → light). */
#themeToggle .icon-sun {
  display: none;
}
body.dark-mode #themeToggle .icon-sun {
  display: block;
}
body.dark-mode #themeToggle .icon-moon {
  display: none;
}
