/* ============================================================
   Image gallery + lightbox
   ------------------------------------------------------------
   Used by content galleries in .mpf-prose (markup: a
   .mpf-gallery wrapper with .mpf-gallery__item anchors, each
   holding one <img>). Replaces the Elementor gallery widget,
   whose lightbox left the page when the builder was removed.
   Enqueued conditionally from inc/enqueue.php.
   ============================================================ */

.mpf-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
    margin: 1.4em 0;
    list-style: none;
    padding: 0;
}

.mpf-gallery__item {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: var(--mpf-radius-sm);
    background: var(--mpf-bg-alt);
    line-height: 0;
    text-decoration: none;
}

.mpf-gallery__item img {
    display: block;
    width: 100%;
    height: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    /* Beat .mpf-prose img, which adds vertical margin and its own radius. */
    margin: 0;
    border-radius: 0;
    transition: transform .35s ease;
}

.mpf-gallery__item:hover img,
.mpf-gallery__item:focus-visible img { transform: scale(1.05); }

.mpf-gallery__item:focus-visible {
    outline: 3px solid var(--mpf-blue);
    outline-offset: 2px;
}

/* Magnifier badge, so it reads as "click to enlarge". */
.mpf-gallery__item::after {
    content: "";
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(37, 64, 111, .85) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5 21 21M10.5 7.5v6M7.5 10.5h6'/%3E%3C/svg%3E") center / 17px 17px no-repeat;
    opacity: 0;
    transition: opacity .2s ease;
    pointer-events: none;
}

.mpf-gallery__item:hover::after,
.mpf-gallery__item:focus-visible::after { opacity: 1; }

/* ------------------------------------------------------------
   Lightbox (built by assets/gallery.js)
   ------------------------------------------------------------ */

.mpf-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(20, 32, 56, .93);
    opacity: 0;
    transition: opacity .2s ease;
}

.mpf-lightbox.is-open { opacity: 1; }

.mpf-lightbox__figure {
    margin: 0;
    max-width: min(1100px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.mpf-lightbox__img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    border-radius: var(--mpf-radius-sm);
    background: #fff;
}

.mpf-lightbox__caption {
    color: #fff;
    font-size: .95rem;
    text-align: center;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

.mpf-lightbox__btn {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    cursor: pointer;
    transition: background .15s ease;
}

.mpf-lightbox__btn:hover { background: rgba(255, 255, 255, .28); }
.mpf-lightbox__btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.mpf-lightbox__btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.mpf-lightbox__close { top: 16px; right: 16px; }
.mpf-lightbox__prev  { left: 16px;  top: 50%; transform: translateY(-50%); }
.mpf-lightbox__next  { right: 16px; top: 50%; transform: translateY(-50%); }

.mpf-lightbox__count {
    position: absolute;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, .75);
    font-size: .85rem;
    letter-spacing: .06em;
}

@media (max-width: 600px) {
    .mpf-lightbox { padding: 12px; }
    .mpf-lightbox__prev { left: 8px; }
    .mpf-lightbox__next { right: 8px; }
    .mpf-lightbox__img { max-height: calc(100vh - 160px); }
}

@media (prefers-reduced-motion: reduce) {
    .mpf-gallery__item img,
    .mpf-lightbox { transition: none; }
    .mpf-gallery__item:hover img { transform: none; }
}
