/* ────────────────────────────────────────────────
   CSS Variables & Reset
──────────────────────────────────────────────── */
:root {
  --navy:       #1B3A6B;
  --navy-dark:  #112850;
  --blue:       #2E75B6;
  --blue-light: #D6E4F7;
  --green:      #1A7F3C;
  --green-bg:   #E8F8EE;
  --red:        #C0392B;
  --red-bg:     #FDECEA;
  --orange:     #D35400;
  --orange-bg:  #FEF0E3;
  --white:      #FFFFFF;
  --bg:         #F0F4F8;
  --card:       #FFFFFF;
  --text:       #1A1A2E;
  --text-muted: #6B7280;
  --border:     #D1D9E0;
  --radius:     12px;
  --shadow:     0 4px 20px rgba(0,0,0,0.10);
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.08);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ────────────────────────────────────────────────
   View management
──────────────────────────────────────────────── */
.view {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.view.active { display: flex; flex-direction: column; }

/* ────────────────────────────────────────────────
   Setup / Completed view
──────────────────────────────────────────────── */
.setup-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  min-height: 100%;
}

.setup-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 28px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--blue-light);
}

.brand-icon { font-size: 3rem; display: block; margin-bottom: 8px; }

.brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.3;
}

/* ────────────────────────────────────────────────
   Form
──────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 8px; }

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group input {
  padding: 14px 16px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--white);
  color: var(--navy);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus { border-color: var(--blue); }
.form-group input::placeholder { font-weight: 400; color: var(--text-muted); font-size: 1rem; }

/* ────────────────────────────────────────────────
   Buttons
──────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s, box-shadow 0.2s;
  text-decoration: none;
  min-height: 52px;
  -webkit-appearance: none;
}

.btn:active { transform: scale(0.97); }

.btn-xl {
  padding: 18px 24px;
  font-size: 1.1rem;
  min-height: 60px;
  border-radius: 12px;
}

.btn-sm { padding: 8px 14px; font-size: 0.85rem; min-height: 36px; }

.btn-success { background: var(--green); color: #fff; box-shadow: 0 3px 10px rgba(26,127,60,0.3); }
.btn-success:hover { background: #1a6e33; }

.btn-danger  { background: var(--red);   color: #fff; box-shadow: 0 3px 10px rgba(192,57,43,0.3); }
.btn-danger:hover  { background: #a93226; }

.btn-primary { background: var(--blue);  color: #fff; box-shadow: 0 3px 10px rgba(46,117,182,0.3); }
.btn-primary:hover { background: #2563a8; }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--blue); font-weight: 600; min-height: 44px; }
.btn-ghost:hover { background: var(--blue-light); }

.btn-icon { font-size: 1em; }

/* ────────────────────────────────────────────────
   Scan View – Header
──────────────────────────────────────────────── */
.scan-header {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  flex-shrink: 0;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.scan-meta { display: flex; flex-direction: column; gap: 2px; }

.scan-ac {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.scan-date {
  font-size: 0.8rem;
  opacity: 0.75;
}

.scan-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 6px 18px;
  min-width: 70px;
}

.scan-count-num {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

.scan-count-label {
  font-size: 0.7rem;
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ────────────────────────────────────────────────
   QR Reader area
──────────────────────────────────────────────── */
#qr-reader-wrapper {
  background: #000;
  position: relative;
  flex-shrink: 0;
  max-height: 55vmin;
  overflow: hidden;
}

#qr-reader {
  width: 100%;
}

/* Override html5-qrcode default styles */
#qr-reader video {
  width: 100% !important;
  object-fit: cover;
}

#qr-reader__scan_region {
  background: transparent !important;
}

#qr-reader__dashboard {
  padding: 6px 8px !important;
  background: #111 !important;
}

#qr-reader__dashboard button {
  padding: 6px 12px !important;
  font-size: 0.8rem !important;
  background: var(--blue) !important;
  color: #fff !important;
  border: none !important;
  border-radius: 6px !important;
  cursor: pointer !important;
}

#qr-reader__status_span {
  color: #aaa !important;
  font-size: 0.75rem !important;
}

.camera-error {
  position: absolute;
  inset: 0;
  background: #1a1a1a;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  font-size: 0.95rem;
}

/* ────────────────────────────────────────────────
   Scan Toast
──────────────────────────────────────────────── */
.scan-toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.3s;
  max-width: calc(100vw - 32px);
  text-align: center;
  white-space: normal;
}

.scan-toast.success {
  background: var(--green);
  color: #fff;
  box-shadow: 0 4px 16px rgba(26,127,60,0.4);
}

.scan-toast.warning {
  background: var(--orange);
  color: #fff;
  box-shadow: 0 4px 16px rgba(211,84,0,0.4);
}

.scan-toast.error {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 16px rgba(192,57,43,0.4);
}

.scan-toast.hidden { opacity: 0; pointer-events: none; }

/* ────────────────────────────────────────────────
   Scan list panel
──────────────────────────────────────────────── */
.scan-list-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.scan-list-title {
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.scan-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scan-item {
  display: flex;
  align-items: center;
  background: var(--card);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  animation: slideIn 0.2s ease;
  gap: 8px;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.scan-item-no {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 22px;
  text-align: right;
}

.scan-staff {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--navy);
  word-break: break-all;
}

.scan-time {
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--border);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s, background 0.2s;
}
.btn-delete:hover { color: var(--red); background: var(--red-bg); }

/* ────────────────────────────────────────────────
   Scan footer
──────────────────────────────────────────────── */
.scan-footer {
  padding: 12px 16px;
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ────────────────────────────────────────────────
   Completed view
──────────────────────────────────────────────── */
.success-anim {
  font-size: 4rem;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.setup-card h2 {
  text-align: center;
  font-size: 1.5rem;
  color: var(--navy);
  line-height: 1.4;
}

.setup-card h2 small {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

.summary-text {
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-muted);
  background: var(--blue-light);
  border-radius: 8px;
  padding: 10px 14px;
  line-height: 1.6;
}

/* ────────────────────────────────────────────────
   History view
──────────────────────────────────────────────── */
.history-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  padding: 0 0 24px;
}

.history-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.history-header h2 {
  font-size: 1.1rem;
  color: var(--navy);
}

.history-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-info strong {
  font-size: 1rem;
  color: var(--navy);
}

.history-info span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.history-status {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  margin-top: 2px;
}

.history-status.done { background: var(--green-bg); color: var(--green); }
.history-status.open { background: var(--orange-bg); color: var(--orange); }

.history-actions { display: flex; gap: 8px; }

.history-actions a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  background: var(--blue);
  color: #fff;
  white-space: nowrap;
}

/* ────────────────────────────────────────────────
   Responsive tweaks for larger screens
──────────────────────────────────────────────── */
@media (min-width: 600px) {
  #view-scanning {
    max-width: 520px;
    margin: 0 auto;
    box-shadow: var(--shadow);
  }

  #qr-reader-wrapper {
    max-height: 300px;
  }
}

/* ────────────────────────────────────────────────
   Pulse animation on successful scan (scanner border)
──────────────────────────────────────────────── */
#qr-reader-wrapper.scan-pulse {
  animation: pulse-border 0.4s ease;
}

@keyframes pulse-border {
  0%   { box-shadow: 0 0 0 0 rgba(26,127,60,0.8); }
  50%  { box-shadow: 0 0 0 12px rgba(26,127,60,0); }
  100% { box-shadow: none; }
}
