/* ============================================================
   SDR MONITOR - IWØRQH LOCAL STAZIONE METEO
   MAIN ESTRUTTURA - File Principale
   ============================================================ */

/* --- 1. ICONA RADAR STANDARD (Aerei comuni sulla mappa) --- */
.adsb-radar-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.adsb-radar-dot {
    width: 10px;
    height: 10px;
    background-color: #00ecff; 
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 10px #00ecff;
    z-index: 2;
}

.adsb-radar-pulse {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: rgba(0, 236, 255, 0.6);
    border-radius: 50%;
    z-index: 1;
    animation: adsb-radar-beam 2s infinite ease-out;
}

/* Effetto per i marker sulla mappa quando il segnale è vecchio */
.plane-stale {
    filter: grayscale(1) opacity(0.4) !important;
    transition: all 0.5s ease;
}

/* Ferma l'animazione del radar quando l'aereo è perso */
.plane-stale .adsb-radar-pulse {
    animation: none !important;
    display: none !important;
}

/* Stile per la riga della tabella (già presente, ma per sicurezza) */
.row-stale {
    opacity: 0.5;
    filter: grayscale(0.8);
}

@keyframes adsb-radar-beam {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(4); opacity: 0; }
}

/* --- 2. MAPPA LEAFLET (Struttura) --- */
#map {
    width: 100%;
    height: 550px !important;
    background: #1a1a1a;
    z-index: 1;
}

.map-card {
    padding: 0 !important;
    overflow: hidden;
    min-height: 550px;
    border: 1px solid var(--border);
}

/* Popup stile tecnico */
.leaflet-popup-content-wrapper {
    background: #1a1a1a !important;
    color: #00ecff !important;
    border: 1px solid #333;
    font-family: 'Courier New', Courier, monospace;
}

.leaflet-popup-tip {
    background: #1a1a1a !important;
}

/* Nota: Lo zoom è gestito in adsb-special.css per il posizionamento in basso */

/* --- 3. STATISTICHE E CARD --- */
.dx-val {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-main);
}

.dx-call {
    font-weight: 600;
    color: var(--accent);
}

.card-footer {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    font-size: 0.8rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 800;
    background: var(--border);
    color: var(--text-dim);
    margin-bottom: 15px;
    letter-spacing: 1px;
}

/* --- 4. TABELLA TRAFFICO --- */
.gap-section { 
    overflow-x: auto; 
    background: transparent;
}

.gap-table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 10px; 
    table-layout: auto;
}

.gap-table th {
    text-align: left;
    padding: 12px 8px;
    border-bottom: 2px solid #333;
    color: var(--text-dim);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.gap-table td {
    padding: 12px 8px;
    border-bottom: 1px solid #222;
    color: var(--text-main);
    font-size: 0.9rem;
    vertical-align: middle;
}

/* Evidenziazione Target Speciali (Gestite via JS adsb-handler.js) */
.row-nibbio {
    background: rgba(239, 68, 68, 0.12) !important; /* Sfondo rosso per il Nibbio */
}

.row-aeroclub {
    background: rgba(52, 152, 219, 0.12) !important; /* Sfondo blu per l'AeroClub */
}

.row-stale {
    opacity: 0.5; /* Aerei con segnale non aggiornato */
    filter: grayscale(0.8);
}

/* Effetto Hover */
.gap-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Responsive: Nasconde colonne extra su mobile per mantenere la struttura */
@media (max-width: 768px) {
    .gap-table th:nth-child(2), .gap-table td:nth-child(2), /* ICAO */
    .gap-table th:nth-child(6), .gap-table td:nth-child(6), /* Segnale */
    .gap-table th:nth-child(7), .gap-table td:nth-child(7)  /* Ultimo Segnale */ {
        display: none;
    }
}

/* --- 5. UNITÀ E INDICATORI --- */
.badge {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    display: inline-block;
}

.rssi-strong { color: #00ff00 !important; font-weight: bold; }
.rssi-medium { color: #ffff00 !important; font-weight: bold; }
.rssi-weak   { color: #ff8000 !important; font-weight: bold; }
.rssi-very-weak { color: #ff0000 !important; font-weight: bold; }

.unit-alt, .unit-speed {
    font-size: 0.8rem;
    color: #888;
    margin-left: 4px;
}

.status-online { 
    background: rgba(16, 185, 129, 0.2) !important; 
    color: #00ecff !important; 
    border: 1px solid rgba(16, 185, 129, 0.4) !important; 
}

.status-offline { 
    background: rgba(148, 163, 184, 0.1) !important; 
    color: #94a3b8 !important; 
    border: 1px solid rgba(148, 163, 184, 0.2) !important; 
}

/* --- 6. NUOVO LAYOUT BILANCIATO --- */
.grid-stats-top {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Due colonne uguali sopra */
    gap: 20px;
    margin-bottom: 20px;
}

.grid-stats-bottom {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.canvas-container {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.polar-height { height: 350px !important; }
.timeline-height { height: 250px !important; }

/* --- 7. REGISTRO STORICO EMERGENZE PERMANENTE --- */
.emergency-section {
    background: rgba(20, 20, 20, 0.4);
    border: 1px solid rgba(231, 76, 60, 0.2);
    border-radius: 12px;
    padding: 25px;
    margin-top: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.emergency-section .section-header h3 {
    color: #e74c3c;
    font-size: 1.4rem;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.emergency-section .section-header p {
    color: #777;
    font-size: 0.9rem;
    margin-bottom: 20px;
}

/* Contenitore per impedire lo sbordamento su mobile */
.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.emergency-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px; /* Garantisce una larghezza minima per non comprimere i dati */
}

.emergency-table th {
    background: rgba(255, 255, 255, 0.03);
    color: #666;
    padding: 15px 12px;
    text-align: left;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid #333;
}

.emergency-table td {
    padding: 18px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #ddd;
    font-size: 0.9rem;
    vertical-align: middle;
}

/* Colonna Tempo con accento visivo */
.time-cell-main {
    border-left: 4px solid #e74c3c;
    padding-left: 15px !important;
}

.time-cell-main span {
    color: #fff;
    font-weight: bold;
    display: block;
}

.time-cell-main small {
    color: #666;
}

/* Badge Squawk Stile Aeronautico */
.squawk-code {
    background: #e74c3c;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-weight: bold;
    font-size: 1rem;
    box-shadow: 0 0 12px rgba(231, 76, 60, 0.2);
}

/* Etichette di Stato */
.label-danger { color: #ff4d4d; font-weight: bold; }
.label-warning { color: #f1c40f; font-weight: bold; }
.label-critical { color: #9b59b6; font-weight: bold; }

/* Link Coordinate */
.map-link {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
}

.map-link:hover {
    color: #5dade2;
    text-shadow: 0 0 8px rgba(52, 152, 219, 0.4);
}

.map-link i {
    margin-right: 5px;
}

.empty-msg {
    text-align: center;
    padding: 50px !important;
    color: #444;
    font-style: italic;
    font-size: 1rem;
}

/* Legenda Minimalista Centrata */
.emergency-footer-tiny {
    margin-top: 15px;
    padding: 12px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    text-align: center;
}

.legend-row {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 25px;
    margin-bottom: 8px;
}

.legend-row span {
    font-size: 0.75rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.legend-row b {
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-family: 'Monaco', 'Courier New', monospace;
    letter-spacing: 0.5px;
}

/* Colori sobri per la legenda (stile Ghost) */
.sq-7700 { background: rgba(231, 76, 60, 0.15); color: #e74c3c; border: 1px solid rgba(231, 76, 60, 0.4); }
.sq-7600 { background: rgba(241, 196, 15, 0.15); color: #f1c40f; border: 1px solid rgba(241, 196, 15, 0.4); }
.sq-7500 { background: rgba(155, 89, 182, 0.15); color: #9b59b6; border: 1px solid rgba(155, 89, 182, 0.4); }

.disclaimer {
    font-size: 0.65rem;
    color: #444;
    margin: 0;
    font-style: italic;
}

/* --- ADATTAMENTO MOBILE --- */
@media (max-width: 768px) {
    .emergency-section { padding: 15px; }
    
    /* Nasconde Quota e Velocità per salvare spazio su cell */
    .emergency-table th:nth-child(6), .emergency-table td:nth-child(6),
    .emergency-table th:nth-child(7), .emergency-table td:nth-child(7) {
        display: none;
    }
    
    .emergency-table { min-width: 450px; } /* Riduce la larghezza minima */
    
    .legend-row { gap: 15px; }
}


/* Responsive */
@media (max-width: 900px) {
    .grid-stats-top { grid-template-columns: 1fr; }
}

/* --- 8. RESPONSIVE --- */
@media (max-width: 1100px) {
    .grid-stats {
        grid-template-columns: 1fr;
    }
    .polar-height { height: 400px !important; }
    .timeline-height { height: 250px !important; }
}

@media (max-width: 1024px) {
    .grid-stats, .grid-2, .grid-stats-special { grid-template-columns: 1fr; }
    .canvas-container { height: 250px; }
}

/* --- 10. GRIGLIA SUPERIORE UNIFICATA --- */
.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    align-items: stretch;
    margin-bottom: 25px;
}

.card {
    background: rgba(30, 30, 30, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Allineamento automatico dei divisori in fondo */
.card-footer {
    margin-top: auto; 
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 12px;
    font-size: 0.8rem;
    color: #888;
}

/* Stili specifici per l'Orizzonte (Box 2) */
.horizon-inner-grid {
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 10px; 
    margin-top: 10px;
}

#radar-n, #radar-e, #radar-s, #radar-w {
    color: var(--accent);
}

/* Stili specifici per i Record (Box 3) */
.dx-call-record {
    font-size: 1.1rem; 
    margin-bottom: 10px;
    color: var(--accent);
}

.record-meta {
    margin-bottom: 10px; 
    font-size: 0.9rem;
    display: flex;
    gap: 15px;
}

#adsb-record-date {
    color: var(--accent); 
    font-family: 'Courier New', monospace;
}

.airport-reference-single {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 25px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: 20px;
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
}

.ref-unit i {
    color: var(--accent); /* Il tuo colore verde/azzurro */
    margin-right: 6px;
    font-size: 0.8rem;
}

.ref-unit strong {
    color: #fff;
    font-weight: 500;
}

.ref-sep {
    color: rgba(255, 255, 255, 0.15);
}

/* Gestione schermi piccoli */
@media (max-width: 768px) {
    .airport-reference-single {
        gap: 12px;
        font-size: 0.65rem;
        flex-wrap: wrap; /* Su smartphone molto piccoli va su due righe per non tagliarsi */
    }
}

/* --- CORREZIONE RESPONSIVE PER BOX SUPERIORI --- */
@media (max-width: 992px) {
    .grid-3 {
        /* Passa da 3 colonne a 1 colonna su tablet e cellulari */
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    .card {
        padding: 15px; /* Riduce leggermente il padding per recuperare spazio */
    }

    .dx-val {
        font-size: 2rem; /* Ridimensiona il numero grande (es. numero aerei) */
    }
}

/* Ottimizzazione extra per smartphone molto stretti */
@media (max-width: 480px) {
    .horizon-inner-grid {
        /* Mette i punti cardinali (N, E, S, W) uno sotto l'altro */
        grid-template-columns: 1fr !important;
    }
    
    .record-meta {
        flex-direction: column; /* Quota e Direzione vanno uno sotto l'altro */
        gap: 5px;
    }
}

/* Stato iniziale: Pannello fuori dallo schermo a destra */
#nibbio-sidebar {
    position: fixed;
    top: 0;
    right: -500px; /* Lo sposta completamente a destra fuori dalla vista */
    width: 480px;
    height: 100vh;
    background: #0d1117;
    border-left: 3px solid #f1c40f; 
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    z-index: 9999;
    transition: right 0.4s cubic-bezier(0.075, 0.82, 0.165, 1);
    padding: 20px;
    visibility: hidden; /* Sicurezza extra per non intercettare click */
}

/* Quando aggiungeremo la classe 'active' con JS, il pannello entrerà */
#nibbio-sidebar.active {
    right: 0;
    visibility: visible;
}

/* --- STILI INTERNI PANNELLO NIBBIO --- */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #30363d;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.sidebar-title {
    color: #f1c40f;
    margin: 0;
    font-size: 1.2rem;
    text-transform: uppercase;
}

.close-btn {
    background: none;
    border: none;
    color: #8b949e;
    font-size: 2rem;
    cursor: pointer;
}

.chart-container {
    height: 250px;
    margin: 20px 0;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 10px;
}

.mission-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.detail-item {
    background: #161b22;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #30363d;
}

.detail-item i { color: #f1c40f; display: block; margin-bottom: 5px; }

#segment-list {
    list-style: none;
    padding: 0;
    font-size: 0.85rem;
}

#segment-list li {
    padding: 10px;
    border-bottom: 1px solid #21262d;
    color: #c9d1d9;
}

/* --- STILI AGGIUNTIVI PER SELETTORE E CONTENUTI NIBBIO --- */

/* Wrapper per la selezione missione */
.mission-data-box {
    background: rgba(241, 196, 15, 0.05);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid rgba(241, 196, 15, 0.2);
    margin-bottom: 20px;
}

/* La tendina a scomparsa */
.nibbio-select {
    width: 100%;
    background: #161b22;
    color: #f1c40f;
    border: 1px solid #30363d;
    padding: 10px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.3s;
    appearance: none; /* Rimuove lo stile di default del browser */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f1c40f'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
}

.nibbio-select:focus {
    border-color: #f1c40f;
}

/* Etichette e Valori */
.label {
    color: #8b949e;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.value {
    color: #fff;
    font-weight: 600;
    margin-left: 5px;
}

/* Lista Segmenti (Scrollabile se sono tanti) */
#segment-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 180px; /* Evita che la sidebar diventi lunghissima */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #30363d transparent;
}

#segment-list li {
    background: #161b22;
    border: 1px solid #21262d;
    padding: 10px;
    margin-bottom: 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.8rem;
    color: #c9d1d9;
    display: flex;
    align-items: center;
    gap: 10px;
}

#segment-list li i {
    font-size: 0.9rem;
}



/* Personalizzazione Scrollbar per Chrome/Safari */
#segment-list::-webkit-scrollbar { width: 5px; }
#segment-list::-webkit-scrollbar-track { background: transparent; }
#segment-list::-webkit-scrollbar-thumb { background: #30363d; border-radius: 10px; }