/* CVG Gallery – Frontend Styles */

/* -----------------------------------------------------------------------
   Grid
----------------------------------------------------------------------- */

.cvg-gallery {
    display: grid;
    gap: 10px;
    margin: 2rem 0 1rem 0;
    list-style: none;
    padding: 0;
}

/* Without crop: grid items don't stretch to row height, so the caption
   absolute-bottom aligns with the actual image bottom, not empty space. */
.cvg-gallery:not(.cvg-gallery--crop) {
    align-items: start;
}

.cvg-gallery--cols-1 { grid-template-columns: 1fr; }
.cvg-gallery--cols-2 { grid-template-columns: repeat(2, 1fr); }
.cvg-gallery--cols-3 { grid-template-columns: repeat(3, 1fr); }
.cvg-gallery--cols-4 { grid-template-columns: repeat(4, 1fr); }
.cvg-gallery--cols-5 { grid-template-columns: repeat(5, 1fr); }
.cvg-gallery--cols-6 { grid-template-columns: repeat(6, 1fr); }

/* -----------------------------------------------------------------------
   Gallery item
----------------------------------------------------------------------- */

.cvg-gallery__item {
    margin: 0;
    position: relative; /* needed for absolute caption overlay */
    overflow: hidden;
    background: transparent;
}

/* -----------------------------------------------------------------------
   Trigger button (wraps the thumbnail)
----------------------------------------------------------------------- */

.cvg-gallery__trigger {
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    -webkit-appearance: none;
    appearance: none;
}

.cvg-gallery__trigger:focus-visible {
    outline: 3px solid var(--color-light-blue, #1497f9);
    outline-offset: 2px;
}

/* -----------------------------------------------------------------------
   Thumbnail image
----------------------------------------------------------------------- */

.cvg-gallery__img {
    display: block;
    width: 100%;
    height: auto;
    transition: transform 0.35s ease;
}

.cvg-gallery__trigger:hover .cvg-gallery__img,
.cvg-gallery__trigger:focus-visible .cvg-gallery__img {
    transform: scale(1.05);
}

/* -----------------------------------------------------------------------
   Zoom icon overlay
----------------------------------------------------------------------- */

.cvg-gallery__overlay-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.7);
    font-size: 2.75rem !important;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

.cvg-gallery__trigger:hover .cvg-gallery__overlay-icon,
.cvg-gallery__trigger:focus-visible .cvg-gallery__overlay-icon {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* -----------------------------------------------------------------------
   Caption
----------------------------------------------------------------------- */

.cvg-gallery__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--color-white, #fff);
    background: rgba(52, 53, 77, 0.72);
}

/* -----------------------------------------------------------------------
   Lightbox backdrop
----------------------------------------------------------------------- */

.cvg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cvg-lightbox[hidden] {
    display: none;
}

/* -----------------------------------------------------------------------
   Lightbox inner (image + caption)
----------------------------------------------------------------------- */

.cvg-lightbox__inner {
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

.cvg-lightbox__caption {
    margin: 0.75rem 0 0;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.9rem;
    text-align: center;
    max-width: 60ch;
}

/* -----------------------------------------------------------------------
   Close button
----------------------------------------------------------------------- */

.cvg-lightbox__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #fff;
    padding: 6px;
    line-height: 1;
    transition: color 0.2s;
    z-index: 1;
}

.cvg-lightbox__close:hover,
.cvg-lightbox__close:focus-visible {
    color: var(--color-light-blue, #1497f9);
}

.cvg-lightbox__close .material-icons {
    font-size: 2rem;
    display: block;
}

/* -----------------------------------------------------------------------
   Navigation arrows
----------------------------------------------------------------------- */

.cvg-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #fff;
    padding: 1rem 0.75rem;
    line-height: 1;
    transition: color 0.2s;
    z-index: 1;
}

.cvg-lightbox__nav:hover,
.cvg-lightbox__nav:focus-visible {
    color: var(--color-light-blue, #1497f9);
}

.cvg-lightbox__nav--prev { left: 0.75rem; }
.cvg-lightbox__nav--next { right: 0.75rem; }

.cvg-lightbox__nav .material-icons {
    font-size: 2.75rem;
    display: block;
}

/* -----------------------------------------------------------------------
   Counter (e.g. "3 / 12")
----------------------------------------------------------------------- */

.cvg-lightbox__counter {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.8rem;
    white-space: nowrap;
}

/* -----------------------------------------------------------------------
   Responsive breakpoints
----------------------------------------------------------------------- */

@media (max-width: 900px) {
    .cvg-gallery--cols-5,
    .cvg-gallery--cols-6 {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 640px) {
    .cvg-gallery--cols-3,
    .cvg-gallery--cols-4,
    .cvg-gallery--cols-5,
    .cvg-gallery--cols-6 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 380px) {
    .cvg-gallery--cols-2,
    .cvg-gallery--cols-3,
    .cvg-gallery--cols-4,
    .cvg-gallery--cols-5,
    .cvg-gallery--cols-6 {
        grid-template-columns: 1fr;
    }

    .cvg-lightbox__nav--prev { left: 0.25rem; }
    .cvg-lightbox__nav--next { right: 0.25rem; }

    .cvg-lightbox__nav .material-icons {
        font-size: 2rem;
    }
}

/* -----------------------------------------------------------------------
   Crop mode (.cvg-gallery--crop)
   --cvg-crop-ratio is set inline by PHP, e.g. "3 / 2" or "16 / 9".

   Key idea: the <figure> defines the aspect-ratio and clips overflow.
   The trigger fills the entire figure absolutely so the image covers it.
   The caption is absolutely overlaid at the bottom – it never adds to the
   item height, so rows with mixed captions / no captions stay uniform.
----------------------------------------------------------------------- */

.cvg-gallery--crop .cvg-gallery__item {
    position: relative;
    aspect-ratio: var(--cvg-crop-ratio, 3 / 2);
    overflow: hidden;
}

/* Trigger fills the figure completely */
.cvg-gallery--crop .cvg-gallery__trigger {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* Image covers the trigger area – cropped, not letter-boxed */
.cvg-gallery--crop .cvg-gallery__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Zoom icon stays centered over the image (inherits from base) */

/* -----------------------------------------------------------------------
   Mobile Swiper
----------------------------------------------------------------------- */

.cvg-gallery-swiper-wrapper {
    position: relative;
}

/* Inner wrapper is layout-transparent on desktop (grid works as before) */
.cvg-gallery__swiper-inner {
    display: contents;
}

/* Swiper controls – hidden on desktop */
.cvg-gallery__swiper-controls {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0 0.5rem;
}

.cvg-gallery__swiper-prev,
.cvg-gallery__swiper-next {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--color-font, #34354d);
    padding: 0.25rem;
    line-height: 1;
}

.cvg-gallery__swiper-prev:hover,
.cvg-gallery__swiper-next:hover {
    color: var(--color-light-blue, #1497f9);
}

.cvg-gallery__swiper-prev .material-icons,
.cvg-gallery__swiper-next .material-icons {
    font-size: 24px;
    display: block;
}

.cvg-gallery__swiper-pagination {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    flex: 1;
}

.cvg-gallery__swiper-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(52, 53, 77, 0.25);
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.cvg-gallery__swiper-dot.active {
    background: var(--color-font, #34354d);
}

@media (max-width: 768px) {
    /* Swiper only active when crop mode is enabled */
    .cvg-gallery--crop {
        display: block;
        overflow: hidden;
    }

    .cvg-gallery--crop .cvg-gallery__swiper-inner {
        display: flex;
        will-change: transform;
        touch-action: pan-y;
    }

    .cvg-gallery--crop .cvg-gallery__swiper-inner .cvg-gallery__item {
        min-width: 100%;
        flex: 0 0 auto;
    }

    /* Show controls only when crop is active */
    .cvg-gallery-swiper-wrapper:has(.cvg-gallery--crop) .cvg-gallery__swiper-controls {
        display: flex;
    }
}

/* -----------------------------------------------------------------------
   Hint – shown on mobile when crop is disabled (admin only via PHP)
----------------------------------------------------------------------- */

.cvg-gallery__swiper-hint {
    display: none;
}

@media (max-width: 768px) {
    .cvg-gallery__swiper-hint {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        margin: 0.5rem 0 1rem;
        padding: 0.5rem 0.75rem;
        background: rgba(20, 151, 249, 0.1);
        border-left: 3px solid var(--color-light-blue, #1497f9);
        font-size: 0.8rem;
        color: var(--color-font, #34354d);
        border-radius: 0 4px 4px 0;
    }

    .cvg-gallery__swiper-hint .material-icons {
        font-size: 1rem;
        color: var(--color-light-blue, #1497f9);
        flex-shrink: 0;
    }
}