/* ===========================================
   LIGHTBOX GALLERY - MODULAR & REUSABLE
   =========================================== */

/* ===========================================
   PORTFOLIO PLACEHOLDERS
   =========================================== */

/* Placeholder container for categories without images */
.portfolio-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #6b8494 0%, #2d4a57 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20%;
}

.portfolio-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.9;
    transition: opacity 0.3s ease;
}

.portfolio-item:hover .portfolio-placeholder img {
    opacity: 1;
}

/* Empty state in lightbox */
.gallery-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: rgba(255, 255, 255, 0.9);
}

.gallery-empty-state .empty-icon {
    width: 120px;
    height: 120px;
    margin-bottom: 1.5rem;
    opacity: 0.7;
}

.gallery-empty-state .empty-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.gallery-empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    color: white;
}

.gallery-empty-state p {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.7);
    max-width: 400px;
    line-height: 1.6;
}

/* Hide thumbnails when empty */
.gallery-lightbox.empty-gallery .gallery-thumbnails {
    display: none;
}

.gallery-lightbox.empty-gallery .gallery-counter {
    display: none;
}

.gallery-lightbox.empty-gallery .gallery-nav {
    display: none;
}

/* Lightbox Overlay */
.gallery-lightbox {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-lightbox.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
    overflow: hidden; /* Prevent page scroll */
}

/* Close Button */
.gallery-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 3rem;
    height: 3rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    transition: all 0.3s ease;
    z-index: 3001;
}

.gallery-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

/* Main Content Area - Improved Layout */
.gallery-content {
    flex: 1 1 auto;
    min-height: 0; /* Critical for flexbox overflow handling */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 5rem 2rem 1rem;
    position: relative;
    overflow: hidden; /* Prevent content overflow */
}

/* Category Title */
.gallery-title {
    position: absolute;
    top: 2rem;
    left: 2rem;
    color: white;
    font-size: 1.5rem;
    font-weight: 600;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* Image Counter */
.gallery-counter {
    position: absolute;
    top: 2rem;
    right: 5rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    font-weight: 500;
}

/* Main Image Container - Improved Dynamic Sizing */
.gallery-main-image {
    flex: 1 1 auto;
    min-height: 0; /* Allow flexbox shrinking */
    width: 100%;
    max-width: 95%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden; /* Prepare for zoom mode */
}

.gallery-main-image img {
    max-width: calc(100% - 140px); /* Space for nav buttons */
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 0.5rem;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    animation: galleryZoomIn 0.3s ease;
    cursor: pointer; /* Indicate clickability */
    transition: transform 0.3s ease, cursor 0.3s ease;
}

/* Zoom Mode Styles */
.gallery-main-image.zoom-mode {
    overflow: auto;
    cursor: grab;
    /* Keep centered alignment for proper zoom positioning */
    align-items: center;
    justify-content: center;
}

.gallery-main-image.zoom-mode:active {
    cursor: grabbing;
}

.gallery-main-image.zoom-mode img {
    max-width: none;
    max-height: none;
    width: auto;
    height: auto;
    cursor: grab;
    object-fit: none;
}

.gallery-main-image.zoom-mode:active img {
    cursor: grabbing;
}

@keyframes galleryZoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Navigation Arrows - Always Visible */
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 3.5rem;
    height: 3.5rem;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s ease, border-color 0.3s ease;
    color: white;
    font-size: 1.5rem;
    user-select: none;
    z-index: 3010; /* Above image and lightbox */
    pointer-events: auto;
}

.gallery-nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.gallery-nav.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.gallery-nav-prev {
    left: 2rem;
}

.gallery-nav-next {
    right: 2rem;
}

/* Desktop Zoom Mode: Fixed buttons so they don't scroll with image */
@media (min-width: 769px) {
    .gallery-main-image.zoom-mode .gallery-nav {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
    }
}

/* Description Area */
.gallery-description {
    margin-top: 1rem;
    max-width: 800px;
    text-align: center;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    line-height: 1.6;
    padding: 0 1rem;
    flex-shrink: 0; /* Don't shrink */
}

/* Thumbnails Container - Responsive Height */
.gallery-thumbnails {
    flex: 0 0 auto; /* Never shrink, fixed size */
    width: 100%;
    height: 15vh; /* Responsive viewport-based height */
    min-height: 120px; /* Minimum size for small screens */
    max-height: 180px; /* Maximum size for large screens */
    background: rgba(0, 0, 0, 0.3);
    padding: 1.5rem 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10; /* Always above image */
}

.gallery-thumbnails-inner {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    max-width: 1200px;
    padding: 0.5rem 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.gallery-thumbnails-inner::-webkit-scrollbar {
    height: 6px;
}

.gallery-thumbnails-inner::-webkit-scrollbar-track {
    background: transparent;
}

.gallery-thumbnails-inner::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.gallery-thumbnails-inner::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Individual Thumbnail */
.gallery-thumbnail {
    flex-shrink: 0;
    width: 8vh; /* Responsive thumbnail size */
    height: 8vh;
    min-width: 60px; /* Minimum size */
    min-height: 60px;
    max-width: 100px; /* Maximum size */
    max-height: 100px;
    border-radius: 0.375rem;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    position: relative;
}

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

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

.gallery-thumbnail.active {
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.gallery-thumbnail.active::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

/* Loading State */
.gallery-loading {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.2rem;
}

.gallery-lightbox.loading .gallery-loading {
    display: block;
}

.gallery-lightbox.loading .gallery-main-image {
    opacity: 0.5;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .gallery-title {
        font-size: 1.2rem;
        top: 1rem;
        left: 1rem;
    }
    
    .gallery-counter {
        top: 1rem;
        right: 3.5rem;
        font-size: 0.8rem;
    }
    
    .gallery-close {
        top: 1rem;
        right: 1rem;
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.2rem;
    }
    
    /* 
     * Mobile Layout with FIXED heights (no vh calculations):
     * - Header: 3rem
     * - Buttons: 3rem + 0.5rem gap = 3.5rem  
     * - Thumbnails: 100px (fixed)
     * - Content fills the rest
     */
    
    /* Mobile: Thumbnails - fixed height for reliable button positioning */
    .gallery-thumbnails {
        height: 100px; /* FIXED height - no vh! */
        min-height: 100px;
        max-height: 100px;
        padding: 0.75rem 1rem;
    }
    
    .gallery-thumbnail {
        width: 70px;
        height: 70px;
        min-width: 50px;
        min-height: 50px;
        max-width: 80px;
        max-height: 80px;
    }
    
    /* Mobile: Nav buttons - fixed directly above thumbnails */
    .gallery-nav {
        position: fixed;
        top: auto;
        bottom: 108px; /* 100px thumbnails + 8px gap */
        transform: none;
        width: 3rem;
        height: 3rem;
        font-size: 1.25rem;
        z-index: 3010;
    }
    
    .gallery-nav-prev {
        left: auto;
        right: calc(50% + 0.5rem);
    }
    
    .gallery-nav-next {
        left: calc(50% + 0.5rem);
        right: auto;
    }
    
    /* Mobile: Content area */
    .gallery-content {
        padding: 3rem 0.5rem 0;
        padding-bottom: 160px; /* 100px thumbnails + 3rem buttons + gap */
        justify-content: center;
        gap: 0.5rem;
    }
    
    /* Mobile: Image container fills available space */
    .gallery-main-image {
        flex: 1 1 auto;
        min-height: 0;
        width: 100%;
        max-width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
    }
    
    .gallery-main-image img {
        max-width: 100%;
        max-height: 100%;
        width: auto;
        height: auto;
        border-radius: 0.5rem;
    }
    
    /* Mobile: Description - compact, below image */
    .gallery-description {
        flex: 0 0 auto;
        font-size: 0.85rem;
        margin-top: 0.5rem;
        padding: 0 0.5rem;
        max-height: 3rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* =====================
     * MOBILE ZOOM MODE 
     * ===================== */
    .gallery-main-image.zoom-mode {
        /* Fill space between header and buttons */
        position: fixed;
        top: 3rem;
        left: 0;
        right: 0;
        bottom: 160px; /* Same as content padding-bottom */
        max-height: none;
        width: 100%;
        max-width: 100%;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 3005;
    }
    
    .gallery-main-image.zoom-mode img {
        max-width: none;
        max-height: none;
    }
    
    /* Mobile zoom: Hide description completely */
    .gallery-main-image.zoom-mode ~ .gallery-description {
        display: none !important;
    }
    
    /* Disable pulse animation on mobile */
    .gallery-lightbox.keyboard-nav .gallery-nav {
        animation: none;
    }
}

/* Touch Gestures Support */
.gallery-main-image {
    touch-action: pan-y pinch-zoom;
}

/* Keyboard Navigation Indicator - Desktop only */
@media (min-width: 769px) {
    .gallery-lightbox.keyboard-nav .gallery-nav {
        animation: pulse 0.5s ease;
    }
}

@keyframes pulse {
    0%, 100% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(-50%) scale(1.15); }
}

/* Accessibility: Focus Styles */
.gallery-nav:focus-visible,
.gallery-close:focus-visible,
.gallery-thumbnail:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .gallery-lightbox {
        background-color: rgb(0, 0, 0);
    }
    
    .gallery-nav,
    .gallery-close {
        border-color: white;
        background: rgba(255, 255, 255, 0.3);
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .gallery-lightbox,
    .gallery-main-image img,
    .gallery-thumbnail img,
    .gallery-nav,
    .gallery-close {
        animation: none !important;
        transition: none !important;
    }
}
