/* ==========================================================================
   Control de acceso QR - hoja unica.
   Mobile-first: la pantalla de escaneo se usa en celulares en una puerta,
   a veces de noche y con una mano ocupada. Objetivos tactiles grandes,
   contraste alto, cero dependencias externas.
   ========================================================================== */

:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1f2630;
  --line: #2a323d;
  --fg: #e8edf3;
  --fg-dim: #9aa7b4;
  --accent: #4c8dff;
  --accent-ink: #ffffff;
  --ok: #1faa5f;
  --ok-soft: #10281c;
  --warn: #e07b16;
  --warn-soft: #2a1d0b;
  --bad: #d93a3a;
  --bad-soft: #2b1314;
  --wa: #25d366;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--bg-3);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  word-break: break-all;
}

.muted { color: var(--fg-dim); }
.small { font-size: 0.875rem; }
.tiny { font-size: 0.78rem; }
.nowrap { white-space: nowrap; }
.empty { padding: 1.5rem 0; text-align: center; }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.inline { display: inline; }
.crumb { margin: 0 0 0.75rem; }
.sub { margin-top: 1.25rem; color: var(--fg-dim); }

/* ---------------------------------------------------------------- layout */

.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem 16px 4rem;
}

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 16px;
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem;
  margin-bottom: 1rem;
}
.card-narrow { width: 100%; max-width: 380px; margin-bottom: 0; }
.card-title { margin-bottom: 0.9rem; }
.card.highlight { border-color: var(--ok); background: linear-gradient(180deg, var(--ok-soft), var(--bg-2)); }

.login-title { margin-bottom: 0.15rem; }

/* ---------------------------------------------------------------- nav */

.nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.7rem 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.nav-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.nav-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(31, 170, 95, 0.18);
  flex: none;
}
.nav-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.nav-links { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-left: auto; }
.nav-links a {
  color: var(--fg-dim);
  text-decoration: none;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.nav-links a:hover { background: var(--bg-3); color: var(--fg); }
.nav-links a.on { background: var(--bg-3); color: var(--fg); }
.nav-logout { display: flex; align-items: center; gap: 0.5rem; }
.nav-user { color: var(--fg-dim); font-size: 0.85rem; }

/* ---------------------------------------------------------------- forms */

label { display: block; margin-bottom: 0.85rem; }
label > span { display: block; font-size: 0.85rem; color: var(--fg-dim); margin-bottom: 0.3rem; }

input[type="text"], input[type="password"], input[type="tel"], input[type="search"],
input[type="file"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 0.6rem 0.7rem;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  /* 16px minimo: menos que eso y iOS hace zoom al enfocar. */
  font-size: 16px;
}
textarea { min-height: 8rem; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9rem; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
input[type="file"] { padding: 0.45rem; }

.stack > label:last-of-type { margin-bottom: 1.1rem; }

.form-grid { display: grid; gap: 0 0.75rem; grid-template-columns: 1fr; }
.form-grid label { margin-bottom: 0.85rem; }
.f-submit { margin-bottom: 0.25rem; }

.filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}
.filters input[type="search"] { flex: 1 1 180px; width: auto; }
.filters select { flex: 0 1 180px; width: auto; }

/* ---------------------------------------------------------------- buttons */

.btn, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--tap);
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--fg);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover, .btn-ghost:hover { filter: brightness(1.12); }
.btn:active, .btn-ghost:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #06281a; font-weight: 600; }
.btn-danger { background: transparent; border-color: var(--bad); color: #ff8e8e; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0.3rem 0.6rem; font-size: 0.85rem; border-radius: 6px; }
.btn-lg { min-height: 54px; padding: 0.8rem 1.4rem; font-size: 1.05rem; }
.btn[disabled], .btn-ghost[disabled] { opacity: 0.5; cursor: not-allowed; }

.row-gap, .send-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.send-row { margin: 0.9rem 0 0.5rem; }
.send-row form { margin: 0; }

/* ---------------------------------------------------------------- alerts */

.alert {
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
  border: 1px solid transparent;
}
.alert-error { background: var(--bad-soft); border-color: var(--bad); color: #ffc9c9; }
.alert-warn { background: var(--warn-soft); border-color: var(--warn); color: #ffd9a8; }
.alert-ok { background: var(--ok-soft); border-color: var(--ok); color: #b6f0cd; }

/* ---------------------------------------------------------------- stats */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
  position: relative;
}
.stat {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 0.6rem;
  text-align: center;
}
.stat-num { display: block; font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { display: block; font-size: 0.78rem; color: var(--fg-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-ok .stat-num { color: #44d98a; }
.stat-wait .stat-num { color: #ffbe5c; }
.stat-bar {
  grid-column: 1 / -1;
  height: 6px;
  background: var(--bg-3);
  border-radius: 99px;
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.feed { list-style: none; margin: 0; padding: 0; }
.feed li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.feed li:last-child { border-bottom: 0; }
.feed .f-hora { color: var(--fg-dim); font-variant-numeric: tabular-nums; }

.foot-links { text-align: center; margin-top: 1.5rem; }

/* ---------------------------------------------------------------- table */

.list-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -0.35rem; }
.tabla { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tabla th, .tabla td { padding: 0.6rem 0.35rem; text-align: left; vertical-align: top; }
.tabla thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tabla tbody tr { border-bottom: 1px solid var(--line); }
.tabla tbody tr:last-child { border-bottom: 0; }
.col-acciones { text-align: right; }
.acciones { display: flex; gap: 0.3rem; justify-content: flex-end; flex-wrap: wrap; }
.acciones form { margin: 0; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-ok { background: var(--ok-soft); color: #76e3a6; border-color: #1f5b3c; }
.badge-wait { background: var(--bg-3); color: var(--fg-dim); border-color: var(--line); }
.badge-bad { background: var(--bad-soft); color: #ff9b9b; border-color: #6b2525; }

/* ---------------------------------------------------------------- detalle */

.detalle { display: grid; gap: 1.1rem; grid-template-columns: 1fr; }
.detalle-qr { background: #fff; border-radius: var(--radius); padding: 0.75rem; display: grid; place-items: center; }
.detalle-qr img { display: block; width: 100%; height: auto; max-width: 320px; }
.detalle-nombre { margin-bottom: 0.2rem; }
.token { margin-top: 1rem; }

/* ---------------------------------------------------------------- ticket */

body.ticket-body {
  background: #f4f6f9;
  color: #11161c;
  display: flex;
  justify-content: center;
  padding: 16px;
}
.ticket {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 10px 40px rgba(16, 24, 40, 0.12);
  padding: 1.25rem;
  text-align: center;
}
.ticket-head { padding-bottom: 0.5rem; }
.ticket-event { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.2rem; }
.ticket-meta { color: #5b6672; font-size: 0.9rem; margin: 0; }
.ticket-qr {
  margin: 1rem 0;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid #e4e8ee;
  border-radius: 14px;
}
.ticket-qr img { display: block; width: 100%; height: auto; }
.ticket-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: #7a8694; margin: 0; }
.ticket-name h1 { font-size: 1.4rem; margin: 0.15rem 0 0.75rem; }
.ticket-state {
  border-radius: 12px;
  padding: 0.7rem;
  margin: 0.75rem 0;
  display: grid;
  gap: 0.15rem;
}
.ticket-state strong { font-size: 1rem; }
.ticket-state span { font-size: 0.85rem; }
.ticket-state.ok { background: #e7f7ee; color: #0d5c33; }
.ticket-state.used { background: #fff3e2; color: #8a4b05; }
.ticket-state.bad { background: #fdeaea; color: #8c1d1d; }
.ticket-tips {
  text-align: left;
  font-size: 0.85rem;
  color: #5b6672;
  margin: 1rem 0 0.5rem;
  padding-left: 1.1rem;
}
.ticket-tips li { margin-bottom: 0.3rem; }
.ticket-foot { font-size: 0.85rem; color: #5b6672; margin: 0.75rem 0 0; }
.ticket-foot a { color: #1f6feb; }

/* ---------------------------------------------------------------- escaneo */

body.scan-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #05070a;
  overscroll-behavior: none;
}

.scan-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 12px;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.scan-top-left { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.scan-estacion {
  font-size: 0.8rem;
  color: var(--fg-dim);
  background: var(--bg-3);
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 24vw;
}
.scan-net { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.scan-net.off { background: var(--bad); }
.scan-counter { margin: 0 auto; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.scan-counter strong { font-size: 1.2rem; color: #44d98a; }
.scan-counter span { color: var(--fg-dim); }
.scan-top-right { display: flex; align-items: center; gap: 0.25rem; }
.scan-top-right .btn-ghost { min-height: 34px; padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.scan-https { margin: 0.75rem 12px 0; }

.scan-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.75rem 12px;
  min-height: 0;
}

.reader {
  width: 100%;
  max-width: 460px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}
.reader:empty { display: none; }
/* html5-qrcode inyecta su propio video y canvas: los forzamos a encajar. */
.reader video { width: 100% !important; height: auto !important; display: block; }
.reader img { display: none; }
#reader__dashboard_section_csr button { font: inherit; }

.scan-hint { text-align: center; max-width: 420px; }
.scan-tools { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }

/* ----- resultado a pantalla completa ----- */

.result {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: #fff;
}
.result[hidden] { display: none; }
.result.valido { background: #0f8a4d; }
.result.usado { background: #c96a09; }
.result.invalido { background: #b82828; }
.result-inner { max-width: 520px; width: 100%; }
.result-icon { font-size: 4.5rem; line-height: 1; margin-bottom: 0.5rem; font-weight: 700; }
.result-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.5rem;
}
.result-name { font-size: 2rem; font-weight: 700; margin: 0 0 0.35rem; overflow-wrap: anywhere; }
.result-sub { font-size: 1.05rem; opacity: 0.92; margin: 0 0 1.5rem; }
.result .btn-ghost { border-color: rgba(255, 255, 255, 0.6); color: #fff; }

/* ----- hoja de busqueda manual ----- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
}
.sheet[hidden] { display: none; }
.sheet-inner {
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 1rem 16px calc(1rem + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.sheet-head h2 { margin: 0; }
.manual-results { list-style: none; margin: 0.75rem 0 0; padding: 0; }
.manual-results li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}
.manual-results li:last-child { border-bottom: 0; }
.manual-nombre { font-weight: 600; }

/* ---------------------------------------------------------------- desktop */

@media (min-width: 680px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .f-nombre { grid-column: 1 / 2; }
  .f-tel { grid-column: 2 / 3; }
  .f-nota { grid-column: 1 / 2; }
  .f-submit { grid-column: 2 / 3; align-self: end; }
  .detalle { grid-template-columns: 320px 1fr; align-items: start; }
  .wrap { padding-top: 1.5rem; }
  .stat-num { font-size: 2.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Bloque de ayuda plegable (por ejemplo, "no se abrio WhatsApp?"). */
.ayuda {
  margin-top: 0.75rem;
  border-top: 1px solid var(--line);
  padding-top: 0.6rem;
}
.ayuda summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--fg-dim);
  min-height: 32px;
  display: flex;
  align-items: center;
}
.ayuda summary:hover { color: var(--fg); }
.ayuda[open] summary { margin-bottom: 0.4rem; }
