:root {
  --green: #008000;
  --green-dark: #006400;
  --black: #111;
  --blue: #007aff;
  --text: #1a1a1a;
  --muted: #666;
  --line: #e0e0e0;
  --bg: #fff;
  --card: #f0f0f0;
  --danger: #d32f2f;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

#app {
  max-width: 640px;
  min-height: 100%;
  margin: 0 auto;
}

.view {
  min-height: 100dvh;
  padding: calc(16px + var(--safe-t)) 16px calc(var(--tabbar-h) + var(--safe-b) + 16px);
}

/* ---------- Botones ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 12px 20px;
  min-height: 46px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: #757575;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { background: #a0a0a0; cursor: default; }
.btn:focus-visible, .tab:focus-visible, .tabbar-item:focus-visible, .input:focus-visible {
  outline: 3px solid rgba(0, 122, 255, .5);
  outline-offset: 2px;
}
.btn-primary { background: var(--green); }
.btn-primary:hover { background: var(--green-dark); }
.btn-dark { background: var(--black); }
.btn-blue { background: var(--blue); }
.btn-light { background: #e3e3e3; color: #000; }
.btn-danger { background: var(--danger); }
.btn-link { background: none; color: #1976d2; min-height: 0; padding: 6px 0; font-weight: 600; }
.btn-pill { border-radius: 999px; padding-inline: 30px; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); }
.btn-block { width: 100%; }
.btn-xl { font-size: 1.15rem; min-height: 60px; }
.btn-glass {
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, .25);
  border-radius: 999px;
  min-height: 42px;
  padding: 8px 16px;
  font-weight: 600;
}

.input {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  /* 16px mínimo: evita el zoom automático de iOS al enfocar */
  font-size: 16px;
  background: #fff;
  color: #000;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(0, 0, 0, .15);
  border-top-color: var(--green);
  border-radius: 50%;
  display: inline-block;
  animation: spin .8s linear infinite;
}
.spinner-light { border-color: rgba(255, 255, 255, .3); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- Inicio ---------- */
.view-home { display: flex; flex-direction: column; }
.brand { padding: 28px 0 12px; text-align: center; min-height: 100px; }
.brand-logo { max-width: 240px; width: 70%; height: 64px; object-fit: contain; }
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  text-align: center;
}
.home-title { font-size: 1.6rem; line-height: 1.2; margin: 0; user-select: none; }
.home-subtitle { font-size: 1.05rem; color: var(--muted); margin: 0 0 12px; }
.home-body .btn { width: 100%; max-width: 340px; }
.code-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: .9rem;
  color: var(--muted);
}
.badge {
  background: #e8f5e9;
  color: var(--green-dark);
  border-radius: 999px;
  padding: 3px 10px;
  font-weight: 700;
  font-size: .78rem;
  letter-spacing: .02em;
}
.badge.badge-test { background: #fff3e0; color: #b25e00; }

/* ---------- Escáner ---------- */
.view-scan {
  position: fixed;
  inset: 0;
  z-index: 20;
  max-width: none;
  padding: 0;
  background: #000;
  color: #fff;
  overflow: hidden;
}
.scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scan-video.mirrored { transform: scaleX(-1); }
.scan-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(68vw, 46vh, 320px);
  aspect-ratio: 1;
  transform: translate(-50%, -55%);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
  pointer-events: none;
}
.scan-frame span {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px solid #fff;
}
.scan-frame span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.scan-frame span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 18px; }
.scan-frame span:nth-child(3) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }
.scan-frame span:nth-child(4) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 18px; }
.scan-top {
  position: absolute;
  top: calc(14px + var(--safe-t));
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
}
.scan-bottom {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(22px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.scan-hint { margin: 0; font-weight: 600; text-shadow: 0 1px 3px #000; }
.scan-message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 28px 150px;
  background: #111;
  text-align: center;
}
.scan-message p { margin: 0; max-width: 420px; font-size: 1.05rem; }
.scan-busy {
  position: absolute;
  top: calc(72px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .75);
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- Listado ---------- */
.list-title { font-size: 1.25rem; text-align: center; margin: 12px 0; }
.tabs { display: flex; margin: 12px 0; }
.tab {
  flex: 1;
  padding: 10px 4px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
}
.tab.active { border-bottom-color: var(--blue); }
.list-status { text-align: center; color: var(--muted); margin: 20px 0; }
.list-status.error { color: var(--danger); }
.ticket-list { list-style: none; margin: 0; padding: 0 0 62px; }
.ticket-card {
  background: var(--card);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}
.ticket-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ticket-name { font-weight: 700; }
.ticket-check { color: var(--green); font-weight: 700; flex: none; }
.ticket-line { font-size: .875rem; color: #444; margin: 1px 0 0; }
.ticket-company { font-size: .8rem; color: var(--muted); font-style: italic; margin: 2px 0 0; }
.list-refresh {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 32px), 608px);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.list-refresh:active { transform: translateX(-50%) translateY(1px); }

/* ---------- Barra inferior ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
}
.tabbar-item {
  flex: 1;
  border: 0;
  background: none;
  font: inherit;
  font-size: .78rem;
  font-weight: 600;
  color: #8a8a8a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}
.tabbar-item.active { color: var(--green); }
.tabbar-icon { font-size: 1.25rem; line-height: 1; }

/* ---------- Modales ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, .65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-box {
  background: #fff;
  color: var(--text);
  border-radius: 14px;
  width: min(100%, 440px);
  max-height: calc(100dvh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.dialog { padding: 24px; display: flex; flex-direction: column; gap: 12px; text-align: center; overflow-y: auto; }
.dialog-title { margin: 0; font-size: 1.15rem; }
.dialog-message { margin: 0; color: #333; overflow-wrap: anywhere; white-space: pre-line; }
.dialog-actions { display: flex; gap: 10px; margin-top: 6px; }
.dialog-actions .btn { flex: 1; }
.dialog-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  background: #1976d2;
}
.dialog-success .dialog-icon { background: #2e9e3a; }
.dialog-warning .dialog-icon { background: #f08c00; }
.dialog-error .dialog-icon { background: var(--danger); }
.dialog label { font-weight: 700; text-align: left; }
.dialog .error-text { color: var(--danger); font-size: .9rem; margin: 0; }
.dialog .btn-stack { display: flex; flex-direction: column; gap: 8px; }
.qr-raw {
  background: #f5f5f5;
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: .85rem;
  overflow-wrap: anywhere;
  user-select: all;
  max-height: 30vh;
  overflow-y: auto;
  margin: 0;
}
.link { color: var(--green); font-weight: 600; }

/* Modal de ticket (ItemValidationModal) */
.contents { display: contents; }
.item-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.item-header { padding: 14px 12px; text-align: center; border-bottom: 1px solid var(--line); }
.item-header.pending { background: #fff3e0; }
.item-header.validated { background: #fdecea; border-bottom: 3px solid var(--danger); }
.item-header-title { margin: 0; font-size: 1.15rem; font-weight: 800; }
.item-header.validated .item-header-title { color: #b71c1c; }
.item-header-sub { margin: 6px 0 0; font-size: .95rem; color: #333; font-weight: 600; }
.item-section { padding: 14px 16px; border-bottom: 1px solid #f0f0f0; }
.item-section.session { background: #e3f2fd; }
.item-section.buyer { background: #fff9e6; }
.item-section h3 { margin: 0 0 6px; font-size: 1rem; color: #333; }
.item-event { font-size: 1.1rem; font-weight: 700; margin: 0; }
.item-session-name { font-weight: 600; color: #1976d2; margin: 0 0 4px; }
.item-session-when { font-weight: 700; color: #1976d2; margin: 0; }
.item-buyer-name { font-size: 1.1rem; font-weight: 700; color: #c66100; margin: 0 0 2px; }
.item-buyer-email { font-size: .875rem; color: var(--muted); margin: 0; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.kv-label { font-size: .875rem; color: var(--muted); font-weight: 500; flex: none; max-width: 50%; }
.kv-value { font-size: .875rem; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.kv-value.small { font-size: .78rem; font-weight: 600; }
.kv-value.price { font-size: 1rem; color: #2e9e3a; }
.kv .input, .added-field .input {
  border-color: #90caf9;
  background: #f5faff;
  padding: 6px 8px;
  font-weight: 700;
}
.kv .input { text-align: right; }
.added-field { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.added-field .input:first-child { font-weight: 400; }
.added-field .remove {
  flex: none;
  border: 0;
  background: none;
  color: #e53935;
  font-size: 1.1rem;
  font-weight: 700;
  width: 36px;
  height: 36px;
  cursor: pointer;
}
.item-actions { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); }
.btn-validate { background: #2e9e3a; min-height: 54px; font-size: 1.05rem; }
