/* ═══════════════════════════════════════════════════════════════════════
   Highsupply · Ficha — Visor de imágenes (lightbox) · 2026-10-20

   Se carga SOLO en body#product (ver head.tpl), después de highsupply.css.
   Marca: fondo crema var(--hs-bg) (las fotos son PNG con alfa), botones
   circulares con borde var(--hs-border) como el corazón de favoritos,
   contador en JetBrains Mono, miniatura activa con borde magenta.

   Piezas:
     1. Botón «Ampliar» sobre la foto de la ficha (+ cursor zoom-in)
     2. Bloqueo de scroll mientras el visor está abierto
     3. Visor: raíz, barra, escenario, flechas, miniaturas
     4. Animación de entrada/salida (tokens de motion) + reduced-motion
     5. Responsive (≤767: foto a ancho completo, swipe, sin flechas)
   ═══════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────── 1. BOTÓN «AMPLIAR» EN LA FICHA
   highsupply.css oculta .expander (FA) con !important; el botón nuevo tiene
   su propia clase y gana con body#product .product-cover .hs-pdp-expand. */
body#product .product-cover .hs-pdp-expand {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 4;                       /* por encima de la slide (1) y de las flags (3) */
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: 1.5px solid var(--hs-border);
  border-radius: 50%;
  background: var(--hs-bg-alt);
  color: var(--hs-text-mute);
  line-height: 0;
  box-shadow: none;
  cursor: zoom-in;
  transition: border-color var(--hs-transition), color var(--hs-transition),
              background var(--hs-transition), transform var(--hs-transition);
}
body#product .product-cover .hs-pdp-expand svg { display: block; }
body#product .product-cover .hs-pdp-expand:hover {
  border-color: var(--hs-text);
  color: var(--hs-text);
}
body#product .product-cover .hs-pdp-expand:active { transform: scale(0.96); }
body#product .product-cover .hs-pdp-expand:focus-visible {
  outline: 2px solid var(--hs-accent);
  outline-offset: 2px;
}
/* La foto principal también abre el visor */
body#product #product-images-large .swiper-slide img[data-image-large-src] { cursor: zoom-in; }

@media (max-width: 767px) {
  /* el marco móvil lleva padding 20px: el botón pegado al mismo margen que la flag */
  body#product .product-cover .hs-pdp-expand { top: 14px; right: 14px; }
}

/* ─────────────────────────────────────── 2. BLOQUEO DE SCROLL
   Va en BODY, no en html: con html visible el overflow de body se propaga
   al viewport, que queda bloqueado CONSERVANDO el scroll. Si se pone
   overflow:hidden en html, body (que lleva overflow-x:hidden de guarda)
   pasa a ser el scroller y el viewport pierde el scrollY (medido por CDP:
   120 → 0). El JS además guarda/restaura scrollY y compensa el ancho de la
   barra de scroll con --hs-lb-sbw para que la página de detrás no salte. */
html.hs-lightbox-open body {
  overflow: hidden !important;
  padding-right: var(--hs-lb-sbw, 0px);
}

/* ─────────────────────────────────────── 3. VISOR
   El JS mueve #hs-lightbox a <body> al iniciar (evita que un transform o
   un overflow de #main lo recorte). hidden siempre gana. */
.hs-lightbox[hidden] { display: none !important; }
.hs-lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;                    /* header en búsqueda 2001, drawer 1100, barra B2B 1100, toast 1200 */
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--hs-bg);
  color: var(--hs-text);
  font-family: var(--hs-font-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: contain;
  box-sizing: border-box;
}
.hs-lightbox *,
.hs-lightbox *::before,
.hs-lightbox *::after { box-sizing: border-box; }
/* El reset `body span` del tema pisa la fuente en spans */
.hs-lightbox span { font-family: inherit !important; }
.hs-lightbox button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.hs-lightbox img,
.hs-lightbox svg { display: block; }
.hs-lightbox:focus { outline: none; }

/* Barra superior: contador + nombre a la izquierda, cerrar a la derecha */
.hs-lightbox__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 0 var(--hs-gutter);
}
.hs-lightbox__meta {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
}
/* .hs-lightbox .hs-lightbox__counter (0,2,0): el contador ES un span y la regla
   `.hs-lightbox span { font-family: inherit !important }` (0,1,1) lo pisaba. */
.hs-lightbox .hs-lightbox__counter {
  flex: none;
  font-family: var(--hs-font-mono) !important;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--hs-text);
  white-space: nowrap;
}
.hs-lightbox__counter span { font-family: inherit !important; }
.hs-lightbox__sep { margin: 0 4px; color: var(--hs-text-faint); }
.hs-lightbox__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  color: var(--hs-text-mute);
}
/* Si solo hay una foto no hay nada que contar */
.hs-lightbox--single .hs-lightbox__counter { display: none; }

/* Botones circulares (cerrar / flechas): mismo lenguaje que el corazón de favoritos */
.hs-lightbox__close,
.hs-lightbox__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: 1.5px solid var(--hs-border);
  border-radius: 50%;
  background: var(--hs-bg-alt);
  color: var(--hs-text);
  line-height: 0;
  box-shadow: none;
  transition: border-color var(--hs-transition), color var(--hs-transition),
              background var(--hs-transition), transform var(--hs-transition);
}
.hs-lightbox__close:hover,
.hs-lightbox__nav:hover {
  background: var(--hs-text);
  border-color: var(--hs-text);
  color: var(--hs-bg);
}
.hs-lightbox__close:active,
.hs-lightbox__nav:active { transform: scale(0.96); }
.hs-lightbox__close:focus-visible,
.hs-lightbox__nav:focus-visible,
.hs-lightbox__thumb:focus-visible {
  outline: 2px solid var(--hs-accent);
  outline-offset: 2px;
}

/* Escenario: flecha · foto · flecha. El fondo cierra (clic fuera). */
.hs-lightbox__stage {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 72px;
  align-items: center;
  min-height: 0;
  padding: 0 var(--hs-gutter);
  cursor: zoom-out;
}
.hs-lightbox__nav { justify-self: center; cursor: pointer; }
.hs-lightbox--single .hs-lightbox__nav { visibility: hidden; }
.hs-lightbox__figure {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 8px 0;
}
.hs-lightbox__img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: default;
  /* No se bloquea touch-action: el pinch-zoom nativo del navegador queda disponible */
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity var(--hs-dur-fast) ease-out;
}
.hs-lightbox__figure.is-loading .hs-lightbox__img { opacity: 0.35; }

/* Raíl de miniaturas: cuadradas, contain, activa con borde magenta */
.hs-lightbox__thumbs {
  display: flex;
  /* centrado con márgenes automáticos (no con justify-content): si el raíl
     desborda, flexbox centraría recortando por los dos lados y las primeras
     miniaturas quedarían fuera del alcance del scroll */
  justify-content: flex-start;
  gap: 8px;
  min-height: 96px;
  padding: 12px var(--hs-gutter) 20px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}
.hs-lightbox__thumbs::-webkit-scrollbar { display: none; }
.hs-lightbox__thumb:first-child { margin-left: auto; }
.hs-lightbox__thumb:last-child { margin-right: auto; }
.hs-lightbox--single .hs-lightbox__thumbs { visibility: hidden; }
.hs-lightbox__thumb {
  flex: none;
  width: 56px;
  height: 56px;
  padding: 4px;
  margin: 0;
  border: 1.5px solid var(--hs-border);
  border-radius: var(--hs-radius-sm);
  background: var(--hs-bg-alt);
  opacity: 0.75;
  transition: border-color var(--hs-transition), opacity var(--hs-transition);
}
.hs-lightbox__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.hs-lightbox__thumb:hover { border-color: var(--hs-text-mute); opacity: 1; }
.hs-lightbox__thumb.is-active {
  border-color: var(--hs-accent);
  opacity: 1;
  cursor: default;
}

/* ─────────────────────────────────────── 4. MOTION
   Entrada: fundido + ligera escala de la foto (ease-out fuerte, 250ms).
   Salida más corta (150ms). El JS añade .is-open tras quitar hidden y
   .is-closing antes de volver a ocultar. */
.hs-lightbox {
  opacity: 0;
  transition: opacity var(--hs-dur-base) var(--hs-ease-out);
}
.hs-lightbox .hs-lightbox__figure {
  transform: scale(0.97);
  transition: transform var(--hs-dur-base) var(--hs-ease-out);
}
.hs-lightbox.is-open { opacity: 1; }
.hs-lightbox.is-open .hs-lightbox__figure { transform: none; }
.hs-lightbox.is-closing {
  opacity: 0;
  transition: opacity var(--hs-dur-fast) ease-out;
  pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
  .hs-lightbox { transition: opacity 120ms ease-out; }
  .hs-lightbox .hs-lightbox__figure,
  .hs-lightbox.is-open .hs-lightbox__figure { transform: none; transition: none; }
  .hs-lightbox__img { transition: none; }
}

/* ─────────────────────────────────────── 5. RESPONSIVE */
@media (max-width: 991px) {
  .hs-lightbox__stage { grid-template-columns: 56px minmax(0, 1fr) 56px; }
}
@media (max-width: 767px) {
  .hs-lightbox__bar {
    min-height: 60px;
    padding: 0 var(--hs-gutter-mobile);
  }
  .hs-lightbox__name { display: none; }  /* en móvil el nombre está en la ficha; aquí sobra */
  /* Foto a ancho completo; se pasa con swipe (JS) o desde las miniaturas */
  .hs-lightbox__stage {
    grid-template-columns: minmax(0, 1fr);
    padding: 0;
  }
  .hs-lightbox__nav { display: none; }
  .hs-lightbox__figure { padding: 0; }
  .hs-lightbox__img {
    width: 100%;
    max-height: 100%;
  }
  .hs-lightbox__thumbs {
    justify-content: flex-start;
    gap: 6px;
    min-height: 84px;
    padding: 12px var(--hs-gutter-mobile) 16px;
    scroll-snap-type: x proximity;
    scroll-padding-left: var(--hs-gutter-mobile);
    scroll-padding-right: var(--hs-gutter-mobile);
  }
  .hs-lightbox__thumb {
    width: 52px;
    height: 52px;
    scroll-snap-align: center;
  }
}
