/**
 * Vini Custom Product Gallery Styles
 *
 * Estilos para la galería personalizada de productos
 * Se aplica cuando usas el template product-image.php personalizado
 */

.vini-product-gallery {
    position: sticky !important;
    top: 20px !important;
    align-self: flex-start;
    margin-right: 32px;
    margin-top: 0px;
    z-index: 10;
    /* Width controlado por media queries */
}

/* Fallback JS Sticky */
.vini-product-gallery.vini-gallery-js-sticky {
    position: fixed !important;
    top: 20px !important;
    /* width se setea via JS para mantener el ancho original */
}

@media (min-width: 1024px) {
    .vini-product-gallery.vini-gallery-js-sticky {
        max-width: 50% !important;
    }
}

/* Parent container fix - CRITICAL para que sticky funcione */
.product-details-wrapper {
    display: flex !important;
    align-items: flex-start;
    flex-wrap: nowrap !important;
    /* No permitir wrap */
    /* Estos son CRÍTICOS para que position sticky funcione */
    overflow: visible !important;
    transform: none !important;
    perspective: none !important;
    filter: none !important;
    will-change: auto !important;
}

/* Main Image Container */
.vini-gallery-main {
    position: relative;
    margin-bottom: 1rem;
    overflow: hidden !important;
    /* Force clip for zoom */
    border-radius: 8px;
    background: #f5f5f5;
    border-radius: 30px;
}

#commercegurus-pdp-gallery-wrapper {
    display: none;
}

.vini-gallery-main__wrapper {
    position: relative;
    width: 100%;
    min-height: 400px;
}

.vini-gallery-main__slide {
    display: none;
    width: 100%;
    overflow: hidden;
    /* Extra safety */
}

.vini-gallery-main__slide.active {
    display: block;
}

.vini-gallery-main__slide a {
    display: block;
    width: 100%;
    height: 100%;
}

.vini-gallery-main__slide img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    transition: transform 0.5s ease;
    /* Smooth zoom transition */
    transform-origin: center center;
}

/* Zoom on hover (Desktop) */
@media (hover: hover) {
    .vini-gallery-main__slide:hover img {
        transform: scale(1.5);
    }
}

/* Navigation Buttons */
.vini-gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.vini-gallery-nav:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.vini-gallery-nav svg {
    width: 24px;
    height: 24px;
    color: #181D27;
}

.vini-gallery-nav--prev {
    left: 1rem;
}

.vini-gallery-nav--next {
    right: 1rem;
}

/* Thumbnails */
.vini-gallery-thumbnails {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #ddd #f5f5f5;
}

.vini-gallery-thumbnails::-webkit-scrollbar {
    height: 6px;
}

.vini-gallery-thumbnails::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 3px;
}

.vini-gallery-thumbnails::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.vini-gallery-thumbnails::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

.vini-gallery-thumbnails__wrapper {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

.vini-gallery-thumbnail {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    background: #f5f5f5;
    padding: 0;
    transition: all 0.3s ease;
    opacity: 0.6;
}

.vini-gallery-thumbnail:hover {
    opacity: 0.8;
    border-color: #ddd;
}

.vini-gallery-thumbnail.active {
    opacity: 1;
    border-color: #181D27;
}

.vini-gallery-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* No Images State */
.vini-product-gallery--no-images {
    width: 100%;
    padding: 2rem;
    background: #f5f5f5;
    border-radius: 8px;
    text-align: center;
}

.vini-product-gallery--no-images img {
    max-width: 300px;
    margin: 0 auto;
    opacity: 0.3;
}

/* Responsive */

/* Mobile: Desactivar sticky */
@media (max-width: 767px) {
    .product-details-wrapper {
        display: block !important;
    }

    .vini-product-gallery {
        position: relative !important;
        top: auto !important;
        margin-right: 0;
        margin-bottom: 24px;
    }

    .vini-product-gallery.vini-gallery-js-sticky {
        position: relative !important;
        top: auto !important;
    }
}

@media (min-width: 768px) {

    /* Asegurar que galería y summary se mantengan lado a lado */
    .vini-product-gallery {
        flex: 0 0 48%;
        /* Galería ocupa 48% del ancho */
        max-width: 48%;
        min-width: 400px;
        /* Mínimo ancho para verse bien */
    }

    .product-details-wrapper .summary.entry-summary {
        flex: 1;
        /* Summary ocupa el espacio restante */
        min-width: 0;
        /* Previene overflow */
        min-height: 100vh;
        /* Asegura altura suficiente para sticky */
    }

    .vini-gallery-main__wrapper {
        min-height: 500px;
    }

    .vini-gallery-thumbnail {
        width: 100px;
        height: 100px;
    }
}

@media (min-width: 1024px) {
    .vini-product-gallery {
        flex: 0 0 50%;
        /* En desktop galería ocupa exactamente 50% */
        max-width: 50%;
    }

    .vini-gallery-main__wrapper {
        min-height: 600px;
    }
}

/* Optional: Vertical Layout (thumbnails on the side) */
@media (min-width: 768px) {
    .vini-product-gallery.vini-gallery-layout--vertical {
        display: flex;
        flex-direction: row-reverse;
        gap: 1rem;
    }

    .vini-product-gallery.vini-gallery-layout--vertical .vini-gallery-main {
        flex: 1;
        margin-bottom: 0;
    }

    .vini-product-gallery.vini-gallery-layout--vertical .vini-gallery-thumbnails {
        flex: 0 0 120px;
        overflow-y: auto;
        overflow-x: hidden;
        max-height: 600px;
    }

    .vini-product-gallery.vini-gallery-layout--vertical .vini-gallery-thumbnails__wrapper {
        flex-direction: column;
    }

    .vini-product-gallery.vini-gallery-layout--vertical .vini-gallery-thumbnail {
        width: 100%;
        height: 120px;
    }
}

/* Zoom Cursor */
.vini-gallery-main__slide a:hover {
    cursor: zoom-in;
}

/* Loading State */
.vini-gallery-main__slide.loading {
    opacity: 0.5;
}

.vini-gallery-main__slide.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #181D27;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ========================================
 * Wishlist Button in Product Gallery
 * ======================================== */

#shoptimizer-modals-wrapper {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 20;
}

.vini-product-gallery .commercekit-wishlist.full {
    position: relative;
}

.vini-product-gallery .commercekit-save-wishlist {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: transparent;
    border-radius: 50%;
    transition: all 0.3s ease;
    position: relative;
    /* box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); */
}

/* Wishlist tooltip (appended to body by JS) */
.vini-wishlist-tooltip {
    position: fixed;
    background: #1C1C1E;
    color: #fff;
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    padding: 6px 12px;
    border-radius: 6px;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.vini-wishlist-tooltip.is-visible {
    opacity: 1;
}

.vini-product-gallery .commercekit-save-wishlist:hover {
    background: #fff;
    transform: scale(1.15);
    /* box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); */
}

.vini-product-gallery .commercekit-save-wishlist svg {
    width: 40px;
    height: 36px;
    transition: stroke 0.3s ease, fill 0.3s ease;
}

.vini-product-gallery .commercekit-save-wishlist:hover svg {
    stroke: #E6532A;
}

/* Wishlist active state */
.vini-product-gallery .commercekit-wishlist.added .commercekit-save-wishlist svg path {
    fill: #E6532A;
    stroke: #E6532A;
}

/* Wishlist is-active state (custom toggle) */
.vini-product-gallery .commercekit-wishlist.is-active .commercekit-save-wishlist svg path {
    fill: #E8562D;
    stroke: #E8562D;
}

/* Hide loading spinner on PDP heart */
.vini-product-gallery .commercekit-wishlist a.processing:after {
    display: none !important;
}

/* Hide "Ver lista de favoritos" text — keep only the heart */
.vini-product-gallery .commercekit-wishlist .commercekit-browse-wishlist span {
    display: none;
}

/* Hide text but keep accessible */
.vini-product-gallery .commercekit-save-wishlist .screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Mobile adjustment */
@media (max-width: 767px) {
    #shoptimizer-modals-wrapper {
        top: 12px;
        right: 12px;
    }

    .vini-product-gallery .commercekit-save-wishlist {
        width: 60px;
        height: 40px;
    }

    .vini-product-gallery .commercekit-save-wishlist svg {
        width: 40px;
        height: 36px;
    }

}
    #shoptimizer-modals-wrapper{
        display: none;
    }
    .vini-gallery-main__wrapper #shoptimizer-modals-wrapper{
        display: flex;
    }

/* Header sticky (144px en escritorio): bajar el offset para que la galería no quede debajo */
@media (min-width: 992px) {
    .vini-product-gallery,
    .vini-product-gallery.vini-gallery-js-sticky {
        top: calc(var(--wp-admin--admin-bar--height, 0px) + 164px) !important;
    }
}
