/**
 * Custom Product Gallery Styles
 * Swiper-based carousel with RTL support
 * Updated for smooth desktop-to-mobile transition
 */

/* ===== Gallery Wrapper ===== */
.custom-product-gallery-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 0;
    position: relative;
    overflow: hidden;
}

/* ===== Main Gallery ===== */
.custom-product-gallery-main {
    width: 100%;
    height: auto;
    margin-bottom: 20px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.custom-product-gallery-main .swiper-wrapper {
    align-items: center;
}

.custom-product-gallery-main .swiper-slide {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fff;
    min-height: 400px;
}

.custom-product-gallery-main .product-gallery-image {
    width: 100%;
    height: auto;
    max-height: 500px;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

/* ===== Zoom Container ===== */
.swiper-zoom-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

/* ===== Pagination Dots ===== */
.custom-product-gallery-main .swiper-pagination {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    gap: 8px;
    direction: ltr;
}

.custom-product-gallery-main .swiper-pagination-bullet {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 1;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.custom-product-gallery-main .swiper-pagination-bullet-active {
    background: #007AFF;
    border-color: #fff;
    width: 12px;
    height: 12px;
}

/* ===== Thumbnail Gallery ===== */
.custom-product-gallery-thumbs {
    width: 100%;
    height: auto;
    padding: 10px 0;
    transition: all 0.3s ease;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox */
}

.custom-product-gallery-thumbs::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
}

.custom-product-gallery-thumbs .swiper-wrapper {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    flex-wrap: nowrap;
}

.custom-product-gallery-thumbs .swiper-slide {
    width: auto !important;
    height: auto;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.3s ease;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid transparent;
    box-sizing: border-box;
    flex-shrink: 0;
}

.custom-product-gallery-thumbs .swiper-slide-thumb-active {
    opacity: 1;
    border-color: #007AFF;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

.custom-product-gallery-thumbs .product-gallery-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    display: block;
    border-radius: 6px;
}

.custom-product-gallery-thumbs .swiper-slide:hover {
    opacity: 0.8;
}

/* ===== Responsive Breakpoints ===== */
/* Only two layouts - desktop (which compacts down) and mobile */
/* No special treatment for iPad - same layout just more compact */

/* Mobile View */
@media (max-width: 768px) {
    /* Gallery Container */
    .custom-product-gallery-wrapper {
        width: 100vw;
        max-width: 100vw;
        padding: 0;
        margin: 0;
        margin-left: -50vw;
        left: 50%;
        position: relative;
        overflow: visible;
    }
    
    /* Main Gallery - Full width, edge to edge */
    .custom-product-gallery-main {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        aspect-ratio: 1 / 1;
        height: auto;
    }
    
    .custom-product-gallery-main .swiper-slide {
        width: 100%;
        aspect-ratio: 1 / 1;
        min-height: unset;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;
    }
    
    .custom-product-gallery-main .swiper-wrapper {
        height: 100%;
    }
    
    .custom-product-gallery-main .product-gallery-image {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }
    
    /* Hide thumbnails completely on mobile */
    .custom-product-gallery-thumbs {
        display: none;
    }
    
    /* Enhance pagination dots */
    .custom-product-gallery-main .swiper-pagination {
        bottom: 15px;
    }
    
    .custom-product-gallery-main .swiper-pagination-bullet {
        width: 6px;
        height: 6px;
        background: rgba(255, 255, 255, 0.8);
        opacity: 1;
        margin: 0 4px;
    }
    
    .custom-product-gallery-main .swiper-pagination-bullet-active {
        background: #007AFF;
        width: 8px;
        height: 8px;
    }
}

/* ===== Desktop Scaling ===== */
/* Large screens get larger thumbnails, but same layout */
@media (min-width: 1200px) {
    .custom-product-gallery-main .swiper-slide {
        min-height: 500px;
    }
    
    .custom-product-gallery-thumbs .product-gallery-thumb {
        width: 100px;
        height: 100px;
    }
}

/* ===== Loading State ===== */
.custom-product-gallery-wrapper.loading {
    opacity: 0.6;
    pointer-events: none;
}

.custom-product-gallery-wrapper.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 #007AFF;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ===== Touch Optimization ===== */
.custom-product-gallery-main,
.custom-product-gallery-thumbs {
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y pinch-zoom;
}

/* ===== Accessibility ===== */
.custom-product-gallery-thumbs .swiper-slide:focus {
    outline: 2px solid #007AFF;
    outline-offset: 2px;
}

/* ===== WooCommerce Integration ===== */
.woocommerce div.product div.images {
    margin-bottom: 2em;
}

.woocommerce div.product .custom-product-gallery-wrapper {
    float: none;
    width: 100%;
}

/* Hide default WooCommerce gallery elements */
.woocommerce div.product div.images .woocommerce-product-gallery__trigger {
    display: none;
}
