/* =====================================================================
   Service Detail — Project Gallery ("Our Recent Works")
   Below the hero/CTA block on pages/service-details.php. Server-side
   omits the whole section when a service has no gallery images yet
   (see pages/service-details.php) rather than rendering empty/
   placeholder tiles — so every rule below only ever needs to describe
   a grid that actually has images in it.
   ===================================================================== */

.gallery__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-lg);
    /* Same soft cap as .services__grid/.why-choose__grid — keeps tiles
       from ballooning on ultrawide monitors now the page itself has no
       max-width. */
    max-width: var(--content-max-width-wide);
    margin-inline: auto;
}

@media (min-width: 640px) {
    .gallery__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .gallery__grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Same breakpoint scheme as .services__grid, just one tier further —
   5 columns reads fine here because gallery tiles are cropped 4:3
   photos (object-fit: cover), not text-bearing service cards. */
@media (min-width: 1280px) {
    .gallery__grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

.gallery__item {
    position: relative;
    margin: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 4 / 3;
    background-color: var(--color-bg-light);
    transition: box-shadow var(--duration-base) var(--ease-base);
}

.gallery__item:hover {
    box-shadow: 0 24px 48px rgba(11, 35, 68, 0.14);
}

.gallery__image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--duration-base) var(--ease-base);
}

/* Click target for the lightbox — a <button> wrapping the <img> rather
   than a click handler on the <figure>, so it's keyboard-reachable and
   announces as a control for free. Reset to fill the tile exactly like
   the bare <img> did. */
.gallery__trigger {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: none;
    cursor: zoom-in;
}

.gallery__trigger:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

.gallery__item:hover .gallery__image {
    transform: scale(1.06);
}

/* Caption sits on a scrim, hidden until hover — captions are optional
   per image (nullable in the DB), so this only ever renders for images
   that actually have one (see the PHP conditional). */
.gallery__caption {
    position: absolute;
    inset: auto 0 0 0;
    margin: 0;
    padding: var(--space-xl) var(--space-md) var(--space-md);
    background: linear-gradient(0deg, rgba(11, 35, 68, 0.8), transparent);
    color: var(--color-white);
    font-size: var(--fs-small);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity var(--duration-base) var(--ease-base),
                transform var(--duration-base) var(--ease-base);
}

.gallery__item:hover .gallery__caption {
    opacity: 1;
    transform: translateY(0);
}

/* ---- Lightbox ---------------------------------------------------------
   Opened by assets/js/gallery-lightbox.js. No existing modal/overlay
   pattern elsewhere on the site to match, so this establishes one:
   dark scrim + centered dialog, consistent with the header's
   backdrop-filter glass treatment and the site's restrained-motion rule.
   Markup lives in pages/service-details.php, right after .gallery__grid,
   gated behind the same "service actually has gallery images" check. */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    background-color: rgba(11, 35, 68, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity var(--duration-base) var(--ease-base);
}

.lightbox[hidden] {
    display: none;
}

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

.lightbox__dialog {
    position: relative;
    max-width: min(1100px, calc(100vw - 160px));
    max-height: calc(100vh - 4rem);
    transform: scale(0.96);
    transition: transform var(--duration-base) var(--ease-base);
}

.lightbox.is-open .lightbox__dialog {
    transform: scale(1);
}

.lightbox__figure {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 100%;
    max-height: 100%;
}

.lightbox__image {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 10rem);
    width: auto;
    height: auto;
    border-radius: var(--radius-md);
    object-fit: contain;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
}

.lightbox__caption {
    margin: var(--space-md) 0 0;
    max-width: 60ch;
    color: var(--color-white);
    font-size: var(--fs-small);
    text-align: center;
}

.lightbox__caption:empty {
    display: none;
}

.lightbox__close,
.lightbox__nav {
    position: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--color-white);
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-base),
                border-color var(--duration-fast) var(--ease-base);
}

.lightbox__close:hover,
.lightbox__nav:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.45);
}

.lightbox__close svg,
.lightbox__nav svg {
    width: 1.25rem;
    height: 1.25rem;
}

.lightbox__close {
    top: var(--space-lg);
    right: var(--space-lg);
}

.lightbox__nav--prev {
    left: var(--space-lg);
    top: 50%;
    transform: translateY(-50%);
}

.lightbox__nav--next {
    right: var(--space-lg);
    top: 50%;
    transform: translateY(-50%);
}

@media (max-width: 640px) {
    .lightbox {
        padding: var(--space-md);
    }

    .lightbox__dialog {
        max-width: calc(100vw - 2rem);
    }

    .lightbox__close,
    .lightbox__nav {
        width: 2.25rem;
        height: 2.25rem;
    }

    .lightbox__close {
        top: var(--space-sm);
        right: var(--space-sm);
    }

    .lightbox__nav--prev {
        left: var(--space-sm);
    }

    .lightbox__nav--next {
        right: var(--space-sm);
    }
}

@media (prefers-reduced-motion: reduce) {
    .lightbox,
    .lightbox__dialog {
        transition: none;
    }
}

/* Applied to <body> while the lightbox is open. */
body.lightbox-open {
    overflow: hidden;
}
