/**
 * Custom Photo Gallery Block Styles
 * Handles 3-7 photos with thumbnail row above or below main image
 */

/* Base Gallery Styles */
.custom-photo-gallery {
    position: relative;
    max-width: 100%;
    margin: 0 auto;
    font-family: inherit;
}

/* Main Photo Display */
.gallery-main {
    position: relative;
    overflow: hidden;
    margin-bottom: 1rem;
    justify-items: center;
}

/* Thumbnail position top - reverse margin */
.thumbnail-position-top .gallery-main {
    margin-bottom: 0;
    margin-top: 1rem;
}

.gallery-slides-container {
    position: relative;
    width: calc(100% - 70px);
    aspect-ratio: 4/3; /* Default 4:3 aspect ratio as recommended */
    overflow: hidden;
}

/* Gallery Slides */
.gallery-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    z-index: 1;
}

.gallery-slide.active {
    opacity: 1;
    z-index: 2;
}

/* Main Images */
.gallery-main-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

/* Navigation Arrows */
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: all 0.3s ease;
    opacity: 1;
    pointer-events: auto;
}

.gallery-nav:hover {
    transform: translateY(-50%) scale(1.05);
}

.gallery-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.gallery-nav svg {
    width: 17px;
    height: 16px;
    transition: all 0.3s ease;
    fill: #4E4E4E;
}

.gallery-nav-prev {
    left: 0;
}

.gallery-nav-next {
    right: 0;
}

.gallery-nav-prev:hover svg {
    fill: #a87b37;
}

.gallery-nav-next:hover svg {
    fill: #8b6a2e;
}

/* Slide Indicators (removed) */

/* Thumbnail Navigation */
.gallery-thumbnails {
    width: 100%;
}

.thumbnails-container {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: nowrap;
    padding: 8px 0;
    width: calc(100% - 70px);
    margin: auto;
}

/* When active thumbnail is hidden, expand remaining thumbnails to fill space */
.thumbnails-container.thumbnails-expanded {
    justify-content: space-between;
}

.thumbnails-container.thumbnails-expanded .gallery-thumbnail:not(.active) {
    flex: 1;
    max-width: calc((100% - (var(--visible-thumbnails, 6) - 1) * 12px) / var(--visible-thumbnails, 6));
}

/* Thumbnail Buttons */
.gallery-thumbnail {
    aspect-ratio: 3 / 2;
    border: none;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    background: none;
    padding: 0;
    position: relative;
    border: none;
}

.gallery-thumbnail:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.gallery-thumbnail.active {
    display: none;
}

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

.gallery-thumbnail:hover img {
    transform: scale(1.05);
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    .custom-photo-gallery {
        margin: 0 auto;
    }

    .gallery-slides-container {
        aspect-ratio: 3/2; /* Slightly wider on mobile */
    }

    /* Smaller navigation arrows on mobile */
    .gallery-nav {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .gallery-nav-prev {
        left: 10px;
    }

    .gallery-nav-next {
        right: 10px;
    }

    .thumbnails-container {
        gap: 8px;
    }

    /* Smaller indicators */
    .gallery-indicator {
        width: 10px;
        height: 10px;
    }
}

@media (max-width: 480px) {
    .gallery-slides-container {
        aspect-ratio: 16/10; /* Even wider on very small screens */
    }

    .gallery-nav {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .thumbnails-container {
        gap: 6px;
    }
}

/* Single image display */
.gallery-single-image-note {
    text-align: center;
    margin-top: 0.5rem;
    opacity: 0.7;
}

.gallery-single-image-note p {
    margin: 0;
    font-size: 0.875rem;
    font-style: italic;
}

/* Loading states */
.gallery-main-image[loading] {
    background: #f0f0f0;
}

/* Focus states for accessibility */
.gallery-nav:focus,
.gallery-thumbnail:focus,
.gallery-indicator:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* High contrast support */
@media (prefers-contrast: high) {
    .gallery-nav {
        background: rgba(0, 0, 0, 0.9);
        border: 2px solid white;
    }

    .gallery-indicator {
        border-width: 3px;
    }

    .gallery-thumbnail.active {
        border-width: 4px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .gallery-slide,
    .gallery-main-image,
    .gallery-nav,
    .gallery-thumbnail,
    .gallery-thumbnail img {
        transition: none;
    }
}

/* Print styles */
@media print {
    .gallery-nav,
    .gallery-indicators,
    .gallery-thumbnails {
        display: none;
    }

    .gallery-slide {
        position: static;
        opacity: 1;
        page-break-inside: avoid;
    }

    .gallery-slides-container {
        height: auto;
    }
}