:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.12);
  --inactive: #64748b;
  --inactive-bg: rgba(100, 116, 139, 0.15);
  --danger: #f87171;
  --highlight: #fbbf24;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.08), transparent 40%),
    var(--bg);
  color: var(--text);
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.header {
  margin-bottom: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ---- Hardware telemetry card ------------------------------------------- */
.hw-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 320px;
  box-shadow: var(--shadow);
}

.hw-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hw-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.hw-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--inactive);
  flex: none;
}

.hw-dot.live {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.hw-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
}

.hw-gauges {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.gauge {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gauge-label {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.bar {
  position: relative;
  height: 6px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.4s ease;
}

/* 1-second peak marker: a thin vertical tick that reveals brief spikes. */
.bar-peak {
  position: absolute;
  top: -1px;
  width: 2px;
  height: 8px;
  margin-left: -1px;
  border-radius: 2px;
  background: rgba(226, 232, 240, 0.55);
  transition: left 0.2s ease;
}

.bar-peak.hot {
  background: var(--highlight);
  box-shadow: 0 0 6px var(--highlight);
}

.bar-fill.warn {
  background: linear-gradient(90deg, #f59e0b, var(--danger));
}

.gauge-val {
  font-size: 0.68rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.hw-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  .hw-card {
    min-width: 0;
    width: 100%;
  }
}

.logo {
  font-size: 2rem;
  color: var(--accent);
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 12px 18px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
  font-size: 0.95rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover:not(.disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.tab.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.status-card,
.demo-panel,
.transcript-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.status-card {
  padding: 24px;
  margin-bottom: 20px;
}

.status-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.status-card h2 {
  margin: 0;
  font-size: 1.25rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge.inactive {
  color: var(--inactive);
  background: var(--inactive-bg);
}

.badge.active {
  color: var(--success);
  background: var(--success-bg);
}

.status-message {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.status-actions {
  display: flex;
  gap: 12px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: #2d3a50;
  border-color: #475569;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  border-color: transparent;
  color: #082f49;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn.danger {
  border-color: rgba(248, 113, 113, 0.35);
  color: var(--danger);
}

.btn.ghost {
  background: transparent;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.demo-panel {
  padding: 20px;
}

.demo-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-group {
  flex: 1;
  justify-content: flex-end;
  min-width: 260px;
}

#transcript-search {
  width: min(100%, 320px);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

#transcript-search:focus {
  outline: 2px solid rgba(56, 189, 248, 0.35);
  border-color: var(--accent);
}

.search-meta {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.mic-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--success);
  font-size: 0.9rem;
}

.pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.7); }
  70% { box-shadow: 0 0 0 10px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

.transcript-shell {
  overflow: hidden;
}

.transcript-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.transcript-view {
  height: 420px;
  overflow-y: auto;
  padding: 16px 18px;
  scroll-behavior: smooth;
}

.transcript-empty {
  color: var(--muted);
  margin: 0;
}

.transcript-line {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(51, 65, 85, 0.45);
}

.transcript-line:last-child {
  border-bottom: none;
}

.transcript-time {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  color: var(--accent);
  padding-top: 2px;
}

.transcript-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.transcript-text {
  line-height: 1.5;
  word-break: break-word;
  margin: 0;
}

.transcript-meta {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.02em;
}

.transcript-line.hidden-by-search {
  display: none;
}

mark.search-hit {
  background: rgba(251, 191, 36, 0.35);
  color: var(--text);
  padding: 0 2px;
  border-radius: 3px;
}

/* ---- Model panel (transcription card) ---------------------------------- */
.model-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model-current {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.model-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.model-name {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
  color: var(--accent);
  word-break: break-all;
}

.model-link {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 8px;
}

.model-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

.model-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.model-select {
  flex: 1;
  min-width: 220px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.model-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  min-height: 1em;
}

.model-loading {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.model-loading-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.model-loading-text strong {
  font-size: 0.9rem;
}

.model-loading-text span {
  font-size: 0.78rem;
  color: var(--muted);
}

.spinner {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--surface);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  .app {
    padding: 16px;
  }

  .transcript-line {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .demo-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-group {
    justify-content: stretch;
  }

  #transcript-search {
    width: 100%;
  }
}
