*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --surface2: #2a2a2a;
  --text: #f0f0f0;
  --text-muted: #aaa;
  --accent: #4a9eff;
  --radius: 10px;
  --state-0: #6c757d;
  --state-1: #3498db;
  --state-2: #e67e22;
  --state-3: #2ecc71;
  --state-4: #9b59b6;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: 16px;
}

/* ── Header ── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid #333;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.05em; }
nav { display: flex; gap: 12px; align-items: center; }
nav a { color: var(--accent); text-decoration: none; font-size: 0.9rem; }

main { padding: 16px; max-width: 600px; margin: 0 auto; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s;
  text-decoration: none;
}
.btn:active { opacity: 0.75; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--accent); padding: 6px 10px; font-size: 0.85rem; }
.btn-github { background: #24292e; color: #fff; font-size: 1.1rem; padding: 14px 28px; }

/* ── Scanner page ── */
#scanner-wrap {
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
  position: relative;
  cursor: pointer;
}

#scanner-wrap.paused::after {
  content: 'Paused – tap to resume';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  pointer-events: none;
}

#scanner-wrap.paused #scan-overlay::before {
  display: none;
}

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

#scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#scan-overlay::before {
  content: '';
  width: 60%;
  height: 2px;
  background: rgba(74, 158, 255, 0.8);
  box-shadow: 0 0 8px var(--accent);
  animation: scan-line 2s ease-in-out infinite alternate;
}

@keyframes scan-line {
  0%   { transform: translateY(-60px); }
  100% { transform: translateY(60px); }
}

#result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  text-align: center;
}

#barcode-value {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  word-break: break-all;
}

#state-badge {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 180px;
}

/* ── Controls ── */
#controls {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-row label { font-size: 0.95rem; font-weight: 500; }

/* Toggle switch */
.toggle {
  appearance: none;
  width: 52px;
  height: 28px;
  background: #444;
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle:checked { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle:checked::after { transform: translateX(24px); }

select {
  flex: 1;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid #444;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.95rem;
  max-width: 240px;
}

/* ── Boxes list ── */
.boxes-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.box-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
}
.box-card:active { background: var(--surface2); }

.state-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.box-card-info { flex: 1; min-width: 0; }
.box-id { font-weight: 600; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.box-state-label { font-size: 0.85rem; font-weight: 600; text-align: right; flex-shrink: 0; }

/* ── Box detail ── */
.detail-info {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 20px;
}

.detail-info p { margin: 6px 0; font-size: 0.95rem; }

.section-title { font-size: 1rem; font-weight: 700; margin: 20px 0 10px; }

/* Photos */
.photos-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.photos-grid img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
}

/* Scan timeline */
.timeline { list-style: none; padding: 0; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #2a2a2a;
}
.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}
.timeline-content { flex: 1; }
.timeline-time { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 4px; }
.timeline-change { font-size: 0.9rem; font-weight: 600; margin-bottom: 2px; }
.timeline-geo a { font-size: 0.8rem; color: var(--accent); text-decoration: none; }

/* ── Login ── */
.login-page body { display: flex; align-items: center; justify-content: center; }
.login-wrap {
  text-align: center;
  padding: 32px 24px;
  max-width: 340px;
  width: 100%;
}
.login-wrap h1 { font-size: 2rem; margin-bottom: 8px; }
.login-wrap p { color: var(--text-muted); margin-bottom: 32px; }

/* ── Utilities ── */
.empty { color: var(--text-muted); font-size: 0.9rem; text-align: center; padding: 24px 0; }
.mt-16 { margin-top: 16px; }
