/* ========================================
   Gallery Carousel Styles
   ======================================== */

/* Modal Overlay */
.gallery-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease-out, visibility 0.25s ease-out;
}

.gallery-modal.is-open {
    opacity: 1;
    visibility: visible;
}

.gallery-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Modal Content Container */
.gallery-modal-content {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Viewport & Track */
.gallery-viewport {
    width: 100%;
    max-width: 90vw;
    max-height: 80vh;
    overflow: hidden;
}

.gallery-track {
    display: flex;
    direction: ltr; /* Prevent RTL from reversing slide order — translateX relies on LTR flow */
    transition: transform 0.25s ease-out;
    will-change: transform;
}

.gallery-slide {
    flex: 0 0 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md, 1.5rem);
    position: relative;
}

.gallery-slide img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: var(--border-radius-md, 0.5rem);
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.gallery-slide.is-loaded img {
    opacity: 1;
}

/* Loader */
.gallery-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease-out;
}

.gallery-slide.is-loaded .gallery-loader {
    opacity: 0;
    pointer-events: none;
}

.gallery-loader__spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: gallery-spin 0.7s linear infinite;
}

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

/* Navigation Buttons */
button.gallery-nav, .gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s ease-out, transform 0.2s ease-out, border-color 0.2s ease-out;
    z-index: 10;
}

button.gallery-nav:hover:not(:disabled), .gallery-nav:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-50%) scale(1.1);
}

button.gallery-nav:disabled, .gallery-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

button.gallery-nav:focus-visible, .gallery-nav:focus-visible {
    outline: 2px solid var(--color-secondary, #14694a);
    outline-offset: 2px;
}

.gallery-prev {
    left: var(--spacing-md, 1.5rem);
}

.gallery-next {
    right: var(--spacing-md, 1.5rem);
}

/* Close Button */
button.gallery-close, .gallery-close {
    position: absolute;
    top: var(--spacing-md, 1.5rem);
    right: var(--spacing-md, 1.5rem);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(192, 98, 64, 0.8);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s ease-out, transform 0.2s ease-out;
    z-index: 10;
}

button.gallery-close:hover, .gallery-close:hover {
    background: rgba(192, 98, 64, 1);
    transform: scale(1.1);
}

button.gallery-close:focus-visible, .gallery-close:focus-visible {
    outline: 2px solid var(--color-secondary, #14694a);
    outline-offset: 2px;
}

/* Counter */
.gallery-counter {
    position: absolute;
    bottom: var(--spacing-lg, 2rem);
    left: 50%;
    transform: translateX(-50%);
    padding: var(--spacing-xs, 0.5rem) var(--spacing-sm, 1rem);
    background: rgba(0, 0, 0, 0.6);
    border-radius: var(--border-radius-md, 0.5rem);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .gallery-viewport {
        max-width: 100vw;
    }

    .gallery-slide {
        padding: var(--spacing-sm, 1rem);
    }

    .gallery-nav {
        width: 40px;
        height: 40px;
    }

    .gallery-prev {
        left: var(--spacing-xs, 0.5rem);
    }

    .gallery-next {
        right: var(--spacing-xs, 0.5rem);
    }

    .gallery-close {
        top: var(--spacing-sm, 1rem);
        right: var(--spacing-sm, 1rem);
    }
}

/* LQIP (Low Quality Image Placeholder) Progressive Loading */
.gallery-image-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

.gallery-thumbnail.lqip {
    filter: blur(10px);
    transform: scale(1.05); /* Prevent blur edges from showing */
    transition: filter 0.4s ease, transform 0.4s ease;
}

.gallery-thumbnail.loaded {
    filter: blur(0);
    transform: scale(1);
}

/* Touch feedback for gallery items */
.gallery-item {
    cursor: pointer;
}

.gallery-item:focus-visible {
    outline: 3px solid var(--color-primary, #c06240);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .gallery-modal,
    .gallery-track,
    .gallery-nav,
    .gallery-close,
    .gallery-slide img,
    .gallery-loader {
        transition: none;
    }

    .gallery-loader__spinner {
        animation: none;
    }
}
