/* ============================================
   CSS COMPLETO CON SCROLL TO TOP BUTTON
   ============================================ */

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #7e8ba3 100%);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 50%, rgba(255,255,255,0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255,255,255,0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

body > * {
    position: relative;
    z-index: 1;
}

/* ============================================
   HEADER FISSO CON ICONA
   ============================================ */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    text-align: center;
    padding: 20px 20px 15px 20px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #7e8ba3 100%);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    color: white;
}

h1 {
    margin: 0 0 10px 0;
    font-size: 2.5rem;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.4);
    font-weight: 700;
}

.stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.stats {
    font-size: 0.95rem;
    opacity: 0.95;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.filters-icon-toggle {
    position: relative;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.filters-icon-toggle:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.filters-icon-toggle:active {
    transform: scale(0.95);
}

.filters-icon-toggle .toggle-icon {
    transition: transform 0.3s;
}

.filters-container.collapsed .filters-icon-toggle .toggle-icon {
    transform: rotate(180deg);
}

.filters-icon-toggle .filter-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff9800;
    color: white;
    padding: 3px 7px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.5);
}

.filters-icon-toggle .filter-badge:empty {
    display: none;
}

/* ============================================
   CONTENITORE FILTRI FISSO
   ============================================ */
.filters-container {
    position: sticky;
    top: 115px;
    z-index: 99;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #7e8ba3 100%);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    max-height: 500px;
    overflow: hidden;
}

.filters-content {
    padding: 15px 20px;
    transition: all 0.3s ease;
}

.filters-container.collapsed {
    max-height: 0;
    opacity: 0;
    box-shadow: none;
}

/* ============================================
   FILTRI CON GLASSMORPHISM
   ============================================ */
#filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 10px;
    padding: 20px;
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(20px) saturate(180%);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    border: 1px solid rgba(255,255,255,0.2);
}

#filters select,
#filters input {
    padding: 12px 16px;
    border-radius: 10px;
    border: 2px solid rgba(255,255,255,0.3);
    font-size: 15px;
    transition: all 0.3s;
    background: rgba(255,255,255,0.95);
}

#filters select:focus,
#filters input:focus {
    outline: none;
    border-color: #2a5298;
    box-shadow: 0 0 0 3px rgba(42, 82, 152, 0.2);
    background: white;
}

.btn-reset {
    padding: 12px 20px;
    background: #2a5298;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(42, 82, 152, 0.3);
}

.btn-reset:hover {
    background: #1e3c72;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(30, 60, 114, 0.4);
}

.btn-filter {
    padding: 12px 20px;
    background: rgba(255,255,255,0.95);
    color: #333;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s;
}

.btn-filter:hover {
    background: white;
    border-color: #2a5298;
    transform: translateY(-2px);
}

#people-count {
    display: inline-block;
    background: #2a5298;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    margin-left: 5px;
}

#people-count:empty {
    display: none;
}

.result-count {
    text-align: center;
    color: white;
    font-size: 1.1rem;
    margin: 0;
    padding: 0 0 10px 0;
    font-weight: 500;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}

.filter-hint {
    text-align: center;
    color: rgba(255,255,255,0.9);
    font-size: 0.85rem;
    margin: 0;
    padding: 0 0 10px 0;
    font-style: italic;
}

/* ============================================
   POPUP FILTRO PERSONE
   ============================================ */
.people-filter-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    z-index: 9998;
    animation: fadeIn 0.2s;
}

.people-filter-backdrop.active {
    display: block;
}

.people-filter-popup {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.4);
    z-index: 9999;
    max-width: 90vw;
    width: 400px;
    max-height: 70vh;
    overflow-y: auto;
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.people-filter-popup.active {
    display: block;
}

.person-checkbox {
    display: block;
    padding: 12px;
    margin: 6px 0;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    border: 2px solid transparent;
    user-select: none;
}

.person-checkbox:hover {
    background: #f0f7ff;
    border-color: #2a5298;
}

.person-checkbox input {
    margin-right: 10px;
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.person-checkbox input:checked + span {
    font-weight: 600;
    color: #2a5298;
}

.btn-primary {
    padding: 10px 20px;
    background: #2a5298;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary:hover {
    background: #1e3c72;
    transform: translateY(-2px);
}

.btn-secondary {
    padding: 10px 20px;
    background: #e0e0e0;
    color: #333;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

/* ============================================
   CONTROLLO VISTA GRIGLIA
   ============================================ */
.view-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px 20px;
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(10px);
    margin: 0 20px 10px 20px;
    border-radius: 12px;
}

.view-controls label {
    color: white;
    font-weight: 500;
    font-size: 14px;
}

.grid-size-btn {
    background: rgba(255,255,255,0.15);
    border: 2px solid rgba(255,255,255,0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.3s;
    min-width: 60px;
}

.grid-size-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-2px);
}

.grid-size-btn.active {
    background: #2a5298;
    border-color: #2a5298;
    box-shadow: 0 4px 12px rgba(42, 82, 152, 0.4);
}

/* ============================================
   🆕 BOTTONE SCROLL TO TOP
   ============================================ */
.scroll-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #2a5298, #1e3c72);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-to-top:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    background: linear-gradient(135deg, #1e3c72, #2a5298);
}

.scroll-to-top:active {
    transform: translateY(-2px);
}

/* ============================================
   GALLERIA CON ANIMAZIONI + DIMENSIONI VARIABILI
   ============================================ */
#gallery {
    display: grid;
    gap: 20px;
    padding: 20px;
    margin-top: 10px;
    transition: all 0.3s ease;
}

/* Dimensioni griglia */
#gallery.grid-small {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

#gallery.grid-medium {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
}

#gallery.grid-large {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

#gallery.grid-xlarge {
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 24px;
}

.photo-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    animation: fadeInUp 0.4s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Bordo colorato al hover */
.photo-card::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, #2a5298, #1e3c72);
    border-radius: 18px;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: -1;
}

.photo-card:hover::before {
    opacity: 1;
}

.photo-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.25);
}

.photo-thumb {
    width: 100%;
    object-fit: cover;
    display: block;
    transition: height 0.3s ease;
}

/* Altezze immagini in base alla griglia */
#gallery.grid-small .photo-thumb {
    height: 140px;
}

#gallery.grid-medium .photo-thumb {
    height: 180px;
}

#gallery.grid-large .photo-thumb {
    height: 220px;
}

#gallery.grid-xlarge .photo-thumb {
    height: 280px;
}

.people-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(135deg, rgba(42, 82, 152, 0.95), rgba(30, 60, 114, 0.95));
    backdrop-filter: blur(10px);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    max-width: calc(100% - 20px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.photo-info {
    padding: 14px;
}

.photo-filename {
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.photo-meta {
    font-size: 13px;
    color: #666;
}

/* ============================================
   LIGHTBOX MIGLIORATO
   ============================================ */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.3s;
}

.lightbox.hidden {
    display: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lb-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90vw;
    max-height: 90vh;
}

.lb-image {
    max-width: 85vw;
    max-height: 75vh;
    border-radius: 12px;
    box-shadow: 0 0 40px rgba(255,255,255,0.2);
    transition: transform 0.2s ease-out;
    cursor: zoom-in;
    user-select: none;
}

.lb-image[style*="scale"] {
    cursor: zoom-out;
}

.lb-info {
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    padding: 16px 24px;
    border-radius: 12px;
    margin-top: 20px;
    color: #333;
    font-size: 14px;
    line-height: 1.6;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.lb-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 50px;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    z-index: 10000;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

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

.lb-nav {
    position: absolute;
    top: 50%;
    padding: 16px 20px;
    font-size: 40px;
    color: white;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    user-select: none;
    transform: translateY(-50%);
    transition: all 0.3s;
    z-index: 10000;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lb-prev {
    left: 30px;
}

.lb-next {
    right: 30px;
}

.lb-nav:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-50%) scale(1.1);
}

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

.lb-hints {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(10px);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    opacity: 0.8;
}

/* ============================================
   SCROLLBAR PERSONALIZZATA
   ============================================ */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 5px;
}

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

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    h1 {
        font-size: 1.8rem;
    }
    
    .stats-bar {
        flex-direction: column;
        gap: 8px;
    }
    
    .stats {
        font-size: 0.85rem;
        padding: 6px 12px;
    }
    
    .filters-icon-toggle {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .filters-container {
        top: 140px;
    }
    
    .filters-content {
        padding: 10px 15px;
    }
    
    #filters {
        padding: 15px;
        gap: 8px;
    }
    
    #filters select,
    #filters input {
        width: 100%;
        font-size: 14px;
        padding: 10px 14px;
    }
    
    .btn-reset,
    .btn-filter {
        width: 100%;
        padding: 10px 16px;
    }
    
    .view-controls {
        flex-wrap: wrap;
        margin: 0 15px 10px 15px;
    }
    
    .grid-size-btn {
        flex: 1;
        min-width: 70px;
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* Scroll to top su mobile */
    .scroll-to-top {
        bottom: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
        font-size: 24px;
    }
    
    /* Forza dimensioni minori su mobile */
    #gallery.grid-small {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 10px;
    }
    
    #gallery.grid-medium {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }
    
    #gallery.grid-large {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 14px;
    }
    
    #gallery.grid-xlarge {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 16px;
    }
    
    #gallery.grid-small .photo-thumb {
        height: 120px;
    }
    
    #gallery.grid-medium .photo-thumb {
        height: 140px;
    }
    
    #gallery.grid-large .photo-thumb {
        height: 160px;
    }
    
    #gallery.grid-xlarge .photo-thumb {
        height: 200px;
    }
    
    .lb-nav {
        width: 50px;
        height: 50px;
        font-size: 30px;
    }
    
    .lb-prev {
        left: 10px;
    }
    
    .lb-next {
        right: 10px;
    }
    
    .lb-close {
        top: 10px;
        right: 10px;
        font-size: 40px;
        width: 45px;
        height: 45px;
    }
    
    .lb-hints {
        display: none;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.5rem;
    }
    
    .stats {
        font-size: 0.8rem;
        padding: 5px 10px;
    }
    
    .view-controls {
        padding: 8px 12px;
    }
    
    .view-controls label {
        font-size: 12px;
        width: 100%;
        text-align: center;
        margin-bottom: 5px;
    }
    
    /* Scroll to top più piccolo su mobile tiny */
    .scroll-to-top {
        bottom: 15px;
        right: 15px;
        width: 44px;
        height: 44px;
        font-size: 22px;
    }
    
    /* Mobile: sempre 2 colonne, varia solo altezza */
    #gallery {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
        padding: 10px;
    }
    
    #gallery.grid-small .photo-thumb {
        height: 100px;
    }
    
    #gallery.grid-medium .photo-thumb {
        height: 120px;
    }
    
    #gallery.grid-large .photo-thumb {
        height: 140px;
    }
    
    #gallery.grid-xlarge .photo-thumb {
        height: 160px;
    }
}
