/* ============================================================
   Vox VAD Tester — Professional Dark UI
   ============================================================ */

:root {
  --bg:         #080c14;
  --surface:    #0f1623;
  --surface-2:  #162035;
  --surface-3:  #1d2a45;
  --border:     #1e3050;
  --border-2:   #2a4060;
  --text:       #e8edf8;
  --text-2:     #a8b8d0;
  --muted:      #5a7090;
  --accent:     #3b82f6;
  --accent-2:   #06b6d4;
  --accent-glow: rgba(59,130,246,0.18);
  --success:    #10b981;
  --success-bg: rgba(16,185,129,0.12);
  --danger:     #ef4444;
  --danger-bg:  rgba(239,68,68,0.12);
  --warn:       #f59e0b;
  --warn-bg:    rgba(245,158,11,0.12);
  --speech:     #f87171;
  --silence:    #60a5fa;
  --gated:      #4b5563;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 4px 24px rgba(0,0,0,0.5);
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.3);
  --font:       'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---- Typography ---- */
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem;   font-weight: 600; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   NAV BAR
   ============================================================ */
.navbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.navbar-brand .brand-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0;
}

.navbar-spacer { flex: 1; }

.navbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--text-2);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-admin   { background: rgba(59,130,246,0.2); color: var(--accent); border: 1px solid rgba(59,130,246,0.3); }
.badge-analyst { background: rgba(6,182,212,0.15); color: var(--accent-2); border: 1px solid rgba(6,182,212,0.25); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: var(--font);
  line-height: 1.4;
  text-decoration: none;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: #2563eb;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border-2);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-2);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-success:hover:not(:disabled) { background: #059669; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(239,68,68,0.3);
}
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-lg { padding: 0.65rem 1.4rem; font-size: 1rem; }

/* ============================================================
   LAYOUT
   ============================================================ */
.page-wrap {
  /* Was 1200px — too narrow for the wide tables (Differences Explorer is now
     14 cols, the per-row detail table 17). Let it fill the viewport on a normal
     1080p/1440p monitor while capping on ultrawides so prose lines don't get
     unreadably long. */
  max-width: min(96vw, 1900px);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.75rem 1.25rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: -1px;
  font-family: var(--font);
}
.tab-btn:hover { color: var(--text-2); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-2); }

.card-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.2rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.card-head:hover { background: var(--surface-3); }

.card-head-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
}
.card-head-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.card-body { padding: 1.25rem; }

.chevron {
  color: var(--muted);
  transition: transform var(--transition);
  font-size: 0.8rem;
  flex-shrink: 0;
}
.collapsed .chevron { transform: rotate(-90deg); }
.collapsed .card-body,
.collapsed .turns-wrap { display: none; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

label.form-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-2);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  padding: 0.55rem 0.85rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder { color: var(--muted); }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 0.4; }
input[type="number"] { -moz-appearance: textfield; }

.file-drop {
  position: relative;
  border: 2px dashed var(--border-2);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--surface);
}
.file-drop:hover, .file-drop.drag-over {
  border-color: var(--accent);
  background: var(--surface-2);
}
.file-drop input[type="file"] {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
  width: 100%; height: 100%;
}
.file-drop-icon { font-size: 2.2rem; color: var(--muted); margin-bottom: 0.5rem; }
.file-drop-label { font-size: 0.9rem; color: var(--text-2); font-weight: 500; }
.file-drop-sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.file-drop-names { font-size: 0.85rem; color: var(--accent-2); margin-top: 0.5rem; font-family: var(--font-mono); }

/* ============================================================
   UPLOAD PANEL
   ============================================================ */
.upload-panel {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 700px) {
  .upload-panel { grid-template-columns: 1fr; }
}

.upload-options {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.upload-options h3 { font-size: 0.875rem; color: var(--text-2); margin-bottom: 0.25rem; }

/* ============================================================
   STATUS BAR
   ============================================================ */
#status-msg {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
#status-msg.info    { background: rgba(59,130,246,0.12); color: #93c5fd; border: 1px solid rgba(59,130,246,0.25); display: flex; }
#status-msg.success { background: var(--success-bg); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.25); display: flex; }
#status-msg.error   { background: var(--danger-bg); color: #fca5a5; border: 1px solid rgba(239,68,68,0.25); display: flex; }

/* ============================================================
   RESULTS TOOLBAR
   ============================================================ */
.results-toolbar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.results-toolbar.visible { display: flex; }
.toolbar-spacer { flex: 1; }

.page-size-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-2);
}
.page-size-wrap select {
  width: auto;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
}

/* ============================================================
   ARCHIVE RESULTS
   ============================================================ */
#results-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.archive-meta {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.meta-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.meta-value {
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-mono);
}

.dl-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* ============================================================
   TURN BLOCK
   ============================================================ */
.turns-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0 1.25rem 1.25rem;
}

.turn-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.turn-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.turn-head:hover { filter: brightness(1.1); }

.turn-label {
  font-weight: 600;
  font-size: 0.875rem;
}
.turn-stats {
  flex: 1;
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.stat-voiced { color: var(--speech); }
.stat-silent { color: var(--silence); }
.stat-gated  { color: var(--gated); }

.turn-body { padding: 0.75rem 1rem; }
.collapsed .turn-body { display: none; }

/* ============================================================
   BAR CHART
   ============================================================ */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 76px;
  padding: 4px 0 0;
  overflow-x: auto;
  margin-bottom: 0.75rem;
}

.bar {
  width: 10px;
  min-width: 10px;
  border-radius: 3px 3px 0 0;
  cursor: pointer;
  transition: filter var(--transition);
  flex-shrink: 0;
  position: relative;
}
.bar:hover { filter: brightness(1.35); }
.bar:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 0.72rem;
  white-space: nowrap;
  z-index: 50;
  pointer-events: none;
  color: var(--text);
  box-shadow: var(--shadow);
}

.bar.speech  { background: linear-gradient(180deg, #f87171 0%, #dc2626 100%); }
.bar.silence { background: linear-gradient(180deg, #60a5fa 0%, #2563eb 100%); }
.bar.gated   { background: var(--gated); opacity: 0.55; }
.bar.error   { background: var(--warn); opacity: 0.8; }

/* ============================================================
   CHUNK TABLE
   ============================================================ */
.chunk-table-wrap { overflow-x: auto; margin-top: 0.5rem; }

table.chunk-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

table.chunk-table thead th {
  padding: 0.5rem 0.75rem;
  text-align: left;
  background: var(--surface-3);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

table.chunk-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
table.chunk-table tbody tr:hover { background: var(--surface-3); }
table.chunk-table tbody tr:last-child { border-bottom: none; }

table.chunk-table td {
  padding: 0.45rem 0.75rem;
  color: var(--text-2);
  font-family: var(--font-mono);
}

tr.speech-row td { color: var(--speech); }
tr.gated-row td  { color: var(--gated); }
tr.error-row td  { color: var(--warn); }

/* ============================================================
   PAGER
   ============================================================ */
.pager {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-size: 0.82rem;
  flex-wrap: wrap;
}
.pager-info { color: var(--muted); flex: 1; font-family: var(--font-mono); }
.pager button {
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: 5px;
  color: var(--text-2);
  cursor: pointer;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  transition: all var(--transition);
  font-family: var(--font);
}
.pager button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}
.pager button:disabled { opacity: 0.35; cursor: not-allowed; }

/* ============================================================
   JSON SUMMARY
   ============================================================ */
.summary-details {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.summary-details summary {
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  background: var(--surface-3);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-2);
  list-style: none;
  user-select: none;
}
.summary-details summary:hover { background: var(--surface-2); }
.summary-details pre {
  background: var(--surface);
  padding: 0.85rem;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  overflow-x: auto;
  color: var(--text-2);
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.5;
}

/* ============================================================
   CSV PROGRESS PANEL
   ============================================================ */
.csv-job-panel {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
}
.csv-job-panel.visible { display: flex; }

.progress-section { }
.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.progress-title {
  font-size: 0.9rem;
  font-weight: 600;
}
.progress-count {
  font-size: 0.85rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

.progress-bar-wrap {
  background: var(--surface-2);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  max-height: 220px;
  overflow-y: auto;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.log-entry { padding: 0.1rem 0; line-height: 1.5; }
.log-entry.ok   { color: var(--success); }
.log-entry.err  { color: var(--danger); }
.log-entry.info { color: var(--accent-2); }
.log-entry.done { color: var(--accent); font-weight: 600; }

/* ============================================================
   RUN HISTORY
   ============================================================ */
.runs-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.run-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  cursor: pointer;
  transition: all var(--transition);
}
.run-item:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}
.run-item-id {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}
.run-item-time { font-size: 0.8rem; color: var(--muted); }
.run-item-counts { display: flex; gap: 0.75rem; font-size: 0.82rem; }
.run-count-ok  { color: var(--success); }
.run-count-err { color: var(--danger); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}
.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px; height: 52px;
  background: var(--accent);
  border-radius: var(--radius-lg);
  font-size: 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 0 24px rgba(59,130,246,0.35);
}
.login-header h1 { font-size: 1.4rem; margin-bottom: 0.25rem; }
.login-header p  { font-size: 0.875rem; color: var(--text-2); }

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.login-error {
  background: var(--danger-bg);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  font-size: 0.875rem;
  color: #fca5a5;
}

/* ============================================================
   ADMIN PANEL
   ============================================================ */
.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.admin-section-head {
  padding: 0.85rem 1.25rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
}
.admin-section-body { padding: 1.25rem; }

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.user-table th {
  text-align: left;
  padding: 0.6rem 0.85rem;
  background: var(--surface-3);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.user-table td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}
.user-table tr:last-child td { border-bottom: none; }
.user-table tr:hover td { background: var(--surface-2); }
.user-inactive { opacity: 0.42; }

.create-user-form {
  display: grid;
  grid-template-columns: 1fr 1fr 130px auto;
  gap: 0.75rem;
  align-items: end;
  margin-top: 1rem;
}
@media (max-width: 640px) {
  .create-user-form { grid-template-columns: 1fr; }
}

/* ============================================================
   CHANGE PASSWORD MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
}
.modal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }
.text-muted   { color: var(--muted); }
.text-accent  { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warn    { color: var(--warn); }
.text-mono    { font-family: var(--font-mono); }
.text-sm      { font-size: 0.85rem; }
.text-xs      { font-size: 0.78rem; }
.fw-600       { font-weight: 600; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.gap-row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

/* Spinner */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Divider */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

/* ===================================================================== */
/*  Comparison + Dataset UI (compare.js)                                 */
/* ===================================================================== */
.cmp-intro { color: var(--muted); margin: 0 0 1rem; max-width: 80ch; }

.cmp-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 1.1rem; overflow: hidden;
}
.cmp-section-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 1rem; background: var(--surface-2, #0c1422);
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.9rem;
}
.cmp-section-body { padding: 1rem; }

/* segmented toggle */
.seg-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 0.9rem; }
.seg {
  background: transparent; color: var(--muted); border: 0; cursor: pointer;
  padding: 0.4rem 0.9rem; font-size: 0.85rem; font-family: inherit;
}
.seg.active { background: var(--accent); color: #fff; }

.file-drop.sm { padding: 1rem; min-height: auto; }

/* variant cards */
.variant-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.8rem; margin-bottom: 0.8rem; background: var(--bg);
}
.variant-card.baseline { border-style: dashed; opacity: 0.92; }
.variant-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.variant-head .v-label { flex: 1 1 160px; font-weight: 600; }
.variant-card input, .variant-card select, .ds-add-row input, .ds-add-row select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.3rem 0.5rem; font-family: inherit; font-size: 0.85rem;
}
.v-params { margin-top: 0.7rem; }
.v-params summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.param-group-title { font-size: 0.78rem; color: var(--accent); margin: 0.7rem 0 0.3rem; text-transform: uppercase; letter-spacing: 0.04em; }
.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.5rem; }
.param-field { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; color: var(--muted); }
.param-field input[type="checkbox"] { align-self: flex-start; }

.v-preprocess { margin-top: 0.8rem; border-top: 1px dashed var(--border); padding-top: 0.7rem; }
.vp-head { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; }
.op-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.4rem 0.6rem; margin-bottom: 0.4rem; }
.op-name { font-weight: 600; font-size: 0.82rem; }
.op-param { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.75rem; color: var(--muted); }
.op-param input { width: 6rem; }

.cmp-run-row { display: flex; align-items: center; gap: 1rem; margin: 0.5rem 0 1rem; }

/* per-variant summary chips + diff table */
.vchips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.8rem; }
.vchip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0.25rem 0.7rem; font-size: 0.78rem; }
.diff-controls { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.diff-controls select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem 0.5rem; }
.diff-table { width: 100%; }
.diff-table td.diff-up   { background: var(--success-bg); color: var(--success); }
.diff-table td.diff-down { background: var(--danger-bg);  color: var(--danger); }
.diff-table td.diff-flip { background: var(--warn-bg);    color: var(--warn); font-weight: 600; }
.diff-table-wrap { max-height: 460px; overflow: auto; }
.sc-cell { font-variant-numeric: tabular-nums; }

/* dataset */
.ds-counts { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.ds-scan-bar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }

/* audio playback row (analyze cards + compare drill-down) */
.audio-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.7rem; margin: 0.5rem 0; }
.audio-row-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.audio-chan { display: inline-flex; align-items: center; gap: 0.35rem; }
.audio-label { font-size: 0.78rem; color: var(--muted); }
.audio-chan audio { height: 2rem; max-width: 16rem; }

/* variant settings panel */
.vset-body { display: flex; flex-direction: column; gap: 0.5rem; }
.vset-row { display: flex; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; }
.vset-name { min-width: 9rem; font-weight: 600; }
.vset-chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* saved-comparison header */
.cmp-run-header { margin-bottom: 0.8rem; padding-bottom: 0.6rem; border-bottom: 1px solid var(--border); }
.cmp-rh-title { display: flex; gap: 0.6rem; align-items: center; }
.cmp-rh-name { font-size: 1.05rem; }

/* History bulk-delete toolbar */
.runs-toolbar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.5rem 0.8rem; margin-bottom: 0.8rem; font-size: 0.85rem; }
.runs-selall-label { display: flex; align-items: center; gap: 0.35rem; }

/* uuid cells in compare tables: truncated visually; the floating #uuid-tooltip
   (appended to body, position:fixed) shows the full value on hover so it isn't
   clipped by overflow:auto wrappers like .dx-table-wrap / .diff-table-wrap. */
.uuid-cell { font-size: 0.8rem; white-space: nowrap; cursor: help; }
.uuid-tip  { cursor: help; }
.nowrap { white-space: nowrap; }

#uuid-tooltip {
  position: fixed;
  z-index: 1000;
  display: none;
  background: #0b1424;
  color: #f5f7fb;
  border: 1px solid var(--border, #2a3550);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  user-select: text;
}
#uuid-tooltip.show { display: block; }

/* one-click copy button next to a uuid (or any other value) */
.copy-btn {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0 0.32rem;
  min-width: 1.5rem;
  height: 1.35rem;
  line-height: 1.25rem;
  font-size: 0.72rem;
  background: transparent;
  border: 1px solid var(--border, #2a3550);
  border-radius: 3px;
  color: var(--muted, #8a96b1);
  cursor: pointer;
  vertical-align: middle;
  user-select: none;
}
.copy-btn:hover { background: rgba(255,255,255,0.06); color: var(--fg, #e8ecf3); }
.copy-btn.copied { color: var(--success, #10b981); border-color: var(--success, #10b981); }
.copy-btn.copy-fail { color: var(--danger, #ef4444); border-color: var(--danger, #ef4444); }

/* ---- Differences Explorer: per-row action buttons ---- */
.dx-actions { white-space: nowrap; }
.dx-act {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.75rem; height: 1.5rem; margin: 0 0.12rem;
  background: transparent; color: var(--muted, #8a96b1);
  border: 1px solid var(--border, #2a3550);
  border-radius: 3px;
  font-size: 0.82rem; line-height: 1;
  cursor: pointer; user-select: none;
}
.dx-act:hover { background: rgba(255,255,255,0.07); color: var(--fg, #e8ecf3); }
.dx-act:disabled { opacity: 0.55; cursor: progress; }
.dx-act.dx-sent { color: var(--success, #10b981); border-color: var(--success, #10b981); }
.dx-act.dx-fail { color: var(--danger, #ef4444); border-color: var(--danger, #ef4444); }

/* ---- Per-row detail panel: full per-packet table for the whole call ------- */
.dx-detail-row > td { background: rgba(255,255,255,0.025); padding: 0.5rem 0.7rem; }
.dx-detail-head { font-size: 0.86rem; margin-bottom: 0.45rem; }
.dx-detail-table-wrap { overflow-x: auto; max-height: 360px; overflow-y: auto;
  border: 1px solid var(--border, #2a3550); border-radius: 4px; }
.dxd-table { font-size: 0.75rem; width: 100%; border-collapse: collapse; }
.dxd-table thead th { position: sticky; top: 0; background: var(--surface, #131c2e);
  font-size: 0.72rem; text-align: center; padding: 0.25rem 0.45rem;
  border-bottom: 1px solid var(--border, #2a3550); white-space: nowrap; }
.dxd-table thead tr:first-child th[colspan] { border-bottom: 1px solid var(--border, #2a3550); }
.dxd-table tbody td { padding: 0.22rem 0.45rem; white-space: nowrap; text-align: right; }
.dxd-table tbody td:nth-child(1), .dxd-table tbody td:nth-child(2) { text-align: center; }
/* verdict + VAD columns (shifted by 1 since the "time" column landed at col 3) */
.dxd-table tbody td:nth-child(9), .dxd-table tbody td:nth-child(10),
.dxd-table tbody td:nth-child(14), .dxd-table tbody td:nth-child(15) { text-align: center; }
.dxd-table tbody tr:hover { background: rgba(255,255,255,0.04); }
.dxd-table tr.dxd-flip td { background: rgba(239, 68, 68, 0.08); }
.dxd-table tr.dxd-current td { background: rgba(245, 158, 11, 0.18); box-shadow: inset 2px 0 0 var(--accent, #f59e0b); }
.dxd-table tr.dxd-current.dxd-flip td { background: rgba(245, 158, 11, 0.22); }

/* ---- 'Send to category' popup (position:fixed so overflow:auto can't clip it) */
.dx-cat-menu {
  position: fixed; z-index: 1000;
  background: var(--surface, #131c2e);
  color: var(--fg, #e8ecf3);
  border: 1px solid var(--border, #2a3550);
  border-radius: 4px;
  padding: 0.25rem 0;
  min-width: 200px;
  max-height: 320px; overflow-y: auto;
  box-shadow: 0 8px 22px rgba(0,0,0,0.55);
}
.dx-cat-title {
  padding: 0.3rem 0.75rem; font-size: 0.75rem; color: var(--muted, #8a96b1);
  border-bottom: 1px solid var(--border, #2a3550); margin-bottom: 0.2rem;
}
.dx-cat-opt {
  display: block; width: 100%; text-align: left;
  padding: 0.35rem 0.8rem;
  background: transparent; color: var(--fg, #e8ecf3);
  border: 0; cursor: pointer; font: inherit; font-size: 0.85rem;
}
.dx-cat-opt:hover { background: rgba(255,255,255,0.08); }
.dx-cat-opt.dx-cat-new { color: var(--accent, #4f8bff); border-top: 1px solid var(--border, #2a3550); margin-top: 0.2rem; }
/* transcript cells: truncated preview, full text on hover */
.transcript-cell { max-width: 16rem; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; cursor: help; font-size: 0.8rem; }
.cmp-transcript { margin: 0.4rem 0; line-height: 1.4; }

/* History run items */
.run-item-main { display: flex; gap: 0.5rem; align-items: center; }
.run-item-name { font-weight: 600; }
.run-kind { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.1rem 0.45rem; border-radius: 999px; border: 1px solid var(--border); }
.run-kind-compare { background: var(--accent-bg, var(--surface)); color: var(--accent); border-color: var(--accent); }
.run-kind-analyze { background: var(--surface); color: var(--muted); }
.run-rename { margin-left: auto; }
.ds-count { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0.25rem 0.7rem; font-size: 0.8rem; }
.ds-add-row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* bulk action toolbar + dataset pagers */
.ds-bulkbar { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.55rem 0.8rem; margin-bottom: 0.6rem; font-size: 0.82rem; }
.ds-bulk-group { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.ds-bulk-group select { font-size: 0.8rem; }
.ds-bulk-view { margin-left: auto; padding-left: 1rem; border-left: 1px solid var(--border); }
.ds-bulk-sep { width: 1px; height: 1.1rem; background: var(--border); margin: 0 0.3rem; }
.ds-pager-top, .ds-pager-bottom { display: flex; gap: 0.6rem; align-items: center; justify-content: flex-end; margin: 0.4rem 0; }
.ds-pager-top:empty, .ds-pager-bottom:empty { display: none; }
#ds-table th:first-child, #ds-table td:first-child { width: 1.6rem; text-align: center; }
.radio-row { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; }
.dataset-pick-list { max-height: 240px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem; }
.ds-pick { display: block; padding: 0.2rem 0; font-size: 0.85rem; }
.ds-pick input { margin-right: 0.4rem; }

/* category badges */
.badge-false_negative, .ds-count.badge-false_negative { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.badge-false_positive, .ds-count.badge-false_positive { background: var(--warn-bg);   color: var(--warn);   border: 1px solid var(--warn); }
.badge-normal,         .ds-count.badge-normal         { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.badge-uncategorized   { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }

/* ---- turn-label threshold tuning + matrix ---- */
.tt-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem 0; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tt-row:last-child { border-bottom: 0; }
.tt-name { flex: 0 0 180px; font-size: 0.85rem; font-weight: 600; }
.tt-slider { flex: 1 1 200px; accent-color: var(--accent); }
.tt-val { font-family: var(--font-mono); font-size: 0.8rem; width: 2.6rem; text-align: right; }
.tt-acc { font-size: 0.85rem; width: 6rem; }
.tt-spark { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; }
.mono { font-family: var(--font-mono); }

.turn-matrix { width: 100%; margin: 0.3rem 0 0.8rem; }
.turn-matrix th, .turn-matrix td { padding: 0.25rem 0.5rem; text-align: left; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.turn-matrix td.tm-ok  { background: var(--success-bg); color: var(--success); }
.turn-matrix td.tm-bad { background: var(--danger-bg);  color: var(--danger); }

.turn-label-editor { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; padding: 0.5rem 0; }
.turn-label-row { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.78rem; color: var(--muted); }
.turn-label-row select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem 0.4rem; }
.ds-detail td { background: var(--bg); }

/* ---- archive-card pagination (large runs) ---- */
.archive-pager {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  padding: 0.5rem 0.75rem; margin: 0.5rem 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.archive-pager .text-sm { margin: 0 0.25rem; }

/* ---- live (production-recorded) vs replayed value comparison ---- */
.chunk-table td.live-match { color: var(--success); }
.chunk-table td.live-diff  { color: var(--warn); font-weight: 600; }

/* ---- CSV import: collapsed, counted error section ---- */
.csv-errors { margin-top: 0.5rem; border: 1px solid var(--danger); border-radius: var(--radius); background: var(--danger-bg); }
.csv-errors > summary { cursor: pointer; padding: 0.5rem 0.75rem; color: var(--danger); font-size: 0.85rem; font-weight: 600; }
.csv-errors-list { max-height: 240px; overflow: auto; padding: 0.25rem 0.75rem 0.6rem; font-family: var(--font-mono); font-size: 0.78rem; }

/* ---- voiced/unvoiced filter ---- */
.cmp-filter-bar { margin: 0.25rem 0 0.75rem; font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 0.5rem; }
.cmp-filter-bar select, .page-size-wrap select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem 0.4rem; font-family: inherit; }

/* ---- dataset picker "select all" row ---- */
.ds-pick-all { border-bottom: 1px solid var(--border); padding-bottom: 0.35rem; margin-bottom: 0.25rem; }

/* ===================================================================== */
/*  Comparison results — analysis views                                  */
/* ===================================================================== */
/* variant summary cards */
.summary-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 0.8rem; }
.vsummary { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem; background: var(--bg); }
.vs-head { font-size: 0.95rem; margin-bottom: 0.5rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem; }
.cfg-chips { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; }
.cfg-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0.05rem 0.4rem; font-size: 0.72rem; font-family: var(--font-mono); color: var(--muted); }
.vs-grid { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.vs-cell { text-align: center; }
.transition { border-collapse: collapse; font-size: 0.8rem; }
.transition th, .transition td { border: 1px solid var(--border); padding: 0.2rem 0.5rem; text-align: center; font-variant-numeric: tabular-nums; }
.transition th { color: var(--muted); font-weight: 500; }
.transition td.t-gain { background: var(--success-bg); color: var(--success); font-weight: 600; }
.transition td.t-loss { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.vs-stats { flex: 1 1 200px; font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.25rem; }
.vs-score { margin-top: 0.5rem; display: flex; flex-wrap: wrap; gap: 0.6rem; font-size: 0.8rem; }
.vs-takeaway { margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px dashed var(--border); font-size: 0.85rem; color: var(--text-2, var(--text)); }

/* differences explorer */
.diff-controls-bar { display: flex; flex-wrap: wrap; gap: 0.6rem 0.9rem; align-items: center; margin-bottom: 0.6rem; font-size: 0.82rem; color: var(--muted); }
.diff-controls-bar select, .diff-controls-bar input { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.2rem 0.4rem; font-family: inherit; margin-left: 0.25rem; }
.dx-headline { margin: 0.2rem 0 0.4rem; }
.dx-spark { display: block; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; margin-bottom: 0.6rem; max-width: 100%; }
.dx-table-wrap { max-height: 520px; overflow: auto; }
.diff-table .tag { display: inline-block; border-radius: 4px; padding: 0.02rem 0.35rem; font-size: 0.72rem; border: 1px solid var(--border); }
.diff-table .tag-up { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.diff-table .tag-down { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.diff-table .tag-gate { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }

/* per-call rollup */
.rollup-table th.sortable { cursor: pointer; user-select: none; }
.rollup-table th.sortable:hover { color: var(--accent); }
.rollup-table tr[data-uuid]:hover td { background: var(--surface-2, var(--surface)); }
.ru-detail { margin-top: 0.8rem; }

/* rollup header controls */
.cmp-section-head select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 0.15rem 0.4rem; font-family: inherit; }
.ru-pager-top, .ru-pager-bottom { margin: 0.3rem 0; }
