/* =====================================================================
   Projects Gallery  (#pg)
   Masonry via CSS columns. Section bg matches the footer (primary).
   Lightbox: 8/10 main image + 2/10 thumbnails column.
   ===================================================================== */

.pg {
    --pg-cols: 4;
    --pg-gap: 10px;
    background: var(--color-primary);
    padding: var(--space-16) 0;
}
.pg__inner {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding-left: var(--space-5);
    padding-right: var(--space-5);
}
.pg__heading {
    color: var(--color-white);
    text-align: center;
    font-size: clamp(1.5rem, 3vw, 2.1rem);
    font-weight: 700;
    margin: 0 0 var(--space-10);
}

/* ── Masonry grid (JS-balanced columns) ──
   CSS-masonry через column-count — надійно, без JS-вимірювань.
   Обкладинки будь-яких пропорцій пакуються у колонки. */
.pg__grid {
    column-count: var(--pg-cols, 4);
    column-gap: var(--pg-gap);
    opacity: 0;
    transition: opacity 0.4s ease;
}
.pg__grid.pg--ready { opacity: 1; }
.pg__grid[hidden] { display: none; }
@media (max-width: 1024px) { .pg__grid { column-count: 3; } }
@media (max-width: 720px)  { .pg__grid { column-count: 2; } }
@media (max-width: 440px)  { .pg__grid { column-count: 1; } }

/* Спінер поки галерея вантажиться */
.pg__loading {
    display: flex;
    justify-content: center;
    padding: var(--space-10) 0;
}
.pg__loading[hidden] { display: none; }
.pg__spinner {
    width: 38px;
    height: 38px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: pg-spin 0.8s linear infinite;
}
@keyframes pg-spin { to { transform: rotate(360deg); } }

.pg__item {
    position: relative;
    display: inline-block;
    width: 100%;
    margin: 0 0 var(--pg-gap);
    padding: 0;
    border: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.06);
    line-height: 0;
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.pg__item:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}
.pg__item:focus-visible {
    outline: 3px solid var(--color-white);
    outline-offset: 2px;
}
.pg__cover {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* Bottom gradient + title so multicolor photos stay readable */
.pg__caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 26px 14px 12px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.25;
    text-align: left;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.78) 0%, rgba(0, 0, 0, 0.45) 45%, rgba(0, 0, 0, 0) 100%);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}

/* =====================================================================
   Lightbox
   ===================================================================== */
.pg-lightbox[hidden] { display: none; }
.pg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2vh 2vw;
}
.pg-lightbox__overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 20, 25, 0.88);
    backdrop-filter: blur(2px);
}
.pg-lightbox__dialog {
    position: relative;
    z-index: 1;
    width: 96vw;
    max-width: 96vw;
    height: 96vh;
    max-height: 96vh;
    display: flex;
    flex-direction: column;
    background: var(--color-bg, #fff);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}
.pg-lightbox__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 14px 18px;
    background: var(--color-primary);
    color: #fff;
    flex: 0 0 auto;
}
.pg-lightbox__title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}
.pg-lightbox__close {
    border: 0;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background 0.2s ease;
}
.pg-lightbox__close:hover { background: rgba(255, 255, 255, 0.3); }

/* Body: 8/10 main + 2/10 thumbs */
.pg-lightbox__body {
    display: grid;
    grid-template-columns: 8fr 2fr;
    min-height: 0;
    flex: 1 1 auto;
}
.pg-lightbox__main {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0e1216;
    padding: 16px;
    min-height: 0;
}
.pg-lightbox__main-img {
    max-width: 100%;
    max-height: 84vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

/* ── Arrow buttons ── */
.pg-lightbox__arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    border: 0;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s ease, opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}
.pg-lightbox__arrow:hover { background: rgba(0,0,0,0.75); opacity: 1; }
.pg-lightbox__arrow--prev { left: 14px; }
.pg-lightbox__arrow--next { right: 14px; }
.pg-lightbox__arrow[disabled] { opacity: 0.18; pointer-events: none; }
.pg-lightbox__thumbs {
    overflow-y: auto;
    padding: 12px;
    background: var(--color-bg-soft, #fdfbf7);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.pg-lightbox__thumb {
    display: block;
    width: 100%;
    padding: 0;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    background: none;
    line-height: 0;
    transition: border-color 0.2s ease, opacity 0.2s ease;
    opacity: 0.7;
}
.pg-lightbox__thumb img {
    width: 100%;
    height: 84px;
    object-fit: cover;
    display: block;
}
.pg-lightbox__thumb:hover { opacity: 1; }
.pg-lightbox__thumb.is-active {
    border-color: var(--color-primary);
    opacity: 1;
}

/* Mobile: stack — main on top, thumbs as a horizontal strip below */
@media (max-width: 700px) {
    .pg-lightbox { padding: 0; }
    .pg-lightbox__dialog { max-height: 100vh; height: 100vh; border-radius: 0; }
    .pg-lightbox__body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
    .pg-lightbox__main-img { max-height: 60vh; }
    .pg-lightbox__thumbs {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }
    .pg-lightbox__thumb { flex: 0 0 96px; }
    .pg-lightbox__thumb img { height: 64px; }
}

/* Lock background scroll when lightbox open */
body.pg-lb-open { overflow: hidden; }
