/* CGB – Before & After Gallery */

.cgb-ba-gallery {
    padding: var(--cgb-section-space-y, 64px) 0;
    background: var(--cgb-light-bg, #f8fbfa);
    font-family: var(--cgb-body-font, var(--bodyfont, inherit));
    color: var(--cgb-main-gradient, #1a2f42);
    position: relative;
}

.cgb-ba-gallery .screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    -webkit-clip-path: inset(50%);
    clip-path: inset(50%);
    height: 1px;
    width: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    word-wrap: normal !important;
}

/* ── Header ── */
.cgb-ba-gallery__header {
    max-width: 720px;
    margin: 0 auto 40px;
    text-align: center;
}

.cgb-ba-gallery__eyebrow {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--cgb-main, var(--main-clr, #9a7099));
    margin-bottom: 12px;
}

.cgb-ba-gallery__heading {
    font-family: var(--cgb-heading-font, var(--headfont, inherit));
    font-size: var(--fs-36, 36px);
    line-height: 1.2;
    color: inherit;
    margin: 0 0 16px;
    padding: 0;
}

.cgb-ba-gallery__intro {
    font-size: 17px;
    line-height: 1.6;
    color: rgba(26, 47, 66, 0.75);
}

.cgb-ba-gallery__intro p {
    margin: 0 0 0.6em;
}

.cgb-ba-gallery__intro p:last-child {
    margin-bottom: 0;
}

/* ── Filter tabs ── */
.cgb-ba-gallery__filters {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin: 0 0 32px;
}

.cgb-ba-gallery__filter {
    display: inline-flex;
    align-items: center;
    padding: 10px 20px;
    font-family: var(--cgb-body-font, inherit);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    color: var(--cgb-main-gradient, #1a2f42);
    background: transparent;
    border: 1.5px solid rgba(26, 47, 66, 0.15);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.cgb-ba-gallery__filter:hover {
    border-color: var(--cgb-main, #9a7099);
    color: var(--cgb-main, #9a7099);
}

.cgb-ba-gallery__filter.is-active,
.cgb-ba-gallery__filter[aria-selected="true"] {
    color: #fff;
    background: var(--cgb-main, #9a7099);
    border-color: var(--cgb-main, #9a7099);
}

.cgb-ba-gallery__filter:focus-visible {
    outline: 2px solid var(--cgb-main, #9a7099);
    outline-offset: 2px;
}

/* ── Grid ── */
.cgb-ba-gallery__grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

.cgb-ba-gallery--cols-2 .cgb-ba-gallery__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cgb-ba-gallery--cols-4 .cgb-ba-gallery__grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 991px) {
    .cgb-ba-gallery__grid,
    .cgb-ba-gallery--cols-2 .cgb-ba-gallery__grid,
    .cgb-ba-gallery--cols-4 .cgb-ba-gallery__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 575px) {
    .cgb-ba-gallery__grid,
    .cgb-ba-gallery--cols-2 .cgb-ba-gallery__grid,
    .cgb-ba-gallery--cols-4 .cgb-ba-gallery__grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

.cgb-ba-gallery__item.is-hidden {
    display: none;
}

/* ── Card ── */
.cgb-ba-gallery__card {
    background: #fff;
    border-radius: var(--cgb-radius-lg, 20px);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(15, 36, 54, 0.06);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

.cgb-ba-gallery__item:hover .cgb-ba-gallery__card,
.cgb-ba-gallery__item:focus-within .cgb-ba-gallery__card {
    transform: translateY(-4px);
    box-shadow: 0 14px 36px rgba(15, 36, 54, 0.14);
}

/* Triggers (buttons) */
.cgb-ba-gallery__trigger {
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
    color: inherit;
    font: inherit;
    -webkit-appearance: none;
    appearance: none;
}

.cgb-ba-gallery__trigger--full {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.cgb-ba-gallery__trigger:focus-visible {
    outline: 2px solid var(--cgb-main, #9a7099);
    outline-offset: -2px;
}

/* Media */
.cgb-ba-gallery__media {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: #e8ecef;
}

/* Safe fallback for browsers without aspect-ratio support. */
@supports not (aspect-ratio: 1) {
    .cgb-ba-gallery__media::before {
        content: '';
        display: block;
        padding-top: 75%;
    }
    .cgb-ba-gallery__media > *:first-child {
        position: absolute;
        inset: 0;
    }
}

.cgb-ba-gallery__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cgb-ba-gallery__media--combined .cgb-ba-gallery__img {
    transition: transform 0.4s ease;
}

.cgb-ba-gallery__trigger--full:hover .cgb-ba-gallery__media--combined .cgb-ba-gallery__img {
    transform: scale(1.03);
}

/* Caption */
.cgb-ba-gallery__caption {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 20px 18px;
    text-align: left;
}

.cgb-ba-gallery__trigger--caption {
    margin-top: auto;
}

.cgb-ba-gallery__treatment {
    font-family: var(--cgb-heading-font, inherit);
    font-size: 16px;
    font-weight: 600;
    color: var(--cgb-main-gradient, #1a2f42);
    line-height: 1.3;
}

.cgb-ba-gallery__location {
    font-size: 13px;
    font-weight: 400;
    color: rgba(26, 47, 66, 0.6);
    line-height: 1.3;
}

/* ── Before/After Slider ── */
.cgb-ba-slider {
    --ba-reveal: 50%;
    position: relative;
    width: 100%;
    height: 100%;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-y;
    overflow: hidden;
}

.cgb-ba-slider.is-dragging {
    touch-action: none;
}

.cgb-ba-slider__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
    -webkit-user-drag: none;
}

.cgb-ba-slider__after-wrap {
    position: absolute;
    inset: 0;
    overflow: hidden;
    clip-path: inset(0 0 0 calc(100% - var(--ba-reveal)));
    -webkit-clip-path: inset(0 0 0 calc(100% - var(--ba-reveal)));
    will-change: clip-path;
}

.cgb-ba-slider__tag {
    position: absolute;
    top: 12px;
    padding: 4px 10px;
    font-family: var(--cgb-heading-font, inherit);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #fff;
    background: rgba(15, 36, 54, 0.65);
    border-radius: 999px;
    pointer-events: none;
}

.cgb-ba-slider__tag--before {
    left: 12px;
}

.cgb-ba-slider__tag--after {
    right: 12px;
}

.cgb-ba-slider__line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--ba-reveal);
    width: 2px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(15, 36, 54, 0.2);
    transform: translateX(-50%);
    pointer-events: none;
    will-change: left;
}

.cgb-ba-slider__handle {
    position: absolute;
    top: 50%;
    left: var(--ba-reveal);
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: var(--cgb-main-gradient, #1a2f42);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(15, 36, 54, 0.25), 0 0 0 1px rgba(15, 36, 54, 0.08);
    cursor: ew-resize;
    touch-action: none;
    will-change: left;
}

.cgb-ba-slider__handle:focus-visible {
    outline: 2px solid var(--cgb-main, #9a7099);
    outline-offset: 3px;
}

.cgb-ba-slider.is-dragging .cgb-ba-slider__line,
.cgb-ba-slider.is-dragging .cgb-ba-slider__handle,
.cgb-ba-slider.is-dragging .cgb-ba-slider__after-wrap {
    transition: none;
}

/* ── Footer CTA ── */
.cgb-ba-gallery__footer {
    text-align: center;
    margin-top: 40px;
}

.cgb-ba-gallery__cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* ── Lightbox ── */
.cgb-ba-gallery__lightbox {
    padding: 0;
    border: 0;
    background: transparent;
    max-width: min(960px, 92vw);
    max-height: 92vh;
    color: inherit;
}

.cgb-ba-gallery__lightbox::backdrop {
    background: rgba(15, 36, 54, 0.82);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.cgb-ba-gallery__lightbox[open] {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Fallback for browsers without dialog support (polyfilled via JS). */
.cgb-ba-gallery__lightbox.is-open-fallback {
    display: flex !important;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 36, 54, 0.82);
    max-width: none;
    max-height: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.cgb-ba-gallery__lightbox-inner {
    position: relative;
    width: 100%;
    max-width: 920px;
    background: #fff;
    border-radius: var(--cgb-radius-lg, 20px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.cgb-ba-gallery__lightbox-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    border: 0;
    border-radius: 50%;
    color: var(--cgb-main-gradient, #1a2f42);
    box-shadow: 0 2px 8px rgba(15, 36, 54, 0.18);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.cgb-ba-gallery__lightbox-close:hover {
    background: #fff;
}

.cgb-ba-gallery__lightbox-close:focus-visible {
    outline: 2px solid var(--cgb-main, #9a7099);
    outline-offset: 2px;
}

.cgb-ba-gallery__lightbox-media {
    background: #0f2436;
    max-height: 70vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.cgb-ba-gallery__lightbox-media img {
    max-width: 100%;
    max-height: 70vh;
    width: auto;
    height: auto;
    display: block;
}

.cgb-ba-gallery__lightbox-media .cgb-ba-slider {
    height: min(70vh, 600px);
}

.cgb-ba-gallery__lightbox-meta {
    padding: 20px 28px 24px;
}

.cgb-ba-gallery__lightbox-treatment {
    font-family: var(--cgb-heading-font, inherit);
    font-size: 18px;
    font-weight: 600;
    color: var(--cgb-main-gradient, #1a2f42);
    margin: 0 0 4px;
}

.cgb-ba-gallery__lightbox-location {
    font-size: 14px;
    color: rgba(26, 47, 66, 0.6);
    margin: 0 0 10px;
}

.cgb-ba-gallery__lightbox-location:empty {
    display: none;
}

.cgb-ba-gallery__lightbox-note {
    font-size: 15px;
    line-height: 1.5;
    color: var(--cgb-main-gradient, #1a2f42);
    margin: 0;
}

.cgb-ba-gallery__lightbox-note:empty {
    display: none;
}

/* ── Mobile adjustments ── */
@media (max-width: 767px) {
    .cgb-ba-gallery {
        padding: var(--cgb-section-space-y-mobile, 44px) 0;
    }

    .cgb-ba-gallery__header {
        margin-bottom: 28px;
    }

    .cgb-ba-gallery__heading {
        font-size: var(--fs-28, 28px);
    }

    .cgb-ba-gallery__filters {
        margin-bottom: 24px;
    }

    .cgb-ba-gallery__footer {
        margin-top: 28px;
    }

    .cgb-ba-gallery__lightbox-media {
        max-height: 55vh;
    }

    .cgb-ba-gallery__lightbox-media img {
        max-height: 55vh;
    }

    .cgb-ba-gallery__lightbox-media .cgb-ba-slider {
        height: 55vh;
    }

    .cgb-ba-gallery__lightbox-meta {
        padding: 16px 20px 20px;
    }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
    .cgb-ba-gallery__card,
    .cgb-ba-gallery__filter,
    .cgb-ba-gallery__media--combined .cgb-ba-gallery__img {
        transition: none !important;
    }
}
