/* WooCommerce Product Video Gallery - Swiper Implementation */

.wc-custom-gallery {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* Main Gallery Swiper */
.product-gallery-swiper {
    width: 100%;
    height: auto;
    margin-bottom: 1em;
    position: relative;
    overflow: hidden;
}

.product-gallery-swiper .swiper-wrapper {
    overflow: visible;
}

.swiper-slide {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #ffffff00;
    position: relative;
    width: 100%;
    flex-shrink: 0;
}

/* Hide partial next/prev slides */
.product-gallery-swiper .swiper-slide:not(.swiper-slide-active) {
    opacity: 0;
    pointer-events: none;
}

.gallery-slide-image {
    width: 100%;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.gallery-image {
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.gallery-slide-image:hover .gallery-image {
    transform: scale(1.02);
}

/* Video Slide Styles */
.gallery-slide-video {
    width: 100%;
    height: auto;
    position: relative;
    background: #00000000;
    aspect-ratio: 16/9;
    border: none !important;
    outline: none !important;
}

/* YouTube Shorts: Portrait aspect ratio (9:16) on ALL devices */
.gallery-slide-video.youtube-short {
    aspect-ratio: 9/16 !important;
}

/* Make Shorts smaller on all devices */
.gallery-slide-video.youtube-short {
    width: 70% !important;
    max-width: 350px !important;
    margin: 0 auto !important;
}

/* Mobile: Make Shorts even smaller */
@media (max-width: 768px) {
    .gallery-slide-video.youtube-short {
        width: 80% !important;
        max-width: 300px !important;
    }
}

/* Normal videos keep landscape on all devices */
.gallery-slide-video:not(.youtube-short) {
    aspect-ratio: 16/9 !important;
}

.video-thumbnail-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
    cursor: pointer !important;
    overflow: hidden;
    border: none !important;
    outline: none !important;
}

.video-thumbnail-wrapper:hover {
    cursor: pointer !important;
}

.video-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease;
    border: none !important;
    outline: none !important;
}

.video-slide {
    border: none !important;
    outline: none !important;
}

.video-play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: transform 0.3s ease;
    z-index: 2;
    opacity: 0.9;
}

.video-play-button:hover {
    transform: translate(-50%, -50%) scale(1.1);
    opacity: 1;
}

.video-thumbnail-wrapper.playing .video-thumbnail,
.video-thumbnail-wrapper.playing .video-play-button {
    display: none;
}

.video-thumbnail-wrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
}

/* Video swipe overlay - allows swiping over playing videos */
.video-swipe-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 10 !important;
    background: transparent !important;
    pointer-events: none !important;
    touch-action: pan-x pan-y !important;
}

/* Ensure video wrapper is properly positioned */
.video-thumbnail-wrapper {
    position: relative;
}

/* Ensure video wrapper allows touch gestures */
.video-thumbnail-wrapper.playing {
    position: relative;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
}

/* Thumbnails for Desktop */
.product-gallery-thumbs {
    width: 100%;
    height: auto;
    margin-top: 1em;
    display: block;
}

.product-gallery-thumbs .swiper-wrapper {
    display: flex;
    gap: 10px;
}

.product-gallery-thumbs .swiper-slide {
    width: 80px !important;
    height: 80px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.3s ease;
    position: relative;
    flex-shrink: 0;
}

.product-gallery-thumbs .swiper-slide-thumb-active {
    opacity: 1;
}

.gallery-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
    border: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.product-gallery-thumbs .swiper-slide-thumb-active .gallery-thumb {
    border-color: #005349;
    border-width: 3px;
}

/* Video thumbnail styling */
.video-thumb {
    position: relative;
    display: block;
}

/* YouTube Shorts thumbnail: Portrait aspect ratio (9:16) for thumbnails */
.youtube-short-thumb .video-thumbnail {
    aspect-ratio: 9/16;
    object-fit: cover;
    width: 100%;
    height: 100%;
}

.video-thumb-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    pointer-events: none;
}

/* Swiper Navigation Buttons */
.swiper-button-next,
.swiper-button-prev {
    color: #333;
    background: rgba(255, 255, 255, 0.8);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.product-gallery-swiper .swiper-button-next,
.product-gallery-swiper .swiper-button-prev {
    top: 50%;
    margin-top: 0 !important;
    transform: translateY(-50%);
    position: absolute;
}

.swiper-button-next:hover,
.swiper-button-prev:hover {
    background: rgba(255, 255, 255, 0.95);
}

.swiper-button-next:after,
.swiper-button-prev:after {
    font-size: 16px;
    font-weight: bold;
}

.product-gallery-swiper .swiper-button-prev {
    left: 10px;
    right: auto;
}

.product-gallery-swiper .swiper-button-next {
    right: 10px;
    left: auto;
}

/* Mobile Pagination - Outside the images */
.swiper-pagination {
    position: static !important;
    margin-top: 1em;
    text-align: center;
    display: none;
}

.swiper-pagination-bullet {
    width: 10px;
    height: 10px;
    background: #d0d0d0;
    opacity: 1;
    transition: all 0.3s ease;
    margin: 0 5px !important;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
}

.swiper-pagination-bullet-active {
    background: #005349;
    transform: scale(1.3);
    box-shadow: 0 2px 8px rgba(0, 83, 73, 0.4);
}

/* Video slide pagination bullet styling - YouTube style */
.swiper-pagination-bullet.video-bullet {
    background: #FF0000; /* YouTube red */
    position: relative;
    width: 24px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px !important; /* Rounded rectangle like YouTube */
}

.swiper-pagination-bullet.video-bullet::before {
    content: '▶';
    position: absolute;
    font-size: 7px;
    color: white;
    font-weight: bold;
    line-height: 1;
    top: 50%;
    left: 51%; /* Slight offset for visual centering */
    transform: translate(-50%, -50%);
}

.swiper-pagination-bullet.video-bullet.swiper-pagination-bullet-active {
    background: #005349; /* Brand color when active */
    transform: scale(1.15);
    box-shadow: 0 2px 10px rgba(0, 83, 73, 0.5);
}

.swiper-pagination-bullet.video-bullet.swiper-pagination-bullet-active::before {
    font-size: 7px;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .product-gallery-thumbs {
        display: none !important;
    }
    
    .swiper-pagination {
        display: block !important;
        position: relative;
        margin-top: 15px;
        text-align: center;
    }
    
    .swiper-pagination-bullet {
        width: 10px;
        height: 10px;
        background: #d0d0d0 !important;
        opacity: 1;
        margin: 0 4px;
        transition: all 0.3s ease;
    }
    
    .swiper-pagination-bullet-active {
        background: #005349 !important;
        transform: scale(1.3);
    }
    
    .swiper-pagination-bullet.video-bullet {
        width: 12px;
        height: 12px;
        background: #e8a8a8 !important;
    }
    
    .swiper-pagination-bullet.video-bullet::before {
        font-size: 7px;
    }
    
    .swiper-pagination-bullet.video-bullet.swiper-pagination-bullet-active {
        background: #005349 !important;
        transform: scale(1.3);
    }
    
    .swiper-pagination-bullet.video-bullet.swiper-pagination-bullet-active::before {
        font-size: 8px;
    }
    
    .product-gallery-swiper .swiper-button-next,
    .product-gallery-swiper .swiper-button-prev {
        width: 36px;
        height: 36px;
        background: rgba(255, 255, 255, 0.9);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    }
    
    .product-gallery-swiper .swiper-button-next:after,
    .product-gallery-swiper .swiper-button-prev:after {
        font-size: 14px;
        font-weight: bold;
    }
    
    .product-gallery-swiper .swiper-button-prev {
        left: 10px !important;
        right: auto !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        margin: 0 !important;
    }

    .product-gallery-swiper .swiper-button-next {
        right: 10px !important;
        left: auto !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        margin: 0 !important;
    }
    
    .video-play-button svg {
        width: 50px;
        height: 50px;
    }
    
    .wc-lightbox-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 26px;
    }
    
    .wc-lightbox-thumbs {
        height: 60px;
        width: 95%;
        max-width: 400px;
        bottom: 10px;
    }
    
    .wc-lightbox-thumbs .swiper-slide {
        width: 60px;
        height: 60px;
    }
    
    .wc-lightbox-swiper {
        height: 80vh;
    }
    
    .wc-lightbox-image {
        max-height: 70vh;
    }
    
    .wc-lightbox-swiper .swiper-button-prev {
        left: 5px !important;
        width: 36px;
        height: 36px;
    }
    
    .wc-lightbox-swiper .swiper-button-next {
        right: 5px !important;
        width: 36px;
        height: 36px;
    }
    
    .wc-lightbox-swiper .swiper-button-prev:after,
    .wc-lightbox-swiper .swiper-button-next:after {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .swiper-pagination-bullet {
        width: 9px;
        height: 9px;
        background: #d0d0d0;
    }
    
    .swiper-pagination-bullet-active {
        background: #005349;
    }
    
    /* YouTube-style video bullet for mobile */
    .swiper-pagination-bullet.video-bullet {
        width: 12px !important;
        height: 8px !important;
        background: #FF0000 !important; /* YouTube red */
        border-radius: 3px !important;
    }
    
    .swiper-pagination-bullet.video-bullet::before {
        font-size: 7px;
        left: 51%;
    }
    
    .swiper-pagination-bullet.video-bullet.swiper-pagination-bullet-active {
        background: #005349; /* Brand color when active */
    }
    
    .swiper-pagination-bullet.video-bullet.swiper-pagination-bullet-active::before {
        font-size: 6px;
    }
    
    .video-play-button svg {
        width: 40px;
        height: 40px;
    }
}

/* Loading State */
.video-thumbnail-wrapper.loading {
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-thumbnail-wrapper.loading:before {
    content: "Loading video...";
    color: #666;
    font-size: 14px;
}

/* Smooth Transitions */
.swiper-slide {
    transition: all 0.3s ease;
}

/* Focus States for Accessibility */
.swiper-button-next:focus,
.swiper-button-prev:focus,
.video-thumbnail-wrapper:focus,
.gallery-thumb:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* Match WooCommerce default styling */
.woocommerce-product-gallery {
    position: relative;
}

.woocommerce-product-gallery .woocommerce-product-gallery__wrapper {
    position: relative;
}

/* Ensure proper aspect ratio for images - match WooCommerce default */
.gallery-slide-image {
    width: 100%;
    height: auto;
}

.gallery-slide-image .gallery-image {
    width: 100%;
    height: auto;
    max-width: 100%;
    display: block;
}

/* Make gallery fit content properly */
.product-gallery-swiper {
    position: relative;
}

.product-gallery-swiper .swiper-wrapper {
    align-items: flex-start;
}

.product-gallery-swiper .swiper-slide {
    height: auto;
}

/* Lightbox Styles */
.wc-lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
}

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

.wc-lightbox-swiper {
    width: 100%;
    max-width: 1200px;
    height: 90vh;
    position: relative;
}

.wc-lightbox-swiper .swiper-slide {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.wc-lightbox-image {
    max-width: 100%;
    max-height: 85vh;
    width: auto;
    height: auto;
    object-fit: contain;
    touch-action: pan-x pan-y pinch-zoom;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    cursor: zoom-in;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.wc-lightbox-image:active {
    cursor: grabbing;
}

.wc-lightbox-close {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: white;
    font-size: 30px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: all 0.3s ease;
    border-radius: 50%;
    z-index: 1000000;
}

.wc-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* Lightbox Navigation Buttons */
.wc-lightbox-swiper .swiper-button-next,
.wc-lightbox-swiper .swiper-button-prev {
    color: white;
    background: rgba(255, 255, 255, 0.2);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    position: absolute;
    top: 50% !important;
    margin-top: 0 !important;
    transform: translateY(-50%);
}

.wc-lightbox-swiper .swiper-button-prev {
    left: 10px !important;
    right: auto !important;
}

.wc-lightbox-swiper .swiper-button-next {
    right: 10px !important;
    left: auto !important;
}

.wc-lightbox-swiper .swiper-button-next:hover,
.wc-lightbox-swiper .swiper-button-prev:hover {
    background: rgba(255, 255, 255, 0.3);
}

.wc-lightbox-swiper .swiper-button-next:after,
.wc-lightbox-swiper .swiper-button-prev:after {
    font-size: 20px;
    font-weight: bold;
}

/* Lightbox Pagination */
.wc-lightbox-swiper .swiper-pagination {
    bottom: 20px;
}

.wc-lightbox-swiper .swiper-pagination-bullet {
    background: rgba(255, 255, 255, 0.5);
    width: 10px;
    height: 10px;
}

.wc-lightbox-swiper .swiper-pagination-bullet-active {
    background: #005349;
}

/* Lightbox Thumbnails */
.wc-lightbox-thumbs {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    height: 80px;
    z-index: 10;
}

.wc-lightbox-thumbs .swiper-slide {
    width: 80px;
    height: 80px;
    opacity: 0.5;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.wc-lightbox-thumbs .swiper-slide-thumb-active {
    opacity: 1;
}

.wc-lightbox-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
    border: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.wc-lightbox-thumbs .swiper-slide-thumb-active .wc-lightbox-thumb {
    border-color: #005349;
    border-width: 3px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .swiper-button-next,
    .swiper-button-prev {
        background: #000;
        border: 2px solid #fff;
        color: #fff;
    }
    
    .swiper-pagination-bullet {
        border: 1px solid #fff;
    }
    
    .gallery-thumb {
        border: 1px solid #333;
    }
}