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

:root {
  --bg:      #08080f;
  --bg2:     #0d0d1a;
  --card:    #14141f;
  --border:  #ffffff12;
  --primary: #6366f1;
  --primary2:#818cf8;
  --accent:  #22d3ee;
  --success: #10b981;
  --danger:  #ef4444;
  --warn:    #f59e0b;
  --text:    #e2e8f0;
  --muted:   #94a3b8;
  --tr:      0.2s ease;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== LOGIN GATE ===== */
.gate {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.gate-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  width: 100%; max-width: 340px;
  text-align: center;
}
.gate-icon { font-size: 36px; margin-bottom: 12px; }
.gate-box h2 { font-size: 22px; font-weight: 800; margin-bottom: 2px; }
.gate-sub { font-size: 12px; color: var(--primary2); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 24px; }
.gate-error {
  background: #ef444418; border: 1px solid #ef444455; color: #fca5a5;
  border-radius: 8px; padding: 8px 12px; font-size: 13px;
  margin-bottom: 16px; display: none;
}
.gate-error.show { display: block; }
.gate-box input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 13px 16px;
  border-radius: 12px;
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
  transition: var(--tr);
}
.gate-box input:focus { border-color: var(--primary2); }

/* ===== BUTTONS ===== */
.btn-go {
  width: 100%;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; border: none;
  padding: 14px; border-radius: 12px;
  font-size: 16px; font-weight: 700;
  cursor: pointer; transition: var(--tr);
}
.btn-go:active { transform: scale(0.97); }

.btn-sm {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 8px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
}

.btn-logout-sm {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ===== TOP BAR ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(8,8,15,0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 50;
  gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.tb-logo { color: var(--primary2); font-size: 18px; }
.tb-title { font-size: 16px; font-weight: 800; }

.topbar-stats { display: flex; gap: 14px; }
.ts { text-align: center; }
.ts-num { font-size: 16px; font-weight: 800; color: var(--muted); display: block; line-height: 1; }
.ts-label { font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.ts-valid .ts-num { color: var(--success); }
.ts-used .ts-num { color: var(--danger); }

/* ===== TABS ===== */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky; top: 60px; z-index: 40;
}
.tab {
  flex: 1;
  background: transparent; border: none;
  color: var(--muted);
  padding: 14px 0;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--tr);
  position: relative;
}
.tab.active { color: var(--primary2); border-bottom-color: var(--primary2); }
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 800;
  width: 18px; height: 18px; border-radius: 50%;
  margin-left: 4px; vertical-align: middle;
}

/* ===== CAMERA ===== */
.camera-box {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  max-height: 65vh;
  background: #000;
  overflow: hidden;
}
#video {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.scan-ui {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scan-frame {
  position: relative;
  width: 220px; height: 220px;
}
.c {
  position: absolute;
  width: 28px; height: 28px;
  border-color: var(--primary2);
  border-style: solid;
}
.c.tl { top:0;left:0; border-width:3px 0 0 3px; border-radius:6px 0 0 0; }
.c.tr { top:0;right:0; border-width:3px 3px 0 0; border-radius:0 6px 0 0; }
.c.bl { bottom:0;left:0; border-width:0 0 3px 3px; border-radius:0 0 0 6px; }
.c.br { bottom:0;right:0; border-width:0 3px 3px 0; border-radius:0 0 6px 0; }

.scan-bar {
  position: absolute;
  left: 8px; right: 8px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 12px var(--accent);
  animation: barMove 2s ease-in-out infinite;
}
@keyframes barMove {
  0%   { top: 10px; }
  50%  { top: calc(100% - 12px); }
  100% { top: 10px; }
}

/* detected flash */
.scan-frame.found .c { border-color: var(--success); }
.scan-frame.found .scan-bar { background: linear-gradient(90deg, transparent, var(--success), transparent); box-shadow: 0 0 12px var(--success); }

.cam-off {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  background: var(--bg2);
  cursor: pointer;
}
.cam-off p { color: var(--muted); font-size: 14px; }
.cam-off.hidden { display: none; }
.cam-off-tickets {
  margin-top: 4px;
  font-size: 12px !important;
  padding: 4px 14px;
  border-radius: 20px;
  font-weight: 600;
}
.cam-off-tickets.loaded { background: #10b98122; color: #6ee7b7 !important; border: 1px solid #10b98133; }
.cam-off-tickets.empty  { background: #ef444422; color: #fca5a5 !important; border: 1px solid #ef444433; }

.cam-controls {
  display: flex; gap: 10px;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.btn-cam {
  flex: 1;
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff; border: none;
  padding: 12px; border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.btn-cam:active { transform: scale(0.97); }
.btn-stop { background: var(--card); border: 1px solid var(--border); color: var(--text); }
.btn-flip { background: var(--card); border: 1px solid var(--border); color: var(--text); flex: 0.5; }

/* ===== MANUAL ===== */
.manual-box { padding: 24px 16px; text-align: center; }
.manual-title { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 16px; }
.input-manual {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 16px;
  border-radius: 12px;
  font-size: 18px;
  font-family: monospace;
  letter-spacing: 2px;
  text-align: center;
  outline: none;
  margin-bottom: 16px;
  transition: var(--tr);
}
.input-manual:focus { border-color: var(--primary2); }

/* ===== RESULT OVERLAY ===== */
.result-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.result-card {
  width: 100%; max-width: 360px;
  border-radius: 20px;
  overflow: hidden;
  animation: popUp 0.25s ease;
}
@keyframes popUp { from { transform: scale(0.9) translateY(20px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.res-inner { padding: 28px 24px; text-align: center; }
.res-icon { font-size: 56px; margin-bottom: 12px; }
.res-title { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.res-id { font-size: 14px; font-family: monospace; color: var(--muted); letter-spacing: 1px; margin-bottom: 20px; }

.res-valid { background: linear-gradient(180deg, #10b98125, var(--card)); border: 1px solid #10b98144; }
.res-valid .res-title { color: var(--success); }

.res-used { background: linear-gradient(180deg, #ef444425, var(--card)); border: 1px solid #ef444444; }
.res-used .res-title { color: var(--danger); }

.res-notfound { background: linear-gradient(180deg, #f59e0b25, var(--card)); border: 1px solid #f59e0b44; }
.res-notfound .res-title { color: var(--warn); }

.res-details { text-align: left; margin-bottom: 20px; }
.res-row {
  display: flex; justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #ffffff08;
  font-size: 13px;
}
.res-row:last-child { border-bottom: none; }
.res-label { color: var(--muted); }
.res-value { font-weight: 600; text-align: right; }

.btn-dismiss {
  width: 100%;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text);
  padding: 14px; border-radius: 12px;
  font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.btn-dismiss:active { transform: scale(0.97); }

/* Haptic vibration colors on card */
.pulse-green { animation: pulseGreen 0.5s ease; }
@keyframes pulseGreen { 0%,100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 40px 10px #10b98144; } }
.pulse-red { animation: pulseRed 0.5s ease; }
@keyframes pulseRed { 0%,100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 40px 10px #ef444444; } }

/* ===== LOG ===== */
.log-header-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.log-title { font-size: 14px; font-weight: 700; }
.log-list { max-height: calc(100vh - 200px); overflow-y: auto; }
.log-empty { text-align: center; padding: 40px 16px; color: var(--muted); font-size: 14px; }

.log-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #ffffff06;
  animation: slideIn 0.15s ease;
}
@keyframes slideIn { from { opacity:0; transform:translateX(-8px); } to { opacity:1; transform:translateX(0); } }

.log-dot {
  width: 10px; height: 10px;
  border-radius: 50%; flex-shrink: 0;
}
.log-dot.valid { background: var(--success); box-shadow: 0 0 6px var(--success); }
.log-dot.used  { background: var(--danger);  box-shadow: 0 0 6px var(--danger); }
.log-dot.notfound { background: var(--warn); box-shadow: 0 0 6px var(--warn); }

.log-info { flex: 1; min-width: 0; }
.log-id { font-family: monospace; font-weight: 700; font-size: 13px; color: var(--primary2); }
.log-name { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-right { text-align: right; flex-shrink: 0; }
.log-status {
  display: inline-block;
  font-size: 9px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
  text-transform: uppercase;
}
.log-status.valid    { background: #10b98122; color: #6ee7b7; }
.log-status.used     { background: #ef444422; color: #fca5a5; }
.log-status.notfound { background: #f59e0b22; color: #fcd34d; }
.log-time { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 20px; left: 16px; right: 16px;
  background: var(--card);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 14px; font-weight: 500;
  z-index: 3000;
  transform: translateY(100px);
  opacity: 0;
  transition: 0.3s ease;
  text-align: center;
}
.toast.valid-t { border: 1px solid var(--success); color: #6ee7b7; }
.toast.used-t  { border: 1px solid var(--danger);  color: #fca5a5; }
.toast.warn-t  { border: 1px solid var(--warn);    color: #fcd34d; }
.toast.info-t  { border: 1px solid var(--primary2); }
.toast.show    { transform: translateY(0); opacity: 1; }

/* ===== SAFE AREA ===== */
@supports (padding-top: env(safe-area-inset-top)) {
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
  .toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
}
