/**
 * WLA Modern Gallery v2
 * Modern grid-based gallery with PhotoSwipe 5 lightbox
 */

/* CSS Variables for easy theming */
.wla-gallery {
    --gallery-gap: 10px;
    --thumb-size-min: 180px;
    --thumb-size-max: 220px;
    --thumb-radius: 8px;
    --accent-color: #2563eb;
    --text-muted: #6b7280;
    --bg-light: #f9fafb;
    --bg-overlay: rgba(0, 0, 0, 0.6);
}

/* Main container */
.wla-gallery {
    margin: 0 auto;
    max-width: 100%;
}

/* Header with photo count */
.wla-gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    margin-bottom: 16px;
}

.wla-gallery-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
}

.wla-gallery-count {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-light);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
}

.wla-gallery-count svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

/* Tabs for photos/videos */
.wla-gallery-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #e5e7eb;
}

.wla-gallery-tab {
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-weight: 500;
    color: var(--text-muted);
    transition: color 0.2s, border-color 0.2s;
    user-select: none;
}

.wla-gallery-tab:hover {
    color: #374151;
}

.wla-gallery-tab.active {
    border-bottom-color: var(--accent-color);
    color: var(--accent-color);
}

/* Grid layout */
.wla-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--thumb-size-min), 1fr));
    gap: var(--gallery-gap);
}

/* Hero mode - large first image */
.wla-gallery-hero-container {
    margin-bottom: var(--gallery-gap);
}

.wla-gallery-hero-link {
    display: block;
    width: 100%;
    border-radius: var(--thumb-radius);
    overflow: hidden;
}

.wla-gallery-hero {
    width: 100%;
    max-height: 500px;
    object-fit: cover;
    cursor: pointer;
    display: block;
    transition: transform 0.3s ease;
}

.wla-gallery-hero-link:hover .wla-gallery-hero {
    transform: scale(1.01);
}

/* Thumbnail grid after hero */
.wla-gallery-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
    margin-top: var(--gallery-gap);
}

.wla-gallery-thumbs .wla-gallery-thumb {
    height: 70px;
}

/* Individual thumbnails */
.wla-gallery-item {
    position: relative;
    display: block;
    border-radius: var(--thumb-radius);
    overflow: hidden;
    background: var(--bg-light);
}

.wla-gallery-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    cursor: pointer;
    display: block;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.wla-gallery-item:hover .wla-gallery-thumb {
    transform: scale(1.03);
}

.wla-gallery-item:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* "View more" tile */
.wla-gallery-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
    color: white;
    font-weight: 700;
    font-size: 2rem;
    cursor: pointer;
    border-radius: var(--thumb-radius);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    user-select: none;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.wla-gallery-more:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 25px rgba(30, 58, 95, 0.5);
    background: linear-gradient(135deg, #2d5a87 0%, #3d7ab7 100%);
}

.wla-gallery-more-label {
    font-size: 1rem;
    font-weight: 500;
    opacity: 0.95;
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Video thumbnails */
.wla-gallery-video-item {
    position: relative;
    border-radius: var(--thumb-radius);
    overflow: hidden;
    cursor: pointer;
}

.wla-gallery-video-item .wla-gallery-thumb {
    aspect-ratio: 16/9;
}

.wla-gallery-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    background: var(--bg-overlay);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    transition: background 0.2s, transform 0.2s;
    pointer-events: none;
}

.wla-gallery-video-item:hover .wla-gallery-play-icon {
    background: rgba(0, 0, 0, 0.8);
    transform: translate(-50%, -50%) scale(1.1);
}

/* Video modal */
.wla-video-modal {
    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: opacity 0.3s, visibility 0.3s;
}

.wla-video-modal.active {
    opacity: 1;
    visibility: visible;
}

.wla-video-modal-content {
    position: relative;
    width: 90%;
    max-width: 900px;
    aspect-ratio: 16/9;
}

.wla-video-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 30px;
    cursor: pointer;
    padding: 5px 10px;
}

.wla-video-modal iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
}

/* Hidden items (for PhotoSwipe navigation) */
.wla-gallery-hidden {
    display: none !important;
}

/* Loading state */
.wla-gallery-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--text-muted);
}

.wla-gallery-loading::after {
    content: '';
    width: 30px;
    height: 30px;
    border: 3px solid var(--bg-light);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: wla-gallery-spin 0.8s linear infinite;
}

@keyframes wla-gallery-spin {
    to { transform: rotate(360deg); }
}

/* Empty state */
.wla-gallery-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

/* Image group sections */
.wla-gallery-group-section {
    margin-bottom: 32px;
}

.wla-gallery-group-section:last-child {
    margin-bottom: 0;
}

.wla-gallery-group-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #374151;
    margin: 0 0 16px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid #e5e7eb;
}

.wla-gallery-group-count {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.25);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 1.1rem;
    font-weight: 500;
    color: #fff;
    margin-left: 12px;
    vertical-align: middle;
}

.wla-gallery-grid-grouped {
    margin-bottom: 0;
}

/* Smaller "View All" button for groups */
.wla-gallery-more-group {
    font-size: 1.5rem;
}

.wla-gallery-more-group .wla-gallery-more-label {
    font-size: 0.85rem;
}

/* Responsive adjustments */
@media (min-width: 768px) {
    .wla-gallery {
        --thumb-size-min: 200px;
    }

    .wla-gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(var(--thumb-size-min), 1fr));
    }
}

@media (min-width: 1024px) {
    .wla-gallery {
        --thumb-size-min: 220px;
    }
}

@media (max-width: 480px) {
    .wla-gallery {
        --thumb-size-min: 140px;
        --gallery-gap: 8px;
    }

    .wla-gallery-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .wla-gallery-more {
        font-size: 1.5rem;
    }

    .wla-gallery-more-label {
        font-size: 0.85rem;
    }

    .wla-gallery-tabs {
        width: 100%;
        overflow-x: auto;
    }

    .wla-gallery-tab {
        padding: 8px 16px;
        white-space: nowrap;
    }

    .wla-gallery-hero {
        max-height: 300px;
    }

    .wla-gallery-thumbs {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }

    .wla-gallery-thumbs .wla-gallery-thumb {
        height: 55px;
    }
}

/* PhotoSwipe customizations */
.pswp {
    --pswp-bg: rgba(0, 0, 0, 0.9);
}

.pswp__counter {
    font-size: 14px;
    font-weight: 500;
}

/* Caption styling in lightbox */
.pswp__caption {
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    padding: 20px 15px 15px;
}

.pswp__caption__center {
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
    font-size: 14px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.9);
}

/* Legacy compatibility - hide old Galleria if both exist */
.wla-gallery ~ .facility_gallery,
.wla-gallery ~ .custom-galleria {
    display: none !important;
}
