/* Badge System Styles - ANTI-GLITCHING VERSION */

.artist-badges {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    flex-wrap: nowrap; /* Previene wrapping */
    min-height: 20px; /* Previene layout shift */
    opacity: 1;
    transition: opacity 0.3s ease;
    will-change: opacity; /* Ottimizza per animazioni */
}

.artist-badges-container {
    min-height: 20px; /* Dimensione fissa per prevenire shift */
    display: flex;
    align-items: center;
    flex-shrink: 0; /* Non comprimere mai */
    contain: layout style; /* Ottimizzazione CSS containment */
    width: auto;
}

.badge-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: all 0.3s ease;
    cursor: pointer;
    will-change: transform; /* Ottimizza per hover */
    contain: layout; /* Previene reflow */
}

.badge-container:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.badge-icon {
    font-size: 14px;
    line-height: 1;
    transition: all 0.3s ease;
    contain: layout; /* Ottimizza rendering */
}

/* Stati di caricamento e errore - STABILI */
.badges-loading {
    display: inline-block;
    font-size: 12px;
    color: #6b7280;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
}

.badge-error {
    display: inline-block;
    font-size: 12px;
    color: #dc2626;
    width: 20px;
    height: 20px;
    text-align: center;
    line-height: 20px;
}

/* Dimensioni badge */
.badge-small .badge-icon {
    font-size: 12px;
}

.badge-medium .badge-icon {
    font-size: 16px;
}

.badge-large .badge-icon {
    font-size: 20px;
}

/* Rarità badge */
.badge-common {
    background: linear-gradient(135deg, #90EE90, #98FB98);
    border-color: #90EE90;
}

.badge-rare {
    background: linear-gradient(135deg, #4A90E2, #5DADE2);
    border-color: #4A90E2;
    box-shadow: 0 0 8px rgba(74, 144, 226, 0.3);
}

.badge-epic {
    background: linear-gradient(135deg, #9B59B6, #BB6BD9);
    border-color: #9B59B6;
    box-shadow: 0 0 12px rgba(155, 89, 182, 0.4);
}

.badge-legendary {
    background: linear-gradient(135deg, #F39C12, #F7DC6F);
    border-color: #F39C12;
    box-shadow: 0 0 15px rgba(243, 156, 18, 0.6);
}

/* Badge text */
.badge-name {
    font-size: 10px;
    font-weight: 600;
    color: #2c3e50;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
    white-space: nowrap;
}

/* Tooltip per badge */
.badge-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 9999;
    margin-bottom: 5px;
    pointer-events: none;
}

.badge-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    z-index: 9999;
}

.badge-container:hover .badge-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Badge count indicator */
.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 4px 6px;
    border-radius: 10px;
    min-width: 20px;
    height: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.3);
    margin-left: 2px;
    line-height: 1;
    text-align: center;
}

.badge-count:hover {
    transform: scale(1.1);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

/* Badge showcase (per pagine dedicate) */
.badge-showcase {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    padding: 16px;
}

.badge-showcase-item {
    text-align: center;
    padding: 16px;
    border-radius: 12px;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.badge-showcase-item:hover {
    transform: translateY(-4px);
}

.badge-showcase-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.badge-showcase-name {
    font-weight: 600;
    margin-bottom: 4px;
    color: #2c3e50;
}

.badge-showcase-desc {
    font-size: 11px;
    color: #7f8c8d;
    line-height: 1.3;
}

/* Responsive */
@media (max-width: 768px) {
    .artist-badges {
        gap: 2px;
    }
    
    .badge-container {
        padding: 1px 4px;
    }
    
    .badge-icon {
        font-size: 12px;
    }
    
    .badge-name {
        font-size: 9px;
    }
    
    .badge-showcase {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
        padding: 12px;
    }
}

/* Animazioni ottimizzate per prevenire glitching */
@keyframes badge-appear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.badge-new {
    animation: badge-appear 0.4s ease forwards;
    animation-fill-mode: forwards;
}

/* Stato caricamento badge */
.badges-loading {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    font-size: 10px;
    color: #666;
}

.badges-loading::before {
    content: '⏳';
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.badges-error {
    color: #dc3545;
    font-size: 14px;
}

/* Modal per tutti i badge */
#allBadgesModal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

#allBadgesModal.active {
    display: flex;
}

#allBadgesModal .modal-content {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.3s ease;
}

#allBadgesModal.active .modal-content {
    transform: scale(1);
    opacity: 1;
}

.badge-showcase-item {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.badge-showcase-item:hover {
    background: #e9ecef;
    transform: translateY(-2px);
    border-color: #dee2e6;
}

/* Responsive modal */
@media (max-width: 768px) {
    #allBadgesModal .modal-content {
        margin: 10px;
        padding: 16px;
    }
    
    #allBadgesContent {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .badge-showcase-item {
        padding: 12px;
    }
}

/* Stili per badge nelle classifiche multiple */
.ranking-card .artist-badges-container {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 0px;
    min-height: 20px; /* Previene layout shift */
    flex-shrink: 0; /* Previene compressione */
}

.ranking-card .artist-badges {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-wrap: nowrap;
    opacity: 1;
    transition: opacity 0.3s ease;
    will-change: opacity;
}

/* Aumenta z-index per tooltip nelle ranking cards */
.ranking-card .badge-tooltip {
    z-index: 99999; /* Più alto del normale per essere sopra le altre ranking-card */
    margin-bottom: 8px; /* Spazio maggiore dalla card */
}

/* Assicura che i badge container nelle ranking cards abbiano posizionamento relativo */
.ranking-card .badge-container {
    position: relative;
}

@keyframes fadeInBadges {
    from { 
        opacity: 0; 
        transform: translateX(-5px); 
    }
    to { 
        opacity: 1; 
        transform: translateX(0); 
    }
}

.ranking-card .badge-container {
    padding: 1px 4px;
    font-size: 12px;
    border-radius: 8px;
    will-change: transform; /* Ottimizza rendering */
}

.ranking-card .badge-icon {
    font-size: 11px;
}

.ranking-card .badge-count {
    font-size: 9px;
    min-width: 16px;
    height: 16px;
    padding: 2px 4px;
}

/* Speciali per Hall of Fame */
.ranking-card[style*="background: linear-gradient"] .badge-container {
    border: 1px solid rgba(218, 165, 32, 0.3);
    /* Mantenere il background del badge-container dalla rarity */
}

.ranking-card[style*="background: linear-gradient"] .badge-count {
    background: linear-gradient(135deg, #daa520 0%, #b8860b 100%);
}