/* ==================== PHOTO GALLERY - OTTIMIZZATO ==================== */

/* OVERRIDE del layout a colonne di style.css */
#photos {
    line-height: normal !important;
    column-count: auto !important;
    column-gap: normal !important;
}

/* Layout Grid Ultra-Ottimizzato */
.photo-section {
    margin-bottom: 3rem;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Photo Item - Performance Ottimizzata */
.photo-item {
    position: relative;
    aspect-ratio: 3/2;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
    background: #e8e8e8;
    transition: transform 0.2s ease;
    will-change: transform;
}

.photo-item:hover {
    transform: translateY(-3px);
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.photo-item img.loaded {
    opacity: 1;
}

/* Skeleton Loader Minimale */
.photo-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #e8e8e8 25%, #f0f0f0 50%, #e8e8e8 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    z-index: 1;
}

.photo-item.loaded::before {
    display: none;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Loading Icon Minimale */
.photo-item .loading-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color, #ff8623);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 3;
}

.photo-item.loaded .loading-icon {
    display: none;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Section Header */
.section-header {
    text-align: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, rgba(255, 134, 35, 0.08) 0%, rgba(230, 117, 30, 0.08) 100%);
    border-radius: 10px;
    margin-bottom: 1.5rem;
    border-left: 4px solid var(--primary-color, #ff8623);
}

.section-header h3 {
    color: var(--primary-color, #ff8623);
    font-family: 'Playfair Display', serif;
    font-weight: 600;
    margin: 0 0 0.5rem 0;
    font-size: 1.4rem;
}

.section-header .photo-count {
    color: #6c757d;
    font-size: 0.9rem;
}

/* Stats Card */
.gallery-stats {
    background: linear-gradient(135deg, #ff8623 0%, #e6751e 100%);
    color: white;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2.5rem;
    box-shadow: 0 8px 25px rgba(255, 134, 35, 0.25);
}

.gallery-stats .stat-item {
    text-align: center;
}

.gallery-stats .stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: white;
}

.gallery-stats .stat-label {
    font-size: 1rem;
    opacity: 0.95;
}

/* Lightbox Ottimizzato - CON OVERRIDE FORZATI E ZOOM */
.lightbox-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.95) !important;
    z-index: 10000 !important;
    display: none !important;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.lightbox-overlay.active {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.lightbox-content {
    position: relative !important;
    max-width: 90% !important;
    max-height: 90% !important;
    display: flex !important;
    flex-direction: column;
    z-index: 10001 !important;
}

.lightbox-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    color: white;
    z-index: 10002 !important;
}

.photo-counter {
    font-size: 1rem;
    opacity: 0.9;
}

.lightbox-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lightbox-close:hover {
    background: var(--primary-color, #ff8623);
    transform: scale(1.05);
}

/* ZOOM STYLES */
.lightbox-image {
    max-width: 100% !important;
    max-height: 75vh !important;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: block !important;
    margin: 0 auto !important;
    cursor: zoom-in !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    transition: transform 0.3s ease !important;
    transform-origin: center center !important;
}

.lightbox-image.zoomed {
    cursor: grab !important;
}

.lightbox-image.zoomed:active {
    cursor: grabbing !important;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lightbox-nav:hover:not(:disabled) {
    background: var(--primary-color, #ff8623);
    transform: translateY(-50%) scale(1.05);
}

.lightbox-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.lightbox-prev { left: 15px; }
.lightbox-next { right: 15px; }

/* Thumbnails */
.lightbox-thumbnails {
    margin-top: 1rem;
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding: 0.5rem;
    max-width: 100%;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.lightbox-thumbnails::-webkit-scrollbar {
    height: 4px;
}

.lightbox-thumbnails::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.lightbox-thumb {
    flex: 0 0 70px;
    height: 50px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.lightbox-thumb:hover {
    opacity: 0.8;
}

.lightbox-thumb.active {
    opacity: 1;
    border-color: var(--primary-color, #ff8623);
}

.lightbox-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Back to Top */
.back-button {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--primary-color, #ff8623);
    color: white;
    border: none;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    font-size: 1.3rem;
    box-shadow: 0 4px 15px rgba(255, 134, 35, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
}

.back-button.visible {
    opacity: 1;
    visibility: visible;
}

.back-button:hover {
    background: #e6751e;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(255, 134, 35, 0.4);
}

/* Breadcrumb Custom */
.custom-breadcrumb {
    background: #f8f9fa;
    padding: 1rem 0;
    margin-bottom: 2rem;
}

.custom-breadcrumb .breadcrumb {
    background: none;
    margin: 0;
}

.custom-breadcrumb .breadcrumb-item a {
    color: var(--primary-color, #ff8623);
    text-decoration: none;
}

.custom-breadcrumb .breadcrumb-item a:hover {
    text-decoration: underline;
}

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 991px) {
    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

@media (max-width: 767px) {
    .photo-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .section-header {
        padding: 1rem;
    }
    
    .section-header h3 {
        font-size: 1.1rem;
    }
    
    .gallery-stats {
        padding: 1.5rem 1rem;
    }
    
    .gallery-stats .stat-number {
        font-size: 1.5rem;
    }
    
    .lightbox-nav {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
    
    .lightbox-prev { left: 10px; }
    .lightbox-next { right: 10px; }
    
    .lightbox-close {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }
    
    .back-button {
        width: 50px;
        height: 50px;
        font-size: 1.1rem;
        bottom: 1rem;
        right: 1rem;
    }
    
    .lightbox-thumb {
        flex: 0 0 60px;
        height: 45px;
    }
}

@media (max-width: 480px) {
    .photo-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header h3 {
        font-size: 1rem;
    }
}

/* Performance: Riduce animazioni su dispositivi lenti */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* FORZA IL MOSAICO 3x3 SU MOBILE */
@media (max-width: 767px) {
    #photos {
        line-height: normal !important;
        column-count: 1 !important;
        column-gap: 0 !important;
        display: block !important;
    }
    
    .photo-section {
        margin-bottom: 2rem !important;
        display: block !important;
    }
    
    .photo-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 4px !important;
        padding: 0 !important;
        margin: 0 !important;
        line-height: normal !important;
        column-count: auto !important;
    }
    
    .photo-item {
        width: 100% !important;
        padding-bottom: 100% !important;
        height: 0 !important;
        position: relative !important;
        border-radius: 4px !important;
        overflow: hidden !important;
        background: #e8e8e8 !important;
        display: block !important;
    }
    
    .photo-item img {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }
}