/* ============================================================
   AI Face Attendance Dashboard - Self-Contained Modern Styles
   ============================================================ */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, 'Sukhumvit Set', 'Sarabun', 'Thonburi', 'Noto Sans Thai', 'Segoe UI', Roboto, sans-serif;

  /* Surfaces */
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #e2e8f0;

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  /* Borders */
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Brand & Accents */
  --indigo-50: #eef2ff;
  --indigo-100: #e0e7ff;
  --indigo-500: #6366f1;
  --indigo-600: #4f46e5;
  --indigo-700: #4338ca;

  --emerald-50: #ecfdf5;
  --emerald-100: #d1fae5;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;

  --sky-50: #f0f9ff;
  --sky-100: #e0f2fe;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;

  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --amber-500: #f59e0b;
  --amber-700: #b45309;

  --rose-50: #fff1f2;
  --rose-100: #ffe4e6;
  --rose-500: #ef4444;
  --rose-600: #dc2626;
  --rose-700: #b91c1c;

  /* Shadows & Radii */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.16), 0 6px 14px rgba(15, 23, 42, 0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --topbar-h: 66px;
  --transition: 160ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

.hidden {
  display: none !important;
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-emerald { color: var(--emerald-600); }
.text-rose { color: var(--rose-600); }
.text-indigo { color: var(--indigo-600); }
.text-muted { color: var(--text-muted); }

/* ==================== TOP NAVIGATION ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.topbar-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--indigo-600), var(--indigo-500));
  color: #ffffff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  line-height: 1.25;
}

.brand-subtitle {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-page);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-tab svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.7);
}

.nav-tab.active {
  background: var(--bg-card);
  color: var(--indigo-600);
  box-shadow: var(--shadow-sm);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.status-pill:hover {
  border-color: var(--border-strong);
  background: #ffffff;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber-500);
  flex-shrink: 0;
}

.status-pill.status-ready {
  background: var(--emerald-50);
  border-color: var(--emerald-100);
  color: var(--emerald-700);
}

.status-pill.status-ready .status-dot {
  background: var(--emerald-500);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.22);
}

.status-pill.status-warning {
  background: var(--amber-50);
  border-color: var(--amber-100);
  color: var(--amber-700);
}

.status-pill.status-warning .status-dot {
  background: var(--amber-500);
}

.status-pill.status-offline {
  background: var(--rose-50);
  border-color: var(--rose-100);
  color: var(--rose-700);
}

.status-pill.status-offline .status-dot {
  background: var(--rose-500);
}

/* ==================== MAIN CONTAINER & TABS ==================== */
.main-container {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px;
}

.tab-panel {
  display: none;
  animation: fadeIn 180ms ease;
}

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

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

/* ==================== BUTTONS & INPUTS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.25;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

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

.btn-lg {
  padding: 11px 20px;
  font-size: 0.95rem;
  border-radius: 10px;
}

.btn-sm {
  padding: 5px 11px;
  font-size: 0.82rem;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--indigo-600);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: var(--indigo-700);
}

.btn-emerald {
  background: var(--emerald-600);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.22);
}

.btn-emerald:hover:not(:disabled) {
  background: var(--emerald-700);
}

.btn-danger {
  background: var(--rose-600);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--rose-700);
}

.btn-secondary {
  background: #ffffff;
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: #94a3b8;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-page);
  color: var(--text-primary);
}

.btn-soft-indigo {
  background: var(--indigo-50);
  color: var(--indigo-700);
  border-color: var(--indigo-100);
}

.btn-soft-indigo:hover:not(:disabled) {
  background: var(--indigo-100);
}

.btn-soft-emerald {
  background: var(--emerald-50);
  color: var(--emerald-700);
  border-color: var(--emerald-100);
}

.btn-soft-emerald:hover:not(:disabled) {
  background: var(--emerald-100);
}

.btn-soft-rose {
  background: var(--rose-50);
  color: var(--rose-700);
  border-color: var(--rose-100);
}

.btn-soft-rose:hover:not(:disabled) {
  background: var(--rose-100);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--indigo-600);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-link:hover {
  text-decoration: underline;
}

.input-text, .input-select {
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-text:focus, .input-select:focus {
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
}

.input-select {
  padding-right: 30px;
  cursor: pointer;
}

/* ==================== CARDS & BADGES ==================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-emerald { background: var(--emerald-50); color: var(--emerald-700); border: 1px solid var(--emerald-100); }
.badge-sky { background: var(--sky-50); color: var(--sky-600); border: 1px solid var(--sky-100); }
.badge-indigo { background: var(--indigo-50); color: var(--indigo-700); border: 1px solid var(--indigo-100); }
.badge-amber { background: var(--amber-50); color: var(--amber-700); border: 1px solid var(--amber-100); }
.badge-rose { background: var(--rose-50); color: var(--rose-700); border: 1px solid var(--rose-100); }
.badge-slate { background: var(--bg-page); color: var(--text-secondary); border: 1px solid var(--border); }

/* ==================== TAB 1: REALTIME CHECK-IN ==================== */
.checkin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.stage-card {
  overflow: hidden;
}

.stage-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}

.segmented-control {
  display: inline-flex;
  background: var(--bg-muted);
  padding: 3px;
  border-radius: 10px;
  gap: 3px;
}

.seg-full {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  margin-bottom: 14px;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  transition: all var(--transition);
}

.seg-btn svg {
  width: 16px;
  height: 16px;
}

.seg-btn.active {
  background: #ffffff;
  color: var(--indigo-600);
  box-shadow: var(--shadow-xs);
}

.stage-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.dot-emerald { background: var(--emerald-500); }
.dot-sky { background: var(--sky-500); }
.dot-red { background: var(--rose-500); }

.stage-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.control-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.control-group-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.control-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
}

.toggle-chip:hover {
  border-color: var(--border-strong);
}

.toggle-chip input[type="checkbox"] {
  accent-color: var(--indigo-600);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.control-cta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Camera Viewport */
.viewport-stage {
  background: #0f172a;
  position: relative;
}

.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  min-height: 400px;
  max-height: 68vh;
  background: #0b1120;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#checkin-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#checkin-video.mirror {
  transform: scaleX(-1);
}

#checkin-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.stage-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  background: radial-gradient(circle at 50% 35%, #1e293b 0%, #0f172a 75%);
  color: #f8fafc;
  z-index: 3;
}

.placeholder-icon {
  width: 68px;
  height: 68px;
  border-radius: 18px;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(129, 140, 248, 0.35);
  color: #a5b4fc;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
}

.placeholder-icon svg {
  width: 34px;
  height: 34px;
}

.stage-placeholder h3 {
  margin: 0 0 6px;
  font-size: 1.2rem;
  font-weight: 700;
}

.stage-placeholder p {
  margin: 0 0 22px;
  color: #94a3b8;
  max-width: 480px;
  font-size: 0.92rem;
}

.placeholder-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* Telemetry HUD */
.telemetry-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.telemetry-left, .telemetry-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.hud-chip, .hud-conn {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #f1f5f9;
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hud-conn.conn-ws {
  background: rgba(5, 150, 105, 0.85);
  border-color: rgba(16, 185, 129, 0.5);
}

.hud-conn.conn-http {
  background: rgba(2, 132, 199, 0.85);
  border-color: rgba(56, 189, 248, 0.5);
}

.hud-conn.conn-err {
  background: rgba(220, 38, 38, 0.85);
  border-color: rgba(248, 113, 113, 0.5);
}

/* Photo / Group Test Stage */
.photo-dropzone {
  min-height: 440px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: radial-gradient(circle at 50% 35%, #1e293b 0%, #0f172a 75%);
  color: #f8fafc;
  cursor: pointer;
  border: 2px dashed rgba(148, 163, 184, 0.35);
  margin: 14px;
  border-radius: 14px;
  transition: all var(--transition);
}

.photo-dropzone:hover, .photo-dropzone.dragover {
  border-color: #818cf8;
  background: radial-gradient(circle at 50% 35%, #27344f 0%, #111827 75%);
}

.dropzone-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 520px;
}

.dropzone-content h3 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.dropzone-content p {
  margin: 0 0 20px;
  color: #94a3b8;
  font-size: 0.9rem;
}

.photo-result-container {
  display: flex;
  flex-direction: column;
}

.photo-canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 400px;
  max-height: 68vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b1120;
  overflow: hidden;
  padding: 10px;
}

#photo-canvas {
  max-width: 100%;
  max-height: calc(68vh - 20px);
  display: block;
  border-radius: 8px;
}

.photo-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #ffffff;
  font-weight: 600;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #818cf8;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.photo-result-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  background: #ffffff;
  border-top: 1px solid var(--border);
}

.photo-result-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.photo-result-actions {
  display: flex;
  gap: 8px;
}

/* ==================== RIGHT SIDEBAR (CHECK-IN) ==================== */
.checkin-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.summary-mini-card, .detected-card, .feed-card {
  padding: 15px 16px;
}

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

.card-title-sm {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-primary);
}

.live-summary-numbers {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.live-stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--emerald-600);
  font-variant-numeric: tabular-nums;
}

.live-stat-total {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
}

.live-stat-rate {
  font-size: 1rem;
  font-weight: 700;
  color: var(--indigo-600);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  overflow: hidden;
}

.progress-sm {
  height: 6px;
  margin-top: 6px;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--emerald-500), var(--indigo-500));
  transition: width 320ms ease;
}

.detected-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.feed-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 310px;
  overflow-y: auto;
}

.feed-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  transition: background var(--transition);
}

.feed-item.feed-new {
  background: var(--emerald-50);
  border-color: var(--emerald-100);
  animation: pulseHighlight 900ms ease;
}

.feed-item.feed-unknown {
  background: var(--rose-50);
  border-color: var(--rose-100);
}

@keyframes pulseHighlight {
  0% { transform: scale(0.98); background: #a7f3d0; }
  100% { transform: scale(1); background: var(--emerald-50); }
}

.avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--indigo-100);
  color: var(--indigo-700);
  font-weight: 700;
  font-size: 0.84rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-circle.avatar-unknown {
  background: var(--rose-100);
  color: var(--rose-700);
}

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

.feed-name {
  font-weight: 700;
  font-size: 0.87rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.feed-right {
  text-align: right;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.feed-time {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.empty-mini {
  padding: 20px 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ==================== PAGE HEADERS & FILTERS ==================== */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.page-subtitle {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-card {
  padding: 14px 16px;
  margin-bottom: 16px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-input-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrap .input-text {
  width: 100%;
  padding-left: 34px;
}

.filter-stats {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 0.83rem;
  color: var(--text-secondary);
}

.stat-pill-emerald {
  background: var(--emerald-50);
  border-color: var(--emerald-100);
  color: var(--emerald-700);
}

.stat-pill-indigo {
  background: var(--indigo-50);
  border-color: var(--indigo-100);
  color: var(--indigo-700);
}

.quality-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 78px;
}

.quality-bar {
  width: 72px;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  overflow: hidden;
}

.quality-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 260ms ease;
}

.quality-fill-high {
  background: var(--emerald-500);
}

.quality-fill-mid {
  background: var(--amber-500);
}

.quality-fill-low {
  background: var(--rose-500);
}

.gallery-header-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

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

/* ==================== KPI GRID ==================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.kpi-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.kpi-icon svg {
  width: 23px;
  height: 23px;
}

.kpi-icon-slate { background: var(--bg-page); color: var(--text-secondary); }
.kpi-icon-emerald { background: var(--emerald-50); color: var(--emerald-600); }
.kpi-icon-rose { background: var(--rose-50); color: var(--rose-600); }
.kpi-icon-indigo { background: var(--indigo-50); color: var(--indigo-600); }

.kpi-body {
  min-width: 0;
  flex: 1;
}

.kpi-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-value {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.status-filter-pills {
  display: inline-flex;
  background: var(--bg-page);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.pill-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.84rem;
  cursor: pointer;
  transition: all var(--transition);
}

.pill-btn.active {
  background: #ffffff;
  color: var(--indigo-600);
  box-shadow: var(--shadow-xs);
}

/* ==================== DATA TABLES ==================== */
.table-card {
  overflow: hidden;
}

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table thead th {
  text-align: left;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}

.data-table thead th.text-center { text-align: center; }
.data-table thead th.text-right { text-align: right; }

.data-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: #f8fafc;
}

.table-empty {
  text-align: center;
  padding: 46px 20px !important;
  color: var(--text-muted);
}

.student-cell {
  display: flex;
  align-items: center;
  gap: 11px;
}

.student-name-main {
  font-weight: 700;
  color: var(--text-primary);
}

.code-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.table-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* ==================== MODALS ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
}

.modal-dialog {
  width: 100%;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 170ms ease;
}

.modal-sm { max-width: 430px; }
.modal-md { max-width: 580px; }
.modal-lg { max-width: 680px; }
.modal-xl { max-width: 920px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.modal-subtitle {
  margin: 2px 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.modal-close {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.modal-close:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
}

.modal-footer:not(:has(.modal-footer-right)) {
  justify-content: flex-end;
}

.modal-footer-right {
  display: flex;
  gap: 8px;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.req {
  color: var(--rose-600);
}

/* Info / Tip Banners & Dropzone */
.info-banner {
  background: var(--indigo-50);
  border: 1px solid var(--indigo-100);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.86rem;
}

.info-banner-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.column-order-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.column-order-chips span {
  padding: 3px 9px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid var(--indigo-100);
  color: var(--indigo-700);
  font-size: 0.78rem;
  font-weight: 600;
}

.tip-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  background: var(--sky-50);
  border: 1px solid var(--sky-100);
  color: #0369a1;
  font-size: 0.84rem;
  margin-bottom: 16px;
}

.tip-banner svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.upload-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  padding: 26px 18px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}

.upload-dropzone:hover, .upload-dropzone.dragover {
  border-color: var(--indigo-500);
  background: var(--indigo-50);
}

.upload-dropzone svg {
  width: 36px;
  height: 36px;
  color: var(--indigo-500);
  margin-bottom: 8px;
}

.dropzone-title {
  margin: 0 0 4px;
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-primary);
}

.dropzone-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--indigo-600);
}

.import-result {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  font-size: 0.86rem;
}

.import-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.import-stat-box {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}

.import-stat-box span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.import-stat-box strong {
  font-size: 1.15rem;
}

.import-errors-list {
  max-height: 150px;
  overflow-y: auto;
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--rose-700);
  font-size: 0.82rem;
}

/* ==================== FACE ENROLLMENT MODAL ==================== */
.faces-modal-grid {
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.enroll-webcam-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0f172a;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 10px;
}

#enroll-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#enroll-video.mirror {
  transform: scaleX(-1);
}

.enroll-guide-oval {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 52%;
  height: 76%;
  border: 2px dashed rgba(16, 185, 129, 0.8);
  border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(15, 23, 42, 0.25);
  pointer-events: none;
}

.enroll-webcam-placeholder {
  position: absolute;
  inset: 0;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.upload-feedback {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.feedback-row {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.81rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.feedback-ok {
  background: var(--emerald-50);
  border: 1px solid var(--emerald-100);
  color: var(--emerald-700);
}

.feedback-err {
  background: var(--rose-50);
  border: 1px solid var(--rose-100);
  color: var(--rose-700);
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.gallery-header h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.faces-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: 12px;
  max-height: 390px;
  overflow-y: auto;
  padding-right: 2px;
}

.face-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.face-card-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #0f172a;
  overflow: hidden;
}

.face-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.face-quality-pill {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: rgba(15, 23, 42, 0.78);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
}

.face-card-footer {
  padding: 7px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 0.73rem;
  color: var(--text-muted);
}

.btn-delete-face {
  border: none;
  background: var(--rose-50);
  color: var(--rose-600);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-delete-face:hover {
  background: var(--rose-100);
}

/* ==================== SETTINGS MODAL ==================== */
.model-info-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 18px;
}

.model-info-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.model-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
}

.model-kv {
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}

.model-kv span {
  color: var(--text-muted);
}

.model-kv strong {
  color: var(--text-primary);
  text-align: right;
  word-break: break-word;
}

.setting-item {
  margin-bottom: 18px;
}

.setting-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.setting-head label {
  font-weight: 700;
  font-size: 0.9rem;
}

.setting-value-badge {
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--indigo-50);
  color: var(--indigo-700);
  font-weight: 800;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.range-slider {
  width: 100%;
  accent-color: var(--indigo-600);
  cursor: pointer;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.setting-help {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cooldown-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.cooldown-controls .input-text {
  width: 120px;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  padding: 5px 11px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn:hover {
  border-color: var(--indigo-500);
  color: var(--indigo-600);
  background: var(--indigo-50);
}

.confirm-message {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.btn-danger-outline {
  background: #ffffff;
  color: var(--rose-600);
  border: 1px solid #fecdd3;
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--rose-50);
  border-color: var(--rose-500);
  color: var(--rose-700);
}

.btn-warning-outline {
  background: #ffffff;
  color: #b45309;
  border: 1px solid #fde68a;
}

.btn-warning-outline:hover:not(:disabled) {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #92400e;
}

.danger-zone-box {
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: #fff1f2;
  border: 1px solid #fecdd3;
}

.danger-zone-title {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--rose-700);
  margin-bottom: 4px;
}

.danger-zone-desc {
  margin: 0 0 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.danger-zone-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ==================== TOAST NOTIFICATIONS ==================== */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 15px;
  border-radius: var(--radius-md);
  background: #0f172a;
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 4px solid var(--indigo-500);
  animation: toastIn 200ms ease;
}

.toast-success { border-left-color: var(--emerald-500); }
.toast-error { border-left-color: var(--rose-500); }
.toast-warning { border-left-color: var(--amber-500); }
.toast-info { border-left-color: var(--sky-500); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1120px) {
  .checkin-layout {
    grid-template-columns: 1fr;
  }

  .checkin-sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-mini-card {
    grid-column: 1 / -1;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .topbar-inner {
    flex-wrap: wrap;
    padding: 10px 14px;
  }

  .nav-tabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .nav-tab {
    flex: 1;
    justify-content: center;
  }

  .faces-modal-grid {
    grid-template-columns: 1fr;
  }

  .model-info-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main-container {
    padding: 12px;
  }

  .hide-sm {
    display: none;
  }

  .checkin-sidebar {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .import-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .control-cta {
    margin-left: 0;
    width: 100%;
  }

  .control-cta .btn {
    flex: 1;
  }
}
