/* ═══════════════════════════════════════════════════
   AegisVoice v4 — ECAPA-TDNN Voice Authentication
   Design: Dark-first, technical aesthetic
   ═══════════════════════════════════════════════════ */

/* ─── Reset & Tokens ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  --text-xs:   0.75rem;
  --text-sm:   0.8125rem;
  --text-base: 0.875rem;
  --text-lg:   1rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem;    --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem;    --space-10: 2.5rem; --space-12: 3rem;

  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px;
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Dark theme */
  --bg: #0a0a0c;
  --surface: #111114;
  --surface-2: #18181c;
  --surface-3: #222228;
  --border: #2a2a32;
  --border-subtle: #1c1c24;
  --text: #e8e8ee;
  --text-muted: #8888a0;
  --text-faint: #555566;
  --primary: #5ba4b0;
  --primary-hover: #6dbdca;
  --primary-muted: rgba(91, 164, 176, 0.12);
  --success: #4ade80;
  --success-muted: rgba(74, 222, 128, 0.10);
  --error: #f87171;
  --error-muted: rgba(248, 113, 113, 0.10);
  --warning: #fbbf24;
  --warning-muted: rgba(251, 191, 36, 0.10);
  --accent-purple: #a78bfa;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 2px 8px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.15);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4), 0 16px 48px rgba(0,0,0,0.2);

  --sidebar-width: 230px;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  color: var(--primary);
}

/* ─── Layout ─── */
#app {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.logo { color: var(--primary); flex-shrink: 0; }

.logo-text {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.nav-list {
  list-style: none;
  padding: var(--space-3) var(--space-3);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-family: inherit;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.nav-item:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-item.active {
  color: var(--primary);
  background: var(--primary-muted);
  font-weight: 500;
}

.nav-item svg { flex-shrink: 0; opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.db-status,
.modal-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background var(--transition);
}

.db-status.connected .status-dot,
.modal-status.connected .status-dot { background: var(--success); box-shadow: 0 0 6px rgba(74, 222, 128, 0.4); }
.db-status.error .status-dot,
.modal-status.error .status-dot { background: var(--error); }

/* ─── Main Content ─── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--space-8) var(--space-8) var(--space-12);
  max-width: 1100px;
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 250ms ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  margin-bottom: var(--space-8);
}

.view-header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: var(--space-1);
}

.subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ─── Stats Grid ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--transition);
}

.stat-card:hover {
  border-color: var(--border);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
  font-weight: 500;
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  line-height: 1;
}

.stat-detail {
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-top: var(--space-2);
}

/* ─── Architecture Card ─── */
.architecture-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-8);
}

.architecture-card h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-5);
  color: var(--text-muted);
}

.pipeline-flow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-2);
}

.pipeline-node {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
}

.pipeline-node.accent {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-muted);
}

.pipeline-node.result {
  border-color: var(--success);
  color: var(--success);
  background: var(--success-muted);
}

.pipeline-arrow {
  color: var(--text-faint);
  font-size: var(--text-sm);
  flex-shrink: 0;
}

/* ─── Quick Actions ─── */
.quick-actions h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--text-muted);
}

.action-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
}

.action-card:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-muted);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.action-card svg { opacity: 0.6; transition: opacity var(--transition); }
.action-card:hover svg { opacity: 1; }

/* ─── Form Cards ─── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-group label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.form-group input::placeholder {
  color: var(--text-faint);
}

.form-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

/* ─── Buttons ─── */
.btn-primary {
  padding: var(--space-3) var(--space-6);
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-sm); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }

.btn-danger {
  padding: var(--space-1) var(--space-3);
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error-muted);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-danger:hover { background: var(--error-muted); border-color: var(--error); }

.btn-small {
  padding: var(--space-1) var(--space-3);
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary-muted);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-small:hover { background: var(--primary-muted); border-color: var(--primary); }

/* ─── Record Button ─── */
.btn-record {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: var(--surface-3);
  border: 2px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-record:hover {
  border-color: var(--primary);
  background: var(--primary-muted);
}

.btn-record.recording {
  border-color: var(--error);
  background: var(--error-muted);
  animation: recordPulse 1.5s infinite;
}

@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.3); }
  50% { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
}

/* ─── Audio Controls ─── */
.audio-controls {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.audio-controls canvas {
  flex: 1;
  height: 80px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.audio-status {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ─── Challenge Phrase ─── */
.challenge-phrase {
  padding: var(--space-4) var(--space-5);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-md);
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: var(--space-3);
  font-style: italic;
}

/* ─── Enrollment/Verify Steps ─── */
.enroll-step, .verify-step {
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.enroll-step:last-child, .verify-step:last-child { border-bottom: none; }

.enroll-step h3, .verify-step h3 {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-4);
}

/* ─── Driver Info Card ─── */
.driver-info-card {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: var(--space-3);
}

.driver-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-muted);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-xs);
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.driver-avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-muted);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.65rem;
  flex-shrink: 0;
  text-transform: uppercase;
}

.driver-avatar-lg {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary-muted);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  flex-shrink: 0;
  text-transform: uppercase;
}

.driver-cell {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.driver-meta { flex: 1; }

.driver-meta .name {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text);
}

.driver-meta .detail {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.text-warning { color: var(--warning); }

/* ─── Result Messages ─── */
.result-message {
  margin-top: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.6;
  display: none;
}

.result-message.show { display: block; animation: fadeIn 250ms ease; }
.result-message.success { background: var(--success-muted); color: var(--success); border: 1px solid rgba(74, 222, 128, 0.25); }
.result-message.error { background: var(--error-muted); color: var(--error); border: 1px solid rgba(248, 113, 113, 0.25); }
.result-message.warning { background: var(--warning-muted); color: var(--warning); border: 1px solid rgba(251, 191, 36, 0.25); }
.result-message.info { background: var(--primary-muted); color: var(--primary); border: 1px solid rgba(91, 164, 176, 0.25); }
.result-message strong { display: block; margin-bottom: var(--space-1); font-size: var(--text-base); }
.result-message code { background: rgba(255,255,255,0.06); color: inherit; }

/* ─── Score Card ─── */
.score-card {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-6);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: var(--space-4);
}

.score-ring-container {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}

.score-ring { width: 100%; height: 100%; }

.score-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-2xl);
  font-weight: 700;
  font-family: var(--font-mono);
}

.score-details {
  flex: 1;
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 2;
  font-family: var(--font-mono);
}

.score-details strong { color: var(--text); font-weight: 600; }

/* ─── Data Table ─── */
.drivers-table-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover td { background: var(--surface-2); }

.table-actions {
  display: flex;
  gap: var(--space-2);
}

.empty-state {
  text-align: center;
  color: var(--text-faint);
  padding: var(--space-10) var(--space-4) !important;
}

.empty-state-text {
  text-align: center;
  color: var(--text-faint);
  padding: var(--space-6);
  font-size: var(--text-sm);
}

.link-action { color: var(--primary); cursor: pointer; }
.link-action:hover { text-decoration: underline; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}

.badge-active { background: var(--success-muted); color: var(--success); }
.badge-pending { background: var(--warning-muted); color: var(--warning); }
.badge-suspended { background: var(--error-muted); color: var(--error); }
.badge-inactive { background: var(--surface-3); color: var(--text-faint); }

/* ─── Settings ─── */
.settings-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.setting-item label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
}

.config-input-row {
  display: flex;
  gap: var(--space-2);
}

.config-input-row input {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
}

.config-input-row input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ─── Schema Grid ─── */
.schema-description {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.schema-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.schema-table-card {
  padding: var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.schema-table-card h4 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--primary);
  font-family: var(--font-mono);
  margin-bottom: var(--space-3);
}

.schema-table-card ul { list-style: none; }

.schema-table-card li {
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding: 2px 0;
  line-height: 1.6;
}

.schema-table-card code {
  font-family: var(--font-mono);
  color: var(--text);
  font-size: var(--text-xs);
  background: transparent;
  padding: 0;
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 200ms ease;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-content h2 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-1);
}

.modal-content h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

.modal-driver-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  transition: all var(--transition);
}

.modal-close:hover { color: var(--text); border-color: var(--text-muted); }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.detail-item {
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}

.detail-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-faint);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ─── Event Log ─── */
.event-log {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 150;
  transition: transform 250ms ease;
}

.event-log.collapsed { transform: translateY(calc(100% - 36px)); }

.event-log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  user-select: none;
}

.event-log-header svg {
  transition: transform 200ms ease;
}

.event-log.collapsed .event-log-header svg {
  transform: rotate(180deg);
}

.event-log-body {
  max-height: 240px;
  overflow-y: auto;
  padding: var(--space-2);
}

.log-entry {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-faint);
  border-bottom: 1px solid var(--border-subtle);
  line-height: 1.5;
}

.log-entry:last-child { border-bottom: none; }
.log-entry .log-time { color: var(--text-faint); margin-right: var(--space-2); }
.log-entry.log-success { color: var(--success); }
.log-entry.log-error { color: var(--error); }
.log-entry.log-warn { color: var(--warning); }
.log-entry.log-info { color: var(--primary); }

/* ─── Footer ─── */
.app-footer {
  position: fixed;
  bottom: var(--space-2);
  left: var(--sidebar-width);
  padding: 0 var(--space-4);
}

.app-footer a,
.app-footer span {
  font-size: var(--text-xs);
  color: var(--text-faint);
  text-decoration: none;
}


/* ═══════════════════════════════════════════════════
   v4 — Transcript, Progress, Checks, Logs, Anti-Spoof
   ═══════════════════════════════════════════════════ */

/* ─── Transcript Live ─── */
.transcript-live {
  margin-top: var(--space-3);
  min-height: 40px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  display: none;
}

.transcript-live.active {
  display: block;
  animation: transcriptPulse 2s ease-in-out infinite;
}

.transcript-live.done {
  display: block;
  animation: none;
  border-color: var(--border);
}

@keyframes transcriptPulse {
  0%, 100% { border-color: var(--border); }
  50% { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-muted); }
}

.speech-note {
  color: var(--text-faint);
  font-style: italic;
}

/* ─── Phrase Progress Bar ─── */
.phrase-progress {
  margin-top: var(--space-2);
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 300ms ease;
}

.phrase-progress.active {
  opacity: 1;
}

.phrase-progress .progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  width: 0%;
  transition: width 300ms ease, background-color 300ms ease;
}

.phrase-progress .progress-fill.complete {
  background: var(--success);
}

/* ─── Checks Breakdown ─── */
.checks-breakdown {
  display: none;
  margin-top: var(--space-4);
}

.checks-breakdown.show {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-3);
}

.check-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition);
}

.check-card.check-pass {
  border-left: 3px solid var(--success);
}

.check-card.check-fail {
  border-left: 3px solid var(--error);
}

.check-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: var(--text-sm);
  font-weight: 700;
}

.check-pass .check-icon {
  background: var(--success-muted);
  color: var(--success);
}

.check-fail .check-icon {
  background: var(--error-muted);
  color: var(--error);
}

.check-info {
  flex: 1;
  min-width: 0;
}

.check-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.check-values {
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-muted);
  line-height: 1.5;
  word-break: break-word;
}

/* ─── Logs View ─── */
.log-filters {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.log-filter-btn {
  padding: var(--space-1) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.log-filter-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.log-filter-btn.active {
  background: var(--primary-muted);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.log-auto-refresh {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.auto-refresh-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  animation: autoRefreshPulse 2s ease-in-out infinite;
}

@keyframes autoRefreshPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.logs-table-container {
  overflow-x: auto;
}

.logs-table {
  min-width: 700px;
}

.logs-table td {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  white-space: nowrap;
}

.logs-table th {
  padding: var(--space-2) var(--space-3);
}

.logs-table .log-details {
  white-space: normal;
  max-width: 300px;
  word-break: break-word;
}

/* Log type badges */
.log-type-badge {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.log-type-badge.type-enrollment {
  background: var(--primary-muted);
  color: var(--primary);
}

.log-type-badge.type-verification {
  background: rgba(167, 139, 250, 0.12);
  color: var(--accent-purple);
}

.log-type-badge.type-spoof {
  background: var(--error-muted);
  color: var(--error);
}

.log-type-badge.type-error {
  background: var(--warning-muted);
  color: var(--warning);
}

.log-type-badge.type-registration {
  background: var(--success-muted);
  color: var(--success);
}

/* ─── Anti-Spoof Controls ─── */
.antispoof-descriptions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.param-category {
  padding: var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.param-category h4 {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--primary);
  margin-bottom: var(--space-2);
}

.param-category p {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.6;
}

/* Slider Controls */
.slider-control {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.slider-control:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.slider-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

.slider-value {
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--primary);
  background: var(--primary-muted);
  padding: 2px var(--space-3);
  border-radius: var(--radius-sm);
  min-width: 52px;
  text-align: center;
}

.slider-track {
  position: relative;
  width: 100%;
}

.slider-track input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  border: none;
}

.slider-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.slider-track input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 4px var(--primary-muted), 0 1px 4px rgba(0, 0, 0, 0.4);
}

.slider-track input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.slider-track input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  border: none;
}

.slider-track input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px var(--primary-muted), 0 1px 4px rgba(0, 0, 0, 0.4);
}

.slider-description {
  font-size: var(--text-xs);
  color: var(--text-faint);
  line-height: 1.5;
}

.slider-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: all var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary-muted);
  border-color: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: var(--primary);
}

.toggle-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.antispoof-actions {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* ─── Responsive ─── */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .action-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .sidebar .logo-text,
  .sidebar .nav-item span,
  .sidebar .status-text { display: none; }
  .sidebar-header { justify-content: center; padding: var(--space-4) var(--space-2); }
  .nav-list { padding: var(--space-2); }
  .nav-item { justify-content: center; padding: var(--space-3); }
  .sidebar-footer { padding: var(--space-2); align-items: center; }
  .main-content { margin-left: 56px; padding: var(--space-4); }
  .form-row { grid-template-columns: 1fr; }
  .app-footer { left: 56px; }
  .score-card { flex-direction: column; }
  .event-log { width: 280px; }
  .checks-breakdown.show { grid-template-columns: 1fr; }
  .antispoof-descriptions { grid-template-columns: 1fr; }
  .settings-group { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .action-cards { grid-template-columns: 1fr; }
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ─── Utility ─── */
.settings-loading {
  text-align: center;
  color: var(--text-faint);
  padding: var(--space-8);
}

/* ═══════════════════════════════════════════════════
   Color Challenge Overlay (Anti-Spoof Liveness)
   ═══════════════════════════════════════════════════ */

.color-challenge-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}

.color-challenge-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.color-challenge-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: ccSlideIn 300ms ease;
}

@keyframes ccSlideIn {
  from { transform: translateY(20px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.color-challenge-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  color: var(--warning);
  font-weight: 600;
  font-size: var(--text-lg);
  margin-bottom: var(--space-4);
}

.color-challenge-header svg {
  stroke: var(--warning);
}

.color-challenge-instruction {
  color: var(--text-muted);
  font-size: var(--text-base);
  margin-bottom: var(--space-5);
}

.color-challenge-square {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-lg);
  margin: 0 auto var(--space-3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: background 200ms ease;
}

.color-challenge-number {
  font-size: 3rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  font-family: var(--font-mono);
}

.color-challenge-status {
  min-height: 28px;
  margin-bottom: var(--space-3);
  font-size: var(--text-base);
}

.color-challenge-listening {
  color: var(--primary);
  animation: ccPulse 1.2s ease-in-out infinite;
}

@keyframes ccPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.color-challenge-heard {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.color-challenge-pass {
  color: var(--success);
  font-weight: 600;
  font-size: var(--text-lg);
}

.color-challenge-fail {
  color: var(--error);
  font-weight: 600;
}

.color-challenge-timer {
  color: var(--text-faint);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
}

/* ─── Login Overlay ─── */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.login-overlay.active {
  display: flex;
  opacity: 1;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: var(--space-8);
  color: var(--primary);
}

.login-logo svg {
  margin-bottom: var(--space-4);
}

.login-logo h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-1);
}

.login-subtitle {
  color: var(--text-muted);
  font-size: var(--text-sm);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.login-card .form-group {
  margin-bottom: var(--space-4);
}

.login-card label {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-1);
}

.login-card input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-base);
  font-family: var(--font-body);
  transition: border-color var(--transition);
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-error {
  background: var(--error-muted);
  color: var(--error);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.login-btn {
  width: 100%;
  padding: var(--space-3);
  font-size: var(--text-base);
  margin-top: var(--space-2);
}

/* ─── User Info in Sidebar Footer ─── */

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-2);
}

.user-info-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.user-info-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
}

.btn-logout:hover {
  color: var(--error);
  border-color: var(--error);
}

/* ─── Role Badges ─── */

.badge-role-super_admin {
  background: rgba(167, 139, 250, 0.15);
  color: var(--accent-purple);
}

.badge-role-admin {
  background: var(--primary-muted);
  color: var(--primary);
}

.badge-role-user {
  background: rgba(136, 136, 160, 0.12);
  color: var(--text-muted);
}

/* ─── User Management ─── */

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.add-user-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.add-user-form h3 {
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--text);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.form-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.btn-danger {
  background: var(--error-muted);
  color: var(--error);
  border: 1px solid transparent;
}

.btn-danger:hover {
  background: var(--error);
  color: white;
}

.actions-cell {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}

.text-muted {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

/* ─── Registration Wizard ─── */
.reg-wizard {
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin-bottom: var(--space-8);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.reg-wizard-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 auto;
}
.reg-wizard-step .step-num {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface-2);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  transition: var(--transition);
}
.reg-wizard-step .step-label {
  font-size: var(--text-xs);
  color: var(--text-faint);
  white-space: nowrap;
  transition: var(--transition);
}
.reg-wizard-step.active .step-num {
  border-color: var(--primary);
  background: var(--primary-muted);
  color: var(--primary);
}
.reg-wizard-step.active .step-label { color: var(--primary); }
.reg-wizard-step.done .step-num {
  border-color: var(--success);
  background: var(--success-muted);
  color: var(--success);
}
.reg-wizard-step.done .step-label { color: var(--success); }
.reg-wizard-connector {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0.9rem 0.375rem 0;
  transition: background var(--transition);
}
.reg-wizard-connector.done { background: var(--success); }
