body { margin: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; overflow: hidden; }
#map { height: 100vh; width: 100%; background: #aad3df; }

#loader { position: fixed; top: 0; left: 0; width: 100%; height: 4px; background: #eee; z-index: 9999; display: block; }
#loader-progress { width: 0%; height: 100%; background: #007bff; transition: width 0.3s; }

#ui-panel {
    position: absolute; top: 15px; left: 15px; z-index: 1000;
    background: rgba(255, 255, 255, 0.95); padding: 18px; border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15); width: 260px;
    max-height: 85vh; overflow-y: auto; border: 1px solid rgba(255,255,255,0.3);
    transition: transform 0.3s ease;
}
#ui-panel.collapsed { transform: translateX(-310px); }

#ranking-sidebar {
    position: absolute; top: 15px; right: 15px; z-index: 1001;
    background: rgba(255, 255, 255, 0.95); padding: 15px; border-radius: 15px;
    box-shadow: -5px 0 20px rgba(0,0,0,0.1); width: 280px;
    max-height: 85vh; overflow-y: auto; display: none;
    border: 1px solid rgba(0,0,0,0.05);
}
.ranking-item {
    display: flex; align-items: center; gap: 10px; padding: 8px;
    border-bottom: 1px solid #eee; cursor: pointer; transition: background 0.2s;
    font-size: 13px;
}
.ranking-item:hover { background: #f0f7ff; }
.rank-pos { font-weight: bold; color: #007bff; min-width: 20px; }
.rank-val { margin-left: auto; font-size: 11px; font-weight: bold; color: #666; }

.color-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.color-circle { 
    width: 22px; height: 22px; border-radius: 50%; border: 2px solid white; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.2); cursor: pointer; transition: transform 0.2s;
}
.color-circle:hover { transform: scale(1.2); }
.color-circle.active { border-color: #007bff; transform: scale(1.2); box-shadow: 0 0 8px rgba(0,123,255,0.5); }

#toggle-panel-btn {
    position: absolute; top: 15px; left: 15px; z-index: 1001;
    background: white; border: none; border-radius: 8px; width: 40px; height: 40px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2); cursor: pointer; display: none;
    justify-content: center; align-items: center; font-size: 20px;
}
.close-panel { float: right; cursor: pointer; font-size: 20px; color: #999; }

#search-container { margin-bottom: 0; display: flex; flex-direction: column; gap: 5px; }
.search-row { display: flex; gap: 5px; }
#search-input { flex-grow: 1; padding: 10px; border-radius: 8px; border: 1px solid #ddd; outline: none; font-size: 14px; font-family: inherit; }

#search-history { display: flex; gap: 5px; margin-top: 5px; overflow-x: auto; padding-bottom: 5px; }
.history-item { 
    flex: 0 0 35px; height: 35px; border-radius: 50%; background: white; 
    border: 1px solid #ddd; cursor: pointer; display: flex; align-items: center; 
    justify-content: center; transition: transform 0.2s;
}
.history-item:hover { transform: scale(1.1); border-color: #007bff; }
.history-item img { width: 70%; height: 70%; object-fit: contain; }

.btn-ui { background: #f0f0f0; border: 1px solid #ddd; border-radius: 8px; padding: 10px; cursor: pointer; font-size: 12px; font-weight: bold; font-family: inherit; margin-top: 0; margin-bottom: 5px; width: 100%;}
.btn-reset { background: #fee; color: #c33; border-color: #fcc; }
.btn-explore { background: #e7f3ff; color: #007bff; border-color: #b3d7ff; }

.custom-div-icon { background: none; border: none; }

.logo-container {
    border-radius: 50%; padding: 3px; display: flex; justify-content: center; align-items: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    box-shadow: 0 0 0 2px white, 0 3px 8px rgba(0,0,0,0.4); 
    width: 44px; height: 44px; position: relative;
}

.highlight-active {
    animation: pulse-gold 2s infinite;
    box-shadow: 0 0 0 4px #ffd700, 0 0 15px #ffd700 !important;
}
@keyframes pulse-gold {
    0% { transform: scale(1); box-shadow: 0 0 0 0px rgba(255, 215, 0, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255, 215, 0, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0px rgba(255, 215, 0, 0); }
}

.logo-container:hover { transform: scale(1.4); z-index: 9999 !important; }
.logo-container:active { transform: scale(0.9); }
.logo-img-inner { width: 100%; height: 100%; border-radius: 50%; background: white; object-fit: contain; }

/* Il contenitore che avvolge il logo (assicurati che il logo sia centrato qui) */
.logo-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* I badge sono visibili, ma ottimizzati per la GPU */
.badge-icon {
    display: flex !important;
    will-change: transform; /* Aiuta la fluidità su mobile */
}

/* Se l'utente preme l'interruttore "Nascondi Badge", allora spariscono */
#map.hide-badges .badge-icon {
    display: none !important;
}

/* Ottimizzazione Loghi per mobile */
.logo-container {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Rimuovi ombre pesanti se la mappa è ancora lenta su mobile */
@media (max-width: 768px) {
    .logo-container {
        box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
    }
}

/* Stile base del badge (il tuo stile originale) */
.badge-icon {
    position: absolute; 
    width: 16px; 
    height: 16px; 
    color: white; 
    border-radius: 50%; 
    border: 2px solid white;
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 9px; 
    font-weight: bold; 
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    
    /* Logica di posizionamento circolare */
    --radius: 24px; /* Distanza dal centro del logo */
    transform: translate(
        calc(cos(var(--angle)) * var(--radius)),
        calc(sin(var(--angle)) * var(--radius))
    );
}

/* Tutti i Badge (Sullo stesso piano) */
.badge-femminile { background: #ff69b4 !important; }
.badge-riserva   { background: #6C757D !important; color: #ffffff !important; }
.badge-pioniere  { background: #5bc0de !important; }
.badge-newentry  { background: #f0ad4e !important; }
.badge-memoria   { background: #333333 !important; }
.badge-gloria    { background: #0047AB !important; }
.badge-secolare  { background: #704214 !important; }
.badge-cattedrale { background: #800020 !important; }
.badge-elite     { background: #ffd700 !important; color: #000 !important; }
.badge-isola { background-color: #00bcd4 !important; }
.badge-porto { background-color: #0277bd !important; }
.badge-enclave { background-color: #e91e63 !important; }
.badge-globetrotter { background-color: #4caf50 !important; }
.badge-vetta     { background: #f0f8ff !important; color: #000 !important; border: 1px solid #ccc; }
.badge-nord { background: #E0F7FA !important; color: #006064 !important; border: 1px solid #006064; }
.badge-sud { background: #1A237E !important; color: white !important; }
.badge-est { background: #FFD54F !important; color: #827717 !important; }
.badge-ovest { background: #BF360C !important; color: white !important; }

@keyframes shimmer {
    0% { box-shadow: 0 0 2px #ffd700; }
    50% { box-shadow: 0 0 8px #ffd700; }
    100% { box-shadow: 0 0 2px #ffd700; }
}

.cluster-modern {
    background: #007bff; border: 2px solid #ffffff;
    border-radius: 50%; width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    color: #ffffff; font-weight: bold; font-family: inherit;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.custom-popup .leaflet-popup-content-wrapper { 
    border-radius: 12px; padding: 5px; 
    border: 4px solid transparent;
    box-shadow: 0 3px 14px rgba(0,0,0,0.4);
}

.popup-card { text-align: center; font-family: 'Segoe UI', sans-serif; width: 220px; }
.popup-header { border-bottom: 2px solid #eee; margin-bottom: 10px; padding-bottom: 8px; }
.popup-title { margin: 5px 0; color: #222; font-size: 1.1em; text-transform: uppercase; letter-spacing: 1px; }
.popup-nickname { font-style: italic; color: #666; font-size: 13px; margin-bottom: 5px; display: block; }
.popup-info { font-size: 13px; color: #555; line-height: 1.4; }

.btn-update {
    display: block; margin-top: 10px; font-size: 10px; color: #999; 
    text-decoration: none; border-top: 1px dotted #ccc; padding-top: 5px;
}
.btn-update:hover { color: #555; text-decoration: underline; }

.precedenti-box { background: #f5f5f5; border: 1px solid #ddd; margin-top: 8px; padding: 8px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; }
.precedenti-grid { display: flex; justify-content: center; gap: 10px; margin-top: 5px; }
.origin-wrapper { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.origin-logo { 
    width: 35px; height: 35px; object-fit: contain; border-radius: 50%; 
    background: white; border: 1px solid #bbb; padding: 2px;
    transition: transform 0.2s;
}
.origin-logo:hover { transform: scale(1.2); border-color: #007bff; }
.origin-name { font-size: 9px; margin-top: 3px; color: #555; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-link-club {
    display: block; background: #fff; border: 1px solid #ccc; color: #555; 
    font-size: 10px; padding: 4px; border-radius: 4px; cursor: pointer;
}

.anniversario-box, .storici-container { margin: 10px 0; padding: 8px; border-radius: 8px; }
.anniversario-box { background: #fff9c4; border: 1px solid #fbc02d; }
.storici-container { background: #e3f2fd; border: 1px solid #90caf9; }

.box-label { font-size: 9px; font-weight: bold; display: block; margin-bottom: 5px; text-transform: uppercase; color: #555; }
.anniversario-img, .storico-img { width: 45px; height: 45px; object-fit: contain; background: white; border: 1px solid #eee; border-radius: 4px; }
.storico-grid, .anniversario-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.storico-item, .anniversario-item { flex: 0 0 45px; text-align: center; font-size: 9px; color: #444; }

.btn-espandi { background: none; border: none; color: #007bff; font-size: 10px; cursor: pointer; text-decoration: underline; margin-top: 5px; display: block; width: 100%; font-weight: bold; }
.hidden-logos { display: none; }

.stat-item { font-size: 13px; font-weight: bold; margin: 8px 0; color: #444; }
#stats-breakdown { font-size: 11px; color: #666; font-weight: normal; margin-top: 5px; line-height: 1.2; }

/* Contenitore della legenda */
.legend-box {
    margin-top: 25px;       /* Crea spazio dal filtro Epoca sopra */
    background: #ffffff;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #eee;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.02); /* Effetto rientrato */
}

/* Titolo della legenda più piccolo */
.legend-box h4 {
    margin: 0 0 8px 0;
    font-size: 11px;        /* Titolo più discreto */
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #666;
}

/* Singolo elemento della legenda */
.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 5px;     /* Spazio ridotto tra le righe */
    font-size: 11px;        /* Testo più piccolo */
    line-height: 1.2;
}

/* Iconcina della legenda rimpicciolita */
.legend-icon {
    width: 18px;            /* Ridotta da 24px */
    height: 18px;           /* Ridotta da 24px */
    font-size: 10px;        /* Emoji più piccola */
    margin-right: 8px;
    border-radius: 3px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

select { width: 100%; margin-top: 5px; padding: 8px; border-radius: 8px; border: 1px solid #ddd; font-family: inherit; }
hr { border: 0; border-top: 1px solid #eee; margin: 15px 0; }
.flag-icon { width: 22px; border-radius: 3px; vertical-align: middle; margin-right: 6px; border: 1px solid #eee; }
.locate-btn {
    background: white; width: 34px; height: 34px; display: flex;
    justify-content: center; align-items: center; border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4); cursor: pointer; margin-bottom: 10px;
}

.switch { position: relative; display: inline-block; width: 40px; height: 20px; vertical-align: middle; margin-left: 10px; }
.switch input { opacity: 0; width: 0; height: 0; }
.filter-row-reserves { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; font-size: 13px; font-weight: bold; color: #444; border-top: 1px solid #eee; margin-top: 10px; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: #007bff; }
input:checked + .slider:before { transform: translateX(20px); }

#timeline-container {
    position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
    z-index: 1000; background: rgba(255,255,255,0.9); padding: 10px 20px;
    border-radius: 50px; box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex; align-items: center; gap: 15px; width: 80%; max-width: 600px;
    transition: all 0.2s;
}
#timeline-slider { flex-grow: 1; cursor: pointer; }
#year-display { font-weight: bold; color: #007bff; min-width: 90px; text-align: center; transition: transform 0.1s; }
.year-active { transform: scale(1.2); color: #ff6b6b !important; }

.notification-toast {
    position: fixed; top: 20px; right: 20px; z-index: 10000;
    background: #333; color: white; padding: 12px 20px; border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3); display: none; animation: slideIn 0.5s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.btn-wiki {
    display: inline-block; margin: 8px 0; padding: 6px 14px;
    background: #ffffff; color: #3366cc; text-decoration: none;
    border: 2px solid #3366cc; border-radius: 20px; font-size: 11px; 
    font-weight: bold; transition: all 0.2s;
}
.btn-wiki:hover { background: #3366cc; color: #ffffff; }
#map.hide-badges .badge-icon { display: none !important; }

/* --- CSS SINCRONIZZATO CON I NOMI IN ITALIANO --- */
.popup-colors {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin: 8px 0;
}

.color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
    display: inline-block;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Mapping diretto sui nomi che scrivi nel Foglio */
.color-rosso        { background-color: #FF0000; }
.color-amaranto     { background-color: #9F2B68; }
.color-granata      { background-color: #800000; }
.color-bordeaux     { background-color: #6D1A22; }
.color-arancione    { background-color: #F75E25; }
.color-oro          { background-color: #DAA520; }
.color-ambra        { background-color: #FFBF00; }
.color-giallo       { background-color: #FFFF00; }
.color-crema        { background-color: #FFFDD0; }
.color-verde-chiaro { background-color: #00FF00; }
.color-verde        { background-color: #008000; }
.color-verde-scuro  { background-color: #004d00; }
.color-celeste      { background-color: #87CEEB; }
.color-azzurro      { background-color: #007FFF; }
.color-blu          { background-color: #0000FF; }
.color-blu-navy     { background-color: #000080; }
.color-viola        { background-color: #8F00FF; }
.color-fucsia       { background-color: #D9027D; }
.color-rosa         { background-color: #FF69B4; }
.color-lilla        { background-color: #C8A2C8; }
.color-marrone      { background-color: #654321; }
.color-bianco       { background-color: #FFFFFF; }
.color-grigio       { background-color: #808080; }
.color-nero         { background-color: #000000; }

/* Nasconde i marker filtrati (es. Squadre Riserva) */
.marker-hidden {
    display: none !important;
}

/* Colori Badge Speciali */
.badge-isola { background: #00bcd4 !important; }
.badge-globetrotter { background: #4caf50 !important; }
.badge-enclave { background: #e91e63 !important; }
.badge-porto { background: #0277bd !important; }

/* Uniformità Totale: Tutti i badge con lo stesso bordo e ombra */
.badge-icon, .legend-icon {
    width: 18px !important;
    height: 18px !important;
    border: 2px solid #ffffff !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px !important;
    border-radius: 50%;
    box-sizing: border-box !important;
    color: white !important;
}

/* Stile per la lista nel pannello laterale */
.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 12px;
    color: #333;
}

/* --- NUOVA LEGENDA MODERNA --- */

.legend-container-wrapper {
    margin-top: 20px;
    border-top: 1px solid #eee;
    padding-top: 15px;
}

/* Bottone moderno con stile coerente al resto della UI */
.legend-toggle-btn {
    width: 100%;
    background: #f8f9fa;
    border: 1px solid #ddd;
    padding: 12px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: bold;
    color: #444;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.legend-toggle-btn:hover {
    background: #f0f7ff;
    border-color: #007bff;
}

/* Contenitore a tendina */
.legend-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
}

.legend-content.open {
    max-height: 2000px; /* Valore alto per permettere l'espansione */
    margin-top: 10px;
    padding-bottom: 10px;
}

/* Griglia per i badge */
#legenda-badge-dinamici {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Singolo Item della legenda */
.legend-item-modern {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 5px;
    transition: background 0.2s;
}

/* Badge grande come sulla mappa (44px) */
.legend-badge-large {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px !important; /* Icona più visibile */
    border: 3px solid white !important;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15) !important;
    color: white !important;
}

/* Testi della legenda */
.legend-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.legend-label {
    font-size: 14px;
    font-weight: bold;
    color: #222;
    margin-bottom: 2px;
}

.legend-desc {
    font-size: 11px;
    color: #777;
    line-height: 1.3;
}

/* Animazione freccia */
#legend-chevron {
    transition: transform 0.3s ease;
}
.open #legend-chevron {
    transform: rotate(180deg);
}
