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

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

  --ink: #053b54;
  --muted: #5b8198;
  --accent: #0096c7;
  --accent-dark: #0077b6;
  --border: #bde7f2;
  --card: #ffffff;

  /* Status colors (playful) */
  --good: #06a77d;
  --good-bg: #d7f5ec;
  --raise: #0096c7;
  --raise-bg: #d6f1fb;
  --lower: #ef476f;
  --lower-bg: #fde3ea;
  --sun: #ffb703;
  --sun-bg: #fff3d6;

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

  --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;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  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, #eafaff 100%);
  background-attachment: fixed;
}

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

/* ---- Header ---- */
.site-header {
  position: relative;
  text-align: center;
  padding: 2.4rem 1rem 3.2rem;
  background: linear-gradient(165deg, #00b4d8 0%, #0096c7 45%, #0077b6 100%);
  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);
}
.site-header .sun {
  display: inline-block;
  animation: spin 14s linear infinite;
}
.tagline {
  margin: 0.5rem 0 0;
  color: #eafaff;
  font-weight: 500;
}

/* bobbing floaties */
.floatie {
  position: absolute;
  font-size: 1.6rem;
  opacity: 0.9;
  z-index: 1;
  animation: bob 4.5s ease-in-out infinite;
}
.floatie-1 { top: 18%; left: 8%; animation-delay: 0s; }
.floatie-2 { top: 32%; right: 10%; font-size: 1.4rem; animation-delay: 0.8s; }
.floatie-3 { top: 10%; right: 22%; font-size: 1.5rem; animation-delay: 1.6s; }

/* wave divider that melts the header into the page */
.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;
  animation: waveDrift 10s ease-in-out infinite;
}
.header-wave path { fill: var(--water-pale); }

@keyframes waveDrift {
  0%, 100% { transform: translateX(-3%); }
  50% { transform: translateX(3%); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-12px) rotate(4deg); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* ---- App tab bar ---- */
.tab-bar {
  position: sticky;
  top: 0.6rem;
  z-index: 50;
  display: flex;
  gap: 0.3rem;
  padding: 0.3rem;
  margin-bottom: 1.25rem;
  background: rgba(255, 255, 255, 0.88);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--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 { font-size: 1.05rem; }
.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.3rem;
  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);
}

input[type="number"],
select {
  width: 100%;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #f5fcff;
  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: #f5fcff;
}
.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: #fbfdff;
  border: 1px solid var(--border);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.link-btn {
  background: none;
  border: none;
  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: #f0fbff;
}
.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 {
  cursor: pointer;
  border-radius: 999px;
  font-size: 1.02rem;
  font-weight: 600;
  padding: 0.8rem 1.6rem;
  border: 2px solid transparent;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.primary-btn {
  background: linear-gradient(180deg, #00c2e0 0%, #0096c7 100%);
  color: #fff;
  flex: 1;
  min-width: 180px;
  box-shadow: 0 6px 0 #006a9e, var(--shadow-sm);
}
.primary-btn:hover { transform: translateY(-1px); }
.primary-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #006a9e, var(--shadow-sm);
}
.secondary-btn {
  background: #fff;
  color: var(--accent-dark);
  border-color: var(--water-light);
}
.secondary-btn:hover { background: #eafaff; transform: translateY(-1px); }

/* ---- 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: #06664c;
  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: linear-gradient(180deg, #f2fbff 0%, #e4f6fd 100%);
  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: #fcd2dd; color: #c32d54; }
.plan-note { color: var(--muted); font-size: 0.85rem; }
.plan-safety {
  margin: 0;
  font-size: 0.85rem;
  color: #8a6300;
  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: #c32d54; }
.rec.lower .dose { color: #c32d54; background: #fcd2dd; }
.rec.good { border-left-color: var(--good); background: var(--good-bg); }
.rec.good h3 { color: #058163; }
.rec.note { border-left-color: var(--sun); background: var(--sun-bg); }
.rec.note h3 { color: #b07a00; }
.rec.note .dose { color: #9a6a00; background: #ffe7a8; }
.rec.lsigood { border-left-color: var(--good); background: var(--good-bg); }
.rec.lsigood h3 { color: #058163; }
.rec.lsibad { border-left-color: #e85d04; background: #ffe9d6; }
.rec.lsibad h3 { color: #b34700; }

/* 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: #8a6300;
}

.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.4rem;
}
.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, #ffffff 0%, #eafaff 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: linear-gradient(180deg, #fff7e0 0%, #ffeec2 100%);
  border: 2px solid #ffd874;
  border-radius: 16px;
  padding: 0.7rem 1.1rem;
  margin-bottom: 1rem;
  font-weight: 600;
  color: #8a6300;
  box-shadow: var(--shadow-sm);
}
.reminder-actions { display: inline-flex; gap: 0.9rem; flex-wrap: wrap; }
.reminder-actions .link-btn { padding: 0; color: #9a6a00; }
.reminder-actions .link-btn:hover { color: #6f4d00; }

/* ---- 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 + number box) ---- */
.input-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
.input-row .param-number {
  width: 6rem;
  text-align: center;
  font-weight: 600;
}

.dial {
  width: 132px;
  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: 9;
  stroke-linecap: round;
}
.dial-ideal {
  fill: none;
  stroke: var(--good);
  stroke-width: 9;
  opacity: 0.32;
  stroke-linecap: butt;
}
.dial-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke 0.15s;
}
.dial-thumb {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 3.5;
  filter: drop-shadow(0 1px 2px rgba(2, 40, 60, 0.35));
  transition: stroke 0.15s;
}
.dial-value {
  fill: var(--ink);
  font-family: var(--font-fun);
  font-size: 24px;
  font-weight: 700;
}
.dial-unit {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
/* Scale endpoints + ideal range printed on the dial itself. */
.dial-end {
  fill: var(--muted);
  font-size: 9px;
  font-weight: 600;
}
.dial-ideal-label {
  fill: var(--good);
  font-size: 9.5px;
  font-weight: 700;
  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); }

.reading-field.status-good .param-number { border-color: var(--good); background: var(--good-bg); }
.reading-field.status-low .param-number,
.reading-field.status-high .param-number { border-color: var(--raise); background: var(--raise-bg); }
.reading-field.status-invalid .param-number { border-color: var(--lower); background: var(--lower-bg); }

.reading-field.status-good .dial-progress { stroke: var(--good); }
.reading-field.status-good .dial-thumb { stroke: var(--good); }
.reading-field.status-good .dial-value { fill: 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); }
.reading-field.status-invalid .dial-value { fill: var(--lower); }

/* ---- 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: #8a6300; }
.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: #058163; }
.insight.good::before { content: "🎉"; }

.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, #f7fdff 0%, #eafaff 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: #f5fcff; }
.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; }

.hidden { display: none !important; }

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  .floatie, .sun, .header-wave svg { animation: none; }
  .header-wave svg { transform: none; }
  .primary-btn, .secondary-btn, .del-btn { transition: none; }
  .panel-enter,
  .action-plan, .rec, .all-good-banner,
  .all-good-check, .tab-badge.pop { animation: none; }
  .droplet { display: none; }
}
