/**
 * Vilstaler Gallery Display Styles
 * Responsive gallery grid with accordion and lightbox
 */

/* ==========================================================================
   Container & Accordion
   ========================================================================== */

.vilstaler-galleries {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.gallery-accordion {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ==========================================================================
   Gallery Item (Accordion Item)
   ========================================================================== */

.gallery-item {
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    transition: box-shadow 0.3s ease;
}

.gallery-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   Gallery Header (Accordion Button)
   ========================================================================== */

.gallery-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: #f8f8f8;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    text-align: left;
    transition: background-color 0.2s ease;
}

.gallery-header:hover {
    background: #f0f0f0;
}

.gallery-header:focus {
    outline: 2px solid #0073aa;
    outline-offset: -2px;
}

.gallery-icon {
    font-size: 0.875rem;
    transition: transform 0.3s ease;
    flex-shrink: 0;
    display: inline-block;
    width: 1rem;
}

.gallery-header[aria-expanded="true"] .gallery-icon {
    transform: rotate(90deg);
}

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

.gallery-count {
    font-size: 0.875rem;
    color: #666;
    background: #e0e0e0;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    flex-shrink: 0;
}

/* ==========================================================================
   Gallery Content (Accordion Panel)
   ========================================================================== */

.gallery-content {
    padding: 1.5rem;
    border-top: 1px solid #ddd;
}

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

/* ==========================================================================
   Gallery Grid
   ========================================================================== */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
}

.gallery-image-link {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: 4px;
    aspect-ratio: 1;
    background: #f5f5f5;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-image-link:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1;
}

.gallery-image-link:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.gallery-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease;
}

/* Lazy loading states */
.gallery-image.lazy {
    opacity: 0;
}

.gallery-image.lazy.loading {
    opacity: 0.5;
}

.gallery-image.lazy.loaded {
    opacity: 1;
}

/* ==========================================================================
   Lightbox
   ========================================================================== */

.vilstaler-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

.vilstaler-lightbox.active {
    opacity: 1;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: calc(90vh - 60px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-caption {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    color: #fff;
    text-align: center;
}

.lightbox-title {
    font-size: 1rem;
    font-weight: 500;
}

.lightbox-counter {
    font-size: 0.875rem;
    color: #ccc;
}

/* Lightbox Controls */
.lightbox-close,
.lightbox-prev,
.lightbox-next {
    position: absolute;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    transition: background-color 0.2s ease;
    border-radius: 4px;
    z-index: 1000000;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-close:focus,
.lightbox-prev:focus,
.lightbox-next:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.lightbox-close {
    top: 1rem;
    right: 1rem;
    font-size: 2.5rem;
    line-height: 1;
    padding: 0.25rem 0.75rem;
}

.lightbox-prev {
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

.lightbox-next {
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

/* Tablet (768px and below) */
@media (max-width: 768px) {
    .vilstaler-galleries {
        padding: 0 0.75rem;
        margin: 1.5rem auto;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    .gallery-header {
        padding: 0.875rem 1rem;
    }

    .gallery-title {
        font-size: 1.125rem;
    }

    .gallery-count {
        font-size: 0.8125rem;
        padding: 0.2rem 0.5rem;
    }

    .gallery-content {
        padding: 1rem;
    }

    .lightbox-prev,
    .lightbox-next {
        font-size: 1.5rem;
        padding: 0.375rem 0.75rem;
    }

    .lightbox-close {
        font-size: 2rem;
        top: 0.5rem;
        right: 0.5rem;
    }
}

/* Mobile (580px and below) */
@media (max-width: 580px) {
    .vilstaler-galleries {
        padding: 0 0.5rem;
        margin: 1rem auto;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }

    .gallery-header {
        padding: 0.75rem 0.875rem;
        gap: 0.75rem;
    }

    .gallery-title {
        font-size: 1rem;
    }

    .gallery-count {
        font-size: 0.75rem;
        padding: 0.2rem 0.4rem;
    }

    .gallery-content {
        padding: 0.875rem;
    }

    .lightbox-content {
        max-width: 95vw;
        max-height: 95vh;
    }

    .lightbox-image {
        max-height: calc(95vh - 50px);
    }

    .lightbox-prev {
        left: 0.5rem;
    }

    .lightbox-next {
        right: 0.5rem;
    }

    .lightbox-caption {
        font-size: 0.875rem;
        margin-top: 0.75rem;
    }
}

/* Extra small mobile (400px and below) */
@media (max-width: 400px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }

    .gallery-header {
        flex-wrap: wrap;
    }

    .gallery-count {
        order: 3;
        width: 100%;
        margin-top: 0.5rem;
        text-align: center;
    }
}

/* ==========================================================================
   Loading Spinner (Optional Enhancement)
   ========================================================================== */

.gallery-image-link::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #666;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-image-link:has(.lazy:not(.loaded))::before {
    opacity: 1;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.vilstaler-galleries-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.vilstaler-galleries-empty p {
    font-size: 1.125rem;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* Focus visible for keyboard navigation */
@supports selector(:focus-visible) {
    .gallery-header:focus {
        outline: none;
    }

    .gallery-header:focus-visible {
        outline: 2px solid #0073aa;
        outline-offset: -2px;
    }

    .gallery-image-link:focus {
        outline: none;
    }

    .gallery-image-link:focus-visible {
        outline: 2px solid #0073aa;
        outline-offset: 2px;
    }

    .lightbox-close:focus,
    .lightbox-prev:focus,
    .lightbox-next:focus {
        outline: none;
    }

    .lightbox-close:focus-visible,
    .lightbox-prev:focus-visible,
    .lightbox-next:focus-visible {
        outline: 2px solid #fff;
        outline-offset: 2px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
