/**
 * Discord Poll Frontend CSS
 * Stili per la visualizzazione frontend dei sondaggi Discord
 */

/* =============================================================================
   Container Principale Sondaggio
   ============================================================================= */

.blitz-poll-container {
    margin: 20px 0px;
    padding: 0;
    overflow: hidden;
}

/* =============================================================================
   Meta Informazioni Sondaggio
   ============================================================================= */

.poll-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 15px 20px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 8px;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 20px 20px 20px;
}

.poll-status {
    font-weight: 600;
    font-size: 0.9em;
    padding: 4px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.poll-status.active {
    color: #28a745;
    background: rgba(40, 167, 69, 0.1);
    border: 1px solid rgba(40, 167, 69, 0.3);
}

.poll-status.expired {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.3);
}

.poll-expiration {
    color: #6c757d;
    font-size: 0.85em;
    font-weight: 500;
}

.total-votes {
    color: #495057;
    font-weight: 600;
}

.total-votes strong {
    color: #2c3e50;
    font-size: 1.1em;
}

/* =============================================================================
   Layout Stili
   ============================================================================= */

.poll-cards.poll-style-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
    padding: 0 20px;
}

.poll-cards.poll-style-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 0 20px;
}

.poll-cards.poll-style-compact {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 20px;
}

.poll-cards.poll-style-compact .poll-card-item {
    padding: 10px 15px;
}

/* =============================================================================
   Carte del Sondaggio
   ============================================================================= */

.poll-card-item {
    border: 2px solid #e9ecef;
    border-radius: 12px;
    padding: 20px;
    background: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.poll-card-item:hover {
    border-color: #007cba;
    box-shadow: 0 8px 25px rgba(0, 124, 186, 0.15);
    transform: translateY(-2px);
}

.poll-card-item.winner {
    border-color: #ffd700;
    background: linear-gradient(135deg, #fff9c4 0%, #ffffff 100%);
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.3);
}

.poll-card-item.winner::before {
    content: "👑";
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 20px;
    animation: pulse 2s infinite;
}

/* Animazione CSS pura per le carte */
.poll-card-item {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s ease forwards;
}

.poll-card-item:nth-child(1) { animation-delay: 0.1s; }
.poll-card-item:nth-child(2) { animation-delay: 0.2s; }
.poll-card-item:nth-child(3) { animation-delay: 0.3s; }
.poll-card-item:nth-child(4) { animation-delay: 0.4s; }
.poll-card-item:nth-child(5) { animation-delay: 0.5s; }
.poll-card-item:nth-child(6) { animation-delay: 0.6s; }

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

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* =============================================================================
   Contenuto Carte
   ============================================================================= */

.card-info {
    margin-bottom: 15px;
}

.card-name {
    font-weight: 700;
    font-size: 1.2em;
    color: #2c3e50;
    margin-bottom: 8px;
    line-height: 1.3;
    word-break: break-word;
}

.card-details {
    color: #6c757d;
    font-size: 0.9em;
    line-height: 1.4;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-details .stars {
    color: #ffc107;
    font-size: 1.1em;
}

.card-details .golden {
    font-size: 1.2em;
}

/* =============================================================================
   Informazioni Voti
   ============================================================================= */

.vote-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    margin-bottom: 10px;
}

.vote-count {
    font-weight: 700;
    font-size: 1.1em;
    color: #495057;
}

.vote-percentage {
    background: linear-gradient(135deg, #007cba, #0056b3);
    color: white;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.8em;
    font-weight: 600;
    min-width: 45px;
    text-align: center;
}

.poll-card-item.winner .vote-percentage {
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    color: #2c3e50;
}

/* =============================================================================
   Barra di Progresso
   ============================================================================= */

.vote-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef !important; /* Forza background */
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    margin-top: 8px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1); /* Aggiunge profondità */
}

.vote-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #007cba, #0056b3) !important;
    transition: width 1.5s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 4px;
    position: relative;
    min-width: 0; /* Importante per partire da 0 */
    width: 0%; /* Stato iniziale */
}

/* Assicura che la barra sia visibile anche con percentuali molto basse */
.vote-bar-fill[style*="width: 0"] {
    min-width: 0 !important;
}

.vote-bar-fill[style*="width: 1px"],
.vote-bar-fill[style*="width: 0."] {
    min-width: 2px !important; /* Minimo visibile per percentuali bassissime */
}


/* Effetto shine animato */
.vote-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shine 3s infinite;
    pointer-events: none;
}

@keyframes shine {
    0% { 
        transform: translateX(-100%); 
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% { 
        transform: translateX(100%); 
        opacity: 0;
    }
}

/* Carta vincitore - barra dorata */
.poll-card-item.winner .vote-bar-fill {
    background: linear-gradient(90deg, #ffd700, #ffed4e) !important;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
}

/* Stati responsive */
@media (max-width: 768px) {
    .vote-bar {
        height: 6px;
        margin-top: 6px;
    }
}

/* =============================================================================
   LOADING STATE - Migliora visualizzazione durante caricamento
   ============================================================================= */

.poll-card-item.loading .vote-bar-fill {
    background: #ccc !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* =============================================================================
   FORCE VISIBILITY - In caso di problemi persistenti
   ============================================================================= */

/* Usa questa classe per debug: aggiungi 'force-visible' alla vote-bar */
.vote-bar.force-visible {
    border: 1px solid #007cba;
    background: #f0f0f0 !important;
}

.vote-bar.force-visible .vote-bar-fill {
    background: #007cba !important;
    opacity: 1 !important;
    display: block !important;
    visibility: visible !important;
}


/* Nasconde il test pattern dopo 3 secondi */
.blitz-poll-container.css-loaded::before {
    display: none;
}

/* Badge vincitore */
.winner-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    color: #2c3e50;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 11px;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
    z-index: 10;
    animation: winnerPulse 2s infinite;
}

@keyframes winnerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Info vincitori nella meta */
.winners-info {
    background: rgba(255, 215, 0, 0.1);
    color: #b8860b;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.85em;
    font-weight: 600;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

/* Migliora l'animazione per vincitori multipli */
.poll-card-item.winner {
    border-color: #ffd700;
    background: linear-gradient(135deg, #fff9c4 0%, #ffffff 100%);
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.3);
    position: relative;
}

/* Rimuovi la corona dal ::before se c'è il badge */
.poll-card-item.winner::before {
    display: none;
}

/* Responsive per mobile */
@media (max-width: 768px) {
    .winner-badge {
        top: -6px;
        right: -6px;
        padding: 3px 8px;
        font-size: 10px;
    }
    
    .winners-info {
        font-size: 0.8em;
        padding: 3px 8px;
    }
}

/* =============================================================================
   Footer Sondaggio
   ============================================================================= */

.poll-footer {
    text-align: center;
    /* margin-top: 30px; */
    padding: 20px;
    /* border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    color: #6c757d; */
    font-size: 0.85em;
}

.poll-footer small {
    font-style: italic;
}

/* =============================================================================
   Pulsante Refresh
   ============================================================================= */

.poll-refresh-btn {
    background: linear-gradient(135deg, #007cba, #0056b3);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    margin-left: 10px;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.poll-refresh-btn:hover {
    background: linear-gradient(135deg, #005a87, #004494);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 124, 186, 0.3);
}

.poll-refresh-btn:active {
    transform: translateY(0);
}

.poll-refresh-btn .refresh-icon {
    display: inline-block;
    transition: transform 0.5s ease;
    font-size: 14px;
}

.poll-refresh-btn:hover .refresh-icon {
    transform: rotate(180deg);
}

/* =============================================================================
   Animazioni e Effetti
   ============================================================================= */

.poll-card-item.updated {
    animation: cardUpdate 2s ease;
}

@keyframes cardUpdate {
    0%, 100% { 
        transform: scale(1); 
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    50% { 
        transform: scale(1.02); 
        box-shadow: 0 12px 30px rgba(0,124,186,0.3);
        border-color: #007cba;
    }
}

.poll-card-item.hovered {
    transform: translateY(-2px);
}

/* =============================================================================
   Overlay di Caricamento
   ============================================================================= */

.poll-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 12px;
    backdrop-filter: blur(2px);
}

.poll-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e9ecef;
    border-top: 3px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.poll-loading-overlay span {
    color: #495057;
    font-weight: 500;
    font-size: 0.9em;
}

/* =============================================================================
   Notifiche
   ============================================================================= */

.poll-notification {
    position: absolute;
    top: 15px;
    right: 15px;
    padding: 8px 15px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    z-index: 1001;
    animation: slideInRight 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.poll-notification-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.poll-notification-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

@keyframes slideInRight {
    from { 
        transform: translateX(100%); 
        opacity: 0; 
    }
    to { 
        transform: translateX(0); 
        opacity: 1; 
    }
}

/* =============================================================================
   Carta Singola (Shortcode poll_card)
   ============================================================================= */

.poll-single-card {
    display: inline-block;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 5px;
    background: white;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.poll-single-card:hover {
    border-color: #007cba;
    box-shadow: 0 4px 12px rgba(0,124,186,0.15);
    transform: translateY(-1px);
}

.poll-single-card .card-name {
    font-weight: 700;
    color: #2c3e50;
    font-size: 1em;
    margin-bottom: 4px;
}

.poll-single-card .card-meta {
    color: #6c757d;
    font-size: 0.85em;
    line-height: 1.4;
}

.poll-single-card .card-votes {
    color: #007cba;
    font-weight: 700;
    margin-top: 6px;
    font-size: 0.9em;
}

/* =============================================================================
   Responsive Design
   ============================================================================= */

@media (max-width: 768px) {
    .blitz-poll-container {
        margin: 15px 0px;
    }
    
    .poll-meta {
        flex-direction: column;
        text-align: center;
        margin: 0 15px 15px 15px;
        padding: 12px;
        gap: 8px;
    }
    
    .poll-cards.poll-style-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 0 15px;
    }
    
    .poll-cards.poll-style-list,
    .poll-cards.poll-style-compact {
        padding: 0 15px;
        gap: 12px;
    }
    
    .poll-card-item {
        padding: 15px;
    }
    
    .card-name {
        font-size: 1.1em;
    }
    
    .vote-info {
        margin-top: 12px;
        margin-bottom: 8px;
    }
    
    .poll-footer {
        padding: 15px;
        margin-top: 20px;
    }
    
    .poll-refresh-btn {
        font-size: 11px;
        padding: 5px 10px;
        margin-left: 8px;
    }
    
    .poll-single-card {
        margin: 3px;
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .blitz-poll-container {
        margin: 10px 0px;
    }
        
    .poll-card-item {
        padding: 12px;
    }
    
    .card-name {
        font-size: 1em;
    }
    
    .vote-percentage {
        padding: 3px 8px;
        font-size: 0.75em;
    }
    
    .vote-bar {
        height: 6px;
    }
}

/* =============================================================================
   Dark Mode Support
   ============================================================================= */

@media (prefers-color-scheme: dark) {
    .blitz-poll-container {
        background: #2d3748;
        color: #e2e8f0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    
    .poll-meta {
        background: linear-gradient(135deg, #4a5568, #2d3748);
    }
    
    .poll-card-item {
        background: #4a5568;
        border-color: #718096;
        color: #e2e8f0;
    }
    
    .poll-card-item:hover {
        border-color: #63b3ed;
        box-shadow: 0 8px 25px rgba(99, 179, 237, 0.15);
    }
    
    .card-name {
        color: #f7fafc;
    }
    
    .card-details {
        color: #a0aec0;
    }
    
    .vote-count {
        color: #e2e8f0;
    }
    
    .vote-bar {
        background: #2d3748;
    }
    
    .poll-footer {
        background: #2d3748;
        border-top-color: #4a5568;
        color: #a0aec0;
    }
    
    .poll-single-card {
        background: #4a5568;
        border-color: #718096;
        color: #e2e8f0;
    }
    
    .poll-single-card .card-name {
        color: #f7fafc;
    }
}

/* =============================================================================
   High Contrast Mode
   ============================================================================= */

@media (prefers-contrast: high) {
    .poll-card-item {
        border-width: 3px;
    }
    
    .poll-card-item:hover {
        border-width: 4px;
    }
    
    .vote-bar {
        height: 10px;
    }
    
    .vote-percentage {
        border: 2px solid;
    }
}

/* =============================================================================
   Reduced Motion
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
    .poll-card-item,
    .poll-refresh-btn,
    .vote-bar-fill {
        transition: none;
    }
    
    .poll-notification {
        animation: none;
    }
    
    .poll-spinner {
        animation: none;
        border-top-color: transparent;
    }
    
    .vote-bar-fill::after {
        animation: none;
    }
    
    .poll-card-item.winner::before {
        animation: none;
    }
}

/* =============================================================================
   Print Styles
   ============================================================================= */

@media print {
    .blitz-poll-container {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .poll-refresh-btn,
    .poll-loading-overlay,
    .poll-notification {
        display: none;
    }
    
    .poll-card-item {
        break-inside: avoid;
        border: 1px solid #000;
        box-shadow: none;
    }
    
    .poll-card-item:hover {
        transform: none;
        box-shadow: none;
    }
    
    .vote-bar-fill::after {
        display: none;
    }
}