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

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #10b981;
  --success-soft: #ecfdf5;
  --warn: #f59e0b;
  --warn-soft: #fffbeb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ── SIDEBAR ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 24px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.demo-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--warn-soft);
  color: #b45309;
  border: 1px solid #fde68a;
}

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

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}

.nav-btn:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.storage-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.storage-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

.reset-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.reset-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

/* ── MAIN & TOPBAR ── */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.demo-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

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

.mobile-reset-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.mobile-reset-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

.clock-pill {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
}

/* ── PAGES ── */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.page.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}

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

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

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

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

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: #cbd5e1;
}

.btn-full {
  width: 100%;
  padding: 11px 16px;
}

/* ── SCANNER PAGE ── */
#page-scanner {
  padding: 20px 28px;
}

.scanner-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.scanner-stage {
  position: relative;
  flex: 1;
  background: #0f172a;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.scanner-stage.detected {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2), var(--shadow-md);
}

.scanner-stage.accepted {
  border-color: var(--success);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.25), var(--shadow-md);
}

.scanner-stage.rejected {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.25), var(--shadow-md);
}

.scanner-stage.unregistered {
  border-color: var(--warn);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.25), var(--shadow-md);
}

#scanner-video,
#scanner-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.model-loading {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #f8fafc;
  font-size: 13.5px;
  z-index: 10;
}

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

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

.scanner-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.scanner-stage.detected .scanner-overlay {
  box-shadow: inset 0 0 60px rgba(37, 99, 235, 0.22);
}

.scanner-stage.accepted .scanner-overlay {
  background: rgba(16, 185, 129, 0.12);
  box-shadow: inset 0 0 80px rgba(16, 185, 129, 0.35);
}

.scanner-stage.rejected .scanner-overlay {
  background: rgba(239, 68, 68, 0.12);
  box-shadow: inset 0 0 80px rgba(239, 68, 68, 0.35);
}

.scanner-stage.unregistered .scanner-overlay {
  background: rgba(245, 158, 11, 0.12);
  box-shadow: inset 0 0 80px rgba(245, 158, 11, 0.32);
}

.scan-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -54%);
  width: min(300px, 56vw);
  height: min(300px, 56vw);
  border-radius: 16px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.scan-frame.detected {
  background: rgba(37, 99, 235, 0.08);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
}

.scan-frame.accepted {
  background: rgba(16, 185, 129, 0.12);
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.45);
}

.scan-frame.rejected {
  background: rgba(239, 68, 68, 0.12);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.45);
}

.scan-frame.unregistered {
  background: rgba(245, 158, 11, 0.12);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.45);
}

.corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: rgba(255, 255, 255, 0.65);
  border-style: solid;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.scan-frame.detected .corner {
  border-color: var(--accent);
}

.scan-frame.accepted .corner {
  border-color: var(--success);
}

.scan-frame.rejected .corner {
  border-color: var(--danger);
}

.scan-frame.unregistered .corner {
  border-color: var(--warn);
}

.corner.tl {
  top: 0;
  left: 0;
  border-width: 2.5px 0 0 2.5px;
  border-top-left-radius: 8px;
}

.corner.tr {
  top: 0;
  right: 0;
  border-width: 2.5px 2.5px 0 0;
  border-top-right-radius: 8px;
}

.corner.bl {
  bottom: 0;
  left: 0;
  border-width: 0 0 2.5px 2.5px;
  border-bottom-left-radius: 8px;
}

.corner.br {
  bottom: 0;
  right: 0;
  border-width: 0 2.5px 2.5px 0;
  border-bottom-right-radius: 8px;
}

.scan-status {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.scan-status.detected {
  border-color: #bfdbfe;
}

.scan-status.accepted {
  border-color: #a7f3d0;
  background: rgba(236, 253, 245, 0.96);
}

.scan-status.rejected {
  border-color: #fecaca;
  background: rgba(254, 242, 242, 0.96);
}

.scan-status.unregistered {
  border-color: #fde68a;
  background: rgba(255, 251, 235, 0.96);
}

.status-icon-wrap {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--surface-subtle);
  color: var(--muted);
}

.scan-status.detected .status-icon-wrap {
  background: var(--accent-soft);
  color: var(--accent);
}

.scan-status.accepted .status-icon-wrap {
  background: #d1fae5;
  color: var(--success);
}

.scan-status.rejected .status-icon-wrap {
  background: #fee2e2;
  color: var(--danger);
}

.scan-status.unregistered .status-icon-wrap {
  background: #fef3c7;
  color: #d97706;
}

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

.scan-status.detected .status-dot {
  background: var(--accent);
}

.scan-status.accepted .status-dot {
  background: var(--success);
}

.scan-status.rejected .status-dot {
  background: var(--danger);
}

.scan-status.unregistered .status-dot {
  background: var(--warn);
}

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

.status-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--muted);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.scan-status.detected .status-badge {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #bfdbfe;
}

.scan-status.accepted .status-badge {
  background: #d1fae5;
  color: #065f46;
  border-color: #a7f3d0;
}

.scan-status.rejected .status-badge {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}

.scan-status.unregistered .status-badge {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

.status-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.steady-track {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
  overflow: hidden;
  margin-top: 7px;
}

.steady-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.08s linear;
}

.confidence-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 72px;
}

.conf-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
}

.conf-track {
  width: 72px;
  height: 5px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.conf-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.match-toast {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid #a7f3d0;
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  transform: translateY(-16px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
}

.match-toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--success-soft);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-name {
  font-size: 14px;
  font-weight: 600;
}

.toast-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ── REGISTER PAGE ── */
.register-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}

.register-camera-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.reg-video-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #0f172a;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.reg-video-wrap.captured {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

#reg-video,
#reg-canvas,
.reg-frozen-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.reg-frozen-preview {
  z-index: 2;
}

.reg-captured-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.92);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
}

.reg-cam-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.reg-face-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(210px, 48%);
  height: min(250px, 76%);
  border: 2px dashed rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  pointer-events: none;
  transition: border-color 0.2s;
}

.reg-face-ring.detected {
  border-color: var(--accent);
  border-style: solid;
}

.reg-face-ring.ready {
  border-color: var(--success);
  border-style: solid;
}

.reg-steady-overlay {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 8px 12px;
  pointer-events: none;
}

.reg-steady-label {
  font-size: 12px;
  font-weight: 500;
  color: #f8fafc;
}

.reg-cam-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reg-face-hint {
  font-size: 13px;
  color: var(--muted);
}

.reg-face-hint span {
  font-weight: 500;
  color: var(--text);
}

.register-form-card {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.card-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}

.form-input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--accent);
}

.descriptor-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.descriptor-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.descriptor-preview.captured {
  background: var(--success-soft);
  border-color: #a7f3d0;
  color: #065f46;
}

.descriptor-preview.captured .descriptor-dot {
  background: var(--success);
}

.form-msg {
  font-size: 13px;
  border-radius: 8px;
  display: none;
  padding: 9px 12px;
}

.form-msg.success {
  display: block;
  background: var(--success-soft);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.form-msg.error {
  display: block;
  background: var(--danger-soft);
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ── EMPLOYEES PAGE ── */
.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  flex: 1;
  min-width: 0;
  max-width: 320px;
  color: var(--muted);
}

.search-box input {
  border: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text);
  width: 100%;
  background: transparent;
}

.count-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 8px;
}

.employees-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 14px;
}

.emp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.emp-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.emp-head > div:last-child {
  min-width: 0;
}

.emp-avatar {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

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

.emp-name {
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emp-id {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--accent);
  margin-top: 2px;
}

.emp-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
}

.emp-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.btn-remove {
  width: 100%;
  padding: 7px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-remove:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

.empty-state {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 56px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13.5px;
}

/* ── LOGS PAGE ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.date-input {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  outline: none;
}

.date-input:focus {
  border-color: var(--accent);
}

.table-card {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

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

th {
  position: sticky;
  top: 0;
  background: var(--surface-subtle);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}

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

tbody tr:hover td {
  background: var(--surface-subtle);
}

.log-thumb {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
}

.log-thumb-placeholder {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.log-id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.log-conf {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--success-soft);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.log-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

.empty-row {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  font-size: 13px;
}

/* ── MODAL ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-md);
}

.modal-card img {
  width: 100%;
  border-radius: 10px;
  display: block;
}

.modal-caption {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(15, 23, 42, 0.7);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    padding: 10px 16px;
    gap: 14px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .nav {
    flex-direction: row;
  }

  .nav-btn {
    white-space: nowrap;
  }

  .sidebar-footer {
    display: none;
  }

  .mobile-reset-btn {
    display: inline-flex;
  }

  .register-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  .main {
    order: 1;
    flex: 1;
    min-height: 0;
  }

  .sidebar {
    order: 2;
    flex-shrink: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 0;
    border-bottom: none;
    border-top: 1px solid var(--border);
    overflow: visible;
  }

  .brand {
    display: none;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    width: 100%;
  }

  .nav-btn {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 7px 4px;
    font-size: 11px;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
  }

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

  .topbar {
    height: 52px;
    padding: 0 14px;
    gap: 8px;
  }

  .topbar-left {
    min-width: 0;
    flex: 1;
  }

  .page-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .demo-tag {
    display: none;
  }

  .clock-pill {
    font-size: 11.5px;
    padding: 4px 8px;
  }

  .mobile-reset-btn {
    width: 30px;
    height: 30px;
  }

  .page {
    padding: 14px;
  }

  .page.active {
    gap: 14px;
  }

  #page-scanner {
    padding: 12px;
  }

  .scanner-stage {
    border-width: 2px;
    border-radius: 12px;
  }

  .scanner-overlay {
    padding: 12px;
  }

  .scan-frame {
    width: min(260px, 64vw, 42dvh);
    height: min(260px, 64vw, 42dvh);
    transform: translate(-50%, -56%);
  }

  .scan-status {
    padding: 10px 12px;
    gap: 10px;
    max-width: none;
    width: 100%;
  }

  .status-name {
    font-size: 13.5px;
  }

  .match-toast {
    top: 12px;
    left: 12px;
    right: 12px;
    padding: 10px 12px;
  }

  .register-camera-card {
    padding: 12px;
    gap: 12px;
  }

  .register-form-card {
    padding: 16px;
    gap: 14px;
  }

  .reg-cam-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .reg-cam-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .form-input,
  .search-box input,
  .date-input {
    font-size: 16px;
  }

  .search-box {
    max-width: none;
    flex: 1 1 180px;
  }

  .stats-grid {
    gap: 8px;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-label {
    font-size: 11px;
  }

  .stat-value {
    font-size: 20px;
  }

  #page-logs .page-toolbar {
    gap: 8px;
  }

  #page-logs .date-input {
    flex: 1;
    min-width: 0;
  }

  .modal-backdrop {
    padding: 14px;
  }
}

@media (max-width: 640px) {
  .table-card {
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
    flex: none;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 40px 1fr auto;
    gap: 2px 12px;
    align-items: center;
    box-shadow: var(--shadow-sm);
  }

  tbody td {
    padding: 0;
    border-bottom: none;
    min-width: 0;
  }

  tbody td:nth-child(1) {
    grid-column: 1;
    grid-row: 1 / 4;
    align-self: center;
  }

  tbody td:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  tbody td:nth-child(3) {
    grid-column: 2;
    grid-row: 2;
  }

  tbody td:nth-child(4) {
    grid-column: 2;
    grid-row: 3;
    font-size: 12px;
    color: var(--muted);
  }

  tbody td:nth-child(5) {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }

  tbody td:nth-child(6) {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
  }

  tbody td.empty-row {
    grid-column: 1 / -1;
    padding: 32px 12px;
  }
}