/**
 * Location Gallery Block - Frontend Styles
 */

.wp-block-portal-loc-re-gallery {
    padding: 4rem 0;
    background: white;

    .loc-re-container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 0 2rem;

        @media (max-width: 768px) {
            padding: 0 1rem;
        }
    }

    .loc-re-gallery-header {
        text-align: center;
        margin-bottom: 3rem;

        h3 {
            font-size: clamp(2rem, 4vw, 2.5rem);
            font-weight: 700;
            color: var(--loc-re-text-dark, #1f2937);
            margin-bottom: 1rem;
            line-height: 1.2;
        }

        p {
            font-size: 1.125rem;
            color: var(--loc-re-text-gray, #6b7280);
            max-width: 600px;
            margin: 0 auto;
            line-height: 1.6;

            @media (max-width: 768px) {
                font-size: 1rem;
            }
        }
    }

    .loc-re-gallery-grid {
        display: grid;
        gap: 1rem;
        
        // Dynamic grid based on columns attribute
        &[data-columns="1"] { grid-template-columns: 1fr; }
        &[data-columns="2"] { grid-template-columns: repeat(2, 1fr); }
        &[data-columns="3"] { grid-template-columns: repeat(3, 1fr); }
        &[data-columns="4"] { grid-template-columns: repeat(4, 1fr); }
        &[data-columns="5"] { grid-template-columns: repeat(5, 1fr); }
        &[data-columns="6"] { grid-template-columns: repeat(6, 1fr); }

        @media (max-width: 1024px) {
            &[data-columns="4"],
            &[data-columns="5"],
            &[data-columns="6"] {
                grid-template-columns: repeat(3, 1fr);
            }
        }

        @media (max-width: 768px) {
            &[data-columns="3"],
            &[data-columns="4"],
            &[data-columns="5"],
            &[data-columns="6"] {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 480px) {
            grid-template-columns: 1fr;
            gap: 0.75rem;
        }
    }

    .loc-re-gallery-item {
        position: relative;
        border-radius: 0.75rem;
        overflow: hidden;
        background: var(--loc-re-bg-light, #f9fafb);
        transition: all 0.3s ease;
        cursor: pointer;

        // Aspect ratio container
        &::before {
            content: '';
            display: block;
            padding-bottom: 75%; // 4:3 aspect ratio
        }

        img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s ease;
        }

        a {
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            text-decoration: none;
        }

        &:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

            img {
                transform: scale(1.05);
            }

            .loc-re-gallery-overlay {
                opacity: 1;
            }
        }

        // Overlay for lightbox indication
        .loc-re-gallery-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.4);
            display: flex;
            align-items: center;
            justify-content: center;
            opacity: 0;
            transition: opacity 0.3s ease;
            z-index: 1;

            &::before {
                content: '🔍';
                font-size: 2rem;
                color: white;
                text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
            }
        }

        .loc-re-gallery-caption {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
            color: white;
            padding: 2rem 1rem 1rem;
            font-size: 0.875rem;
            line-height: 1.4;
            z-index: 2;

            @media (max-width: 480px) {
                padding: 1.5rem 0.75rem 0.75rem;
                font-size: 0.8rem;
            }
        }

        // Staggered animation on load
        opacity: 0;
        transform: translateY(30px);

        &.animate-in {
            animation: fadeInUp 0.6s ease-out forwards;
        }

        // Stagger delays
        &:nth-child(1).animate-in { animation-delay: 0.1s; }
        &:nth-child(2).animate-in { animation-delay: 0.15s; }
        &:nth-child(3).animate-in { animation-delay: 0.2s; }
        &:nth-child(4).animate-in { animation-delay: 0.25s; }
        &:nth-child(5).animate-in { animation-delay: 0.3s; }
        &:nth-child(6).animate-in { animation-delay: 0.35s; }
        &:nth-child(7).animate-in { animation-delay: 0.4s; }
        &:nth-child(8).animate-in { animation-delay: 0.45s; }
        &:nth-child(9).animate-in { animation-delay: 0.5s; }
    }

    // Masonry layout option (if needed)
    &.loc-re-gallery-masonry {
        .loc-re-gallery-grid {
            column-count: 3;
            column-gap: 1rem;

            @media (max-width: 768px) {
                column-count: 2;
            }

            @media (max-width: 480px) {
                column-count: 1;
            }
        }

        .loc-re-gallery-item {
            break-inside: avoid;
            margin-bottom: 1rem;

            &::before {
                display: none;
            }

            img {
                position: static;
                width: 100%;
                height: auto;
            }
        }
    }
}

// Lightbox styles
.loc-re-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;

    &.active {
        opacity: 1;
        visibility: visible;
    }

    .loc-re-lightbox-content {
        position: relative;
        max-width: 90vw;
        max-height: 90vh;
        margin: 2rem;

        img {
            max-width: 100%;
            max-height: 100%;
            object-fit: contain;
            border-radius: 0.5rem;
        }

        .loc-re-lightbox-caption {
            position: absolute;
            bottom: -3rem;
            left: 0;
            right: 0;
            color: white;
            text-align: center;
            font-size: 1rem;
            line-height: 1.4;
        }
    }

    .loc-re-lightbox-close {
        position: absolute;
        top: 2rem;
        right: 2rem;
        background: rgba(255, 255, 255, 0.2);
        border: none;
        color: white;
        font-size: 2rem;
        width: 3rem;
        height: 3rem;
        border-radius: 50%;
        cursor: pointer;
        transition: background 0.3s ease;
        backdrop-filter: blur(10px);

        &:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        @media (max-width: 768px) {
            top: 1rem;
            right: 1rem;
            width: 2.5rem;
            height: 2.5rem;
            font-size: 1.5rem;
        }
    }

    .loc-re-lightbox-nav {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(255, 255, 255, 0.2);
        border: none;
        color: white;
        font-size: 1.5rem;
        width: 3rem;
        height: 3rem;
        border-radius: 50%;
        cursor: pointer;
        transition: background 0.3s ease;
        backdrop-filter: blur(10px);

        &:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        &.prev {
            left: 2rem;
        }

        &.next {
            right: 2rem;
        }

        @media (max-width: 768px) {
            width: 2.5rem;
            height: 2.5rem;
            font-size: 1.25rem;

            &.prev {
                left: 1rem;
            }

            &.next {
                right: 1rem;
            }
        }
    }
}

// Animations
@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

// Accessibility improvements
@media (prefers-reduced-motion: reduce) {
    .wp-block-portal-loc-re-gallery {
        .loc-re-gallery-item {
            animation: none;
            opacity: 1;
            transform: none;

            &:hover {
                transform: none;
            }

            img {
                transition: none;
            }
        }
    }

    .loc-re-lightbox {
        transition: none;
    }
}

// High contrast mode support
@media (prefers-contrast: high) {
    .wp-block-portal-loc-re-gallery {
        .loc-re-gallery-item {
            border: 2px solid var(--loc-re-text-dark, #1f2937);

            .loc-re-gallery-overlay {
                background: rgba(0, 0, 0, 0.8);
            }
        }
    }
}

// Print styles
@media print {
    .wp-block-portal-loc-re-gallery {
        .loc-re-gallery-item {
            break-inside: avoid;
            transform: none;
            box-shadow: none;

            .loc-re-gallery-overlay {
                display: none;
            }
        }
    }

    .loc-re-lightbox {
        display: none;
    }
}

