/**
 * WC Bricks Product Gallery — front-end styles.
 *
 * The element exposes every value below as a CSS custom property set
 * inline by the PHP renderer (see class-element.php render()). The Bricks
 * editor's controls just feed those variables — there are no hard-coded
 * sizes / colors here, so what you tweak in Bricks is what you get on
 * the front end.
 *
 * Layout: thumbnails column on the left, large main image on the right.
 * The `.wbg-gallery--reverse` modifier flips the order (thumbs on the
 * right). On mobile the layout stacks vertically (main image on top,
 * thumbnails below) by default.
 */

/* --------------------------------------------------------------------- */
/* Root container                                                         */
/* --------------------------------------------------------------------- */

.wbg-gallery {
        display: flex;
        flex-direction: row;
        align-items: stretch;
        gap: var(--wbg-gap, 16px);
        width: 100%;
        position: relative;
        box-sizing: border-box;
}

.wbg-gallery--reverse {
        flex-direction: row-reverse;
}

.wbg-gallery * {
        box-sizing: border-box;
}

.wbg-gallery--empty {
        padding: 24px;
        background: #F8F8F8;
        color: #777;
        text-align: center;
        font-size: 14px;
        border: 1px dashed #DDD;
}

/* --------------------------------------------------------------------- */
/* Thumbnails column                                                      */
/* --------------------------------------------------------------------- */

.wbg-gallery__thumbs {
        display: flex;
        flex-direction: column;
        gap: var(--wbg-thumb-gap, 12px);
        flex: 0 0 var(--wbg-thumb-width, 88px);
        width: var(--wbg-thumb-width, 88px);
        /* Allow vertical scroll if there are many thumbnails. */
        overflow-y: auto;
        overflow-x: hidden;
        max-height: 100%;
        /* Thin, unobtrusive scrollbar. */
        scrollbar-width: thin;
        scrollbar-color: #DDD transparent;
        -webkit-overflow-scrolling: touch;
        padding-right: 2px;
}

.wbg-gallery__thumbs::-webkit-scrollbar {
        width: 6px;
}

.wbg-gallery__thumbs::-webkit-scrollbar-track {
        background: transparent;
}

.wbg-gallery__thumbs::-webkit-scrollbar-thumb {
        background: #DDD;
        border-radius: 3px;
}

.wbg-gallery__thumb {
        position: relative;
        display: block;
        width: var(--wbg-thumb-width, 88px);
        height: var(--wbg-thumb-width, 88px);
        padding: 0;
        border: var(--wbg-thumb-border-w, 1px) solid var(--wbg-thumb-border-c, #E5E5E5);
        border-radius: var(--wbg-thumb-radius, 0);
        background: #FFF;
        cursor: pointer;
        outline: none;
        opacity: var(--wbg-inactive-opacity, 1);
        transition: opacity .15s ease, transform .15s ease, border-color .15s ease, box-shadow .15s ease;
        flex: 0 0 auto;
        overflow: hidden;
}

.wbg-gallery__thumb img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
        pointer-events: none;
}

/* Hover state — small lift, stronger border. */
.wbg-gallery__thumb:hover {
        border-color: var(--wbg-active-border-c, #111111);
        opacity: 1;
}

.wbg-gallery__thumb:focus-visible {
        border-color: var(--wbg-active-border-c, #111111);
        box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
        opacity: 1;
}

/* Active state — solid border, full opacity. */
.wbg-gallery__thumb.is-active {
        border-width: var(--wbg-active-border-w, 2px);
        border-color: var(--wbg-active-border-c, #111111);
        opacity: 1;
}

/* Hover scale on the thumbnail image (not the button) so the border
   stays put. */
.wbg-gallery__thumb img {
        transition: transform .15s ease;
}

.wbg-gallery__thumb:hover img {
        transform: scale(1.04);
}

/* --------------------------------------------------------------------- */
/* Main image                                                             */
/* --------------------------------------------------------------------- */

.wbg-gallery__main {
        position: relative;
        flex: 1 1 auto;
        min-width: 0;
        background: var(--wbg-main-bg, #FFFFFF);
        border: var(--wbg-main-border-w, 0px) solid var(--wbg-main-border-c, #E5E5E5);
        border-radius: var(--wbg-main-radius, 0);
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        aspect-ratio: var(--wbg-aspect-ratio, auto);
}

/* Aspect ratio fallback for older browsers / "auto" value. */
.wbg-gallery__main[style*="aspect-ratio:auto"],
.wbg-gallery__main {
        min-height: 320px;
}

.wbg-gallery__main-img {
        display: block;
        max-width: 100%;
        max-height: 100%;
        width: 100%;
        height: 100%;
        object-fit: var(--wbg-object-fit, cover);
        object-position: center;
        transition: transform .25s ease, opacity .15s ease;
}

/* When zoom on hover is enabled, the image grows inside the container. */
.wbg-gallery--zoom .wbg-gallery__main-img {
        cursor: zoom-in;
}

.wbg-gallery--zoom .wbg-gallery__main:hover .wbg-gallery__main-img {
        transform: scale(var(--wbg-zoom-level, 1.6));
}

/* Sale flash badge. */
.wbg-gallery__sale-flash {
        position: absolute;
        top: 12px;
        left: 12px;
        padding: 4px 10px;
        background: #C9A55A;
        color: #FFF;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        border-radius: 0;
        pointer-events: none;
        z-index: 2;
}

/* Lightbox trigger button. */
.wbg-gallery__lightbox-btn {
        position: absolute;
        bottom: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        background: rgba(255, 255, 255, 0.9);
        color: #111;
        border: 0;
        border-radius: 50%;
        cursor: pointer;
        opacity: 0;
        transition: opacity .15s ease, background .15s ease;
        z-index: 2;
}

.wbg-gallery__main:hover .wbg-gallery__lightbox-btn {
        opacity: 1;
}

.wbg-gallery__lightbox-btn:hover {
        background: #FFF;
}

/* --------------------------------------------------------------------- */
/* Responsive — stack vertically on small screens                         */
/* --------------------------------------------------------------------- */

/* Default breakpoint is 768px — overridden inline by the element if the
   user picks a different value in the editor. We use a CSS media query
   that is generic enough to work out of the box, and the inline
   `--wbg-mobile-bp` variable is read by JS to toggle the class. */
.wbg-gallery.is-stacked {
        flex-direction: column;
}

.wbg-gallery.is-stacked .wbg-gallery__thumbs {
        flex-direction: row;
        flex: 0 0 auto;
        width: 100%;
        max-height: none;
        overflow-x: auto;
        overflow-y: hidden;
}

.wbg-gallery.is-stacked .wbg-gallery__thumb {
        flex: 0 0 auto;
}

.wbg-gallery.is-stacked .wbg-gallery__main {
        min-height: 280px;
}

/* --------------------------------------------------------------------- */
/* Lightbox overlay (rendered into <body> by JS)                          */
/* --------------------------------------------------------------------- */

.wbg-lightbox {
        position: fixed;
        inset: 0;
        z-index: 999999;
        background: rgba(0, 0, 0, 0.92);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 24px;
        opacity: 0;
        visibility: hidden;
        transition: opacity .2s ease;
}

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

.wbg-lightbox__img {
        max-width: 90vw;
        max-height: 90vh;
        object-fit: contain;
        display: block;
        box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.wbg-lightbox__close {
        position: absolute;
        top: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
        background: transparent;
        color: #FFF;
        border: 0;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
}

.wbg-lightbox__close:hover {
        opacity: 0.8;
}

.wbg-lightbox__prev,
.wbg-lightbox__next {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 56px;
        height: 56px;
        background: transparent;
        color: #FFF;
        border: 0;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 28px;
}

.wbg-lightbox__prev {
        left: 16px;
}

.wbg-lightbox__next {
        right: 16px;
}

.wbg-lightbox__prev:hover,
.wbg-lightbox__next:hover {
        opacity: 0.8;
}
