/**
 * MIN AI Gallery - CSS Styles
 * ===========================
 * Moderne Galerie-Styles mit CSS Grid/Flexbox.
 * Kein jQuery, keine externen Abhaengigkeiten.
 * WCAG 2.2 AA konform.
 *
 * (c) made in nature Projektagentur
 */

/* =========================================
   CSS Custom Properties (Design Tokens)
   ========================================= */

:root {
    /* Galerie-Variablen */
    --aigallery-columns: 4;
    --aigallery-gap: 1rem;
    --aigallery-aspect-ratio: 1;
    --aigallery-autoplay-delay: 5000ms;

    /* Farben */
    --aigallery-bg: #f5f5f5;
    --aigallery-text: #333;
    --aigallery-overlay-bg: rgba(0, 0, 0, 0.85);
    --aigallery-overlay-text: #fff;
    --aigallery-focus-color: #0066cc;

    /* Transitions */
    --aigallery-transition: 0.3s ease;

    /* Abstände */
    --aigallery-caption-padding: 0.75rem;
    --aigallery-button-size: 44px;
}

/* =========================================
   Base Styles
   ========================================= */

.aigallery {
    position: relative;
    width: 100%;
}

.aigallery__item {
    position: relative;
    overflow: hidden;
    margin: 0;
}

.aigallery__link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.aigallery__image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* =========================================
   Grid Layout
   ========================================= */

.aigallery--grid {
    display: grid;
    grid-template-columns: repeat(var(--aigallery-columns), 1fr);
    gap: var(--aigallery-gap);
}

.aigallery--grid .aigallery__item {
    aspect-ratio: var(--aigallery-aspect-ratio);
}

/* Responsive Grid */
@media (max-width: 1199px) {
    .aigallery--grid {
        --aigallery-columns: 3;
    }
}

@media (max-width: 767px) {
    .aigallery--grid {
        --aigallery-columns: 2;
    }
}

@media (max-width: 479px) {
    .aigallery--grid {
        --aigallery-columns: 1;
    }
}

/* =========================================
   Masonry Layout
   ========================================= */

.aigallery--masonry {
    column-count: var(--aigallery-columns);
    column-gap: var(--aigallery-gap);
}

.aigallery--masonry .aigallery__item {
    break-inside: avoid;
    margin-bottom: var(--aigallery-gap);
}

.aigallery--masonry .aigallery__item--preserve-ratio .aigallery__image {
    height: auto;
    object-fit: contain;
}

/* Responsive Masonry */
@media (max-width: 1199px) {
    .aigallery--masonry {
        column-count: 3;
    }
}

@media (max-width: 767px) {
    .aigallery--masonry {
        column-count: 2;
    }
}

@media (max-width: 479px) {
    .aigallery--masonry {
        column-count: 1;
    }
}

/* =========================================
   Carousel Layout
   ========================================= */

.aigallery--carousel {
    position: relative;
    overflow: hidden;
}

.aigallery__track {
    display: flex;
    transition: transform var(--aigallery-transition);
}

.aigallery__slide {
    flex: 0 0 100%;
    min-width: 100%;
}

.aigallery__slide[aria-hidden="true"] {
    display: none;
}

/* Navigation Buttons */
.aigallery__nav {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    padding: 0 1rem;
    pointer-events: none;
    z-index: 10;
}

.aigallery__prev,
.aigallery__next {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--aigallery-button-size);
    height: var(--aigallery-button-size);
    background: var(--aigallery-overlay-bg);
    color: var(--aigallery-overlay-text);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    transition: background-color var(--aigallery-transition);
}

.aigallery__prev:hover,
.aigallery__next:hover {
    background: rgba(0, 0, 0, 0.95);
}

.aigallery__prev:focus-visible,
.aigallery__next:focus-visible {
    outline: 2px solid var(--aigallery-focus-color);
    outline-offset: 2px;
}

.aigallery__prev:disabled,
.aigallery__next:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Pagination */
.aigallery__pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
}

.aigallery__bullet {
    width: 12px;
    height: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color var(--aigallery-transition);
}

.aigallery__bullet:hover,
.aigallery__bullet--active {
    background: var(--aigallery-focus-color);
}

.aigallery__bullet:focus-visible {
    outline: 2px solid var(--aigallery-focus-color);
    outline-offset: 2px;
}

/* Fraction Pagination */
.aigallery__fraction {
    font-size: 0.875rem;
    color: var(--aigallery-text);
    font-variant-numeric: tabular-nums;
}

/* Progress Bar Pagination */
.aigallery__progressbar {
    width: 100%;
    max-width: 200px;
    height: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.aigallery__progressbar-fill {
    height: 100%;
    background: var(--aigallery-focus-color);
    transition: width var(--aigallery-transition);
}

/* Autoplay Toggle */
.aigallery__autoplay-toggle {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--aigallery-overlay-bg);
    color: var(--aigallery-overlay-text);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
}

.aigallery__autoplay-toggle:focus-visible {
    outline: 2px solid var(--aigallery-focus-color);
    outline-offset: 2px;
}

/* =========================================
   Aspect Ratio Variants
   ========================================= */

.aigallery--format-square .aigallery__item {
    --aigallery-aspect-ratio: 1;
}

.aigallery--format-widescreen .aigallery__item {
    --aigallery-aspect-ratio: 16/9;
}

.aigallery--format-skyscraper .aigallery__item {
    --aigallery-aspect-ratio: 9/16;
}

.aigallery--format-landscape .aigallery__item {
    --aigallery-aspect-ratio: 4/3;
}

.aigallery--format-panorama .aigallery__item {
    --aigallery-aspect-ratio: 21/9;
}

.aigallery--format-original .aigallery__item {
    aspect-ratio: auto;
}

.aigallery--format-original .aigallery__image {
    height: auto;
}

/* =========================================
   Hover Effects
   ========================================= */

.aigallery--hover-zoom .aigallery__image {
    transition: transform var(--aigallery-transition);
}

.aigallery--hover-zoom .aigallery__item:hover .aigallery__image,
.aigallery--hover-zoom .aigallery__link:focus .aigallery__image {
    transform: scale(1.05);
}

.aigallery--hover-fade .aigallery__image {
    transition: opacity var(--aigallery-transition);
}

.aigallery--hover-fade .aigallery__item:hover .aigallery__image,
.aigallery--hover-fade .aigallery__link:focus .aigallery__image {
    opacity: 0.8;
}

.aigallery--hover-slide .aigallery__item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
    opacity: 0;
    transition: opacity var(--aigallery-transition);
}

.aigallery--hover-slide .aigallery__item:hover::after,
.aigallery--hover-slide .aigallery__link:focus ~ ::after {
    opacity: 1;
}

/* =========================================
   Caption Styles
   ========================================= */

.aigallery__caption {
    padding: var(--aigallery-caption-padding);
    background: var(--aigallery-bg);
}

.aigallery__title {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.aigallery__description {
    display: block;
    font-size: 0.875rem;
    opacity: 0.8;
}

/* Caption Overlay */
.aigallery--caption-overlay .aigallery__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--aigallery-overlay-bg);
    color: var(--aigallery-overlay-text);
}

/* Caption on Hover */
.aigallery--caption-hover .aigallery__caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--aigallery-overlay-bg);
    color: var(--aigallery-overlay-text);
    transform: translateY(100%);
    transition: transform var(--aigallery-transition);
}

.aigallery--caption-hover .aigallery__item:hover .aigallery__caption,
.aigallery--caption-hover .aigallery__link:focus + .aigallery__caption {
    transform: translateY(0);
}

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

.aigallery-lightbox {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    z-index: 9999;
}

.aigallery-lightbox::backdrop {
    background: var(--aigallery-overlay-bg);
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    cursor: pointer;
}

.lightbox-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
}

.lightbox-figure {
    max-width: 90vw;
    max-height: 80vh;
    margin: 0;
    text-align: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 75vh;
    object-fit: contain;
}

.lightbox-caption {
    padding: 1rem 0;
    color: var(--aigallery-overlay-text);
}

.lightbox-title {
    display: block;
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.lightbox-description {
    display: block;
    font-size: 0.875rem;
    opacity: 0.8;
}

/* Lightbox Navigation */
.lightbox-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.lightbox-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--aigallery-button-size);
    height: var(--aigallery-button-size);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: var(--aigallery-overlay-text);
    cursor: pointer;
    transition: background-color var(--aigallery-transition);
}

.lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-btn:focus-visible {
    outline: 2px solid var(--aigallery-overlay-text);
    outline-offset: 2px;
}

.lightbox-btn svg {
    width: 24px;
    height: 24px;
}

.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

.lightbox-counter {
    color: rgba(255, 255, 255, 0.7);
    font-variant-numeric: tabular-nums;
}

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

.aigallery--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background: var(--aigallery-bg);
    border-radius: 4px;
}

.aigallery__empty-message {
    color: var(--aigallery-text);
    opacity: 0.7;
    font-style: italic;
}

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

/* Fokus-Stile */
.aigallery__link:focus-visible {
    outline: 2px solid var(--aigallery-focus-color);
    outline-offset: 2px;
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* =========================================
   Reduced Motion
   ========================================= */

@media (prefers-reduced-motion: reduce) {
    .aigallery__image,
    .aigallery__caption,
    .lightbox-image,
    .lightbox-btn,
    .aigallery__bullet,
    .aigallery__prev,
    .aigallery__next,
    .aigallery__track,
    .aigallery__progressbar-fill {
        transition: none !important;
    }

    .aigallery--hover-zoom .aigallery__item:hover .aigallery__image,
    .aigallery--hover-zoom .aigallery__link:focus .aigallery__image {
        transform: none;
    }
}

/* =========================================
   Lazy Loading Animation
   ========================================= */

.aigallery--lazy .aigallery__image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.aigallery--lazy .aigallery__image.loaded,
.aigallery--lazy .aigallery__image[style*="opacity: 1"] {
    opacity: 1;
}

/* Skeleton Loading (optional) */
.aigallery__item--loading {
    background: linear-gradient(90deg,
        var(--aigallery-bg) 0%,
        #e0e0e0 50%,
        var(--aigallery-bg) 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .aigallery__item--loading {
        animation: none;
        background: var(--aigallery-bg);
    }
}

/* =========================================
   Print Styles
   ========================================= */

/* =========================================
   Slider Layout
   ========================================= */

.aigallery--slider {
    position: relative;
    overflow: hidden;
    width: 100%;
}

.aigallery__slider-track {
    position: relative;
    width: 100%;
    height: 100%;
}

.aigallery__slide {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease, visibility 0.6s ease;
    z-index: 1;
}

.aigallery__slide--active {
    position: relative;
    opacity: 1;
    visibility: visible;
    z-index: 2;
}

.aigallery__slide-inner {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.aigallery__image--slider {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Fullscreen/Hero Slider */
.aigallery--fullscreen {
    height: 100vh;
    height: 100dvh;
}

.aigallery--hero {
    height: 70vh;
    min-height: 400px;
    max-height: 800px;
}

/* Slider Navigation */
.aigallery__slider-nav {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    padding: 0 1.5rem;
    pointer-events: none;
    z-index: 10;
}

.aigallery__slider-prev,
.aigallery__slider-next {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    transition: background-color 0.3s ease, transform 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.aigallery__slider-prev:hover,
.aigallery__slider-next:hover {
    background: #fff;
    transform: scale(1.1);
}

.aigallery__slider-prev:focus-visible,
.aigallery__slider-next:focus-visible {
    outline: 2px solid var(--aigallery-focus-color);
    outline-offset: 2px;
}

.aigallery__slider-prev:disabled,
.aigallery__slider-next:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Slider Pagination */
.aigallery__slider-pagination {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 2rem;
    z-index: 10;
}

.aigallery__slider-pagination .aigallery__bullet {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.5);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.3s ease;
}

.aigallery__slider-pagination .aigallery__bullet:hover {
    background: rgba(255, 255, 255, 0.8);
}

.aigallery__slider-pagination .aigallery__bullet--active {
    background: #fff;
    transform: scale(1.2);
}

/* Slider Content Overlay */
.aigallery__slide-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 3rem 2rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
    color: #fff;
    z-index: 5;
}

.aigallery__slide-title {
    margin: 0 0 0.5rem;
    font-size: clamp(1.5rem, 4vw, 3rem);
    font-weight: 700;
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.aigallery__slide-description {
    margin: 0;
    font-size: clamp(1rem, 2vw, 1.25rem);
    line-height: 1.5;
    opacity: 0.9;
    max-width: 60ch;
}

/* =========================================
   Ken Burns Effect
   ========================================= */

.aigallery--kenburns .aigallery__slide-inner {
    animation: kenburns var(--aigallery-kenburns-duration, 8s) ease-out forwards;
    transform-origin: center center;
}

/* Verschiedene Ken Burns Varianten fuer visuelles Interesse */
.aigallery--kenburns .aigallery__slide:nth-child(4n+1) .aigallery__slide-inner {
    animation-name: kenburns-zoom-in;
    transform-origin: 30% 30%;
}

.aigallery--kenburns .aigallery__slide:nth-child(4n+2) .aigallery__slide-inner {
    animation-name: kenburns-zoom-out;
    transform-origin: 70% 70%;
}

.aigallery--kenburns .aigallery__slide:nth-child(4n+3) .aigallery__slide-inner {
    animation-name: kenburns-pan-left;
    transform-origin: 70% 50%;
}

.aigallery--kenburns .aigallery__slide:nth-child(4n+4) .aigallery__slide-inner {
    animation-name: kenburns-pan-right;
    transform-origin: 30% 50%;
}

/* Ken Burns nur auf aktivem Slide */
.aigallery--kenburns .aigallery__slide:not(.aigallery__slide--active) .aigallery__slide-inner {
    animation-play-state: paused;
    transform: scale(1);
}

@keyframes kenburns-zoom-in {
    0% {
        transform: scale(1);
    }
    100% {
        transform: scale(1.15);
    }
}

@keyframes kenburns-zoom-out {
    0% {
        transform: scale(1.15);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes kenburns-pan-left {
    0% {
        transform: scale(1.1) translateX(0);
    }
    100% {
        transform: scale(1.1) translateX(-5%);
    }
}

@keyframes kenburns-pan-right {
    0% {
        transform: scale(1.1) translateX(0);
    }
    100% {
        transform: scale(1.1) translateX(5%);
    }
}

/* Ken Burns Deaktivierung bei reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .aigallery--kenburns .aigallery__slide-inner {
        animation: none !important;
        transform: none !important;
    }
}

/* =========================================
   Responsive Slider
   ========================================= */

@media (max-width: 767px) {
    .aigallery__slider-nav {
        padding: 0 0.75rem;
    }

    .aigallery__slider-prev,
    .aigallery__slider-next {
        width: 44px;
        height: 44px;
    }

    .aigallery__slider-prev svg,
    .aigallery__slider-next svg {
        width: 24px;
        height: 24px;
    }

    .aigallery__slide-content {
        padding: 2rem 1rem;
    }

    .aigallery--hero {
        height: 50vh;
        min-height: 300px;
    }

    .aigallery__slider-pagination {
        bottom: 1rem;
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }

    .aigallery__slider-pagination .aigallery__bullet {
        width: 8px;
        height: 8px;
    }
}

/* =========================================
   Print Styles
   ========================================= */

@media print {
    .aigallery--carousel .aigallery__nav,
    .aigallery--carousel .aigallery__pagination,
    .aigallery--carousel .aigallery__autoplay-toggle,
    .aigallery--slider .aigallery__slider-nav,
    .aigallery--slider .aigallery__slider-pagination,
    .aigallery--slider .aigallery__autoplay-toggle,
    .aigallery-lightbox {
        display: none !important;
    }

    .aigallery--carousel .aigallery__slide,
    .aigallery--slider .aigallery__slide {
        display: block !important;
        position: relative !important;
        opacity: 1 !important;
        visibility: visible !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .aigallery--kenburns .aigallery__slide-inner {
        animation: none !important;
        transform: none !important;
    }

    .aigallery {
        display: block !important;
    }

    .aigallery--grid,
    .aigallery--masonry {
        display: block;
        column-count: 2;
    }

    .aigallery__item {
        margin-bottom: 1rem;
        break-inside: avoid;
    }
}
