/* ============================================================
   GEMINI PRODUCT GALLERY — v1.1.3
   - Desktop (>768px): 2-column uniform grid, no slider, no thumbnails
   - Mobile (≤768px):  FlexSlider single-image view + dot navigation
   - Video support at configurable position
   ============================================================ */

/* ── Base ────────────────────────────────────────────────── */
.brxe-product-gallery *,
.brxe-product-gallery *::before,
.brxe-product-gallery *::after {
    box-sizing: border-box;
}

/* ── Thumbnails — hidden on all viewports ────────────────── */
.brx-product-gallery-thumbnail-slider,
.brxe-product-gallery .flex-control-nav,
.brxe-product-gallery .flex-control-thumbs,
.brxe-product-gallery .flex-control-nav.flex-control-thumbs {
    display: none !important;
}


/* ============================================================
   DESKTOP — 2-Column Grid (>768px)
   ============================================================ */
@media (min-width: 769px) {

    /* Remove FlexSlider viewport constraints */
    .brxe-product-gallery .flex-viewport {
        overflow: visible !important;
        height: auto !important;
        position: relative !important;
    }

    /* Convert the slider wrapper into a 2-column grid */
    .brxe-product-gallery .woocommerce-product-gallery__wrapper {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 4px !important;
        width: 100% !important;
        transform: none !important;
        transition: none !important;
    }

    /* Each gallery image container */
    .brxe-product-gallery .woocommerce-product-gallery__image {
        width: 100% !important;
        height: auto !important;
        float: none !important;
        margin: 0 !important;
        position: relative !important;
        overflow: hidden;
        aspect-ratio: 1 / 1;
        cursor: pointer;
        background: #f8f8f8;
    }

    .brxe-product-gallery .woocommerce-product-gallery__image a {
        display: block;
        width: 100%;
        height: 100%;
    }

    .brxe-product-gallery .woocommerce-product-gallery__image img {
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        object-fit: cover !important;
        transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        will-change: transform;
    }

    /* Hover zoom */
    .brxe-product-gallery .woocommerce-product-gallery__image:hover img {
        transform: scale(1.03);
    }

    /* Subtle dark overlay on hover */
    .brxe-product-gallery .woocommerce-product-gallery__image::after {
        content: '';
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0);
        transition: background 0.3s ease;
        pointer-events: none;
        z-index: 1;
    }

    .brxe-product-gallery .woocommerce-product-gallery__image:hover::after {
        background: rgba(0, 0, 0, 0.03);
    }

    /* Zoom / magnifier icon on hover */
    .brxe-product-gallery .woocommerce-product-gallery__image::before {
        content: '';
        position: absolute;
        bottom: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        z-index: 2;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 50%;
        opacity: 0;
        transform: scale(0.8);
        transition: opacity 0.3s ease, transform 0.3s ease;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3Cline x1='11' y1='8' x2='11' y2='14'/%3E%3Cline x1='8' y1='11' x2='14' y2='11'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: center;
        background-size: 18px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .brxe-product-gallery .woocommerce-product-gallery__image:hover::before {
        opacity: 1;
        transform: scale(1);
    }

    /* No hover UI on video slides */
    .brxe-product-gallery .woocommerce-product-gallery__image.gemini-video-slide::before,
    .brxe-product-gallery .woocommerce-product-gallery__image.gemini-video-slide::after {
        display: none !important;
    }

    /* Odd-count last image spans full width - DISABLED to keep all images same size */
    /* .brxe-product-gallery .woocommerce-product-gallery__image:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        max-height: 500px;
    } */

    /* Hide FlexSlider direction arrows on desktop */
    .brxe-product-gallery .flex-direction-nav {
        display: none !important;
    }

    /* Hide mobile-only UI on desktop */
    .gemini-gallery-dots,
    .gemini-gallery-counter {
        display: none !important;
    }
}


/* ============================================================
   MOBILE — Single Image + Dots (≤768px)
   FlexSlider handles slide transitions; we restyle navigation.
   ============================================================ */
@media (max-width: 768px) {

    /* Hide FlexSlider direction arrows on mobile */
    .brxe-product-gallery .flex-direction-nav {
        display: none !important;
    }

    /* padding-bottom pre-reserves exactly 48px for the dots strip before JS
       runs, so the injected .gemini-gallery-dots never shifts the page. */
    .brxe-product-gallery .woocommerce-product-gallery {
        position: relative;
        padding-bottom: 48px;
    }

    .brxe-product-gallery .woocommerce-product-gallery__image {
        cursor: pointer;
    }

    .brxe-product-gallery .woocommerce-product-gallery__image img {
        width: 100%;
        height: auto;
        object-fit: cover;
    }

    /* ── Dot Pagination ──────────────────────────────── */

    /* Absolutely positioned inside the pre-reserved 48px padding area —
       no layout shift because the space already exists before JS injects this. */
    .gemini-gallery-dots {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 48px;
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 12px;
        margin: 0;
        padding: 0;
    }

    /* padding + background-clip gives a 24×24px tap target (WCAG 2.5.5)
       with an 8px visual dot. */
    .gemini-gallery-dot {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        border: none;
        padding: 8px;
        background: #ccc;
        background-clip: content-box;
        box-sizing: content-box;
        cursor: pointer;
        transition: background 0.3s ease, transform 0.3s ease;
        -webkit-appearance: none;
        appearance: none;
    }

    .gemini-gallery-dot.is-active {
        background: #333;
        background-clip: content-box;
    }

    .gemini-gallery-dot:focus-visible {
        outline: 2px solid #333;
        outline-offset: 2px;
    }

    /* ── Image Counter Badge ─────────────────────────── */

    /* bottom: 64px = 48px dots area + 16px gap above it */
    .gemini-gallery-counter {
        position: absolute;
        bottom: 64px;
        right: 12px;
        background: rgba(0, 0, 0, 0.55);
        color: #fff;
        font-size: 12px;
        font-weight: 500;
        padding: 4px 10px;
        border-radius: 12px;
        letter-spacing: 0.5px;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        z-index: 5;
        pointer-events: none;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
}


/* ============================================================
   VIDEO SLIDE — Shared desktop + mobile
   ============================================================ */
.gemini-video-slide {
    cursor: default !important;
    position: relative !important;
    overflow: hidden !important;
    aspect-ratio: 1 / 1;
    width: 100%;
}

.gemini-video-slide video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

@media (min-width: 769px) {
    .gemini-video-slide video {
        position: absolute;
        inset: 0;
    }
}


/* ============================================================
   LIGHTBOX — Fullscreen Image Viewer
   ============================================================ */
.gemini-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.gemini-lightbox.is-open {
    opacity: 1;
    visibility: visible;
}

.gemini-lightbox__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.gemini-lightbox__close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.gemini-lightbox__close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.gemini-lightbox__close:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 3px;
}

.gemini-lightbox__counter {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 500;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    z-index: 10;
    letter-spacing: 1px;
}

.gemini-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.gemini-lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: translateY(-50%) scale(1.08);
}

.gemini-lightbox__nav:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 3px;
}

.gemini-lightbox__prev { left: 16px; }
.gemini-lightbox__next { right: 16px; }

.gemini-lightbox__image-wrap {
    position: relative;
    z-index: 5;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-in;
    overflow: hidden;
}

.gemini-lightbox__image-wrap.is-zoomed {
    cursor: grab;
    overflow: auto;
}

.gemini-lightbox__image-wrap.is-zoomed:active {
    cursor: grabbing;
}

.gemini-lightbox__img,
.gemini-lightbox__video {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    transition: opacity 0.25s ease;
    user-select: none;
    -webkit-user-select: none;
}

.gemini-lightbox__img.is-loading {
    opacity: 0.4;
}

.gemini-lightbox__image-wrap.is-zoomed .gemini-lightbox__img {
    max-width: none;
    max-height: none;
    width: 150%;
    cursor: grab;
}

.gemini-lightbox__video {
    width: 80vw;
    max-width: 900px;
}

@media (max-width: 768px) {
    .gemini-lightbox__nav {
        display: none;
    }

    .gemini-lightbox__image-wrap {
        max-width: 100vw;
        max-height: 90vh;
    }

    .gemini-lightbox__video {
        width: 100vw;
    }
}


/* ── Accessibility — Reduced Motion ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .brxe-product-gallery .woocommerce-product-gallery__image img,
    .brxe-product-gallery .woocommerce-product-gallery__image::before,
    .brxe-product-gallery .woocommerce-product-gallery__image::after,
    .gemini-gallery-dot,
    .gemini-lightbox,
    .gemini-lightbox__img,
    .gemini-lightbox__close,
    .gemini-lightbox__nav {
        transition: none !important;
        animation: none !important;
    }

    .gemini-gallery-dot.is-active {
        transform: none !important;
    }
}
