/**
 * WebCreator - photo gallery with lightbox (markup: docs/page-editor-blocks.md)
 *
 * Loaded only on pages that contain a gallery (<figure class="wc-gallery">) or ContentBuilder photo links
 * (a.is-lightbox). Uses the colours and fonts of the theme through its CSS variables, with fallbacks.
 * Selectors are a little more specific than the .cb-content rules of content.css, which are loaded before this file.
 */

/* ---------- the grid ---------- */
.wc-gallery {
    --wc-gal-cols: 3;
    --wc-gal-gap: 0.75rem;
    display: grid;
    grid-template-columns: repeat(var(--wc-gal-cols), minmax(0, 1fr));
    gap: var(--wc-gal-gap);
    margin: 1.5rem 0;
    padding: 0;
}
.wc-gallery[data-wc-columns="2"] { --wc-gal-cols: 2; }
.wc-gallery[data-wc-columns="3"] { --wc-gal-cols: 3; }
.wc-gallery[data-wc-columns="4"] { --wc-gal-cols: 4; }
.wc-gallery[data-wc-gap="s"] { --wc-gal-gap: 0.25rem; }
.wc-gallery[data-wc-gap="m"] { --wc-gal-gap: 0.75rem; }
.wc-gallery[data-wc-gap="l"] { --wc-gal-gap: 1.5rem; }
@media (max-width: 40rem) {
    .wc-gallery[data-wc-columns="3"],
    .wc-gallery[data-wc-columns="4"] { --wc-gal-cols: 2; }
    .wc-gallery[data-wc-gap="l"] { --wc-gal-gap: 0.75rem; }
}

.wc-gallery .wc-gallery-item {
    margin: 0;
    min-width: 0;
}
.wc-gallery .wc-gallery-item > a {
    display: block;
    overflow: hidden;
    border-radius: var(--radius-md, 6px);
    background: var(--color-bg-tertiary, #f3f4f6);
    line-height: 0;
}
/* A fixed ratio: the grid has its final size before one image is loaded (no layout shift, also with 200 photos) */
.wc-gallery .wc-gallery-item img {
    display: block;
    width: 100%;
    height: auto;
    margin: 0;
    max-width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    transition: transform 0.25s ease;
}
@media (hover: hover) {
    .wc-gallery .wc-gallery-item > a:hover img { transform: scale(1.04); }
}
.wc-gallery .wc-gallery-item a:focus-visible {
    outline: 3px solid var(--wc-focus-ring, var(--color-primary, #27ae60));
    outline-offset: 2px;
}
/* the lightbox has its own near-black overlay (rgba(0,0,0,.95)): a white ring has 20:1 there, whatever the colours of the site */
.wc-lightbox button:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}
.wc-gallery .wc-gallery-item figcaption {
    margin: 0.4rem 0 0;
    font-size: var(--font-size-sm, 0.875rem);
    line-height: 1.4;
    color: var(--color-text-muted, #4b5563);
}
/* Captions off: they are still in the page (and in the lightbox), only not under the photos */
.wc-gallery[data-wc-captions="off"] .wc-gallery-item figcaption {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
    .wc-gallery .wc-gallery-item img { transition: none; }
    .wc-gallery .wc-gallery-item > a:hover img { transform: none; }
}

/* ---------- the lightbox (built by gallery.js) ---------- */
.wc-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.95);
    color: #fff;
    font-family: var(--font-family, system-ui, sans-serif);
    touch-action: pan-y pinch-zoom;
    animation: wc-lb-in 0.2s ease;
}
.wc-lightbox[hidden] { display: none; }
@keyframes wc-lb-in { from { opacity: 0; } to { opacity: 1; } }
.wc-lb-figure {
    margin: 0;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3.5rem 0.5rem 4.5rem;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
}
.wc-lb-image {
    display: block;
    max-width: 100%;
    min-height: 0;
    flex: 0 1 auto;
    object-fit: contain;
    margin: 0;
    border-radius: 2px;
}
.wc-lightbox.is-loading .wc-lb-image { opacity: 0.35; }
.wc-lb-caption {
    margin: 0.75rem 3.5rem 0;
    max-width: 60rem;
    text-align: center;
    font-size: 1rem;
    line-height: 1.45;
    color: #fff;
}
.wc-lb-caption:empty { display: none; }
.wc-lb-counter {
    position: absolute;
    top: 0;
    left: 0;
    padding: 1rem 1.25rem;
    font-size: 0.9375rem;
    font-variant-numeric: tabular-nums;
    color: #fff;
    pointer-events: none;
}
.wc-lb-close,
.wc-lb-prev,
.wc-lb-next {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}
.wc-lb-close:hover,
.wc-lb-prev:hover,
.wc-lb-next:hover { background: rgba(255, 255, 255, 0.28); }
.wc-lb-close { top: 0.5rem; right: 0.5rem; }
.wc-lb-prev,
.wc-lb-next { top: 50%; margin-top: -1.5rem; }
.wc-lb-prev { left: 0.5rem; }
.wc-lb-next { right: 0.5rem; }
.wc-lightbox.is-single .wc-lb-prev,
.wc-lightbox.is-single .wc-lb-next { display: none; }
.wc-lb-error { margin: 0 3.5rem; text-align: center; }
@media (max-width: 40rem) {
    /* On a phone the arrows sit at the bottom, so the photo can use the full width */
    .wc-lb-prev,
    .wc-lb-next { top: auto; bottom: 0.75rem; margin-top: 0; }
    .wc-lb-prev { left: calc(50% - 3.5rem); }
    .wc-lb-next { right: calc(50% - 3.5rem); }
    .wc-lb-caption { margin: 0.75rem 1rem 0; font-size: 0.9375rem; }
    .wc-lb-figure { padding-bottom: 5rem; }
}
@media (prefers-reduced-motion: reduce) {
    .wc-lightbox { animation: none; }
}
