/* ==========================================================
   POST GALLERY WIDGET
   ========================================================== */

/* ── Page layout guard ────────────────────────────────────────
   A grid track of `1fr` has min-width:auto, so the flex track of Swiper
   (slides with intrinsic image sizes) used to blow the whole article up
   to the max layout width on mobile. Let the column shrink instead. */
.layout__grid > main,
.layout__grid > aside {
    min-width: 0;
}

/* ── Wrapper ──────────────────────────────────────────────── */
.post-gallery {
    margin: 28px 0;
    border-radius: var(--r-md);
    overflow: hidden;
    border: 1px solid #e5e5e5;
    background: #fff;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* ── Header ───────────────────────────────────────────────── */
.post-gallery__head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--red-dark);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.post-gallery__head i {
    font-size: 15px;
}

/* ── Main swiper area ─────────────────────────────────────── */
.post-gallery__main {
    position: relative;
    background: #000;
    overflow: hidden;           /* clip the swiper-wrapper translate */
}

/* Swiper container must also clip — belt & braces */
.post-gallery__main .swiper {
    width: 100%;
    overflow: hidden;
}

/* Before JS init: slides must NOT stack vertically */
.post-gallery__main .swiper-wrapper {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
}

.post-gallery__main .swiper-slide {
    flex-shrink: 0;
    width: 100%;
    min-width: 0;               /* prevent flex blowout */
}

.post-gallery__main .swiper-slide img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
    cursor: zoom-in;
    max-width: 100%;            /* never exceed container */
}

/* ── Caption bar ──────────────────────────────────────────── */
.post-gallery__caption {
    background: #f7f7f7;
    color: #555;
    font-size: 13px;
    line-height: 1.5;
    padding: 7px 60px;
    text-align: center;
    min-height: 34px;
    border-top: 1px solid #eee;
}

.post-gallery__caption:empty {
    display: none;
}

/* ── Nav buttons ──────────────────────────────────────────── */
.post-gallery__prev,
.post-gallery__next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    transition: background .2s, opacity .2s;
    opacity: .7;
}

.post-gallery__prev { left: 10px; }
.post-gallery__next { right: 10px; }

.post-gallery__prev:hover,
.post-gallery__next:hover {
    background: var(--red-bright, #e74c3c);
    opacity: 1;
}

.post-gallery__prev.swiper-button-disabled,
.post-gallery__next.swiper-button-disabled {
    opacity: .2;
    pointer-events: none;
}

/* ── Photo counter ────────────────────────────────────────── */
.post-gallery__counter {
    position: absolute;
    bottom: 10px;
    right: 12px;
    z-index: 10;
    background: rgba(0, 0, 0, .5);
    color: rgba(255, 255, 255, .9);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    pointer-events: none;
}

/* ── Thumbnail strip ──────────────────────────────────────── */
.post-gallery__thumbs-wrap {
    padding: 8px 10px;
    background: #fff;
    border-top: 1px solid #eee;
}

.post-gallery__thumbs .swiper-slide {
    width: 68px !important;
    height: 48px;
    flex-shrink: 0;
    border-radius: var(--r-sm);
    overflow: hidden;
    cursor: pointer;
    opacity: .5;
    transition: opacity .2s, border-color .2s;
    border: 2px solid transparent;
}

.post-gallery__thumbs .swiper-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.post-gallery__thumbs .swiper-slide-thumb-active {
    opacity: 1;
    border-color: var(--amber, #f1a829);
}

.post-gallery__thumbs .swiper-slide:hover {
    opacity: .85;
}

/* ==========================================================
   LIGHTBOX
   ========================================================== */

.pg-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, .94);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.pg-lightbox.is-open {
    display: flex;
}

.pg-lightbox__img {
    max-width: min(94vw, 1200px);
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--r-md);
    user-select: none;
}

.pg-lightbox__cap {
    margin-top: 10px;
    color: rgba(255, 255, 255, .7);
    font-size: 13px;
    text-align: center;
    max-width: 680px;
    padding: 0 16px;
}

.pg-lightbox__close {
    position: fixed;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    opacity: .75;
    transition: opacity .2s;
    z-index: 1;
}

.pg-lightbox__close:hover { opacity: 1; }

.pg-lightbox__nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, .12);
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 12px 10px;
    border-radius: var(--r-md);
    transition: background .2s;
    z-index: 1;
}

.pg-lightbox__nav:hover { background: var(--red-bright, #e74c3c); }
.pg-lightbox__nav--prev { left: 12px; }
.pg-lightbox__nav--next { right: 12px; }

/* ==========================================================
   RESPONSIVE
   ========================================================== */

/* Tablet */
@media (max-width: 768px) {
    .post-gallery__caption {
        padding: 7px 50px;
        font-size: 12px;
    }

    .post-gallery__prev,
    .post-gallery__next {
        width: 32px;
        height: 32px;
        font-size: 15px;
        /* Always visible on touch devices */
        opacity: .75;
    }

    .post-gallery__prev { left: 8px; }
    .post-gallery__next { right: 8px; }

    .post-gallery__thumbs .swiper-slide {
        width: 58px !important;
        height: 42px;
    }

    .pg-lightbox__nav {
        font-size: 20px;
        padding: 10px 8px;
    }

    .pg-lightbox__nav--prev { left: 6px; }
    .pg-lightbox__nav--next { right: 6px; }
}

/* Mobile */
@media (max-width: 480px) {
    .post-gallery {
        margin: 20px 0;
        border-radius: var(--r-sm);
    }

    .post-gallery__main .swiper-slide img {
        aspect-ratio: 4 / 3;
    }

    .post-gallery__caption {
        padding: 6px 44px;
        font-size: 11.5px;
    }

    .post-gallery__prev,
    .post-gallery__next {
        width: 28px;
        height: 28px;
        font-size: 13px;
        opacity: .8;
    }

    .post-gallery__thumbs-wrap {
        padding: 6px 8px;
    }

    .post-gallery__thumbs .swiper-slide {
        width: 50px !important;
        height: 36px;
    }

    /* Hide lightbox side buttons on very small screens — swipe only */
    .pg-lightbox__nav {
        display: none;
    }

    .pg-lightbox__img {
        max-width: 98vw;
        max-height: 80vh;
    }
}
