:root {
  --bg: #f4f5f6;
  --surface: #ffffff;
  --surface-2: #f0f2f3;
  --text: #16191c;
  --muted: #646b73;
  --border: #e1e4e7;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --ok: #15803d;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 1px 3px rgba(16, 24, 32, .04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1214;
    --surface: #171b1e;
    --surface-2: #1f2427;
    --text: #e8eaec;
    --muted: #9aa2a9;
    --border: #2a3035;
    --accent: #2dd4bf;
    --accent-ink: #062a26;
    --accent-soft: #123a35;
    --ok: #4ade80;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --danger: #f87171;
    --danger-soft: #3b1717;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 16px; font-weight: 650; }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.hint.center { text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 24px 0 8px; margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner, .tabs, main { max-width: 760px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand.small { gap: 10px; font-weight: 650; font-size: 16px; min-width: 0; }
.brand.small span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pills { display: flex; gap: 6px; flex-shrink: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.online { color: var(--ok); }
.pill.online .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.pill.low { color: var(--warn); background: var(--warn-soft); }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: none; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px 12px; cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.banner { max-width: 760px; margin: 12px auto 0; padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); margin-left: 16px; margin-right: 16px; }
@media (min-width: 792px) { .banner.warn { margin-left: auto; margin-right: auto; } }

main { padding-top: 16px; padding-bottom: 40px; }
.panel { display: flex; flex-direction: column; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* ---------- form controls ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 550; }
label + label { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 label + label { margin-top: 0; }
.grid2 .span2 { grid-column: 1 / -1; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
input[type="text"], input[type="password"], input[type="number"], input[type="time"], select {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 32px; }
output { color: var(--accent); font-weight: 650; }

.btn {
  appearance: none; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 10px 16px; min-height: 44px;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg label { flex: 1; margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 9px 8px; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--muted);
}
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.small span { padding: 4px 10px; font-size: 12px; white-space: nowrap; }
.seg.small { padding: 2px; }

.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch span::after {
  content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.is-disabled { opacity: .5; }

.savebar {
  position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px);
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
}
.savebar .muted { flex: 1; min-width: 0; font-size: 13px; text-align: right; }
.savebar .btn { white-space: nowrap; flex-shrink: 0; }

/* ---------- live ---------- */
.live-card { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 28px 16px 20px; }
.listen-btn {
  appearance: none; border: 0; cursor: pointer; width: 168px; height: 168px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 700; font-size: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .1s;
}
.listen-btn:active { transform: scale(.97); }
.listen-icon {
  width: 0; height: 0; border-style: solid; border-width: 16px 0 16px 26px;
  border-color: transparent transparent transparent currentColor; margin-left: 6px;
}
.listen-btn.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 3px var(--accent); }
.listen-btn.on .listen-icon { border: 0; width: 24px; height: 24px; background: currentColor; border-radius: 4px; margin: 0; }
.live-status { margin: 16px 0 14px; min-height: 22px; }
.meter { width: 100%; height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) 70%, var(--warn) 88%, var(--danger) 100%);
  background-size: 100vw 100%; transition: width .08s linear;
}
.meter-row { width: 100%; display: flex; justify-content: space-between; font-size: 13px; margin-top: 6px; }
.volume { flex-direction: row; align-items: center; gap: 12px; width: 100%; margin-top: 18px; font-weight: 550; }
.volume input { flex: 1; }
.volume .muted { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- recordings ---------- */
.days { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.day { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.day-head {
  width: 100%; appearance: none; border: 0; background: var(--surface-2); color: var(--text); font: inherit;
  display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; cursor: pointer; text-align: left;
}
.day-head strong { font-weight: 650; }
.day-head .chev { transition: transform .15s; color: var(--muted); }
.day.open .chev { transform: rotate(90deg); }
.rec-list { list-style: none; margin: 0; padding: 0; }
.rec { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.rec-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rec-time { font-weight: 650; font-variant-numeric: tabular-nums; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 2px 7px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.badge.event { background: var(--warn-soft); color: var(--warn); }
.badge.continuous { background: var(--accent-soft); color: var(--accent); }
.rec-meta { color: var(--muted); font-size: 13px; margin-left: auto; }
.rec audio { width: 100%; height: 40px; }
.rec-actions { display: flex; gap: 8px; }
.rec-actions a, .rec-actions button { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- device ---------- */
.battery-big { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.battery-shell {
  position: relative; width: 64px; height: 30px; border: 3px solid var(--text); border-radius: 7px; padding: 3px;
}
.battery-shell::after { content: ""; position: absolute; right: -8px; top: 7px; width: 4px; height: 10px; background: var(--text); border-radius: 0 3px 3px 0; }
.battery-level { height: 100%; width: 0%; background: var(--ok); border-radius: 3px; transition: width .3s; }
.battery-level.low { background: var(--danger); }
.big-num { font-size: 30px; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; }
.chart { width: 100%; min-height: 160px; }
.chart svg { width: 100%; height: 180px; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.chart text { fill: var(--muted); font-size: 11px; }
.events { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; font-size: 13px; }
.events li { display: flex; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); }
.events li:first-child { border-top: 0; }
.events time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 92px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 50; max-width: calc(100% - 32px);
}

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 24px; }
.login-card .brand p { margin: 2px 0 0; font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 0; font-size: 14px; }
