.pswp {
    --pswp-bg: #f0f0f0;
    --pswp-icon-color: #000;
    --pswp-icon-color-secondary: transparent;
    --pswp-placeholder-bg: #222;
    --pswp-error-text-color: #ff0000;
}

.pswp__img {
    object-fit: contain;
}

.pswp__icn {
    color: #fff;
}

.pswp__zoom-level {
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    padding: 5px 10px;
    border-radius: 3px;
}

/* Gallery styles */
.image-gallery .swiper-slide img {
    height: 100%;
    width: 100%;
    object-fit: cover;
    border-radius: 10px;
    cursor: zoom-in;
}

.product-gallery-flex {
    display: flex;
}

.product-gallery-flex .product-gallery-thumb {
    width: calc(14% - 10px);
    margin: 0px;
    height: 600px;
}

.product-gallery-flex .product-gallery {
    width: calc(86% - 10px);
    height: 600px;
}

.thumbnail-image {
    filter: brightness(1);
    transition: all 0.3s ease-in-out;
}

.swiper-slide-thumb-active .thumbnail-image {
    filter: brightness(0.7);
    border: 1.5px solid #000 !important;
}

.grid-gallery-container {
    width: 100%;
    padding: 0;
    overflow: hidden;
    margin-bottom: 30px;
}

.grid-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto;
    gap: 15px;
    height: 100%;
    max-height: 600px;
    overflow: hidden;
}

/* Different layouts based on number of images */
.grid-gallery:has(.grid-gallery-item:nth-child(1):nth-last-child(1)) {
    grid-template-columns: 1fr;
}

.grid-gallery:has(.grid-gallery-item:nth-child(2):nth-last-child(1)) {
    grid-template-columns: repeat(2, 1fr);
}

.grid-gallery:has(.grid-gallery-item:nth-child(3):nth-last-child(1)) {
    grid-template-columns: repeat(2, 1fr);
}

.grid-gallery:has(.grid-gallery-item:nth-child(3):nth-last-child(1)) .grid-gallery-item:first-child {
    grid-column: 1 / 3;
}

.grid-gallery:has(.grid-gallery-item:nth-child(4):nth-last-child(1)) {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* For more than 4 images, show only first 4 */
.grid-gallery .grid-gallery-item.hidden-image {
    display: none;
}

.grid-gallery img {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 10px;
    border: 1px solid #ebebeb;
    object-fit: cover;
    transition: transform 0.3s ease-in-out, filter 0.3s ease;
}

.grid-gallery-item:hover img {
    transform: scale(1.03);
    filter: brightness(1.05);
}

.grid-gallery-item {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    height: 100%;
}

.more-images-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
}

.grid-swiper-gallery {
    display: none;
}

.bottom-flex {
    flex-direction: column;
}

.bottom-flex .product-gallery-thumb {
    width: 100%;
    height: 105px;
    margin-top: 15px;
}

.product-gallery-flex .swiper-button-next,
.product-gallery-flex .swiper-button-prev {
    background-color: white;
}

.product-gallery-flex .swiper-button-next::after,
.product-gallery-flex .swiper-button-prev::after {
    color: black;
}

@media (max-width: 776px) {
    .product-thumb-left-right {
        display: none !important;
    }

    .product-gallery {
        width: 100% !important;
    }

    .product-gallery-flex .product-gallery {
        height: 350px !important;
    }

    /* ONE slide fills the gallery — exactly one image at a time.
       The old `width: 80% !important` left a fifth of the NEXT image showing
       at the right edge, and — because Swiper still laid its slides out at
       100% (slidesGrid) while the browser rendered them at 80% — the last
       slide landed ~28px off the LEFT edge of the gallery, so the final image
       was sliced in half. Pinning the slides to the container width puts the
       rendered geometry back in step with Swiper's own: no peek, and the
       last slide lands flush. Scoped to `.product-gallery` so the thumbnail
       strip's slides are left alone. */
    .product-gallery-flex .product-gallery .swiper-slide {
        width: 100% !important;
    }

    /* Square frame. Product photos are square (the x-product-image component
       and PhotoSwipe's 1600x1600 defaults both assume it), so a square
       gallery fits the image edge to edge — no letterbox bars, no crop.
       Browsers without aspect-ratio support keep the 350px height above. */
    @supports (aspect-ratio: 1 / 1) {
        .product-gallery-flex .product-gallery {
            height: auto !important;
            aspect-ratio: 1 / 1;
        }
    }

    /* Never crop the picture itself: a size guide or an infographic has to
       be readable in full, not sliced to fit the frame. */
    .image-gallery .product-gallery .swiper-slide img {
        object-fit: contain;
    }

    .grid-gallery {
        grid-template-columns: 1fr !important;
        max-height: none;
        overflow: visible;
    }

    .grid-gallery-container {
        max-height: none;
        overflow: visible;
    }

    /* Override grid layouts for mobile */
    .grid-gallery:has(.grid-gallery-item:nth-child(3):nth-last-child(1)) .grid-gallery-item:first-child,
    .grid-gallery:has(.grid-gallery-item:nth-child(4):nth-last-child(1)) .grid-gallery-item:first-child {
        grid-column: 1 / 2;
    }

    .grid-gallery .grid-gallery-item {
        height: auto;
        min-height: 350px;
    }

    .bottom-flex .product-gallery-thumb {
        display: none;
    }

    .product-gallery-flex .swiper-button-next,
    .product-gallery-flex .swiper-button-prev {
        display: none;
    }
}

@media (min-width: 777px) and (max-width: 1024px) {
    .product-thumb-left-right {
        display: none !important;
    }

    .product-gallery {
        width: 100% !important;
    }

    .product-gallery-flex .product-gallery {
        height: 400px !important;
    }

    /* Same one-image-per-screen fix as the phone breakpoint: at 80% the next
       image peeked in at the right edge and the last slide was sliced off
       the left edge of the gallery. */
    .product-gallery-flex .product-gallery .swiper-slide {
        width: 100% !important;
    }

    .bottom-flex .product-gallery-thumb {
        display: none;
    }

    .product-gallery-flex .swiper-button-next,
    .product-gallery-flex .swiper-button-prev {
        display: none;
    }

    /* Grid gallery styles for tablets */
    .grid-gallery {
        grid-template-columns: repeat(2, 1fr);
        grid-gap: 15px;
        height: auto;
        max-height: 500px;
    }

    .grid-gallery .grid-gallery-item {
        height: auto;
        min-height: 250px;
    }

    .grid-gallery img {
        height: 100%;
        max-height: 400px;
    }
}