:root {
  /* "eau & été" — summery water palette (light, default) */
  --bg: #e4f4fb;        /* pale sky */
  --bg2: #b6e3f2;       /* sea (gradient bottom) */
  --card: #ffffff;
  --card-hi: #e1f3fa;   /* pale aqua surface (off toggles, step buttons) */
  --fg: #0b3b51;        /* deep ocean text */
  --muted: #5c8aa0;     /* muted teal */
  --accent: #06b6d4;    /* cyan water */
  --warn: #ea8a0b;
  --err: #ef4444;
  --shadow: 0 12px 30px rgba(8, 70, 95, 0.13);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #06293c;      /* deep sea at night */
    --bg2: #021620;
    --card: #0b3950;
    --card-hi: #0f4a67;
    --fg: #e8f8ff;
    --muted: #82b0c4;
    --accent: #38bdf8;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  }
}

body[data-sky="day-clear"] {
  --bg: #d9f4ff;
  --bg2: #8fd7ee;
  --card: rgba(255, 255, 255, 0.94);
  --card-hi: #d9f1f7;
  --fg: #08384d;
  --muted: #527f93;
  --accent: #06b6d4;
  --shadow: 0 12px 30px rgba(6, 83, 112, 0.14);
}

body[data-sky="day-cloudy"] {
  --bg: #d8e8ef;
  --bg2: #a7c6d6;
  --card: rgba(255, 255, 255, 0.95);
  --card-hi: #dfeaf0;
  --fg: #17394a;
  --muted: #647f8c;
  --accent: #0891b2;
  --shadow: 0 12px 30px rgba(43, 73, 88, 0.16);
}

body[data-sky="golden"] {
  --bg: #ffe0a8;
  --bg2: #7fcbd5;
  --card: rgba(255, 252, 244, 0.95);
  --card-hi: #f6e9cc;
  --fg: #214052;
  --muted: #7b7460;
  --accent: #0ea5b7;
  --warn: #d97706;
  --shadow: 0 14px 34px rgba(117, 82, 31, 0.18);
}

body[data-sky="night"] {
  --bg: #061827;
  --bg2: #0b3142;
  --card: rgba(8, 38, 54, 0.94);
  --card-hi: #103f55;
  --fg: #e8f8ff;
  --muted: #8ab5c7;
  --accent: #38bdf8;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.48);
}

* { box-sizing: border-box; }

html { min-height: 100%; }
body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 75%);
  background-attachment: fixed;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 600ms ease, color 300ms ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.85;
  transition: opacity 600ms ease, background 600ms ease;
}

body[data-sky="day-clear"]::before {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0 1px, transparent 120px),
    linear-gradient(160deg, rgba(255, 245, 188, 0.42) 0%, transparent 34%),
    linear-gradient(180deg, transparent 55%, rgba(255, 255, 255, 0.28) 100%);
}

body[data-sky="day-cloudy"]::before {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.52), transparent 130px),
    repeating-linear-gradient(170deg,
      rgba(255, 255, 255, 0.23) 0 70px,
      rgba(194, 211, 220, 0.18) 70px 150px,
      transparent 150px 270px);
}

body[data-sky="golden"]::before {
  background:
    linear-gradient(180deg, rgba(255, 248, 221, 0.55), transparent 110px),
    linear-gradient(150deg, rgba(255, 178, 88, 0.56), transparent 42%),
    linear-gradient(180deg, transparent 62%, rgba(0, 121, 140, 0.18) 100%);
}

body[data-sky="night"]::before {
  opacity: 0.7;
  background:
    repeating-linear-gradient(105deg,
      rgba(255, 255, 255, 0.08) 0 1px,
      transparent 1px 42px),
    linear-gradient(180deg, rgba(99, 179, 237, 0.12), transparent 42%);
}

main {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

/* layout: single column on mobile (existing card margins handle spacing),
   two columns on desktop with the scheduler in a right-hand column */
@media (min-width: 880px) {
  main { max-width: 980px; }
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 20px;
    align-items: start;
  }
  .col-side > :first-child { margin-top: 0; }
}

.lang-switcher {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px;
  margin: 0; display: inline-flex; gap: 4px; font-size: 0.7rem;
}
.lang-switcher a {
  color: var(--muted); text-decoration: none; padding: 3px 8px;
  border-radius: 999px; font-weight: 600; letter-spacing: 0.05em;
}
.lang-switcher a.active { background: var(--card-hi); color: var(--fg); }

header { position: relative; }

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
  margin: 8px 0 4px;
}
.spa-ip {
  margin: 0 0 16px;
  font-size: 0.75rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.02em;
}

.banner {
  background: color-mix(in srgb, var(--warn) 18%, var(--card));
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  color: var(--fg);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}
.banner-error {
  /* hardware error from the spa itself — louder than the soft "offline" banner */
  background: color-mix(in srgb, var(--err) 18%, var(--card));
  border-color: color-mix(in srgb, var(--err) 55%, transparent);
  display: grid; gap: 4px;
}
.banner-error strong { font-size: 0.95rem; }
.banner-error small { font-size: 0.75rem; opacity: 0.75; }

/* pause controls — small, sits between the panel and the chart card */
.pause-row { margin-top: 12px; display: grid; gap: 8px; }
.banner-paused {
  /* same shape as .banner, neutral palette so it's clearly informational */
  background: color-mix(in srgb, var(--muted) 15%, var(--card));
  border: 1px solid color-mix(in srgb, var(--muted) 35%, transparent);
  color: var(--fg); padding: 10px 14px; border-radius: 12px;
  font-size: 0.78rem; line-height: 1.4;
}
.banner-manual-hold {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border-color: color-mix(in srgb, var(--accent) 38%, transparent);
  font-size: 0.8rem;
  line-height: 1.4;
}
.pause-btn {
  align-self: end; justify-self: end;
  border: 1px solid var(--card-hi); background: transparent; color: var(--muted);
  font-size: 0.75rem; font-weight: 600; padding: 6px 14px; border-radius: 999px;
  cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.pause-btn:hover { background: var(--card-hi); color: var(--fg); }
.pause-btn.is-paused { background: var(--accent); color: #fff; border-color: var(--accent); }

.readout {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}

.temp {
  text-align: center;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}
.temp .cur { font-size: 4.5rem; font-weight: 700; line-height: 1; }
.temp .cur small { font-size: 1.6rem; color: var(--muted); font-weight: 600; }
.temp .errcode {
  background: var(--err); color: #fff; padding: 4px 10px;
  border-radius: 999px; font-size: 0.9rem; font-weight: 700; align-self: center;
}
.temp .mood { font-size: 2.4rem; align-self: center; line-height: 1; }
.temp .mood-ok {
  font-size: 2rem;
  filter: saturate(0.95);
}
.toggle .lbl .ico { font-size: 1.05rem; }

.setpoint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 20px 0 4px;
}
.setpoint .val {
  display: flex; flex-direction: column; align-items: center;
  min-width: 96px; font-size: 1.9rem; font-weight: 700;
}
.setpoint .val small { font-size: 1rem; color: var(--muted); }
.setpoint .val em { font-style: normal; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.step {
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--card-hi); background: var(--card-hi);
  color: var(--fg); font-size: 1.8rem; line-height: 1; cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
}
.step:active { transform: scale(0.92); }
.step:disabled { opacity: 0.35; cursor: not-allowed; }

.eta {
  text-align: center;
  margin: 0 0 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.toggles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 22px;
}
.toggle {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 16px; border-radius: 14px;
  border: 1px solid var(--card-hi); background: var(--card-hi);
  color: var(--fg); cursor: pointer; text-align: left;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.toggle:active { transform: scale(0.97); }
.toggle .lbl { font-size: 0.95rem; font-weight: 600; }
.toggle .state { font-size: 0.78rem; color: var(--muted); font-weight: 700; letter-spacing: 0.06em; }
/* "on" = turquoise→cyan water gradient, white text (reads in both themes) */
.toggle.on {
  background: linear-gradient(135deg, #22d3ee, #0891b2);
  border-color: transparent;
  color: #ffffff;
}
.toggle.on .lbl { color: #ffffff; }
.toggle.on .state { color: #e6feff; }

.waiting { text-align: center; color: var(--muted); margin: 12px 0; }

.updated {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin: 16px 0 0;
  min-height: 1em;
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 18px 10px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.chart-head span:first-child {
  font-size: 0.9rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.chart-head .range { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.range-btn {
  border: 1px solid var(--card-hi); background: transparent; color: var(--muted);
  font-size: 0.75rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; cursor: pointer;
}
.range-btn.active { background: var(--card-hi); color: var(--fg); }
.chart-activity-legend {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 6px;
  min-height: 16px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}
.chart-activity-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-activity-legend i {
  display: inline-block;
  width: 18px;
  height: 5px;
  border-radius: 999px;
}
.chart-activity-legend i.heat { background: #ef4444; }
.chart-activity-legend i.filter { background: #2563eb; }

/* weather + algorithm explainer card */
.weather-card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-top: 16px; box-shadow: var(--shadow); }
.wx-top { display: flex; align-items: baseline; justify-content: space-between; }
.wx-title { font-size: 0.95rem; font-weight: 700; }
.wx-age { font-size: 0.72rem; color: var(--muted); }
.wx-now { margin-top: 8px; font-size: 0.95rem; font-weight: 600; }
.wx-algo { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--card-hi); }
.wx-algo-head { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.wx-algo-now-head, .wx-algo-rate-head {
  margin-top: 12px; font-size: 0.68rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7;
}
.algo-now-list {
  margin: 6px 0 0; padding: 0; list-style: none;
  display: grid; gap: 4px;
  font-size: 0.85rem; line-height: 1.4;
}
.algo-now-list li { padding-left: 0; }
.wx-line { margin-top: 8px; font-size: 0.85rem; line-height: 1.4; }
.wx-line b { color: var(--accent); }
.wx-note { margin: 10px 0 0; font-size: 0.76rem; color: var(--muted); line-height: 1.35; }

/* camera card */
.cam-card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-top: 16px; box-shadow: var(--shadow); }
.cam-top { display: flex; align-items: baseline; justify-content: space-between; }
.cam-title { font-size: 0.95rem; font-weight: 700; }
.cam-meta { font-size: 0.72rem; color: var(--muted); }
.cam-frame {
  position: relative; margin-top: 10px;
  border-radius: 12px; overflow: hidden;
  background: var(--card-hi);
  aspect-ratio: 16 / 9;
}
.cam-frame img { width: 100%; height: 100%; object-fit: cover; }
.cam-frame img[hidden] { display: none; }  /* explicit so display: block can't leak */
.cam-empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 0.85rem; color: var(--muted);
}
.cam-empty[hidden] { display: none; }  /* same trap as img[hidden] above */
.cam-roi-canvas { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
.cam-row {
  margin-top: 12px; display: flex; gap: 10px; align-items: center;
  justify-content: space-between; flex-wrap: wrap;
}
.cam-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.cam-roi-actions { justify-content: flex-end; }
.cam-roi-actions[hidden] { display: none; }  /* .cam-row sets display:flex, which would otherwise leak past [hidden] */
.cam-badge {
  border-radius: 999px; padding: 5px 12px; font-size: 0.78rem; font-weight: 600;
  background: var(--card-hi); color: var(--fg);
  display: inline-flex; align-items: center; gap: 6px;
}
.cam-badge.cover-on  { background: color-mix(in srgb, var(--accent) 22%, var(--card-hi)); }
.cam-badge.cover-off { background: color-mix(in srgb, var(--warn) 28%, var(--card-hi)); color: var(--fg); }
.cam-badge.cover-unknown { color: var(--muted); }
.cam-btn {
  border: 1px solid var(--card-hi); background: transparent; color: var(--muted);
  font-size: 0.75rem; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  cursor: pointer; text-decoration: none; line-height: 1.4;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.cam-btn:hover { background: var(--card-hi); color: var(--fg); border-color: var(--card-hi); }
.cam-btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.cam-btn-primary:hover { background: var(--accent); color: #fff; border-color: var(--accent); filter: brightness(1.05); }
.cam-note { margin: 10px 0 0; font-size: 0.72rem; color: var(--muted); line-height: 1.35; }
.cam-btn-icon { padding: 5px 9px; font-size: 0.95rem; line-height: 1; }
.cam-settings {
  margin-top: 12px; padding: 12px;
  background: color-mix(in srgb, var(--card-hi) 50%, transparent);
  border-radius: 12px; display: grid; gap: 14px;
}
.cam-settings[hidden] { display: none; }
.cam-settings-section { display: grid; gap: 8px; }
.cam-settings-label {
  font-size: 0.7rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.cam-settings .cam-actions { gap: 6px; }
.cam-settings .cam-note { margin: 0; }

/* segmented control — 3-way selector for the force-state override */
.cam-segmented {
  display: inline-flex; padding: 3px;
  background: color-mix(in srgb, var(--bg2) 50%, var(--card));
  border-radius: 999px; gap: 0;
}
.cam-seg {
  border: 0; background: transparent; color: var(--muted);
  font-size: 0.78rem; font-weight: 600; padding: 6px 14px;
  border-radius: 999px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.cam-seg.active { background: var(--accent); color: #fff; }
.cam-seg:not(.active):hover { color: var(--fg); }

/* scheduler card */
.sched-card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-top: 16px; box-shadow: var(--shadow); }
.sched-top { display: flex; align-items: center; justify-content: space-between; }
.sched-title { font-size: 0.95rem; font-weight: 700; }
.sched-plan { margin: 6px 0 2px; }
.plan-now {
  background: var(--card-hi); color: var(--fg); border-radius: 999px;
  padding: 8px 14px; font-size: 0.85rem; font-weight: 600; display: inline-block;
}
.eco { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0 6px; font-weight: 600; }

.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track { position: absolute; inset: 0; background: var(--card-hi); border-radius: 999px; transition: 0.2s; }
.switch .track::before {
  content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(20px); }

.rgroup { margin-top: 16px; }
.rgroup-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.rgroup-head span { font-weight: 600; font-size: 0.92rem; }
.add { border: 0; background: transparent; color: var(--accent); font-weight: 700; font-size: 0.82rem; cursor: pointer; }

.rule { background: var(--card-hi); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.days { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.day {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--card);
  background: var(--card); color: var(--muted); font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.day.on { background: var(--accent); color: #06283a; border-color: transparent; }
.rfields { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rfields .t, .rfields .temp, .eco input {
  border: 1px solid var(--card); background: var(--card); color: var(--fg);
  border-radius: 8px; padding: 7px 8px; font-size: 0.9rem;
}
.rfields .temp, .eco input { width: 58px; }
.num { display: inline-flex; align-items: center; color: var(--muted); }
.dash { color: var(--muted); }
.del { margin-left: auto; border: 0; background: transparent; color: var(--err); font-size: 1rem; cursor: pointer; }

.save-btn {
  width: 100%; margin-top: 14px; padding: 13px; border: 0; border-radius: 12px;
  background: var(--accent); color: #06283a; font-size: 1rem; font-weight: 700; cursor: pointer;
}
.sched-msg { min-height: 1.2em; margin: 8px 2px 0; font-size: 0.85rem; text-align: center; }
.sched-msg.ok { color: #0891b2; }
.sched-msg.err { color: var(--err); }
/* Chart.js (maintainAspectRatio:false) sizes the canvas to this fixed-height
   wrapper — without it the canvas grows unbounded, esp. on mobile. */
.chart-wrap { position: relative; height: 200px; }
.chart-empty { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 24px 0; }

/* login */
main.login { display: flex; min-height: 80vh; align-items: center; justify-content: center; }
.login-card {
  background: var(--card); border-radius: var(--radius); padding: 28px 24px;
  width: 100%; max-width: 320px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.login-card input {
  padding: 14px 16px; border-radius: 12px; border: 1px solid var(--card-hi);
  background: var(--card-hi); color: var(--fg); font-size: 1rem;
}
.login-card button {
  padding: 14px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent); color: #08131f; font-size: 1rem; font-weight: 700;
}
.login-err { color: var(--err); font-size: 0.85rem; margin: 0; }
