:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good: #0ca30c;
  --critical: #d03b3b;
  --radius: 12px;
  --gauge-edge: rgba(11, 11, 11, 0.22);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --gauge-edge: transparent;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --gauge-edge: transparent;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  line-height: 1.4;
}
.top, main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 24px;
  padding-bottom: 8px;
}
h1 { margin: 0; font-size: 1.5rem; }
.status { margin: 4px 0 0; color: var(--text-2); font-size: 0.9rem; }
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}
.dot.online { background: var(--good); }
.dot.offline { background: var(--critical); }
.back {
  display: inline-block; margin-bottom: 8px; color: var(--accent);
  text-decoration: none; font-size: 0.9rem;
}
.back:hover { text-decoration: underline; }

/* ---------- Home: one card per room ---------- */
.rooms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 12px;
  padding: 16px 0 32px;
}
.room-card {
  display: block; color: inherit; text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.room-card:hover, .room-card:focus-visible { border-color: var(--accent); transform: translateY(-1px); }
.room-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.room-head h2 { margin: 0; font-size: 1.15rem; }
.room-status { color: var(--text-2); font-size: 0.8rem; }
.room-body { margin-top: 8px; }
.room-gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.room-more { display: block; margin-top: 12px; text-align: right; font-size: 0.85rem; color: var(--accent); }
.wide-only { display: none; }
.mini-chart h3 { margin: 0 0 2px; font-size: 0.8rem; font-weight: 600; color: var(--text-2); }
.mini-box { position: relative; height: 130px; }

/* Desktop: one row per room – dials on the left, 30-day graphs on the right */
@media (min-width: 1000px) {
  .rooms { grid-template-columns: 1fr; }
  .wide-only { display: block; }
  .room-body { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 24px; align-items: center; }
  .room-gauges { grid-template-columns: repeat(3, 170px); align-items: start; }
  .room-charts.wide-only { display: flex; flex-direction: column; gap: 10px; }
}

.section-title {
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-2); margin: 24px 0 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 { margin: 0 0 8px; font-size: 1rem; }

/* ---------- Gauges ---------- */
.gauges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.gauges > .card { width: 220px; }
.gauge { text-align: center; }
.gauge h3 { font-size: 0.95rem; font-weight: 600; color: var(--text-2); }
.gauge svg { width: 100%; max-width: 220px; display: block; margin: 0 auto; }
.gauge .track { stroke: var(--grid); }
.gauge .fill { stroke: var(--accent); transition: stroke-dasharray 0.6s ease; }
.gauge .fill-edge { stroke: var(--gauge-edge); }
.gauge .value { fill: var(--text); font-size: 30px; font-weight: 600; }
.gauge .unit { fill: var(--text-2); font-size: 14px; }
.gauge .end { fill: var(--muted); font-size: 11px; }
.day-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  border-top: 1px solid var(--grid); margin-top: 4px; padding-top: 10px;
}
.day-stats .v { display: block; font-size: 1rem; font-weight: 600; }
.day-stats .k { display: block; font-size: 0.75rem; color: var(--text-2); }
.day-label { grid-column: 1 / -1; margin: 0 0 2px; font-size: 0.75rem; color: var(--muted); letter-spacing: 0.04em; }

/* ---------- Range controls ---------- */
.history-head {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
}
.history-head .section-title { margin: 24px 0 0; }
.range-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 16px; }
.presets { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.presets button, .custom button, select, input {
  font: inherit; font-size: 0.9rem; color: var(--text);
  background: var(--surface); border: 0; padding: 6px 12px; cursor: pointer;
}
.presets button + button { border-left: 1px solid var(--border); }
.presets button:hover { background: var(--grid); }
.presets button.active { background: var(--accent); color: #fff; }
.custom { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.85rem; color: var(--text-2); }
.custom label { display: flex; gap: 6px; align-items: center; }
.custom input, select { border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; }
.custom button { border: 1px solid var(--border); border-radius: 8px; }
.custom button:hover { background: var(--grid); }
.range-label { color: var(--text-2); font-size: 0.9rem; margin: 12px 0; }

/* ---------- Stats table ---------- */
.stats-card { margin-bottom: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-2); font-weight: 600; font-size: 0.8rem; }
td { font-variant-numeric: tabular-nums; }
td.avg { font-weight: 600; }
tr:last-child td { border-bottom: 0; }

/* ---------- Charts ---------- */
.charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding-bottom: 32px;
}
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.chart-head .avg { color: var(--text-2); font-size: 0.85rem; }
.chart-box { position: relative; height: 240px; }
.empty { color: var(--muted); font-size: 0.9rem; padding: 24px 0; text-align: center; }

@media (max-width: 600px) {
  .gauges > .card { width: calc(50% - 6px); }
  .day-stats .v { font-size: 0.9rem; }
  .gauge .value { font-size: 26px; }
  .gauge h3 { font-size: 0.85rem; }
}
