:root {
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #f4f5f7;
  color: #1c1c1e;
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: white;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 360px;
}

.auth-title {
  margin: 0 0 6px;
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 24px;
}

.auth-subtitle { margin: 0; color: #8c8073; font-size: 14px; }

label { display: block; font-size: 13px; font-weight: 600; margin: 16px 0 6px; color: #444; }

input[type="text"], input[type="email"], input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #d8d8dc;
  font-size: 15px;
}

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  background: #1c1c1e;
  color: white;
}

.btn-secondary { background: #eceef1; color: #1c1c1e; }
.btn-green { background: #1f9d55; }
.btn-danger { background: #e74c3c; }

/* Quitar un sello es una corrección, no una acción principal: gris con
   contorno, para que la mirada del cajero siga cayendo en "+1 sello". */
.btn-undo {
  background: #f4f5f7;
  color: #4a4a4f;
  border: 1px solid #d8d8dc;
}

.btn-undo:hover:not(:disabled) { background: #eceef1; }
.btn-undo:disabled { opacity: 0.45; cursor: not-allowed; }

/* Borrar va en contorno, no en rojo macizo: es la única acción irreversible de
   la tabla y no debe competir por la mirada con "+1 sello", que es la que el
   cajero usa cien veces al día. */
.btn-delete {
  background: transparent;
  color: #b3261e;
  border: 1px solid #e7b3ae;
}

.btn-delete:hover { background: #fdecea; }

.error-banner {
  background: #fdecea;
  color: #b3261e;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 16px;
}

.warning-banner {
  background: #fff4e5;
  color: #8a5a00;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 20px;
}

.success-banner {
  background: #e7f7ee;
  color: #157a41;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  background: white;
  border-bottom: 1px solid #eaeaea;
}

.topbar h1 { font-family: "Fraunces", serif; font-weight: 700; font-size: 19px; margin: 0; }
.topbar .meta { font-size: 13px; color: #777; }

.page { max-width: 960px; margin: 0 auto; padding: 32px; }

.panel {
  background: white;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.04);
  margin-bottom: 24px;
}

.panel h2 { margin-top: 0; font-size: 16px; }

.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 180px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #f0f0f0; }
th { color: #888; font-weight: 600; font-size: 12px; text-transform: uppercase; }

.stamp-row { display: flex; gap: 4px; }
.stamp-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #ddd;
}
.stamp-dot.filled { background: #1f9d55; border-color: #16803f; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions form { display: inline; }
.actions button { padding: 6px 10px; font-size: 12px; }

.scan-hint { font-size: 13px; color: #777; margin: 0 0 14px; line-height: 1.5; }

@media (max-width: 640px) {
  .topbar { padding: 16px 20px; flex-wrap: wrap; gap: 10px; }
  .page { padding: 16px; }
  .panel { padding: 18px; }

  table thead { display: none; }
  table, table tbody, table tr, table td { display: block; width: 100%; }
  table tr {
    background: #fafafa;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  table td {
    border-bottom: none;
    padding: 5px 0;
    word-break: break-word;
  }
  table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 2px;
  }
  table td.actions { padding-top: 10px; }
}

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  overflow-y: auto;
}

.btn-close-fixed {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #111;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  z-index: 1001;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.scanner-box {
  background: #111;
  border-radius: 18px;
  padding: 16px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: auto;
}

.btn-activate-camera {
  background: #1f9d55;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.scanner-box video {
  width: 100%;
  max-height: 50vh;
  border-radius: 12px;
  background: #000;
  aspect-ratio: 1;
  object-fit: cover;
}

.scanner-status {
  color: #f4f4f4;
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}

.scanner-status.scanner-success { color: #4ade80; font-weight: 600; }
.scanner-status.scanner-error { color: #f87171; font-weight: 600; }

/* ===== Tarjeta pública: tarjeta de fidelidad estilo "impresa" (fondo oscuro + color de marca) ===== */

.card-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #e9e9ec;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --dark-bg: #111013;
  --muted: #9d9891;
  --hairline: rgba(255,255,255,0.14);
}

.ticket {
  --brand-color: #f5b400;
  width: 100%;
  max-width: 380px;
  border-radius: 26px;
  overflow: hidden;
  box-shadow: 0 28px 60px -20px rgba(0,0,0,0.45), 0 2px 6px rgba(0,0,0,0.15);
  /* Cada negocio puede traer su propio fondo (ver StampTheme en stampIcons.ts).
     Sin tema queda el oscuro de siempre. */
  background: var(--ticket-bg, var(--dark-bg));
  border: 1px solid rgba(255,255,255,0.06);
}

.ticket-header {
  background: var(--brand-color);
  color: var(--header-text, white);
  padding: 22px 24px 18px;
}

.header-top { display: flex; flex-direction: column; gap: 12px; }

.brand-row { display: flex; align-items: center; gap: 12px; }

.brand-row-wordmark { flex-direction: column; align-items: flex-start; gap: 4px; }

.brand-wordmark {
  max-width: 100%;
  max-height: 64px;
  width: auto;
  object-fit: contain;
}

.brand-logo {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255,255,255,0.85);
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.brand-name {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.brand-subtitle {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  opacity: 0.85;
  margin-top: 2px;
}

.header-divider {
  height: 1px;
  background: color-mix(in srgb, currentColor 30%, transparent);
}

.tagline-lines {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.9;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.ticket-body {
  padding: 26px 24px 28px;
  color: white;
}

.fidelidad-title {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.fidelidad-title strong { font-weight: 800; }

.fidelidad-sub {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.fidelidad-sub .dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--brand-color);
  display: inline-block;
}

.member-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--hairline);
}

.member-name { font-weight: 600; font-size: 14px; color: white; }

.member-code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--muted);
}

/* Sellos de tamaño fijo que se acomodan solos, en vez de 5 columnas fijas que
   los encogían a ~58px: a 72px el logo de dentro se distingue de verdad. Con
   flex-wrap la cantidad por fila la decide el ancho disponible y la última fila
   incompleta queda centrada, sirva el negocio 6 sellos o 20. */
.stamp-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 12px;
  margin: 6px 0 26px;
  /* Panel con fondo propio: sin tema es transparente y se ve el ticket, como
     hasta ahora. */
  background: var(--stamp-panel-bg, transparent);
  padding: var(--stamp-panel-padding, 0);
  border-radius: var(--stamp-panel-radius, 0);
}

.stamp-cell {
  width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.stamp-hole {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid var(--stamp-empty-ring, var(--brand-color));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.25s ease;
}

.stamp-hole.filled {
  background: var(--stamp-filled-bg, var(--brand-color));
  border-color: var(--stamp-filled-bg, var(--brand-color));
  /* `color` es lo que resuelve el currentColor del dibujo de dentro. */
  color: var(--stamp-filled-icon, inherit);
  box-shadow: 0 3px 10px color-mix(in srgb, var(--stamp-filled-bg, var(--brand-color)) 45%, transparent);
}

/* Dibujo dentro del sello lleno, para los negocios que usan un icono en vez
   del logo. La mitad del circulo, como en la maqueta. */
.stamp-hole > svg { width: 50%; height: 50%; display: block; }

.stamp-hole img { width: 88%; height: 88%; object-fit: cover; border-radius: 50%; }

/* Sello premio: fondo crema en vez del amarillo de marca — sobre el amarillo,
   el pan de la hamburguesa se confundía con el fondo. El anillo de marca lo
   sigue marcando como parte de la tarjeta. */
.stamp-hole.milestone {
  background: var(--stamp-milestone-pending-bg, rgba(251,247,239,0.14));
  border-color: var(--stamp-milestone-pending-ring, var(--brand-color));
  color: var(--stamp-milestone-pending-icon, inherit);
}
.stamp-hole.milestone.filled {
  background: var(--stamp-milestone-bg, #fbf7ef);
  /* Sin tema, el aro sigue siendo el de marca: es lo que marca el sello
     premio como parte de la tarjeta del negocio. */
  border-color: var(--stamp-milestone-ring, var(--brand-color));
  color: var(--stamp-milestone-icon, inherit);
  box-shadow: 0 3px 12px rgba(0,0,0,0.35);
}

.stamp-hole.milestone svg { width: 78%; height: 78%; display: block; }

/* Vacío: el premio se ve, atenuado, como una promesa de lo que falta. */
.stamp-hole.milestone:not(.filled) svg { opacity: 0.6; }

.stamp-number {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--stamp-number-color, var(--muted));
}

/* Nombre del premio bajo el sello que lo da. En el color de marca y no en gris:
   es lo único de la rejilla que el cliente tiene que llegar a leer. */
.stamp-reward {
  font-size: 9.5px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-align: center;
  text-transform: uppercase;
  color: var(--stamp-reward-color, var(--brand-color));
  margin-top: -2px;
}

@media (prefers-reduced-motion: no-preference) {
  .stamp-hole.filled { animation: stamp-pop 0.35s ease; }
}

@keyframes stamp-pop {
  0% { transform: scale(0.7); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.qr-block {
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 16px;
  padding: 14px;
  width: fit-content;
  margin: 4px auto 22px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

.qr-block img { display: block; }

/* El código va justo debajo del QR, como en la maqueta de referencia de Apple:
   es lo que el cliente dicta si el lector no llega a escanear. */
.qr-code-line {
  margin: -14px auto 20px;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.72);
}

.progress-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 22px;
}

.progress-count {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  font-size: 15px;
  color: white;
  flex-shrink: 0;
}

.progress-reward {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.wallet-btn-group { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* Espacio libre mínimo que pide Apple alrededor de la insignia: .1X, donde X
   es su altura (48px aquí). El padding lo pone el enlace, así que nada del
   layout de al lado puede acercarse más de esos 4.8px. */
.wallet-badge {
  display: inline-block;
  padding: 4.8px;
  transition: transform 0.15s ease;
}

/* Solo se fija la altura: el ancho lo decide la proporción del arte oficial,
   que no se puede deformar ni recortar. */
.wallet-badge img { display: block; height: 48px; width: auto; }

.wallet-badge:hover { transform: translateY(-1px); }
.wallet-badge:focus-visible { outline: 2px solid var(--brand-color); outline-offset: 2px; border-radius: 8px; }

/* Reserva para cuando el arte oficial de Apple/Google no está instalado: un
   enlace de texto, nunca una imitación del botón. */
.wallet-text-link {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  color: white;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px 2px;
}

.wallet-hint {
  margin: 4px 0 0;
  max-width: 30ch;
  text-align: center;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.wallet-pending {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  background: rgba(255,255,255,0.06);
  border: 1px dashed var(--hairline);
  border-radius: 12px;
  padding: 12px;
}

.ticket-footer {
  background: var(--brand-color);
  color: var(--header-text, white);
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.social-row { display: flex; align-items: center; gap: 8px; }

.social-icon {
  width: 26px; height: 26px; border-radius: 50%;
  background: color-mix(in srgb, currentColor 20%, transparent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.social-handle {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.footer-slogan {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.9;
}

.ticket.not-found .ticket-body { text-align: center; padding: 40px 30px; }
.ticket.not-found h1 { font-size: 20px; margin: 0 0 8px; color: white; }
.ticket.not-found p { color: var(--muted); margin: 0; font-size: 14px; }
