/* ==========================================================================
   Galería de la ficha (spec 065) — inc/modules/product-gallery/render.php
   Celular (< 728): foto a todo el ancho, puntitos y «n/N», se desliza con el dedo.
   Tablet (728–1023): miniaturas abajo y flechas.
   Escritorio (≥ 1024): miniaturas al costado y flechas; la columna crece al 48 %
   para que la foto no quede más chica que antes (~430 px a 1366).
   Lo que va encima de la foto usa colores fijos: la foto siempre es blanca.
   ========================================================================== */

.bb-gallery {
    --bb-gal-radius: 0px;
    --bb-gal-thumb: 64px;
    position: relative;
    display: grid;
    gap: 12px;
    min-width: 0;
    margin-bottom: 0;
}
.bb-gallery__stage {
    position: relative;
    aspect-ratio: 1 / 1;
    max-width: 100%;
    overflow: hidden;
    border-radius: var(--bb-gal-radius);
    background: var(--bb-white);
    transition: opacity 120ms ease;
}
.bb-gallery__stage:has(.bb-gallery__track:focus-visible) {
    outline: 2px solid var(--bb-purple);
    outline-offset: 2px;
}
.bb-gallery.is-swapping .bb-gallery__stage {
    opacity: .35;
}
.bb-gallery__track {
    display: flex;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    outline: 0;
}
.bb-gallery__track::-webkit-scrollbar {
    display: none;
}
.bb-gallery__slide {
    flex: 0 0 100%;
    height: 100%;
    margin: 0;
    display: grid;
    /* Fila y columna del tamaño del cuadro: con filas «auto», el height: 100% de la foto
       tomaba su alto natural y una foto vertical quedaba cortada (solo se veía la parte de arriba). */
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    cursor: pointer;
}
.bb-gallery__slide--empty {
    cursor: default;
}
.bb-gallery__slide img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

/* Etiquetas: no se meten debajo del botón de pantalla completa. */
.bb-gallery .product-labels--overlay {
    right: 64px;
    display: flex;
    flex-wrap: wrap;
}

/* Botones sobre la foto. Blindados contra el button global de Storefront. */
:is(.bb-gallery, .bb-lightbox) .bb-gallery__btn {
    position: absolute;
    z-index: 4;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, .94);
    color: var(--bb-ink);
    box-shadow: 0 4px 14px rgba(61, 58, 92, .14);
    cursor: pointer;
    transition: opacity 150ms ease, color 150ms ease;
}
:is(.bb-gallery, .bb-lightbox) .bb-gallery__btn:hover,
:is(.bb-gallery, .bb-lightbox) .bb-gallery__btn:focus {
    background: var(--bb-white);
    color: var(--bb-purple-strong);
}
:is(.bb-gallery, .bb-lightbox) .bb-gallery__btn:focus-visible {
    outline: 2px solid var(--bb-purple);
    outline-offset: 2px;
}
.bb-gallery__btn--prev {
    top: calc(50% - 22px);
    left: 12px;
}
.bb-gallery__btn--next {
    top: calc(50% - 22px);
    right: 12px;
}
.bb-gallery .bb-gallery__btn--full {
    top: 12px;
    right: 12px;
}
.bb-gallery #product-reel {
    left: 14px;
    bottom: 30px;
}

.bb-gallery__dots {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 14px;
    z-index: 3;
    display: flex;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
}
.bb-gallery__dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--bb-purple-200);
    transition: width 200ms ease, background 200ms ease;
}
.bb-gallery__dot.is-on {
    width: 18px;
    background: var(--bb-purple);
}
.bb-gallery__count {
    position: absolute;
    right: 14px;
    bottom: 10px;
    z-index: 3;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--bb-white);
    box-shadow: 0 2px 8px rgba(61, 58, 92, .14);
    color: var(--bb-ink);
    font-size: 11.5px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

.bb-gallery__thumbs {
    display: none;
}
:is(.bb-gallery, .bb-lightbox) .bb-gallery__thumb {
    flex: 0 0 auto;
    width: var(--bb-gal-thumb);
    height: var(--bb-gal-thumb);
    margin: 0;
    padding: 3px;
    border: 1px solid var(--bb-line);
    border-radius: 12px;
    background: var(--bb-white);
    cursor: pointer;
}
:is(.bb-gallery, .bb-lightbox) .bb-gallery__thumb:hover {
    background: var(--bb-white);
    border-color: var(--bb-purple-200);
}
:is(.bb-gallery, .bb-lightbox) .bb-gallery__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}
:is(.bb-gallery, .bb-lightbox) .bb-gallery__thumb[aria-current="true"] {
    padding: 2px;
    border: 2px solid var(--bb-purple);
}
:is(.bb-gallery, .bb-lightbox) .bb-gallery__thumb:focus-visible {
    outline: 2px solid var(--bb-purple);
    outline-offset: 2px;
}

/* Una sola foto: nada de navegación. */
.bb-gallery[data-single] .bb-gallery__btn--prev,
.bb-gallery[data-single] .bb-gallery__btn--next,
.bb-gallery[data-single] .bb-gallery__dots,
.bb-gallery[data-single] .bb-gallery__count,
.bb-gallery[data-single] .bb-gallery__thumbs {
    display: none !important;
}

/* Celular */
@media (max-width: 727px) {
    .bb-gallery__btn--prev,
    .bb-gallery__btn--next {
        display: none !important;
    }
    /* Aire entre la foto y lo que sigue (rating o título). Con la especificidad de la regla
       de Storefront/tema que deja margin-bottom: 0 en la galería. */
    .single-product div.product .bb-gallery {
        margin-bottom: 16px;
    }
}

/* Tablet y escritorio: miniaturas + flechas, sin puntitos ni contador. */
@media (min-width: 728px) {
    .bb-gallery {
        --bb-gal-radius: 20px;
    }
    .bb-gallery__dots,
    .bb-gallery__count {
        display: none;
    }
    .bb-gallery #product-reel {
        bottom: 12px;
    }
    /* Ancho propio: entre 728 y 767 el contenedor ya es una fila flex pero el 41 % de Storefront
       recién aplica desde 768, y la rejilla (min-width: 0) se achicaba a nada. */
    .single-product div.product .bb-gallery {
        flex: 0 0 42%;
        width: 42%;
        margin-right: 4%;
    }
    .single-product div.product .product-header-container > .summary {
        flex: 1 1 0;
        width: auto;
        min-width: 0;
    }
    .bb-gallery__thumbs {
        display: flex;
        gap: 8px;
        padding: 2px;
        overflow-x: auto;
        scrollbar-width: thin;
    }
}
/* Con mouse, las flechas aparecen al pasar por la foto; en tablets táctiles quedan siempre a la vista. */
@media (min-width: 728px) and (hover: hover) {
    .bb-gallery__stage:not(:hover):not(:focus-within) .bb-gallery__btn--prev,
    .bb-gallery__stage:not(:hover):not(:focus-within) .bb-gallery__btn--next {
        opacity: 0;
        pointer-events: none;
    }
}
@media (min-width: 1024px) {
    .single-product div.product .bb-gallery {
        flex: 0 0 48%;
        width: 48%;
        grid-template-columns: calc(var(--bb-gal-thumb) + 8px) minmax(0, 1fr);
        align-items: start;
    }
    /* Las miniaturas van después de la foto en el HTML (orden del Tab) y a la izquierda en la rejilla.
       contain: size → la fila la define la foto y la tira se desplaza en vez de estirar la galería. */
    .bb-gallery__thumbs {
        grid-column: 1;
        grid-row: 1;
        flex-direction: column;
        align-self: stretch;
        contain: size;
        overflow-x: hidden;
        overflow-y: auto;
    }
    /* Con una o varias fotos la foto mide lo mismo: siempre en la segunda columna. */
    .bb-gallery__stage {
        grid-column: 2;
        grid-row: 1;
    }
    /* La rejilla tiene dos columnas: el modal del video no ocupa celda. */
    .bb-gallery > .bdev-modal-overlay {
        grid-column: 1 / -1;
    }
}

/* ---- Pantalla completa (assets/js/product-gallery-lightbox.js) ---- */
.bb-lightbox {
    --bb-gal-thumb: 64px;
}
.bb-lightbox {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: var(--bb-white);
    color: var(--bb-ink);
}
.bb-lightbox::backdrop {
    background: var(--bb-white);
}
.bb-lightbox[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}
.bb-lightbox__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
}
.bb-lightbox__count {
    min-width: 3ch;
    font-size: 14px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.bb-lightbox__hint {
    font-size: 12.5px;
    color: var(--bb-ink-2);
    text-align: center;
}
.bb-lightbox .bb-lightbox__close {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--bb-purple-50);
    color: var(--bb-ink);
    cursor: pointer;
}
.bb-lightbox .bb-lightbox__close:hover {
    background: var(--bb-purple-100);
    color: var(--bb-ink);
}
.bb-lightbox .bb-lightbox__close:focus-visible {
    outline: 2px solid var(--bb-purple);
    outline-offset: 2px;
}
.bb-lightbox__track {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    overscroll-behavior: contain;
}
.bb-lightbox__track::-webkit-scrollbar {
    display: none;
}
.bb-lightbox.is-zoomed .bb-lightbox__track {
    overflow-x: hidden;
}
.bb-lightbox__slide {
    flex: 0 0 100%;
    height: 100%;
    margin: 0;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    touch-action: pan-x;
}
.bb-lightbox__slide img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 12px;
    background: var(--bb-white);
    transform-origin: center;
    transition: transform 180ms ease;
    user-select: none;
    -webkit-user-drag: none;
}
.bb-lightbox__slide.can-zoom img {
    cursor: zoom-in;
}
.bb-lightbox.is-zoomed .bb-lightbox__slide.is-active {
    touch-action: none;
}
.bb-lightbox.is-zoomed .bb-lightbox__slide.is-active img {
    cursor: zoom-out;
}
.bb-lightbox.is-dragging .bb-lightbox__slide img {
    transition: none;
}
.bb-lightbox__thumbs {
    display: flex;
    justify-content: safe center;
    gap: 8px;
    padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;
}
.bb-lightbox .bb-gallery__btn {
    position: fixed;
}
@media (max-width: 727px) {
    .bb-lightbox .bb-gallery__thumb {
        --bb-gal-thumb: 52px;
    }
    .bb-lightbox .bb-gallery__btn--prev,
    .bb-lightbox .bb-gallery__btn--next {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bb-gallery__stage,
    .bb-gallery__dot,
    .bb-gallery .bb-gallery__btn,
    .bb-lightbox__slide img {
        transition: none;
    }
}

.bb-lightbox [hidden] {
    display: none !important;
}
