/* Gallery Lightbox - Pattern Grid
   Rows alternate between 2 and 3 images. Every cell in a row is the same
   width, every row is the same height, images are cropped to fill. */

.gallery-lightbox-wrapper {
    width: 100%;
}

.gallery-grid {
    display: grid;
    /* 12 base columns: divisible by 2, 3 and 4 */
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: var(--row-h, 220px);
    gap: var(--gap, 12px);
    width: 100%;
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    grid-column: span 4; /* default: 3 per row */
}

/* ---- Patterns ------------------------------------------------------- */

/* 2 per row, then 3 per row, repeating (cycle of 5) */
.gallery-grid[data-pattern="alt23"] .gallery-item:nth-child(5n + 1),
.gallery-grid[data-pattern="alt23"] .gallery-item:nth-child(5n + 2) {
    grid-column: span 6;
}
.gallery-grid[data-pattern="alt23"] .gallery-item:nth-child(5n + 3),
.gallery-grid[data-pattern="alt23"] .gallery-item:nth-child(5n + 4),
.gallery-grid[data-pattern="alt23"] .gallery-item:nth-child(5n + 5) {
    grid-column: span 4;
}

/* 3 per row, then 2 per row, repeating */
.gallery-grid[data-pattern="alt32"] .gallery-item:nth-child(5n + 1),
.gallery-grid[data-pattern="alt32"] .gallery-item:nth-child(5n + 2),
.gallery-grid[data-pattern="alt32"] .gallery-item:nth-child(5n + 3) {
    grid-column: span 4;
}
.gallery-grid[data-pattern="alt32"] .gallery-item:nth-child(5n + 4),
.gallery-grid[data-pattern="alt32"] .gallery-item:nth-child(5n + 5) {
    grid-column: span 6;
}

/* Fixed columns */
.gallery-grid[data-pattern="2"] .gallery-item { grid-column: span 6; }
.gallery-grid[data-pattern="3"] .gallery-item { grid-column: span 4; }
.gallery-grid[data-pattern="4"] .gallery-item { grid-column: span 3; }

/* ---- Item internals ------------------------------------------------- */

.gallery-link {
    display: block;
    width: 100%;
    height: 100%;
    position: relative;
    text-decoration: none;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    background-color: #f0f0f0;
    transition: transform 0.4s ease;
}

.gallery-link:hover img {
    transform: scale(1.05);
}

.gallery-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0);
    transition: background-color 0.3s ease;
    z-index: 1;
}

.gallery-link:hover .gallery-overlay {
    background-color: rgba(0, 0, 0, 0.35);
}

.gallery-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.85);
    width: 44px;
    height: 44px;
    background-color: rgba(255, 255, 255, 0.92);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    z-index: 2;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.gallery-link:hover .gallery-icon {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.gallery-icon svg { width: 22px; height: 22px; }

.gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    padding: 10px 12px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 3;
    pointer-events: none;
}

.gallery-item:hover .gallery-caption { transform: translateY(0); }

.gallery-caption h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
}

/* ---- Responsive ----------------------------------------------------- */

@media (max-width: 1024px) {
    .gallery-grid { --row-h: 180px; }
}

/* Tablet / mobile: everything becomes 2 per row so nothing gets tiny */
@media (max-width: 767px) {
    .gallery-grid {
        --row-h: 150px;
        --gap: 8px;
    }
    .gallery-grid[data-pattern] .gallery-item,
    .gallery-item {
        grid-column: span 6 !important;
    }
}

/* Optional: one per row on small phones */
@media (max-width: 480px) {
    .gallery-grid.gallery-stack-mobile { --row-h: 200px; }
    .gallery-grid.gallery-stack-mobile[data-pattern] .gallery-item,
    .gallery-grid.gallery-stack-mobile .gallery-item {
        grid-column: span 12 !important;
    }
    .gallery-caption { padding: 8px; }
    .gallery-caption h4 { font-size: 12px; }
    .gallery-icon { width: 36px; height: 36px; }
}

/* ---- Lightbox ------------------------------------------------------- */

.glightbox-container { background-color: rgba(0, 0, 0, 0.95); }
.glightbox-title { color: #fff; font-size: 16px; font-weight: 500; }
.glightbox-desc { color: #fff; font-size: 14px; line-height: 1.6; }
.gclose, .gnext, .gprev { color: #fff; opacity: 0.85; }
.gclose:hover, .gnext:hover, .gprev:hover { opacity: 1; }

.gallery-link:focus-visible {
    outline: 3px solid #0066cc;
    outline-offset: 2px;
}

@media print {
    .gallery-overlay, .gallery-icon { display: none; }
    .gallery-caption { transform: none; background: transparent; color: #000; }
}
