/**
 * Galería de producto TBS (desktop / tablet / mobile).
 * Se carga después de producto.css y custom.css únicamente en la ficha.
 * Desactivar eliminando este asset y su script del header/footer.
 */
body.template-product product-images.tbs-gallery-upgraded {
    display: grid !important;
    grid-template-columns: 72px minmax(0, 1fr) !important;
    grid-template-areas: "thumbnails image";
    align-items: start !important;
    column-gap: 14px !important;
    width: 100% !important;
    min-width: 0 !important;
}

/* Producto con una sola imagen: no reservar una columna vacía. */
body.template-product product-images.tbs-gallery-upgraded.tbs-gallery--single {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas: "image";
}
body.template-product product-images.tbs-gallery-upgraded.tbs-gallery--single product-thumbs.product__thumbs {
    display: none !important;
}

/* Badge de oferta sobre la imagen, sin tapar las miniaturas verticales. */
@media (min-width: 981px) {
    body.template-product product-images.tbs-gallery-upgraded.tbs-gallery--multiple .tbs-product-promotion {
        left: 98px !important;
    }
    body.template-product product-images.tbs-gallery-upgraded.tbs-gallery--multiple .product__badges {
        left: 86px !important;
    }
}

/* La imagen principal deja de ser una cuadrícula de fotografías. */
body.template-product product-images.tbs-gallery-upgraded zoom-images.tbs-gallery-stage,
body.template-product product-images.tbs-gallery-upgraded .product__slides.tbs-gallery-stage {
    grid-area: image;
    position: relative !important;
    display: block !important;
    grid-template-columns: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff;
    overflow: hidden !important;
    isolation: isolate;
    touch-action: pan-y;
}

body.template-product product-images.tbs-gallery-upgraded zoom-images.tbs-gallery-stage > .product__slide,
body.template-product product-images.tbs-gallery-upgraded zoom-images.tbs-gallery-stage > .product__slide:first-child,
body.template-product product-images.tbs-gallery-upgraded zoom-images.tbs-gallery-stage > .product__slide.media--hidden {
    grid-column: auto !important;
    position: absolute !important;
    inset: 0 !important;
    display: none !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: none !important;
}

body.template-product product-images.tbs-gallery-upgraded zoom-images.tbs-gallery-stage > .product__slide.media--active {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-stage .product__slide .product__photo,
body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-stage .product__slide .image-wrapper {
    position: relative !important;
    inset: auto !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    aspect-ratio: auto !important;
    overflow: hidden !important;
    background: #fff !important;
}

body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-stage .product__slide img,
body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-stage .product__slide img.tbs-product-image {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    margin: 0 auto !important;
    padding: 0 !important;
    object-fit: contain !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
}

/* Miniaturas verticales a la izquierda en desktop. */
body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs {
    grid-area: thumbnails;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 9px !important;
    align-self: stretch !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: 100% !important;
    margin: 0 !important;
    padding: 0 2px 2px 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scroll-snap-type: y proximity !important;
    scrollbar-width: thin;
    scrollbar-color: #c4d3ce transparent;
}

body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .tbs-gallery-thumb {
    display: flex !important;
    flex: 0 0 68px !important;
    align-items: center !important;
    justify-content: center !important;
    width: 68px !important;
    height: 68px !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 3px !important;
    border: 1px solid #e0e7e3 !important;
    border-radius: 4px !important;
    background: #fff !important;
    cursor: pointer !important;
    scroll-snap-align: start;
    transition: border-color .15s ease;
}

body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .tbs-gallery-thumb.is-active,
body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .tbs-gallery-thumb.is-selected,
body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .tbs-gallery-thumb[aria-current="true"] {
    border: 2px solid #004236 !important;
    padding: 2px !important;
}

body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .tbs-gallery-thumb:focus-visible,
body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-arrow:focus-visible,
body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-stage:focus-visible {
    outline: 2px solid #004236 !important;
    outline-offset: 2px;
}

body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .pswp__thumb,
body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .image-wrapper {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    aspect-ratio: 1 / 1 !important;
}

body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs img {
    position: static !important;
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    object-fit: contain !important;
    pointer-events: none;
}

/* Controles superpuestos, sin alterar el zoom existente de la fotografía. */
body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-controls {
    position: absolute;
    z-index: 6;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 9px;
    pointer-events: none;
}

body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid #d8e3df;
    border-radius: 50%;
    background: rgba(255, 255, 255, .96);
    color: #004236;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .09);
    cursor: pointer;
    pointer-events: auto;
}

body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-arrow svg {
    display: block;
    width: 18px;
    height: 18px;
}

body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-arrow:disabled {
    opacity: .28;
    cursor: default;
}

body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-counter {
    position: absolute;
    z-index: 6;
    right: 12px;
    bottom: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(0, 66, 54, .86);
    color: #fff;
    font-size: 12px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}

@media (max-width: 980px) {
    body.template-product product-images.tbs-gallery-upgraded {
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-areas: "image" "thumbnails";
        row-gap: 10px;
    }

    body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        flex-direction: row !important;
        align-self: auto !important;
        gap: 8px !important;
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        margin: 0 0 12px !important;
        padding: 0 0 5px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x proximity !important;
        -webkit-overflow-scrolling: touch;
    }

    body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .tbs-gallery-thumb {
        flex: 0 0 62px !important;
        width: 62px !important;
        height: 62px !important;
    }
}

@media (max-width: 560px) {
    body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-arrow {
        width: 34px;
        height: 34px;
    }

    body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-controls {
        padding: 0 5px;
    }

    body.template-product product-images.tbs-gallery-upgraded product-thumbs.product__thumbs .tbs-gallery-thumb {
        flex-basis: 58px !important;
        width: 58px !important;
        height: 58px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.template-product product-images.tbs-gallery-upgraded .tbs-gallery-thumb {
        transition: none !important;
    }
}

/*
 * Visor ampliado: controles alrededor de la foto y miniaturas próximas.
 * El lightbox existente lo crea main.js. Estos cambios son solo de estilo:
 * no alteran su navegación, la imagen de variaciones ni el cierre del modal.
 */
body.template-product .product-lightbox {
    height: 100vh;
    height: 100dvh;
}

body.template-product .product-lightbox__container {
    box-sizing: border-box;
    justify-content: center;
    align-items: center;
    gap: clamp(8px, 1.5vh, 16px);
    padding: 52px 16px 20px;
    min-height: 0;
    overflow: hidden;
}

/* El cierre queda independiente del espacio ocupado por la foto. */
body.template-product .product-lightbox__header {
    position: absolute;
    z-index: 5;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    padding: 0;
}

body.template-product .product-lightbox__close {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    background: rgba(255, 255, 255, .95);
}

/* Foto y miniaturas forman un mismo grupo, centrado verticalmente. */
body.template-product .product-lightbox__main {
    position: relative;
    flex: 0 1 auto;
    box-sizing: border-box;
    width: min(920px, calc(100vw - 136px), calc(100vh - 176px));
    width: min(920px, calc(100vw - 136px), calc(100dvh - 176px));
    height: auto;
    min-height: 0;
    padding: 0;
    margin: 0;
}

body.template-product .product-lightbox__image-wrap {
    flex: 0 1 auto;
    box-sizing: border-box;
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: none;
    aspect-ratio: 1 / 1;
    overflow: hidden;
}

body.template-product .product-lightbox__image {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    min-width: 0;
    min-height: 0;
    object-fit: contain;
}

body.template-product .product-lightbox__arrow {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid #d8e3df;
    border-radius: 50%;
    color: #004236;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 1px 6px rgba(0, 0, 0, .1);
    font-size: 28px;
    line-height: 1;
}

body.template-product .product-lightbox__arrow--prev {
    left: -48px;
}

body.template-product .product-lightbox__arrow--next {
    right: -48px;
}

body.template-product .product-lightbox__thumbs {
    flex: 0 0 auto;
    box-sizing: border-box;
    align-items: center;
    justify-content: flex-start;
    width: max-content;
    max-width: 100%;
    min-height: 0;
    padding: 3px 4px 5px;
    margin: 0 auto;
    gap: 10px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

body.template-product .product-lightbox__thumb {
    width: 64px;
    height: 64px;
}

@media (max-width: 749px) {
    body.template-product .product-lightbox__container {
        gap: 12px;
        padding: max(54px, env(safe-area-inset-top, 0px)) 12px max(16px, env(safe-area-inset-bottom, 0px));
    }

    body.template-product .product-lightbox__main {
        width: min(calc(100vw - 28px), calc(100vh - 168px));
        width: min(calc(100vw - 28px), calc(100dvh - 168px));
    }

    body.template-product .product-lightbox__arrow {
        width: 36px;
        height: 36px;
        font-size: 25px;
    }

    body.template-product .product-lightbox__arrow--prev {
        left: 5px;
    }

    body.template-product .product-lightbox__arrow--next {
        right: 5px;
    }

    body.template-product .product-lightbox__thumbs {
        gap: 8px;
    }

    body.template-product .product-lightbox__thumb {
        width: 58px;
        height: 58px;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.template-product .product-lightbox__thumbs {
        scroll-behavior: auto;
    }
}
