/* ==========================================================================
   Gallery Page (masonry, Pexels-style)
   ==========================================================================
   Sections in this file:
   1. Section wrapper + result count
   2. Masonry layout + tiles
   3. Pagination
   4. Empty state
   5. Fullscreen viewer (lightbox)
   6. Responsive breakpoints
   7. RTL
   8. Reduced motion
   ========================================================================== */

/* ----------------------------------------------------------------
   1. Section wrapper + result count
   ---------------------------------------------------------------- */
.gallery-page {
    padding-block: 0 !important;
    padding-inline: 0 !important;
}

/* ----------------------------------------------------------------
   2. Masonry layout + tiles
   Images keep their natural proportions (width/height attributes on the
   <img> reserve the space, so nothing jumps while they load). CSS columns
   keep the DOM in image order, which is what crawlers and screen readers read.
   ---------------------------------------------------------------- */
.gp-masonry {
    list-style: none;
    margin: 0;
    padding: var(--spacing-lg) 0 var(--spacing-md);
    column-count: 3;
    column-gap: var(--spacing-lg);
}

.gp-item {
    margin: 0 0 var(--spacing-lg);
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
}

.gp-tile {
    position: relative;
    isolation: isolate;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
    cursor: zoom-in;
    -webkit-tap-highlight-color: transparent;
}

.gp-tile img {
    display: block;
    width: 100%;
    height: auto;
    transition: transform var(--transition-slow);
}

/* Images without stored dimensions fall back to a fixed ratio */
.gp-tile--fallback {
    aspect-ratio: 4 / 5;
}

.gp-tile--fallback img {
    height: 100%;
    object-fit: cover;
}

/* Soft shade so the zoom icon stays readable on bright photos */
.gp-tile::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(to top, rgb(0 0 0 / 0.38), transparent 45%);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.gp-tile__icon {
    position: absolute;
    inset-block-end: var(--spacing-md);
    inset-inline-end: var(--spacing-md);
    z-index: 2;
    display: grid;
    place-items: center;
    width: 40px;
    aspect-ratio: 1;
    border-radius: var(--radius-full);
    background: var(--bg-primary);
    box-shadow: var(--shadow-medium);
    color: var(--primary-color);
    opacity: 0;
    translate: 0 6px;
    transition: opacity var(--transition-normal),
                translate var(--transition-normal);
}

.gp-tile:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

.gp-tile:focus-visible::after,
.gp-tile:focus-visible .gp-tile__icon {
    opacity: 1;
}

.gp-tile:focus-visible .gp-tile__icon {
    translate: 0 0;
}

@media (hover: hover) and (pointer: fine) {
    .gp-tile:hover img {
        transform: scale(1.04);
    }

    .gp-tile:hover::after,
    .gp-tile:hover .gp-tile__icon {
        opacity: 1;
    }

    .gp-tile:hover .gp-tile__icon {
        translate: 0 0;
    }
}

/* ----------------------------------------------------------------
   3. Pagination
   ---------------------------------------------------------------- */
.gp-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding-block: var(--spacing-2xl) 0;
}

.gp-page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 44px;
    padding-inline: var(--spacing-md);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-full);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: var(--font-size-base);
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast),
                color var(--transition-fast);
}

.gp-page svg {
    flex-shrink: 0;
}

.gp-page:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

@media (hover: hover) and (pointer: fine) {
    a.gp-page:hover {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }
}

.gp-page.is-active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    box-shadow: var(--shadow-light);
    color: var(--text-white);
    font-weight: 600;
}

.gp-page.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.gp-dots {
    padding-inline: var(--spacing-xs);
    color: var(--text-muted);
    user-select: none;
}

/* ----------------------------------------------------------------
   4. Empty state
   ---------------------------------------------------------------- */
.gp-empty {
    padding: var(--spacing-4xl) var(--spacing-lg);
    text-align: center;
}

.gp-empty h3 {
    margin: 0 0 var(--spacing-sm);
    color: var(--text-primary);
    font-size: var(--font-size-3xl);
    font-weight: 700;
}

.gp-empty p {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--font-size-base);
    line-height: 1.6;
}

/* ----------------------------------------------------------------
   5. Fullscreen viewer
   ---------------------------------------------------------------- */
.gp-lightbox {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-2xl);
    background: var(--bg-modal);
}

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

.gp-lightbox__stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    max-width: min(92vw, 1200px);
    max-height: 94vh;
}

.gp-lightbox__stage img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 82vh;
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    box-shadow: var(--shadow-heavy);
    object-fit: contain;
}

.gp-lightbox.is-open .gp-lightbox__stage img {
    animation: gpLightboxEnter var(--transition-normal);
}

@keyframes gpLightboxEnter {
    from {
        opacity: 0;
        transform: scale(0.94);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.gp-lightbox__counter {
    margin: 0;
    color: var(--text-white);
    font-size: var(--font-size-sm);
    letter-spacing: 0.04em;
    opacity: 0.85;
}

.gp-lightbox__btn {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    aspect-ratio: 1;
    padding: 0;
    border: none;
    border-radius: var(--radius-full);
    background: rgb(255 255 255 / 0.12);
    color: var(--text-white);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color var(--transition-fast),
                scale var(--transition-fast);
}

.gp-lightbox__btn:focus-visible {
    outline: 2px solid var(--text-white);
    outline-offset: 3px;
}

@media (hover: hover) {
    .gp-lightbox__btn:hover {
        background: rgb(255 255 255 / 0.22);
        scale: 1.05;
    }
}

.gp-lightbox__close {
    inset-block-start: var(--spacing-2xl);
    inset-inline-end: var(--spacing-2xl);
}

.gp-lightbox__prev,
.gp-lightbox__next {
    inset-block-start: 50%;
    translate: 0 -50%;
}

.gp-lightbox__prev {
    inset-inline-start: var(--spacing-2xl);
}

.gp-lightbox__next {
    inset-inline-end: var(--spacing-2xl);
}

/* ----------------------------------------------------------------
   6. Responsive breakpoints
   ---------------------------------------------------------------- */
@media (max-width: 1000px) {
    .gp-masonry {
        column-count: 2;
    }
}

@media (max-width: 640px) {
    .gp-masonry {
        column-gap: var(--spacing-sm);
    }

    .gp-item {
        margin-bottom: var(--spacing-sm);
    }

    .gp-tile {
        border-radius: var(--radius-md);
    }

    /* The zoom icon is a hover cue; hide it on touch layouts */
    .gp-tile__icon {
        display: none;
    }

    .gp-page {
        min-width: 40px;
        height: 40px;
        padding-inline: var(--spacing-sm);
        font-size: var(--font-size-sm);
    }

    .gp-lightbox {
        padding: var(--spacing-lg);
    }

    .gp-lightbox__btn {
        width: 38px;
    }

    .gp-lightbox__close {
        inset-block-start: var(--spacing-lg);
        inset-inline-end: var(--spacing-lg);
    }

    /* Arrows move to the bottom so they never cover the photo */
    .gp-lightbox__prev,
    .gp-lightbox__next {
        inset-block-start: auto;
        inset-block-end: var(--spacing-lg);
        translate: none;
    }

    .gp-lightbox__prev {
        inset-inline-start: var(--spacing-lg);
    }

    .gp-lightbox__next {
        inset-inline-end: var(--spacing-lg);
    }

    .gp-lightbox__stage img {
        max-height: 72vh;
    }
}

/* ----------------------------------------------------------------
   7. RTL (logical properties handle layout; only the arrows need
      mirroring so they point in the direction of travel)
   ---------------------------------------------------------------- */
[dir="rtl"] .gp-page svg,
[dir="rtl"] .gp-lightbox__prev svg,
[dir="rtl"] .gp-lightbox__next svg {
    transform: scaleX(-1);
}

/* ----------------------------------------------------------------
   8. Reduced motion
   ---------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .gp-tile img,
    .gp-tile::after,
    .gp-tile__icon,
    .gp-page,
    .gp-lightbox__btn {
        transition: none;
    }

    .gp-lightbox.is-open .gp-lightbox__stage img {
        animation: none;
    }
}