/* Product Gallery — CSS scroll-snap carousel + native <dialog> lightbox. */

/* Gallery Container */

.rg-gallery {
    position: relative;
    max-width: 100%;
    margin-bottom: 1.5em;
    opacity: 1 !important;
}

/* Main Carousel */

.rg-gallery__carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    gap: 0;
    border-radius: 8px;
    background: #f8f8f8;
}

/* Hide scrollbar but keep functionality */
.rg-gallery__carousel::-webkit-scrollbar {
    display: none;
}

.rg-gallery__carousel {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.rg-gallery__carousel:focus-visible {
    outline: 2px solid #004E81;
    outline-offset: 2px;
    border-radius: 8px;
}

/* Slides */

.rg-gallery__slide {
    flex: 0 0 100%;
    width: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    position: relative;
    aspect-ratio: 4 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: zoom-in;
    background: #f8f8f8;
}

/* Video slides should not trigger lightbox */
.rg-gallery__slide--video {
    cursor: default;
}

.rg-gallery__image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
}

/* Single image gallery — no scroll needed */
.rg-gallery--single .rg-gallery__carousel {
    overflow: hidden;
}

/* Empty gallery placeholder — center WooCommerce placeholder image */
.rg-gallery--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 4 / 3;
    background: #f8f8f8;
    border-radius: 8px;
}

.rg-gallery--empty img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Thumbnails */

.rg-gallery__thumbs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.rg-gallery__thumb {
    position: relative;
    aspect-ratio: 4 / 3;
    border: 2px solid transparent;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    background: #f8f8f8;
    padding: 0;
    transition: border-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rg-gallery__thumb:hover {
    border-color: #999;
}

.rg-gallery__thumb--active {
    border-color: #004E81;
}

.rg-gallery__thumb:focus-visible {
    outline: 2px solid #004E81;
    outline-offset: 2px;
}

.rg-gallery__thumb-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    pointer-events: none;
}

/* Video thumbnail play icon overlay */
.rg-gallery__thumb-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0.85;
    z-index: 1;
}

/* Lightbox */

.rg-lightbox {
    border: none;
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    color: #fff;
    z-index: 999999;
}

.rg-lightbox::backdrop {
    background: rgba(0, 0, 0, 0.95);
}

.rg-lightbox[open] {
    display: flex;
    flex-direction: column;
}

.rg-lightbox__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    flex-shrink: 0;
}

.rg-lightbox__counter {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.8);
}

.rg-lightbox__close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
}

.rg-lightbox__close:hover {
    background: rgba(255, 255, 255, 0.15);
}

.rg-lightbox__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.rg-lightbox__body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0;
    padding: 0 48px 24px;
}

.rg-lightbox__content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.rg-lightbox__content img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.rg-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    z-index: 2;
}

.rg-lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.25);
}

.rg-lightbox__nav:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.rg-lightbox__nav--prev {
    left: 8px;
}

.rg-lightbox__nav--next {
    right: 8px;
}

/* Hide navigation for single-image galleries */
.rg-gallery--single .rg-lightbox__nav,
.rg-gallery--single .rg-lightbox__counter {
    display: none;
}

/* Video */

/* Video slide — 4:3 to match product images */
.rg-gallery__slide--video .rg-video-wrapper {
    aspect-ratio: 4 / 3;
    width: 100%;
    height: auto;
    margin: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Video poster in gallery context — contain to show full frame */
.rg-gallery__slide--video .rg-video-poster {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

/* iframe when video is playing */
.rg-gallery__slide--video .rg-video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Play button positioning in gallery */
.rg-gallery__slide--video .rg-play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 68px;
    height: 48px;
    z-index: 10;
    display: block;
}

/* Responsive */

/* Mobile: smaller thumbnail gap, smaller border-radius */
@media (max-width: 768px) {
    .rg-gallery__carousel {
        border-radius: 4px;
    }

    .rg-gallery__thumbs {
        gap: 6px;
        margin-top: 8px;
    }

    .rg-gallery__thumb {
        border-radius: 4px;
    }

    /* Lightbox navigation is larger on mobile for easier tapping */
    .rg-lightbox__body {
        padding: 0 8px 16px;
    }

    .rg-lightbox__nav {
        padding: 10px;
    }

    .rg-lightbox__nav--prev {
        left: 4px;
    }

    .rg-lightbox__nav--next {
        right: 4px;
    }
}

/* Desktop: Astra gives product image ~48% width, so gallery fits naturally */
@media (min-width: 922px) {
    .rg-gallery {
        margin-bottom: 0;
    }
}

/* Dark Mode + High Contrast */

@media (prefers-color-scheme: dark) {
    .rg-gallery__carousel,
    .rg-gallery__slide,
    .rg-gallery--empty,
    .rg-gallery__thumb {
        background: #0f172a;
    }

    .rg-gallery__thumb {
        border-color: #334155;
    }

    .rg-gallery__thumb:hover,
    .rg-gallery__thumb--active {
        border-color: #93c5fd;
    }

    .rg-gallery__carousel:focus-visible,
    .rg-gallery__thumb:focus-visible {
        outline-color: #93c5fd;
    }
}

@media (forced-colors: active) {
    .rg-gallery__thumb,
    .rg-gallery__carousel {
        border: 1px solid CanvasText;
    }

    .rg-gallery__carousel:focus-visible,
    .rg-gallery__thumb:focus-visible,
    .rg-lightbox__close:focus-visible,
    .rg-lightbox__nav:focus-visible {
        outline: 2px solid Highlight;
        outline-offset: 2px;
    }
}
