:root {
  --bg: #f3f2ef;
  --surface: #fcfcfb;
  --surface-2: #ecebe7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --axis: #898781;
  --grid: #e1e0d9;
  --border: #e1e0d9;
  --series: #2a78d6;
  --series-range: rgb(42 120 214 / 0.4);
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --warning-text: #8a5a00;
  --critical: #d03b3b;
  --on-critical: #ffffff;
  --accent: #2a78d6;
  --radius: 14px;
  --gutter: 16px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #2a2a28;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a3a29b;
    --axis: #898781;
    --grid: #2c2c2a;
    --border: #2c2c2a;
    --series: #3987e5;
    --series-range: rgb(57 135 229 / 0.5);
    --good-text: #0ca30c;
    --warning-text: #fab219;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

main, .top {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

main { display: grid; gap: 16px; padding-bottom: 32px; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
  padding-bottom: 10px;
}

h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: 0.95rem; margin: 0 0 6px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }

/* Live indicator */
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--ink-2); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--axis); }
.live[data-state="live"] .dot { background: var(--good); }
.live[data-state="lost"] .dot { background: var(--warning); }

/* Active alerts */
.alerts { display: grid; gap: 8px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
}
.alert[data-level="critical"] { background: var(--critical); color: var(--on-critical); border-color: transparent; }
.alert[data-level="warning"] { border-left: 4px solid var(--warning); }
.alert .badge { font-weight: 700; white-space: nowrap; }
.alert .since { font-size: 0.85rem; opacity: 0.85; }
.alert-text { flex: 1; min-width: 0; }
.alert .ack {
  flex: none; align-self: center; min-width: 44px; min-height: 44px; padding: 0 14px;
  border: 1px solid currentColor; border-radius: 10px; background: transparent;
  color: inherit; font-weight: 600; cursor: pointer;
}
/* Seen: still listed, no longer asking for attention. */
.alert[data-ack] { background: var(--surface); color: var(--ink-2); border: 1px solid var(--border); }
.alert[data-ack][data-level="critical"] { border-left: 4px solid var(--critical); }
.alert[data-ack][data-level="warning"] { border-left: 4px solid var(--warning); }

/* The week */
.week-body { display: grid; gap: 4px 16px; margin: 0; }
.week-body dt { font-weight: 600; margin-top: 8px; }
.week-body dd { margin: 0; color: var(--ink-2); overflow-wrap: anywhere; }
.week-list { margin: 0; padding-left: 1.1em; }
.week-list time { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Safety hero cards */
.safety { display: grid; gap: 12px; }
.hero {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px 14px;
  align-items: center;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.hero-icon {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2);
}
.hero-icon svg { width: 28px; height: 28px; }
.hero[data-level="ok"] .hero-icon { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good-text); }
.hero[data-level="warning"] .hero-icon { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--warning-text); }
.hero-kicker { font-size: 0.85rem; color: var(--ink-2); }
.hero-state { font-size: 1.35rem; font-weight: 700; line-height: 1.2; margin: 2px 0; }
.hero-sub { font-size: 0.9rem; color: var(--ink-2); }
.hero-advice { grid-column: 1 / -1; font-weight: 600; }
.hero[data-level="critical"] {
  background: var(--critical); color: var(--on-critical); border-color: transparent;
  animation: pulse 1.6s ease-in-out infinite;
}
.hero[data-level="critical"] .hero-kicker,
.hero[data-level="critical"] .hero-sub { color: var(--on-critical); }
.hero[data-level="critical"] .hero-icon { background: rgb(255 255 255 / 0.2); color: var(--on-critical); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--critical) 35%, transparent); } }
@media (prefers-reduced-motion: reduce) { .hero[data-level="critical"] { animation: none; } }

.chips { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.chip {
  display: inline-flex; gap: 6px; align-items: baseline;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 0.85rem;
}
.hero[data-level="critical"] .chip { background: rgb(255 255 255 / 0.18); }
.chip dt { color: var(--ink-2); }
.hero[data-level="critical"] .chip dt { color: var(--on-critical); }
.chip dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip[data-flag="bad"] dd { color: var(--critical); }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 12px;
  min-width: 0;
}
.panel-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }

.range { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.range button {
  border: 0; background: transparent; color: var(--ink-2);
  font: inherit; font-size: 0.85rem; padding: 6px 11px; border-radius: 8px; min-height: 32px;
  cursor: pointer;
}
.range button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }

/* Charts */
.charts { display: grid; gap: 22px; min-width: 0; }
.chart { min-width: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.chart-summary { font-size: 0.85rem; color: var(--ink-2); }
.chart-body { position: relative; min-height: 40px; }
.chart-empty { font-size: 0.9rem; color: var(--muted); padding: 10px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: var(--ink-2); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.legend i.tick { width: 2px; height: 12px; border-radius: 1px; background: var(--ink-2); }
.timeline { display: block; width: 100%; touch-action: pan-y; }
.timeline text { fill: var(--axis); font-size: 11px; }
.u-over { touch-action: pan-y; }

/* Tooltip */
.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--ink); color: var(--surface);
  padding: 6px 9px; border-radius: 8px; font-size: 0.8rem; line-height: 1.35;
  max-width: 240px; box-shadow: 0 4px 14px rgb(0 0 0 / 0.2);
}
.tip strong { font-variant-numeric: tabular-nums; }

/* Events */
.events { list-style: none; margin: 0; padding: 0; display: grid; }
.events li {
  display: grid; grid-template-columns: 22px 1fr; gap: 2px 8px;
  padding: 9px 0; border-top: 1px solid var(--border);
}
.events li:first-child { border-top: 0; }
.events .lvl { width: 14px; height: 14px; margin-top: 4px; }
.events .msg { min-width: 0; overflow-wrap: anywhere; }
.events time { grid-column: 2; font-size: 0.8rem; color: var(--muted); }
.events li.empty { display: block; color: var(--muted); }

/* Devices */
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.devices li { padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.devices .meta { font-size: 0.8rem; color: var(--muted); }
.devices .vals { font-size: 0.9rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Buttons */
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button { font: inherit; }
#notif-on, #notif-test {
  border: 0; border-radius: 10px; padding: 10px 14px; min-height: 44px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600;
}
button.secondary { background: var(--surface-2) !important; color: var(--ink) !important; }
button.link {
  border: 0; background: none; color: var(--accent); padding: 8px 0; min-height: 44px;
  cursor: pointer; justify-self: start;
}

.foot { font-size: 0.8rem; color: var(--muted); text-align: center; }

/* Login and enrolment */
.auth-page { min-height: 100dvh; display: grid; place-items: center; }
.auth {
  width: min(380px, calc(100vw - 2 * var(--gutter)));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px 22px; display: grid; gap: 14px; justify-items: center; text-align: center;
}
.auth-logo { border-radius: 16px; }
.auth h1 { font-size: 1.35rem; }
button.primary {
  border: 0; border-radius: 10px; padding: 12px 18px; min-height: 48px; width: 100%;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
button.primary:disabled { opacity: 0.55; cursor: default; }
.auth-status { min-height: 1.4em; font-size: 0.9rem; color: var(--ink-2); }
.auth-status[data-kind="error"] { color: var(--critical); }

/* Passkeys */
.passkeys { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.passkeys li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--surface-2); border-radius: 10px;
}
.passkeys .meta { font-size: 0.8rem; color: var(--muted); }
.passkeys button { flex: none; }
button.secondary {
  border: 0; border-radius: 10px; padding: 10px 14px; min-height: 44px; font-weight: 600; cursor: pointer;
}
