/* Wildfire sensor dashboard.
   Palette roles are declared once here so light/dark swap in one place and the
   rest of the sheet is written against roles, never raw hex. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  /* Categorical slots 1 and 2. Environment charts wear blue, fire-risk charts
     wear orange; the hue follows the group, never the value or the rank. */
  --series-env: #2a78d6;
  --series-fire: #eb6834;

  /* Status palette is fixed -- identical in both themes, never themed, and
     never reused for a data series. Always shipped with an icon + label. */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-env: #3987e5;
  --series-fire: #d95926;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

/* ---------- header ---------- */

header.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 12px 18px;
  margin-bottom: 22px;
}

.page-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.page-head .sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-left: auto;
}

/* ---------- status pill ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  font-size: 13px;
  font-weight: 550;
  color: var(--text-primary);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: var(--status-good);
}

.lvl-good    .dot, .dot.lvl-good    { background: var(--status-good); }
.lvl-warning .dot, .dot.lvl-warning { background: var(--status-warning); }
.lvl-serious .dot, .dot.lvl-serious { background: var(--status-serious); }
.lvl-critical .dot, .dot.lvl-critical { background: var(--status-critical); }

/* ---------- cards ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card h2 {
  margin: 0 0 2px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.card .card-note {
  margin: 0 0 14px;
  font-size: 12.5px;
  color: var(--text-muted);
}

section { margin-bottom: 20px; }

/* ---------- health checks ---------- */

.health-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.health-list li {
  display: grid;
  grid-template-columns: 22px minmax(120px, 160px) 1fr;
  gap: 10px;
  align-items: start;
  padding: 11px 12px;
  background: var(--surface-1);
  font-size: 13.5px;
}

/* The glyph is the non-color channel: status is never color alone. */
.health-list .glyph {
  font-size: 13px;
  line-height: 1.45;
  font-weight: 700;
  text-align: center;
}
.lvl-good     .glyph { color: var(--status-good); }
.lvl-warning  .glyph { color: var(--status-warning); }
.lvl-serious  .glyph { color: var(--status-serious); }
.lvl-critical .glyph { color: var(--status-critical); }

.health-list .name { font-weight: 550; color: var(--text-primary); }
.health-list .detail { color: var(--text-secondary); }
.health-list .state {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* ---------- hero ---------- */

.hero-row {
  display: grid;
  grid-template-columns: minmax(210px, 260px) 1fr;
  gap: 20px;
  align-items: stretch;
}

.hero .hero-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.hero .hero-value {
  font-size: 60px;
  font-weight: 650;
  line-height: 1.02;
  letter-spacing: -0.025em;
  /* Proportional figures: tabular-nums makes a big number look loose. */
}

.hero .hero-scale {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 6px;
}

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

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px 10px;
  min-width: 0;
}

.tile .t-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.tile .t-value {
  font-size: 25px;
  font-weight: 620;
  letter-spacing: -0.015em;
  line-height: 1.15;
  white-space: nowrap;
}

.tile .t-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 3px;
}

.tile .t-flag {
  font-size: 11.5px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
}

.tile svg { display: block; margin-top: 6px; }

/* ---------- filter row (one row, scopes every chart below) ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.filters .flabel {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-right: 2px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-1);
}

.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  padding: 6px 13px;
  cursor: pointer;
  min-height: 32px;
}

.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: color-mix(in srgb, var(--text-primary) 6%, transparent); }
.seg button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--text-primary) 10%, transparent);
  color: var(--text-primary);
  font-weight: 600;
}

.toggle-btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  padding: 6px 13px;
  min-height: 32px;
  cursor: pointer;
}
.toggle-btn:hover { background: color-mix(in srgb, var(--text-primary) 6%, transparent); }

/* ---------- chart grid (small multiples) ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.group-key {
  width: 18px;
  height: 3px;
  border-radius: 2px;
  flex: none;
}
.group-key.env  { background: var(--series-env); }
.group-key.fire { background: var(--series-fire); }

.chart-card { position: relative; }

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

.chart-title { font-size: 13.5px; font-weight: 600; }

.chart-last {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.chart-body { position: relative; }
.chart-body svg { display: block; width: 100%; height: auto; overflow: visible; }

.empty {
  padding: 26px 6px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* refetch holds the previous render rather than flashing a skeleton */
.stale { opacity: 0.55; transition: opacity 120ms ease; }

/* ---------- tooltip ---------- */

.tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--text-primary);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.13);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 90ms ease;
}
.tip.on { opacity: 1; }
.tip .tip-t { color: var(--text-muted); font-size: 11.5px; }
.tip .tip-v { font-weight: 620; font-variant-numeric: tabular-nums; }

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

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

table.readings {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

table.readings th,
table.readings td {
  text-align: right;
  padding: 6px 9px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

table.readings th {
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}

table.readings th:first-child,
table.readings td:first-child { text-align: left; }
table.readings tbody tr:hover td {
  background: color-mix(in srgb, var(--text-primary) 4%, transparent);
}

.loc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px 20px;
  font-size: 13.5px;
}
.loc-grid dt { color: var(--text-secondary); font-size: 12.5px; }
.loc-grid dd { margin: 2px 0 0; font-weight: 550; font-variant-numeric: tabular-nums; }

footer.page-foot {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .hero-row { grid-template-columns: 1fr; }
  .health-list li { grid-template-columns: 20px 1fr; }
  .health-list .detail { grid-column: 2; }
}
