/* ── Reset & base ─────────────────────────────────────── */
:root {
  font-family: system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
  color: #171717;
  background: #f0f2f5;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: inherit; }

/* ── Header ───────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: .85rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  position: sticky;
  top: 0;
  z-index: 100;
}
nav { display: flex; gap: 1rem; align-items: center; }

/* ── Shared ───────────────────────────────────────────── */
.container { max-width: 960px; margin: 1.5rem auto; padding: 0 1rem; }
.card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
h1,h2 { margin-top: 0; }
form { display: grid; gap: .85rem; }
label { display: grid; gap: .35rem; font-weight: 600; }
input, select, button {
  font: inherit;
  padding: .7rem .9rem;
  border-radius: 8px;
  border: 1px solid #ccc;
}
button {
  cursor: pointer;
  background: #111;
  color: #fff;
  border-color: #111;
  font-weight: 600;
}
button.secondary { background: #fff; color: #111; }
.danger { background: #c0392b; border-color: #c0392b; color: #fff; }
.danger-outline {
  background: #fff;
  color: #c0392b;
  border: 1px solid #c0392b;
}
.danger-outline:hover { background: #fff0ee; }
.small-btn { padding: .35rem .75rem; font-size: .85rem; border-radius: 6px; }
.linkbtn { padding: 0; background: none; color: #111; border: 0; text-decoration: underline; }
.inline { display: inline; }
.muted { color: #666; }
.small { font-size: .88rem; }
.center-text { text-align: center; }
.hidden { display: none !important; }
.topgap { margin-top: 1rem; }

/* ── Alerts ───────────────────────────────────────────── */
.alert { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.error  { background: #ffe9e9; border: 1px solid #e89b9b; }
.alert.success { background: #e7f8eb; border: 1px solid #94d3a4; }

/* ── Stats bar ────────────────────────────────────────── */
.stats { display: flex; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: .85rem 1.25rem;
  display: grid;
  gap: .1rem;
  min-width: 100px;
}
.stat b { font-size: 1.7rem; line-height: 1; }
.stat span { color: #666; font-size: .85rem; }

/* ── Tabs — CSS-only radio approach ───────────────────── */
.tab-radio { display: none; }

.tab-wrap .tabs {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid #e0e0e0;
}

.tab-wrap .tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: #666;
  font-size: 1rem;
  font-weight: 600;
  padding: .65rem 1.25rem;
  margin-bottom: -2px;
  cursor: pointer;
  border-radius: 0;
  display: inline-block;
}
.tab-wrap .tab-btn:hover { color: #111; background: none; }

/* Show active tab label when radio checked */
#tab-items-radio:checked ~ .tabs label[for="tab-items-radio"],
#tab-users-radio:checked ~ .tabs label[for="tab-users-radio"] {
  color: #111;
  border-bottom-color: #111;
}

/* Hide all tab panels by default */
.tab-wrap .tab-panel { display: none; }

/* Show correct panel when radio checked */
#tab-items-radio:checked ~ #tab-items { display: block; }
#tab-users-radio:checked ~ #tab-users { display: block; }
/* ── Delete bar ───────────────────────────────────────── */
.delete-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 8px;
  margin-bottom: .75rem;
  flex-wrap: wrap;
}

/* ── Filter row ───────────────────────────────────────── */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}
.filter-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.filter-label { font-size: .85rem; color: #666; font-weight: normal; }
.filter-btn {
  background: #f0f2f5;
  border: 1px solid #ddd;
  color: #444;
  font-size: .85rem;
  padding: .35rem .85rem;
  border-radius: 20px;
  font-weight: 500;
}
.filter-btn.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

/* ── Clear row ────────────────────────────────────────── */
.clear-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  padding: .75rem;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid #eee;
}

/* ── Upload row ───────────────────────────────────────── */
.upload-row {
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
}
.upload-row input[type=file] { flex: 1; }
.upload-row button { white-space: nowrap; }

/* ── Badges ───────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-a, .badge-adult   { background: #dbeafe; color: #1e40af; }
.badge-k, .badge-kid     { background: #dcfce7; color: #166534; }
.badge-s, .badge-sponsor { background: #fef3c7; color: #92400e; }
.badge-scanned  { background: #d1fae5; color: #065f46; }
.badge-pending  { background: #f3f4f6; color: #6b7280; }
.badge-admin    { background: #fce7f3; color: #9d174d; }
.badge-user     { background: #e0e7ff; color: #3730a3; }

/* ── Table ────────────────────────────────────────────── */
.tablewrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .75rem; border-bottom: 1px solid #f0f0f0; }
th { font-size: .85rem; color: #555; font-weight: 600; background: #fafafa; }
tr:hover { background: #fafcff; }
code { background: #f3f4f6; padding: .1rem .4rem; border-radius: 4px; font-size: .88rem; }

/* ── Grid layout for forms ─────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 1rem;
}

/* ═══════════════════════════════════════════════════════ */
/* SCAN PAGE                                               */
/* ═══════════════════════════════════════════════════════ */
.scan-main {
  max-width: 600px;
  margin: 0 auto;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* ── Today counter ────────────────────────────────────── */
.today-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: .75rem 1.25rem;
}
.today-label { font-weight: 600; color: #555; }
.today-count {
  font-size: 2rem;
  font-weight: 800;
  color: #111;
  line-height: 1;
}

/* ── Camera card ──────────────────────────────────────── */
.camera-card {
  background: #111;
  border-radius: 16px;
  overflow: hidden;
  padding: 0;
}
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #111;
  overflow: hidden;
}
video, #video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* html5-qrcode injects its own elements inside #video */
#video video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

/* ── Scan frame overlay ───────────────────────────────── */
.scan-frame {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scan-frame::before {
  content: '';
  display: block;
  width: 60%;
  height: 55%;
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 8px;
  position: absolute;
}
.corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: #4ade80;
  border-style: solid;
}
/* calculate corner positions relative to frame (60% wide, 55% tall) */
.corner.tl { top: 22.5%; left: 20%; border-width: 3px 0 0 3px; border-radius: 6px 0 0 0; }
.corner.tr { top: 22.5%; right: 20%; border-width: 3px 3px 0 0; border-radius: 0 6px 0 0; }
.corner.bl { bottom: 22.5%; left: 20%; border-width: 0 0 3px 3px; border-radius: 0 0 0 6px; }
.corner.br { bottom: 22.5%; right: 20%; border-width: 0 3px 3px 0; border-radius: 0 0 6px 0; }

/* Animated scan line */
.scan-line {
  position: absolute;
  left: 20%;
  width: 60%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #4ade80, transparent);
  top: 22.5%;
  animation: scanAnim 2s ease-in-out infinite;
  display: none;
}
.scan-line.active { display: block; }
@keyframes scanAnim {
  0%   { top: 22.5%; opacity: 1; }
  50%  { top: 55%; opacity: .8; }
  100% { top: 22.5%; opacity: 1; }
}

.video-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,.75);
  font-size: .85rem;
  white-space: nowrap;
  background: rgba(0,0,0,.4);
  padding: .3rem .8rem;
  border-radius: 20px;
}

/* Camera buttons */
.camera-actions {
  display: flex;
  gap: .75rem;
  padding: .75rem;
  background: #1a1a1a;
}
.cam-btn {
  flex: 1;
  padding: .7rem;
  border-radius: 10px;
  font-weight: 700;
  font-size: .95rem;
}
.cam-btn.start { background: #22c55e; border-color: #22c55e; color: #fff; }
.cam-btn.start:hover { background: #16a34a; }
.cam-btn.stop  { background: #ef4444; border-color: #ef4444; color: #fff; }
.cam-btn.stop:hover { background: #dc2626; }
.cam-btn:disabled { opacity: .4; cursor: not-allowed; }
#cameraHelp { padding: .5rem .75rem; background: #1a1a1a; color: #888; margin: 0; }

/* ── Result card ──────────────────────────────────────── */
.result-card {
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  animation: popIn .2s ease-out;
}
@keyframes popIn {
  from { transform: scale(.95); opacity: .5; }
  to   { transform: scale(1);   opacity: 1; }
}
.result-card.valid   { background: #dcfce7; border: 2px solid #22c55e; }
.result-card.invalid { background: #fee2e2; border: 2px solid #ef4444; }
.result-card.used    { background: #fef3c7; border: 2px solid #f59e0b; }
.result-card.pending { background: #e0e7ff; border: 2px solid #6366f1; }
.result-card.error   { background: #fee2e2; border: 2px solid #ef4444; }

.result-icon  { font-size: 3rem; line-height: 1; margin-bottom: .5rem; }
.result-title { font-size: 1.5rem; font-weight: 800; margin-bottom: .35rem; }
.result-item  { font-size: 1rem; font-weight: 600; color: #444; margin-bottom: .25rem; }
.result-msg   { font-size: .9rem; color: #555; }

/* ── Manual entry card ────────────────────────────────── */
.manual-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  padding: 1rem;
}
.manual-row { display: flex; gap: .75rem; }
.barcode-input {
  flex: 1;
  font-size: 1.1rem;
  padding: .75rem 1rem;
  border-radius: 10px;
  border: 1.5px solid #ccc;
}
.barcode-input:focus { outline: none; border-color: #111; }
.check-btn {
  padding: .75rem 1.5rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Login page */
.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.narrow { width: min(420px,100%); }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 640px) {
  header { align-items: flex-start; }
  .grid { grid-template-columns: 1fr; }
  .container { margin-top: 1rem; }
  .stats { gap: .5rem; }
  .stat { min-width: 80px; padding: .65rem .85rem; }
  .stat b { font-size: 1.4rem; }
  .list-header { flex-direction: column; align-items: flex-start; }
  .corner.tl { top: 20%; left: 18%; }
  .corner.tr { top: 20%; right: 18%; }
  .corner.bl { bottom: 20%; left: 18%; }
  .corner.br { bottom: 20%; right: 18%; }
}
