/* Gallery Modal - Responsive Lightbox with Carousel Functionality */

/* Modal Overlay */
.gallery-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.gallery-modal.active {
    display: block;
    opacity: 1;
}

/* Modal Content Container */
.gallery-modal-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
}

/* Main Image Container */
.gallery-modal-image-container {
    position: relative;
    max-width: 90%;
    max-height: 80%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: visible;
}

/* Main Image */
.gallery-modal-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    transition: transform 0.3s ease;
}

/* Image Loading State */
.gallery-modal-image.loading {
    opacity: 0.5;
}

/* Close Button */
.gallery-modal-close {
    position: absolute;
    top: 15px;
    right: 25px;
    color: #fff;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.gallery-modal-close:hover,
.gallery-modal-close:focus {
    background: rgba(0, 0, 0, 0.8);
    outline: 2px solid #fff;
}

/* Navigation Arrows */
.gallery-modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
    user-select: none;
}

.gallery-modal-nav:hover,
.gallery-modal-nav:focus {
    background: rgba(0, 0, 0, 0.8);
    outline: 2px solid #fff;
}

.gallery-modal-nav.prev {
    left: 20px;
}

.gallery-modal-nav.next {
    right: 20px;
}

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

/* Image Counter */
.gallery-modal-counter {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    z-index: 10;
}

/* Caption Area - Positioned above the image */
.gallery-modal-caption {
    position: absolute;
    top: -40px;
    left: 0;
    max-width: 90%;
    text-align: left;
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
}

.gallery-modal-alt {
    display: inline;
    font-weight: bold;
    margin-right: 8px;
}

.gallery-modal-desc {
    display: inline;
    opacity: 0.9;
    font-style: italic;
}

/* Thumbnail Navigation Strip */
.gallery-modal-thumbnails {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    max-width: 80%;
    overflow-x: auto;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 25px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.gallery-modal-thumbnails::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Individual Thumbnails */
.gallery-modal-thumb {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.3s ease, transform 0.2s ease;
    border: 2px solid transparent;
    flex-shrink: 0;
}

.gallery-modal-thumb:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.gallery-modal-thumb.active {
    opacity: 1;
    border-color: #fff;
    transform: scale(1.1);
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .gallery-modal-content {
        padding: 10px;
    }
    
    .gallery-modal-image-container {
        max-height: 70%;
    }
    
    .gallery-modal-close {
        top: 10px;
        right: 15px;
        font-size: 28px;
        width: 40px;
        height: 40px;
    }
    
    .gallery-modal-nav {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
    
    .gallery-modal-nav.prev {
        left: 10px;
    }
    
    .gallery-modal-nav.next {
        right: 10px;
    }
    
    .gallery-modal-caption {
        top: -35px;
    }
    
    .gallery-modal-alt {
        font-size: 14px;
    }
    
    .gallery-modal-desc {
        font-size: 12px;
    }
    
    .gallery-modal-thumbnails {
        bottom: 10px;
        max-width: 90%;
        padding: 8px;
    }
    
    .gallery-modal-thumb {
        width: 40px;
        height: 40px;
    }
    
    .gallery-modal-counter {
        top: 15px;
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* Very Small Screens */
@media (max-width: 480px) {
    .gallery-modal-thumbnails {
        display: none; /* Hide thumbnails on very small screens */
    }
    
    .gallery-modal-image-container {
        max-height: 75%;
    }
    
    .gallery-modal-caption {
        top: -30px;
        max-width: 95%;
    }
}

/* Loading Animation */
.gallery-modal-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: gallery-spin 1s linear infinite;
    z-index: 5;
}

@keyframes gallery-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Accessibility Features */
.gallery-modal-close:focus,
.gallery-modal-nav:focus,
.gallery-modal-thumb:focus {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .gallery-modal {
        display: none !important;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .gallery-modal {
        background-color: rgba(0, 0, 0, 0.95);
    }
    
    .gallery-modal-close,
    .gallery-modal-nav {
        background: rgba(0, 0, 0, 0.9);
        border: 2px solid #fff;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .gallery-modal,
    .gallery-modal-image,
    .gallery-modal-close,
    .gallery-modal-nav,
    .gallery-modal-thumb {
        transition: none;
    }
    
    .gallery-modal-loading {
        animation: none;
        border: 4px solid #fff;
    }
}

/* === PHASE 3: PROFESSIONAL THUMBNAIL STYLING === */

/* Integrated Gallery Labels - Physical nameplate attached to gallery border */
.gallery-integrated-label {
    position: absolute;
    top: -19px;
    left: 16px;
    font-size: 12px;
    font-weight: 500;
    color: #495057;
    padding: 4px 12px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px solid #dee2e6;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    display: flex;
    align-items: center;
    line-height: 1.2;
    box-shadow: 
        0 -2px 4px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    z-index: 2;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Connecting line that integrates label with gallery border */
.gallery-integrated-label::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-left: 1px solid #dee2e6;
    border-right: 1px solid #dee2e6;
}

/* Icon removed per user request */

/* Gallery Container - Groups multiple thumbnails in a post */
.gallery-post-container {
    position: relative; /* Required for absolute positioned label */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    margin: 20px 0;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 12px;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.gallery-post-container:has(.gallery-integrated-label) {
    margin-top: 32px; /* Add space for the protruding label */
}

/* Single Gallery Item - Professional Styling */
.gallery-item-single {
    position: relative;
    background: #fff;
    border-radius: 12px;
    overflow: visible;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: 2px solid transparent;
    padding-bottom: 10px;
    transform-origin: center center;
}

/* Removed entrance animations to prevent hover conflicts */

.gallery-item-single:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: #2196F3;
}

.gallery-item-single:focus {
    outline: 3px solid #2196F3;
    outline-offset: 2px;
}

/* Gallery Thumbnail Image - Perfect 1:1 Square */
.gallery-thumbnail {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    display: block;
    border-radius: 12px 12px 0 0;
    transition: filter 0.3s ease;
    /* Start as grayscale */
    filter: grayscale(1);
    /* Retina display optimization */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.gallery-item-single:hover .gallery-thumbnail {
    /* Remove grayscale and add color saturation on hover */
    filter: grayscale(0) saturate(1.2) brightness(1.05);
}

/* Gallery Item Content - No longer used for captions */
.gallery-item-content {
    display: none;
}

/* Gallery Item Caption - Under thumbnail with monospace font */
.gallery-item-caption {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    color: #495057;
    line-height: 1.3;
    margin-top: 8px;
    margin-bottom: 0;
    padding: 0 8px;
    text-align: left;
    font-style: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    background: transparent;
    position: relative;
    z-index: 2;
}

/* Gallery Item Hint - Removed for cleaner display */

/* Hover Overlay Effect - Removed to prevent covering images */

/* Gallery Badge - Shows image count when multiple images */
.gallery-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    z-index: 2;
    backdrop-filter: blur(4px);
}

/* Responsive Grid Adjustments */
@media (max-width: 768px) {
    .gallery-post-container {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
        padding: 15px;
        margin: 15px 0;
    }
    
    .gallery-thumbnail {
        aspect-ratio: 1 / 1;
    }
    
    /* Gallery item content no longer used */
    
    .gallery-item-caption {
        font-size: 12px;
        -webkit-line-clamp: 1;
    }
    
    .gallery-integrated-label {
        font-size: 15px;
        padding: 14px 15px 10px 15px;
        margin: -15px -15px 14px -15px;
    }
}

@media (max-width: 480px) {
    .gallery-post-container {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        padding: 12px;
    }
    
    .gallery-thumbnail {
        aspect-ratio: 1 / 1;
    }
    
    /* Gallery item content no longer used */
    
    .gallery-integrated-label {
        font-size: 14px;
        padding: 12px 12px 8px 12px;
        margin: -12px -12px 12px -12px;
    }
    
    .gallery-integrated-label::before {
        font-size: 14px; /* Slightly smaller icon on mobile */
    }
    
    /* Gallery hint removed */
}

/* Responsive Container Width - Based on thumbnail count */
.gallery-post-container.single-image {
    grid-template-columns: 1fr;
    max-width: 300px;
    margin: 20px auto;
}

.gallery-post-container.two-images {
    max-width: 420px;
    margin: 20px auto;
}

.gallery-post-container.three-images {
    max-width: 620px;
    margin: 20px auto;
}

.gallery-post-container.four-plus-images {
    max-width: 820px;
    margin: 20px auto;
}

.gallery-post-container.single-image .gallery-item-single {
    max-width: none;
}

.gallery-post-container.single-image .gallery-thumbnail {
    aspect-ratio: 1 / 1;
}

/* Loading State for Gallery Items */
.gallery-item-single.loading {
    opacity: 0.8;
    pointer-events: none;
}

.gallery-item-single.loading .gallery-thumbnail {
    background: linear-gradient(90deg, #f8f9fa 25%, #e9ecef 50%, #f8f9fa 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s ease-in-out infinite;
    aspect-ratio: 1 / 1;
    filter: grayscale(1);
}

/* Enhanced shimmer animation */
@keyframes loading-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Image fade-in after loading */
.gallery-thumbnail {
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
}

.gallery-thumbnail.loaded {
    opacity: 1;
    filter: grayscale(1);
}

/* Focus Indicators for Accessibility */
.gallery-item-single:focus-visible {
    outline: 3px solid #2196F3;
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .gallery-item-single {
        border: 2px solid #000;
        background: #fff;
    }
    
    .gallery-item-single:hover {
        border-color: #2196F3;
        background: #f0f8ff;
    }
    
    .gallery-post-container {
        background: #fff;
        border: 2px solid #000;
    }
}

/* Retina Display Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .gallery-thumbnail {
        image-rendering: auto;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    .gallery-item-single {
        transform: translateZ(0);
    }
}

/* High-resolution display optimization */
@media (-webkit-min-device-pixel-ratio: 3), (min-resolution: 288dpi) {
    .gallery-thumbnail {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* === DARK MODE SUPPORT FOR MILK THEME === */

/* Dark mode gallery container */
.fd_dark .gallery-post-container {
    background: linear-gradient(135deg, #242a36 0%, #171b24 100%);
    border-color: #444;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Dark mode gallery items */
.fd_dark .gallery-item-single {
    background: #101216;
    border-color: #333;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Dark mode integrated gallery labels */
.fd_dark .gallery-integrated-label {
    color: #e0e0e0;
    background: linear-gradient(135deg, #2a2f3a 0%, #1f242e 100%);
    border-color: #444;
    box-shadow: 
        0 -2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.fd_dark .gallery-integrated-label::after {
    background: linear-gradient(135deg, #2a2f3a 0%, #1f242e 100%);
    border-left-color: #444;
    border-right-color: #444;
}

.fd_dark .gallery-item-single:hover {
    border-color: #2196F3;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
}

/* Dark mode captions */
.fd_dark .gallery-item-caption {
    color: #e0e0e0;
}


/* Dark mode loading states */
.fd_dark .gallery-item-single.loading .gallery-thumbnail {
    background: linear-gradient(90deg, #242a36 25%, #171b24 50%, #242a36 75%);
}

/* Dark mode modal elements */
.fd_dark .gallery-modal {
    background-color: rgba(0, 0, 0, 0.95);
}

.fd_dark .gallery-modal-close,
.fd_dark .gallery-modal-nav {
    background: rgba(16, 18, 22, 0.8);
    color: #e0e0e0;
}

.fd_dark .gallery-modal-close:hover,
.fd_dark .gallery-modal-close:focus,
.fd_dark .gallery-modal-nav:hover,
.fd_dark .gallery-modal-nav:focus {
    background: rgba(16, 18, 22, 0.95);
    outline-color: #e0e0e0;
}

.fd_dark .gallery-modal-counter {
    background: rgba(16, 18, 22, 0.9);
    color: #e0e0e0;
}

.fd_dark .gallery-modal-thumbnails {
    background: rgba(16, 18, 22, 0.8);
}

.fd_dark .gallery-modal-thumb.active {
    border-color: #e0e0e0;
}

.fd_dark .gallery-modal-alt,
.fd_dark .gallery-modal-desc {
    color: #e0e0e0;
}

/* === FLUID/BOXED LAYOUT ADAPTATION === */

/* Fluid Layout: Allow galleries to expand and accommodate more thumbnails */
.body-layout-Fluid .gallery-post-container.two-images {
    max-width: 500px; /* Allow slight expansion */
}

.body-layout-Fluid .gallery-post-container.three-images {
    max-width: 750px; /* Allow growth to ~4 thumbnails */
}

.body-layout-Fluid .gallery-post-container.four-plus-images {
    max-width: 1100px; /* Full expansion for 5-6 thumbnails */
}

/* Boxed Layout: Maintain current conservative widths */
.body-layout-Boxed .gallery-post-container.two-images {
    max-width: 420px; /* Current behavior */
}

.body-layout-Boxed .gallery-post-container.three-images {
    max-width: 620px; /* Current behavior */
}

.body-layout-Boxed .gallery-post-container.four-plus-images {
    max-width: 820px; /* Current behavior */
}

/* Print Styles */
@media print {
    .gallery-post-container {
        background: none;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .gallery-item-single {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    /* Gallery hint already removed */
}