:root {
  color-scheme: dark;
  --bg: #0f1115; --panel: #171a21; --border: #262b36;
  --text: #e6e9ef; --muted: #8b93a3; --accent: #76b900; /* NVIDIA green */
  --interim: #b9c0cd; --danger: #ff5c5c; --ai: #a970ff; /* AI activity */
  --notice-bg: #3a1d1d; --notice-fg: #ffb4b4;
}
/* Light theme — auto from the OS unless toggled, or forced via data-theme. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #eef1f5; --panel: #ffffff; --border: #d6dbe3;
    --text: #1a1d24; --muted: #5b6472; --interim: #6b7280;
    --danger: #c92a2a; --ai: #7c3aed;
    --notice-bg: #fdecec; --notice-fg: #a12020;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f5; --panel: #ffffff; --border: #d6dbe3;
  --text: #1a1d24; --muted: #5b6472; --interim: #6b7280;
  --danger: #c92a2a; --ai: #7c3aed;
  --notice-bg: #fdecec; --notice-fg: #a12020;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column;
}
header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
header .logo { height: 40px; width: auto; flex: 0 0 auto; }
h1 { font-size: 16px; margin: 0; font-weight: 600; }
h1 span { color: var(--accent); }
#meeting-title {
  font: inherit; font-size: 18px; padding: 8px 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  min-width: 360px; flex: 1 1 360px; max-width: 560px;
}
#meeting-title:focus { outline: none; border-color: var(--accent); }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-left: auto; }
select, button {
  font: inherit; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); cursor: pointer;
}
select { min-width: 220px; }
button.primary { background: var(--accent); color: #0f1115; border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.connected { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.reconnecting { background: #f5a623; animation: pulse 1s infinite; }
.dot.error { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }
.content { flex: 1; display: flex; min-height: 0; }
main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#main-scroll { flex: 1; overflow-y: auto; padding: 24px 20px; min-height: 0; }
/* Analysis panel pinned to the bottom of the main column. */
#analysis-panel {
  flex: 0 0 40%; min-height: 0; display: flex; flex-direction: column;
  border-top: 1px solid var(--border); background: var(--panel);
}
#analysis-panel .analysis-panel-head {
  flex: 0 0 auto; padding: 8px 20px; font-size: 12px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
#analysis-panel #analysis-list {
  flex: 1; min-height: 0; overflow-y: scroll; padding: 14px 20px;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent; /* Firefox */
}
/* Force an always-visible scrollbar (macOS overlay scrollbars hide otherwise). */
#analysis-panel #analysis-list::-webkit-scrollbar { width: 12px; }
#analysis-panel #analysis-list::-webkit-scrollbar-track { background: var(--panel); }
#analysis-panel #analysis-list::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 6px; border: 3px solid var(--panel);
}
#analysis-panel #analysis-list::-webkit-scrollbar-thumb:hover { background: var(--muted); }
#analysis-panel #analysis-empty { padding: 14px 20px; }
#transcript {
  max-width: 900px; margin: 0 auto; font-size: 19px; line-height: 1.7; white-space: pre-wrap; word-wrap: break-word;
}
#transcript .line { margin: 0 0 6px 0; }
#transcript .speaker-tag { font-weight: 600; }
#interim { color: var(--interim); font-style: italic; }

/* Side panel: Speakers / Analysis / Admin */
aside#speakers {
  width: 400px; flex: 0 0 auto; border-left: 1px solid var(--border);
  background: var(--panel); overflow-y: auto; padding: 0 0 14px;
  display: flex; flex-direction: column;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.tabs .tab {
  flex: 1; border: none; border-radius: 0; background: none; color: var(--muted);
  font-size: 14px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 10px 4px; cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.tab-body[hidden] { display: none; } /* display:flex above would otherwise defeat [hidden] */
#speaker-list { display: flex; flex-direction: column; gap: 10px; }
.speaker-item { display: flex; align-items: center; gap: 8px; }
.speaker-swatch { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.speaker-item .sp-id { font-size: 14px; color: var(--muted); flex: 0 0 auto; min-width: 20px; }
.speaker-item input {
  flex: 1; min-width: 0; font: inherit; font-size: 15px; padding: 7px 9px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.speaker-item input:focus { outline: none; border-color: var(--accent); }
#speakers-empty, #analysis-empty { font-size: 14px; color: var(--muted); font-style: italic; }

/* Analysis cards */
/* flex:0 0 auto so cards keep their natural height and the list scrolls
   (overflow:hidden here would otherwise let flex shrink them to nothing). */
.analysis-card { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); overflow: hidden; flex: 0 0 auto; }
.analysis-card .a-head {
  display: flex; align-items: baseline; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600;
}
.analysis-card .a-time { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 11px; }
.analysis-card .a-body { padding: 10px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.analysis-card .a-body.error { color: var(--danger); }

/* Admin editor */
.admin-item { border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.admin-item.dragging { opacity: 0.5; }
.admin-head { display: flex; align-items: center; gap: 8px; }
.admin-head .drag-handle {
  cursor: grab; color: var(--muted); user-select: none; font-size: 16px;
  line-height: 1; padding: 0 2px; flex: 0 0 auto;
}
.admin-head .drag-handle:active { cursor: grabbing; }
.admin-head .fold {
  background: none; border: none; color: var(--text); cursor: pointer;
  font-size: 18px; line-height: 1; padding: 2px 6px; flex: 0 0 auto;
}
.admin-head .fold:hover { color: var(--accent); }
.admin-head input[type="text"] { flex: 1; width: auto; }
.admin-head .run-now { flex: 0 0 auto; font-size: 12px; padding: 4px 10px; }
.admin-body { display: flex; flex-direction: column; gap: 6px; }
.admin-item.collapsed .admin-body { display: none; }
.admin-item input[type="text"], .admin-item textarea, #admin-token {
  font: inherit; font-size: 15px; padding: 7px 9px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); width: 100%;
}
.admin-item textarea { resize: vertical; min-height: 140px; }
.admin-item .row { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); }
.admin-item .row select {
  font: inherit; font-size: 14px; padding: 5px 7px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  max-width: 120px; min-width: 0;
}
.admin-item .row input[type="number"] {
  width: 70px; font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
}
.admin-item .row .del { margin-left: auto; color: var(--danger); border-color: var(--danger); padding: 5px 9px; font-size: 14px; }
.admin-actions { display: flex; gap: 8px; }
.admin-actions button { flex: 1; font-size: 14px; }
#admin-run-all {
  width: 100%; font-size: 14px; margin-top: 8px; font-weight: 600;
  background: #2f6fed; border-color: #2f6fed; color: #fff;
}
#admin-run-all:hover { background: #4380f5; border-color: #4380f5; }
#admin-reset { width: 100%; font-size: 13px; margin-top: 8px; color: var(--muted); }
#admin-reset:hover { color: var(--text); }
#admin-status { font-size: 13px; color: var(--muted); min-height: 16px; margin-top: 8px; }

/* Extras: per-connection transcription settings */
#settings { border: 0; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#settings[disabled] { opacity: 0.55; }
#settings .set-note { font-size: 12px; color: var(--muted); font-style: italic; }
#settings .set-sub { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 6px; }
#settings .set-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
#settings .set-row input[type="checkbox"] { flex: 0 0 auto; }
#settings .set-row input[type="number"] {
  width: 64px; margin-left: auto; font: inherit; font-size: 14px; padding: 4px 6px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text);
}
#settings-reset { color: var(--muted); }
#settings-reset:hover { color: var(--text); }
@media (max-width: 760px) {
  .content { flex-direction: column; }
  aside#speakers {
    width: auto; border-left: none; border-top: 1px solid var(--border);
    max-height: 300px;
  }
  #analysis-panel { flex: 0 0 auto; max-height: 40%; }
}
footer {
  border-top: 1px solid var(--border); padding: 10px 20px; display: flex; gap: 18px;
  align-items: center; font-size: 13px; color: var(--muted);
}
footer .spacer { margin-left: auto; }
/* AI activity indicator: grey when idle, purple + pulsing while running. */
#ai-activity {
  display: flex; align-items: center; gap: 6px; color: var(--muted);
  font-weight: 600; letter-spacing: 0.03em; transition: color 0.2s;
}
#ai-activity .ai-dot {
  width: 10px; height: 10px; border-radius: 50%; background: currentColor;
}
#ai-activity.running { color: var(--ai); }
#ai-activity.running .ai-dot { box-shadow: 0 0 8px var(--ai); animation: pulse 1s infinite; }
/* Portrait/narrow: wrap the footer so action buttons don't run off-screen.
   (Placed after the base footer rules above so these win — media queries
   don't add specificity.) Stats on line 1, then buttons stretch across
   their own rows. */
@media (max-width: 760px) {
  footer { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  footer .spacer { flex-basis: 100%; height: 0; margin: 0; }
  footer button { flex: 1 1 auto; }
}
.placeholder { color: var(--muted); font-style: italic; }
#notice {
  background: var(--notice-bg); color: var(--notice-fg); border-bottom: 1px solid var(--danger);
  padding: 10px 20px; font-size: 14px; text-align: center;
}
#llm-panel {
  max-width: 900px; margin: 24px auto 0; border: 1px solid var(--border);
  border-radius: 10px; background: var(--panel); overflow: hidden;
}
#llm-panel .llm-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); font-size: 13px; color: var(--muted);
}
#llm-panel .llm-head .spacer { margin-left: auto; }
#llm-panel .llm-head button { padding: 4px 10px; font-size: 12px; }
#llm-result {
  padding: 14px; font-size: 15px; line-height: 1.6; white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---- Login page (static/login.html; served at /login when auth is on) ---- */
body.login-body { align-items: center; justify-content: center; padding: 16px; }
.login-wrap {
  width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 24px; display: flex; flex-direction: column; gap: 6px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.login-brand img { height: 32px; }
.login-card h2 { margin: 0 0 12px; font-size: 26px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.login-card input {
  font: inherit; font-size: 15px; padding: 9px 11px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  width: 100%;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-pass { position: relative; }
.login-pass input { padding-right: 44px; }
.login-pass button {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: none; background: none; padding: 4px 8px; font-size: 16px;
  color: var(--muted); line-height: 1;
}
.login-card button.primary { margin-top: 14px; padding: 10px; font-size: 15px; }
#login-error {
  background: var(--notice-bg); color: var(--notice-fg);
  border: 1px solid var(--danger); border-radius: 6px;
  padding: 8px 10px; font-size: 13px; margin-top: 10px;
}
#login-error[hidden] { display: none; }
.login-note {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 13px 16px; font-size: 14px; color: var(--muted);
}
