:root {
  --bg: #0f1115;
  --panel: #171a21;
  --line: #262b36;
  --text: #e6e9ef;
  --muted: #8b93a3;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --accent: #4fc3f7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--line);
}
header h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
#status { color: var(--muted); font-size: 13px; margin-left: auto; }
#status.stale { color: var(--warn); }
#status.error { color: var(--bad); }

main { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }

/* Room cards ------------------------------------------------------------- */
#cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--seriescolor, var(--accent));
  border-radius: 10px;
  padding: 14px 16px;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: opacity .12s, border-color .12s;
}
.card:hover { border-color: var(--seriescolor, var(--accent)); }
.card.muted { opacity: .38; }
.card .name { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

/* Humidity and temperature carry the same weight. Damp is the reason this
 * exists, but the two only mean anything together: the same moisture reads as
 * a different RH in a colder room, so shrinking one of them hides half the
 * story. Colour still does the flagging, size does not. */
.card .readings { display: flex; gap: 14px; }
.card .reading { flex: 1 1 0; min-width: 0; }
.card .value { font-size: 27px; font-weight: 650; letter-spacing: -0.02em; }
.card .unit { font-size: 15px; font-weight: 500; margin-left: 2px; }
.card .value.ok { color: var(--ok); }
.card .value.warn { color: var(--warn); }
.card .value.bad { color: var(--bad); }
.card .value.temp { color: var(--text); }
.card .rlabel { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* Controls --------------------------------------------------------------- */
#ranges { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
#ranges button {
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 15px; font-size: 13px; cursor: pointer;
}
#ranges button:hover { color: var(--text); }
#ranges button[aria-pressed="true"] {
  color: var(--text); border-color: var(--accent); background: #1d2531;
}
#ranges button.ghost { margin-left: auto; }
/* Sits directly after the range buttons; .ghost's auto margin takes the rest
 * of the row, so this needs no margin of its own. */
#ranges .hint { font-size: 12px; color: var(--muted); }
/* Derived figures sit BELOW the two headline readings and stay smaller than
 * them. The rule from the headline row applies here too: nothing added may
 * shrink temperature relative to humidity — these carry meaning by colour and
 * position, never by taking size from the numbers above. */
.card .derived {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-top: 9px; padding-top: 8px;
  border-top: 1px solid var(--border, #262b36);
  font-size: 12px; color: var(--muted);
}
.card .derived .unit { font-size: 10px; margin-left: 2px; font-weight: 500; }
.card .derived .risk { color: var(--warn); }
.card .derived .margin { font-weight: 650; }

/* The verdict is the one thing on the card you can act on, so it gets a colour
 * block. Red is reserved for the mould threshold elsewhere, so "keep shut" is
 * amber rather than red -- shutting a window is not an emergency. */
.card .vent {
  margin-top: 7px; padding: 3px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 650; letter-spacing: .02em;
  display: flex; gap: 7px; align-items: baseline; flex-wrap: wrap;
}
.card .vent .vd, .card .vent .vc { font-weight: 500; opacity: .85; }
.card .vent.open { background: rgba(129,199,132,.15); color: #81c784; }
.card .vent.shut { background: rgba(255,213,79,.13);  color: #ffd54f; }
.card .vent.none { background: rgba(139,147,163,.12); color: var(--muted); }
.card .vent.ref  { background: transparent; color: var(--muted);
                   font-weight: 500; padding-left: 0; }

.card .batt { font-size: 11px; color: var(--muted); margin-top: 10px; }

/* Companion cursor: the same clock time 24 h earlier. Dotted so it never reads
 * as the live crosshair, and pointer-events:none so it cannot eat the mouse. */
.u-companion {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px dotted #7f8899;
  pointer-events: none;
  display: none;
}
.u-companion-tag {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 10px;
  color: #7f8899;
  white-space: nowrap;
}

/* Charts ----------------------------------------------------------------- */
.chart-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 6px;
  margin-bottom: 18px;
}
.chart-panel h2 {
  margin: 0 0 4px; font-size: 14px; font-weight: 600;
}
.chart-panel p.note { margin: 0 0 10px; font-size: 12px; color: var(--muted); }

.u-legend { font-size: 12px; }
.u-legend .u-marker { width: 10px; height: 10px; border-radius: 2px; }

#empty, #error {
  padding: 40px; text-align: center; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 10px;
}
#error { color: var(--bad); border-color: #45252b; white-space: pre-wrap; text-align: left; }
[hidden] { display: none !important; }

/* uPlot's legend is a control here, not a caption. */
.u-legend .u-series { cursor: pointer; }
.u-legend .u-series.u-off { opacity: .4; }
.u-over { touch-action: none; }
