:root {
  --bg-0: #0b0d12;
  --bg-1: #11141b;
  --bg-2: #161a24;
  --bg-3: #1d2230;
  --line: #262c3b;
  --line-soft: #1c2230;
  --fg-0: #e8ecf3;
  --fg-1: #aab2c4;
  /* WCAG 1.4.3 AA: contrast vs --bg-1 (#11141b) ≈ 5.6:1 — passes for the small
     11px hints, age, status, and chip-status text that use this color. The
     previous #6b7488 was ~3.4:1 and failed AA on most small-text instances. */
  --fg-2: #8a93a8;
  --accent: #7c9cff;
  --accent-2: #a78bfa;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --sidebar-w: 380px;
  --ctrl-h: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
  color: var(--fg-0);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: var(--accent); }
a:hover { text-decoration: underline; }

/* ─── Icons ─── */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  flex-shrink: 0;
}

/* ─── Topbar ─── */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-top: calc(10px + var(--safe-top));
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-1);
}
.title { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.title .logo {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.title .logo svg,
.title .logo img { width: 100%; height: 100%; display: block; object-fit: contain; }
.title .logo img { border-radius: 4px; }
.title-text { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Simple/Advanced toggle — compact, inline-fit version of .segmented */
.mode-switch {
  display: inline-flex;
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 2px;
  flex: 0 0 auto;
}
.mode-opt {
  padding: 5px 12px;
  font-size: 11px; font-weight: 600;
  color: var(--fg-2);
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: 0.3px;
  transition: background 0.12s ease, color 0.12s ease;
}
.mode-opt:hover { color: var(--fg-1); }
.mode-opt.is-active {
  background: var(--bg-1);
  color: var(--fg-0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
@media (max-width: 480px) {
  .mode-opt { padding: 5px 8px; font-size: 10px; }
}

/* Generic segmented control for form fields (mode/dir/audio source/VAD sensitivity).
   Fills the field width; options share the row equally; long labels ellipsise. */
.segmented {
  display: flex;
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 2px;
  gap: 0;
  width: 100%;
  min-height: var(--ctrl-h);
}
.segmented.seg-wrap { flex-wrap: wrap; row-gap: 4px; border-radius: var(--radius-sm); }
.seg-opt {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 8px;
  font-size: 12px; font-weight: 600;
  color: var(--fg-2);
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: 0.2px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.segmented.seg-wrap .seg-opt { border-radius: var(--radius-sm); flex-basis: 0; }
.seg-opt:hover:not(:disabled) { color: var(--fg-1); }
.seg-opt.is-active {
  background: var(--bg-1);
  color: var(--fg-0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.seg-opt:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  color: var(--fg-2);
}
.segmented.is-locked { pointer-events: none; opacity: 0.6; }

/* Wide-enough screens get a roomier VAD grid (segmented controls breathe). */
.vad-grid { gap: 10px 12px; }

/* Push-to-talk hotkey button (mono, fixed-width look). */
.ptt-key-btn {
  justify-content: flex-start !important;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px !important;
  flex: 1 1 auto;
}
.ptt-key-btn.is-capturing {
  background: rgba(124, 156, 255, 0.12) !important;
  color: var(--accent) !important;
  border-color: rgba(124, 156, 255, 0.4) !important;
  animation: pulse 1s infinite;
}

/* Simple mode keeps the tab strip — it carries the only mic/out visualiser
   and the per-session status now — but strips multi-session affordances:
   the "+" button, the per-chip "×" close, and the chip's max-width cap so
   the single visible chip can stretch to fill the row.
   Advanced-only sidebar sections are still hidden, of course. */
body[data-ui-mode="simple"] .advanced-only { display: none !important; }

/* Basic normally hides the whole Audio section. The microphone picker is the
   one exception, and only when the machine actually offers a choice (2+ real,
   labelled inputs — see the has-mic-choice toggle in refreshAudioInputDevices).
   Rationale: every other Advanced setting still produces *something* when it's
   wrong, but a wrong mic produces silence — no meter, no turns, no error — and
   a Basic user has no way to diagnose or fix it without finding the mode
   switcher. Reveal the select alone; source/output/preview stay Advanced. */
body[data-ui-mode="simple"].has-mic-choice #audio-section { display: block !important; }
body[data-ui-mode="simple"].has-mic-choice #audio-section > .field,
body[data-ui-mode="simple"].has-mic-choice #audio-section > .subgroup:not(#mic-section) {
  display: none !important;
}
body[data-ui-mode="simple"].has-mic-choice #mic-section .icon-btn,
body[data-ui-mode="simple"].has-mic-choice #mic-section .mic-preview-list,
body[data-ui-mode="simple"].has-mic-choice #mic-section .live-line,
/* The hint talks about "Mic + Tab", an audio-source option Basic doesn't
   show — a labelled dropdown needs no caption anyway. */
body[data-ui-mode="simple"].has-mic-choice #mic-section .hint {
  display: none !important;
}
body[data-ui-mode="simple"] .tab-new      { display: none; }
body[data-ui-mode="simple"] .tab-close    { display: none; }
body[data-ui-mode="simple"] .tab-chip {
  max-width: none;
  flex: 1 1 auto;
}
/* Hide any non-active chip in simple mode — the user can only ever act on
   one session, and visually there should be just one "card" up there.
   Switching to Advanced or Full reveals the rest. */
body[data-ui-mode="simple"] .tab-chip:not(.is-active) { display: none; }

/* "Advanced" mode (data-ui-mode="mid") sits between Basic and Full. It
   reveals the advanced-only chrome (audio source/output, speech detection,
   bulk session actions) but still hides the .full-only sections — namely
   the translation-mode/direction segmented controls and the system-prompt
   editor — which would mostly only be useful to power users. */
body[data-ui-mode="mid"] .full-only { display: none !important; }
/* Simple also hides .full-only (.full-only is strictly more restrictive
   than .advanced-only, so any element that's full-only should be hidden in
   simple too, even when only one class is on it). */
body[data-ui-mode="simple"] .full-only { display: none !important; }

/* Companion-dependent UI — hidden whenever the local companion service isn't
   reachable. JS toggles body.no-companion based on detectCompanionService(). */
body.no-companion .companion-only { display: none !important; }

/* Generic "hide" utility. The HTML [hidden] attribute is too easy to override
   (the .btn class defaults to display: inline-flex), so JS toggles this class
   for elements that need to disappear/reappear at runtime. */
.is-hidden { display: none !important; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ─── Tab strip ─── */
.tabs {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 8px 8px 0;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-soft);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  /* The chips do not propagate their height up through the stretch chain, so
     this floor — not intrinsic sizing — is what gives the strip its height
     (setting it to `auto` collapses the strip to its padding). It must clear
     the tallest chip: head + status/age + device row + meters, which needs
     ~99px in Advanced/Full. At the old 80px the meters row was cropped away
     entirely and the device row was sliced in half. */
  min-height: 100px;
}
.tabs::-webkit-scrollbar { height: 4px; }
.tabs::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 2px; }
.tab-list {
  display: flex; align-items: stretch;
  gap: 4px;
  flex: 1 1 auto; min-width: 0;
}

/* Each chip is a mini session card: top row = identity + close, middle = state +
   age, bottom = mic / out level. Active chip has a thick accent bar across the
   top and merges with the conv panel below. */
.tab-chip {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px 10px 7px;
  background: var(--bg-2);
  color: var(--fg-1);
  border: 1px solid var(--line-soft);
  border-radius: 10px 10px 0 0;
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
  user-select: none;
  flex: 0 0 auto;
  min-width: 180px;
  max-width: 260px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  animation: tab-in 0.18s ease-out;
  position: relative;
}
.tab-chip:hover { background: var(--bg-3); color: var(--fg-0); }
.tab-chip.is-active {
  background: var(--bg-0);
  color: var(--fg-0);
  /* Strong active indicator: accent bar across the top edge. The bottom border
     matches the conv panel and the negative margin overlaps the strip's own
     border-bottom, so the chip "drops into" the panel visually. */
  box-shadow: inset 0 3px 0 var(--accent);
  padding-top: 7px;
  border-bottom-color: var(--bg-0);
  margin-bottom: -1px;
}
.tab-chip.is-switching { border-color: rgba(245, 158, 11, 0.42); }
.tab-chip.is-active.is-switching { box-shadow: inset 0 3px 0 var(--warn); }
.tab-chip.is-active .tab-label { color: var(--fg-0); }
@keyframes tab-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.tab-chip-head {
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.tab-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-2); flex: 0 0 auto;
}
.tab-label {
  flex: 1; min-width: 0;
  letter-spacing: 0.3px;
  line-height: 1;
  font-weight: 700;
  overflow: hidden; text-overflow: ellipsis;
}
.tab-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  font-size: 16px; line-height: 1;
  color: var(--fg-2);
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.12s ease, color 0.12s ease;
}
.tab-close:hover { background: rgba(248, 113, 113, 0.18); color: var(--bad); }

.tab-chip-mid {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.tab-status-text {
  color: var(--fg-2);
  min-width: 0; overflow: hidden; text-overflow: ellipsis;
}
.tab-age {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px; font-weight: 600;
  color: var(--fg-2);
  letter-spacing: 0.3px;
  flex: 0 0 auto;
  min-width: 42px;
  text-align: right;
  padding: 2px 0;
  border-radius: 999px;
}
.tab-age.is-switching {
  min-width: 68px;
  padding: 2px 7px;
  color: var(--warn);
  background: rgba(245, 158, 11, 0.12);
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.28);
  font-weight: 800;
  text-align: center;
  animation: pulse 1.2s infinite;
}

/* Per-session device summary inside the chip: "🎤 mic → 🔊 output". Each
   half ellipses independently so a long output name doesn't squash the mic
   half. Full names are surfaced via title= tooltips. */
.tab-chip-devices {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500;
  text-transform: none; letter-spacing: 0;
  color: var(--fg-2);
  min-width: 0;
}
.tab-chip-devices .tab-dev {
  display: inline-flex; align-items: center; gap: 3px;
  min-width: 0; flex: 1 1 0;
}
.tab-chip-devices .tab-dev-ico {
  flex: 0 0 auto;
  font-size: 10px;
  line-height: 1;
}
.tab-chip-devices .tab-dev-name {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tab-chip-devices .tab-dev-sep {
  flex: 0 0 auto;
  opacity: 0.55;
  font-size: 10px;
}
.tab-chip.is-active .tab-chip-devices { color: var(--fg-1); }
/* Text-mode session has no audio in/out — hide the row entirely. */
.tab-chip[data-audio="false"] .tab-chip-devices[data-mode="text"] { display: none; }

.tab-meters {
  display: flex; flex-direction: column; gap: 2px;
}
.tab-meter {
  position: relative;
  height: 3px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
}
.tab-meter-fill {
  height: 100%; width: 0%;
  border-radius: 2px;
  will-change: width;
  transition: background-color 0.18s ease, opacity 0.18s ease;
}
.tab-meter.mic .tab-meter-fill { background: var(--accent); }
.tab-meter.out .tab-meter-fill { background: var(--accent-2); }
/* In transcribe/text modes there's no TTS, so the OUT bar would always be
   empty — hide it entirely instead of showing dead space. */
.tab-chip[data-audio="false"] .tab-meter.out { display: none; }

/* Status-conditional colors for the dot and status text. */
.tab-chip[data-status="connecting"]   .tab-status-dot,
.tab-chip[data-status="reconnecting"] .tab-status-dot { background: var(--warn); animation: pulse 1.2s infinite; }
.tab-chip[data-status="connected"]    .tab-status-dot { background: var(--good);  animation: pulse 1.6s infinite; }
.tab-chip[data-status="translating"]  .tab-status-dot { background: var(--accent); animation: pulse 0.8s infinite; }
.tab-chip[data-status="paused"]       .tab-status-dot { background: var(--warn); }
.tab-chip[data-status="waiting"]      .tab-status-dot { background: var(--warn); animation: pulse 1.2s infinite; }
.tab-chip[data-status="queued"]       .tab-status-dot { background: var(--accent-2); animation: pulse 0.8s infinite; }
.tab-chip[data-status="error"]        .tab-status-dot { background: var(--bad); }

.tab-chip[data-status="connecting"]   .tab-status-text,
.tab-chip[data-status="reconnecting"] .tab-status-text { color: var(--warn); }
.tab-chip[data-status="connected"]    .tab-status-text { color: var(--good); }
.tab-chip[data-status="translating"]  .tab-status-text { color: var(--accent); }
.tab-chip[data-status="paused"]       .tab-status-text,
.tab-chip[data-status="waiting"]      .tab-status-text { color: var(--warn); }
.tab-chip[data-status="queued"]       .tab-status-text { color: var(--accent-2); }
.tab-chip[data-status="error"]        .tab-status-text { color: var(--bad); }

/* When the session is muted (paused / waiting / queued) or the WebSocket is
   not yet up (connecting / reconnecting) dim the meters so the user can see
   at a glance that the model is NOT receiving audio. The mic itself is still
   live — the meter would otherwise show real levels and mislead the user
   into thinking they're being heard while frames are being dropped. */
.tab-chip[data-status="waiting"]      .tab-meter-fill,
.tab-chip[data-status="queued"]       .tab-meter-fill,
.tab-chip[data-status="connecting"]   .tab-meter-fill,
.tab-chip[data-status="reconnecting"] .tab-meter-fill {
  background: var(--fg-2) !important;
  opacity: 0.55;
}
.tab-chip[data-status="paused"] .tab-meter.mic .tab-meter-fill {
  background: var(--warn) !important;
  opacity: 0.7;
}
.tab-chip[data-status="paused"] .tab-meter.mic::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 5px, rgba(251,191,36,0.35) 5px 8px);
}

.tab-new {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--bg-2);
  color: var(--fg-1);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  align-self: center;
  flex: 0 0 auto;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}
.tab-new:hover:not(:disabled) { background: var(--bg-3); color: var(--fg-0); }
.tab-new:disabled { opacity: 0.35; cursor: not-allowed; }
.tab-new .icon { width: 14px; height: 14px; }

/* Bulk-action buttons (Start all / Stop all) sit next to "+" in the tab strip
   so they're discoverable when the user has multiple sessions. Each button
   disables itself when there's nothing to act on. */
.tab-actions {
  display: inline-flex; align-items: center; gap: 4px;
  align-self: center;
  flex: 0 0 auto;
  margin-right: 4px;
  padding-right: 6px;
  border-right: 1px solid var(--line-soft);
}
.tab-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  background: transparent;
  color: var(--fg-2);
  border-radius: 6px;
  flex: 0 0 auto;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}
.tab-action:hover:not(:disabled) { background: var(--bg-3); color: var(--fg-0); }
.tab-action:disabled { opacity: 0.3; cursor: not-allowed; }
.tab-action .icon { width: 14px; height: 14px; }
#btn-start-all:not(:disabled):hover { color: var(--accent); }
#btn-stop-all:not(:disabled):hover  { color: var(--bad); }

/* Top-level meter row removed — per-session meters live inside each tab chip
   (.tab-meters), so the chrome shows every running session's activity at once
   without the user having to switch tabs. */

/* ─── Conversation ─── */
.conv {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--bg-0);
}
.turns-host {
  flex: 1 1 auto; min-height: 0;
  display: flex;
  position: relative;
}
/* Per-session panel wraps the header strip + transcript; turns-host shows
   only the active panel. */
.session-panel {
  display: none;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0; min-height: 0;
  width: 100%;
  position: relative;
}
.session-panel.is-active { display: flex; }

/* Floating "jump to latest" button. Lives inside each session-panel and only
   shows when refreshScrollStuck() sets data-scroll-stuck="true" on the panel
   (user scrolled away from the bottom by more than the autoscroll tolerance).
   Position bottom-right of the panel — since session-turns fills the panel
   under the header strip, this lands at the bottom-right of the transcript. */
.scroll-bottom-btn {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center; justify-content: center;
  background: var(--bg-2);
  color: var(--fg-0);
  border: 1px solid var(--line);
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.38);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(0.92);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, background 0.12s ease, color 0.12s ease;
  z-index: 5;
}
.scroll-bottom-btn:hover { background: var(--bg-3); color: var(--accent); }
.scroll-bottom-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.scroll-bottom-btn .icon { width: 18px; height: 18px; }
.session-panel[data-scroll-stuck="true"] .scroll-bottom-btn {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
@media (max-width: 480px) {
  .scroll-bottom-btn { right: 12px; bottom: 12px; width: 36px; height: 36px; }
}

/* Per-session header strip — sits above the active transcript and hosts
   Clear and Export (with per-session and all-sessions scopes). */
.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
  position: relative;
  z-index: 4;
}
.session-header-meta {
  display: flex; flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.session-header-title {
  font-size: 13px; font-weight: 700;
  color: var(--fg-0);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-header-sub {
  font-size: 11px; color: var(--fg-2);
  text-transform: uppercase; letter-spacing: 0.5px;
}
/* Mirror of the chip's mic→out summary, revealed only on narrow viewports
   where the compact chip drops its device row. Painted in lockstep with the
   chip by paintTabChipDevices(). */
.session-header-devices {
  display: none;
  align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500;
  color: var(--fg-2);
  margin-top: 2px;
  min-width: 0;
}
.session-header-devices .hdr-dev {
  display: inline-flex; align-items: center; gap: 3px;
  min-width: 0;
}
.session-header-devices .hdr-dev-ico { flex: 0 0 auto; font-size: 10px; line-height: 1; }
.session-header-devices .hdr-dev-name {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.session-header-devices .hdr-dev-sep { flex: 0 0 auto; opacity: 0.55; font-size: 10px; }
.session-header-actions {
  display: flex; align-items: center; gap: 6px;
  flex: 0 0 auto;
}
/* Follow-latest lock toggle. Pressed (is-following) state mirrors the
   "primary action active" look used by other toggle buttons in the app:
   accent fg + tinted background + accent border. Default ghost look applies
   in the off/unlocked state via the .btn ghost base class. */
.session-header-actions .session-lock.is-following {
  color: var(--accent);
  border-color: rgba(124, 156, 255, 0.4);
  background: rgba(124, 156, 255, 0.12);
}
.session-header-actions .session-lock.is-following:not(:disabled):hover {
  background: rgba(124, 156, 255, 0.18);
}
.session-header-actions .btn {
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.session-header-actions .btn .icon {
  width: 14px; height: 14px;
  margin-right: 4px; vertical-align: middle;
}
.session-header-actions .dropdown-caret {
  margin-left: 4px;
  font-size: 10px;
  opacity: 0.7;
}
/* Per-session export menu — opens downward (the strip is at the top of the
   conversation area, so above-anchored makes no sense here). */
.session-header .export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0; left: auto;
  min-width: 180px;
  z-index: 60;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 4px 0;
  animation: fade-in 0.12s ease-out;
}
.session-header .export-menu .export-menu-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--fg-2);
  padding: 6px 12px 2px;
}
.session-header .export-menu .export-menu-sep {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}
.session-header .export-menu .export-item + .export-item { border-top: 0; }

@media (max-width: 480px) {
  .session-header { padding: 6px 12px; gap: 8px; }
  .session-header-actions .btn .btn-tx { display: none; }
  .session-header-actions .btn .caret { margin-left: 0; }
  .session-header-actions .btn { padding: 6px 8px; min-width: 36px; }
  .session-header-actions .btn .icon { margin-right: 0; }
  .session-header-devices { display: flex; }

  /* Compact tab strip: chips share the row evenly (no horizontal scroll for
     up to MAX_SESSIONS=3), drop the status-text/age and devices rows, keep
     the dot+label+close head and the mic/out meters. */
  .tabs { min-height: 0; padding: 6px 6px 0; gap: 4px; }
  .tab-list { gap: 3px; }
  .tab-chip {
    min-width: 0;
    max-width: none;
    flex: 1 1 0;
    padding: 6px 8px 5px;
    gap: 4px;
  }
  .tab-chip .tab-chip-devices { display: none; }
  .tab-chip .tab-chip-mid { font-size: 9px; gap: 6px; }
  .tab-chip .tab-age { min-width: 36px; font-size: 9px; }
  .tab-chip .tab-label { font-size: 11px; letter-spacing: 0.2px; }
  .tab-chip .tab-close { width: 20px; height: 20px; font-size: 14px; }
}

.session-turns {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
  width: 100%;
}

.empty-state {
  margin: auto; text-align: center; color: var(--fg-2);
  max-width: 360px; padding: 20px;
}
.empty-state .empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
  opacity: 0.6;
  color: var(--accent);
}
.empty-state .empty-icon svg { width: 100%; height: 100%; }
.empty-state p { margin: 8px 0 0; font-size: 13px; }
.empty-state .hint { font-size: 12px; color: var(--fg-2); }
.link-btn { color: var(--accent); padding: 0; font-weight: 600; text-decoration: underline; background: none; }

.turn {
  padding: 12px;
  background: var(--bg-1);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 10px;
  contain: layout style;
}
.turn.live {
  border-color: var(--accent);
  background: rgba(124, 156, 255, 0.06);
  box-shadow: 0 0 0 1px rgba(124,156,255,0.10);
}
.turn-thinking {
  display: none;
  align-items: center;
  gap: 4px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 700;
}
.turn.is-thinking .turn-thinking { display: inline-flex; }
.turn-time {
  align-self: flex-start;
  color: var(--fg-2);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.thinking-dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: currentColor;
  animation: thinking-dot 0.9s infinite ease-in-out;
}
.thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinking-dot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}
.turn-row { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.turn-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--fg-2);
}
.turn-row.input .turn-label { color: var(--accent); }
.turn-row.output .turn-label { color: var(--accent-2); }
.turn-text {
  font-size: 14px; color: var(--fg-0);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.turn-text.empty { color: var(--fg-2); font-style: italic; }
.caret {
  display: inline-block; width: 5px; height: 13px;
  background: currentColor; vertical-align: text-bottom;
  margin-left: 2px; animation: caret 0.9s steps(2) infinite; opacity: 0.7;
}
@keyframes caret { 50% { opacity: 0; } }

/* ─── Bottom controls ─── */
.controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto auto auto auto auto;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--bg-1);
  border-top: 1px solid var(--line-soft);
}

/* Start/Stop wrapper participates in the grid as if its children were direct
   grid items — one of the two is always display:none, so the grid always sees
   exactly one wide button in column 1. */
.start-stop { display: contents; }
.start-stop[data-running="true"]  #btn-start { display: none; }
.start-stop[data-running="false"] #btn-stop  { display: none; }

/* PTT toggle: idle = subtle outline, engaged = accent fill so the live state
   is obvious at a glance from the meter row. */
.btn.ptt { color: var(--fg-1); }
.btn.ptt[data-engaged="true"] {
  background: var(--accent);
  color: var(--bg-0);
  border-color: var(--accent);
}
.btn.ptt[data-engaged="true"]:not(:disabled):hover { filter: brightness(1.08); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; min-height: var(--ctrl-h); padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-3); color: var(--fg-0);
  font-weight: 600; font-size: 14px;
  transition: opacity 0.15s, background 0.15s, transform 0.06s;
  border: 1px solid var(--line);
}
.btn:disabled { opacity: 0.4; }
.btn:not(:disabled):active { transform: scale(0.97); }
.btn:not(:disabled):hover { background: var(--bg-2); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0d12; border-color: transparent;
}
.btn.primary:not(:disabled):hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.btn.danger { color: var(--bad); border-color: rgba(248, 113, 113, 0.35); }
.btn.danger:not(:disabled):hover { background: rgba(248, 113, 113, 0.08); }
.btn.warn { color: var(--warn); border-color: rgba(251, 191, 36, 0.35); }
.btn.warn:not(:disabled):hover { background: rgba(251, 191, 36, 0.08); }
.btn.ghost { background: transparent; color: var(--fg-1); }
.btn.ghost:hover { background: var(--bg-2); color: var(--fg-0); }
.btn.full { width: 100%; }

/* "Open Companion App" button — connected state */
#btn-open-companion.is-companion-connected {
  color: var(--good, #4ade80);
  border-color: rgba(74, 222, 128, 0.3);
  cursor: default;
  pointer-events: none;
  opacity: 0.85;
}

/* Notice shown when the translatorcompanion:// protocol is unregistered */
.companion-launch-notice {
  margin-top: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  background: rgba(251, 191, 36, 0.07);
  border: 1px solid rgba(251, 191, 36, 0.28);
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--fg-1);
}
.companion-launch-notice p { margin: 0 0 0.35rem; }
.companion-launch-notice a { color: var(--accent); text-decoration: underline; }
.companion-launch-notice a:hover { color: var(--fg-0); }


.icon-btn {
  width: var(--ctrl-h); height: var(--ctrl-h);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-2); color: var(--fg-1);
  font-size: 18px; border: 1px solid var(--line);
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg-0); }
.icon-btn:active { background: var(--bg-3); }
.icon-btn.small { width: var(--ctrl-h); height: var(--ctrl-h); font-size: 14px; }

/* Pause button toggle states */
#btn-pause .icon-mic-off { display: none; }
#btn-pause.is-paused .icon-mic { display: none; }
#btn-pause.is-paused .icon-mic-off { display: inline-block; }
#btn-pause.is-paused {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.08);
}
#btn-pause.is-paused:hover { background: rgba(251, 191, 36, 0.14); }

/* Renew button text swings between "Renew", "Renew in Ns" (countdown during a
   GoAway window), and "Renewing" (close+reconnect tail). Reserve enough room
   for the longest so the surrounding controls don't shift each second. */
#btn-force-reset { min-width: 110px; justify-content: center; }

/* Narrow phones: collapse secondary labels to icons */
@media (max-width: 380px) {
  .btn.warn .btn-tx, .btn.danger .btn-tx, #btn-force-reset .btn-tx, #btn-ptt .btn-tx { display: none; }
  .btn.warn, .btn.danger, #btn-force-reset, #btn-ptt { padding: 0; width: 44px; min-width: 0; }
}

/* ─── Sidebar / Sheet ─── */
.sidebar {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  align-items: flex-end; justify-content: center;
}
.sidebar.is-open { display: flex; }
.sidebar-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in 0.18s ease-out;
}
.sidebar-inner {
  position: relative;
  width: 100%; max-width: 540px;
  max-height: 88vh;
  max-height: 88dvh;
  background: var(--bg-1);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  display: flex; flex-direction: column;
  animation: slide-up 0.22s ease-out;
  padding-bottom: var(--safe-bottom);
}
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--line); border-radius: 2px;
  margin: 8px auto 4px; flex: 0 0 auto;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.sheet-head h2 {
  margin: 0; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--fg-1);
}
.sheet-body {
  padding: 14px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
  flex: 1 1 auto; min-height: 0;
}
.section { display: flex; flex-direction: column; gap: 10px; }
.section-title {
  margin: 0 0 2px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--fg-2);
}
.subgroup {
  margin-left: 10px;
  padding-left: 12px;
  border-left: 2px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 10px;
}
.section.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section.actions .actions-title { flex-basis: 100%; margin: 0; }
.section.actions .btn { flex: 1 1 0; min-width: 90px; padding: 0 10px; }

/* Export popup menu — base styles; positioning is set by callers (the
   per-session header overrides with its own top/right anchoring). Closed by
   outside-click or Escape (see wireUI). */
.export-menu[hidden] { display: none; }
.export-item {
  background: none; border: 0; cursor: pointer;
  color: var(--fg-0);
  font-size: 13px;
  padding: 8px 12px;
  text-align: left;
  display: flex; align-items: center;
  width: 100%;
}
.export-item:hover, .export-item:focus-visible { background: var(--bg-3); outline: none; }

.footer-hint { margin: 8px 0 0; font-size: 11px; color: var(--fg-2); text-align: center; }

/* Generic sheets (prompt, log) */
.sheet {
  position: fixed; inset: 0; z-index: 110;
  display: none; align-items: flex-end; justify-content: center;
}
.sheet.is-open { display: flex; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in 0.18s ease-out;
}
.sheet-content {
  position: relative;
  width: 100%; max-width: 720px;
  max-height: 88vh;
  max-height: 88dvh;
  background: var(--bg-1);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  display: flex; flex-direction: column;
  animation: slide-up 0.22s ease-out;
  padding-bottom: var(--safe-bottom);
}

/* Compact "alert" variant for confirm dialogs — centered, narrow, no handle. */
.sheet-alert { align-items: center; padding: 16px; }
.sheet-alert .sheet-content {
  width: auto;
  max-width: 440px;
  border-radius: 14px;
  border-bottom: 1px solid var(--line);
  animation: alert-pop 0.18s ease-out;
  padding-bottom: 0;
}
.sheet-alert .sheet-head { padding: 12px 14px; }
.sheet-alert .confirm-message {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg-1);
}
@keyframes alert-pop {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: none; }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }

/* ─── Form ─── */
.field, #vad-auto-fields { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px; color: var(--fg-2);
}
.input-row { display: flex; gap: 6px; align-items: stretch; }
.input-row input,
.input-row select { flex: 1; min-width: 0; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 15px;
  width: 100%; outline: none;
  -webkit-appearance: none; appearance: none;
  color: var(--fg-0);
}
input[type="text"], input[type="password"], input[type="number"], select {
  min-height: var(--ctrl-h);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23aab2c4' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px;
  padding-right: 30px;
}
textarea {
  resize: vertical; min-height: 200px;
  padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.55;
}
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; background: var(--bg-3); padding: 1px 5px; border-radius: 4px; }
.hint { margin: 0; font-size: 11px; color: var(--fg-2); }
.hint-inline { font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 10px; color: var(--fg-2); margin-left: 4px; }
.checkbox-row {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: 12px; font-weight: 500;
  text-transform: none; letter-spacing: normal; color: var(--fg-0);
}
.checkbox-row input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; }
.checkbox-row:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
.checkbox-row:has(input:disabled) input { cursor: not-allowed; }

/* ─── Multi-device checkbox list ─── */
.device-list {
  display: flex; flex-direction: column;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.device-list.is-disabled { opacity: 0.45; pointer-events: none; }
.device-option {
  display: flex; align-items: stretch;
  font-size: 14px; color: var(--fg-0);
  user-select: none;
  min-height: 48px;                  /* WCAG 2.5.5 target size on touch */
}
.device-option:not(:last-child) { border-bottom: 1px solid var(--line); }
.device-option.is-live-tts { background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* Left: TTS output checkbox + device name + live badge */
.device-tts-label {
  flex: 1; display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  cursor: pointer; min-width: 0;
  -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 30%, transparent);
  touch-action: manipulation;
}
.device-tts-label:hover,
.device-tts-label:active { background: var(--bg-2); }
.device-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.live-badge {
  display: none; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--accent);
  flex-shrink: 0;
}
.device-option.is-live-tts .live-badge { display: inline-flex; }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent);
  animation: live-pulse 1.6s ease-out infinite;
}
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0   color-mix(in srgb, var(--accent) 60%, transparent); }
  70%  { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 0%,  transparent); }
  100% { box-shadow: 0 0 0 0   color-mix(in srgb, var(--accent) 0%,  transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
}

/* Inline "Live: <device>" line shown under the input <select>. */
.live-line {
  margin: 4px 0 0; font-size: 11.5px; color: var(--accent);
  display: none; align-items: center; gap: 6px;
}
.live-line.is-visible { display: inline-flex; }
.live-line::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
  animation: live-pulse 1.6s ease-out infinite;
}

/* Multi-mic preview list + toggle button. One clickable row per microphone
   with a live level bar along its bottom edge (same --pt-level overlay trick
   as the passthrough rows). [hidden] keeps it out of layout until the user
   clicks Preview, so the panel doesn't reserve vertical space for it. */
.mic-preview-list {
  margin: 6px 0 0;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}
.mic-preview-row {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 10px 10px;
  background: none; border: 0;
  font: inherit; color: var(--fg);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 30%, transparent);
  touch-action: manipulation;
}
.mic-preview-row:not(:last-child) { border-bottom: 1px solid var(--line); }
.mic-preview-row:hover,
.mic-preview-row:active { background: var(--bg-2); }
.mic-preview-row.is-selected {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.mic-preview-row.is-unavailable { color: var(--fg-2); cursor: default; }
.mic-preview-note {
  flex-shrink: 0;
  font-size: 0.78em;
  color: var(--fg-2);
}
/* Live level bar driven by the --mic-level variable set from JS at rAF rate. */
.mic-preview-row::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(to right,
    var(--accent) 0%,
    var(--accent) calc(var(--mic-level, 0%) - 1px),
    transparent calc(var(--mic-level, 0%)),
    transparent 100%);
}
.mic-preview-row.is-unavailable::after { display: none; }
#btn-mic-preview { flex-shrink: 0; }
#btn-mic-preview.is-active {
  background: color-mix(in srgb, var(--accent) 18%, var(--bg-2));
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}
#btn-mic-preview.is-active .icon { animation: live-pulse 1.6s ease-out infinite; }

/* Right: per-row passthrough toggle (each device row in the output list) */
.passthrough-toggle {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 14px;
  border-left: 1px solid var(--line);
  cursor: pointer; flex-shrink: 0;
  color: var(--fg-2);
  transition: color 0.15s, background 0.15s;
  min-width: 44px;                   /* touch target */
  -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 30%, transparent);
  touch-action: manipulation;
}
.passthrough-toggle:hover,
.passthrough-toggle:active { background: var(--bg-2); }
.passthrough-toggle input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.passthrough-toggle:has(input:checked) { color: var(--accent); }
.device-option.is-live-passthrough .passthrough-toggle { color: var(--accent); }
.device-option.is-live-passthrough .passthrough-toggle::after {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-left: 4px;
  animation: live-pulse 1.6s ease-out infinite;
}
/* Live mic-level bar at the bottom of every row currently routing the mic.
   Width is driven by the --pt-level CSS variable set from JS at rAF rate so
   the user sees real audio flowing — solves "is it actually routing?". The
   bar is rendered via a thin overlay on .device-option so it doesn't shift
   layout when it appears/disappears. */
.device-option { position: relative; }
.device-option.is-live-passthrough::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(to right,
    var(--accent) 0%,
    var(--accent) calc(var(--pt-level, 0%) - 1px),
    transparent calc(var(--pt-level, 0%)),
    transparent 100%);
  transition: background 0.04s linear;
  pointer-events: none;
}
.pt-icon svg { width: 18px; height: 18px; display: block; }
.device-test {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 14px;
  border-left: 1px solid var(--line);
  color: var(--fg-2);
  flex-shrink: 0;
  min-width: 44px;                   /* touch target */
  -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 30%, transparent);
  touch-action: manipulation;
}
.device-test:hover:not(:disabled),
.device-test:active:not(:disabled) { background: var(--bg-2); color: var(--accent); }
.device-test svg { width: 18px; height: 18px; display: block; }

/* Speaker test "playing" state. Three signals so the user can't miss that the
   test is actually firing:
     1. The button background is tinted accent so the busy state is visible
        even with the speaker icon's tiny silhouette.
     2. The icon scales up and down on a soft pulse (matches the cadence of
        the three-note arpeggio testOutputDevice plays).
     3. An expanding ring radiates outward, the same "tap ripple" idiom users
        already associate with audio actively emitting. */
.device-test.is-playing {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
  position: relative; overflow: visible;
  opacity: 1 !important;          /* override the :disabled dim */
}
.device-test.is-playing svg {
  animation: speaker-pulse 0.5s ease-in-out infinite alternate;
}
.device-test.is-playing::after {
  content: '';
  position: absolute; inset: -2px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  opacity: 0;
  animation: speaker-ring 1.0s ease-out infinite;
  pointer-events: none;
}
@keyframes speaker-pulse {
  from { transform: scale(1);    }
  to   { transform: scale(1.18); }
}
@keyframes speaker-ring {
  0%   { transform: scale(0.85); opacity: 0.85; }
  100% { transform: scale(1.45); opacity: 0;    }
}
@media (prefers-reduced-motion: reduce) {
  .device-test.is-playing svg { animation: none; }
  .device-test.is-playing::after { animation: none; opacity: 0.6; }
}

/* Shared checkbox overrides (undo the blanket input[type=text/password/number] rule) */
.device-tts-label input[type=checkbox] {
  width: 18px; height: 18px; flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer; padding: 0;
}

.field-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: end; }
.vad-grid.field-grid { grid-template-columns: 1fr 1fr; }
.swap {
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 44px; width: 40px;
  font-size: 16px; color: var(--fg-1);
  display: inline-flex; align-items: center; justify-content: center;
}
.swap:hover { color: var(--accent); }

.row-end { display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Log ─── */
.log-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-1);
}
.log-toolbar-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--fg-2);
}
.log-toolbar .btn.small {
  min-height: 30px; padding: 4px 10px; font-size: 12px;
}
.log-toolbar-spacer { flex: 1 1 auto; }
.log {
  padding: 10px 14px;
  font-size: 11.5px; line-height: 1.55;
  overflow-y: auto;
  max-height: 70vh;
  max-height: 70dvh;
  color: var(--fg-1); flex: 1;
}
.log-line { padding: 2px 0; word-wrap: break-word; }
.log-line .ts { color: var(--fg-2); margin-right: 8px; }
.log-line .level { font-weight: 700; margin-right: 8px; }
.log-line.info .level { color: var(--accent); }
.log-line.warn .level { color: var(--warn); }
.log-line.error .level { color: var(--bad); }

/* ───────────────────────── Desktop ───────────────────────── */
@media (min-width: 1024px) {
  body {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "sidebar topbar"
      "sidebar tabs"
      "sidebar conv"
      "sidebar controls";
    overflow: hidden;
  }

  .topbar    { grid-area: topbar; }
  .tabs      { grid-area: tabs; }
  .conv      { grid-area: conv; }
  .controls  { grid-area: controls; }

  /* Sidebar becomes a permanent left column */
  .sidebar {
    position: static !important;
    grid-area: sidebar;
    display: flex !important;
    background: var(--bg-1);
    border-right: 1px solid var(--line-soft);
    height: 100dvh;
    z-index: 1;
  }
  .sidebar-backdrop { display: none; }
  .sidebar-inner {
    width: 100%; max-width: none;
    max-height: none; height: 100%;
    border-radius: 0;
    border: 0;
    animation: none;
    padding-bottom: 0;
  }
  .sidebar .sheet-handle { display: none; }
  .sidebar .sheet-head .close-btn { display: none; }
  .sidebar .sheet-head {
    padding: 14px 18px;
  }
  .sidebar .sheet-head h2 { font-size: 14px; }
  .sidebar .sheet-body { padding: 18px; gap: 18px; }

  /* Hide the hamburger; settings always visible */
  .menu-btn { display: none; }

  /* Topbar is bigger & roomier on desktop */
  .topbar { padding: 14px 22px; padding-top: 14px; }
  .title-text { font-size: 16px; }
  .title .logo { font-size: 20px; }

  /* Controls bar sits below the conversation column */
  .controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 22px;
    padding-bottom: 12px;
  }
  .controls .btn.primary { min-width: 160px; }
  .controls #btn-pip-quick { margin-left: auto; }

  /* Tab strip — roomier on desktop */
  .tabs { padding: 10px 22px 0; gap: 8px; }
  .tab-chip {
    padding: 10px 12px 9px;
    min-width: 200px;
    max-width: 280px;
  }
  .tab-chip.is-active { padding-top: 9px; }
  .tab-new { width: 36px; height: 36px; }

  /* Two-column turns on wide screens */
  .session-turns { padding: 18px; gap: 12px; }
  .turn {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    gap: 18px;
    align-items: start;
    padding: 14px 16px;
  }
  .turn.turn-single {
    grid-template-columns: 1fr;
  }
  .turn-row.output {
    padding-left: 18px;
    border-left: 1px dashed var(--line-soft);
  }
  .turn-text { font-size: 15px; line-height: 1.5; }

  /* Sheets: cap width centered on desktop */
  .sheet-content { max-width: 640px; }
}

/* ─── Polish: focus, scrollbars, dividers, narrow phones ─── */

/* Visible keyboard focus on every interactive surface. Preserves :focus
   behaviour for mouse/touch (no ring) but shows it for keyboard nav. */
.btn:focus-visible,
.icon-btn:focus-visible,
.swap:focus-visible,
.mode-opt:focus-visible,
.tab-chip:focus-visible,
.tab-close:focus-visible,
.tab-new:focus-visible,
.link-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.tab-chip { outline-offset: -2px; }
/* Keyboard focus on form fields: explicit 2px outline at 1px offset on top of
   the existing border-color emphasis. The previous `outline: none` relied
   entirely on the border colour change, which is too subtle to satisfy WCAG
   2.4.7 once the focus indicator overlaps the field's own border. */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Custom scrollbars — match the dark palette, stay slim. */
.session-turns, .log, .sheet-body, .sidebar-inner {
  scrollbar-width: thin;
  scrollbar-color: var(--bg-3) transparent;
}
.session-turns::-webkit-scrollbar,
.log::-webkit-scrollbar,
.sheet-body::-webkit-scrollbar,
.sidebar-inner::-webkit-scrollbar { width: 8px; }
.session-turns::-webkit-scrollbar-thumb,
.log::-webkit-scrollbar-thumb,
.sheet-body::-webkit-scrollbar-thumb,
.sidebar-inner::-webkit-scrollbar-thumb {
  background: var(--bg-3); border-radius: 4px;
  border: 2px solid transparent; background-clip: padding-box;
}
.session-turns::-webkit-scrollbar-thumb:hover,
.log::-webkit-scrollbar-thumb:hover,
.sheet-body::-webkit-scrollbar-thumb:hover,
.sidebar-inner::-webkit-scrollbar-thumb:hover {
  background: var(--line); background-clip: padding-box;
}

/* Subtle dividers between sidebar sections — gives the panel rhythm without
   shouting. Skip the first and any hidden section so the spacing stays clean.
   Sections that have their own .section-title heading don't get the hairline:
   the heading already provides the visual break. */
.sheet-body > .section + .section:not(.actions) {
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}
.sheet-body > .section + .section:has(> .section-title) {
  border-top: none;
  padding-top: 6px;
}
.sheet-body > .section.actions { margin-top: 4px; }

/* Subtle elevation: a 1px highlight on the topbar gives it depth against
   the sidebar/content seam. */
.topbar { box-shadow: inset 0 -1px 0 var(--line-soft); border-bottom: 0; }
.controls { box-shadow: inset 0 1px 0 var(--line-soft); border-top: 0; }

/* Smooth transition between sessions. Showing/hiding via display: flex/none
   can't transition; fade the active session instead. */
.session-turns.is-active { animation: session-in 0.14s ease-out; }
@keyframes session-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Pause/Hush/Stop transitions match the rest. */
.btn .icon, .icon-btn .icon { transition: color 0.12s ease; }

/* Narrow phones: reclaim space in the topbar.
   - Below 480px, keep the mode-switch but tighten it.
   - Below 340px, drop the title text too (logo stays). */
@media (max-width: 340px) {
  .title-text { display: none; }
  .topbar { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .mode-opt { padding: 4px 6px; font-size: 9.5px; }
}

/* Tabs at touch-friendly height on mobile. */
@media (hover: none) {
  .tab-close { width: 26px; height: 26px; }
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
