/* Light/dark theme for the free tools (CleanBites, ClearLab AI and its guides, Pill Identifier,
   Prescription Record). Loaded after each tool's own stylesheet by scripts/tools-theme.cjs.
   The tools share one base stylesheet, so the same tokens and fixes cover all of them.
   Printable sheets (medicine card, prescription record, pharmacist note) stay paper-white on purpose:
   they preview the PDF you save. Dark styles are screen-only, so printouts are always light. */

/* Light: the same AA-passing terracotta as the main site (links 4.6:1, white button text 5:1) */
:root {
  --accent: #ad5639;
  --accent-deep: #934229;
  color-scheme: light;
}

@media screen {
  [data-theme="dark"] {
    color-scheme: dark;
    --bg: #14110e;
    --bg-elev: #1c1814;
    --surface: #221d18;
    --ink: #f7f1e6;
    --ink-soft: #e0d7c9;
    --ink-muted: #b4a998;
    --line: #372f27;
    --line-strong: #4a4034;
    --accent: #e98a6a;
    --accent-deep: #f29071;
    --accent-ink: #f29071;
    --accent-soft: #3a2419;
    --mint: #2c3a2a;
    --mint-ink: #a7d2a9;
    --butter: #3b3420;
    --butter-ink: #e0c377;
    --rose: #3a2620;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 40px rgba(0, 0, 0, .45);
  }
  [data-theme="dark"] body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

  /* Text on the terracotta hover fill: dark, not white */
  [data-theme="dark"] .button-primary:hover,
  [data-theme="dark"] .header-action:hover { color: #14110e; }
  [data-theme="dark"] .skip-link { color: #14110e; }

  /* Warnings and errors */
  [data-theme="dark"] .upload-message.error { color: #f2b9a6; }
  [data-theme="dark"] .disclaimer,
  [data-theme="dark"] .note-warn { color: #f1dfae; background: #2e2716; border-color: #4d4122; }
  [data-theme="dark"] .note-warn p { color: #f1dfae; }
  [data-theme="dark"] .disclaimer strong { color: #fff4d6; }

  /* Pill Identifier: emergency box, swatches */
  [data-theme="dark"] .emergency { background: #3a1f19; border-color: #5c2e24; color: #f3d6cc; }
  [data-theme="dark"] .emergency svg { color: #f2b9a6; }
  [data-theme="dark"] .emergency strong { color: #fff1ec; }
  [data-theme="dark"] .emergency a { color: #ffb8a3; }
  [data-theme="dark"] .emergency.loud { outline-color: #f07a5f; }
  [data-theme="dark"] .swatch { border-color: rgba(255, 255, 255, .35); }

  /* Illustrations in the tools (strip diagram, sample images) toned down slightly */
  [data-theme="dark"] .strip-figure svg,
  [data-theme="dark"] .preview-img { filter: brightness(.92); }

  /* Sheets keep their paper look: everything inside uses the light colours, exactly as the saved PDF.
     A soft edge stops them glaring on the dark page. */
  [data-theme="dark"] .sheet {
    color-scheme: light;
    --bg: #f7f3ec; --bg-elev: #fdfbf6; --surface: #fff;
    --ink: #1a1714; --ink-soft: #3e3933; --ink-muted: #655e55;
    --line: #e6ddcf; --line-strong: #d6ccbb;
    --accent: #ad5639; --accent-deep: #934229; --accent-ink: #8d3d24; --accent-soft: #f4e2d8;
    --mint: #d8e6d5; --mint-ink: #2d5c3d; --butter: #f4e5b8; --butter-ink: #6b4e0f; --rose: #f0d4cb;
    color: #1a1714;
    border-color: #4a4034;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 50px rgba(0, 0, 0, .5);
  }
  [data-theme="dark"] .sheet img { filter: none; }
}

/* Theme toggle in the tool header: one icon for the current choice */
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm, 8px);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--ink-muted); }
.theme-toggle svg { width: 17px; height: 17px; display: none; }
.theme-toggle[data-mode="light"] .sun,
.theme-toggle[data-mode="dark"] .moon,
.theme-toggle[data-mode="system"] .auto,
.theme-toggle:not([data-mode]) .moon { display: block; }

/* Switching: pause transitions, then reveal the new theme from the button (see tool-theme.js) */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after { transition: none !important; }
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
html.theme-reveal::view-transition-new(root) { animation: nc-theme-reveal 420ms cubic-bezier(0.23, 1, 0.32, 1) both; }
@keyframes nc-theme-reveal {
  from { clip-path: circle(0 at var(--theme-x, 50%) var(--theme-y, 0)); }
  to { clip-path: circle(var(--theme-r, 150vmax) at var(--theme-x, 50%) var(--theme-y, 0)); }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
@media print { .theme-toggle { display: none !important; } }
