:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f8f9f6;
  --line: #e2e4de;
  --text: #1b1f1d;
  --muted: #6b726e;
  --accent: #0f9d8a;
  --accent-soft: #dff3ef;
  --ok: #178a4c;
  --ok-soft: #e1f3e8;
  --bad: #c2362f;
  --bad-soft: #fbe6e4;
  --idle: #a86b0c;
  --idle-soft: #fbf0dc;
  --shadow: 0 1px 2px rgb(20 30 25 / 0.05), 0 4px 16px rgb(20 30 25 / 0.04);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413;
    --surface: #181c1a;
    --surface-2: #1e2320;
    --line: #2a302d;
    --text: #e6ebe8;
    --muted: #8d9691;
    --accent: #3cc4ae;
    --accent-soft: #163a34;
    --ok: #4cc585;
    --ok-soft: #173826;
    --bad: #f07067;
    --bad-soft: #3d1f1d;
    --idle: #e0a445;
    --idle-soft: #3a2d15;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.mono { font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.wrap { overflow-wrap: anywhere; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand svg {
  width: 34px; height: 34px; padding: 6px; flex: none;
  border-radius: 10px; background: var(--accent-soft);
  fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round;
}
.brand svg rect { fill: var(--accent); stroke: none; }
h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.sub { margin: 0; color: var(--muted); font-size: 12.5px; }

.link { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.link .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.link[data-state="live"] .dot { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.link[data-state="down"] .dot { background: var(--bad); }

main { padding: 24px clamp(16px, 4vw, 40px) 48px; max-width: 1320px; margin: 0 auto; }

/* ---------- device tabs ---------- */

.devices { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.devices:empty { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-family: var(--mono); font-size: 12.5px; cursor: pointer;
}
.tab[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.tab .dot.on { background: var(--ok); }
.tab .dot.rec { background: var(--bad); animation: pulse 1.4s ease-in-out infinite; }

.empty {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 28px; margin-bottom: 18px; text-align: center;
}
.empty h2 { margin: 0 0 6px; font-size: 16px; }
.empty p { margin: 0 auto; max-width: 560px; color: var(--muted); }

/* ---------- cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
  min-width: 0;
}
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }

dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0; }
dt { color: var(--muted); white-space: nowrap; }
dd { margin: 0; text-align: right; min-width: 0; }

.pill {
  font-size: 11px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.idle { background: var(--idle-soft); color: var(--idle); }
.pill.rec { background: var(--bad-soft); color: var(--bad); }

.state-ok { color: var(--ok); font-weight: 600; }
.state-bad { color: var(--bad); font-weight: 600; }
.state-idle { color: var(--idle); font-weight: 600; }

.big { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; }
.big .mono { font-size: 30px; letter-spacing: -0.02em; font-weight: 500; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line); flex: none; }
.rec-dot.on { background: var(--bad); animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .rec-dot.on, .tab .dot.rec { animation: none; } }

.warn {
  margin: 12px 0 0; padding: 8px 10px; border-radius: 8px;
  background: var(--idle-soft); color: var(--idle); font-size: 12.5px;
}

.meter { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 14px; overflow: hidden; border: 1px solid var(--line); }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }

/* ---------- recordings ---------- */

.recordings { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.section-head h2 { margin: 0; font-size: 16px; }

.player {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px;
}
.player-meta { display: flex; flex-direction: column; min-width: 0; flex: 1 1 200px; }
.player-meta .mono { overflow-wrap: anywhere; }
.player audio { flex: 2 1 280px; height: 36px; }

.table-wrap {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow-x: auto; box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.playing { background: var(--accent-soft) !important; }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
td.name { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
td.actions, th.actions { text-align: right; white-space: nowrap; }
tr.placeholder td { text-align: center; color: var(--muted); padding: 28px; }
.live-tag {
  display: inline-block; margin-left: 8px; font-family: system-ui, sans-serif;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; color: var(--bad);
  border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; vertical-align: 1px;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12.5px; font-weight: 550;
  padding: 5px 11px; border-radius: 8px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn + .btn { margin-left: 6px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- live listening ---------- */

.live { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.live .btn.listening { background: var(--bad); border-color: var(--bad); }
.live-meter { margin-top: 10px; }
.live-meter span { transition: width 0.08s linear; }

/* ---------- login ---------- */

.top-right { display: flex; align-items: center; gap: 12px; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 18px; }
.login p { margin: 0; }
.login label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login input {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login .btn { justify-content: center; padding: 9px; font-size: 14px; }

/* ---------- delete ---------- */

.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #fff; }
#rec-alert { margin: 0 0 12px; }

/* ---------- bulk selection ---------- */

.bulk { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.bulk #bulk-text { color: var(--muted); font-size: 13px; }
th.pick, td.pick { width: 36px; padding-right: 0; }
td.pick input, th.pick input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
tr.selected { background: var(--accent-soft); }

.notice { margin: 0 0 12px; padding: 8px 10px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); font-size: 12.5px; }
