/* =========================================================================
   THE EVENT — Check-in Scanner
   Brand: dark navy background, gold accents, white text, elegant cards.
   Mobile-first; desktop gets a two-column scanner/dashboard layout.
   ========================================================================= */

:root {
  --navy: #071A2B;
  --navy-dark: #04111D;
  --gold: #C9A227;
  --gold-light: #E6C65C;
  --white: #FFFFFF;
  --gray: #8A96A3;

  --success: #3FBF7F;
  --success-bg: rgba(63, 191, 127, 0.14);
  --warn: #E6C65C;
  --warn-bg: rgba(230, 198, 92, 0.14);
  --danger: #E15C5C;
  --danger-bg: rgba(225, 92, 92, 0.14);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.35);
  --touch-min: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, var(--navy) 0%, var(--navy-dark) 70%);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0; }

button { font-family: inherit; }

a { color: var(--gold-light); }

.hidden { display: none !important; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch-min);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
  touch-action: manipulation;
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: var(--navy-dark);
}
.btn-primary:hover { filter: brightness(1.05); }

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--white);
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.14); }

.btn-danger {
  background: rgba(225, 92, 92, 0.12);
  color: #ffb3b3;
  border: 1px solid rgba(225, 92, 92, 0.4);
}

.btn-large { min-height: 60px; font-size: 17px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--gold-light);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ---------- Cards ---------- */

.card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 17px;
  color: var(--white);
  margin-bottom: 14px;
  letter-spacing: 0.02em;
}
.scope-note {
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  color: var(--gray);
}

/* ---------- Fields ---------- */

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gray);
  margin-bottom: 8px;
}
.field input[type="text"] {
  width: 100%;
  min-height: var(--touch-min);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(4, 17, 29, 0.6);
  color: var(--white);
  font-size: 16px;
}
.field input[type="text"]:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.25);
}
.field input[readonly] { color: var(--gray); }
.field-hint { font-size: 12.5px; color: var(--gray); margin: 6px 0 0; line-height: 1.4; }

.switch-field { margin-bottom: 14px; }
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--white);
  text-transform: none;
  cursor: pointer;
}
.switch-row input[type="checkbox"] {
  width: 44px;
  height: 26px;
  cursor: pointer;
  accent-color: var(--gold);
}
.switch-row em { color: var(--gray); font-style: normal; font-size: 12px; }

/* ---------- Gate choice buttons (setup + settings) ---------- */

.gate-choice-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.gate-choice {
  min-height: var(--touch-min);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: var(--white);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.gate-choice.active {
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: var(--navy-dark);
  border-color: var(--gold);
}

/* ---------- Setup screen ---------- */

.setup-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.setup-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015));
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px 24px;
}
.brand-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 20px;
}
.brand-mark.small { align-items: flex-start; text-align: left; }
.brand-name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--gold-light);
}
.brand-mark.small .brand-name { font-size: 18px; }
.brand-tag {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gray);
  margin-top: 4px;
}
.setup-heading { font-size: 22px; text-align: center; margin-bottom: 6px; }
.setup-sub { text-align: center; color: var(--gray); font-size: 14px; margin: 0 0 22px; line-height: 1.5; }
.setup-note { text-align: center; color: var(--gray); font-size: 12.5px; margin-top: 14px; }

/* ---------- App shell / topbar ---------- */

.app-shell { min-height: 100vh; min-height: 100dvh; padding-bottom: max(24px, env(safe-area-inset-bottom)); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 16px 8px;
}
.status-group { display: flex; align-items: center; gap: 10px; }
.status-pill {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 6px 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.06);
}
.status-pill.online { color: var(--success); }
.status-pill.offline { color: var(--danger); background: rgba(225, 92, 92, 0.14); }

/* ---------- Active gate banner ---------- */

.active-gate-banner {
  margin: 4px 16px 16px;
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.16), rgba(201, 162, 39, 0.04));
  border: 1px solid rgba(201, 162, 39, 0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gate-banner-text { display: flex; flex-direction: column; }
.gate-banner-label {
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--gray);
  text-transform: uppercase;
}
.gate-banner-value {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--gold-light);
}
.gate-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gate-btn {
  min-height: 46px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: var(--white);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.gate-btn.active {
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: var(--navy-dark);
  border-color: var(--gold);
}

/* ---------- Layout ---------- */

.layout {
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  gap: 0;
}

/* ---------- Banners ---------- */

.banner {
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.banner strong { display: block; font-size: 14px; letter-spacing: 0.05em; margin-bottom: 4px; }
.banner p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.5; }
.banner-error {
  background: var(--danger-bg);
  border-color: rgba(225, 92, 92, 0.4);
  color: #ffd6d6;
}
.banner-test {
  background: var(--warn-bg);
  border-color: rgba(230, 198, 92, 0.5);
  color: var(--gold-light);
}

/* ---------- Scanner card ---------- */

.scanner-card { padding: 16px; }
.qr-reader {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  min-height: 280px;
}
.qr-reader video { border-radius: var(--radius-md); }
.qr-placeholder {
  min-height: 280px;
  border-radius: var(--radius-md);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gray);
  gap: 8px;
}
.qr-placeholder-icon { font-size: 40px; opacity: 0.5; }
.scanner-controls { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.hint { text-align: center; color: var(--gray); font-size: 13px; margin: 10px 0 0; min-height: 18px; }

/* ---------- Manual input ---------- */

.manual-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gray);
  margin-bottom: 8px;
}
.manual-row { display: flex; gap: 10px; }
.manual-row input {
  flex: 1;
  min-height: var(--touch-min);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(4, 17, 29, 0.6);
  color: var(--white);
  font-size: 16px;
  min-width: 0;
}
.manual-row input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.25);
}
.manual-row .btn { flex-shrink: 0; }

/* ---------- Result card ---------- */

.result-card { text-align: center; padding: 28px 20px; }
.result-icon { font-size: 56px; line-height: 1; margin-bottom: 10px; }
.result-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.result-message { color: var(--gray); font-size: 14px; margin-bottom: 18px; line-height: 1.5; }
.result-details {
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.result-details .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
}
.result-details .row:last-child { border-bottom: none; }
.result-details .row .k { color: var(--gray); }
.result-details .row .v { font-weight: 600; text-align: right; }

.result-success { border-color: rgba(63, 191, 127, 0.5); background: linear-gradient(160deg, var(--success-bg), rgba(255,255,255,0.02)); }
.result-success .result-icon, .result-success .result-title { color: var(--success); }

.result-duplicate { border-color: rgba(230, 198, 92, 0.5); background: linear-gradient(160deg, var(--warn-bg), rgba(255,255,255,0.02)); }
.result-duplicate .result-icon, .result-duplicate .result-title { color: var(--warn); }

.result-invalid, .result-blocked, .result-cancelled, .result-gate-error, .result-error {
  border-color: rgba(225, 92, 92, 0.5);
  background: linear-gradient(160deg, var(--danger-bg), rgba(255,255,255,0.02));
}
.result-invalid .result-icon, .result-blocked .result-icon, .result-cancelled .result-icon,
.result-gate-error .result-icon, .result-error .result-icon,
.result-invalid .result-title, .result-blocked .result-title, .result-cancelled .result-title,
.result-gate-error .result-title, .result-error .result-title { color: var(--danger); }

.result-test-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--navy-dark);
  background: var(--gold-light);
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.result-timestamp { font-size: 12px; color: var(--gray); margin-bottom: 16px; }

/* ---------- Dashboard ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-tile {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.stat-tile.good { border-color: rgba(63, 191, 127, 0.4); }
.stat-tile.warn { border-color: rgba(230, 198, 92, 0.4); }
.stat-tile.bad { border-color: rgba(225, 92, 92, 0.4); }
.stat-value {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--gold-light);
}
.stat-tile.good .stat-value { color: var(--success); }
.stat-tile.warn .stat-value { color: var(--warn); }
.stat-tile.bad .stat-value { color: var(--danger); }
.stat-label {
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--gray);
  margin-top: 4px;
  text-transform: uppercase;
}

/* ---------- Recent check-ins ---------- */

.recent-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.empty-note { color: var(--gray); font-size: 13px; text-align: center; padding: 12px 0; }
.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.recent-item .ri-name { font-weight: 600; }
.recent-item .ri-meta { color: var(--gray); font-size: 11.5px; }
.recent-item .ri-status {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.recent-item .ri-status.success { color: var(--success); background: var(--success-bg); }
.recent-item .ri-status.duplicate { color: var(--warn); background: var(--warn-bg); }
.recent-item .ri-status.fail { color: var(--danger); background: var(--danger-bg); }
.recent-item .ri-status.test { color: var(--navy-dark); background: var(--gold-light); }

/* ---------- Settings modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 17, 29, 0.78);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  background: linear-gradient(160deg, var(--navy), var(--navy-dark));
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-card);
  padding: 20px 20px 28px;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.settings-note { color: var(--gray); font-size: 12.5px; line-height: 1.5; margin: 0 0 20px; }
.settings-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.tech-details { margin-top: 18px; color: var(--gray); font-size: 12.5px; }
.tech-details summary { cursor: pointer; color: var(--gold-light); margin-bottom: 8px; }
.tech-details code { color: var(--white); word-break: break-all; }
.tech-error { color: #ffb3b3; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(4, 17, 29, 0.95);
  border: 1px solid rgba(201, 162, 39, 0.4);
  color: var(--white);
  padding: 12px 18px;
  border-radius: 30px;
  font-size: 13.5px;
  box-shadow: var(--shadow-card);
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}

/* =========================================================================
   Desktop layout: scanner on the left, dashboard on the right.
   ========================================================================= */
@media (min-width: 900px) {
  .layout {
    flex-direction: row;
    align-items: flex-start;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
  }
  .scanner-column { flex: 1 1 0; max-width: 560px; }
  .dashboard-column { flex: 1 1 0; max-width: 480px; }
  .active-gate-banner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 4px auto 16px;
  }
  .gate-switch { min-width: 320px; }
  .setup-card { max-width: 460px; }
  .modal-overlay { align-items: center; }
  .modal-card { border-radius: 24px; max-width: 520px; }
}

@media (min-width: 1200px) {
  .layout, .active-gate-banner { max-width: 1280px; }
}
