:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e4e3df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --grid: #ecebe7;
  --series: #2a78d6;
  --series-hover: #1c5cab;
  --series-est: #86b6ef;
  --ref: #8a8984;
  --ok: #0a7d0a;
  --bad: #c22f2f;
  --warn: #9a6500;
  --accent: #2a78d6;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --border: #2c2c2a;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --grid: #2a2a28;
    --series: #3987e5;
    --series-hover: #6da7ec;
    --series-est: #1c5cab;
    --ref: #a3a29b;
    --ok: #2fbf2f;
    --bad: #e66767;
    --warn: #e0a326;
    --accent: #6da7ec;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
main { max-width: 1080px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 8px 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { color: var(--text-2); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.top nav a[aria-current] { color: var(--text); background: var(--bg); font-weight: 550; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.status { color: var(--text-2); font-size: .9rem; }
.status.ok::first-letter { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.warn { color: var(--warn); }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; color: var(--text-2); font: inherit; padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.seg.small button { font-size: .85rem; padding: 3px 10px; }

.hero { display: grid; grid-template-columns: minmax(220px, 1fr) 2.2fr; gap: 24px; align-items: center; }
.label { color: var(--text-2); font-size: .9rem; }
.big { font-size: clamp(2.4rem, 7vw, 3.4rem); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; margin: 4px 0; }
.sub { color: var(--text-2); font-size: .88rem; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 18px; margin: 0; }
.tiles dt { color: var(--text-2); font-size: .8rem; }
.tiles dd { margin: 2px 0 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.tiles small { display: block; font-size: .75rem; font-weight: 400; color: var(--muted); }
@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}

.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.legend { color: var(--text-2); font-size: .85rem; display: flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 8px; }
.key-bar { background: var(--series); }
.key-ref { height: 2px; border-radius: 0; background: var(--ref); }
.key-avg { height: 0; border-radius: 0; border-top: 1px dashed var(--text-2); margin-left: 0; }
.chart-head h2 { margin-right: auto; }
.chart { width: 100%; min-height: 220px; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--muted); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series); }
.chart .bar-est { fill: var(--series-est); }
.key-est { background: var(--series-est); }
.chart .ref { fill: none; stroke: var(--ref); stroke-width: 2; stroke-linejoin: round; }
.chart .avg { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .avg-label { fill: var(--text-2); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit.on { fill: var(--text); fill-opacity: .05; }
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: .82rem; box-shadow: 0 4px 16px rgb(0 0 0 / .14); white-space: nowrap; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }

details { margin-top: 10px; }
summary { color: var(--text-2); font-size: .85rem; cursor: pointer; }
table.small { border-collapse: collapse; width: 100%; font-size: .85rem; margin-top: 8px; font-variant-numeric: tabular-nums; }
table.small caption { text-align: left; color: var(--text-2); padding: 12px 0 4px; }
table.small th, table.small td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); }
table.small .num { text-align: right; }
details table.small { max-height: 320px; display: block; overflow: auto; }

form.card label { display: block; margin: 12px 0; font-weight: 550; font-size: .9rem; }
form.card input { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); }
button[type="submit"] { font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 9px; border: 0; background: var(--series); color: #fff; cursor: pointer; }
.hint { display: block; color: var(--text-2); font-size: .82rem; font-weight: 400; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .grid2 { grid-template-columns: 1fr; } }
.msg { padding: 10px 14px; border-radius: 10px; }
.msg.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.msg.err { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.warn { color: var(--warn); }
.login { max-width: 360px; margin: 10vh auto 0; }

.calib-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; align-items: start; }
.calib-form label { display: block; font-weight: 550; font-size: .9rem; }
.calib-form input[type="datetime-local"], .calib-form .with-unit input { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 9px 11px;
  border-radius: 9px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.calib-form #c-meter { font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; padding-right: 44px; }
.with-unit { position: relative; display: block; }
.with-unit > span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-2); margin-top: 2px; }
.calib-form .check { grid-column: 1 / -1; display: flex; gap: 10px; align-items: flex-start; font-weight: 550; }
.calib-form .check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--series); flex: none; }
.calib-form button { grid-column: 1 / -1; justify-self: start; }
@media (max-width: 600px) { .calib-form { grid-template-columns: 1fr; } }
.c-result { margin-top: 14px; padding: 10px 14px; border-radius: 10px; font-size: .9rem; }
.c-result.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.c-result.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); }
.c-result.err { background: color-mix(in srgb, var(--bad) 14%, transparent); }
tr.off td:nth-child(4) { color: var(--bad); font-weight: 600; }
button.link { background: none; border: 0; padding: 0; color: var(--text-2); font: inherit; font-size: .8rem; text-decoration: underline; cursor: pointer; }
h3 { font-size: .95rem; margin: 0 0 4px; }
.sub-form label { display: block; margin: 10px 0; font-weight: 550; font-size: .9rem; }
.sub-form input, .sub-form textarea { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.sub-form textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.row2 label { margin: 10px 0; }
#history { margin-top: 16px; }
#history .grid2 { margin-top: 8px; }
#history table.small { display: table; max-height: none; }
form.inline { display: inline; margin: 0; }
#c-history { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#c-history table.small { max-height: none; display: table; }
#c-history td.num, #c-history th { white-space: nowrap; }
ul.links { padding-left: 18px; }
ul.links li { margin: 4px 0; }
code { font-size: .85em; background: var(--bg); padding: 1px 5px; border-radius: 5px; }
