/* ============================================================
   Pool Chemistry Calculator — "sunny backyard pool" theme
   ============================================================ */

:root {
  color-scheme: light;
  /* Water + sun palette */
  --water-deep: #0077b6;
  --water-mid: #00b4d8;
  --water-light: #90e0ef;
  --water-pale: #caf0f8;

  --ink: #053b54;
  /* Text colors darkened just enough to meet WCAG AA (4.5:1) on the white
     card and pale field/inset backgrounds — same hues, slightly deeper. */
  --muted: #4e7389;
  --accent: #0077b6;
  --accent-dark: #0077b6;
  --border: #bde7f2;
  --card: #ffffff;

  /* Status colors (playful). --raise and --sun are darkened slightly from
     their original hues to clear WCAG AA (4.5:1 text / 3:1 non-text) against
     their -bg tints and the surrounding card/page surfaces. */
  --good: #07775c;
  --good-bg: #d7f5ec;
  --raise: #0070ac;
  --raise-bg: #d6f1fb;
  --lower: #c22852;
  --lower-bg: #fde3ea;
  --sun: #b88300;
  --sun-bg: #fff3d6;
  /* Separate, darker token for actual warning *text* set on --sun-bg — --sun
     itself only needs to clear the lighter 3:1 bar used for borders/swatches,
     but text needs the full 4.5:1. Passes in every light theme; overridden to
     the bright --sun value in Midnight where --sun-bg is dark. */
  --sun-text: #8a6300;
  --sun-text-hover: #6f4d00;

  --shadow: 0 8px 24px rgba(0, 119, 182, 0.16);
  --shadow-sm: 0 3px 10px rgba(0, 119, 182, 0.12);
  --radius: 14px;

  /* Themable surfaces (overridden per theme below). Kept as variables so the
     header, page background, form fields and bottom dock recolor with the
     palette instead of being hard-coded. */
  --header-bg: linear-gradient(165deg, #00b4d8 0%, #0096c7 45%, #0077b6 100%);
  --page-bg-far: #eafaff;
  --field-bg: #f5fcff;
  --dock-bg: rgba(255, 255, 255, 0.92);
  --dock-shadow: 0 -6px 22px rgba(0, 119, 182, 0.18);
  /* Inset / secondary surfaces (panels, table zebra, button fills, modal). */
  --inset: #f5fcff;
  --inset-2: #eafaff;
  --modal-bg: linear-gradient(180deg, #f2fbff 0%, #e4f6fd 100%);

  --font-fun: "Fredoka", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ============================================================
   Themes — each overrides the palette variables above. The base :root is the
   "Sunny" (light) theme; "Auto" resolves to Sunny or Midnight from the system
   preference (handled in JS, which sets data-theme before first paint).
   ============================================================ */

/* Midnight — dark mode. */
[data-theme="midnight"] {
  color-scheme: dark;
  --water-deep: #0a3349;
  --water-mid: #15526e;
  --water-light: #0e2f43;
  --water-pale: #0a2030;
  --ink: #e7f3fa;
  --muted: #93b3c6;
  --accent: #38bdf0;
  --accent-dark: #1f9fd1;
  --border: #1d4156;
  --card: #0f2a3b;
  --good: #2ad1a3;  --good-bg: #0d3a31;
  --raise: #46b6e6; --raise-bg: #0d3346;
  --lower: #ff6f8c; --lower-bg: #3e1a23;
  --sun: #ffc233;   --sun-bg: #3a2f12;
  /* --sun-bg is dark here, so warning text needs the bright --sun tone
     instead of the dark-mode-default --sun-text (which assumes a light bg). */
  --sun-text: #ffc233;
  --sun-text-hover: #ffd769;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.45);
  --header-bg: linear-gradient(165deg, #0c3a52 0%, #082a3d 55%, #051d2b 100%);
  --page-bg-far: #050f17;
  --field-bg: #0c2433;
  --dock-bg: rgba(12, 32, 45, 0.92);
  --dock-shadow: 0 -6px 22px rgba(0, 0, 0, 0.55);
  --inset: #12303f;
  --inset-2: #0c2433;
  --modal-bg: linear-gradient(180deg, #103043 0%, #0c2433 100%);
}
/* The page background's "sun glints" are white in light themes; swap them for
   subtle blue glows so dark mode doesn't show white blooms. */
[data-theme="midnight"] body {
  background-color: #081722;
  background-image:
    radial-gradient(circle at 18% 12%, rgba(120, 200, 230, 0.08) 0, rgba(120, 200, 230, 0) 18%),
    radial-gradient(circle at 82% 30%, rgba(120, 200, 230, 0.06) 0, rgba(120, 200, 230, 0) 16%),
    radial-gradient(circle at 50% 80%, rgba(21, 82, 110, 0.45) 0, rgba(21, 82, 110, 0) 30%),
    linear-gradient(180deg, var(--water-light) 0%, var(--water-pale) 320px, var(--page-bg-far) 100%);
}
/* --inset-2 is a dark surface tone in Midnight, unlike the other (light)
   themes — the header tagline needs its own light color here instead. */
[data-theme="midnight"] .tagline { color: rgba(255, 255, 255, 0.85); }

/* Lagoon — bright tropical teal/green mood (light). */
[data-theme="lagoon"] {
  --water-deep: #0c8577;
  --water-mid: #16b5a0;
  --water-light: #9bead9;
  --water-pale: #d8f7ef;
  --ink: #06403a;
  /* Darkened from the original hues to clear WCAG AA against --card and the
     pale surface tokens below (re-derived numerically for this palette). */
  --muted: #42776e;
  --accent: #10a594;
  --accent-dark: #0b7c6f;
  --border: #bdebe0;
  --card: #ffffff;
  --good: #057954;  --good-bg: #d2f3e6;
  --raise: #0c776b; --raise-bg: #d3f2ec;
  --lower: #d0123f; --lower-bg: #fde3ea;
  --sun: #b98000;   --sun-bg: #fdf0d2;
  --header-bg: linear-gradient(165deg, #16b5a0 0%, #0c9b88 45%, #0c8577 100%);
  --page-bg-far: #e9fbf6;
  --field-bg: #f1fdfa;
  --dock-bg: rgba(255, 255, 255, 0.92);
  --shadow: 0 8px 24px rgba(12, 133, 119, 0.16);
  --shadow-sm: 0 3px 10px rgba(12, 133, 119, 0.12);
  --dock-shadow: 0 -6px 22px rgba(12, 133, 119, 0.18);
  --inset: #f0fdf9;
  --inset-2: #ddf7ef;
  --modal-bg: linear-gradient(180deg, #f0fdf9 0%, #dcf7ef 100%);
}

/* Sunset — warm coral / dusk mood (light). */
[data-theme="sunset"] {
  --water-deep: #c1466b;
  --water-mid: #f3722c;
  --water-light: #ffcaa0;
  --water-pale: #ffe9d6;
  --ink: #4a2235;
  /* Darkened from the original hues to clear WCAG AA against --card and the
     pale surface tokens below (re-derived numerically for this palette). */
  --muted: #8c6064;
  --accent: #f3722c;
  --accent-dark: #b74715;
  --border: #f6d4c2;
  --card: #fff8f3;
  --good: #20776c;  --good-bg: #d9f0ec;
  --raise: #bd3b1a; --raise-bg: #fce4dc;
  --lower: #c41f40; --lower-bg: #fbdce2;
  --sun: #b77f00;   --sun-bg: #fdeecb;
  --header-bg: linear-gradient(165deg, #ff9e6d 0%, #f3722c 45%, #c1466b 100%);
  --page-bg-far: #fff1e6;
  --field-bg: #fff6ee;
  --dock-bg: rgba(255, 248, 243, 0.92);
  --shadow: 0 8px 24px rgba(193, 70, 107, 0.16);
  --shadow-sm: 0 3px 10px rgba(193, 70, 107, 0.12);
  --dock-shadow: 0 -6px 22px rgba(193, 70, 107, 0.18);
  --inset: #fff6ef;
  --inset-2: #ffe9d8;
  --modal-bg: linear-gradient(180deg, #fff6ef 0%, #ffe7d6 100%);
}

* { box-sizing: border-box; }

/* ---- Accessibility helpers ---- */

/* Screen-reader-only content (e.g. the live announcement region). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* "Skip to content" link — off-screen until it receives keyboard focus.
   Uses :focus (not :focus-visible): the link can only be reached with the
   keyboard, and appearing instantly is more dependable than a transition. */
.skip-link {
  position: fixed;
  top: -6rem;
  left: 1rem;
  z-index: 300;
  padding: 0.65rem 1.2rem;
  border-radius: 0 0 12px 12px;
  background: var(--card);
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.skip-link:focus {
  top: 0;
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
/* The skip link targets <main> — don't draw a ring on the page itself. */
main:focus { outline: none; }

/* Consistent, theme-aware focus ring on every interactive control. More
   specific per-component rings (tabs, dials, theme toggle…) override this. */
button:focus-visible,
a:focus-visible,
label[role="button"]:focus-visible,
input[type="radio"]:focus-visible,
input[type="checkbox"]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  /* Leave room for the fixed bottom navigation dock. */
  padding-bottom: 5.5rem;
  background-color: var(--water-pale);
  /* layered "pool water" caustics + gentle gradient */
  background-image:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.55) 0, rgba(255, 255, 255, 0) 18%),
    radial-gradient(circle at 82% 30%, rgba(255, 255, 255, 0.4) 0, rgba(255, 255, 255, 0) 16%),
    radial-gradient(circle at 50% 80%, rgba(144, 224, 239, 0.45) 0, rgba(144, 224, 239, 0) 30%),
    linear-gradient(180deg, var(--water-light) 0%, var(--water-pale) 320px, var(--page-bg-far) 100%);
  background-attachment: fixed;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3,
.primary-btn, .secondary-btn,
.chart-card .chart-title,
.rec h3 {
  font-family: var(--font-fun);
  letter-spacing: 0.2px;
}

/* Base type scale — a fallback for any heading that doesn't set its own
   size; more specific rules (.site-header h1, .card h2, .modal h2, …) still
   win via specificity and may intentionally sit a touch larger/smaller. */
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

/* ---- Header ---- */
.site-header {
  position: relative;
  text-align: center;
  padding: 2.4rem 1rem 3.2rem;
  background: var(--header-bg);
  color: #fff;
  overflow: hidden;
}
.header-inner { position: relative; z-index: 2; }
.site-header h1 {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(0, 73, 112, 0.25);
}
/* Inline (not flex) so the mark wraps with the title text on narrow screens
   exactly like the emoji it replaced, instead of pinning to one side. */
.logo-mark {
  width: 1.4rem;
  height: 1.4rem;
  vertical-align: -0.2em;
  margin-right: 0.3rem;
  color: #fff;
  filter: drop-shadow(0 2px 0 rgba(0, 73, 112, 0.25));
}
.tagline {
  margin: 0.5rem 0 0;
  color: var(--inset-2);
  font-weight: 500;
}

/* wave divider that melts the header into the page — kept static (no drift
   animation) so the header reads as calm chrome, not a decoration. */
.header-wave {
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  line-height: 0;
  z-index: 2;
}
.header-wave svg {
  width: 110%;
  margin-left: -5%;
  height: 70px;
  display: block;
}
.header-wave path { fill: var(--water-pale); }

/* ---- Theme switcher (quick toggle, top-right over the header) ---- */
/* Sits outside <header> so the header's overflow:hidden doesn't clip the menu;
   absolutely positioned so it scrolls away with the header. */
.theme-switch {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  z-index: 60;
}
/* Language toggle (EN / ES) sits just left of the theme switcher. */
.lang-switch {
  position: absolute;
  top: 0.9rem;
  right: 3.9rem;
  z-index: 60;
}
.lang-toggle {
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.02em;
}
.theme-toggle {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  line-height: 1;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  cursor: pointer;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.15s;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.36); transform: scale(1.06); }
.theme-toggle:focus-visible { outline: 3px solid rgba(255, 255, 255, 0.75); outline-offset: 2px; }
.theme-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 172px;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  padding: 0.4rem;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.theme-menu.hidden { display: none; }
.theme-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.92rem;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
}
.theme-option:hover { background: rgba(128, 128, 128, 0.14); }
.theme-option[aria-checked="true"] { background: var(--raise-bg); font-weight: 700; }
.theme-option .theme-ic { font-size: 1.1rem; width: 1.4rem; text-align: center; }
.theme-option .theme-check { margin-left: auto; color: var(--accent); font-weight: 700; }
.theme-option .theme-check::after { content: "✓"; }
.theme-option[aria-checked="false"] .theme-check::after { content: ""; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 1rem 2rem;
}

/* ---- App tab bar (static bottom navigation) ---- */
/* Always pinned to the bottom of the screen. On wider screens it's a centered
   floating dock that matches the 720px content width; on phones it spans the
   full width (see the small-screen override below). */
.tab-bar {
  position: fixed;
  left: 50%;
  bottom: 0.6rem;
  transform: translateX(-50%);
  width: calc(100% - 2rem);
  max-width: 720px;
  z-index: 50;
  display: flex;
  gap: 0.3rem;
  padding: 0.3rem;
  background: var(--dock-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--dock-shadow);
}
.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  background: none;
  border-radius: 9px;
  padding: 0.6rem 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--accent-dark); }
.tab[aria-selected="true"] {
  background: var(--accent);
  color: #fff;
}
.tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(2, 136, 209, 0.3);
}
.tab .tab-icon {
  display: inline-flex;
  color: inherit;
}
.tab .tab-icon svg {
  width: 1.05rem;
  height: 1.05rem;
  stroke: currentColor;
  display: block;
}
/* On phones the five tabs can't share one row as inline icon+label, so the
   bottom bar spans the full width edge-to-edge with the icon stacked over the
   label — every tab stays visible and thumb-reachable. */
@media (max-width: 600px) {
  .tab-bar {
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    width: auto;
    max-width: none;
    margin: 0;
    gap: 0;
    padding: 0.2rem 0.2rem calc(0.2rem + env(safe-area-inset-bottom, 0px));
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border);
    background: var(--dock-bg);
    box-shadow: 0 -6px 18px rgba(0, 119, 182, 0.16);
    z-index: 60;
  }
  .tab {
    position: relative;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.4rem 0.15rem;
    font-size: 0.68rem;
    border-radius: 12px;
  }
  .tab .tab-icon svg { width: 1.3rem; height: 1.3rem; }
  /* Active tab uses colour + a soft tint (not a full pill) so the small
     stacked label stays legible. */
  .tab[aria-selected="true"] {
    background: var(--raise-bg);
    color: var(--accent-dark);
  }
  /* The History count badge rides the corner of the icon in stacked layout. */
  .tab .tab-badge {
    position: absolute;
    top: 0.2rem;
    left: calc(50% + 0.35rem);
    min-width: 1.05rem;
    line-height: 1.05rem;
    font-size: 0.62rem;
  }
  .tab[aria-selected="true"] .tab-badge { background: var(--accent); color: #fff; }
  /* Keep page content and footer clear of the fixed bar. */
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  /* Lift the floating "Take a tour" button clear of the bottom bar. */
  .tour-fab { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}
.tab-badge {
  min-width: 1.3rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.3rem;
  text-align: center;
}
.tab[aria-selected="true"] .tab-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.tab-badge.pop { animation: badgePop 0.45s ease; }
@keyframes badgePop {
  0% { transform: scale(1); }
  40% { transform: scale(1.45); }
  70% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

/* ---- Tab panel enter transition ---- */
.panel-enter { animation: panelIn 0.24s ease-out both; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---- Cards with pool-tile top trim ---- */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem;
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.card::before {
  /* glossy pool-tile mosaic strip */
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 8px;
  background:
    repeating-linear-gradient(90deg, #00b4d8 0 18px, #48cae4 18px 36px);
  opacity: 0.9;
}
.card h2 {
  margin: 0.2rem 0 1rem;
  font-size: 1.25rem;
  color: var(--accent-dark);
}

.helper-intro {
  margin: -0.4rem 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }

label,
legend {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.92rem;
  color: var(--ink);
}

/* Emoji marker before a field label or group heading. */
.field-icon {
  margin-right: 0.15rem;
  font-size: 1.05em;
}

/* Card heading row with trailing controls (e.g. the voice-entry mic). */
.section-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.section-head h2 { margin: 0; }

/* ---- Voice entry (mic button + live status) ---- */
.voice-btn {
  width: 2.5rem;
  height: 2.5rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--field-bg);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background 0.15s ease;
}
.voice-btn:hover { transform: scale(1.06); border-color: var(--water-mid); }
.voice-btn[aria-pressed="true"] {
  border-color: var(--lower);
  background: var(--lower-bg);
  animation: micPulse 1.6s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(194, 40, 82, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(194, 40, 82, 0); }
}
.voice-status {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

/* Heading that groups related fields (e.g. the chlorine readings). */
.group-heading {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  margin: 0 0 0.6rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}

input[type="number"],
select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--field-bg);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--water-mid);
  box-shadow: 0 0 0 4px rgba(0, 180, 216, 0.18);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}
@media (max-width: 480px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.type-field {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem;
  margin-top: 0.5rem;
  background: var(--inset);
}
.radio {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  margin-right: 1.2rem;
  cursor: pointer;
}
.radio input { width: auto; accent-color: var(--water-mid); }

/* ---- Thermometer temperature slider ---- */
.temp-field { margin-top: 0.5rem; }
.thermo {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.thermo-icon {
  font-size: 1.5rem;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15));
}

/* The track is a cold→warm gradient, so the slider itself reads as temperature */
.thermo input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  width: 100%;
  height: 14px;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  background: linear-gradient(90deg,
    #4fc3f7 0%,
    #4dd0e1 22%,
    #81c784 42%,
    #fff176 60%,
    #ffb74d 78%,
    #e57373 90%,
    #e53935 100%);
}
.thermo input[type="range"]:focus {
  outline: none;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), 0 0 0 3px rgba(2, 136, 209, 0.18);
}

/* Thumb — a glassy "bulb" of mercury */
.thermo input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, #ffd9d9 35%, #e53935 100%);
}
.thermo input[type="range"]::-moz-range-track {
  height: 14px;
  border-radius: 999px;
  background: transparent;
}
.thermo input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, #ffd9d9 35%, #e53935 100%);
}

/* Live readout bubble — its colour is tinted cool→warm in JS */
.thermo-readout {
  min-width: 3.6rem;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.3rem 0.5rem;
  border-radius: 9px;
  background: var(--inset);
  border: 1px solid var(--border);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.link-btn {
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--accent-dark);
  cursor: pointer;
  padding: 0.4rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--water-mid); }

.volume-helper {
  border: 2px dashed var(--water-light);
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: var(--inset);
}
.vh-result {
  margin: 0.75rem 0 0;
  font-weight: 600;
  color: var(--good);
  min-height: 1.2em;
}

/* ---- Buttons ---- */
.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

button.primary-btn,
button.secondary-btn,
a.primary-btn,
a.secondary-btn,
label.secondary-btn {
  cursor: pointer;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 1.02rem;
  font-weight: 600;
  padding: 0.75rem 1.6rem;
  border: 2px solid transparent;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease, filter 0.15s ease;
}
/* Anchors/labels styled as buttons need explicit inline-block + no underline. */
a.primary-btn,
a.secondary-btn,
label.secondary-btn {
  text-align: center;
  text-decoration: none;
}
.primary-btn {
  background: linear-gradient(180deg, var(--water-mid) 0%, var(--accent-dark) 100%);
  color: #fff;
  flex: 1;
  min-width: 180px;
  box-shadow: var(--shadow-sm);
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); filter: brightness(1.05); }
.primary-btn:active {
  transform: translateY(1px);
  box-shadow: var(--shadow-sm);
  filter: brightness(0.97);
}
.secondary-btn {
  background: var(--card);
  color: var(--accent-dark);
  border-color: var(--water-light);
  box-shadow: var(--shadow-sm);
}
.secondary-btn:hover { background: var(--inset-2); border-color: var(--water-mid); transform: translateY(-1px); }
.secondary-btn:active { transform: translateY(1px); }

/* ---- Cloud Backup card ---- */
.cloud-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 0.5rem;
}
.cloud-actions .primary-btn,
.cloud-actions .secondary-btn { flex: 0 1 auto; min-width: 0; }
.cloud-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.1rem 0;
}
.cloud-offer {
  background: var(--inset-2);
  border: 1px solid var(--water-light);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.cloud-msg { margin-top: 0.6rem; font-weight: 600; color: var(--accent-dark); }
.cloud-msg.is-error { color: #c0392b; }

/* ---- Results ---- */
.results {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem;
  margin-top: 0.5rem;
  overflow: hidden;
}
.results::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 8px;
  background: repeating-linear-gradient(90deg, #00b4d8 0 18px, #48cae4 18px 36px);
}
.results h2 {
  margin: 0.2rem 0 1rem;
  color: var(--accent-dark);
}

/* ---- Result entrance + celebration animations ---- */
.action-plan,
.rec,
.all-good-banner {
  animation: recIn 0.34s ease-out both;
}
@keyframes recIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

.all-good-banner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--good-bg) 0%, #c9f3e5 100%);
  border: 1px solid #9fe6cf;
  color: var(--good);
  font-family: var(--font-fun);
  font-weight: 600;
  font-size: 1.02rem;
}
.all-good-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  flex: none;
  border-radius: 50%;
  background: var(--good);
  color: #fff;
  font-size: 1rem;
  animation: checkPop 0.5s 0.1s ease both;
}
@keyframes checkPop {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* one-shot droplet shower over the results card */
.celebrate-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}
.droplet {
  position: absolute;
  top: -1.5rem;
  will-change: transform, opacity;
  animation: dropFall 1.7s ease-in forwards;
}
@keyframes dropFall {
  0%   { transform: translateY(0) rotate(0); opacity: 0; }
  12%  { opacity: 1; }
  100% { transform: translateY(180px) rotate(22deg); opacity: 0; }
}

/* ---- Ordered action plan ---- */
.action-plan {
  border: 2px solid var(--water-light);
  background: var(--modal-bg);
  border-radius: 14px;
  padding: 0.9rem 1.1rem 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.action-plan h3 {
  margin: 0 0 0.5rem;
  font-size: 1.06rem;
  color: var(--accent-dark);
}
.action-plan ol {
  margin: 0 0 0.6rem;
  padding-left: 1.3rem;
}
.action-plan li {
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}
.plan-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0.08em 0.5em;
  border-radius: 999px;
  margin-right: 0.35rem;
  vertical-align: middle;
}
.plan-tag.raise { background: var(--raise-bg); color: var(--accent-dark); }
.plan-tag.lower { background: var(--lower-bg); color: var(--lower); }
.plan-note { color: var(--muted); font-size: 0.85rem; }
.plan-safety {
  margin: 0;
  font-size: 0.85rem;
  color: var(--sun-text);
  background: var(--sun-bg);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
}

.rec {
  border: 1px solid var(--border);
  border-left-width: 6px;
  border-radius: 14px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.85rem;
  box-shadow: var(--shadow-sm);
}
.rec:last-of-type { margin-bottom: 0; }
.rec h3 {
  margin: 0 0 0.25rem;
  font-size: 1.06rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}
.rec .reading {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}
.rec .action { margin: 0.25rem 0 0; font-size: 0.96rem; }

/* "Buy on Amazon" affiliate call-to-action on a recommendation. */
.buy-row { margin: 0.6rem 0 0; }
.buy-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: linear-gradient(180deg, #ffd460 0%, #ffb703 100%);
  color: #3a2e05;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid #e0a000;
  box-shadow: 0 2px 0 #d49600;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.buy-link:hover { transform: translateY(-1px); box-shadow: 0 3px 0 #d49600; }
.buy-link:active { transform: translateY(2px); box-shadow: 0 0 0 #d49600; }

.affiliate-disclosure {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}

/* ---- Buy tab shopping guide ---- */
.buy-cat h3 {
  margin: 0.2rem 0 0.5rem;
  font-size: 1.15rem;
  color: var(--accent-dark);
}
.buy-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}
.buy-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border);
}
.buy-item:last-child { border-bottom: none; padding-bottom: 0; }
.buy-item-text { display: flex; flex-direction: column; }
.buy-name { font-weight: 600; font-size: 0.96rem; }
.buy-note { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }
.buy-item .buy-link { flex-shrink: 0; }
.rec .dose {
  font-weight: 700;
  font-size: 1.06rem;
  color: var(--accent-dark);
  background: var(--water-pale);
  padding: 0.05em 0.4em;
  border-radius: 7px;
}
.rec.raise { border-left-color: var(--raise); background: var(--raise-bg); }
.rec.raise h3 { color: var(--accent-dark); }
.rec.lower { border-left-color: var(--lower); background: var(--lower-bg); }
.rec.lower h3 { color: var(--lower); }
.rec.lower .dose { color: var(--lower); background: var(--lower-bg); }
.rec.good { border-left-color: var(--good); background: var(--good-bg); }
.rec.good h3 { color: var(--good); }
.rec.note { border-left-color: var(--sun); background: var(--sun-bg); }
.rec.note h3 { color: var(--sun-text); }
.rec.note .dose { color: var(--ink); background: var(--sun-bg); }
.rec.lsigood { border-left-color: var(--good); background: var(--good-bg); }
.rec.lsigood h3 { color: var(--good); }
.rec.lsibad { border-left-color: #e85d04; background: var(--sun-bg); }
.rec.lsibad h3 { color: var(--sun-text); }

/* result heading emoji cues */
.rec.raise h3 span:first-child::before { content: "⬆️ "; }
.rec.lower h3 span:first-child::before { content: "⬇️ "; }
.rec.good h3 span:first-child::before { content: "✅ "; }
.rec.note h3 span:first-child::before { content: "🧂 "; }
.rec.lsigood h3 span:first-child::before { content: "⚖️ "; }
.rec.lsibad h3 span:first-child::before { content: "⚖️ "; }

.disclaimer {
  margin: 1.25rem 0 0;
  padding: 0.95rem 1.1rem;
  background: var(--sun-bg);
  border: 2px solid #ffe09a;
  border-radius: 14px;
  font-size: 0.86rem;
  color: var(--sun-text);
}

.site-footer {
  text-align: center;
  color: var(--accent-dark);
  font-size: 0.82rem;
  padding: 1.2rem;
  font-weight: 500;
}
#install-btn { margin-bottom: 0.8rem; }

/* ---- Setup modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 50, 76, 0.6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.5rem 1rem;
  overflow-y: auto;
  z-index: 100;
}
.modal {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(2, 50, 76, 0.45);
  padding: 1.6rem;
  width: 100%;
  max-width: 520px;
  margin: auto;
  overflow: hidden;
}
.modal::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 8px;
  background: repeating-linear-gradient(90deg, #00b4d8 0 18px, #48cae4 18px 36px);
}
.modal h2 {
  margin: 0.2rem 0 0.5rem;
  color: var(--accent-dark);
  font-size: 1.25rem;
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.modal-actions .primary-btn { flex: 1; min-width: 0; }
.setup-error {
  color: var(--lower);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
  min-height: 1.1em;
}

/* ---- Saved-pool banner ---- */
.pool-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: linear-gradient(180deg, var(--card) 0%, var(--inset-2) 100%);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 0.7rem 1.2rem;
  margin-bottom: 1.25rem;
  font-weight: 600;
  color: var(--accent-dark);
  box-shadow: var(--shadow-sm);
}
.pool-banner #pool-banner-text::before { content: "🏊 "; }
.pool-banner .link-btn { padding: 0; }
.banner-actions { display: inline-flex; gap: 1rem; white-space: nowrap; }

/* ---- Test reminder banner ---- */
.reminder-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  flex-wrap: wrap;
  background: var(--sun-bg);
  border: 2px solid #ffd874;
  border-radius: 16px;
  padding: 0.7rem 1.1rem;
  margin-bottom: 1rem;
  font-weight: 600;
  color: var(--sun-text);
  box-shadow: var(--shadow-sm);
}
.reminder-actions { display: inline-flex; gap: 0.9rem; flex-wrap: wrap; }
.reminder-actions .link-btn { padding: 0; color: var(--sun-text); }
.reminder-actions .link-btn:hover { color: var(--sun-text-hover); }

/* ---- Push notification opt-in (revealed only when the server supports it) ---- */
.push-toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: 600;
  cursor: pointer;
}
.push-toggle input { width: auto; margin-top: 0.2rem; accent-color: var(--good); }

/* ---- Range hint under each input ---- */
.range-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
.range-hint::before { content: "🎯 "; }

/* ---- Range-aware reading inputs (circular dial with centred number) ---- */
.input-row {
  position: relative;
  display: flex;
  justify-content: center;
}
/* The reading is typed directly into the centre of the dial, overlaid on the
   SVG, so the value isn't duplicated in a separate box below. */
.input-row .param-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -62%);
  width: 5rem;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  text-align: center;
  font-family: var(--font-fun);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}
.input-row .param-number::placeholder { color: var(--muted); opacity: 0.6; }
.input-row .param-number:focus { outline: none; box-shadow: none; }
/* …but keyboard focus on the centre input still gets a visible ring. */
.input-row .param-number:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
/* Hide native number spinners so the value stays clean and centred. */
.input-row .param-number::-webkit-outer-spin-button,
.input-row .param-number::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-row .param-number { -moz-appearance: textfield; appearance: textfield; }

.dial {
  width: 210px;
  max-width: 100%;
}
.dial-svg {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  touch-action: none; /* let us drag the thumb without scrolling the page */
  border-radius: 50%;
  outline: none;
}
.dial-svg:focus-visible {
  box-shadow: 0 0 0 4px rgba(0, 180, 216, 0.25);
}

.dial-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 11;
  stroke-linecap: round;
}
/* Acceptable range on the outer ring — a wider, lighter arc behind the ideal
   band, marking the "still fine" zone. */
.dial-acceptable {
  fill: none;
  stroke: var(--good);
  stroke-width: 6;
  stroke-linecap: round;
  opacity: 0.3;
}
/* Ideal range on the outer ring — a clear green arc marking the target zone. */
.dial-ideal {
  fill: none;
  stroke: var(--good);
  stroke-width: 6;
  stroke-linecap: round;
  opacity: 0.95;
}
.dial-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 11;
  stroke-linecap: round;
  transition: stroke 0.15s;
}
.dial-thumb {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 4;
  filter: drop-shadow(0 1px 2px rgba(2, 40, 60, 0.35));
  transition: stroke 0.15s;
}
.dial-unit {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
/* Scale endpoints (min / max) printed on the dial itself. */
.dial-end {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
/* Ideal range min/max, sitting at the two ends of the green outer ring. */
.dial-ideal-end {
  fill: var(--good);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
/* Acceptable range min/max, at the ends of the wider band — lighter + smaller
   so they read as the looser "still fine" bounds. */
.dial-acceptable-end {
  fill: var(--good);
  opacity: 0.6;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* Status colouring driven by the field's ideal-range class. */
.validity-hint {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 1.05em;
  text-align: center;
}
.validity-hint.good { color: var(--good); }
.validity-hint.low,
.validity-hint.high { color: var(--raise); }
.validity-hint.invalid { color: var(--lower); }

/* The centred value takes on the field's status color. */
.reading-field.status-good .param-number { color: var(--good); }
.reading-field.status-low .param-number,
.reading-field.status-high .param-number { color: var(--raise); }
.reading-field.status-invalid .param-number { color: var(--lower); }

.reading-field.status-good .dial-progress { stroke: var(--good); }
.reading-field.status-good .dial-thumb { stroke: var(--good); }
.reading-field.status-low .dial-progress,
.reading-field.status-high .dial-progress { stroke: var(--raise); }
.reading-field.status-low .dial-thumb,
.reading-field.status-high .dial-thumb { stroke: var(--raise); }
.reading-field.status-invalid .dial-progress { stroke: var(--lower); }
.reading-field.status-invalid .dial-thumb { stroke: var(--lower); }

/* ---- Linear slider reading inputs (FC / TC) ---- */
/* The slider's active colour follows the field's status (accent by default). */
.slider-field { --slider-color: var(--accent); }
.slider-field.status-good { --slider-color: var(--good); }
.slider-field.status-low,
.slider-field.status-high { --slider-color: var(--raise); }
.slider-field.status-invalid { --slider-color: var(--lower); }

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.slider-row .param-number {
  width: 4.6rem;
  text-align: center;
  font-weight: 600;
  flex: none;
}

/* The track wrap stacks the base track, ideal band and fill behind a
   transparent native range input that supplies the draggable thumb. */
.slider-track-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 26px;
  display: flex;
  align-items: center;
}
.slider-base,
.slider-acceptable,
.slider-ideal,
.slider-fill {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 8px;
  border-radius: 999px;
  pointer-events: none;
}
.slider-base {
  left: 0;
  right: 0;
  background: var(--border);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12);
}
/* Wider, lighter "acceptable" band behind the stronger ideal band. */
.slider-acceptable {
  background: var(--good);
  opacity: 0.18;
}
.slider-ideal {
  background: var(--good);
  opacity: 0.32;
}
.slider-fill {
  left: 0;
  width: 0;
  background: var(--slider-color);
  transition: width 0.05s linear, background 0.15s;
}

.param-slider {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  z-index: 1;
  width: 100%;
  height: 26px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}
.param-slider:focus { outline: none; }
.param-slider::-webkit-slider-runnable-track {
  height: 8px;
  background: transparent;
  border-radius: 999px;
}
.param-slider::-moz-range-track {
  height: 8px;
  background: transparent;
  border-radius: 999px;
}
.param-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -7px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--slider-color);
  box-shadow: 0 1px 3px rgba(2, 40, 60, 0.35);
  cursor: pointer;
  transition: background 0.15s;
}
.param-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--slider-color);
  box-shadow: 0 1px 3px rgba(2, 40, 60, 0.35);
  cursor: pointer;
  transition: background 0.15s;
}
.param-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 1px 3px rgba(2, 40, 60, 0.35), 0 0 0 4px rgba(0, 180, 216, 0.25);
}
.param-slider:focus-visible::-moz-range-thumb {
  box-shadow: 0 1px 3px rgba(2, 40, 60, 0.35), 0 0 0 4px rgba(0, 180, 216, 0.25);
}

/* When no value is entered yet, mute the thumb so it doesn't imply a reading. */
.slider-field.slider-empty .param-slider::-webkit-slider-thumb { background: var(--muted); opacity: 0.55; }
.slider-field.slider-empty .param-slider::-moz-range-thumb { background: var(--muted); opacity: 0.55; }

/* Scale endpoints + ideal label beneath the track. */
.slider-scale {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 0.2rem;
  padding-right: 5.3rem; /* keep the scale under the track, not the number box */
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}
.slider-range-labels {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
}
.slider-ideal-label {
  color: var(--good);
  font-weight: 700;
}
.slider-acceptable-label {
  color: var(--good);
  opacity: 0.65;
  font-weight: 600;
}

/* ---- Save reading confirmation ---- */
.save-confirm {
  margin: 0.6rem 0 0;
  color: var(--good);
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 1.1em;
}

/* ---- History & Trends ---- */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.history-header h2 { margin: 0.2rem 0; }

.history-empty {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0.75rem 0 0;
}

/* ---- Trend insights / alerts ---- */
.insights {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.9rem 0 0.4rem;
}
.insight {
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 5px solid;
}
.insight::before { margin-right: 0.35rem; }
.insight.warn { background: var(--sun-bg); border-color: var(--sun); color: var(--sun-text); }
.insight.warn::before { content: "📈"; }
.insight.info { background: var(--raise-bg); border-color: var(--raise); color: var(--accent-dark); }
.insight.info::before { content: "ℹ️"; }
.insight.good { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.insight.good::before { content: "🎉"; }

/* Legend for the history graphs: what the two shaded bands and the coloured
   data points mean. Swatches mirror the fills used in sparklineSVG(). */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 1rem 0 -0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.chart-legend .lg {
  display: inline-flex;
  align-items: center;
}
.chart-legend .lg::before {
  content: "";
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  margin-right: 0.35rem;
}
.chart-legend .lg-ideal::before  { background: rgba(46, 125, 50, 0.35); border: 1px solid rgba(46, 125, 50, 0.55); }
.chart-legend .lg-accept::before { background: rgba(199, 125, 0, 0.28); border: 1px solid rgba(199, 125, 0, 0.5); }
.chart-legend .lg-out::before    { background: #d84315; }

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1rem 0 0.5rem;
}
@media (max-width: 540px) {
  .chart-grid { grid-template-columns: 1fr; }
}

.chart-card {
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 0.9rem 0.55rem;
  background: linear-gradient(180deg, var(--inset) 0%, var(--inset-2) 100%);
}
.chart-card .chart-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--accent-dark);
  margin-bottom: 0.25rem;
}
.chart-card .chart-latest {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.chart-card svg { width: 100%; height: auto; display: block; }

.history-table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
  border-radius: 12px;
  border: 2px solid var(--border);
}
table.history-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}
.history-table th,
.history-table td {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.7rem;
  text-align: right;
  white-space: nowrap;
}
.history-table th:first-child,
.history-table td:first-child { text-align: left; }
.history-table thead th {
  color: var(--accent-dark);
  font-weight: 700;
  background: var(--water-pale);
  border-bottom: 2px solid var(--border);
}
.history-table tbody tr:nth-child(even) { background: var(--inset); }
.history-table td.out { color: var(--lower); font-weight: 700; }
.history-table td.in  { color: var(--good); }
.history-table .row-actions {
  white-space: nowrap;
}
.history-table .del-btn,
.history-table .rec-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
}
.history-table .del-btn { color: var(--lower); }
.history-table .del-btn:hover,
.history-table .rec-btn:hover { transform: scale(1.2); }

/* ---- "Recommendations from a saved reading" note ---- */
.results-context {
  margin: -0.4rem 0 1rem;
  padding: 0.5rem 0.8rem;
  background: var(--raise-bg);
  border-left: 4px solid var(--raise);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-dark);
}

/* ---- pH phenol-red dial caption ---- */
/* Phenol red ("PR") is the reagent in pool pH test kits: yellow at low pH,
   through red in the ideal range, to purple at high pH. The pH dial is tinted
   along that scale (see phColor in app.js); this caption names the colors. */
.ph-caption {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.ph-key {
  font-weight: 700;
  padding: 0 0.15rem;
  border-radius: 4px;
}
.ph-key-low { color: #9a7a08; }
.ph-key-mid { color: #c62828; }
.ph-key-high { color: #7a2768; }

/* ---- Home tab ---- */
.home-hero .home-cta {
  flex: none;
  width: 100%;
  margin-top: 0.5rem;
}

/* ---- Weather-aware care ---- */
.weather-card .weather-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.weather-card .weather-head h2 { margin: 0; }
.weather-actions { display: inline-flex; gap: 0.6rem; flex-wrap: wrap; }
.weather-actions .link-btn { padding: 0; }

.weather-privacy {
  margin: 0.85rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}
.weather-privacy a { color: var(--accent-dark); }
.weather-error {
  margin: 0.6rem 0 0;
  color: var(--lower);
  font-weight: 600;
  font-size: 0.85rem;
}

.weather-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.weather-search input {
  flex: 1;
  min-width: 7rem;
  width: auto;
}
.weather-or { color: var(--muted); font-size: 0.85rem; }

.weather-loc {
  margin: 0.1rem 0 0.9rem;
  font-weight: 600;
  color: var(--accent-dark);
  font-size: 0.9rem;
}
.weather-now {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  background: var(--raise-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.weather-now-emoji { font-size: 1.8rem; line-height: 1; }
.weather-now-temp {
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--ink);
}
.weather-now-label { color: var(--muted); font-weight: 600; font-size: 0.9rem; }

.weather-advice { display: flex; flex-direction: column; gap: 0.6rem; }
.weather-nudge {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  background: var(--inset);
}
.weather-nudge .nudge-icon { font-size: 1.3rem; line-height: 1.4; flex: none; }
.weather-nudge .nudge-text strong { display: block; font-size: 0.95rem; color: var(--ink); }
.weather-nudge .nudge-text p { margin: 0.15rem 0 0; font-size: 0.88rem; color: var(--muted); }

/* ---- Diagnose: troubleshooting wizard ---- */
.dx-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-top: 1rem;
}
@media (max-width: 480px) { .dx-grid { grid-template-columns: 1fr; } }

.dx-card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-align: left;
  padding: 0.85rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--inset);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.dx-card:hover { border-color: var(--water-mid); box-shadow: var(--shadow-sm); }
.dx-card:active { transform: scale(0.99); }
.dx-card:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(0, 180, 216, 0.3); }
.dx-card-icon { font-size: 1.7rem; line-height: 1; flex: none; }
.dx-card-text { display: flex; flex-direction: column; }
.dx-card-text strong { color: var(--ink); font-size: 0.98rem; }
.dx-card-text span { color: var(--muted); font-size: 0.82rem; }

.dx-flow-head {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}
.dx-flow-head .link-btn { align-self: flex-start; padding: 0; }
.dx-flow-head h2 { margin: 0; }

.dx-intro { margin: 0.4rem 0 1rem; color: var(--ink); }
.dx-chem-note {
  margin: 0 0 1rem;
  padding: 0.6rem 0.8rem;
  background: var(--raise-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--accent-dark);
}
.dx-chem-note .link-btn { font-size: 0.85rem; padding: 0; }

.dx-steps { list-style: none; margin: 0; padding: 0; counter-reset: none; }
.dx-step {
  display: flex;
  gap: 0.75rem;
  padding: 0.9rem 0;
  border-top: 1px solid var(--border);
}
.dx-step:first-child { border-top: none; padding-top: 0.3rem; }
.dx-step-n {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 0.9rem;
}
.dx-step-body { flex: 1; min-width: 0; }
.dx-step-body h4 {
  margin: 0.15rem 0 0.3rem;
  font-size: 1rem;
  color: var(--accent-dark);
}
.dx-step-body p { margin: 0.3rem 0 0; }
.dx-checks { margin: 0.4rem 0 0; padding-left: 1.1rem; }
.dx-checks li { margin-bottom: 0.25rem; }

.dx-leads {
  margin: 0 0 1rem;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border);
  border-left: 5px solid var(--sun);
  border-radius: 10px;
  background: var(--sun-bg);
}
.dx-leads h4 { margin: 0 0 0.4rem; color: #8a6d00; font-size: 0.95rem; }
.dx-leads-list { margin: 0; padding-left: 1.1rem; }
.dx-leads-list li { margin-bottom: 0.4rem; }
.dx-leads-list li:last-child { margin-bottom: 0; }

.dx-question {
  margin: 1rem 0;
  padding: 0.9rem 1rem;
  border: 2px dashed var(--water-light);
  border-radius: 12px;
  background: var(--inset);
}
.dx-q { margin: 0 0 0.6rem; font-weight: 600; color: var(--ink); }
.dx-choices { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.dx-choice {
  cursor: pointer;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.dx-choice:hover { border-color: var(--water-mid); }
.dx-choice.chosen { background: var(--accent); color: #fff; border-color: var(--accent); }

.dx-resolved {
  margin: 1rem 0;
  padding: 0.7rem 0.9rem;
  background: var(--good-bg);
  border: 1px solid #9fe6cf;
  border-radius: 10px;
  color: var(--good);
  font-weight: 500;
}

.dx-safety {
  margin: 1rem 0 0;
  padding: 0.75rem 0.9rem;
  background: var(--sun-bg);
  border: 1px solid #f2dca6;
  border-radius: 10px;
  font-size: 0.85rem;
  color: #7a5b12;
}

.dx-inline-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent-dark);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.dx-flow .buy-link { margin-top: 0.4rem; }

/* ---- "I added this" button + dose log ---- */
.added-row { margin: 0.6rem 0 0; }
.added-btn {
  cursor: pointer;
  border: 1px solid var(--good);
  background: var(--card);
  color: var(--good);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.added-btn:hover { background: var(--good-bg); }
.added-btn.logged {
  background: var(--good);
  color: #fff;
  cursor: default;
  border-color: var(--good);
}
.added-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(6, 167, 125, 0.3); }

.dose-list { list-style: none; margin: 0; padding: 0; }
.dose-entry {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
}
.dose-entry:first-child { border-top: none; }
.dose-arrow {
  flex: none;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 0.15rem;
}
.dose-arrow.raise { color: var(--raise); }
.dose-arrow.lower { color: var(--lower); }
.dose-entry-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dose-entry-body strong { font-size: 0.92rem; color: var(--ink); }
.dose-meta { font-size: 0.83rem; color: var(--accent-dark); }
.dose-time { font-size: 0.78rem; color: var(--muted); margin-top: 0.1rem; }

/* Predicted vs. actual */
.dose-outcome {
  margin-top: 0.15rem;
  font-size: 0.8rem;
  font-weight: 600;
}
.dose-outcome.good { color: var(--good); }
.dose-outcome.off { color: var(--accent-dark); }
.dose-outcome.miss { color: var(--lower); }
.dose-outcome.pending { color: var(--muted); font-weight: 500; }

.dose-insight {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 12px;
  background: var(--raise-bg);
}
.dose-insight.good { border-left-color: var(--good); background: var(--good-bg); }
.dose-insight.miss { border-left-color: var(--lower); background: var(--lower-bg); }
.dose-insight h3 { margin: 0 0 0.35rem; font-size: 1rem; color: var(--accent-dark); }
.dose-insight p { margin: 0.25rem 0 0; font-size: 0.9rem; }
.dose-insight-note { color: var(--muted); font-size: 0.82rem !important; }
.dose-entry .del-btn {
  flex: none;
  background: none;
  border: none;
  color: var(--lower);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.2rem;
}

/* ---- LSI water-balance gauge ---- */
.lsi-gauge-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0.5rem 0 0.25rem;
}
.lsi-gauge { width: 100%; max-width: 340px; height: auto; display: block; }
.lsi-gauge .lsi-tick { fill: var(--muted); font-size: 9px; font-weight: 600; }
.lsi-gauge .lsi-end { fill: var(--muted); font-size: 8.5px; text-transform: uppercase; letter-spacing: 0.3px; }
.lsi-gauge .lsi-val { font-family: var(--font-fun); font-size: 13px; font-weight: 700; }
.lsi-verdict {
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 0.1rem;
}

/* ---- Combined chlorine live insight ---- */
.cc-insight {
  margin: 0.4rem 0 0;
  padding: 0.5rem 0.7rem;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 500;
  border: 1px solid var(--border);
}
.cc-insight.cc-good { color: var(--good); background: var(--good-bg); border-color: #9fe6cf; }
.cc-insight.cc-high { color: var(--sun-text); background: var(--sun-bg); border-color: #f2dca6; }
.cc-insight.cc-warn { color: var(--lower); background: var(--lower-bg); border-color: #f3b8c4; }

/* ---- Chlorine breakdown bar (Total = Free + Combined) ---- */
.chlorine-block { grid-column: 1 / -1; }
.chl-entry {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1rem;
}
.chl-input { margin: 0; }
@media (max-width: 520px) {
  .chl-entry { grid-template-columns: 1fr; }
}

.chl-bar { margin-top: 0.9rem; }
.chl-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
}
.chl-bar:not(.chl-empty) .chl-hint { margin-top: 0.5rem; text-align: left; }
.chl-hint.chl-warn { color: var(--lower); font-weight: 600; }

.chl-track {
  position: relative;
  height: 32px;
  border-radius: 9px;
  background: var(--border);
  overflow: hidden;
}
.chl-acceptable {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  background: rgba(6, 167, 125, 0.06);
}
.chl-ideal {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  background: rgba(6, 167, 125, 0.12);
  border-left: 2px dashed var(--good);
  border-right: 2px dashed var(--good);
}
.chl-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  transition: width 0.25s ease, left 0.25s ease;
}
.chl-free { background: var(--good); border-radius: 9px 0 0 9px; }
.chl-combined { background: var(--sun); }
.chl-combined.is-high { background: var(--lower); }
.chl-unknown {
  background: repeating-linear-gradient(45deg, #aacfe0, #aacfe0 7px, #bfe0ee 7px, #bfe0ee 14px);
  border-radius: 9px 0 0 9px;
}
.chl-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 3px;
  margin-left: -1.5px;
  z-index: 3;
  background: var(--ink);
  border-radius: 2px;
}
.chl-tick.chl-tick-warn { background: var(--lower); }

.chl-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-top: 0.55rem;
  font-size: 0.82rem;
  font-weight: 600;
}
.chl-key { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--ink); }
.chl-key i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.chl-key.free i { background: var(--good); }
.chl-key.combined i { background: var(--sun); }
.chl-key.combined.is-high i { background: var(--lower); }
.chl-key.total i { width: 4px; height: 14px; border-radius: 2px; background: var(--ink); }

.chl-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---- Export & share ---- */
.export-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.export-bar .secondary-btn { padding: 0.55rem 1rem; font-size: 0.9rem; }
.export-msg { font-size: 0.85rem; font-weight: 600; color: var(--good); }

/* Print-only report (hidden on screen) */
#print-report { display: none; }

@media print {
  /* Hide the live app, show only the report. */
  body * { visibility: hidden; }
  #print-report, #print-report * { visibility: visible; }
  #print-report {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }
  .pr-doc {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: #000;
    padding: 0.5rem 0.75rem;
  }
  .pr-doc h1 { font-size: 20px; margin: 0 0 2px; }
  .pr-doc h2 { font-size: 15px; margin: 16px 0 6px; }
  .pr-sub { color: #444; margin: 0 0 10px; font-size: 12px; }
  .pr-pool { font-size: 13px; margin: 0 0 4px; }
  .pr-table { width: 100%; border-collapse: collapse; margin-top: 4px; }
  .pr-table th, .pr-table td {
    border: 1px solid #999;
    padding: 4px 8px;
    text-align: left;
    font-size: 12px;
  }
  .pr-table th { background: #eee; }
  .pr-actions { font-size: 12.5px; padding-left: 18px; }
  .pr-actions li { margin-bottom: 6px; }
  .pr-ok { font-size: 13px; }
  .pr-foot { margin-top: 16px; font-size: 10.5px; color: #555; border-top: 1px solid #ccc; padding-top: 6px; }
}

/* ---- Logbook: inventory & cost ---- */
.lb-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  background: var(--raise-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.lb-summary span { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.lb-summary strong { font-family: var(--font-fun); font-size: 1.3rem; color: var(--accent-dark); }
.lb-note { font-size: 0.85rem; color: var(--muted); margin: 0 0 1rem; }

.lb-cheap {
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid #9fe6cf;
  border-left: 5px solid var(--good);
  border-radius: 12px;
  background: var(--good-bg);
}
.lb-cheap h3 { margin: 0 0 0.4rem; font-size: 1rem; color: var(--good); }
.lb-cheap p { margin: 0.2rem 0; font-size: 0.9rem; }
.lb-best { font-size: 1rem !important; }
.lb-short, .lb-rank li { color: var(--lower); }
.lb-rank { margin: 0.4rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; }
.lb-rank li { color: var(--ink); margin-bottom: 0.15rem; }
.lb-perppm { color: var(--muted); }

.lb-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.lb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
}
.lb-item:first-child { border-top: none; }
.lb-item-body { display: flex; flex-direction: column; min-width: 0; }
.lb-item-body strong { font-size: 0.92rem; color: var(--ink); }
.lb-item-meta { font-size: 0.82rem; color: var(--muted); }
.lb-item-actions { display: inline-flex; align-items: center; gap: 0.5rem; flex: none; }
.lb-item-actions .link-btn { padding: 0; }
.lb-item-actions .del-btn {
  background: none; border: none; color: var(--lower);
  cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 0.2rem;
}

.lb-form {
  border-top: 2px solid var(--border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}
.lb-form h3 { margin: 0 0 0.75rem; font-size: 1.05rem; color: var(--accent-dark); }
.lb-form .actions { margin-top: 0.5rem; }

/* ---- Seasonal & maintenance checklists ---- */
.cl-seg { margin: 0.25rem 0 1rem; }
.cl-due-banner, .cl-ok-banner {
  margin: 0 0 0.85rem;
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.88rem;
}
.cl-due-banner { background: var(--sun-bg); border: 1px solid #f2dca6; color: var(--sun-text); }
.cl-ok-banner { background: var(--good-bg); border: 1px solid #9fe6cf; color: var(--good); }

.cl-list { list-style: none; margin: 0; padding: 0; }
.cl-routine {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.7rem 0;
  border-top: 1px solid var(--border);
}
.cl-routine:first-child { border-top: none; }
.cl-routine.cl-overdue { border-left: 4px solid var(--lower); padding-left: 0.6rem; }
.cl-routine-body { display: flex; flex-direction: column; min-width: 0; }
.cl-routine-body strong { font-size: 0.92rem; color: var(--ink); }
.cl-status { font-size: 0.8rem; color: var(--muted); }
.cl-overdue-txt { color: var(--lower); font-weight: 700; }
.cl-due-txt { color: #c77700; font-weight: 700; }
.cl-ok-txt { color: var(--good); font-weight: 600; }
.cl-done-btn { flex: none; padding: 0.45rem 0.8rem; font-size: 0.85rem; }

.cl-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--accent-dark);
  font-size: 0.9rem;
}
.cl-progress .link-btn { padding: 0; }
.cl-check { padding: 0.5rem 0; border-top: 1px solid var(--border); }
.cl-check:first-child { border-top: none; }
.cl-check label { display: flex; align-items: flex-start; gap: 0.5rem; font-weight: 500; cursor: pointer; }
.cl-check input { width: auto; margin-top: 0.2rem; accent-color: var(--good); }
.cl-check.checked span { color: var(--muted); text-decoration: line-through; }

.cl-cell {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 2px solid var(--border);
}
.cl-cell input[type="date"] {
  width: auto;
  padding: 0.5rem 0.7rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--inset);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cl-cell input[type="date"]:focus {
  outline: none;
  border-color: var(--water-mid);
  box-shadow: 0 0 0 4px rgba(0, 180, 216, 0.18);
}
.cl-cell-status { margin: 0.5rem 0 0; font-size: 0.9rem; }

/* ---- Balanced streak & badges ---- */
.streak-head h2 { margin: 0 0 0.75rem; color: var(--accent-dark); }
.streak-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
@media (max-width: 480px) { .streak-stats { grid-template-columns: repeat(2, 1fr); } }
.streak-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0.6rem 0.4rem;
  background: var(--raise-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.streak-num { font-family: var(--font-fun); font-weight: 700; font-size: 1.4rem; color: var(--accent-dark); }
.streak-lbl { font-size: 0.74rem; color: var(--muted); font-weight: 600; }
.streak-nudge {
  margin: 0 0 1rem;
  padding: 0.55rem 0.8rem;
  background: var(--good-bg);
  border: 1px solid #9fe6cf;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--good);
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}
@media (max-width: 480px) { .badge-grid { grid-template-columns: repeat(2, 1fr); } }
.badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.15rem;
  padding: 0.7rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--inset);
}
.badge.locked { opacity: 0.55; filter: grayscale(0.6); }
.badge.earned { border-color: var(--sun); background: var(--sun-bg); }
.badge-icon { font-size: 1.6rem; line-height: 1; }
.badge-name { font-weight: 700; font-size: 0.8rem; color: var(--ink); }
.badge-desc { font-size: 0.7rem; color: var(--muted); line-height: 1.25; }

/* ---- Adaptive calibration ---- */
.cal-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-dark);
  cursor: pointer;
  margin: 0;
}
.cal-toggle input { width: auto; accent-color: var(--accent); }
.cal-note { color: var(--muted); font-size: 0.88rem; margin: 0.25rem 0 0; }
.cal-list { list-style: none; margin: 0.5rem 0 0.75rem; padding: 0; }
.cal-item {
  padding: 0.6rem 0;
  border-top: 1px solid var(--border);
}
.cal-item:first-child { border-top: none; }
.cal-item strong { font-size: 0.92rem; color: var(--ink); }
.cal-detail { display: block; font-size: 0.82rem; color: var(--muted); margin-top: 0.1rem; }
.cal-more { color: var(--raise); font-weight: 700; }
.cal-less { color: var(--good); font-weight: 700; }
.cal-even { color: var(--muted); font-weight: 700; }
.cal-foot { font-size: 0.8rem; color: var(--muted); margin: 0.25rem 0 0.6rem; }
#cal-reset { padding: 0; }

/* Inline "tuned for your pool" tag on calibrated recommendations */
.cal-tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-dark);
  background: var(--raise-bg);
  border-radius: 6px;
  padding: 0.05rem 0.35rem;
  white-space: nowrap;
}

.hidden { display: none !important; }

/* ============================================================
   Guided walkthrough (spotlight tour)
   ============================================================ */

/* Floating "Take a tour" button */
.tour-fab {
  position: fixed;
  right: 1rem;
  /* Sit clear of the fixed bottom navigation dock. */
  bottom: 6.5rem;
  z-index: 90;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, var(--water-mid) 0%, var(--accent-dark) 100%);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tour-fab:hover { transform: translateY(-2px) scale(1.05); }
.tour-fab:active { transform: translateY(0) scale(0.97); }

/* Tour overlay */
.tour { position: fixed; inset: 0; z-index: 1000; }

/* Click-catcher: blocks the page while the tour is running */
.tour-backdrop {
  position: absolute;
  inset: 0;
  background: transparent;
  cursor: pointer;
}
/* Centered (no-target) steps dim the whole screen */
.tour.tour--center .tour-backdrop { background: rgba(2, 50, 76, 0.6); }

/* The spotlight ring — a transparent hole over the highlighted element,
   created with a huge box-shadow that dims everything around it */
.tour-spotlight {
  position: fixed;
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(2, 50, 76, 0.6);
  outline: 3px solid var(--water-light);
  outline-offset: 2px;
  pointer-events: none;
  transition: left 0.2s ease, top 0.2s ease, width 0.2s ease, height 0.2s ease;
}

.tour-tooltip {
  position: fixed;
  width: min(340px, calc(100vw - 24px));
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(2, 50, 76, 0.45);
  padding: 1.1rem 1.2rem 1rem;
  overflow: hidden;
}
.tour-tooltip::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, #00b4d8 0 18px, #48cae4 18px 36px);
}
.tour-count {
  margin: 0.2rem 0 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}
.tour-tooltip h3 {
  margin: 0 0 0.4rem;
  color: var(--accent-dark);
  font-size: 1.15rem;
}
.tour-tooltip p#tour-text {
  margin: 0;
  font-size: 0.95rem;
  color: var(--ink);
  line-height: 1.5;
}
.tour-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1rem;
}
.tour-nav { display: flex; gap: 0.5rem; }
.tour-nav .secondary-btn,
.tour-nav .primary-btn { padding: 0.5rem 1rem; min-height: 38px; }
.tour-nav .secondary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .primary-btn, .secondary-btn, .del-btn { transition: none; }
  .primary-btn:hover, .secondary-btn:hover,
  .tab, .theme-toggle, .voice-btn, .skip-link { transition: none; }
  .theme-toggle:hover, .voice-btn:hover,
  .tour-fab:hover, .history-table .del-btn:hover, .history-table .rec-btn:hover { transform: none; }
  .panel-enter,
  .action-plan, .rec, .all-good-banner,
  .all-good-check, .tab-badge.pop { animation: none; }
  .voice-btn[aria-pressed="true"] { animation: none; box-shadow: 0 0 0 3px rgba(194, 40, 82, 0.3); }
  .droplet { display: none; }
  .tour-fab, .tour-spotlight { transition: none; }
  .dial-progress, .slider-fill, .thermo input[type="range"] { transition: none; }
}

/* ---- Test-strip reader (beta) ---- */
.strip-launch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  margin: 0.2rem 0 1.1rem;
}
.strip-launch-hint {
  font-size: 0.82rem;
  color: var(--ink);
  opacity: 0.72;
}
.beta-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 0.14rem 0.5rem;
  margin-left: 0.3rem;
  vertical-align: 0.15em;
}
.strip-overlay { padding: 0.75rem; }
.strip-modal { max-width: 560px; }
.strip-close {
  position: absolute;
  top: 0.9rem;
  right: 0.8rem;
  z-index: 2;
  background: var(--inset-2);
  color: var(--ink);
  border: none;
  border-radius: 50%;
  width: 2.1rem;
  height: 2.1rem;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}
.strip-close:hover { background: var(--inset); }
.strip-stage {
  position: relative;
  width: 100%;
  max-width: 330px;
  margin: 0.8rem auto;
  aspect-ratio: 3 / 4;
  background: #05202c;
  border-radius: 14px;
  overflow: hidden;
}
.strip-stage video,
.strip-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.strip-guide-canvas { touch-action: none; }
.strip-guide-drag { cursor: grab; }
.strip-guide-drag:active { cursor: grabbing; }
.strip-tips {
  background: var(--inset);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font-size: 0.88rem;
  margin: 0.9rem 0 0;
}
.strip-error {
  color: var(--lower);
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0.6rem 0 0;
}
.strip-layout-choice { display: block; margin: 0.25rem 0; }
.strip-layout-pads {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-left: 0.35rem;
}
.strip-scale-field { max-width: 330px; margin: 0 auto; }
.strip-scale-field input[type="range"] { width: 100%; }
.strip-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--inset-2);
}
.strip-row-na { opacity: 0.55; }
.strip-chip {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.18);
}
.strip-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.strip-row-label { font-weight: 600; font-size: 0.92rem; }
.strip-conf {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.76rem;
  opacity: 0.85;
  white-space: nowrap;
}
.strip-conf-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}
.strip-conf-great { color: var(--good); }
.strip-conf-ok { color: #e0912f; }
.strip-conf-poor { color: var(--lower); }
input.strip-row-value[type="number"] {
  width: 5.4rem;
  flex: none;
  padding: 0.4rem 0.5rem;
  font-size: 0.92rem;
  border-radius: 9px;
}
.strip-row-unit {
  flex: none;
  font-size: 0.78rem;
  opacity: 0.7;
  min-width: 3.2rem;
}
.strip-disclaimer {
  background: var(--inset);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 0.9rem 0 0;
}
@media (max-width: 480px) {
  .strip-overlay { padding: 0.4rem; }
  .strip-modal { padding: 1.1rem; }
  .strip-row { flex-wrap: wrap; }
  .strip-row-unit { min-width: 0; }
}

/* ---- Chlorine demand forecast (Calculate tab) ---- */
.forecast-card { margin-top: 1.25rem; }

.forecast-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.forecast-head h2 { margin: 0.2rem 0; }

/* Small pill saying whether the decay rate is textbook or calibrated. */
.forecast-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: var(--inset);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.forecast-badge.tuned {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
}

/* The one-sentence answer, styled like the History tab's insight rows. */
.forecast-verdict {
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  border-left: 5px solid;
  margin-bottom: 0.9rem;
}
.forecast-verdict::before { margin-right: 0.35rem; }
.forecast-verdict.good { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.forecast-verdict.good::before { content: "✅"; }
.forecast-verdict.warn { background: var(--sun-bg); border-color: var(--sun); color: var(--sun-text); }
.forecast-verdict.warn::before { content: "⏳"; }
.forecast-verdict.bad { background: var(--lower-bg); border-color: var(--lower); color: var(--lower); }
.forecast-verdict.bad::before { content: "⚠️"; }

/* The burn-down chart reuses .chart-card; it just needs the full width. */
.forecast-chart { margin-bottom: 0.9rem; }

/* Pool-party toggle + day picker on one wrapping row. */
.forecast-party {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}
.forecast-party-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.forecast-party-toggle input { accent-color: var(--accent); width: 1.05rem; height: 1.05rem; }
.forecast-party select {
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--field-bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
}
.forecast-party select:disabled { opacity: 0.5; }

/* Fine print: loss rate, weather source, reading age, CYA caveat. */
.forecast-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}
