/*
  Fim's Farm Bettingen — heating dashboard visual language

  This reads a heating installation, so the palette leans into that: a
  near-black graphite base (like a plant-room control panel), a copper/amber
  accent for anything hot, a cool cyan for anything cold (outdoor temps).
  Sharp corners and hairline rules rather than soft rounded cards; a single
  display face used at both headline and readout scale, set in tabular
  figures so the numbers hold still as they update.
*/

:root {
  --bg: #12161a;
  --panel: #1a2025;
  --panel-border: #2a333b;
  --text: #e7e3da;
  --text-muted: #8b96a1;

  --heat: #cf8a3c;
  --heat-dim: #7a5a34;
  --cold: #4a9bb8;
  --ok: #6a9a6a;
  --off: #454e56;

  --radius: 3px;
}

* {
  box-sizing: border-box;
}

/* An author rule like `main { display: grid }` otherwise beats the
   user-agent's default `[hidden] { display: none }` regardless of
   selector specificity, since origin outranks specificity in the
   cascade - toggling `hidden` (e.g. the dashboard's view switcher)
   would silently do nothing without this. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.display,
h1,
h2,
.value {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
}

header {
  padding: 2.5rem clamp(1.25rem, 4vw, 3rem) 1.5rem;
  border-bottom: 1px solid var(--panel-border);
}

header h1 {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 1.1rem;
}

.topnav a {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
}

.topnav a:hover {
  color: var(--text);
  background: var(--panel);
  text-decoration: none;
}

.topnav a.active {
  color: var(--bg);
  background: var(--heat);
  font-weight: 600;
}

.topnav a:focus-visible {
  outline: 2px solid var(--heat);
  outline-offset: 2px;
}

.updated {
  margin: 1.25rem 0 0;
  padding: 0 clamp(1.25rem, 4vw, 3rem);
  color: var(--text-muted);
  font-size: 0.9rem;
}

main {
  padding: 1.75rem clamp(1.25rem, 4vw, 3rem) 3rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-top: 3px solid var(--heat);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem 0.6rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.card-body {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
}

dl {
  margin: 0;
  flex: 1;
  min-width: 0;
}

/* --- Tank gauge (buffer / boiler current-values cards) -------------- */

.tank-wrap {
  position: relative;
  width: 100px;
  height: 160px;
  flex-shrink: 0;
  margin-top: 0.25rem;
}

.tank {
  position: absolute;
  top: 0;
  left: 0;
  width: 46px;
  height: 100%;
  border-radius: 23px;
  border: 1px solid var(--panel-border);
}

.tank-buffer {
  background: linear-gradient(180deg, var(--heat) 0%, var(--cold) 100%);
}

.tank-boiler {
  background: linear-gradient(180deg, var(--heat) 0%, var(--heat-dim) 100%);
}

.tank-level {
  position: absolute;
  left: 0;
  width: 46px;
  height: 2px;
  background: var(--text);
}

.tank-badge {
  position: absolute;
  left: 54px;
  transform: translateY(-50%);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}

.tank-badge::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 2px;
  margin-right: 5px;
  background: var(--text-muted);
  vertical-align: middle;
}

.tank-pct {
  position: absolute;
  left: 0;
  width: 46px;
  transform: translateY(-50%);
  text-align: center;
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--panel-border);
}

.row:last-child {
  border-bottom: none;
}

dt {
  color: var(--text-muted);
  font-size: 0.88rem;
}

dd {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.05rem;
}

.value.cold {
  color: var(--cold);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot.on {
  background: var(--ok);
  box-shadow: 0 0 6px 0 rgba(106, 154, 106, 0.55);
}

.dot.off {
  background: var(--off);
}

.status-text {
  font-size: 0.9rem;
  color: var(--text-muted);
}

a {
  color: var(--heat);
  text-decoration: none;
}

a:hover,
a:focus-visible {
  text-decoration: underline;
}

a:focus-visible {
  outline: 2px solid var(--heat);
  outline-offset: 2px;
}

/* --- Trends page ----------------------------------------------------- */

.trends-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1.75rem clamp(1.25rem, 4vw, 3rem) 0;
}

.trends-toolbar h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
}

.trends-toolbar-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.period-toggle {
  display: inline-flex;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.period-toggle button {
  background: var(--panel);
  color: var(--text-muted);
  border: none;
  padding: 0.45rem 0.9rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.period-toggle button + button {
  border-left: 1px solid var(--panel-border);
}

.period-toggle button.active {
  background: var(--heat);
  color: var(--bg);
  font-weight: 600;
}

.period-toggle button:focus-visible {
  outline: 2px solid var(--heat);
  outline-offset: -2px;
}

main.trends {
  display: block;
  padding: 0 clamp(1.25rem, 4vw, 3rem) 3rem;
}

.chart-wrap {
  position: relative;
  margin: 1.5rem 0 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  /* Chart.js's `responsive: true` measures this element to size the
     canvas - without `position: relative` it can't reliably shrink
     the canvas to fit a narrow (mobile) viewport. Height is set
     explicitly (paired with `maintainAspectRatio: false` in trends.php)
     because the canvas's intrinsic width/height attributes otherwise
     define a fixed aspect ratio - on a narrow phone viewport that
     squashed the chart down to ~100px tall, cramming the legend, both
     axes and the x-axis labels on top of each other. */
  height: 320px;
}

.chart-wrap-bottom {
  margin-top: 0.6rem;
  height: 200px;
}

.chart-wrap canvas {
  max-width: 100%;
}

/* --- Dashboard display-mode toggle + schematic view ------------------ */

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 1.25rem clamp(1.25rem, 4vw, 3rem) 0;
}

.view-toggle button {
  background: var(--panel);
  color: var(--text-muted);
  border: none;
  padding: 0.45rem 0.9rem;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.view-toggle button + button {
  border-left: 1px solid var(--panel-border);
}

.view-toggle button.active {
  background: var(--heat);
  color: var(--bg);
  font-weight: 600;
}

.view-toggle button:focus-visible {
  outline: 2px solid var(--heat);
  outline-offset: -2px;
}

.schematic-wrap {
  padding: 1.75rem clamp(1.25rem, 4vw, 3rem) 3rem;
}

.schematic {
  width: 100%;
  height: auto;
  /* On a wide desktop window the diagram's width (and so, via its fixed
     900x460 viewBox aspect ratio, its height) can grow past the visible
     viewport, forcing a scroll just to see the whole house. Capping the
     rendered box's height here doesn't distort or crop the diagram - the
     SVG's default `preserveAspectRatio` (xMidYMid meet) just scales the
     900x460 content down to fit inside a shorter box, centered, rather
     than stretching it. The subtracted 340px is the header/nav/"Last
     updated"/view-toggle chrome plus this wrap's own padding, measured
     on desktop; harmless if it's slightly off since the SVG only
     shrinks further; on mobile the diagram is already far shorter than
     this cap, so it never applies there.
  */
  max-height: calc(100vh - 340px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
}

.schem-ground {
  stroke: var(--panel-border);
  stroke-width: 2;
}

.schem-wall,
.schem-roof {
  fill: var(--panel);
  stroke: var(--panel-border);
  stroke-width: 2;
}

.schem-wall-mini,
.schem-roof-mini {
  fill: var(--panel);
  stroke: var(--panel-border);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.schem-house-label {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  fill: var(--text-muted);
}

.schem-tank {
  stroke: var(--panel-border);
  stroke-width: 2;
}

.schem-tank-level {
  stroke: var(--text);
  stroke-width: 2;
}

.schem-tick {
  stroke: var(--text-muted);
  stroke-width: 2;
}

.schem-pipe {
  stroke: var(--off);
  stroke-width: 6;
  stroke-linecap: round;
}

.schem-pipe.pipe-flow {
  stroke: var(--heat);
  stroke-dasharray: 10 8;
  animation: schem-flow 0.8s linear infinite;
}

@keyframes schem-flow {
  to {
    stroke-dashoffset: -18;
  }
}

.pump-dot {
  fill: var(--off);
}

.pump-dot.on {
  fill: var(--ok);
  filter: drop-shadow(0 0 4px rgba(106, 154, 106, 0.7));
}

.schem-room {
  fill: transparent;
  stroke: var(--panel-border);
  stroke-width: 2;
}

.schem-room.active {
  stroke: var(--heat);
}

.schem-radiator {
  fill: var(--off);
}

.schem-radiator.active {
  fill: var(--heat);
}

.schem-value {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 600;
  font-size: 22px;
  fill: var(--text);
  font-variant-numeric: tabular-nums;
}

.schem-value-lg {
  font-size: 32px;
}

.schem-value-bold {
  font-weight: 700;
}

.schem-value-sm {
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  fill: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.schem-on-tank {
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 3px;
  stroke-linejoin: round;
}

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