/* === design-system/hero-gallery.css === */
/* ============================================================================
   Hero de subcategoría + galería inmersiva (Hero Gallery)
   Figma CANTOVI · UI › Hero 52746:27614 (Step Default / 2 / 3 · Desktop y Mobile)
   Card 52765:29816 (Desktop 281×407 · Mobile 213×301 · hover: zoom + botón +).

   Contrato de marcado (el que ya generan las 20 plantillas de subcategoría y
   single-producto.php — no hay que tocarlas):
     <section class="subcategory-hero"> breadcrumb + h1.subcategory-title + p.subcategory-lead
     <section class="media-mosaic"> <figure class="media-tile"><img></figure> …
   Sin JS, la galería ya se ve como carrusel horizontal (mismo layout que con JS,
   sin saltos). hero-gallery.js añade .hero-gallery, el track, los controles y
   el visor a pantalla completa con transición FLIP (shared element).
   Los heroes de familia (.hero--family) y del resto de páginas no se tocan.
   ========================================================================== */

.subcategory-page {
  --hg-bg: var(--bg-pastel, #f3f0ea);
  --hg-fg: var(--fg-default, #1b2124);
  --hg-text: #2e2e2e;
  --hg-card-bg: #adb1b6;                 /* Background/Static/Dim4 */
  --hg-max: 1184px;                      /* = .subcategory-container */
  --hg-gutter: clamp(20px, 4vw, 32px);
  --hg-inset: calc(max(0px, (100% - var(--hg-max)) / 2) + var(--hg-gutter));
  --hg-end-pad: 24.4%;                   /* Figma: la tira de cards acaba en 1025/1355 → aire a la derecha */
  --hg-card-w: 281px;
  --hg-card-h: 407px;
  --hg-gap: 28px;
  --hg-pad-top: 36px;                    /* + 32 del hero = 68 (descripción → cards) */
  --hg-nav-gap: 24px;                    /* cards → paginación */
  --hg-nav-h: 40px;
  --hg-pad-bottom: 24px;
  --hg-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---- Cabecera del hero (Figma 52782:35272) -------------------------------
   breadcrumb → H1 → descripción, gap 24 (mobile 16). El H1 lo controla
   page-hero-title.css (48/56 · 28/36). */
.subcategory-page .subcategory-hero {
  background: var(--hg-bg);
  padding: 48px 0 32px;
}
.subcategory-page .subcategory-hero .subcategory-container { gap: 24px; transition: opacity .5s var(--hg-ease); }
.subcategory-page .subcategory-hero .subcategory-lead {
  max-width: 640px;
  margin: 0;
  font-family: var(--font-family-base);
  font-size: var(--font-size-18, 18px);
  line-height: 24px;
  font-weight: var(--font-weight-medium, 500);
  color: var(--hg-text);
}

/* ---- Sección galería = parte inferior del hero ----------------------------
   La propia sección es el track horizontal a sangre: 1.ª card alineada con
   breadcrumb/H1 y scroll hasta los bordes. Sin JS reserva también el hueco de
   los controles; con JS ese hueco lo ocupa .hero-gallery__foot (misma altura). */
.subcategory-hero + .media-mosaic {
  position: relative;
  display: flex;
  flex-direction: row-reverse;           /* 1.ª card en la posición focal; las demás salen por la izquierda */
  justify-content: flex-start;
  align-items: stretch;
  gap: var(--hg-gap);
  max-width: none;
  margin: 0;
  /* izq.: hueco suficiente para que también la última card llegue a la posición focal */
  padding: var(--hg-pad-top) var(--hg-end-pad) calc(var(--hg-pad-bottom) + var(--hg-nav-gap) + var(--hg-nav-h)) max(var(--hg-inset), calc(100% - var(--hg-end-pad) - var(--hg-card-w)));
  background: var(--hg-bg);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--hg-inset) var(--hg-end-pad);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.subcategory-hero + .media-mosaic::-webkit-scrollbar { display: none; }
.subcategory-hero + .media-mosaic.hero-gallery { padding-bottom: 0; }
.hero-gallery__foot {
  background: var(--hg-bg);
  padding: var(--hg-nav-gap) 0 var(--hg-pad-bottom);
}

/* ---- Card (Figma 52765:29816) -------------------------------------------- */
.subcategory-hero + .media-mosaic .media-tile {
  position: relative;
  flex: 0 0 var(--hg-card-w);
  width: var(--hg-card-w);
  height: var(--hg-card-h);
  min-height: 0;
  margin: 0;
  aspect-ratio: auto;
  overflow: hidden;
  background: var(--hg-card-bg);
  scroll-snap-align: end;
}
.subcategory-hero + .media-mosaic .media-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transform: none;
  transition: transform .9s var(--hg-ease);
}
.subcategory-hero + .media-mosaic .media-tile:hover img { transform: scale(1.06); }

/* Entrada al cargar la página: las cards llegan desde la izquierda, en
   secuencia (1100 ms · stagger 100 ms · ease-out largo, sin rebote). Es CSS
   sobre las propias cards: se ejecuta una sola vez al pintar y nunca al cerrar
   el visor (ocultar/mostrar las cards no reinicia una animación terminada). */
@keyframes hg-card-in {
  from { opacity: 0; transform: translate3d(-72px, 0, 0); }
  to   { opacity: 1; transform: none; }
}
.subcategory-hero + .media-mosaic .media-tile {
  animation: hg-card-in 1100ms cubic-bezier(0.25, 1, 0.5, 1) both;
  animation-delay: calc(120ms + var(--hg-i, 0) * 100ms);
}
.subcategory-hero + .media-mosaic .media-tile:nth-child(2) { --hg-i: 1; }
.subcategory-hero + .media-mosaic .media-tile:nth-child(3) { --hg-i: 2; }
.subcategory-hero + .media-mosaic .media-tile:nth-child(4) { --hg-i: 3; }
.subcategory-hero + .media-mosaic .media-tile:nth-child(5) { --hg-i: 4; }
.subcategory-hero + .media-mosaic .media-tile:nth-child(6) { --hg-i: 5; }
.subcategory-hero + .media-mosaic .media-tile:nth-child(n+7) { --hg-i: 6; }

/* Botón que cubre la card: abre el visor. Icono + 48×48 (24 de glifo) al hover/focus */
.hero-gallery__open {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  cursor: zoom-in;
}
.hero-gallery__plus {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  opacity: 0;
  transform: scale(.6);
  transition: opacity .45s var(--hg-ease), transform .6s var(--hg-ease);
  filter: drop-shadow(0 1px 6px rgba(0, 0, 0, .35));
}
.hero-gallery__plus svg { width: 24px; height: 24px; }
.hero-gallery__open:hover .hero-gallery__plus,
.hero-gallery__open:focus-visible .hero-gallery__plus { opacity: 1; transform: none; }
.hero-gallery__open:focus { outline: none; }
.hero-gallery__open:focus-visible { box-shadow: inset 0 0 0 3px var(--bg-interactive-focus, #ffd970); }
.subcategory-hero + .media-mosaic .media-tile:has(.hero-gallery__open:focus-visible) img { transform: scale(1.06); }
@media (hover: none) {
  .hero-gallery__plus { opacity: 1; transform: none; }
}

/* ---- Paginación del hero (Figma 52746:27625): flechas + contador, 343 de ancho */
.hero-gallery__nav.carrusel-nav {
  width: 343px;
  max-width: calc(100% - 2 * var(--hg-gutter));
  margin: 0 0 0 var(--hg-inset);
  height: var(--hg-nav-h);
  transition: opacity .5s var(--hg-ease);
}
.hero-gallery__nav .section-related__nav { display: flex; gap: 16px; }

/* Mientras el visor está abierto el resto del hero se desvanece */
.hg-is-open .subcategory-page .subcategory-hero .subcategory-container,
.hg-is-open .hero-gallery__nav { opacity: 0; }
.hero-gallery.is-open .media-tile { visibility: hidden; }
.hero-gallery.is-open .media-tile img { transition: none; }

/* ---- Mobile (≤640) · Figma 52765:29542 ---------------------------------- */
@media (max-width: 640px) {
  .subcategory-page {
    --hg-gutter: 20px;
    --hg-card-w: 213px;
    --hg-card-h: 301px;
    --hg-gap: 16px;
    --hg-pad-top: 18px;                  /* + 16 del hero = 34 */
    --hg-pad-bottom: 28px;
    --hg-end-pad: 23%;                   /* Figma mobile: la card focal acaba en 289/375 */
  }
  .subcategory-page .subcategory-hero { padding: 24px 0 16px; }
  .subcategory-page .subcategory-hero .subcategory-container { gap: 16px; padding-inline: var(--hg-gutter); }
  .subcategory-page .subcategory-hero .breadcrumb .crumb-link,
  .subcategory-page .subcategory-hero .breadcrumb .crumb-current { font-size: 14px; line-height: 20px; }
  .hero-gallery__nav.carrusel-nav { width: auto; max-width: none; margin-inline: var(--hg-inset); }
}

/* ============================================================================
   Visor a pantalla completa (Figma Step 3 · 52746:27645 / Mobile Step 2 · 52772:30537)
   Lo crea hero-gallery.js dentro de <body>; la transición la hace JS (FLIP).
   ========================================================================== */
.hg-viewer {
  --sr-fg: var(--fg-inverse, #f7f8f8);
  --sr-fg-muted: rgba(247, 248, 248, .6);
  --sr-ease: var(--hg-ease, cubic-bezier(0.22, 1, 0.36, 1));
  --hg-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --hg-thumb: 73px;
  --hg-thumb-gap: clamp(16px, 2.9vw, 42px);
  --hg-thumb-dim: .55;
  position: fixed;
  inset: 0;
  z-index: 10000;
  overflow: hidden;
  color: var(--fg-inverse, #f7f8f8);
  font-family: var(--font-family-base);
  contain: layout paint;
  -webkit-tap-highlight-color: transparent;
}
.hg-viewer__backdrop {
  position: absolute;
  inset: 0;
  background: #14181b;
  opacity: 0;
}
.hg-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}
.hg-slide,
.hg-flyer {
  position: absolute;
  overflow: hidden;
  transform-origin: 0 0;
  backface-visibility: hidden;
}
.hg-slide { inset: 0; }
.hg-flyer { background: var(--hg-card-bg, #adb1b6); will-change: transform, opacity; pointer-events: none; }
.hg-slide img,
.hg-flyer img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: center;
  transform-origin: 50% 50%;
  user-select: none;
  -webkit-user-drag: none;
}
.hg-viewer.is-animating .hg-slide,
.hg-viewer.is-animating .hg-slide img { will-change: transform; }
.hg-flyers { position: absolute; inset: 0; pointer-events: none; }

/* Degradados de legibilidad (inferior = Figma 52782:35392, 256 → 60 % negro) */
.hg-shade { position: absolute; left: 0; right: 0; pointer-events: none; }
.hg-shade--bottom { bottom: 0; height: 256px; background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.6) 100%); }
.hg-shade--top { top: 0; height: 140px; background: linear-gradient(0deg, rgba(0,0,0,0) 0%, rgba(0,0,0,.28) 100%); }

/* Controles: entran progresivamente durante la transición */
.hg-ui {
  opacity: 0;
  transition: opacity .45s var(--hg-ease), transform .7s var(--hg-ease);
}
.hg-ui--rise { transform: translate3d(0, 14px, 0); }
.hg-viewer.is-ui .hg-ui { opacity: 1; transform: none; }
.hg-viewer.is-ui .hg-close { transition-delay: .05s; }
.hg-viewer.is-ui .hg-bar__info { transition-delay: .12s; }
.hg-viewer.is-closing .hg-ui { transition-duration: .3s; transition-delay: 0s; }

/* «Cerrar» — Button Link · Neutral inverse con icono izquierdo (Figma 52746:27652) */
.hg-close.btn {
  --_fg: var(--fg-inverse, #f7f8f8);
  position: absolute;
  top: 42px;
  left: 64px;
  z-index: 3;
  gap: 10px;
  width: auto;
  min-width: 0;                          /* .btn trae min-width 190 */
  justify-content: flex-start;
  height: 44px;
  padding: 0 4px 0 0;
  border: 0;
  background: transparent;
  color: var(--fg-inverse, #f7f8f8);
  cursor: pointer;
}
.hg-close .btn__icon { width: 24px; height: 24px; }
.hg-close .btn__label {
  font-weight: var(--font-weight-light, 300);   /* Figma 52746:27652: texto Light */
  font-size: 16px;
  line-height: 16px;
  letter-spacing: .03em;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
}
.hg-close:hover .btn__label { text-decoration-color: transparent; }
.hg-close:focus { outline: none; }
.hg-close:focus-visible { outline: 2px solid var(--fg-inverse, #f7f8f8); outline-offset: 4px; }

/* Barra inferior: nombre | flechas + contador · miniaturas */
.hg-bar {
  position: absolute;
  left: 64px;
  right: 64px;
  bottom: 56px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 40px;
}
.hg-bar__info {
  display: flex;
  align-items: center;
  gap: 40px;
  min-width: 0;
  flex: 0 1 auto;
}
/* Altura fija de una línea: si el nombre ocupa dos, crece hacia arriba y la
   barra (divider, flechas, contador, miniaturas) no se mueve al navegar. */
.hg-name {
  margin: 0;
  width: 34vw;
  max-width: 34vw;
  height: 48px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: visible;
  font-size: var(--font-size-40, 40px);
  line-height: 48px;
  font-weight: var(--font-weight-light, 300);
  letter-spacing: 0;
  color: inherit;
}
.hg-name__text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-wrap: balance;
}
.hg-divider { flex: none; width: 2px; height: 54px; background: #fff; }
.hg-viewer .hg-pager.carrusel-nav {
  --sr-fg: var(--fg-inverse, #f7f8f8);
  --sr-fg-muted: rgba(247, 248, 248, .6);
  flex: none;
  justify-content: flex-start;
  gap: 32px;
  margin: 0;
}
.hg-viewer .hg-pager .section-related__nav { display: flex; gap: 16px; }
.hg-viewer .hg-pager .carrusel-nav__count { color: var(--fg-inverse, #f7f8f8); min-width: 3ch; }
.hg-viewer .arrow-btn:focus-visible { outline-color: var(--fg-inverse, #f7f8f8); }

.hg-thumbs {
  display: flex;
  gap: var(--hg-thumb-gap);
  min-width: 0;
  flex: 0 1 auto;
  padding: 6px;
  margin: -6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  touch-action: pan-x;
}
.hg-thumbs::-webkit-scrollbar { display: none; }
.hg-thumb {
  position: relative;
  flex: 0 0 var(--hg-thumb);
  width: var(--hg-thumb);
  height: var(--hg-thumb);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.hg-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: var(--hg-thumb-dim);
  transition: opacity .4s var(--hg-ease);
}
.hg-thumb::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 1px solid #fff;
  opacity: 0;
  transform: scale(.94);
  transition: opacity .4s var(--hg-ease), transform .5s var(--hg-ease);
  pointer-events: none;
}
.hg-thumb:hover img { opacity: .85; }
.hg-thumb[aria-current="true"] img { opacity: 1; }
.hg-thumb[aria-current="true"]::after { opacity: 1; transform: none; }
.hg-thumb:focus { outline: none; }
.hg-thumb:focus-visible::after { opacity: 1; transform: none; border-width: 2px; border-color: var(--bg-interactive-focus, #ffd970); }
/* Clon de la miniatura activa que sube desde fuera del viewport (con su aro) */
.hg-lift {
  position: absolute;
  pointer-events: none;
  will-change: transform;
  backface-visibility: hidden;
}
.hg-lift img { display: block; width: 100%; height: 100%; object-fit: cover; }
.hg-lift::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 1px solid #fff;
  pointer-events: none;
}
.hg-viewer.is-landing .hg-thumb img,
.hg-viewer.is-landing .hg-thumb::after { transition: none !important; }
/* Durante el vuelo de las cards las miniaturas reales esperan ocultas */
.hg-viewer.is-flying .hg-thumb img,
.hg-viewer.is-flying .hg-thumb::after { opacity: 0 !important; transition: none; }

.hg-sr {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---- Tablet / mobile: barra apilada (Figma Mobile Step 2 · 52772:30537) --- */
@media (max-width: 900px) {
  .hg-viewer { --hg-thumb: 60px; --hg-thumb-gap: 16px; }
  .hg-close.btn { top: 32px; left: 28px; }
  .hg-bar {
    left: 28px;
    right: 28px;
    bottom: 34px;
    flex-direction: column;
    align-items: stretch;
    gap: 24px;
  }
  .hg-bar__info {
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px 16px;
  }
  .hg-name {
    flex: 1 1 0;
    width: auto;
    max-width: none;
    height: 32px;
    font-size: var(--font-size-24, 24px);
    line-height: 32px;
    font-weight: var(--font-weight-medium, 500);
  }
  .hg-divider { height: 32px; }
  .hg-viewer .hg-pager.carrusel-nav { flex-basis: 100%; }
  .hg-thumb:first-child { margin-left: auto; }
  .hg-thumb:last-child { margin-right: auto; }
}

/* ---- Movimiento reducido: sin morph ni zoom (el JS hace un fundido corto) -- */
@media (prefers-reduced-motion: reduce) {
  .subcategory-hero + .media-mosaic .media-tile img,
  .hero-gallery__plus,
  .hg-ui,
  .hg-thumb img,
  .hg-thumb::after { transition-duration: .01ms !important; transition-delay: 0s !important; }
  .subcategory-hero + .media-mosaic .media-tile:hover img { transform: none; }
  .hg-ui--rise { transform: none; }
  .subcategory-hero + .media-mosaic .media-tile { animation: none; }
}

/* Fichas con fotos pendientes («Imagen no disponible»): sin visor ni controles */
.subcategory-hero + .media-mosaic.media-mosaic--pending { padding-bottom: calc(var(--hg-pad-bottom) + var(--hg-nav-gap)); }
.subcategory-hero + .media-mosaic.media-mosaic--pending .media-tile { animation: none; }
