﻿/* ========================================
   STANDINGS MOTOGP STYLE - REGOLARITÀ
   Stili personalizzati per classifica con font più grandi
   ======================================== */

/* ========================================
   RIMUOVI SPAZIO LATERALE - FULL WIDTH
   ======================================== */

/* Override del container Bootstrap per questa pagina */
body .container {
    max-width: 100% !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
}

/* ========================================
   HEADER FISSO - TABELLA UNICA
   ======================================== */

/* Container tabella con scroll - LO SCROLL DEVE ESSERE QUI */
.table-container {
    position: relative !important;
    max-height: 70vh !important;
    overflow-y: auto !important;
    overflow-x: auto !important;
}

/* Rimuovi overflow dal table-responsive che interferisce con sticky */
.table-container .table-responsive {
    overflow: visible !important;
}

/* Tabella con bordi separati per mantenere le linee verticali */
.table-live {
    border-collapse: separate !important;
    border-spacing: 0 !important;
}

/* Header fisso - STICKY SULLE CELLE TH con bordi verticali */
.table-live thead th {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    background-color: #ffffff !important;
    border: 1px solid #dee2e6 !important;
    padding: 12px 8px !important;
}

/* Rimuovi bordi duplicati tra celle adiacenti */
.table-live thead th + th {
    border-left: none !important;
}

/* Aggiungi ombra sotto l'header per evidenziarlo */
.table-live thead {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
}

/* Se ci sono due righe di header, la seconda deve stare sotto la prima */
.table-live thead tr:first-child th {
    top: 0 !important;
    z-index: 101 !important;
    border-bottom: 1px solid #dee2e6 !important;
}

.table-live thead tr:nth-child(2) th {
    top: 0 !important;
    z-index: 100 !important;
    border-top: none !important;
}

/* ========================================
   TABELLE SEPARATE: HEADER FISSO + BODY SCROLLABILE
   (per implementazione futura)
   ======================================== */

.split-table-container {
    position: relative !important;
    margin-bottom: 20px;
}

/* Header tabella - COMPLETAMENTE FISSO */
.table-header-fixed {
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    background-color: #ffffff !important;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15) !important;
    overflow: hidden;
}

.table-live-header {
    width: 100% !important;
    margin-bottom: 0 !important;
    table-layout: fixed !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}

.table-live-header thead th {
    background-color: #ffffff !important;
    border: 1px solid #dee2e6 !important;
    padding: 12px 8px !important;
    font-weight: 600 !important;
    white-space: nowrap !important;
}

.table-live-header thead th + th {
    border-left: none !important;
}

/* Body tabella - SCROLLABILE */
.table-body-scroll {
    max-height: 60vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
}

.table-live-body {
    width: 100% !important;
    margin-bottom: 0 !important;
    table-layout: fixed !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}

/* ========================================
   OVERRIDE COLONNA POSIZIONE
   ======================================== */

/* Colonna Posizione - Font ridotto + BORDO COLORATO A SINISTRA */
.table-live tbody td:first-child,
.table-live-body tbody td:first-child {
    font-size: 2em !important;
    font-weight: 900 !important;
    color: #007bff !important;
    text-align: center !important;
    vertical-align: middle !important;
    padding: 10px 15px !important;
    width: 70px;
    border-left: 8px solid transparent !important; /* Spessore ridotto, JS imposta il colore */
}

/* Colori distintivi per le prime 3 posizioni - USA CLASSI INVECE DI nth-child */
.table-live tbody tr.position-1 td:first-child,
.table-live-body tbody tr.position-1 td:first-child {
    color: #FFD700 !important; /* Oro */
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.table-live tbody tr.position-2 td:first-child,
.table-live-body tbody tr.position-2 td:first-child {
    color: #C0C0C0 !important; /* Argento */
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.table-live tbody tr.position-3 td:first-child,
.table-live-body tbody tr.position-3 td:first-child {
    color: #CD7F32 !important; /* Bronzo */
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

/* Colonna Numero Gara - Font più piccolo e GRIGIO */
.table-live tbody td:nth-child(2),
.table-live-body tbody td:nth-child(2) {
    font-size: 1.5em !important;
    font-weight: 600 !important;
    color: #999 !important;
    text-align: center !important;
    vertical-align: middle !important;
}

/* Colonna Nome Pilota - Font più grande e grassetto */
.table-live tbody td:nth-child(3),
.table-live-body tbody td:nth-child(3) {
    font-size: 1.3em !important;
    font-weight: 600 !important;
    color: #212529 !important;
    vertical-align: middle !important;
}

/* Ultima colonna TOTALE - Evidenziata */
.table-live tbody td:last-child,
.table-live-body tbody td:last-child {
    font-size: 1.4em !important;
    font-weight: 900 !important;
    color: #28a745 !important;
    background-color: #d4edda !important;
    vertical-align: middle !important;
}

/* Altezza righe ridotta con bordo grigio chiaro sotto */
.table-live tbody tr,
.table-live-body tbody tr {
    height: 45px !important;
    border-bottom: 1px solid #e9ecef !important;
    background-color: transparent !important;
}

/* Override esplicito per rimuovere colori alternati */
.table-live tbody tr:nth-child(odd),
.table-live tbody tr:nth-child(even),
.table-live-body tbody tr:nth-child(odd),
.table-live-body tbody tr:nth-child(even) {
    background-color: transparent !important;
}

/* Override per tutte le celle - rimuovi bordi laterali e superiori ECCETTO il border-left della riga */
.table-live tbody td,
.table-live-body tbody td {
    background-color: transparent !important;
    border-top: none !important;
    border-right: none !important;
}

/* Rimuovi border-left dalle celle che NON sono la prima */
.table-live tbody td:not(:first-child),
.table-live-body tbody td:not(:first-child) {
    border-left: none !important;
}

/* Righe cliccabili con effetto hover */
.table-live tbody tr[onclick],
.table-live-body tbody tr[onclick] {
    cursor: pointer !important;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease !important;
}

.table-live tbody tr[onclick]:hover,
.table-live-body tbody tr[onclick]:hover {
    background-color: #fff3cd !important;
    transform: scale(1.01) !important;
    box-shadow: 0 2px 8px rgba(250, 165, 0, 0.4) !important;
}

/* Evidenziazione pilota appena passato */
.table-live tbody tr.pilot-highlight,
.table-live-body tbody tr.pilot-highlight {
    background-color: #fff3cd !important;
    border: 2px solid #ffc107 !important;
    box-shadow: 0 0 15px rgba(255, 193, 7, 0.5) !important;
    animation: pulseHighlight 0.5s ease-in-out !important;
}

@keyframes pulseHighlight {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.01); }
}

/* ========================================
   LEGENDA CLASSI
   ======================================== */

/* Container per filtro + legenda sulla stessa riga */
.filter-and-legend-container {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap; /* Permette di andare a capo su schermi piccoli */
}

/* Filtro categoria - A SINISTRA */
.filter-section {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    flex: 0 0 auto; /* Non si allarga */
    min-width: 280px;
}

.filter-section label {
    font-weight: 700;
    color: #212529;
    font-size: 1rem;
    margin-right: 10px;
    display: inline-block;
}

.filter-section select {
    padding: 8px 15px;
    font-size: 0.95rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background-color: white;
    color: #495057;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 180px;
}

.filter-section select:hover {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.filter-section select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 0.3rem rgba(0, 123, 255, 0.4);
}

/* Legenda classi - A DESTRA */
.class-legend {
    background-color: #f8f9fa;
    padding: 15px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    flex: 1 1 auto; /* Si allarga per riempire lo spazio disponibile */
    min-width: 300px;
}

.class-legend h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #212529;
    margin-bottom: 10px;
    margin-top: 0;
}

.class-legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start; /* Allinea a sinistra invece che al centro */
}

.class-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background-color: white;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.class-legend-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 6px rgba(0,0,0,0.12);
}

.class-legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.class-legend-item span {
    font-size: 0.9rem;
    font-weight: 600;
    color: #495057;
}

/* ========================================
   RESPONSIVE - MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Padding bilanciato su mobile */
    body .container {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Legenda classi responsive */
    .class-legend {
        padding: 12px; /* ✅ Ridotto da 15px a 12px */
        margin-top: 15px; /* ✅ Ridotto da 20px a 15px */
    }
    
    .class-legend h3 {
        font-size: 1em; /* ✅ Ridotto da 1.1em a 1em */
    }
    
    .class-legend-items {
        gap: 8px; /* ✅ Ridotto da 10px a 8px */
    }
    
    .class-legend-item {
        padding: 6px 10px; /* ✅ Ridotto da 8px 12px a 6px 10px */
    }
    
    .class-legend-color {
        width: 20px; /* ✅ Ridotto da 25px a 20px */
        height: 20px; /* ✅ Ridotto da 25px a 20px */
    }
    
    .class-legend-item span {
        font-size: 0.85em; /* ✅ Ridotto da 0.95em a 0.85em */
    }

    /* Mantieni font grandi anche su mobile per le card */
    .pilot-card-header .position {
        font-size: 2.5em !important;
        font-weight: 900 !important;
        color: #007bff !important;
    }
    
    /* Colori podio anche su mobile - USA CLASSI */
    .pilot-card.position-1 .position {
        color: #FFD700 !important;
        text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    }
    
    .pilot-card.position-2 .position {
        color: #C0C0C0 !important;
        text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    }
    
    .pilot-card.position-3 .position {
        color: #CD7F32 !important;
        text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    }
    
    /* Numero gara in grigio anche su mobile */
    .pilot-card-header .pilot-number {
        font-size: 1.3em !important;
        font-weight: 600 !important;
        color: #999 !important;
    }
    
    .pilot-card-header .total-score {
        font-size: 1.6em !important;
        font-weight: 900 !important;
        color: #28a745 !important;
    }
    
    /* Riduci padding righe tabella su mobile */
    .table-live tbody td,
    .table-live_body tbody td {
        padding: 8px 12px !important;
    }
}

/* ✅ AGGIUNGI ALLA FINE DEL FILE - Filtro categoria */
.filter-section {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.filter-section label {
    font-weight: 700;
    color: #212529;
    font-size: 1.1rem;
    margin-right: 15px;
    display: inline-block;
}

.filter-section select {
    padding: 10px 20px;
    font-size: 1rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background-color: white;
    color: #495057;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 200px;
}

.filter-section select:hover {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.filter-section select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 0.3rem rgba(0, 123, 255, 0.4);
}

/* Mobile */
@media screen and (max-width: 768px) {
    .filter-section {
        padding: 15px;
        margin-bottom: 15px;
    }

    .filter-section label {
        display: block;
        margin-bottom: 10px;
        font-size: 1rem;
    }

    .filter-section select {
        width: 100%;
        min-width: unset;
    }
}

/* ✅ VERIFICA CHE CI SIA QUESTO BLOCCO RESPONSIVE (circa riga 630) */
@media screen and (max-width: 992px) {
    .filter-and-legend-container {
        flex-direction: column;
        gap: 15px;
    }
    
    .filter-section,
    .class-legend {
        width: 100%;
        min-width: unset;
    }
    
    .filter-section {
        text-align: center;
        padding: 12px 15px;
    }
    
    .filter-section label {
        display: block;
        margin-bottom: 8px;
        font-size: 0.95rem;
    }
    
    .filter-section select {
        width: 100%;
        font-size: 0.9rem;
    }
    
    /* Legenda più compatta su mobile */
    .class-legend {
        padding: 12px 15px;
    }
    
    .class-legend h3 {
        font-size: 0.9rem;
        margin-bottom: 8px;
    }
    
    .class-legend-items {
        gap: 8px;
        justify-content: center;
    }
    
    .class-legend-item {
        padding: 5px 10px;
        font-size: 0.85rem;
    }
    
    .class-legend-color {
        width: 16px;
        height: 16px;
    }
    
    .class-legend-item span {
        font-size: 0.85rem;
    }
}

/* ✅ AGGIUNGI ANCHE QUESTO PER SCHERMI MOLTO PICCOLI */
@media screen and (max-width: 480px) {
    .class-legend h3 {
        font-size: 0.85rem;
        margin-bottom: 6px;
    }
    
    .class-legend-items {
        gap: 6px;
    }
    
    .class-legend-item {
        padding: 4px 8px;
    }
    
    .class-legend-color {
        width: 14px;
        height: 14px;
    }
    
    .class-legend-item span {
        font-size: 0.8rem;
    }
}

/* ========================================
   FILTRO CLASSI E LEGENDA - COMPATTI
   ======================================== */

.filter-and-legend-container {
    background: #f8f9fa;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    padding: 10px 15px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    flex-wrap: wrap;
}

.filter-section {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0;
    margin: 0;
}

.filter-section label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
    margin: 0;
    white-space: nowrap;
}

#classFilter,
#classFilterMobile {
    padding: 6px 10px;
    font-size: 0.9rem;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: white;
    min-width: 180px;
}

.class-legend {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.class-legend h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
    margin: 0;
    white-space: nowrap;
}

.class-legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.class-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.class-legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* Mobile - Filtro ultra compatto */
.mobile-filter,
.mobile-legend {
    background: #f8f9fa;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 10px;
}

.mobile-filter label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 5px;
    display: block;
}

.mobile-legend h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 8px;
}

.mobile-legend .class-legend-items {
    gap: 6px;
}

.mobile-legend .class-legend-item {
    padding: 3px 8px;
    font-size: 0.8rem;
}

@media (max-width: 768px) {
    .filter-and-legend-container {
        flex-direction: column;
        align-items: stretch;
        padding: 8px;
        gap: 10px;
    }
    
    .filter-section {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
    
    #classFilter {
        width: 100%;
    }
    
    .class-legend {
        flex-direction: column;
        align-items: stretch;
    }
    
    .class-legend h3 {
        margin-bottom: 6px;
    }
}

/* Riduzione margini generali per dare più spazio alla tabella */
.desktop-only {
    padding-top: 0;
}

.table-container {
    margin-top: 0;
}