/**
 * Photo Gallery v1.2 — photo-first tile styling
 *
 * Hooks onto v1.2's BEM photo-tile surface. No card metadata —
 * grid is image-only per DQ8. Mobile-first; breakpoints at 600px
 * (tablet) and 960px (desktop) match v1.1 site conventions.
 *
 * Brand colors inherit from CSS variables exposed by color-integration
 * (--am-color-*) where applicable; hardcoded grays for neutral chrome.
 *
 * No !important declarations — preserves per-client cascade override
 * capacity per a11y v1.1 §3.7.a.
 */

/* ============================================================
   FILTER CONTROLS (carry-forward from v1.1 — filter UI markup
   unchanged; this whole block survives the v1.2 rewrite)
============================================================ */

.mr4-photo-gallery__filters {
    margin: 0 0 1.5rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 6px;
}

.mr4-photo-gallery__filters fieldset {
    border: 0;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.mr4-photo-gallery__filters legend {
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #495057;
    margin-bottom: 0.5rem;
    padding: 0;
}

.mr4-photo-gallery__filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.mr4-photo-gallery__filter-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #495057;
}

/* v1.3 DQ12 — chip group container. Chips wrap to multiple rows on
   narrow viewports; each chip carries its own selection state via
   aria-pressed so there is no parent "selected one" mode. */
.mr4-photo-gallery__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

/* v1.3 DQ12 — chip button. 44x44 min tap target per a11y v1.1.
   aria-pressed="true" styles the selected state. The native button
   element preserves keyboard Enter / Space activation semantics for
   free; we just style the visual surface. */
.mr4-photo-gallery__chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.4rem 0.85rem;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    color: #495057;
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.mr4-photo-gallery__chip:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.mr4-photo-gallery__chip:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.mr4-photo-gallery__chip[aria-pressed="true"] {
    color: #fff;
    background: #2563eb;
    border-color: #2563eb;
}

.mr4-photo-gallery__chip[aria-pressed="true"]:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

@media (prefers-reduced-motion: reduce) {
    .mr4-photo-gallery__chip {
        transition: none;
    }
}

.mr4-photo-gallery__filter-reset {
    align-self: flex-start;
    margin-top: 0.5rem;
    padding: 0.4rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #495057;
    background: transparent;
    border: 1px solid #ced4da;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.mr4-photo-gallery__filter-reset:hover,
.mr4-photo-gallery__filter-reset:focus {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.mr4-photo-gallery__filter-reset:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

@media (min-width: 600px) {
    .mr4-photo-gallery__filters fieldset {
        flex-direction: row;
        align-items: flex-end;
        flex-wrap: wrap;
    }

    .mr4-photo-gallery__filter-group {
        flex: 1 1 200px;
    }

    .mr4-photo-gallery__filters legend {
        flex-basis: 100%;
    }
}

/* ============================================================
   PHOTO GRID — photo-first density
   Mobile 2-col → tablet 3-col → desktop 4-col. Higher density
   than v1.1's card grid because tiles are image-only.
============================================================ */

.mr4-photo-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin: 1.5rem 0;
}

@media (min-width: 600px) {
    .mr4-photo-gallery {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.75rem;
    }
}

@media (min-width: 960px) {
    .mr4-photo-gallery {
        grid-template-columns: repeat(4, 1fr);
        gap: 1rem;
    }
}

/* AJAX loading state — fade the grid slightly while a fetch is in
   flight so the operator gets a visual cue that interactivity is
   working. JS toggles .is-loading on the wrapper. */
.mr4-photo-gallery-wrapper.is-loading .mr4-photo-gallery {
    opacity: 0.55;
    transition: opacity 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
    .mr4-photo-gallery-wrapper.is-loading .mr4-photo-gallery {
        transition: none;
    }
}

/* ============================================================
   MASONRY VARIANT (v1.3 DQ4 + DQ5) — opt-in via layout="masonry"
   Server computes grid-row: span N per tile from aspect ratio so
   tiles preserve native proportions without center-crop. Pure CSS
   Grid; no JS layout shift. grid-auto-flow: dense back-fills gaps
   with shorter tiles so the wall stays visually packed.
============================================================ */

.mr4-photo-gallery--masonry {
    grid-auto-rows: 10px;
    grid-auto-flow: dense;
}

/* Override the uniform-grid square aspect ratio so each tile takes
   the height its server-computed row-span dictates. */
.mr4-photo-gallery--masonry .mr4-photo-gallery__tile {
    aspect-ratio: auto;
    height: 100%;
}

/* ============================================================
   PHOTO TILES — anchor wraps img per spec §3.3
   Square aspect ratio for grid uniformity; object-fit covers the
   actual image regardless of source aspect ratio. Subtle hover
   elevation; focus ring for keyboard users.
============================================================ */

.mr4-photo-gallery__tile {
    display: block;
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f1f3f5;
    border-radius: 4px;
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: zoom-in;
}

.mr4-photo-gallery__tile:hover,
.mr4-photo-gallery__tile:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.mr4-photo-gallery__tile:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.mr4-photo-gallery__photo {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.mr4-photo-gallery__tile:hover .mr4-photo-gallery__photo,
.mr4-photo-gallery__tile:focus .mr4-photo-gallery__photo {
    transform: scale(1.04);
}

@media (prefers-reduced-motion: reduce) {
    .mr4-photo-gallery__tile,
    .mr4-photo-gallery__photo {
        transition: none;
    }
    .mr4-photo-gallery__tile:hover,
    .mr4-photo-gallery__tile:focus,
    .mr4-photo-gallery__tile:hover .mr4-photo-gallery__photo,
    .mr4-photo-gallery__tile:focus .mr4-photo-gallery__photo {
        transform: none;
    }
}

/* ============================================================
   LOAD MORE BUTTON + IO SENTINEL
   Button is the a11y fallback path (focusable, keyboard-triggerable);
   sentinel is the IntersectionObserver target for infinite scroll.
============================================================ */

.mr4-photo-gallery__pagination {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 0 0;
}

.mr4-photo-gallery__load-more {
    padding: 0.65rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    background: #2563eb;
    border: 1px solid #2563eb;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    min-width: 180px;
}

.mr4-photo-gallery__load-more:hover,
.mr4-photo-gallery__load-more:focus {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.mr4-photo-gallery__load-more:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.mr4-photo-gallery__load-more[disabled],
.mr4-photo-gallery__load-more[aria-disabled="true"] {
    background: #adb5bd;
    border-color: #adb5bd;
    cursor: not-allowed;
}

.mr4-photo-gallery__load-more[hidden] {
    display: none;
}

.mr4-photo-gallery__sentinel {
    width: 100%;
    height: 1px;
    margin: 0;
    /* Invisible — purely an IntersectionObserver target. Padding
       reservation up-shifts the observer trigger so the next page
       starts fetching before the user hits the bottom. */
    padding-top: 2rem;
}

/* Live region for AJAX status updates (SR-only). Visually hidden but
   announced to assistive tech when load completes / fails. */
.mr4-photo-gallery__status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================================
   PHOTOSWIPE LIGHTBOX OVERRIDES
   PhotoSwipe ships its own stylesheet (enqueued via CDN). These
   rules style the custom "View Project" CTA we register through
   PhotoSwipe's uiRegister API.
============================================================ */

.pswp__button--view-project {
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    height: 44px;
    padding: 0 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    background: #2563eb;
    text-decoration: none;
    border-radius: 4px;
    margin-right: 0.5rem;
    transition: background-color 0.15s ease;
}

.pswp__button--view-project:hover,
.pswp__button--view-project:focus {
    background: #1d4ed8;
    color: #fff;
}

.pswp__button--view-project:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ============================================================
   EMPTY STATE
============================================================ */

.mr4-photo-gallery--empty {
    grid-column: 1 / -1;
    padding: 3rem 1.5rem;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    background: #f8f9fa;
    border-radius: 8px;
}

.mr4-photo-gallery--empty p {
    margin: 0;
    font-size: 1rem;
}

/* ============================================================
   PAGE TEMPLATE WRAPPER
   (mr4-gallery-page__* classes from templates/gallery-portfolio.php)
============================================================ */

.mr4-gallery-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.mr4-gallery-page__header {
    margin-bottom: 2rem;
}

.mr4-gallery-page__title {
    margin: 0 0 0.5rem;
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    color: #212529;
}

@media (min-width: 600px) {
    .mr4-gallery-page__title {
        font-size: 2.5rem;
    }
}

.mr4-gallery-page__description {
    font-size: 1.125rem;
    line-height: 1.6;
    color: #495057;
}

.mr4-gallery-page__content {
    margin-bottom: 1.5rem;
}
