:root {
  --bg: #060d14;
  --bg2: #0a1722;
  --card: rgba(18, 36, 50, .72);
  --card-solid: #102331;
  --line: rgba(140, 200, 220, .14);
  --line2: rgba(140, 200, 220, .26);
  --text: #eaf7fb;
  --muted: #8fb0bd;
  --faint: #5d7d8a;
  --accent: #2ee6c5;
  --accent2: #7c9cff;
  --accent-ink: #032a24;
  --warn: #ffcf5c;
  --bad: #ff7a7a;
  --good: #46e39b;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --k-voice: #6fd3ff;
  --k-noise: #ffcf5c;
  --k-car: #ff9f6e;
  --k-air: #b99cff;
  --k-dog: #ff7ab8;
  --k-moto: #ff6b6b;
  --k-test: #9ab0bb;
  --k-other: #46e39b;
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #eef4f7;
  --bg2: #ffffff;
  --card: rgba(255, 255, 255, .9);
  --card-solid: #ffffff;
  --line: rgba(10, 50, 70, .12);
  --line2: rgba(10, 50, 70, .24);
  --text: #06202c;
  --muted: #3f5f6c;
  --faint: #6c8792;
  --accent: #00927b;
  --accent2: #3b5bdb;
  --accent-ink: #ffffff;
  --warn: #b7791f;
  --bad: #c92a2a;
  --good: #1f8f5a;
  --shadow: 0 8px 30px rgba(10, 40, 60, .12);
  --k-voice: #1c7ed6;
  --k-noise: #c28a00;
  --k-car: #e8590c;
  --k-air: #7048e8;
  --k-dog: #d6336c;
  --k-moto: #c92a2a;
  --k-test: #6c8792;
  --k-other: #2b8a3e;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #eef4f7; --bg2: #ffffff; --card: rgba(255, 255, 255, .9); --card-solid: #ffffff;
    --line: rgba(10, 50, 70, .12); --line2: rgba(10, 50, 70, .24); --text: #06202c; --muted: #3f5f6c;
    --faint: #6c8792; --accent: #00927b; --accent2: #3b5bdb; --accent-ink: #ffffff; --warn: #b7791f;
    --bad: #c92a2a; --good: #1f8f5a; --shadow: 0 8px 30px rgba(10, 40, 60, .12);
    --k-voice: #1c7ed6; --k-noise: #c28a00; --k-car: #e8590c; --k-air: #7048e8; --k-dog: #d6336c;
    --k-moto: #c92a2a; --k-test: #6c8792; --k-other: #2b8a3e;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Google Sans", sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 85% -10%, color-mix(in srgb, var(--accent2) 18%, transparent), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%);
  background-attachment: fixed;
  color: var(--text);
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------ login */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
}
.login-card {
  width: min(420px, 100%); text-align: center; padding: 36px 24px 28px;
  background: var(--card); border: 1px solid var(--line); border-radius: 28px;
  box-shadow: var(--shadow); backdrop-filter: blur(18px);
}
.login-logo { width: 120px; height: 120px; margin: 0 auto 8px; display: block; }
.login-logo .w { transform-origin: 60px 78px; animation: ping 2.4s ease-out infinite; opacity: 0; }
.login-logo .w2 { animation-delay: .8s; } .login-logo .w3 { animation-delay: 1.6s; }
@keyframes ping { 0% { transform: scale(.55); opacity: 0; } 25% { opacity: 1; } 100% { transform: scale(1.15); opacity: 0; } }
.login h1 { margin: 6px 0 2px; font-size: 32px; letter-spacing: -.02em; }
.login p.tagline { margin: 0 0 24px; color: var(--muted); }
.field { position: relative; text-align: left; }
.field input {
  width: 100%; height: 58px; padding: 0 56px 0 18px; border-radius: 16px; font-size: 18px;
  border: 1.5px solid var(--line2); background: var(--bg2); outline: none; transition: border-color .2s, box-shadow .2s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.field .eye { position: absolute; right: 6px; top: 6px; width: 46px; height: 46px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 0 22px; border-radius: 16px; border: 1px solid var(--line2);
  background: var(--card-solid); font-weight: 650; transition: transform .12s, background .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent2))); color: var(--accent-ink); border: 0; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.block { width: 100%; margin-top: 14px; font-size: 17px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 14px; }
.err { color: var(--bad); min-height: 1.4em; margin: 10px 0 0; font-weight: 600; }
.fine { color: var(--faint); font-size: 13px; margin-top: 20px; }

/* ------------------------------------------------ shell */
.shell { max-width: 880px; margin: 0 auto; padding: 0 16px calc(104px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 14px 0 12px; margin: 0 -16px; padding-inline: 16px;
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 20px; letter-spacing: -.01em; margin-right: auto; }
.brand img { width: 34px; height: 34px; border-radius: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: 99px;
  font-size: 14px; font-weight: 650; background: var(--card); border: 1px solid var(--line);
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); animation: pulse 2s infinite; }
.dot.off { background: var(--bad); }
.dot.sim { background: var(--accent2); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { margin: 6px 0 10px; padding: 12px 16px; border-radius: 14px; font-size: 14px; font-weight: 600;
  background: color-mix(in srgb, var(--warn) 16%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.banner.sim { background: color-mix(in srgb, var(--accent2) 14%, transparent); border-color: color-mix(in srgb, var(--accent2) 40%, transparent); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 14px 0; box-shadow: var(--shadow); backdrop-filter: blur(14px);
  animation: rise .45s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; display: flex; align-items: center; gap: 8px; }
.card h2 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--faint); font-size: 13px; }

/* ------------------------------------------------ hero radar */
.hero { padding: 14px 14px 18px; overflow: hidden; }
.radar-wrap { position: relative; }
#radar { width: 100%; height: auto; display: block; }
.r-grid { fill: none; stroke: var(--line2); stroke-width: 1; }
.r-grid.dash { stroke-dasharray: 3 5; }
.r-fill { fill: color-mix(in srgb, var(--accent) 6%, transparent); }
.r-label { fill: var(--faint); font-size: 11px; font-weight: 600; }
.r-label.front { fill: var(--muted); font-size: 12px; letter-spacing: .12em; }
.r-sweep { fill: url(#sweepGrad); }
.r-needle { stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; }
.r-mic { fill: var(--text); }
.r-pt { stroke: var(--bg); stroke-width: 1.5; transition: opacity .3s; }
.readout { text-align: center; margin-top: 2px; }
.readout .big { font-size: clamp(40px, 12vw, 64px); font-weight: 800; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.readout .unit { font-size: 16px; font-weight: 700; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.readout .sub { color: var(--muted); font-size: 14px; margin-top: 4px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* kind colours (fill for svg, background for html) */
.g-people { --k: var(--k-voice); } .g-noise { --k: var(--k-noise); } .g-vehicle { --k: var(--k-car); }
.g-air { --k: var(--k-air); } .g-animal { --k: var(--k-dog); } .g-alert { --k: var(--k-moto); }
.g-bird { --k: var(--k-other); } .g-home { --k: var(--k-noise); } .g-weather { --k: var(--k-test); }
.g-test { --k: var(--k-test); } .g-other { --k: var(--k-other); }

/* birds of the day */
.birds { display: grid; gap: 8px; }
.bird-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 14px; background: var(--bg2); border: 1px solid var(--line); text-align: left; width: 100%; min-height: 52px; }
.bird-row b { font-weight: 700; }
.bird-row small { display: block; color: var(--muted); font-size: 12px; }
.bird-row .count { min-width: 36px; height: 30px; padding: 0 10px; border-radius: 99px; display: grid; place-items: center;
  font-weight: 800; background: color-mix(in srgb, var(--k-other) 20%, transparent); color: var(--k-other); font-variant-numeric: tabular-nums; }
.bird-bar { height: 4px; border-radius: 2px; background: var(--k-other); opacity: .55; margin-top: 6px; }
.seg.wrap { flex-wrap: wrap; margin-top: 10px; }
#quiet-head { padding: 0; border: 0; }
.quiet-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; color: var(--muted); }
svg .kf { fill: var(--k, var(--k-other)); }
.kb { background: var(--k, var(--k-other)); }

/* ------------------------------------------------ devices + kpis */
.devices { display: grid; gap: 10px; }
.device { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--bg2); border: 1px solid var(--line); }
.device .name { font-weight: 700; overflow-wrap: anywhere; }
.device .meta { color: var(--muted); font-size: 13px; }
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 16px; }
.bars b { width: 4px; border-radius: 2px; background: var(--line2); }
.bars b.lit { background: var(--accent); }
.bars b:nth-child(1) { height: 25%; } .bars b:nth-child(2) { height: 50%; } .bars b:nth-child(3) { height: 75%; } .bars b:nth-child(4) { height: 100%; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; animation: rise .45s both; }
.kpi .v { font-size: 28px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

/* ------------------------------------------------ charts */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.c-axis { fill: var(--faint); font-size: 10px; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-area { fill: url(#areaGrad); }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.c-bar { rx: 2; }
.empty-chart { color: var(--faint); font-size: 14px; padding: 18px 0; text-align: center; }

/* ------------------------------------------------ events */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 40px; padding: 0 16px; border-radius: 99px; border: 1px solid var(--line2);
  background: var(--card); font-weight: 650; font-size: 14px; display: inline-flex; align-items: center; gap: 8px;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip i { width: 9px; height: 9px; border-radius: 50%; }
.day { margin: 18px 4px 6px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.ev {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center;
  padding: 12px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); margin: 8px 0;
  animation: rise .35s both;
}
.ev .ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: color-mix(in srgb, var(--k, var(--k-other)) 18%, transparent); color: var(--k, var(--k-other)); }
.ev .ic svg { width: 24px; height: 24px; }
.ev .t { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ev .m { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.ev .when { text-align: right; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.ev .arrow { width: 28px; height: 28px; margin-left: auto; display: block; }
.tag { font-size: 11px; font-weight: 750; padding: 2px 8px; border-radius: 99px; letter-spacing: .04em; text-transform: uppercase; }
.tag.sim { background: color-mix(in srgb, var(--accent2) 22%, transparent); color: var(--accent2); }
.tag.ai { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.tag.test { background: var(--line); color: var(--muted); }
.more { display: flex; justify-content: center; margin: 16px 0; }

.empty { text-align: center; padding: 28px 12px; }
.empty .art { width: 96px; height: 96px; margin: 0 auto 10px; opacity: .9; }
.empty h3 { margin: 6px 0; font-size: 20px; }
.empty p { color: var(--muted); margin: 6px auto 16px; max-width: 420px; }
.steps { text-align: left; max-width: 440px; margin: 0 auto 18px; padding-left: 22px; color: var(--muted); }
.steps li { margin: 6px 0; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ------------------------------------------------ settings */
.set { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.set:last-child { border-bottom: 0; }
.set .lbl { flex: 1; min-width: 0; }
.set .lbl b { display: block; font-weight: 650; }
.set .lbl small { color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 58px; height: 34px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line2); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(24px); }
.switch input:focus-visible + span { outline: 3px solid var(--accent2); outline-offset: 2px; }
select.sel { min-height: 46px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line2); background: var(--bg2); }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 12px; overflow: hidden; }
.seg button { min-height: 44px; padding: 0 14px; border: 0; background: transparent; font-weight: 650; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.range { width: 100%; accent-color: var(--accent); height: 32px; }
.kind-grid { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 4px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.5; }
.note li { margin: 4px 0; }

/* ------------------------------------------------ bottom nav */
.nav {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b)); z-index: 30;
  display: flex; gap: 4px; padding: 6px; border-radius: 24px; width: min(420px, calc(100% - 32px));
  background: color-mix(in srgb, var(--card-solid) 88%, transparent); border: 1px solid var(--line2);
  box-shadow: var(--shadow); backdrop-filter: blur(18px);
}
.nav button {
  flex: 1; min-height: 58px; border: 0; border-radius: 18px; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; font-weight: 700;
  position: relative;
}
.nav button svg { width: 24px; height: 24px; }
.nav button[aria-current="page"] { color: var(--text); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.nav .badge { position: absolute; top: 6px; right: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; }

/* ------------------------------------------------ toast + dialog */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0; z-index: 50;
  padding: 14px 20px; border-radius: 16px; background: var(--text); color: var(--bg); font-weight: 650;
  box-shadow: var(--shadow); transition: opacity .25s, transform .25s; max-width: calc(100% - 32px); pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
dialog { border: 1px solid var(--line2); border-radius: 24px; background: var(--card-solid); color: var(--text); padding: 22px; width: min(400px, calc(100% - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
dialog h3 { margin: 0 0 8px; }
dialog p { color: var(--muted); margin: 0 0 18px; }
dialog .row-btns { justify-content: flex-end; }

.skeleton { height: 14px; border-radius: 7px; background: linear-gradient(90deg, var(--line) 0%, var(--line2) 50%, var(--line) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin: 8px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.set.col { display: block; }
.row-btns.start { justify-content: flex-start; margin-top: 12px; }

