/* ==========================================================================
   PRODUCT GALLERY - ENHANCED WITH CLASSIC ZOOM
   ========================================================================== */

/* Gallery Wrapper */
.product-gallery-wrapper {
    position: relative;
}

/* Featured Image (Static - Always on Top) */
.product-main-image {
    position: relative;
    aspect-ratio: 1/1;
    overflow: hidden;
    background: #f9fafb;
    transition: box-shadow 0.8s ease;
}

.product-main-image:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.product-main-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Dynamic Display Image */
.product-main-display {
    position: relative;
    aspect-ratio: 1/1;
    overflow: hidden;
    background: #f9fafb;
}

.gallery-main-image-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Fade transition support */
.gallery-main-image-container.loading {
    position: relative;
}

.gallery-main-image-container.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.05);
    z-index: 2;
    pointer-events: none;
    /* Smoother fade-in for loading overlay */
    animation: fadeInOverlay 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.gallery-main-image-container.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    /* Improved animation with better easing */
    animation: spin 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
    z-index: 3;
    pointer-events: none;
    /* GPU acceleration */
    transform: translate3d(-50%, -50%, 0);
    will-change: transform;
}

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

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.gallery-main-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    /* Improved transition with cubic-bezier for smoother fade */
    transition: opacity 450ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 450ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    /* GPU acceleration for better performance */
    transform: translate3d(0, 0, 0);
    will-change: opacity, transform;
}

/* Cross-fade effect for smooth transitions */
.gallery-main-image.fade-out {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(1.02);
    z-index: 1;
}

.gallery-main-image.fade-in {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    z-index: 2;
}

/* Classic Zoom Functionality - Direct on Image */
.zoom-image {
    cursor: zoom-in;
    /* Improved transition with better easing */
    transition: transform 450ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: transform;
}

.zoom-image:hover:not(.zoomed) {
    transform: translate3d(0, 0, 0) scale(1.03);
}

.zoom-image.zoomed {
    transform: translate3d(0, 0, 0) scale(2.2);
    cursor: zoom-out;
    z-index: 1000;
    position: relative;
    transition: transform 150ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Fullscreen Button - Optional */
.gallery-fullscreen-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 0.5rem;
    border-radius: 0.375rem;
    opacity: 0;
    /* Improved transition with cubic-bezier */
    transition: all 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 450ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    cursor: pointer;
    border: none;
    z-index: 10;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: opacity, transform;
}

/* Fade transition for fullscreen button */
.gallery-fullscreen-btn.fade-out {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.95);
    z-index: 1;
}

.gallery-fullscreen-btn.fade-in {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
    z-index: 11;
}

.product-main-image:hover .gallery-fullscreen-btn,
.gallery-main-image-container:hover .gallery-fullscreen-btn {
    opacity: 1;
}

.gallery-fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.1);
}

/* Gallery Counter */
.gallery-counter {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 1.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    z-index: 10;
}

/* Navigation Arrows */
.gallery-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    color: #1f2937;
    padding: 0.75rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.product-main-display:hover .gallery-nav-btn {
    opacity: 1;
}

.gallery-prev-btn {
    left: 1rem;
}

.gallery-next-btn {
    right: 1rem;
}

.gallery-nav-btn:hover {
    background: white;
    transform: translateY(-50%) scale(1.1);
}

.gallery-nav-btn:disabled {
    opacity: 0.3 !important;
    cursor: not-allowed;
}

/* Thumbnails Wrapper */
.gallery-thumbnails-wrapper {
    position: relative;
    margin-top: 1rem;
}

.gallery-thumbnails-scroll {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 0.5rem;
}

.gallery-thumbnails-scroll::-webkit-scrollbar {
    display: none;
}

/* Gallery Thumbnails */
.gallery-thumb {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 0.375rem;
    overflow: hidden;
    cursor: pointer;
    opacity: 0.6;
    transition: all 0.3s ease;
    position: relative;
}


.gallery-thumb img,
.gallery-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-thumb.video-thumb::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1;
    pointer-events: none;
}

/* Thumbnail Scroll Buttons */
.thumb-scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: white;
    border: 1px solid #e5e7eb;
    color: #374151;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.gallery-thumbnails-wrapper:hover .thumb-scroll-btn {
    opacity: 1;
}

.thumb-scroll-left {
    left: -16px;
}

.thumb-scroll-right {
    right: -16px;
}

.thumb-scroll-btn:hover {
    background: #f9fafb;
    transform: translateY(-50%) scale(1.1);
}

.thumb-scroll-btn:disabled {
    opacity: 0 !important;
}

/* ==========================================================================
   LIGHTBOX MODAL - Optional Fullscreen View
   ========================================================================== */

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-lightbox.active {
    display: flex;
    opacity: 1;
}

.lightbox-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
}

.lightbox-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

/* Lightbox Close Button */
.lightbox-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    padding: 0.75rem;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg) scale(1.1);
}

/* Lightbox Media Container */
.lightbox-media-container {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-loading {
    position: absolute;
    color: white;
    z-index: 1;
}

.lightbox-image,
.lightbox-video {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    display: none;
    border-radius: 0.5rem;
}

.lightbox-image.active,
.lightbox-video.active {
    display: block;
}

.lightbox-image {
    cursor: grab;
    transition: transform 0.3s ease;
}

.lightbox-image.dragging {
    cursor: grabbing;
}

/* Lightbox Navigation */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    color: #1f2937;
    padding: 1rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
}

.lightbox-prev {
    left: 2rem;
}

.lightbox-next {
    right: 2rem;
}

.lightbox-nav:hover {
    background: white;
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Lightbox Counter */
.lightbox-counter {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 2rem;
    font-size: 1rem;
    font-weight: 600;
    z-index: 10;
}

/* Lightbox Zoom Controls */
.lightbox-zoom-controls {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    gap: 0.5rem;
    z-index: 10;
}

.zoom-btn {
    background: rgba(255, 255, 255, 0.9);
    color: #1f2937;
    padding: 0.75rem;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-btn:hover {
    background: white;
    transform: scale(1.1);
}

.zoom-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ==========================================================================
   MOBILE RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
    .gallery-thumb {
        width: 60px;
        height: 60px;
    }
    
    .gallery-nav-btn {
        padding: 0.5rem;
        opacity: 1;
    }
    
    .gallery-fullscreen-btn {
        opacity: 1;
    }
    
    .lightbox-nav {
        padding: 0.75rem;
    }
    
    .lightbox-prev {
        left: 1rem;
    }
    
    .lightbox-next {
        right: 1rem;
    }
    
    .lightbox-close {
        top: 1rem;
        right: 1rem;
    }
    
    .lightbox-counter {
        bottom: 1rem;
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }
    
    .lightbox-zoom-controls {
        bottom: 1rem;
        right: 1rem;
    }
    
    .zoom-btn {
        width: 36px;
        height: 36px;
        padding: 0.5rem;
    }
    
    /* Mobile zoom behavior */
    .zoom-image.zoomed {
        transform: scale(1.8);
    }
}


/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate3d(0, 0, 0) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: translate3d(0, 0, 0) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

.gallery-lightbox.active .lightbox-media-container {
    animation: fadeInScale 450ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Improved thumbnail transitions */
.gallery-thumb {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 0.375rem;
    overflow: hidden;
    cursor: pointer;
    opacity: 0.6;
    /* Improved transition with better easing */
    transition: all 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    /* GPU acceleration */
    transform: translate3d(0, 0, 0);
    will-change: opacity, transform;
}

.gallery-thumb.active {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1.05);
}

.gallery-thumb:hover {
    opacity: 0.8;
    transform: translate3d(0, 0, 0) scale(1.02);
}
