/**
 * GWH Gallery - CSS Styles
 * A high-performance image gallery for TYPO3
 */

/* CSS Custom Properties (configurable via inline styles) */
.gwh-gallery {
    --gwh-gallery-columns: 4;
    --gwh-gallery-gap: 8px;
    --gwh-gallery-row-height: 200px;
    --gwh-gallery-transition: 0.3s ease;
    --gwh-gallery-overlay-bg: rgba(0, 0, 0, 0.7);
    --gwh-gallery-caption-bg: rgba(0, 0, 0, 0.75);
    --gwh-gallery-caption-color: #fff;
    --gwh-gallery-border-radius: 4px;
    --gwh-gallery-spinner-color: #333;

    position: relative;
    width: 100%;
}

/* Header - uses site_gwh CSS for span.kicker styling */
.gwh-gallery .ce-header {
    margin-bottom: 1.5rem;
}

/* Grid Container */
.gwh-gallery__grid {
    display: grid;
    gap: var(--gwh-gallery-gap);
}

/* Grid Layout */
.gwh-gallery__grid--grid {
    grid-template-columns: repeat(var(--gwh-gallery-columns), 1fr);
}

/* Masonry Layout */
.gwh-gallery__grid--masonry {
    grid-template-columns: repeat(var(--gwh-gallery-columns), 1fr);
    grid-auto-rows: 10px;
}

/* Justified Layout */
.gwh-gallery__grid--justified {
    display: flex;
    flex-wrap: wrap;
    gap: var(--gwh-gallery-gap);
}

.gwh-gallery__grid--justified .gwh-gallery__item {
    flex-grow: 1;
    height: var(--gwh-gallery-row-height);
}

/* Gallery Item */
.gwh-gallery__item {
    position: relative;
    overflow: hidden;
    border-radius: var(--gwh-gallery-border-radius);
    cursor: pointer;
    text-decoration: none;
    display: block;
    background-color: #f0f0f0;
}

.gwh-gallery__grid--grid .gwh-gallery__item {
    aspect-ratio: 1 / 1;
}

.gwh-gallery__grid--masonry .gwh-gallery__item {
    grid-row-end: span var(--masonry-span, 20);
}

/* Image Wrapper */
.gwh-gallery__img-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Image */
.gwh-gallery__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--gwh-gallery-transition), opacity var(--gwh-gallery-transition);
    opacity: 1;
}

.gwh-gallery__img--lazy {
    opacity: 0;
}

.gwh-gallery__img--lazy[src]:not([src^="data:"]) {
    opacity: 1;
}

.gwh-gallery__item:hover .gwh-gallery__img {
    transform: scale(1.05);
}

/* Caption Overlay */
.gwh-gallery__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem;
    background: var(--gwh-gallery-caption-bg);
    color: var(--gwh-gallery-caption-color);
    font-size: 0.875rem;
    line-height: 1.4;
    transform: translateY(100%);
    transition: transform var(--gwh-gallery-transition);
    max-height: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gwh-gallery__item:hover .gwh-gallery__caption,
.gwh-gallery__item:focus .gwh-gallery__caption {
    transform: translateY(0);
}

/* Load More */
.gwh-gallery__load-more {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
}

.gwh-gallery__load-more-btn {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--gwh-gallery-transition), transform 0.15s ease;
}

.gwh-gallery__load-more-btn:hover {
    transform: translateY(-2px);
}

.gwh-gallery__load-more-btn:active {
    transform: translateY(0);
}

/* Counter */
.gwh-gallery__counter {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: #666;
}

.gwh-gallery__counter-separator {
    margin: 0 0.25rem;
}

/* Loading Spinner */
.gwh-gallery__loading {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    z-index: 10;
}

.gwh-gallery__loading--visible {
    opacity: 1;
    visibility: visible;
}

.gwh-gallery__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f0f0f0;
    border-top-color: var(--gwh-gallery-spinner-color);
    border-radius: 50%;
    animation: gwh-gallery-spin 0.8s linear infinite;
}

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

/* Infinite Scroll Trigger */
.gwh-gallery__infinite-trigger {
    height: 1px;
    width: 100%;
}

/* Lightbox */
.gwh-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.gwh-lightbox--open {
    opacity: 1;
    visibility: visible;
}

.gwh-lightbox__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
}

.gwh-lightbox__container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.gwh-lightbox__image {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    transition: transform 0.3s ease-out, opacity 0.2s ease;
    will-change: transform, opacity;
    touch-action: pan-y pinch-zoom;
    -webkit-user-drag: none;
    user-select: none;
    pointer-events: none;
}

.gwh-lightbox__caption {
    color: #fff;
    padding: 1rem;
    text-align: center;
    font-size: 0.95rem;
    max-width: 600px;
    line-height: 1.5;
}

.gwh-lightbox__close,
.gwh-lightbox__prev,
.gwh-lightbox__next {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    z-index: 10;
}

.gwh-lightbox__close:hover,
.gwh-lightbox__prev:hover,
.gwh-lightbox__next:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.gwh-lightbox__close:focus,
.gwh-lightbox__prev:focus,
.gwh-lightbox__next:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.gwh-lightbox__close {
    top: 1rem;
    right: 1rem;
}

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

.gwh-lightbox__prev:hover {
    transform: translateY(-50%) scale(1.1);
}

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

.gwh-lightbox__next:hover {
    transform: translateY(-50%) scale(1.1);
}

.gwh-lightbox__counter {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.875rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 0.5rem 1rem;
    border-radius: 4px;
}

/* Swipe navigation styles */
.gwh-lightbox__nav--active {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: translateY(-50%) scale(1.15);
}

.gwh-lightbox__content {
    touch-action: pan-x pan-y;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
}

.gwh-lightbox__content:active {
    cursor: grabbing;
}

.gwh-lightbox__backdrop {
    will-change: opacity;
    transition: opacity 0.3s ease-out;
}

/* Responsive lightbox */
@media (max-width: 768px) {
    .gwh-lightbox__close,
    .gwh-lightbox__prev,
    .gwh-lightbox__next {
        width: 40px;
        height: 40px;
    }

    .gwh-lightbox__prev {
        left: 0.5rem;
    }

    .gwh-lightbox__next {
        right: 0.5rem;
    }

    .gwh-lightbox__close {
        top: 0.5rem;
        right: 0.5rem;
    }

    .gwh-lightbox__image {
        max-width: 100vw;
        max-height: 70vh;
    }

    .gwh-lightbox__caption {
        padding: 0.75rem;
        font-size: 0.875rem;
    }
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
    .gwh-gallery__grid--grid,
    .gwh-gallery__grid--masonry {
        grid-template-columns: repeat(min(var(--gwh-gallery-columns), 4), 1fr);
    }
}

@media (max-width: 992px) {
    .gwh-gallery__grid--grid,
    .gwh-gallery__grid--masonry {
        grid-template-columns: repeat(min(var(--gwh-gallery-columns), 3), 1fr);
    }
}

@media (max-width: 800px) {
    /* Force square grid layout on small screens */
    .gwh-gallery__grid--justified {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .gwh-gallery__grid--justified .gwh-gallery__item {
        height: auto !important;
        width: auto !important;
        aspect-ratio: 1 / 1;
        flex-grow: 0;
    }
}

@media (max-width: 768px) {
    .gwh-gallery__grid--grid,
    .gwh-gallery__grid--masonry {
        grid-template-columns: repeat(min(var(--gwh-gallery-columns), 2), 1fr);
    }

    .gwh-gallery__grid--justified {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .gwh-gallery__grid--grid,
    .gwh-gallery__grid--masonry {
        grid-template-columns: repeat(2, 1fr);
    }

    .gwh-gallery__grid--justified {
        grid-template-columns: repeat(2, 1fr);
    }

    .gwh-gallery__load-more-btn {
        width: 100%;
    }
}

/* Accessibility */
.gwh-gallery__item:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

.gwh-gallery__item:focus .gwh-gallery__caption {
    transform: translateY(0);
}

/* Print Styles */
@media print {
    .gwh-gallery__load-more,
    .gwh-gallery__loading,
    .gwh-gallery__counter {
        display: none !important;
    }

    .gwh-gallery__item {
        break-inside: avoid;
    }
}

/* Skeleton Loading Animation */
.gwh-gallery__item--skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: gwh-gallery-skeleton 1.5s infinite;
}

@keyframes gwh-gallery-skeleton {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .gwh-gallery__caption {
        background: #000;
        border-top: 2px solid #fff;
    }

    .gwh-gallery__item:focus {
        outline-width: 3px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .gwh-gallery__img {
        transition: none;
    }

    .gwh-gallery__caption {
        transition: none;
        transform: translateY(0);
        background: var(--gwh-gallery-caption-bg);
    }

    .gwh-gallery__spinner {
        animation: none;
    }

    @keyframes gwh-gallery-skeleton {
        0%, 100% {
            background-position: 0 0;
        }
    }
}
