:root {
  color-scheme: light;
  --background: #f5f5f1;
  --surface: #ffffff;
  --border: #d9d7cf;
  --border-strong: #aaa69b;
  --text: #292724;
  --muted: #69655e;
  --amber: #a44f13;
  --olive: #64722e;
  --green: #26735b;
  --red: #a33a32;
  --grid: #e9e7df;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

.topbar {
  padding: 10px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px 24px;
  flex-wrap: wrap;
}

h1, h2, p { margin: 0; }
h1 { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; }
.identity { min-width: 12rem; }
.identity p, .section-heading > span { color: var(--muted); font-size: 13px; }
.identity p { margin-top: 2px; }

.timespan { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: nowrap; }
.timespan-sep { color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.timespan label, .timezone-note { color: var(--muted); font-size: 13px; }
input[type="datetime-local"] { padding: 0 8px; width: 13.2rem; }
.node-filter { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; margin: 0; padding: 8px 10px 10px; border: 0; }
.node-filter label { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.node-filter label:hover { background: #fafaf8; }
.node-filter input { accent-color: var(--text); }
.node-swatch { width: 8px; height: 8px; border-radius: 50%; }
select, button, input[type="datetime-local"] {
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font: inherit;
}
input[type="datetime-local"] { padding: 0 8px; width: 13.2rem; }
button { cursor: pointer; background: var(--text); color: #fff; border-color: var(--text); }
button:hover { background: #46423c; }
button:disabled { cursor: wait; opacity: 0.6; }
button.secondary { background: var(--surface); color: var(--text); }
button.secondary:hover { background: #eeece6; }
#action-status { color: var(--muted); font-size: 13px; min-width: 52px; }
.timezone-note { white-space: nowrap; }

main { max-width: 1320px; margin: 0 auto; padding: 24px 28px 48px; }
section { background: var(--surface); border: 1px solid var(--border); }
.overview { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 16px; margin-bottom: 16px; }
.overview .current, .nodes-card { margin-bottom: 0; }
.current, .plot-section, .attempts { margin-bottom: 16px; }

.section-heading {
  min-height: 48px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.section-heading > span { margin: 0; }

.readings {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  margin: 0;
}
.readings > div { padding: 14px 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.readings > div:nth-child(4n) { border-right: 0; }
.readings > div:nth-last-child(-n + 4) { border-bottom: 0; }
dt { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
dd { margin: 0; font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 620; }

.legend { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: 13px; }
.legend span::before { content: ""; display: inline-block; width: 18px; height: 2px; margin: 0 6px 3px 0; }
.adc-key::before { background: var(--amber); }
.bq-key::before { background: var(--olive); }
.soh-key::before { background: var(--green); }

.chart { height: 280px; padding: 10px 8px 4px; display: flex; flex-direction: column; }
.chart.compact { height: 230px; }
.chart svg { width: 100%; min-height: 0; flex: 1; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .series { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .series.secondary { stroke-dasharray: 5 3; }
.chart .empty { fill: var(--muted); font-size: 13px; }

.plot-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.plot-pair .plot-section { min-width: 0; }

.attempts-more {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}
.attempts-more button { min-width: 140px; }
.attempts-more[hidden] { display: none; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 550; background: #fafaf8; }
tbody tr:last-child td { border-bottom: 0; }
.result-ok { color: var(--green); }
.result-failed { color: var(--red); }

#error {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 440px;
  padding: 12px 14px;
  border: 1px solid #d39a94;
  border-radius: 6px;
  background: #fff4f2;
  color: #752923;
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; padding: 14px 16px; }
  .actions { margin-left: 0; }
  main { padding: 16px; }
  .overview { grid-template-columns: 1fr; }
  .readings { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .readings > div:nth-child(4n) { border-right: 1px solid var(--border); }
  .readings > div:nth-child(2n) { border-right: 0; }
  .readings > div:nth-last-child(-n + 4) { border-bottom: 1px solid var(--border); }
  .readings > div:nth-last-child(-n + 2) { border-bottom: 0; }
  .plot-pair { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 540px) {
  .topbar { display: block; }
  .timespan, .actions { margin-top: 12px; }
  .readings { grid-template-columns: 1fr; }
  .readings > div { border-right: 0 !important; border-bottom: 1px solid var(--border) !important; }
  .readings > div:last-child { border-bottom: 0 !important; }
  .chart { height: 230px; }
}
