/* styles for the dashboard (display.php) */

/* ---------- colours: dark by default, light when the phone is in light mode ---------- */
:root{
  color-scheme: dark light;
  --ground: #0f1115;
  --tile: #1b1f27;
  --tile-hover: #222733;
  --track: #2c3240;
  --text: #e8eaed;
  --muted: #a1a8b3;
  --water: #4ea8ff;
  --heat: #ff9f43;
  --ok: #3ddc97;
  --warn: #f5b942;
  --alert: #ff5c5c;
  --alert-strong: #d63333; /* filled alert pill, dark enough for white text */
  --partial: #f5b942;
  --focus: #8ec5ff;
  --edge: transparent;
  --warn-strong: #8a5a00; /* filled warning bar, dark enough for white text */
}
@media (prefers-color-scheme: light){
  :root{
    --ground: #eef1f5;
    --tile: #ffffff;
    --tile-hover: #f6f8fb;
    --track: #dde2ea;
    --text: #111827;
    --muted: #4b5563;
    --water: #1769d1;
    --heat: #c45a06;
    --ok: #0f8a5a;
    --warn: #9a6400;
    --alert: #c62828;
    --alert-strong: #c62828;
    --partial: #e0a21b;
    --focus: #1769d1;
    --edge: #d5dbe4; /* tiles keep their outline in bright sunlight */
    --warn-strong: #8a5a00;
  }
}

/* ---------- page ---------- */
*{
  box-sizing: border-box;
}
body{
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, p, ul, figure{
  margin: 0;
}
a{
  color: inherit;
  text-decoration: none;
}
a:focus-visible{
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
::selection{
  background: var(--water);
  color: #fff;
}
main{
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* ---------- top bar ---------- */
.topbar{
  display: flex;
  align-items: baseline;
  gap: 12px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px 14px;
}
.topbar h1{
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.time{
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
@media (max-width: 480px){
  .refresh{
    display: none; /* not enough room on phones; the page still refreshes */
  }
}
.help{
  margin-left: auto;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---------- status bar ---------- */
.status{
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: var(--tile);
}
.status-main{
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.0625rem;
  font-weight: 700;
}
.status-main::before{
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
}
.status-rest{
  margin: 4px 0 0 20px;
  font-size: 0.875rem;
  opacity: 0.85;
}
.status.info .status-main::before{ background: var(--ok); }
.status.warn{
  border-color: transparent;
  background: var(--warn-strong);
  color: #fff;
}
.status.alert{
  border-color: transparent;
  background: var(--alert-strong);
  color: #fff;
}
.status.warn .status-main::before,
.status.alert .status-main::before{ background: #fff; }

/* ---------- tiles ---------- */
.tiles{
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 760px){
  .tiles{
    grid-template-columns: repeat(4, 1fr);
  }
}
.tile{
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--edge);
  border-radius: 16px;
  background: var(--tile);
  transition: background-color 150ms ease-out;
}
.tile:hover{
  background: var(--tile-hover);
}
.tile-head{
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.tile-head h2{
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
}
.icon{
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.age{
  margin-top: auto;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.age.stale{
  color: var(--warn);
  font-weight: 600;
}

/* ring gauge with the number in the middle */
.ring-box{
  position: relative;
  width: min(100%, 132px);
  aspect-ratio: 1;
  margin: 2px auto 0;
}
.ring{
  width: 100%;
  height: 100%;
}
.ring circle{
  fill: none;
  stroke-width: 9;
}
.ring .track{ stroke: var(--track); }
.ring .fill{ stroke-linecap: round; }
.ring.water .fill{ stroke: var(--water); }
.ring.heat .fill{ stroke: var(--heat); }
.ring-text{
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* small line graph of the last hours */
.sparkline{
  width: 100%;
  height: 28px;
}
.sparkline polyline{
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.sparkline.water polyline{ stroke: var(--water); }
.sparkline.heat polyline{ stroke: var(--heat); }

/* pump: big fan that turns while the pump runs */
.pump-state{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
}
.pump-state .icon{
  width: 64px;
  height: 64px;
  stroke-width: 1.5;
  color: var(--muted);
}
.pump.running .pump-state .icon{
  color: var(--ok);
  animation: spin 2.4s linear infinite;
}
@keyframes spin{
  to{ transform: rotate(360deg); }
}

/* ---------- power ---------- */
.power{
  display: grid;
  gap: 12px;
  margin-top: 12px;
}
@media (min-width: 900px){
  .power{
    grid-template-columns: 1fr 1fr;
  }
}
.power-tile .tile-head .age{
  margin: 0 0 0 auto;
}
.gauges{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.gauge{
  min-width: 0;
  text-align: center;
}
.gauge svg{
  display: block;
  width: 100%;
  max-width: 150px;
  margin: 0 auto;
}
.gauge path{
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
}
.gauge .track{ stroke: var(--track); }
.gauge .value{ stroke: var(--ok); }
.gauge.low .value,
.gauge.high .value{ stroke: var(--alert); }
/* thin inner arc marking the safe voltage range (LOW_VOLTAGE to HIGH_VOLTAGE) */
.gauge .safe-range{
  stroke: var(--ok);
  stroke-width: 3;
  opacity: 0.6;
}
.gauge.off .safe-range{
  stroke: var(--muted);
  opacity: 0.4;
}
.gauge .needle{
  stroke: var(--text);
  stroke-width: 3;
  stroke-linecap: round;
  transform-box: view-box;
  transform-origin: 50px 50px;
  transform: rotate(var(--angle));
  animation: sweep 900ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes sweep{
  from{ transform: rotate(-90deg); }
}
.gauge .hub{ fill: var(--text); }
.gauge.low .needle,
.gauge.high .needle{ stroke: var(--alert); }
.gauge.low .hub,
.gauge.high .hub{ fill: var(--alert); }
.gauge figcaption{
  display: flex;
  flex-direction: column;
}
.volts{
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.gauge.low .volts,
.gauge.high .volts{ color: var(--alert); }
.gauge.off .needle{ stroke: var(--muted); }
.gauge.off .hub{ fill: var(--muted); }
.gauge.off .volts{ color: var(--muted); }
.phase{
  color: var(--muted);
  font-size: 0.8125rem;
}
.empty{
  grid-column: 1 / -1;
  padding: 24px 0;
  color: var(--muted);
  text-align: center;
}

/* on/off bar of the last hours */
.history{
  display: block;
  width: 100%;
  height: 14px;
  border-radius: 4px;
  background: var(--track);
}
.history .on{ fill: var(--ok); }
.history .partial{ fill: var(--partial); }
.history .high{ fill: var(--alert); }
.history .off{ fill: var(--muted); opacity: 0.7; }
.history-scale{
  display: flex;
  justify-content: space-between;
  margin-top: -4px;
  color: var(--muted);
  font-size: 0.75rem;
}

/* legend under everything */
.legend{
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.8125rem;
}
.legend span{
  white-space: nowrap; /* keep each swatch next to its label */
}
.legend i{
  display: inline-block;
  width: 10px;
  height: 10px;
  margin: 0 2px 0 8px;
  border-radius: 2px;
  vertical-align: -1px;
}
.legend .on{ background: var(--ok); }
.legend .partial{ background: var(--partial); }
.legend .high{ background: var(--alert); }
.legend .off{ background: var(--muted); opacity: 0.7; }
.legend .none{ background: var(--track); box-shadow: inset 0 0 0 1px var(--muted); }

/* no spinning or sweeping for people who turned animations off */
/* ---------- units, temperature, states ---------- */
.ring-text small,
.value small,
.volts small{
  margin-left: 1px;
  font-size: 0.6em;
  font-weight: 600;
  color: var(--muted);
}
.big-number{
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 4px;
  min-height: 96px;
}
.big-number .value{
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.range{
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

/* a tank level that needs attention */
.tile.attention .ring .fill{ stroke: var(--alert); }
.tile.attention .ring-text{ color: var(--alert); }

/* an old reading: greyed out so it never looks current */
.tile.stale .ring .fill,
.tile.stale .sparkline polyline{ stroke: var(--muted); opacity: 0.5; }
.tile.stale .ring-text,
.tile.stale .value{ color: var(--muted); }

/* the needles sweep only on the first load of a visit (see the script in display.php) */
.no-sweep .gauge .needle{
  animation: none;
}

@media (prefers-reduced-motion: reduce){
  .pump.running .pump-state .icon,
  .gauge .needle{
    animation: none;
  }
}
