/* ==========================================================================
   ticket.css — Talón espectador Cinemark (impresora térmica ESC/POS)
   Componente .ticket a tamaño real (mm). Ver DESIGN.md para la especificación.

   Fuentes: ThermalA / ThermalB (fonts/thermal-a.woff2, fonts/thermal-b.woff2),
   bitmaps de la impresora dibujados punto por punto (tools/glyphs_*.txt) y
   compilados con tools/build_fonts.py. Cada punto térmico es un cuadrado exacto
   en la fuente: el texto imprime nítido, en vectores, sin curvas.
   Las @font-face están acá abajo, con rutas relativas a este archivo.

   Escala: 180 dpi -> 1 punto = 25.4 / 180 = 0.14111 mm.
     ThermalA: 1 em = 24 puntos (celda 12 x 24)  -> font-size 24 x 0.14111 = 3.3867 mm
     ThermalB: 1 em = 17 puntos (celda  9 x 17)  -> font-size 17 x 0.14111 = 2.3989 mm
   Avance: A 12 puntos (0.5 em) = 1.6933 mm · B 9 puntos = 1.2700 mm.

   Ampliación ESC/POS (GS !): enteros de alto (--sy) y ancho (--sx).
   .t-x: font-size = base x --sy  y luego  transform: scaleX(--sx / --sy).
   Cada punto pasa a ser un bloque exacto de sx x sy puntos (p.ej. SALA: 3 x 2).
   El alto de línea es real (el layout y la envoltura funcionan sin JS) y el
   paso horizontal sigue la grilla de columnas del ticket.
   ========================================================================== */

@font-face {
  font-family: "ThermalA";
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url("../fonts/thermal-a.woff2") format("woff2"),
       url("../fonts/thermal-a.ttf") format("truetype");
}
@font-face {
  /* peso 700: trazo de 3 x 3 puntos, solo para la franja SALA (ver DESIGN.md §2) */
  font-family: "ThermalA";
  font-style: normal;
  font-weight: 700;
  font-display: block;
  src: url("../fonts/thermal-a-bold.woff2") format("woff2"),
       url("../fonts/thermal-a-bold.ttf") format("truetype");
}
@font-face {
  font-family: "ThermalB";
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url("../fonts/thermal-b.woff2") format("woff2"),
       url("../fonts/thermal-b.ttf") format("truetype");
}

.ticket {
  /* ---- Tamaño físico ---- */
  --ticket-w: 49mm;
  --ticket-h: 123mm;            /* oficial: 120–125 mm */

  /* ---- Tinta / papel ---- */
  --ink: #000;
  --paper: #fff;
  --perf-color: #9a9a9a;

  /* ---- Grilla de puntos (180 dpi) ---- */
  --dot: 0.141111mm;            /* 25.4 mm / 180 */
  --font-a: "ThermalA", monospace;
  --font-b: "ThermalB", "ThermalA", monospace;
  --adv: 0.5;                   /* avance de ThermalA en em (12 / 24) */
  --fs-a: calc(24 * var(--dot));   /* 3.3867 mm: 1ch = 12 puntos = 1.693 mm, versal 19 puntos = 2.68 mm */
  --fs-b: calc(17 * var(--dot));   /* 2.3989 mm: 1ch =  9 puntos = 1.270 mm, versal 14 puntos = 1.98 mm */
  --cols: 24;                   /* columnas Font A por línea (40.6 mm) */
  --line: 4.233mm;              /* interlineado ESC/POS por defecto: 30 puntos = 1/6" */

  /* ---- Multiplicadores ESC/POS (enteros: alto --sy, ancho --sx) ---- */
  --dh: 2;                      /* doble alto: título, fecha, FILA/BUT, promo */
  --row-dh: 6.8mm;              /* fila de doble alto (48 puntos = 6.77 mm) */
  --sala-sx: 3;  --sala-sy: 2;  /* SALA: triple ancho, doble alto */
  --seat-sy: 2;
  --promo-sy: 2;
  --row-promo: 7.4mm;

  /* ---- Franjas negras ---- */
  --bar-h: 7mm;                 /* SALA y FILA/BUT */
  --step-w: 1.65mm;             /* "escalón" bajo FILA/BUT: ≈ 1 columna */
  --step-h: 3.1mm;

  /* ---- Márgenes internos ---- */
  --pad-top: 9.6mm;
  --pad-x: 3.8mm;               /* margen izquierdo parte superior */
  --pad-x-stub: 4.4mm;          /* margen izquierdo del talón (BOC...) */
  --perf-y: 56.5mm;             /* posición del perforado desde el borde superior */
  --stub-pad-top: 1.9mm;

  box-sizing: border-box;
  position: relative;
  display: block;
  width: var(--ticket-w);
  height: var(--ticket-h);
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-a);
  font-size: var(--fs-a);
  font-weight: 400;
  font-style: normal;
  font-synthesis: none;         /* nunca negrita/itálica falsa: rompería los puntos */
  line-height: var(--line);
  letter-spacing: 0;
  word-spacing: 0;
  font-variant-ligatures: none;
  font-kerning: none;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  -webkit-text-stroke: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.ticket *, .ticket *::before, .ticket *::after { box-sizing: border-box; }
.ticket p { margin: 0; }

/* ---------- Secciones ---------- */
.ticket__head {
  /* el perforado cae en --perf-y; si el título ocupa 2 líneas, el bloque
     crece y empuja perforado y talón hacia abajo (como en la impresora) */
  min-height: var(--perf-y);
  padding: var(--pad-top) 0 0.9mm var(--pad-x);
}
.ticket__stub {
  padding: var(--stub-pad-top) 0 0 var(--pad-x-stub);
}

/* Línea simple (Font A o B según sección) */
.t-line {
  display: block;
  height: var(--line);
  line-height: var(--line);
  white-space: pre;
  overflow: visible;
}

/* Texto ampliado tipo ESC/POS (ver encabezado). No anidar .t-x */
.t-x {
  --sx: 1; --sy: 1;
  display: block;
  font-size: calc(var(--fs) * var(--sy));
  transform: scaleX(calc(var(--sx) / var(--sy)));
  transform-origin: 0 0;
  white-space: pre;
}
.ticket__head { --fs: var(--fs-a); }
.ticket__stub { --fs: var(--fs-a); } /* el promo usa Font A */

/* ---------- SALA: franja negra a todo el ancho, triple ancho x doble alto ---------- */
.ticket__sala {
  display: flex; justify-content: center; align-items: flex-start;
  width: calc(var(--cols) * var(--fs-a) * var(--adv));   /* 24 col = 288 puntos = 40.6 mm */
  height: var(--bar-h);
  margin-top: 0.35mm;
  background: var(--ink);
  color: var(--paper);
  overflow: hidden;
}
.ticket__sala .t-x {
  --sx: var(--sala-sx); --sy: var(--sala-sy);
  font-weight: 700;                        /* ThermalA Bold: letras gruesas como en la foto */
  line-height: var(--bar-h);
  margin-top: calc(3 * var(--dot));        /* centra la versal (21 filas x2) en la franja */
  transform-origin: 50% 0;
  display: inline-block;
}

/* ---------- Título + versión: doble alto, máx 2 líneas de 24 col ---------- */
.ticket__title {
  --sy: var(--dh);
  width: calc(var(--cols) * 1ch);          /* 24 col en la fuente agrandada */
  max-height: calc(2 * var(--row-dh));     /* truncado duro a 2 líneas */
  line-height: var(--row-dh);
  white-space: normal;
  overflow-wrap: anywhere;
  overflow: hidden;
  text-transform: uppercase;
}

/* ---------- Fecha y hora de la función ---------- */
.ticket__datetime {
  --sy: var(--dh);
  line-height: var(--row-dh);
  height: var(--row-dh);
}

/* ---------- FILA / BUT: franja negra ajustada al texto + escalón ---------- */
.ticket__seat { height: var(--bar-h); }
.ticket__seat .t-x {
  --sy: var(--seat-sy);
  display: inline-block;
  padding: 0 1ch;                          /* 1 columna de aire a cada lado */
  line-height: var(--bar-h);
  height: var(--bar-h);
  background: var(--ink);
  color: var(--paper);
}
.ticket__step {
  width: var(--step-w);
  height: var(--step-h);
  background: var(--ink);
}

/* ---------- Precio - medio de pago ---------- */
.ticket__price { margin-top: 0.45mm; }

/* ---------- Perforado ---------- */
.ticket__perf {
  height: 0;
  margin-top: -0.1mm;
  border-top: 0.2mm dashed var(--perf-color);
}
.ticket--no-perf .ticket__perf { display: none; }

/* ---------- Talón (Font B) ---------- */
.ticket__stub .t-line {
  font-family: var(--font-b);
  font-size: var(--fs-b);
}
.ticket__promo {
  --sy: var(--promo-sy);
  font-family: var(--font-a);
  height: var(--row-promo);
  line-height: var(--row-promo);
  text-transform: none;
}

/* ==========================================================================
   Efecto impresión térmica (opcional): .ticket--thermal
   - negro no puro y un sangrado mínimo del punto (text-shadow de 0.03 mm,
     menor que un punto: los bloques siguen leyéndose cuadrados)
   - motas blancas (dropout de puntos del cabezal) sobre las zonas impresas
   - desvanecido irregular (bandas y manchas más claras)
   Todo son imágenes de fondo/overlay: el texto sigue siendo vectorial.
   ========================================================================== */
.ticket--thermal {
  --ink: #1d1c1f;
  --perf-color: #a7a7a7;
}
.ticket--thermal .ticket__head,
.ticket--thermal .ticket__stub {
  text-shadow: 0 0 0.03mm rgba(29, 28, 31, .5);
}
.ticket--thermal .ticket__sala,
.ticket--thermal .ticket__seat .t-x { text-shadow: none; }

.ticket--thermal::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 2;
  background-image:
    /* motas finas */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.15' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 7 0 0 0 -4.15'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    /* motas más gruesas y espaciadas */
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.45' numOctaves='1' seed='19' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 9 0 0 0 -5.6'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E"),
    /* desvanecido irregular: manchas y una banda de cabezal gastado */
    radial-gradient(ellipse 60% 22% at 78% 30%, rgba(255,255,255,.28), transparent 70%),
    radial-gradient(ellipse 45% 18% at 20% 72%, rgba(255,255,255,.22), transparent 70%),
    linear-gradient(90deg, transparent 0 62%, rgba(255,255,255,.12) 70%, transparent 80%);
  background-size: 9mm 9mm, 14mm 14mm, 100% 100%, 100% 100%, 100% 100%;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ---------- Solo pantalla: contorno sutil para ver el recorte ---------- */
@media screen {
  .ticket { box-shadow: 0 0 0 0.2mm rgba(0,0,0,.08), 0 1mm 4mm rgba(0,0,0,.12); }
}
@media print {
  .ticket { box-shadow: none; }
}
