/* Climate Station — precision-instrument aesthetic.
   Chart color roles come from the validated reference palette:
   temperature = slot 2 (orange), humidity = slot 1 (blue). */

:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --series-temp:    #eb6834;
  --series-hum:     #2a78d6;
  --good:           #0ca30c;
  --critical:       #d03b3b;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-temp:    #d95926;
    --series-hum:     #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --series-temp:    #d95926;
  --series-hum:     #3987e5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  background-image: radial-gradient(color-mix(in oklab, var(--text-muted) 14%, transparent) 1px, transparent 1px);
  background-size: 26px 26px;
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
}

.frame {
  max-width: 1060px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--baseline);
}

.masthead-id { display: flex; align-items: center; gap: 14px; }

.glyph {
  font-size: 22px;
  color: var(--series-temp);
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: 0.35; } }

.masthead h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sub {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.masthead-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-dot[data-state="live"]       { background: var(--good); }
.status-dot[data-state="connecting"] { background: var(--text-muted); animation: pulse 1.2s infinite; }
.status-dot[data-state="down"]       { background: var(--critical); }

.status-text { color: var(--text-secondary); letter-spacing: 0.06em; }

.divider { width: 1px; height: 14px; background: var(--baseline); }

/* ---------- stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 14px;
  margin: 22px 0;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 18px 12px;
}

.tile-label {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tile-value {
  margin: 0;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 34px;
  line-height: 1.1;
}

.tile-hero .tile-value { font-size: 52px; }

.tile-unit {
  margin-left: 6px;
  font-size: 15px;
  font-weight: 400;
  color: var(--text-secondary);
}

.tile-delta {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
  min-height: 1.2em;
}

/* ---------- panels & charts ---------- */

.panel { margin: 26px 0; }

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.panel-note {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.range-row { display: flex; gap: 6px; }

.range-row button {
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}

.range-row button:hover { color: var(--text-primary); }

.range-row button[aria-checked="true"] {
  color: var(--text-primary);
  border-color: var(--text-primary);
  font-weight: 600;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.chart-card {
  margin: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 14px 8px;
}

.chart-card figcaption {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.unit-tag { color: var(--text-muted); font-weight: 400; }

.chart { position: relative; height: 220px; }

.chart.refetching svg { opacity: 0.45; transition: opacity 0.15s; }

.chart svg { display: block; width: 100%; height: 100%; }

.chart .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* tooltip */

.viz-tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  padding: 6px 10px;
  font-family: var(--mono);
  white-space: nowrap;
  z-index: 5;
  display: none;
}

.viz-tip .tip-value { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.viz-tip .tip-key {
  display: inline-block;
  width: 12px; height: 0;
  border-top: 2px solid;
  vertical-align: middle;
  margin-right: 6px;
}
.viz-tip .tip-time { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* ---------- table view ---------- */

.table-fold {
  margin: 26px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
}

.table-fold summary {
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  cursor: pointer;
}

.table-scroll { overflow-x: auto; }

#readings-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 13px;
}

#readings-table th, #readings-table td {
  text-align: left;
  padding: 7px 16px;
  border-top: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}

#readings-table th {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 500;
}

.colophon {
  margin-top: 30px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 760px) {
  .tiles { grid-template-columns: 1fr; }
  .chart-grid { grid-template-columns: 1fr; }
  .tile-hero .tile-value { font-size: 42px; }
}
