/* =============================================================
   CPB Product Gallery  –  rewritten
   Replaces all previous .cpb-gallery-* / .cpb-product-main-image
   / .cpb-product-thumbnails / .cpb-lightbox-* blocks in style.css
   ============================================================= */

/* ── Shared wrapper ── */
.cpb-product-gallery {
    width: 100%;
    min-width: 0; /* prevents grid blowout */
}

/* ── Main image container (classic / left-thumb) ── */
.cpb-product-main-image {
    position: relative;
    width: 100%;
    background: var(--cpb-bg-alt, #f7f7f7);
    border-radius: var(--cpb-radius, 8px);
    overflow: hidden;
    line-height: 0;
}

.cpb-product-main-image img,
.cpb-main-product-img {
    width: 100%;
    height: auto;
    max-height: 520px;
    object-fit: contain;
    border-radius: var(--cpb-radius, 8px);
    display: block;
    transition: opacity 0.15s ease;
}

/* Fade transition when switching main image */
.cpb-main-product-img.cpb-main-img--fading {
    opacity: 0;
}

/* ── Thumbnails (classic – bottom row) ── */
.cpb-product-thumbnails {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.cpb-gallery-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    flex-shrink: 0;
    transition: border-color 0.2s ease, opacity 0.2s ease;
    background: var(--cpb-bg-alt, #f7f7f7);
    display: block;
}

.cpb-gallery-thumb:hover {
    border-color: var(--cpb-primary, #253993);
    opacity: 0.85;
}

.cpb-gallery-thumb--active {
    border-color: var(--cpb-primary, #253993);
}

/* ── Left-thumbnail layout ── */
.cpb-gallery-left-layout {
    display: grid;
    grid-template-columns: 84px 1fr;
    gap: 10px;
    align-items: start;
}

.cpb-gallery-vertical-thumbs {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    max-height: 520px;
    scrollbar-width: thin;
    scrollbar-color: var(--cpb-primary, #253993) transparent;
}

.cpb-gallery-vertical-thumbs::-webkit-scrollbar { width: 4px; }
.cpb-gallery-vertical-thumbs::-webkit-scrollbar-thumb {
    background: var(--cpb-primary, #253993);
    border-radius: 2px;
}

.cpb-gallery-vertical-thumbs .cpb-gallery-thumb {
    width: 100%;
    height: 72px;
}

/* ── Grid layout ── */
.cpb-gallery-grid-wrap {
    width: 100%;
}

.cpb-gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.cpb-gallery-grid-item {
    overflow: hidden;
    border-radius: var(--cpb-radius, 8px);
    cursor: zoom-in;
    background: var(--cpb-bg-alt, #f7f7f7);
    line-height: 0;
}

.cpb-gallery-grid-item--main {
    grid-column: 1 / -1;
}

.cpb-gallery-grid-img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    transition: transform 0.35s ease;
    aspect-ratio: 4 / 3;
}

.cpb-gallery-grid-item--main .cpb-gallery-grid-img {
    aspect-ratio: 16 / 9;
}

.cpb-gallery-grid-item:hover .cpb-gallery-grid-img {
    transform: scale(1.04);
}

/* ── Slider layout ── */
.cpb-gallery-slider {
    position: relative;
    border-radius: var(--cpb-radius, 8px);
    background: var(--cpb-bg-alt, #f7f7f7);
    overflow: hidden;
    user-select: none;
}

.cpb-gallery-slider-track {
    position: relative;
    width: 100%;
    overflow: hidden;
    line-height: 0;
}

/* Each slide */
.cpb-gallery-slide {
    display: none;
    position: absolute;
    inset: 0;
    transition: transform 0.35s ease, opacity 0.35s ease;
    opacity: 0;
    pointer-events: none;
}

.cpb-gallery-slide--visible {
    display: block;
}

.cpb-gallery-slide--active {
    display: block;
    position: relative;
    opacity: 1;
    pointer-events: auto;
}

/* Slide-in / slide-out animation classes */
.cpb-slide-enter--right {
    transform: translateX(100%);
    opacity: 0;
}

.cpb-slide-enter--left {
    transform: translateX(-100%);
    opacity: 0;
}

.cpb-gallery-slide--active:not(.cpb-slide-enter--right):not(.cpb-slide-enter--left) {
    transform: translateX(0);
    opacity: 1;
}

.cpb-slide-leave--left {
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    opacity: 0;
    display: block;
    transition: transform 0.35s ease, opacity 0.35s ease;
    pointer-events: none;
}

.cpb-slide-leave--right {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    opacity: 0;
    display: block;
    transition: transform 0.35s ease, opacity 0.35s ease;
    pointer-events: none;
}

.cpb-gallery-slide img {
    width: 100%;
    height: auto;
    max-height: 520px;
    object-fit: contain;
    display: block;
}

/* Arrow buttons */
.cpb-gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    border: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cpb-text, #1a1a2e);
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
    line-height: 1;
}

.cpb-gallery-arrow:hover {
    background: var(--cpb-primary, #253993);
    color: #fff;
    transform: translateY(-50%) scale(1.08);
}

.cpb-gallery-arrow--prev { left: 12px; }
.cpb-gallery-arrow--next { right: 12px; }

/* Dots */
.cpb-gallery-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 12px 0 8px;
}

.cpb-gallery-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ccc;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    border: none;
    padding: 0;
}

.cpb-gallery-dot--active,
.cpb-gallery-dot:hover {
    background: var(--cpb-primary, #253993);
    transform: scale(1.25);
}

/* ── Lightbox ── */
.cpb-lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: pointer;
    animation: cpbLightboxIn 0.25s ease forwards;
}

.cpb-lightbox-overlay--closing {
    animation: cpbLightboxOut 0.25s ease forwards;
}

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

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

.cpb-lightbox-inner {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
}

.cpb-lightbox-img {
    max-width: min(90vw, 1200px);
    max-height: 88vh;
    object-fit: contain;
    border-radius: var(--cpb-radius, 8px);
    cursor: default;
    display: block;
    transition: opacity 0.2s ease;
}

.cpb-lightbox-img--loading {
    opacity: 0.2;
}

.cpb-lightbox-close {
    position: fixed;
    top: 16px;
    right: 20px;
    font-size: 2.2rem;
    line-height: 1;
    color: #fff;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s ease, transform 0.2s ease;
    z-index: 100000;
}

.cpb-lightbox-close:hover {
    color: #f0f0f0;
    transform: scale(1.15);
}

.cpb-lightbox-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.3rem;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 100000;
}

.cpb-lightbox-arrow:hover { background: rgba(255, 255, 255, 0.3); }
.cpb-lightbox-arrow--prev { left: 16px; }
.cpb-lightbox-arrow--next { right: 16px; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .cpb-gallery-thumb { width: 62px; height: 62px; }
    .cpb-gallery-vertical-thumbs .cpb-gallery-thumb { height: 62px; }
    .cpb-gallery-slide img,
    .cpb-product-main-image img,
    .cpb-main-product-img { max-height: 420px; }
}

@media (max-width: 600px) {
    /* Left-thumb: stack vertically (thumbs below main) */
    .cpb-gallery-left-layout {
        grid-template-columns: 1fr;
    }

    .cpb-gallery-vertical-thumbs {
        flex-direction: row;
        flex-wrap: wrap;
        overflow-y: visible;
        max-height: none;
        order: 2;
    }

    .cpb-gallery-vertical-thumbs .cpb-gallery-thumb {
        width: 58px;
        height: 58px;
    }

    .cpb-gallery-left-layout .cpb-product-main-image {
        order: 1;
    }

    /* Classic thumbs smaller */
    .cpb-gallery-thumb { width: 58px; height: 58px; }

    /* Grid: single column on very small */
    .cpb-gallery-grid { grid-template-columns: 1fr; gap: 6px; }
    .cpb-gallery-grid-item--main { grid-column: auto; }

    /* Slider */
    .cpb-gallery-slide img,
    .cpb-product-main-image img,
    .cpb-main-product-img { max-height: 300px; }
    .cpb-gallery-arrow { width: 36px; height: 36px; font-size: 1rem; }
    .cpb-gallery-arrow--prev { left: 8px; }
    .cpb-gallery-arrow--next { right: 8px; }
    .cpb-gallery-dot { width: 8px; height: 8px; }

    /* Lightbox arrows – hide on very small (swipe instead) */
    .cpb-lightbox-arrow { display: none; }
    .cpb-lightbox-img { max-width: 96vw; max-height: 80vh; }
}
