:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #14181f;
  --ink-2: #4b5563;
  --ink-3: #8a919c;
  --line: #e6e6e1;
  --accent: #14181f;
  --accent-2: #22c55e;
  --danger: #dc2626;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 31, 0.04), 0 8px 24px rgba(20, 24, 31, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; letter-spacing: -0.02em; }
h1 { font-size: 34px; font-weight: 700; }
h2 { font-size: 20px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 12px; color: var(--ink-2); }
small { color: var(--ink-3); }

.muted { color: var(--ink-3); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.wrap-narrow { max-width: 420px; margin: 0 auto; padding: 0 20px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(247, 247, 245, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 58px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; text-decoration: none; }
.brand-dot {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, #14181f, #3d4653);
  display: grid; place-items: center;
  color: #fff; font-size: 12px;
}
.spacer { flex: 1; }

.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 4px; background: #ecece7; border-radius: 11px; }
.tab {
  border: 0; background: transparent; padding: 7px 13px; border-radius: 8px;
  font: inherit; font-size: 13.5px; color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.tab.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); font-weight: 600; }

/* ---------- tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: 14px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
/* En una rejilla la separación la da el `gap`: con el margen de `.card + .card`, las columnas no empezarían a la misma altura. */
.grid > .card + .card { margin-top: 0; }

.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi-val { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.kpi-lab { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* ---------- formularios ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 5px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--surface); border: 1px solid #d7d7d0; border-radius: 10px;
  padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--ink); box-shadow: 0 0 0 3px rgba(20, 24, 31, 0.08);
}
textarea { resize: vertical; min-height: 84px; }
.field { margin-bottom: 13px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 600; font-size: 14.5px;
  padding: 11px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: #fff; cursor: pointer; text-decoration: none;
  transition: transform .06s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink); border-color: #d7d7d0; }
.btn-soft { background: #ecece7; color: var(--ink); }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-danger { background: transparent; color: var(--danger); border-color: #f0caca; }

/* ---------- avisos ---------- */
.note {
  display: flex; gap: 9px; align-items: flex-start;
  font-size: 13px; padding: 10px 12px; border-radius: 10px;
  background: #f4f6f8; color: var(--ink-2); border: 1px solid #e3e7ec;
}
.note-warn { background: #fff8ed; border-color: #f5e2c3; color: #7c4a03; }
.note-ok { background: #f0fdf4; border-color: #cdebd6; color: #14532d; }
.note-err { background: #fef2f2; border-color: #f6d3d3; color: #7f1d1d; }

/* ---------- tabla ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
td { padding: 11px 10px; border-bottom: 1px solid #f0f0ec; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; background: #eef2f6; color: #334155;
}
.badge-ok { background: #e8f7ee; color: #166534; }
.badge-warn { background: #fdf3e2; color: #92400e; }
.badge-off { background: #f3f4f6; color: #6b7280; }

/* ---------- tarjeta ---------- */
/*
 * Cada elemento se coloca sobre la tarjeta con medidas en % de su ancho: `--u` es ese 1 %. Con unidades de contenedor,
 * la tarjeta se ve igual en un móvil que en el panel. Lo que no cabe a lo ancho se ajusta dentro de su hueco (`--hueco`).
 */
.pass {
  --u: 1cqw;
  position: relative;
  display: block;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 100 / var(--alto, 63);
  container-type: inline-size;
  color: #fff;
  overflow: hidden;
  overflow: clip;
  box-shadow: 0 12px 30px rgba(20, 24, 31, .22);
}
.pass-el {
  position: absolute;
  left: calc(var(--x) * var(--u));
  top: calc(var(--y) * var(--u));
  width: max-content;
  max-width: calc(var(--hueco) * var(--u));
  font-size: calc(var(--tam) * var(--u));
  line-height: 1.15;
  overflow-wrap: anywhere;
  color: var(--c);
}
.pass-el[data-ancla="c"] { transform: translateX(-50%); text-align: center; }
.pass-el[data-ancla="d"] { transform: translateX(-100%); text-align: right; }
.pass-nombre { font-weight: 650; }
.pass-codigo { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pass-num { display: block; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.pass-lab { display: block; margin-top: .4em; font-size: .36em; text-transform: uppercase; letter-spacing: .08em; opacity: .8; }

/* El alto del logo sale del tamaño elegido y su ancho, de su forma. Si no cabe a lo ancho, se reduce entero: nunca se recorta. */
.pass-logo.sin-imagen {
  display: grid; place-items: center;
  width: calc(var(--tam) * var(--u)); height: calc(var(--tam) * var(--u));
  font-size: calc(var(--tam) * .55 * var(--u)); line-height: 1;
  border-radius: calc(var(--tam) * .25 * var(--u));
  background: rgba(255,255,255,.18);
}
.pass-logo img {
  display: block;
  width: min(calc(var(--tam) * var(--proporcion, 1) * var(--u)), calc(var(--hueco) * var(--u)));
  height: auto;
  border-radius: calc(var(--tam) * .12 * var(--u));
}
.pass-logo.con-placa {
  padding: calc(var(--tam) * .1 * var(--u)) calc(var(--tam) * .16 * var(--u));
  border-radius: calc(var(--tam) * .18 * var(--u));
  background: var(--placa);
}
.pass-logo.con-placa img {
  width: min(calc(var(--tam) * .8 * var(--proporcion, 1) * var(--u)), calc((var(--hueco) - var(--tam) * .32) * var(--u)));
}
.marca-logo { height: 32px; width: auto; max-width: min(100%, 300px); min-width: 0; padding: 3px 7px; box-sizing: content-box; border-radius: 8px; object-fit: contain; vertical-align: middle; }
.marca-logo.sin-fondo { padding: 0; background: transparent; }

.pass-sellos {
  display: grid;
  grid-template-columns: repeat(var(--columnas), calc(var(--sello) * var(--u)));
  gap: calc(var(--sep) * var(--u));
  max-width: none;
  font-size: calc(var(--sello) * .46 * var(--u));
  line-height: 1;
}
.sello {
  aspect-ratio: 1;
  border-radius: var(--redondez, 50%);
  border: calc(.36 * var(--u)) solid rgba(255,255,255,.5);
  border-color: color-mix(in srgb, var(--pass-sello, #fff) 50%, transparent);
  display: grid; place-items: center;
}
.sello.on { background: var(--pass-sello, rgba(255,255,255,.95)); color: var(--pass-sello-texto, #14181f); border-color: transparent; font-weight: 700; }

/* Sellos dibujados: una plantilla es una máscara blanca que se tiñe con el color del sello; un dibujo propio se pinta tal cual. */
.pass-sellos .sello.con-dibujo { border: 0; border-radius: 0; background: var(--dibujo) center / contain no-repeat; }
.pass-sellos .sello.con-dibujo.tenido { background: var(--pass-sello, #fff); -webkit-mask: var(--dibujo) center / contain no-repeat; mask: var(--dibujo) center / contain no-repeat; }
.pass-sellos .sello.con-dibujo.tenue { opacity: .4; }

/* ---------- diseñador de la tarjeta ---------- */
.disenador { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.disenador-vista { position: sticky; top: 72px; z-index: 5; }
.disenador-vista .pass { margin: 0 auto; }
.disenador-controles > .card:first-child { margin-top: 0; }
.pass.editando .pass-el { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.pass.editando .pass-el:hover { outline: 1px dashed rgba(255,255,255,.8); outline-offset: 2px; }
.pass.editando .pass-el.elegido { outline: 2px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 2px rgba(0,0,0,.55); }
.pass.editando .pass-el.moviendo { cursor: grabbing; }
.pass-guia { position: absolute; background: #ff2d78; pointer-events: none; z-index: 2; }
.pass-guia-v { top: 0; bottom: 0; width: 1px; left: calc(var(--g) * var(--u)); }
.pass-guia-h { left: 0; right: 0; height: 1px; top: calc(var(--g) * var(--u)); }
.control { margin-bottom: 12px; }
.control label { display: flex; justify-content: space-between; gap: 10px; }
.control output { font-weight: 400; color: var(--ink-3); font-variant-numeric: tabular-nums; }
input[type="range"] { padding: 0; border: 0; height: 24px; background: transparent; accent-color: var(--ink); box-shadow: none; }
input[type="color"] { height: 42px; padding: 4px; }
.piezas { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.pieza-boton {
  font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid #d7d7d0; background: transparent; color: var(--ink);
}
.pieza-boton.oculta { color: var(--ink-3); border-style: dashed; }
.pieza-boton.on { background: var(--ink); color: #fff; border-color: var(--ink); border-style: solid; }
.opcion { display: flex; gap: 9px; align-items: center; font-weight: 500; font-size: 13.5px; margin-bottom: 12px; cursor: pointer; }
.opcion input { width: 16px; height: 16px; flex: 0 0 16px; }

/* La tarjeta del resumen, en el centro del hueco que deja la caja de al lado. */
.tarjeta-centrada { display: flex; flex-direction: column; }
.tarjeta-centrada .pass { margin: auto; }

/* ---------- edición de un cliente ---------- */
.cliente-edicion td { background: var(--bg); }
.cliente-edicion .row { align-items: flex-end; }
.cliente-edicion .field { flex: 1 1 150px; }

/* ---------- vista previa de los wallets ---------- */
#vistaWallets { scroll-margin-top: 70px; }
.wallets { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; align-items: start; }
.opciones-logo { border: 0; padding: 0; margin: 0 0 4px; min-width: 0; }
.opciones-logo legend { padding: 0; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.wallet-nombre { font-size: 14px; font-weight: 650; margin: 0 0 8px; }
.wallet-pase { max-width: 340px; border-radius: 22px; overflow: hidden; padding: 16px; box-shadow: var(--shadow); }
.wallet-cab { display: flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 600; min-width: 0; }
.wallet-logo-g { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; }
.wallet-logo-g img { display: block; object-fit: contain; }
.wallet-logo-ancho { display: block; height: 40px; max-width: 100%; object-fit: contain; object-position: left center; }
.wallet-logo-a { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 6px; }
.wallet-prog { font-size: 21px; font-weight: 500; line-height: 1.2; margin: 12px 0 14px; }
.wallet-hero { display: block; width: calc(100% + 32px); margin: 0 -16px 14px; aspect-ratio: 1032 / 812; object-fit: cover; }
.wallet-fila { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.wallet-dato { min-width: 0; }
.wallet-dato:last-child:not(:first-child) { text-align: right; }
.wallet-dato small { display: block; font-size: 11px; color: inherit; opacity: .8; }
.wallet-dato span { display: block; font-size: 15px; overflow-wrap: anywhere; }
.wallet-franja { margin: 12px -16px; padding: 14px 16px; }
.wallet-franja small { display: block; font-size: 11px; }
.wallet-franja span { display: block; font-size: 30px; font-weight: 300; line-height: 1.1; }
.wallet-qr { background: #fff; color: #14181f; border-radius: 12px; padding: 12px; margin-top: 4px; text-align: center; font-size: 12px; }
.wallet-qr img { display: block; width: 130px; height: 130px; margin: 0 auto 6px; }
.wallet-detalles { max-width: 340px; list-style: none; padding: 0; margin: 12px 0 0; font-size: 12.5px; color: var(--ink-2); }
.wallet-detalles li { padding: 6px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.wallet-detalles strong { display: block; font-size: 11px; color: var(--ink-3); font-weight: 600; }
.cabecera-muestra { background: var(--bg); border-radius: 10px; padding: 14px; text-align: center; margin-bottom: 14px; overflow: hidden; }
.cabecera-muestra .brand { justify-content: center; }

/* ---------- landing ---------- */
.hero { padding: 56px 0 28px; }
.hero h1 { font-size: clamp(30px, 5vw, 44px); max-width: 15ch; }
.hero p { font-size: 17px; max-width: 52ch; }
.eyebrow {
  display: inline-block; font-size: 12px; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px;
}
.feature { display: flex; gap: 10px; align-items: flex-start; }
.feature-ico {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 9px; background: #ecece7;
  display: grid; place-items: center; font-size: 15px;
}

/* ---------- escáner ---------- */
.scan-stage {
  position: relative; width: 100%; aspect-ratio: 4 / 3; background: #0b0e13;
  border-radius: var(--radius); overflow: hidden;
}
.scan-stage video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 18% 14%; border: 2px solid rgba(255,255,255,.85);
  border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
}
/* El resultado va pegado a la cámara y dura hasta el siguiente escaneo: cada estado tiene su color e icono. */
.scan-result { margin-top: 12px; }
.scan-result.ok, .scan-result.espera, .scan-result.err { padding: 16px; border-radius: var(--radius); border: 3px solid; }
.scan-result.ok { background: #16a34a; border-color: #166534; color: #fff; }
.scan-result.espera { background: #fff8ed; border-color: #d99a2b; color: #7c4a03; border-style: dashed; }
.scan-result.err { background: #fef2f2; border-color: #dc2626; color: #7f1d1d; }
.scan-estado-cab { display: flex; align-items: center; gap: 14px; }
.scan-estado-icono {
  flex: 0 0 auto; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font-size: 30px; font-weight: 800; background: rgba(255,255,255,.95);
}
.scan-result.ok .scan-estado-icono { color: #16a34a; }
.scan-result.espera .scan-estado-icono { color: #b7791f; background: #fde9bd; }
.scan-result.err .scan-estado-icono { color: #dc2626; background: #fbd5d5; }
.scan-estado-titulo { font-size: 21px; font-weight: 800; line-height: 1.2; }
.scan-estado-sub { font-size: 15px; margin-top: 2px; opacity: .95; }
.scan-estado-detalle { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; margin-top: 10px; }
.scan-result.ok .badge-ok { background: #fff; color: #166534; }

/* ---------- utilidades ---------- */
.hide { display: none !important; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.mt-2 { margin-top: 10px; } .mt-3 { margin-top: 16px; } .mt-4 { margin-top: 24px; }
.flex { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.right { text-align: right; }
.foot { padding: 28px 0 40px; font-size: 12.5px; color: var(--ink-3); }

@media (max-width: 640px) {
  h1 { font-size: 27px; }
  .hero { padding: 30px 0 18px; }
  .card { padding: 15px; }
  .hide-sm { display: none !important; }
  .pass { max-width: 100%; }
}

/* En pantallas estrechas la tarjeta se queda arriba mientras se mueven los sliders. */
@media (max-width: 820px) {
  .disenador { grid-template-columns: minmax(0, 1fr); }
  .disenador-vista { top: 58px; background: var(--bg); padding: 8px 0; }
  .disenador-ayuda { display: none; }
}

/* --- premio conseguido (escáner) --- */
.premio-flash {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #7c2d12;
  font-weight: 700;
  font-size: 13.5px;
  animation: pulsePremio 1.1s ease-in-out infinite;
}
@keyframes pulsePremio {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.02); }
}

/* ---------- dibujo del sello en el panel ---------- */
.sello-plantillas { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-bottom: 6px; }
.sello-opcion { display: grid; justify-items: center; gap: 4px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; font-size: .78rem; cursor: pointer; }
.sello-opcion[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.sello-miniatura { width: 38px; height: 38px; background: var(--accent); -webkit-mask: var(--dibujo) center / contain no-repeat; mask: var(--dibujo) center / contain no-repeat; }
.sello-miniatura.sin-mascara { background: var(--dibujo) center / contain no-repeat; -webkit-mask: none; mask: none; display: grid; place-items: center; font-size: 1.4rem; }
.sello-ranuras { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sello-ranura { display: grid; gap: 4px; font-size: .8rem; }
.sello-ranura img { width: 48px; height: 48px; object-fit: contain; background: repeating-conic-gradient(#e5e8ec 0 25%, #fff 0 50%) 0 0 / 12px 12px; border-radius: 6px; }
.wallet-franja.con-cartilla { aspect-ratio: 375 / 123; display: flex; flex-direction: column; justify-content: flex-end; }
