:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #22c55e;
  --warn: #f59e0b;
  --warn-bg: #422006;
  --danger: #ef4444;
  --danger-bg: #450a0a;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  min-height: 100%;
  overscroll-behavior-y: none;
}

.app { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(120px + env(safe-area-inset-bottom)); }
.loading { text-align: center; color: var(--muted); padding: 48px 0; }

/* ---------- QR válido / portada (pantalla pública) ---------- */
.qr-check {
  min-height: 88vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 14px;
}
.qr-check h1 { font-size: 2rem; line-height: 1.15; font-weight: 800; }
.qr-check .sub { color: var(--muted); font-size: 1rem; }

.check-svg { width: min(58vw, 220px); height: auto; stroke-width: 3.5; }
.check-circulo { stroke: var(--primary); stroke-dasharray: 166; stroke-dashoffset: 166; animation: trazar-circulo .6s cubic-bezier(.65,0,.45,1) forwards; }
.check-trazo {
  stroke: var(--primary); stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 60; stroke-dashoffset: 60;
  animation: trazar-check .35s cubic-bezier(.65,0,.45,1) .55s forwards;
}
.qr-check:not(.invalido) .check-svg { animation: latido .5s ease-in-out .9s; }
.qr-check.invalido .check-circulo, .qr-check.invalido .check-trazo { stroke: var(--danger); }
.qr-check.invalido h1 { color: #fca5a5; }

@keyframes trazar-circulo { to { stroke-dashoffset: 0; } }
@keyframes trazar-check { to { stroke-dashoffset: 0; } }
@keyframes latido { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.08); } }

@media (prefers-reduced-motion: reduce) {
  .check-circulo, .check-trazo { animation: none; stroke-dashoffset: 0; }
  .qr-check:not(.invalido) .check-svg { animation: none; }
}

/* Botón de acceso del funcionario, fijo arriba a la derecha. */
.login-corner {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  width: auto;
  padding: 9px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  z-index: 10;
}

.logo { width: min(70%, 260px); height: auto; margin: 0 auto; background: #fff; border-radius: var(--radius); padding: 12px; }

/* ---------- Login ---------- */
.login { min-height: 92vh; display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.linkish.centrado { display: block; margin: 0 auto; }
.login h1 { font-size: 1.6rem; line-height: 1.2; }
.login p.sub { color: var(--muted); font-size: 0.95rem; margin-top: -10px; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
input[type="text"], input[type="password"] {
  width: 100%;
  padding: 15px 14px;
  font-size: 1.05rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.field + .field { margin-top: 14px; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }

/* ---------- Botones ---------- */
button {
  font: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: #052e16;
  background: var(--primary);
  font-weight: 700;
  padding: 16px;
  width: 100%;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 600; }
button.big { font-size: 1.25rem; padding: 20px; letter-spacing: .02em; }
button.done { background: var(--surface-2); color: var(--muted); }
.linkish { background: none; border: none; color: var(--muted); text-decoration: underline; font-size: 0.85rem; width: auto; padding: 8px; }

/* ---------- Banners ---------- */
.banner { border-radius: var(--radius); padding: 12px 14px; font-size: 0.95rem; font-weight: 600; margin-bottom: 14px; }
.banner.warn { background: var(--warn-bg); color: #fcd34d; border: 1px solid var(--warn); }
.banner.danger, .banner.error { background: var(--danger-bg); color: #fca5a5; border: 1px solid var(--danger); }

/* ---------- Ficha ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.topbar .who { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .acciones { display: flex; gap: 4px; flex-shrink: 0; }

.foto-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.foto-wrap img { width: 100%; height: 100%; object-fit: cover; }
.foto-wrap .sinfoto { color: var(--muted); font-size: 0.9rem; }

.nombre { font-size: 1.7rem; font-weight: 800; line-height: 1.15; margin-top: 14px; }
.meta { color: var(--muted); margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 0.85rem; font-weight: 600; }
.chip.ok { background: #052e16; border-color: var(--primary); color: #86efac; }
.chip.bad { background: var(--danger-bg); border-color: var(--danger); color: #fca5a5; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-top: 14px; }
.card h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.card.salud { background: var(--warn-bg); border-color: var(--warn); }
.card.salud h2 { color: #fcd34d; }
.card.salud ul { margin-left: 18px; font-weight: 600; }
.card.salud li + li { margin-top: 4px; }

.row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.row + .row { border-top: 1px solid var(--surface-2); }
.row .k { color: var(--muted); font-size: 0.9rem; flex-shrink: 0; }
.row .v { text-align: right; font-weight: 600; word-break: break-word; }
.row .v a { color: var(--primary); text-decoration: none; }

.sticky {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.sticky .inner { max-width: 560px; margin: 0 auto; }
.sticky .undo { text-align: center; margin-top: 4px; }

/* ---------- Éxito ---------- */
.exito { min-height: 88vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; }
.exito .check { font-size: 5rem; line-height: 1; color: var(--primary); }
.exito .check.warn { color: var(--warn); }
.exito h1 { font-size: 1.8rem; }
.exito .quien { color: var(--muted); }
.exito .acciones { margin-top: 22px; width: 100%; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Escáner ---------- */
.scanner { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; object-fit: cover; }
.scanner .barra { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.scanner .msg { color: var(--muted); text-align: center; padding: 24px; }
