:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand-icon { width: 26px; height: 26px; }

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-ok { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-muted { background: rgba(148,163,184,0.15); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
}
.tab-btn.active { background: var(--accent); color: #06222f; font-weight: 600; }

main { flex: 1; padding: 16px; }

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

.camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
#video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#overlay { pointer-events: none; }

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(15,23,42,0.9);
  text-align: center;
}

.camera-controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--accent); color: #06222f; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-danger { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.4); }
.btn-sm { padding: 6px 10px; font-size: 12px; }

.select, .input {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
}

.toast-stack {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.toast {
  background: rgba(34,197,94,0.12);
  border: 1px solid rgba(34,197,94,0.4);
  color: var(--green);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  animation: fadein 0.2s ease-out;
}
@keyframes fadein { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: translateY(0);} }

.panel {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h3 { margin: 0 0 4px; font-size: 15px; }
.hint { color: var(--text-muted); font-size: 13px; margin: 4px 0 12px; }

.unknown-grid, .people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.unknown-card, .person-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  text-align: center;
}
.unknown-thumb, .person-thumb {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  background: #000;
  border: 2px solid var(--border);
}
.name-input { width: 100%; text-align: center; }
.unknown-actions { display: flex; gap: 6px; width: 100%; }
.unknown-actions .btn { flex: 1; }
.person-actions { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.person-actions .btn { width: 100%; white-space: nowrap; }
.person-name { font-weight: 600; font-size: 14px; word-break: break-word; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.spacer { flex: 1; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  text-align: left;
}
.table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table tr:last-child td { border-bottom: none; }

@media (max-width: 480px) {
  main { padding: 12px; }
  .unknown-grid, .people-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
