:root {
  --bg: #f6f6f4; --surface: #ffffff; --surface-2: #efefec; --line: #e2e2dd;
  --text: #17181b; --muted: #6b6e76; --accent: #4f46e5; --accent-ink: #fff;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --sev1: #94a3b8; --sev2: #d97706; --sev3: #ea580c; --sev4: #dc2626;
  --radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .04);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1f232b; --line: #2a2f38;
    --text: #e9eaee; --muted: #9298a3; --accent: #8b85ff; --accent-ink: #0f1115;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code, pre { font-family: var(--mono); font-size: 13px; }
pre { background: var(--surface-2); padding: 12px; border-radius: 10px; white-space: pre-wrap; word-break: break-all; }
ul.plain { list-style: none; padding: 0; margin: 8px 0; }

/* controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 42px; padding: 0; font-size: 22px; }
.btn.wide { width: 100%; }
.btn.danger { color: var(--bad); }
.btn svg { width: 20px; height: 20px; fill: currentColor; }
.field {
  min-height: 42px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; min-width: 0;
}
.field:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.link { color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; }
.error { color: var(--bad); min-height: 1.4em; margin: 0; font-size: 14px; }

/* sign in */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.gate-card {
  width: min(360px, 100%); display: grid; gap: 10px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px;
  box-shadow: var(--shadow);
}
.gate-logo { width: 56px; height: 56px; margin: 0 auto; border-radius: 14px; }
.gate-card p { margin: 0 0 6px; color: var(--muted); }

/* shell */
.app { min-height: 100dvh; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 99px;
  background: var(--surface-2); font-size: 13px; font-weight: 600;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.pill.off .dot { background: var(--bad); }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px max(6px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 6px 0;
  color: var(--muted); text-decoration: none; font-size: 11.5px; font-weight: 600;
}
.tabs a svg { width: 23px; height: 23px; fill: currentColor; }
.tabs a.on { color: var(--accent); }
.tabs b {
  position: absolute; top: 1px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.views { padding: 14px 16px 96px; max-width: 760px; margin: 0 auto; }
.view { display: none; }
.view.on { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { margin-bottom: 6px; }
.card > .muted { margin: 0 0 12px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; color: var(--muted); margin: 20px 2px 8px; }
.stack { display: grid; gap: 10px; }
.stack > .card { margin-bottom: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 7px 12px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.toolbar .btn.small { margin-left: auto; }
.date { width: 150px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* microphone */
.mic-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.mic-head p { margin: 2px 0 0; font-size: 14px; }
.btn.live { min-width: 136px; }
.btn.live.on { background: var(--bad); border-color: var(--bad); color: #fff; }
.meter { position: relative; height: 8px; margin-top: 14px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ok); border-radius: 4px; transition: width .2s; }
.meter i.speaking { background: var(--accent); }
.meter b { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--muted); opacity: .6; }

/* today */
.today h2 { margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--surface-2); border-radius: 11px; padding: 10px 4px; display: grid; }
.stats b { font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }
.today p { margin: 10px 0 0; }
.tv { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 6px;
      background: var(--surface-2); color: var(--muted); vertical-align: 1px; }
.line.media > div { color: var(--muted); }

/* alerts */
.alert { border-left: 4px solid var(--sev2); padding: 14px; }
.alert[data-sev="3"] { border-left-color: var(--sev3); }
.alert[data-sev="4"] { border-left-color: var(--sev4); }
.alert.done { opacity: .6; }
.alert-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.sev { font-weight: 700; color: var(--sev2); }
.alert[data-sev="3"] .sev { color: var(--sev3); }
.alert[data-sev="4"] .sev { color: var(--sev4); }
.cat { font-weight: 600; }
.when { margin-left: auto; color: var(--muted); }
.alert-text { margin: 8px 0 12px; font-size: 16px; }
.alert-actions { display: flex; gap: 8px; }
mark { background: color-mix(in srgb, var(--sev3) 25%, transparent); color: inherit; border-radius: 4px; padding: 0 2px; }
mark.s1 { background: color-mix(in srgb, var(--sev1) 25%, transparent); }
mark.s4 { background: color-mix(in srgb, var(--sev4) 30%, transparent); }

/* lines */
.lines { padding: 4px 0; }
.line { display: grid; grid-template-columns: 54px 1fr 40px; gap: 8px; align-items: start; padding: 10px 14px; border-top: 1px solid var(--line); }
.line:first-child { border-top: 0; }
.line time { color: var(--muted); font: 12.5px var(--mono); padding-top: 2px; }
.line .sound { font-style: italic; color: var(--warn); }
.play {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); display: grid; place-items: center; cursor: pointer;
}
.play svg { width: 16px; height: 16px; fill: currentColor; }
.play.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* settings */
.steps { padding-left: 18px; margin: 0 0 10px; display: grid; gap: 8px; }
.qr svg { width: 180px; height: 180px; background: #fff; border-radius: 10px; padding: 6px; }
#phones li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.card > .btn + .btn, #totpBox { margin-top: 10px; }
#signOut { margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: .2s; max-width: calc(100% - 32px); z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* wider screens: sidebar instead of bottom tabs */
@media (min-width: 900px) {
  .tabs { inset: 64px auto 0 0; width: 200px; display: flex; flex-direction: column; gap: 4px;
          padding: 16px 10px; border-top: 0; border-right: 1px solid var(--line); background: transparent; }
  .tabs a { display: flex; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: 14.5px; }
  .tabs a.on { background: var(--surface-2); }
  .tabs b { position: static; margin-left: auto; }
  .views { padding: 24px 32px 40px 232px; max-width: 1000px; }
  .toast { bottom: 24px; }
}
@media (max-width: 520px) {
  #search { flex-basis: 100%; }
  .date { flex: 1; width: auto; }
}
