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

:root {
  --bg: #0c0c0f;
  --surface: #14141a;
  --surface2: #1c1c24;
  --surface3: #24242f;
  --accent: #2563eb;
  --accent-dim: rgba(37, 99, 235, 0.18);
  --accent-glow: rgba(37, 99, 235, 0.35);
  --ok: #22c55e;
  --ok-dim: rgba(34, 197, 94, 0.15);
  --ok-border: rgba(34, 197, 94, 0.35);
  --followup: #ef4444;
  --followup-dim: rgba(239, 68, 68, 0.15);
  --followup-border: rgba(239, 68, 68, 0.35);
  --text: #f0f0f5;
  --text-muted: #9090a8;
  --text-dim: #50506a;
  --border: rgba(255,255,255,0.07);
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
}

html { scroll-behavior: smooth; overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
}

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #38384a; }

/* ── LOGO ── */
.logo {
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  background: linear-gradient(125deg, #ffffff 0%, #f0f0f5 50%, #2563eb 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  user-select: none;
  text-decoration: none;
}
.logo span {
  background: linear-gradient(125deg, #2563eb, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── TOPBAR ── */
.topbar {
  position: sticky; top: 0; z-index: 100; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  background: rgba(12, 12, 15, 0.90);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; gap: 4px; align-items: center; }

.nav-link {
  font-size: 0.84rem; font-weight: 700;
  color: var(--text-muted); text-decoration: none;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid transparent;
  transition: all 0.18s ease;
}
.nav-link:hover,
.nav-link.active { color: var(--text); border-color: var(--border); background: var(--surface2); }

/* ── BADGE ── */
.badge {
  display: inline-flex; align-items: center;
  font-size: 0.67rem; font-weight: 800;
  padding: 3px 8px; border-radius: 100px; letter-spacing: 0.3px;
}
.badge-ok { background: var(--ok-dim); color: var(--ok); border: 1px solid var(--ok-border); }
.badge-followup { background: var(--followup-dim); color: var(--followup); border: 1px solid var(--followup-border); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.9rem; font-weight: 700;
  cursor: pointer; transition: all 0.18s ease; text-decoration: none;
  white-space: nowrap; width: 100%;
}
.btn:hover:not(:disabled) { background: var(--surface3); border-color: rgba(255,255,255,0.12); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; border-color: #1d4ed8; }

/* ── SECTION HEADER ── */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 10px;
}
.section-title { font-size: 0.9rem; font-weight: 800; letter-spacing: -0.1px; }
.session-count {
  font-size: 0.72rem; font-weight: 800; color: var(--text-dim);
  background: var(--surface2); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 100px;
}

/* ── EMPTY / LOADING STATE ── */
.empty-state, .loading-state {
  text-align: center; padding: 48px 18px;
  color: var(--text-muted); font-size: 0.9rem; line-height: 1.6;
}
.empty-state a { color: var(--accent); text-decoration: none; font-weight: 700; }

/* ── STATUS BANNER ── */
.status-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px; border-radius: var(--radius-lg);
  border: 1px solid var(--border); background: var(--surface);
  margin-bottom: 16px;
}
.status-banner.all-clear { border-color: var(--ok-border); background: var(--ok-dim); }
.status-banner.action-required { border-color: var(--followup-border); background: var(--followup-dim); }
.status-icon {
  font-size: 1.5rem; line-height: 1; flex-shrink: 0;
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
}
.all-clear .status-icon { color: var(--ok); }
.action-required .status-icon { color: var(--followup); }
.no-activity .status-icon { color: var(--text-dim); }
.status-text { display: flex; flex-direction: column; gap: 3px; }
.status-text strong { font-size: 0.95rem; font-weight: 800; }
.status-text span { font-size: 0.8rem; color: var(--text-muted); }
.all-clear .status-text strong { color: var(--ok); }
.action-required .status-text strong { color: var(--followup); }

/* ── STATS GRID ── */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px;
  margin-bottom: 20px;
}
@media (max-width: 600px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-card.ok { border-color: var(--ok-border); }
.stat-card.followup { border-color: var(--followup-border); }
.stat-value { font-size: 1.9rem; font-weight: 900; letter-spacing: -1px; line-height: 1; margin-bottom: 5px; }
.stat-card.ok .stat-value { color: var(--ok); }
.stat-card.followup .stat-value { color: var(--followup); }
.stat-label { font-size: 0.7rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── QUICK ACTIONS ── */
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
@media (max-width: 480px) { .quick-actions { grid-template-columns: 1fr; } }

.action-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  text-decoration: none; color: var(--text);
  transition: all 0.22s ease; display: flex; flex-direction: column; gap: 4px;
}
.action-card:hover { border-color: rgba(255,255,255,0.12); background: var(--surface2); transform: translateY(-1px); }
.action-icon { width: 36px; height: 36px; margin-bottom: 4px; color: var(--accent); }
.action-icon svg { width: 36px; height: 36px; }
.action-title { font-size: 0.9rem; font-weight: 800; }
.action-desc { font-size: 0.75rem; color: var(--text-muted); }

/* ── SCANS LIST ── */
.scans-list { display: flex; flex-direction: column; gap: 5px; }
.scan-row {
  display: grid; grid-template-columns: 90px 80px 1fr auto;
  align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--radius); padding: 10px 14px;
}
.scan-row.ok { border-left-color: var(--ok); }
.scan-row.followup { border-left-color: var(--followup); }
.scan-device-id { font-size: 0.84rem; font-weight: 800; font-family: monospace; }
.scan-reason { font-size: 0.76rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-time { font-size: 0.7rem; color: var(--text-dim); white-space: nowrap; }
@media (max-width: 560px) { .scan-row { grid-template-columns: 75px 70px 1fr; } .scan-time { display: none; } }

/* ── DASHBOARD WRAPPER ── */
.dashboard { max-width: 860px; margin: 0 auto; padding: 20px 18px 60px; }

/* ── SCAN PAGE ── */
.scan-page { max-width: 520px; margin: 0 auto; padding: 20px 18px 60px; }

.viewfinder {
  position: relative; width: 100%; aspect-ratio: 4 / 3;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--radius-xl); overflow: hidden; margin-bottom: 14px;
}
.viewfinder.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: none; }
.viewfinder.active video { display: block; }
.viewfinder canvas { display: none; }
.viewfinder-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; color: var(--text-dim);
}
.viewfinder-placeholder svg { width: 52px; height: 52px; }
.viewfinder-placeholder span { font-size: 0.82rem; font-weight: 600; }

.scan-toggle-btn {
  display: block; width: 100%; padding: 14px;
  border-radius: var(--radius-lg); border: none;
  font-size: 0.95rem; font-weight: 800; cursor: pointer;
  transition: all 0.18s ease; margin-bottom: 12px;
  background: var(--accent); color: #fff;
}
.scan-toggle-btn:hover { background: #1d4ed8; }
.scan-toggle-btn.stop {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted);
}
.scan-toggle-btn.stop:hover { background: var(--surface3); color: var(--followup); border-color: var(--followup-border); }

.scan-result {
  padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); margin-bottom: 12px;
}
.scan-result.ok { border-color: var(--ok-border); background: var(--ok-dim); }
.scan-result.followup { border-color: var(--followup-border); background: var(--followup-dim); }
.result-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.result-status-icon { font-size: 1.1rem; }
.ok .result-status-icon { color: var(--ok); }
.followup .result-status-icon { color: var(--followup); }
.result-status-text { font-size: 0.95rem; font-weight: 900; }
.ok .result-status-text { color: var(--ok); }
.followup .result-status-text { color: var(--followup); }
.result-device-id { font-size: 0.78rem; color: var(--text-muted); margin-left: auto; font-family: monospace; }
.result-reason { font-size: 0.8rem; color: var(--text-muted); }

.scan-message {
  font-size: 0.8rem; color: var(--text-muted); padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 12px;
}

/* ── UPLOAD PAGE ── */
.upload-page { max-width: 600px; margin: 0 auto; padding: 24px 18px 60px; }

.upload-header { margin-bottom: 24px; }
.upload-header h1 { font-size: 1.4rem; font-weight: 900; letter-spacing: -0.4px; margin-bottom: 6px; }
.upload-header p { font-size: 0.84rem; color: var(--text-muted); line-height: 1.55; }
.upload-header code {
  font-family: monospace; font-size: 0.8rem;
  background: var(--surface2); padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--border);
}

.upload-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: 22px;
  margin-bottom: 24px; display: flex; flex-direction: column; gap: 12px;
}

.upload-zone {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 32px 24px; border-radius: var(--radius-lg);
  border: 2px dashed var(--border); cursor: pointer;
  transition: all 0.22s ease; text-align: center;
}
.upload-zone:hover { border-color: var(--accent); background: var(--accent-dim); }
.upload-zone svg { width: 38px; height: 38px; color: var(--text-dim); transition: color 0.18s; }
.upload-zone:hover svg { color: var(--accent); }
.upload-zone-title { font-size: 0.88rem; font-weight: 700; color: var(--text-muted); }
.upload-zone-hint { font-size: 0.72rem; color: var(--text-dim); }

.selected-file-info {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--surface2); border-radius: var(--radius);
  font-size: 0.8rem; color: var(--text-muted);
}
.file-size { font-family: monospace; color: var(--text-dim); }

.upload-result {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 0.86rem; font-weight: 700;
}
.upload-result.success { background: var(--ok-dim); color: var(--ok); border: 1px solid var(--ok-border); }
.upload-result.error { background: var(--followup-dim); color: var(--followup); border: 1px solid var(--followup-border); }

.upload-info { }
.upload-info h2 {
  font-size: 0.75rem; font-weight: 800; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 10px;
}
.code-block {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; font-family: monospace; font-size: 0.76rem;
  color: var(--text-muted); line-height: 1.65; overflow-x: auto; white-space: pre;
}

/* ── LOGIN PAGE ── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); padding: 36px 32px;
  width: 100%; max-width: 340px;
}
.login-input {
  display: block; width: 100%; padding: 11px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.95rem; outline: none; transition: border-color 0.18s;
}
.login-input:focus { border-color: var(--accent); }
.login-input::placeholder { color: var(--text-dim); }

/* ── LOGOUT BUTTON ── */
.logout-btn {
  background: none; border: 1px solid transparent; cursor: pointer;
  font-family: inherit;
}
