/* === Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-secondary: #6b7280;
  --color-border: #e5e7eb;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-danger: #ef4444;
  --color-ok: #16a34a;
  --color-warn: #ea580c;
  --color-header-bg: #1e293b;
  --color-header-text: #ffffff;
  --header-height: 48px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

:root[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-text: #e2e8f0;
  --color-text-secondary: #94a3b8;
  --color-border: #334155;
  --color-header-bg: #0f172a;
  --color-header-text: #e2e8f0;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #e2e8f0;
    --color-text-secondary: #94a3b8;
    --color-border: #334155;
    --color-header-bg: #0f172a;
    --color-header-text: #e2e8f0;
  }
}

html, body { height: 100%; }
body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  display: flex; flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

/* === Landing page === */
.landing {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 20px;
}
.landing-card {
  background: var(--color-surface); border-radius: 16px;
  padding: 32px; max-width: 400px; width: 100%;
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}
.landing-card h1 { font-size: 28px; margin-bottom: 4px; text-align: center; }
.landing-subtitle {
  text-align: center; color: var(--color-text-secondary);
  font-size: 14px; margin-bottom: 24px;
}
.landing-roles { display: flex; flex-direction: column; gap: 12px; }
.landing-card h2 { font-size: 20px; margin-bottom: 8px; }
.auth-error {
  color: var(--color-danger); font-size: 14px; font-weight: 600;
  margin: 4px 0;
}

/* === Buttons === */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px; border: 1px solid var(--color-border); border-radius: 8px;
  background: var(--color-surface); color: var(--color-text);
  font-size: 15px; cursor: pointer; transition: background 0.15s;
  font-family: var(--font-family); text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-ok { background: var(--color-ok); color: #fff; border-color: var(--color-ok); }
.btn-warn { background: var(--color-warn); color: #fff; border-color: var(--color-warn); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 6px; }
.btn-huge {
  min-height: 56px; font-size: 18px; font-weight: 700;
  width: 100%; border-radius: 12px; padding: 14px 20px;
}
.btn-icon {
  background: none; border: none; color: var(--color-header-text);
  font-size: 20px; padding: 4px 10px; cursor: pointer; text-decoration: none;
}

/* === Header === */
.header {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-height); padding: 0 12px;
  background: var(--color-header-bg); color: var(--color-header-text);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 16px; font-weight: 600; white-space: nowrap; }

/* === Queue badge === */
.queue-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--color-warn); color: #fff;
  padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}

/* === Event select === */
.event-select {
  background: rgba(255,255,255,0.12); color: var(--color-header-text);
  border: 1px solid rgba(255,255,255,0.2); border-radius: 6px;
  padding: 4px 8px; font-size: 13px; font-family: var(--font-family);
}
.event-select option { color: #000; }

/* === Menu === */
.menu-dropdown {
  position: absolute; top: var(--header-height); right: 8px; z-index: 600;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 10px; min-width: 200px; padding: 6px 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.menu-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 12px 16px; font-size: 15px; cursor: pointer;
  border: none; background: none; color: var(--color-text); text-align: left;
  font-family: var(--font-family);
}
.menu-item:hover { background: var(--color-bg); }
.menu-item input[type="checkbox"] { width: 20px; height: 20px; cursor: pointer; }
.menu-item-value { color: var(--color-text-secondary); font-size: 13px; }

/* === Tabs === */
.tab-bar {
  display: flex; border-bottom: 2px solid var(--color-border);
  background: var(--color-surface); flex-shrink: 0; overflow-x: auto;
}
.tab {
  flex: 1; padding: 12px 8px; text-align: center; text-decoration: none;
  font-size: 14px; font-weight: 600; color: var(--color-text-secondary);
  white-space: nowrap; border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

#main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen { padding: 14px; max-width: 900px; margin: 0 auto; width: 100%; }

/* === Video / Scanner === */
.video-wrap {
  position: relative; border-radius: 12px; overflow: hidden; background: #000;
  aspect-ratio: 4 / 3; margin-bottom: 12px;
}
.video-wrap video { width: 100%; height: 100%; object-fit: cover; }
.video-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
}
.video-hint {
  position: absolute; inset: 0; margin: auto; width: 70%; height: 45%;
  border: 3px solid rgba(255,255,255,0.5); border-radius: 14px; pointer-events: none;
}
.btn-torch {
  position: absolute; bottom: 10px; right: 10px; z-index: 10;
  width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.45); color: #fff;
  font-size: 18px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-torch.active {
  background: rgba(255,215,0,0.9); border-color: rgba(255,190,0,0.8); color: #333;
}
.video-cover {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center;
  background: rgba(0,0,0,0.75); color: #fff; padding: 20px;
}

/* === Scan status / log === */
.scan-prompt {
  text-align: center; padding: 16px 12px; color: var(--color-text-secondary);
  font-size: 16px; font-weight: 600;
}
.scan-result {
  text-align: center; padding: 12px; font-size: 18px; font-weight: 700;
  border-radius: 8px;
}
.scan-ok { background: color-mix(in srgb, var(--color-ok) 14%, var(--color-surface)); color: var(--color-ok); }
.scan-warn { background: color-mix(in srgb, var(--color-warn) 14%, var(--color-surface)); color: var(--color-warn); }
.scan-error { background: color-mix(in srgb, var(--color-danger) 14%, var(--color-surface)); color: var(--color-danger); }

.scan-log { margin-top: 12px; }
.log-entry {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border-bottom: 1px solid var(--color-border); font-size: 13px;
}
.log-barcode { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 80px; }
.log-message { flex: 1; color: var(--color-text-secondary); }
.log-time { color: var(--color-text-secondary); font-size: 12px; }
.log-ok .log-barcode { color: var(--color-ok); }
.log-warn .log-barcode { color: var(--color-warn); }
.log-error .log-barcode { color: var(--color-danger); }

/* === Location grid === */
.location-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; margin: 12px 0;
}
.comp-btn {
  min-height: 72px; border-radius: 12px; border: 2px solid var(--color-border);
  background: var(--color-surface); color: var(--color-text);
  font-size: 18px; font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.comp-btn.last-used { border-color: var(--color-primary); }
.comp-btn:active { transform: scale(0.97); }

/* === Dashboard stat cards === */
.dash-counts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px;
}
@media (max-width: 480px) { .dash-counts { grid-template-columns: repeat(2, 1fr); } }
.dash-count-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 12px; padding: 16px; text-align: center;
}
.dash-count-num { font-size: 32px; font-weight: 800; line-height: 1.1; margin-bottom: 4px; }
.stat-ok .dash-count-num { color: var(--color-ok); }
.stat-danger .dash-count-num { color: var(--color-danger); }
.stat-warn .dash-count-num { color: var(--color-warn); }

/* === Progress bar === */
.progress-wrap { margin: 14px 0; }
.progress-bar-bg {
  height: 28px; background: var(--color-bg); border-radius: 14px;
  border: 1px solid var(--color-border); overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--color-primary); border-radius: 14px;
  transition: width 0.5s ease; min-width: 0;
}
.progress-bar-fill.progress-complete { background: var(--color-ok); }
.progress-label {
  text-align: center; font-size: 14px; font-weight: 600; margin-top: 6px;
}

/* === Dashboard bar rows === */
.dash-bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dash-bar-name { width: 100px; font-size: 13px; font-weight: 600; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-bar-track {
  flex: 1; height: 18px; background: var(--color-bg); border-radius: 9px; overflow: hidden;
  border: 1px solid var(--color-border);
}
.dash-bar-fill { height: 100%; background: var(--color-primary); border-radius: 9px; transition: width 0.3s; }
.dash-bar-label { font-size: 13px; color: var(--color-text-secondary); width: 40px; text-align: right; }

/* === Participant table === */
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row input {
  flex: 1; padding: 12px; border: 1px solid var(--color-border); border-radius: 10px;
  font-size: 16px; background: var(--color-surface); color: var(--color-text);
}

.filter-row {
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px;
  align-items: center;
}
.filter-group { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.filter-group label { font-weight: 600; color: var(--color-text-secondary); }
.filter-group select {
  padding: 4px 8px; border: 1px solid var(--color-border); border-radius: 6px;
  background: var(--color-surface); color: var(--color-text); font-size: 13px;
}

.participant-actions {
  display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap;
}
.participant-count { font-size: 13px; color: var(--color-text-secondary); margin-left: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 10px 0; }
.data-table th, .data-table td {
  padding: 7px 8px; border-bottom: 1px solid var(--color-border); text-align: left;
  vertical-align: top;
}
.data-table th {
  font-weight: 600; background: var(--color-bg); position: sticky; top: 0; z-index: 1;
}
.sortable { cursor: pointer; user-select: none; }
.sortable::after { content: ''; margin-left: 4px; }
.sort-asc::after { content: ' \25B2'; font-size: 10px; }
.sort-desc::after { content: ' \25BC'; font-size: 10px; }

.participant-row { cursor: pointer; }
.participant-row:hover { background: var(--color-bg); }
.status-missing { }
.status-scanned { }

/* === State chips === */
.state-chip {
  display: inline-block; padding: 1px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: #fff;
}
.state-ready { background: var(--color-ok); }
.state-dropped { background: #64748b; }
.state-returned { background: #94a3b8; }

/* === Cards === */
.card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 12px; padding: 16px; margin-bottom: 14px;
}
.card h3 { font-size: 16px; margin-bottom: 10px; }
.event-list { margin-top: 14px; }
.location-list { margin-top: 14px; }

/* === Forms === */
.form-help { font-size: 13px; color: var(--color-text-secondary); margin-bottom: 8px; }
.admin-form { display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.admin-form label { font-size: 13px; font-weight: 600; }
.admin-form input, .admin-form select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--color-border);
  border-radius: 8px; font-size: 15px; background: var(--color-surface); color: var(--color-text);
}
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* === Modals === */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 500; display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--color-surface); border-radius: 14px 14px 0 0;
  width: 100%; max-width: 480px; max-height: 85dvh; overflow-y: auto;
  padding: 20px; position: relative; color: var(--color-text);
  animation: modal-slide-up 0.2s ease-out;
}
@keyframes modal-slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (min-width: 768px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 14px; }
}
.modal h2 { font-size: 19px; margin-bottom: 10px; }
.modal-close {
  position: absolute; top: 10px; right: 12px; background: none; border: none;
  font-size: 28px; cursor: pointer; color: var(--color-text-secondary); z-index: 2;
}
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal input[type="text"], .modal input[type="password"],
.modal input[type="number"], .modal input[type="datetime-local"],
.modal select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--color-border);
  border-radius: 8px; font-size: 16px; background: var(--color-bg); color: var(--color-text);
}
.modal label { font-size: 13px; font-weight: 600; color: var(--color-text-secondary); }

/* === Toasts === */
#toast-wrap {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 900; display: flex; flex-direction: column; gap: 6px; width: min(94vw, 480px);
}
.toast {
  padding: 12px 16px; border-radius: 10px; font-size: 15px; font-weight: 600;
  color: #fff; background: #334155; box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  animation: toast-in 0.2s ease-out;
}
.toast-warn { background: var(--color-warn); }
.toast-error { background: var(--color-danger); }
.toast-ok { background: var(--color-ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* === Feedback overlays === */
.fx-overlay { position: fixed; inset: 0; z-index: 950; pointer-events: none; opacity: 0; }
#fx-swipe {
  background: linear-gradient(115deg,
    transparent 0%, transparent 30%,
    rgba(24,201,100,0) 35%,
    rgba(24,201,100,0.85) 50%,
    rgba(24,201,100,0) 65%,
    transparent 70%, transparent 100%);
  transform: translateX(-120%);
}
#fx-swipe.run { animation: fx-swipe 0.55s ease-out; }
@keyframes fx-swipe {
  0%   { transform: translateX(-120%); opacity: 1; }
  100% { transform: translateX(120%); opacity: 1; }
}
#fx-red { background: var(--color-danger); box-shadow: inset 0 0 120px 40px rgba(0,0,0,0.4); }
#fx-red.run { animation: fx-red 0.6s ease-out; }
@keyframes fx-red {
  0%, 100% { opacity: 0; }
  15%, 55% { opacity: 0.55; }
  35%      { opacity: 0.15; }
}
#fx-orange { background: var(--color-warn); box-shadow: inset 0 0 120px 40px rgba(0,0,0,0.3); }
#fx-orange.run { animation: fx-orange 0.6s ease-out; }
@keyframes fx-orange {
  0%, 100% { opacity: 0; }
  15%, 55% { opacity: 0.45; }
  35%      { opacity: 0.12; }
}

/* === Print === */
@media print {
  .header, .tab-bar, #toast-wrap, .no-print, .filter-row,
  .participant-actions, .search-row { display: none !important; }
  body { background: #fff; color: #000; }
  #main { overflow: visible; }
  .card { border: 1px solid #999; break-inside: avoid; }
  .data-table { font-size: 11px; }
  .data-table th { background: #f0f0f0; }
  .state-chip { color: #000; background: #ddd; }
}
