/**
 * Project Gallery — v1.0
 *
 * Sibling to photo-gallery.css. Reuses visual language (rounded corners,
 * hover states, spacing scale) but has its own class prefix (mr4-pg-)
 * so the two galleries can coexist on a page without style collisions.
 *
 * Phase 1 scope: masonry grid + tile styles + empty state + Load More.
 * Phases 2 + 3 add chip filter rows, search input, and hover overlay
 * transitions.
 */

/* ============================================================
   Wrapper + layout modes

   Default (tablet + mobile): single column. Controls stacked above
   the tile grid.

   Desktop (≥ 1024px): two-column grid. Controls on the left at ~33%
   width, tiles on the right at ~66% width, with the controls sticky
   so search + chip state stays visible as tiles scroll.
============================================================ */

.mr4-pg-wrapper {
    box-sizing: border-box;
    margin: 0 auto;
    max-width: 100%;
    padding: 0;
    font-family: inherit;
}

.mr4-pg-wrapper *,
.mr4-pg-wrapper *::before,
.mr4-pg-wrapper *::after {
    box-sizing: inherit;
}

/* Controls slot — chips + search live here */
.mr4-pg-controls {
    margin-bottom: 1.5rem;
}

.mr4-pg-controls:empty {
    display: none;
}

/* Right column — passthrough at tablet + mobile (just wraps grid +
   loadmore), becomes the second cell of the 2-column grid at desktop. */
.mr4-pg-right-column {
    min-width: 0;                       /* prevent grid child overflow */
}

/* ============================================================
   Desktop 2-column layout with sticky sidebar
============================================================ */

@media (min-width: 1024px) {
    .mr4-pg-wrapper {
        display: grid;
        grid-template-columns: 1fr 2fr;  /* 33% / 66% split */
        gap: 2rem;
        align-items: start;             /* controls don't stretch to match tile column height */
    }

    .mr4-pg-controls {
        margin-bottom: 0;               /* margin only meaningful in stacked layout */
        grid-column: 1;                 /* v5.33.5 — pin to first track (see comment below) */
    }

    .mr4-pg-right-column {
        grid-column: 2;                 /* v5.33.5 — pin to second track */
    }

    /* v5.33.4 — CSS `position: sticky` was defeated by a Cornerstone
       container ancestor with `overflow: hidden` on this canary
       (sticky bounds to its containing block; any overflow-clipped
       ancestor truncates the sticky context). Replaced with JS-driven
       `position: fixed` — see updateFixedSidebar() in
       js/project-gallery.js.

       v5.33.5 — when the JS applies `position: fixed` to
       .mr4-pg-controls, the element is removed from grid flow. Without
       explicit grid-column assignments, CSS Grid auto-placement then
       shifts the remaining in-flow item (.mr4-pg-right-column) into
       track 1 (33% wide), collapsing the tile column onto the sidebar
       position. Explicit `grid-column: 1` and `grid-column: 2`
       anchors both items to their intended tracks regardless of
       which is in-flow. */
}

/* ============================================================
   Search input (Phase 3)
============================================================ */

.mr4-pg-search {
    position: relative;
    margin-bottom: 1.25rem;
    max-width: 480px;
}

.mr4-pg-search-input {
    width: 100%;
    min-height: 44px;
    padding: 0.6rem 2.5rem 0.6rem 1rem;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: #111827;
    font-size: 0.95rem;
    line-height: 1.3;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.mr4-pg-search-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.mr4-pg-search-input::placeholder {
    color: #9ca3af;
}

.mr4-pg-search-clear {
    position: absolute;
    top: 50%;
    right: 0.5rem;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 150ms ease, color 150ms ease;
}

.mr4-pg-search-clear:hover,
.mr4-pg-search-clear:focus-visible {
    background: #f3f4f6;
    color: #111827;
    outline: none;
}

.mr4-pg-search-clear[hidden] {
    display: none;
}

/* ============================================================
   Chip filter rows (Phase 2)
============================================================ */

.mr4-pg-chip-row {
    margin-bottom: 1rem;
}

.mr4-pg-chip-row:last-child {
    margin-bottom: 0;
}

.mr4-pg-chip-row-label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #4b5563;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.mr4-pg-chip-row-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.mr4-pg-chip {
    /* 44x44 min tap target per a11y contract; padding tuned for readable
       chip labels while preserving the tap-target floor. */
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0.4rem 0.9rem;
    border: 1.5px solid #d1d5db;
    border-radius: 999px;
    background: #fff;
    color: #374151;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
    white-space: nowrap;
}

.mr4-pg-chip:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.mr4-pg-chip:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

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

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

.mr4-pg-chip-count {
    margin-left: 0.35rem;
    font-size: 0.75rem;
    color: inherit;
    opacity: 0.75;
}

/* ============================================================
   Grid — masonry
============================================================ */

.mr4-pg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-rows: 10px;              /* small unit; spans multiply this */
    grid-auto-flow: dense;
    gap: 1rem;
}

/* Grid variant — fixed aspect (opt-in via layout="grid" shortcode attr) */
.mr4-pg-layout-grid .mr4-pg-grid {
    grid-auto-rows: auto;
    grid-auto-flow: row;
}

.mr4-pg-layout-grid .mr4-pg-tile {
    /* Fixed 4:3 aspect for grid layout — overrides masonry span */
    grid-row: auto !important;
    aspect-ratio: 4 / 3;
}

/* ============================================================
   Tile
============================================================ */

.mr4-pg-tile {
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: 8px;
    background: #f3f4f6;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: transform 200ms ease, box-shadow 200ms ease;
    line-height: 0;                     /* kills img descender gap */
}

.mr4-pg-tile:hover,
.mr4-pg-tile:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    outline: none;
}

.mr4-pg-tile:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.mr4-pg-tile-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    line-height: 0;
}

/* Overlay — hover-reveal on capable-of-hover devices (desktop pointer);
   always visible on touch devices per spec Q6. Uses (hover: hover) +
   (pointer: fine) so laptops with touchscreens still get hover UX from
   the mouse but touch-only devices get always-visible.
   Excerpt reveals only on hover; title always visible in a compact strip
   so touch users still see project titles at rest. */
.mr4-pg-tile-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.75rem 1rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.35) 60%, rgba(0, 0, 0, 0) 100%);
    color: #fff;
    line-height: 1.4;
    pointer-events: none;
    transition: transform 200ms ease, opacity 200ms ease;
}

/* Desktop hover-reveal: title visible at rest, excerpt slides in on hover */
@media (hover: hover) and (pointer: fine) {
    .mr4-pg-tile-excerpt {
        max-height: 0;
        margin-top: 0;
        opacity: 0;
        overflow: hidden;
        transition: max-height 250ms ease, margin-top 250ms ease, opacity 200ms ease;
    }
    .mr4-pg-tile:hover .mr4-pg-tile-excerpt,
    .mr4-pg-tile:focus-visible .mr4-pg-tile-excerpt {
        max-height: 4.5em;              /* enough for line-clamp 2 */
        margin-top: 0.35rem;
        opacity: 1;
    }
}

.mr4-pg-tile-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
}

.mr4-pg-tile-excerpt {
    margin: 0.25rem 0 0 0;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.9);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================================
   Empty state
============================================================ */

.mr4-pg-empty {
    grid-column: 1 / -1;
    padding: 3rem 1rem;
    text-align: center;
    color: #6b7280;
    background: #f9fafb;
    border-radius: 8px;
}

.mr4-pg-empty p {
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
}

.mr4-pg-empty p:last-child {
    margin-bottom: 0;
}

.mr4-pg-reset {
    min-height: 44px;
    padding: 0.5rem 1.25rem;
    background: #fff;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    color: #374151;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease;
}

.mr4-pg-reset:hover,
.mr4-pg-reset:focus-visible {
    background: #f3f4f6;
    border-color: #9ca3af;
    outline: none;
}

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

/* ============================================================
   Load More
============================================================ */

.mr4-pg-loadmore-wrap {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
}

.mr4-pg-loadmore {
    padding: 0.65rem 1.5rem;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 200ms ease;
    min-height: 44px;                   /* a11y tap target */
}

.mr4-pg-loadmore:hover,
.mr4-pg-loadmore:focus-visible {
    background: #1d4ed8;
    outline: none;
}

.mr4-pg-loadmore:focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
}

.mr4-pg-loadmore:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* ============================================================
   Loading state — Phase 2 wires this in
============================================================ */

.mr4-pg-wrapper.is-loading .mr4-pg-grid {
    opacity: 0.5;
    transition: opacity 200ms ease;
    pointer-events: none;
}
