/* ==========================================================================
   GALLERY.CSS — Reusable Gallery Component
   ========================================================================== */

/* --- Gallery Toolbar --- */
.gallery-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-6);
    flex-wrap: wrap;
    margin-bottom: var(--space-8);
}

/* --- Filter Buttons --- */
.gallery-filters {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    flex-wrap: wrap;
}

.gallery-filter-btn {
    padding: var(--space-2) var(--space-6);
    border-radius: var(--rounded-full);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    font-family: var(--font-body);
    border: 1px solid var(--color-light-gray);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: var(--leading-normal);
}

.gallery-filter-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.gallery-filter-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.gallery-filter-btn.is-active {
    background: var(--color-accent);
    color: var(--color-white);
    border-color: var(--color-accent);
}

.gallery-filter-btn.is-active:hover {
    background: var(--color-accent-dark);
    border-color: var(--color-accent-dark);
    color: var(--color-white);
}

/* --- Gallery Grid --- */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
}

/* --- Gallery Item --- */
.gallery-item {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--rounded-lg);
    cursor: pointer;
    background: var(--color-lighter-gray);
}

.gallery-item picture {
    display: block;
    width: 100%;
    height: 100%;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-slow);
}

.gallery-item:hover img {
    transform: scale(1.05);
}

/* Placeholder styling (for items without real images) */
.gallery-item-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--color-slate);
    font-family: var(--font-body);
    transition: transform var(--transition-slow);
}

.gallery-item:hover .gallery-item-placeholder {
    transform: scale(1.05);
}

/* Overlay */
.gallery-item-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
}

.gallery-item:hover .gallery-item-overlay {
    opacity: 1;
}

/* Hidden state for filtering */
.gallery-item.is-hidden {
    display: none;
}

/* --- Layout Switcher --- */
.gallery-layout-switcher {
    display: flex;
    gap: var(--space-1);
    background: var(--bg-secondary);
    border-radius: var(--rounded-lg);
    padding: var(--space-1);
}

.gallery-layout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--rounded-md);
    background: transparent;
    color: var(--color-slate);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.gallery-layout-btn:hover {
    color: var(--color-accent);
    background: rgba(74, 144, 164, 0.08);
}

.gallery-layout-btn.is-active {
    background: var(--color-accent);
    color: var(--color-white);
    box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   LAYOUT VARIANTS
   ========================================================================== */

/* --- Grid --- */
.gallery-grid.layout-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
}

.gallery-grid.layout-grid .gallery-item {
    aspect-ratio: 1;
}

/* --- Masonry --- */
.gallery-grid.layout-masonry {
    display: block;
    column-count: 4;
    column-gap: var(--space-4);
}

.gallery-grid.layout-masonry .gallery-item {
    aspect-ratio: auto;
    break-inside: avoid;
    margin-bottom: var(--space-4);
}

/* Varied heights — 8-item cycle for natural look */
.gallery-grid.layout-masonry .gallery-item:nth-child(8n+1) { aspect-ratio: 3 / 4; }
.gallery-grid.layout-masonry .gallery-item:nth-child(8n+2) { aspect-ratio: 4 / 3; }
.gallery-grid.layout-masonry .gallery-item:nth-child(8n+3) { aspect-ratio: 2 / 3; }
.gallery-grid.layout-masonry .gallery-item:nth-child(8n+4) { aspect-ratio: 1; }
.gallery-grid.layout-masonry .gallery-item:nth-child(8n+5) { aspect-ratio: 5 / 4; }
.gallery-grid.layout-masonry .gallery-item:nth-child(8n+6) { aspect-ratio: 3 / 5; }
.gallery-grid.layout-masonry .gallery-item:nth-child(8n+7) { aspect-ratio: 4 / 3; }
.gallery-grid.layout-masonry .gallery-item:nth-child(8n)   { aspect-ratio: 3 / 4; }

/* --- Mosaic --- */
.gallery-grid.layout-mosaic {
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 180px;
    grid-auto-flow: dense;
}

.gallery-grid.layout-mosaic .gallery-item {
    aspect-ratio: auto;
}

/* Feature items — every 5th item spans 2x2 */
.gallery-grid.layout-mosaic .gallery-item:nth-child(5n+1) {
    grid-column: span 2;
    grid-row: span 2;
}

/* Every 7th item spans 2 columns */
.gallery-grid.layout-mosaic .gallery-item:nth-child(7n+4) {
    grid-column: span 2;
}

/* --- List --- */
.gallery-grid.layout-list {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-6);
}

.gallery-grid.layout-list .gallery-item {
    aspect-ratio: 16 / 10;
    border-radius: var(--rounded-xl);
}

/* ==========================================================================
   LAYOUT RESPONSIVE
   ========================================================================== */
@media (max-width: 1024px) {
    .gallery-grid.layout-masonry {
        column-count: 3;
    }

    .gallery-grid.layout-mosaic {
        grid-template-columns: repeat(3, 1fr);
        grid-auto-rows: 150px;
    }

    .gallery-grid.layout-mosaic .gallery-item:nth-child(5n+1) {
        grid-column: span 2;
        grid-row: span 2;
    }
}

@media (max-width: 640px) {
    .gallery-toolbar {
        flex-direction: column;
        gap: var(--space-4);
    }

    .gallery-grid.layout-masonry {
        column-count: 2;
        column-gap: var(--space-3);
    }

    .gallery-grid.layout-masonry .gallery-item {
        margin-bottom: var(--space-3);
    }

    .gallery-grid.layout-mosaic {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 120px;
    }

    .gallery-grid.layout-mosaic .gallery-item:nth-child(5n+1) {
        grid-column: span 2;
        grid-row: span 1;
    }

    .gallery-grid.layout-mosaic .gallery-item:nth-child(7n+4) {
        grid-column: span 1;
    }

    .gallery-grid.layout-list {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .gallery-grid.layout-list .gallery-item {
        aspect-ratio: 16 / 9;
    }
}

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.lightbox.is-open {
    opacity: 1;
    visibility: visible;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-image {
    max-width: 90vw;
    max-height: 85vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--rounded-lg);
}

.lightbox-close {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--rounded-full);
    cursor: pointer;
    transition: background var(--transition-fast);
    z-index: 2;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-close:focus-visible {
    outline: 2px solid var(--color-white);
    outline-offset: -2px;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
    background: transparent;
    border: none;
    border-radius: var(--rounded-full);
    cursor: pointer;
    transition: background var(--transition-fast);
    z-index: 2;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.1);
}

.lightbox-nav:focus-visible {
    outline: 2px solid var(--color-white);
    outline-offset: -2px;
}

.lightbox-nav-prev {
    left: var(--space-4);
}

.lightbox-nav-next {
    right: var(--space-4);
}

.lightbox-counter {
    position: absolute;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    color: var(--color-white);
    font-size: var(--text-sm);
    font-family: var(--font-body);
    background: rgba(0, 0, 0, 0.5);
    padding: var(--space-1) var(--space-4);
    border-radius: var(--rounded-full);
    z-index: 2;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .gallery-grid.layout-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 640px) {
    .gallery-grid.layout-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .lightbox-image {
        max-width: 95vw;
        max-height: 80vh;
    }

    .lightbox-nav {
        width: 40px;
        height: 40px;
    }

    .lightbox-nav-prev {
        left: var(--space-2);
    }

    .lightbox-nav-next {
        right: var(--space-2);
    }
}
