/* Spa Controller. Plain CSS with no build step. */

:root {
  --paper: #f3efe6;
  --paper-deep: #e9e3d6;
  --card: #fbf9f4;
  --ink: #16282d;
  --ink-soft: #566a6e;
  --line: #d9d2c2;
  --teal: #0f4c5c;
  --teal-bright: #14707f;
  --chart-line: #c2410c;
  --chart-set: #00809a;
  --water: rgb(20 112 127 / 0.13);
  --water-edge: rgb(20 112 127 / 0.42);
  --heat: #d97706;
  --heat-glow: rgb(245 158 11 / 0.55);
  --heat-water: rgb(217 119 6 / 0.15);
  --heat-edge: rgb(217 119 6 / 0.55);
  --ok: #1a7f5a;
  --wait: #8a6d1a;
  --alert: #b3361f;
  --alert-wash: #f8e6df;
  --ok-wash: #e0f0e8;
  --mono: 'Spline Sans Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans: 'Schibsted Grotesk', ui-sans-serif, -apple-system, 'Segoe UI', sans-serif;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1a1e;
    --paper-deep: #0a1417;
    --card: #15252a;
    --ink: #ebe7dc;
    --ink-soft: #94a6a8;
    --line: #27393e;
    --teal: #7fd0db;
    --teal-bright: #7fd0db;
    --chart-line: #c8622c;
    --chart-set: #0099b5;
    --water: rgb(90 190 205 / 0.13);
    --water-edge: rgb(127 208 219 / 0.45);
    --heat: #f5a524;
    --heat-glow: rgb(245 165 36 / 0.65);
    --heat-water: rgb(245 165 36 / 0.13);
    --heat-edge: rgb(245 165 36 / 0.55);
    --ok: #57c79a;
    --wait: #d9b94d;
    --alert: #f0836a;
    --alert-wash: #3a1f1a;
    --ok-wash: #16332a;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, dl, dd, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
a { color: var(--teal-bright); text-underline-offset: 3px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--teal-bright); outline-offset: 2px; border-radius: 4px; }

/* Brand */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand:hover { color: var(--ink); }
/* The favicon, so the tab and the page match. */
.brand-mark {
  flex: none;
  width: 26px;
  height: 26px;
  background: url('../favicon.svg') center / contain no-repeat;
}

/* Login and registration */
.page-auth {
  background:
    linear-gradient(to top, var(--water) 0, var(--water) 34vh, transparent 34vh),
    var(--paper);
}
.auth {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  max-width: 460px;
  margin: 0 auto;
  padding: clamp(32px, 9vh, 88px) 16px 48px;
}
.panel {
  width: 100%;
  padding: clamp(24px, 5vw, 36px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 44px -28px rgb(15 40 45 / 0.45);
}
.panel h1 {
  font-size: 1.65rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.panel .lead {
  margin: 8px 0 24px;
  color: var(--ink-soft);
}
.panel .after-form {
  margin-top: 20px;
  color: var(--ink-soft);
  font-size: 0.94rem;
  text-align: center;
}

/* Forms */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
  font-weight: 600;
}
.field .optional { color: var(--ink-soft); font-weight: 400; }
.field input,
.field textarea {
  width: 100%;
  padding: 11px 13px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field textarea:focus {
  border-color: var(--teal-bright);
  outline: none;
  box-shadow: 0 0 0 3px var(--water-edge);
}
.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  font-size: 0.94rem;
}
.field-check input { width: 16px; height: 16px; accent-color: var(--teal-bright); }

.btn {
  display: block;
  width: 100%;
  padding: 12px 18px;
  background: var(--teal);
  border: 0;
  border-radius: 9px;
  color: var(--card);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover { color: var(--card); filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-secondary {
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn-secondary:hover { color: var(--ink); filter: none; background: var(--paper); }

.link-button {
  padding: 0;
  background: none;
  border: 0;
  color: var(--ink-soft);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-button:hover { color: var(--ink); }

/* Registration steps */
.steps {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.02em;
}
.step {
  flex: 1;
  padding-top: 8px;
  border-top: 3px solid var(--line);
  color: var(--ink-soft);
}
.step-active { border-color: var(--teal-bright); color: var(--ink); font-weight: 600; }
.step-done { border-color: var(--ok); }

/* Messages */
.notice {
  margin-bottom: 20px;
  padding: 12px 14px;
  border-radius: 9px;
  font-size: 0.94rem;
}
.notice p + p { margin-top: 4px; }
.notice-ok { background: var(--ok-wash); color: var(--ok); }
.notice-alert { background: var(--alert-wash); color: var(--alert); }

/* Dashboard */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px;
  border-bottom: 1px solid var(--line);
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.92rem;
}
.topbar-account { color: var(--ink-soft); }
.topbar-user form { margin: 0; }

.dashboard {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 16px 56px;
}
.admin-title {
  margin-bottom: 20px;
  font-size: 1.8rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.doc h2 { margin: 24px 0 8px; font-size: 1.1rem; }
.doc ul, .doc ol { margin: 8px 0 8px 1.3em; }
.doc li { margin-bottom: 6px; }
.doc .hint { color: var(--ink-soft); font-size: 0.9rem; }
.dashboard-footer {
  margin-top: 32px;
  font-size: 0.94rem;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 40px;
  margin-bottom: 24px;
}
.summary dt {
  color: var(--ink-soft);
  font-size: 0.82rem;
}
.summary dd {
  font-family: var(--mono);
  font-size: 1.7rem;
  font-weight: 500;
  line-height: 1.2;
}
.summary dd span { color: var(--ink-soft); font-size: 1rem; }
.summary-alert dd { color: var(--alert); }

.tubs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
  gap: 14px;
}

.tub {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  min-height: 262px;
  padding: 18px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tub-alert, .tub-offline { border-color: var(--alert); }

/* The water line: rises with temperature, and turns amber while heating. */
.tub-water {
  position: absolute;
  inset: auto 0 0;
  z-index: -1;
  height: var(--level);
  background: var(--water);
  border-top: 2px solid var(--water-edge);
  transition: height 0.8s ease;
}
.tub-water-heating {
  background: var(--heat-water);
  border-top-color: var(--heat-edge);
}
.tub-offline .tub-water { opacity: 0.45; filter: grayscale(1); }

.tub-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.tub-head h2 {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.tub-status {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 500;
}
.dot { width: 8px; height: 8px; background: currentColor; border-radius: 50%; }
.tub-ok .tub-status { color: var(--ok); }
.tub-wait .tub-status { color: var(--wait); }
.tub-alert .tub-status { color: var(--alert); }
.tub-offline .tub-status { color: var(--ink-soft); }

.tub-temp {
  margin-top: 14px;
  font-family: var(--mono);
  font-size: 3.9rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
}
.tub-unit {
  margin-left: 4px;
  color: var(--ink-soft);
  font-size: 1.25rem;
  letter-spacing: 0;
}
.tub-temp-none { color: var(--ink-soft); }
.tub-temp-note {
  margin-left: 6px;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0;
}
.tub-offline .tub-temp { color: var(--ink-soft); }

.tub-detail {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.4;
}

.tub-facts {
  display: flex;
  gap: 28px;
  margin-top: auto;
  padding-top: 16px;
}
.tub-facts dt {
  color: var(--ink-soft);
  font-size: 0.78rem;
}
.tub-facts dd {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 6px;
  font-weight: 600;
}
.tub-facts small {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 400;
}

/* Echoes the amber HEAT light on the spa's own panel. */
.led {
  align-self: center;
  width: 9px;
  height: 9px;
  background: var(--heat);
  border-radius: 50%;
  box-shadow: 0 0 9px 1px var(--heat-glow);
}

.refresh-note {
  margin-top: 16px;
  color: var(--alert);
  font-size: 0.92rem;
}

.empty {
  padding: 56px 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--ink-soft);
  text-align: center;
}
.empty h1 {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 1.3rem;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Tub page */
.back { margin-bottom: 16px; font-size: 0.94rem; }
.tub-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 16px;
}
.tub-title h1 {
  font-size: 1.8rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.tub-title-detail { margin-top: 4px; color: var(--ink-soft); }
.tub-title + .summary, .tub-title-detail + .summary { margin-top: 20px; }
.tub-status.tub-ok { color: var(--ok); }
.tub-status.tub-wait { color: var(--wait); }
.tub-status.tub-alert { color: var(--alert); }
.tub-status.tub-offline { color: var(--ink-soft); }
/* The name is the link, stretched over the card so the whole card is clickable. */
.tub-link { color: inherit; text-decoration: none; }
.tub-link::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
}
.tub-link:focus-visible { outline: none; }
.tub-link:focus-visible::after { outline: 2px solid var(--teal-bright); outline-offset: -2px; }
.tub:hover { border-color: var(--teal-bright); box-shadow: 0 10px 24px -18px rgb(15 40 45 / 0.6); }
.tub:hover .tub-link { color: var(--teal-bright); }
.tub-alert:hover, .tub-offline:hover { border-color: var(--alert); }

.section {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}
.section h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 14px; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 14px;
}
.section-head h2 { margin: 0; }
.section-note { margin-top: 10px; color: var(--ink-soft); font-size: 0.82rem; }
.empty-inline { color: var(--ink-soft); }

.ranges { display: flex; gap: 4px; font-family: var(--mono); font-size: 0.82rem; }
.range {
  padding: 3px 9px;
  border-radius: 6px;
  color: var(--ink-soft);
  text-decoration: none;
}
.range:hover { color: var(--ink); background: var(--paper-deep); }
.range-active { color: var(--card); background: var(--teal); }
.range-active:hover { color: var(--card); background: var(--teal); }

/* Temperature chart: positions are percentages, so it fits any width. */
.chart { margin: 0; padding-left: 36px; }
.chart-plot {
  position: relative;
  height: 240px;
  touch-action: pan-y;
  cursor: crosshair;
}
.chart-plot svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.chart-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart-line-set {
  stroke: var(--chart-set);
  stroke-dasharray: 6 4;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 0.8rem;
}
.chart-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.chart-key { width: 18px; height: 0; border-top: 2px solid var(--chart-line); }
.chart-key-set { border-top: 2px dashed var(--chart-set); }
.chart-gridline {
  position: absolute;
  right: 0;
  left: 0;
  border-top: 1px solid var(--line);
}
.chart-gridline span {
  position: absolute;
  top: -0.7em;
  left: -36px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.74rem;
}
.chart-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--ink-soft);
  pointer-events: none;
}
.chart-marker {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  background: var(--chart-line);
  border: 2px solid var(--paper);
  border-radius: 50%;
  pointer-events: none;
}
.chart-tooltip {
  position: absolute;
  top: 6px;
  max-width: 62%;
  padding: 6px 9px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 0.8rem;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 8px 18px -12px rgb(15 40 45 / 0.5);
}
.chart-cursor[hidden], .chart-marker[hidden], .chart-tooltip[hidden] { display: none; }

.chart-heat { margin-top: 12px; }
.chart-heat-label {
  display: block;
  margin-bottom: 4px;
  color: var(--ink-soft);
  font-size: 0.74rem;
}
.chart-heat-track {
  position: relative;
  height: 8px;
  background: var(--paper-deep);
  border-radius: 4px;
  overflow: hidden;
}
.chart-heat-track span {
  position: absolute;
  top: 0;
  bottom: 0;
  min-width: 2px;
  background: var(--heat);
}
.chart-x {
  position: relative;
  height: 22px;
  margin-top: 6px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.74rem;
}
.chart-x span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.chart-x span:first-child { transform: none; }
.chart-x span:last-child { transform: translateX(-100%); }

.details { margin-top: 14px; font-size: 0.94rem; }
.details summary { cursor: pointer; color: var(--teal-bright); }
.details .table-scroll { margin-top: 10px; max-height: 320px; overflow: auto; }

.table-scroll { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.table th {
  padding: 6px 12px 6px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
}
.table td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table-time { color: var(--ink-soft); font-family: var(--mono); font-size: 0.82rem; white-space: nowrap; }
.table-mono { font-family: var(--mono); font-size: 0.85rem; white-space: nowrap; }
.table .tub-status { white-space: nowrap; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.rename {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  max-width: 480px;
  margin-bottom: 20px;
}
.rename .field { flex: 1 1 220px; margin: 0; }
.btn-inline { width: auto; padding: 11px 20px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

.set-temp { margin-bottom: 8px; }
/* As wide as the limit boxes. The label runs on past the box, above the Set button. */
.set-temp .field { flex: 0 0 130px; min-width: 0; }
.set-temp label { white-space: nowrap; }
.command-status { font-size: 0.9rem; color: var(--ink-soft); }
.command-status::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; vertical-align: 1px; background: currentColor; }
.command-ok { color: var(--ok); }
.command-wait { color: var(--wait); }
.command-alert { color: var(--alert); }
.limits { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); display: grid; gap: 12px; max-width: 62ch; }
.limits .field-check { margin: 0; font-weight: 600; }
.limits-range { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.limits-range .field { flex: 0 1 130px; margin: 0; }
.limits .section-note { margin-top: 0; }
.alarms { display: grid; gap: 12px; max-width: 62ch; }
.alarms .field-check { margin: 0; }
.alarms .section-note { margin-top: 0; }
.remote-control { margin-top: 18px; display: grid; gap: 10px; justify-items: start; max-width: 62ch; }
.remote-control .btn-secondary { margin-top: 0; }

.facts { display: flex; flex-wrap: wrap; gap: 8px 36px; }
.facts dt { color: var(--ink-soft); font-size: 0.8rem; }
.facts dd { font-family: var(--mono); font-size: 0.9rem; overflow-wrap: anywhere; }

/* Spa Controller Admin (/sca) */
.sca-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; font-family: var(--mono); font-size: 0.9rem; }
.sca-nav .range { padding: 6px 12px; }
.sca-head { margin-bottom: 8px; }
.sca-head .admin-title { margin: 0; }
.sca-form { max-width: 460px; margin-bottom: 8px; }
.field select {
  width: 100%;
  padding: 11px 13px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  font: inherit;
}
.field select:focus { border-color: var(--teal-bright); outline: none; box-shadow: 0 0 0 3px var(--water-edge); }
.section .facts { margin-bottom: 14px; }
.section .btn-secondary.btn-inline { margin-top: 0; }

/* Heat mode and the light test, below the limits */
.heat-mode { margin-top: 20px; }
.heat-mode .field { flex: 0 0 200px; min-width: 0; }
.light-test { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 18px; }
.light-test .btn-secondary { margin-top: 0; }
