:root {
  --bg: #12151a;
  --fg: #e8ebf0;
  --muted: #8b94a3;
  --card: #1b2028;
  --line: #2d3440;
  --ok: #3fb950;
  --warn: #e3b341;
  --bad: #f85149;
  --accent: #58a6ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
}
[hidden] { display: none !important; }

h1 { margin: 0 0 16px; text-align: center; font-weight: 600; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }

.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 20px; }
form { display: flex; flex-direction: column; gap: 12px; max-width: 340px; width: 100%; margin: 0 auto; }
input, select {
  padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); font-size: 16px;
}
select { padding: 6px 8px; font-size: 14px; }
button {
  padding: 11px 14px; border-radius: 8px; border: 0; background: #2f6feb;
  color: #fff; font-size: 15px; cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.small, .tabs button {
  padding: 6px 10px; font-size: 13px; background: var(--card); color: var(--fg); border: 1px solid var(--line);
}
.okmsg { color: var(--ok); min-height: 1.2em; font-size: 14px; margin: 0; text-align: center; }
.login .center { text-align: center; margin: 14px 0 0; }
.error { color: var(--bad); min-height: 1.2em; font-size: 14px; margin: 0; text-align: center; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
header { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 14px; }
.small-text { font-size: 12px; text-align: center; }

.banner {
  background: #3a2f12; border: 1px solid #6b5518; color: #f0d98a;
  padding: 10px 12px; border-radius: 8px; font-size: 14px; margin: 8px 0;
}
.banner.err { background: #3a1616; border-color: #7a2a2a; color: #ffb4ae; }

.reading { text-align: center; padding: 12px 0 6px; }
.value { font-size: clamp(72px, 22vw, 112px); font-weight: 700; line-height: 1; }
.trend { font-size: 40px; min-height: 48px; }
.reading.ok .value { color: var(--ok); }
.reading.high .value { color: var(--warn); }
.reading.low .value { color: var(--bad); }
.reading.stale .value { opacity: 0.45; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin: 8px 0; }
.tabs button.active { background: #2f6feb; border-color: #2f6feb; }

.rangebar { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; }
#rangeLabel { flex: 1; text-align: center; font-size: 13px; }
.customrange { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; }
.customrange label { display: flex; flex-direction: column; gap: 4px; flex: 1 1 150px; font-size: 12px; color: var(--muted); }
.customrange input { font-size: 14px; min-width: 0; }
button:disabled { opacity: 0.4; cursor: default; filter: none; }
.statsinfo { margin: -4px 0 8px; }
.chartwrap { position: relative; }
canvas { width: 100%; height: 280px; display: block; background: var(--card); border-radius: 10px; touch-action: pan-y; cursor: grab; user-select: none; }
canvas.grabbing { cursor: grabbing; }
.tip {
  position: absolute; pointer-events: none; background: #0b0d11; border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -100%);
}

.noteshead { margin: 20px 0 8px; }
.notebox { background: var(--card); border-radius: 10px; padding: 10px 12px; }
.notebox summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.notebox form { display: flex; flex-direction: column; gap: 10px; max-width: none; margin: 12px 0 0; }
.notebox .row { display: flex; gap: 8px; }
.notebox .row select, .notebox .row input { flex: 1; min-width: 0; }
.notelist { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.note { background: var(--card); border-radius: 10px; padding: 10px 12px; }
.notehead { display: flex; gap: 8px; align-items: center; }
.notetext { margin: 4px 0; overflow-wrap: anywhere; }
.note .muted { font-size: 12px; }
.noteactions { margin-top: 6px; display: flex; gap: 6px; }
.spike {
  max-width: none; margin: 8px 0; background: var(--card); border-radius: 10px;
  border-left: 4px solid var(--warn); padding: 12px; gap: 10px;
}
.spike .row { display: flex; gap: 8px; }
.spike .row select, .spike .row input { flex: 1; min-width: 0; }
.spike .title { font-weight: 600; }
/* on narrow screens the type and date/time fields get a line each, so the date is not cut off */
@media (max-width: 520px) {
  .spike .row.pair, .notebox .row.pair { flex-direction: column; }
}
.statshead { display: flex; align-items: center; gap: 10px; margin: 20px 0 8px; }
.statshead h2 { flex: 1; }
.statshead { margin-bottom: 8px; }
.linkbtn { color: var(--accent); font-size: 13px; text-decoration: none; }
.linkbtn:hover { text-decoration: underline; }

.tir { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--card); }
.seg.low { background: var(--bad); }
.seg.ok { background: var(--ok); }
.seg.high { background: var(--warn); }
.tirlegend { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 13px; margin: 8px 0 12px; color: var(--muted); }
.tirlegend b { color: var(--fg); margin-left: 4px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.low { background: var(--bad); }
.dot.ok { background: var(--ok); }
.dot.high { background: var(--warn); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--card); border-radius: 10px; padding: 12px; }
.big { font-size: 24px; font-weight: 600; margin-top: 4px; }

.disclaimer { margin: 20px 0 0; font-size: 11px; color: var(--muted); text-align: center; }
