/* =============================================================================
   MiEventos Check-in PWA — mobile-first stylesheet
   Brand: navy #0a1a2e bg, lime #c8d600 accents.
   ============================================================================= */

:root {
  --nav:        #0a1a2e;
  --nav-2:      #15294a;
  --lime:       #c8d600;
  --lime-2:     #b3bf00;
  --grey:       #94a3b8;
  --grey-soft:  #cbd5e1;
  --card:       #ffffff;
  --bg:         #0a1a2e;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --success:    #16a34a;
  --line:       #e5e7eb;
  --radius:     16px;
  --shadow:     0 6px 24px rgba(0, 0, 0, 0.25);
  --safe-bot:   env(safe-area-inset-bottom, 0px);
  --safe-top:   env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, system-ui, sans-serif;
  background: var(--bg);
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: contain;
}
button { font-family: inherit; }
input { font-family: inherit; }
img { display: block; max-width: 100%; }

/* ----- View management ----- */
.view { display: none; min-height: 100vh; min-height: 100dvh; }
.view--active { display: block; }

/* ----- Loading view ----- */
#view-loading {
  display: none;
  align-items: center;
  justify-content: center;
}
#view-loading.view--active { display: flex; }
.spinner {
  width: 44px; height: 44px;
  border: 3px solid rgba(200, 214, 0, 0.25);
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   LOGIN VIEW
   ============================================================================ */
#view-login.view--active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bot));
}
.login-card {
  background: var(--card);
  color: var(--nav);
  border-radius: var(--radius);
  padding: 28px 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow);
}
.login-logo {
  width: 64px; height: 64px;
  border-radius: 14px;
  margin: 0 auto 14px;
  display: block;
}
.login-title {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  margin: 0 0 4px;
  color: var(--nav);
}
.login-subtitle {
  font-size: 13px;
  text-align: center;
  margin: 0 0 22px;
  color: var(--grey);
}
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--grey);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 6px;
}
.field-label:first-of-type { margin-top: 0; }
#view-login input[type="email"],
#view-login input[type="password"] {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 16px; /* 16px+ prevents iOS auto-zoom on focus */
  color: var(--nav);
  background: #fff;
  transition: border-color 0.15s ease;
}
#view-login input:focus { outline: none; border-color: var(--nav); }

.login-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #fee2e2;
  border-radius: 8px;
  color: #991b1b;
  font-size: 13px;
  font-weight: 600;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  text-decoration: none;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease, color 120ms ease;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { display: flex; width: 100%; margin-top: 18px; }
.btn-primary {
  background: var(--lime);
  color: var(--nav);
  border-color: var(--lime);
}
.btn-primary:hover { background: var(--lime-2); border-color: var(--lime-2); }
.btn-ghost {
  background: transparent;
  color: var(--nav);
  border-color: var(--line);
}
.btn-ghost:hover { background: #f3f4f6; }

.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(10, 26, 46, 0.25);
  border-top-color: var(--nav);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ============================================================================
   INSTALL HINTS
   ============================================================================ */
.install-hint { margin-top: 12px; }
.install-ios-msg {
  position: relative;
  background: #f3f8e6;
  border-left: 4px solid var(--lime);
  border-radius: 0 8px 8px 0;
  color: var(--nav);
  font-size: 13px;
  padding: 12px 36px 12px 14px;
  line-height: 1.45;
}
.install-dismiss {
  position: absolute;
  top: 6px; right: 8px;
  background: transparent;
  border: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--grey);
  cursor: pointer;
  padding: 4px 6px;
}

/* ============================================================================
   APP HEADER (scanner + event-picker views)
   ============================================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 14px 12px;
  background: var(--nav);
  color: #fff;
  position: relative;
  z-index: 5;
}
.header-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}
.header-event {
  background: transparent;
  border: 0;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 700;
  padding: 6px 8px;
  margin-left: -8px;
  cursor: pointer;
  text-align: left;
  max-width: 80%;
}
.header-event-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-event-caret { color: var(--lime); font-size: 12px; }
.header-menu-btn {
  background: transparent; border: 0; color: #fff;
  padding: 6px; cursor: pointer;
}

.menu-pop {
  /* fixed so it positions relative to the viewport rather than the static
     #view-scanner ancestor — previously the popup could land off-screen if
     the parent's stacking context shifted. fixed + high z-index defends
     against future DOM reshuffles. */
  position: fixed;
  top: calc(56px + var(--safe-top));
  right: 8px;
  background: #fff;
  color: var(--nav);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 200px;
  overflow: hidden;
  z-index: 9999;
}
.menu-item {
  display: block; width: 100%; text-align: left;
  background: transparent; border: 0;
  padding: 13px 16px;
  font-size: 14px; font-weight: 600;
  color: var(--nav);
  cursor: pointer;
}
.menu-item + .menu-item { border-top: 1px solid var(--line); }
.menu-item:hover { background: #f7f9fc; }

/* ============================================================================
   SCANNER VIEW
   ============================================================================ */
.scanner-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  position: relative;
  min-height: 50vh;
}
/* Wrapper hosts both the html5-qrcode-managed div AND the SVG corner overlay
   on top. The wrap gives us a fixed positioning context for the SVG. */
.qr-reader-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.qr-reader {
  width: 100%;
  height: 100%;
  background: #000;
  border-radius: 24px;
  overflow: hidden;
  position: relative;
}
/* Lime corner brackets on the camera viewfinder. SVG follows the rounded
   container; replaces the older single-rectangle ::before. */
.qr-corners {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 12;
}
.qr-corners path {
  stroke: rgba(200, 214, 0, 0.85);
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
/* Force full brightness on the camera feed. Inherited filter/opacity rules
   from elsewhere would otherwise dim the live video. */
.qr-reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  filter: none !important;
  opacity: 1 !important;
  background: transparent;
}
/* html5-qrcode renders a heavy shaded "viewfinder" overlay (4 absolutely-
   positioned divs with background rgba(0,0,0,0.48)) around the qrbox.
   That's what users perceive as "the camera is too dark" — the feed itself
   is fine, just heavily vignetted. Lighten it so surroundings stay visible. */
.qr-reader div[style*="rgba(0, 0, 0, 0.48)"],
.qr-reader div[style*="rgba(0,0,0,0.48)"] {
  background-color: rgba(0, 0, 0, 0.15) !important;
}
/* Hide html5-qrcode's built-in chrome buttons — we drive lifecycle ourselves. */
.qr-reader #html5-qrcode-button-camera-permission,
.qr-reader #html5-qrcode-button-camera-start,
.qr-reader #html5-qrcode-button-camera-stop,
.qr-reader #html5-qrcode-button-torch,
.qr-reader #html5-qrcode-anchor-scan-type-change,
.qr-reader select,
.qr-reader img[alt="Info icon"] {
  display: none !important;
}
/* Old ::before single-rectangle bracket replaced by SVG corners overlay
   inside .qr-reader-wrap (see .qr-corners). */
.scanner-hint {
  color: var(--grey-soft);
  font-size: 13px;
  text-align: center;
  margin: 14px 0 0;
}

/* ============================================================================
   SCAN MODAL — center-anchored, animated banner + draw-in SVG icon.
   Replaces the older bottom-sheet result-card. Door staff sees the result
   instantly without their eyes leaving the camera area.
   ============================================================================ */
.scan-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 26, 46, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 2000;
  opacity: 0;
  transition: opacity 250ms ease;
}
.scan-modal-backdrop.is-visible { opacity: 1; }

.scan-modal {
  position: fixed;
  left: 50%; top: 50%;
  transform: translate(-50%, calc(-50% + 40px));
  width: 92%; max-width: 420px;
  background: #fff;
  color: var(--nav);
  border-radius: 28px;
  z-index: 2001;
  overflow: hidden;
  opacity: 0;
  transition: opacity 300ms ease, transform 300ms cubic-bezier(0.2, 0.9, 0.3, 1.2);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}
.scan-modal.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.scan-modal-banner {
  padding: 36px 24px 28px;
  text-align: center;
  color: #fff;
  background: #1f2937; /* fallback before state class applies */
}
.scan-modal-banner.is-valid    { background: linear-gradient(135deg, #16a34a, #22c55e); }
.scan-modal-banner.is-used     { background: linear-gradient(135deg, #ea580c, #f97316); }
.scan-modal-banner.is-error    { background: linear-gradient(135deg, #dc2626, #ef4444); }
.scan-modal-banner.is-canceled { background: linear-gradient(135deg, #525252, #737373); }

.scan-modal-icon { margin-bottom: 12px; line-height: 0; }
.scan-modal-icon svg { display: inline-block; }
/* SVG strokes draw in via stroke-dashoffset. Animation runs every time the
   modal opens because ui.js sets innerHTML on each render, re-creating the
   element. */
.scan-modal-icon .icon-anim {
  stroke: #fff;
  stroke-width: 6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: iconDraw 600ms ease-out forwards;
}
@keyframes iconDraw {
  from { stroke-dasharray: 300; stroke-dashoffset: 300; }
  to   { stroke-dasharray: 300; stroke-dashoffset: 0; }
}

.scan-modal-headline {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.scan-modal-body { padding: 24px; color: var(--nav); }
.scan-modal-name { font-size: 22px; font-weight: 700; margin-bottom: 6px; line-height: 1.2; }
.scan-modal-type { font-size: 16px; color: #525252; margin-bottom: 14px; font-weight: 600; }
.scan-modal-seat {
  background: #f3f4f6;
  border-left: 4px solid var(--lime);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 15px;
  margin-bottom: 14px;
  font-weight: 600;
}
.scan-modal-seat[hidden] { display: none; }
.scan-modal-meta {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 12px;
  line-height: 1.4;
}
.scan-modal-meta[hidden] { display: none; }
.scan-modal-validated {
  background: #fef2f2;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}
.scan-modal-validated[hidden] { display: none; }
.validated-label { font-weight: 400; margin-right: 6px; }

.scan-modal-actions {
  display: flex;
  gap: 12px;
  padding: 0 24px calc(24px + var(--safe-bot));
}
.btn-modal-cancel, .btn-modal-confirm {
  flex: 1;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 100ms;
  font-family: inherit;
  min-height: 52px;
}
.btn-modal-cancel  { background: #f3f4f6; color: #525252; }
.btn-modal-confirm { background: var(--lime); color: var(--nav); }
.btn-modal-confirm:active, .btn-modal-cancel:active { transform: scale(0.97); }
.btn-modal-confirm:disabled, .btn-modal-cancel:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-modal-confirm[hidden] { display: none; }

/* When only Cerrar shows (non-valid states), let it span full width. */
.scan-modal-actions:has(.btn-modal-confirm[hidden]) .btn-modal-cancel { flex: 1; }

/* ============================================================================
   STATS PANEL — swipe-up from bottom, peek mode + expanded mode
   ============================================================================ */
.stats-panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--nav-2);
  color: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
  z-index: 30;
  transform: translateY(calc(100% - 80px - var(--safe-bot)));
  transition: transform 320ms cubic-bezier(0.2, 0.85, 0.3, 1);
  padding-bottom: var(--safe-bot);
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}
.stats-panel.is-expanded {
  transform: translateY(0);
}
.stats-handle {
  width: 100%;
  background: transparent;
  border: 0;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 16px 14px;
  cursor: pointer;
  font-family: inherit;
}
.stats-grip {
  width: 44px; height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.35);
}
.stats-handle-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.75);
}
.stats-handle-summary #stats-percent-mini {
  font-size: 18px; font-weight: 800; color: var(--lime);
}
.stats-content {
  padding: 8px 18px 16px;
  overflow-y: auto;
  flex: 1;
}
.stats-summary { margin-bottom: 18px; }
.stats-big-number {
  font-size: 56px;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  text-align: center;
  margin: 8px 0 12px;
}
.stats-progress-bar {
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}
.stats-progress-fill {
  height: 100%;
  background: var(--lime);
  border-radius: 999px;
  transition: width 400ms ease-out, background-color 250ms ease;
}
.stats-progress-fill.is-25  { background: var(--lime); }
.stats-progress-fill.is-50  { background: #fbbf24; }
.stats-progress-fill.is-75  { background: #fb923c; }
.stats-progress-fill.is-100 { background: #16a34a; }
.stats-counts {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}
.stats-counts strong { color: #fff; font-weight: 700; }
.stats-types { display: flex; flex-direction: column; gap: 10px; }
.stats-type-row {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 10px 12px;
}
.stats-type-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 13px;
}
.stats-type-name { font-weight: 700; color: #fff; }
.stats-type-counts { color: rgba(255, 255, 255, 0.65); font-variant-numeric: tabular-nums; }
.stats-type-sub {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.stats-type-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.stats-type-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 400ms ease-out;
}

/* ============================================================================
   EVENT PICKER VIEW
   ============================================================================ */
.event-list { list-style: none; margin: 0; padding: 8px 14px var(--safe-bot); }
.event-list li {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.event-list li:active { transform: scale(0.99); }
.event-list li.is-active { border-color: var(--lime); background: rgba(200, 214, 0, 0.1); }
.event-list .event-title { font-size: 15px; font-weight: 700; color: #fff; }
.event-list .event-meta  { font-size: 12px; color: var(--grey-soft); margin-top: 4px; }

/* ============================================================================
   TOAST
   ============================================================================ */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bot));
  left: 50%;
  transform: translateX(-50%);
  background: var(--nav-2);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  max-width: 90vw;
}
.toast.is-visible { opacity: 1; pointer-events: auto; }
.toast--error { background: #991b1b; }
.toast--success { background: var(--success); }

/* ============================================================================
   INSTALL MODAL (iOS Safari instructions, triggered from hamburger menu)
   ============================================================================ */
.install-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 300;
}
.install-modal[hidden] { display: none; }
.install-modal-card {
  background: #fff;
  color: var(--nav);
  border-radius: var(--radius);
  padding: 24px 22px calc(22px + var(--safe-bot));
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: slide-up 0.25s cubic-bezier(0.2, 0.9, 0.4, 1);
}
.install-modal-title {
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 10px;
  color: var(--nav);
}
.install-modal-body {
  font-size: 14px;
  line-height: 1.55;
  color: var(--nav);
  margin: 0 0 18px;
}

/* ============================================================================
   Larger viewports — modest centering, nothing fancy
   ============================================================================ */
@media (min-width: 768px) {
  .view { max-width: 480px; margin: 0 auto; }
  .scanner-area { min-height: 60vh; }
}
