:root {
  color-scheme: dark;
  --canvas: #0d1117;
  --surface: #161b22;
  --muted-surface: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --blue: #58a6ff;
  --green: #3fb950;
  --amber: #d29922;
  --outside: #d2a8ff;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--text); line-height: 1.5; }
a { color: var(--blue); }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.shell { width: min(100% - 3rem, 1320px); margin-inline: auto; }
.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link { position: absolute; z-index: 1; inset: .5rem auto auto .5rem; transform: translateY(-200%); padding: .55rem .8rem; background: var(--surface); }
.skip-link:focus { transform: none; }

.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-content { min-height: 62px; display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.wordmark { display: inline-flex; align-items: center; gap: .7rem; color: var(--text); text-decoration: none; font-size: .98rem; font-weight: 700; }
.wordmark-secondary { color: var(--muted); font-weight: 500; }
.brand-icon {
  position: relative;
  width: 27px;
  height: 25px;
  display: block;
  background: var(--blue);
  clip-path: polygon(50% 0, 100% 44%, 92% 54%, 86% 49%, 86% 100%, 14% 100%, 14% 49%, 8% 54%, 0 44%);
}
.brand-icon::after { content: ""; position: absolute; width: 9px; height: 11px; inset: auto 9px 0; border-radius: 5px 5px 0 0; background: var(--surface); }

.dashboard { padding-block: clamp(1.65rem, 4vw, 3.25rem); }
.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1.1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.page-heading h1 { font-size: clamp(1.75rem, 4vw, 2.6rem); font-weight: 700; line-height: 1.12; letter-spacing: -.04em; }
.station { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .25rem 1rem; margin-bottom: .75rem; }
.last-receipt { color: var(--muted); font-size: .8rem; }
.last-receipt time { margin-inline-start: .28rem; font-variant-numeric: tabular-nums; color: #c9d1d9; }
.device-line { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; color: var(--muted); font-size: .85rem; }
.device-name { overflow-wrap: anywhere; font-family: var(--mono); }
.dot { inline-size: .42rem; block-size: .42rem; background: var(--muted); border-radius: 50%; flex: none; }
.status { display: inline-flex; align-items: center; gap: .36rem; border: 1px solid var(--border); border-radius: 100px; padding: .15rem .52rem; font-size: .75rem; font-weight: 650; }
.status-online { color: #7ee787; background: #12261c; border-color: #234831; }
.status-online .dot, .dot-fresh { background: var(--green); }
.status-offline .dot, .dot-stale { background: var(--amber); }
.heading-controls { display: flex; align-items: start; gap: .6rem; flex-wrap: wrap; max-width: 100%; }
.period-picker { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
.period-picker a {
  padding: .56rem .85rem;
  min-height: 42px;
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
  font-size: .84rem;
  font-weight: 650;
  border-inline-end: 1px solid var(--border);
}
.period-picker a:last-child { border-inline-end: 0; }
.period-picker a:hover { color: var(--text); }
.period-picker a[aria-current] { background: #25364d; color: #a5d6ff; }
.period-picker a:first-child { border-start-start-radius: 6px; border-end-start-radius: 6px; }
.period-picker a:last-child { border-start-end-radius: 6px; border-end-end-radius: 6px; }
.device-picker { display: flex; gap: .4rem; min-width: 0; }
.device-picker select, .device-picker button {
  font: inherit;
  font-size: .83rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 44px;
  padding-inline: .6rem;
}
.device-picker select { min-width: 0; max-width: 17ch; }
.device-picker button { cursor: pointer; }

.readings { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .85rem; margin-bottom: 1.1rem; }
.metric, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; min-width: 0; }
.metric {
  position: relative;
  min-height: 151px;
  padding: 1rem clamp(.7rem, 1.8vw, 1.3rem);
  overflow: clip;
}
.metric-primary { background: #141f2b; border-color: #304962; }
.metric-primary::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--blue); }
.metric h2 { font-size: .86rem; font-weight: 650; color: #c9d1d9; }
.reading { margin-block: .36rem .42rem; display: flex; align-items: baseline; gap: .18rem; }
.reading-value { font-size: clamp(1.6rem, 4vw, 2.85rem); font-weight: 650; letter-spacing: -.06em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.reading-unit { color: var(--muted); font-size: clamp(.83rem, 2vw, 1.17rem); font-weight: 600; }
.reading-empty { font-size: clamp(.98rem, 2.2vw, 1.3rem); font-weight: 650; line-height: 2; color: var(--muted); }
.freshness { display: flex; align-items: center; gap: .38rem; }
.freshness, .conditions, .metric-note { color: var(--muted); font-size: .79rem; }
.conditions { margin-top: .24rem; }

.chart-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; flex-wrap: wrap; gap: .4rem .75rem; padding: 1rem 1.15rem .65rem; }
.panel-heading h2, .unavailable h2 { font-size: 1.04rem; font-weight: 650; }
.panel-heading p, .empty-chart { color: var(--muted); font-size: .8rem; }
.panel-heading p { margin-top: .18rem; }
.legend { display: flex; flex-wrap: wrap; gap: .35rem .75rem; font-size: .76rem; color: #c9d1d9; }
.legend span { display: inline-flex; align-items: center; gap: .32rem; white-space: nowrap; }
.legend-line { inline-size: .9rem; block-size: 0; border-top: 2px solid var(--blue); }
.legend-line.outdoor { border-color: var(--outside); border-top-style: dashed; }
.plot { position: relative; height: clamp(205px, 31vw, 290px); margin: .75rem .9rem 1rem .6rem; }
.empty-chart { margin: .7rem 1.15rem 1rem; min-height: 175px; display: grid; place-items: center; text-align: center; border: 1px dashed var(--border); border-radius: 6px; padding: 1rem; }
.chart-data { border-top: 1px solid var(--border); font-size: .82rem; }
.chart-data summary { cursor: pointer; color: var(--blue); padding: .65rem 1.15rem; }
.table-scroll { max-height: 240px; overflow: auto; }

.summary-grid { margin-top: 1rem; max-width: 640px; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; }
th, td { border-top: 1px solid var(--border); padding: .47rem .85rem; text-align: end; }
th:first-child { text-align: start; }
thead th { color: var(--muted); font-weight: 600; }
tbody th { color: #c9d1d9; font-weight: 500; }
.summary-table { margin-block: .25rem .45rem; }
.unavailable { padding: 1.15rem; }
.unavailable p { margin-block: .3rem .7rem; color: var(--muted); }
.request-error { border: 1px solid #713b40; background: #321b24; border-radius: 6px; padding: .65rem .85rem; margin-bottom: .75rem; }

@media (max-width: 860px) {
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .plot { height: clamp(215px, 45vw, 290px); }
}

@media (max-width: 620px) {
  .shell { width: calc(100% - 1.5rem); }
  .topbar-content { min-height: 52px; }
  .page-heading { align-items: start; flex-direction: column; margin-bottom: 1.05rem; }
  .heading-controls, .period-picker { width: 100%; }
  .period-picker a { flex: 1; padding-inline: .4rem; }
  .readings { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .metric { min-height: 123px; }
  .chart-grid, .summary-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: .7rem; }
  .summary-grid { margin-top: .7rem; }
  .panel-heading { padding-inline: .82rem; }
  .plot { margin-inline: .35rem .65rem; }
  th, td { padding-inline: .55rem; }
}

.sign-out {
  min-height: 42px;
  padding: .35rem .75rem;
  background: var(--muted-surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  font: inherit;
  font-size: .83rem;
  cursor: pointer;
}
.sign-out:hover { border-color: var(--muted); }
