/* Photo gallery page (villa-pics/{alias}) */
.villa-gallery-page {
    padding: 28px 0 48px;
}

/* ---------- Header ---------- */
.gallery-header {
    margin-bottom: 24px;
}

.gallery-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary-color, #93241F);
    text-decoration: none;
}

.gallery-back i {
    font-size: 1.15rem;
    transition: transform 0.2s ease;
}

.gallery-back:hover {
    color: var(--primary-color, #93241F);
    text-decoration: none;
}

.gallery-back:hover i {
    transform: translateX(-3px);
}

.gallery-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 18px;
    border-bottom: 3px solid var(--primary-color, #93241F);
}

.gallery-title {
    margin: 0 0 6px;
    font-family: "Playfair Display", Georgia, serif;
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1.15;
    color: #1d1716;
}

.gallery-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 0.95rem;
    color: #6f6560;
}

.gallery-count {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: #faf6f2;
    border: 1px solid #efe6dd;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--primary-color, #93241F);
}

.gallery-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.gallery-halal {
    height: 44px;
    width: auto;
}

.gallery-pdf {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--primary-color, #93241F);
    color: #fff;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-decoration: none;
    transition: background 0.2s ease, transform 0.2s ease;
}

.gallery-pdf-short {
    display: none;
}

.gallery-pdf:hover,
.gallery-pdf:focus {
    background: #7a1c18;
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
}

/* ---------- Grid: a large photo every 6, small ones around it ---------- */
.gallery-wrap {
    container-type: inline-size;
}

.gallery-grid {
    --cols: 3;
    --gap: 12px;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-auto-rows: 220px; /* fallback for browsers without container units */
    grid-auto-rows: calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols) * 0.72);
    grid-auto-flow: dense;
    gap: var(--gap);
}

/* narrow gallery (phones in portrait, under 480px): 2 columns, a full-width photo every 5 */
@container (max-width: 480px) {
    .gallery-grid {
        --cols: 2;
        --gap: 8px;
    }

    .gallery-item:nth-child(6n + 1) {
        grid-column: auto;
        grid-row: auto;
    }

    .gallery-item:nth-child(5n + 1) {
        grid-column: 1 / -1;
        grid-row: span 2;
    }

    .gallery-item {
        border-radius: 8px;
    }
}

.gallery-item {
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: 10px;
    background: #efe9e4;
    cursor: zoom-in;
}

.gallery-item:nth-child(6n + 1) {
    grid-column: span 2;
    grid-row: span 2;
}

.gallery-item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s ease;
}

.gallery-item::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(18, 14, 13, 0.35), transparent 45%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-zoom {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: #1d1716;
    font-size: 0.85rem;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.gallery-item:hover img,
.gallery-item:focus-visible img {
    transform: scale(1.04);
}

.gallery-item:hover::after,
.gallery-item:focus-visible::after,
.gallery-item:hover .gallery-zoom,
.gallery-item:focus-visible .gallery-zoom {
    opacity: 1;
    transform: none;
}

.gallery-item:focus-visible {
    outline: 3px solid var(--primary-color, #93241F);
    outline-offset: 2px;
}

.gallery-note,
.gallery-empty {
    margin: 18px 0 0;
    font-size: 0.85rem;
    color: #8a7f78;
}

/* ---------- Lightbox ---------- */
body.lb-open {
    overflow: hidden;
}

.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 300000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(14, 10, 9, 0.94);
}

.gallery-lightbox[hidden] {
    display: none;
}

.lb-figure {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 64px 84px;
}

.lb-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.lb-close,
.lb-nav {
    position: absolute;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease;
}

.lb-close:hover,
.lb-nav:hover,
.lb-close:focus-visible,
.lb-nav:focus-visible {
    background: var(--primary-color, #93241F);
    outline: none;
}

.lb-close {
    top: 18px;
    right: 18px;
    width: 44px;
    height: 44px;
    font-size: 1.8rem;
    line-height: 1;
}

.lb-nav {
    top: 50%;
    width: 52px;
    height: 52px;
    margin-top: -26px;
    font-size: 1.8rem;
}

.lb-prev {
    left: 18px;
}

.lb-next {
    right: 18px;
}

.lb-counter {
    position: absolute;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
}

/* ---------- Responsive ---------- */
@media (max-width: 991px) {
    .gallery-grid {
        grid-auto-rows: 180px;
        grid-auto-rows: calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols) * 0.72);
    }
}

@media (max-width: 767px) {
    .villa-gallery-page {
        padding: 16px 0 32px;
    }

    .gallery-header {
        margin-bottom: 16px;
    }

    .gallery-back {
        margin-bottom: 10px;
    }

    /* title on the left, a compact PDF button on the right */
    .gallery-heading {
        align-items: flex-end;
        gap: 12px;
        padding-bottom: 14px;
    }

    .gallery-heading > div:first-child {
        min-width: 0;
    }

    .gallery-title {
        font-size: 1.6rem;
        overflow-wrap: anywhere;
    }

    .gallery-meta {
        gap: 6px 8px;
        font-size: 0.85rem;
    }

    .gallery-count {
        padding: 2px 8px;
        font-size: 0.68rem;
    }

    .gallery-actions {
        gap: 10px;
    }

    .gallery-halal {
        height: 34px;
    }

    .gallery-pdf {
        padding: 9px 14px;
    }

    .gallery-pdf-long {
        display: none;
    }

    .gallery-pdf-short {
        display: inline;
    }

    .gallery-zoom {
        display: none;
    }

    .lb-figure {
        padding: 64px 10px 70px;
    }

    .lb-nav {
        top: auto;
        bottom: 12px;
        margin-top: 0;
        width: 46px;
        height: 46px;
    }

    .lb-prev {
        left: 12px;
    }

    .lb-next {
        right: 12px;
    }

    .lb-counter {
        bottom: 22px;
    }
}

@media (max-width: 520px) {
    .gallery-grid {
        grid-auto-rows: 140px;
        grid-auto-rows: calc((100cqw - (var(--cols) - 1) * var(--gap)) / var(--cols) * 0.72);
    }
}

/* phone held sideways: little height, so give the photo all of it */
@media (max-height: 500px) and (orientation: landscape) {
    .lb-figure {
        padding: 10px 76px;
    }

    .lb-nav {
        top: 50%;
        bottom: auto;
        margin-top: -23px;
    }

    .lb-close {
        top: 10px;
        right: 12px;
        width: 40px;
        height: 40px;
    }

    .lb-counter {
        left: 12px;
        bottom: auto;
        top: 14px;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gallery-item img,
    .gallery-zoom,
    .gallery-item::after {
        transition: none;
    }
}
