/**
 * IW0RQH - VHF Propagation Dashboard
 * Stazione Radio Foligno - "Dark Matter" Style
 * Versione Integrata e Ottimizzata (Filtri + Tabella SDR Style)
 */

/* --- 1. CONTENITORE MAPPA E STRUTTURA --- */
#vhfMap {
    background: #000 !important;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1 !important;
    height: 600px;
}

.leaflet-container {
    background: #000 !important;
}

#vhfMap .leaflet-tile-pane {
    filter: none !important;
}

/* --- 2. MARKER RADAR (IW0RQH STATION) --- */
.radar-marker {
    position: relative;
    width: 20px;
    height: 20px;
}

.radar-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background-color: #00ff00;
    border-radius: 50%;
    box-shadow: 0 0 10px #00ff00;
    z-index: 10;
}

.radar-wave {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    border: 2px solid #00ff00;
    border-radius: 50%;
    opacity: 0;
    animation: radar-pulse 2s infinite;
}

.radar-wave:nth-child(2) { animation-delay: 0.6s; }
.radar-wave:nth-child(3) { animation-delay: 1.2s; }

@keyframes radar-pulse {
    0% { width: 10px; height: 10px; opacity: 0.8; }
    100% { width: 80px; height: 80px; opacity: 0; }
}

/* --- 3. LIVELLI E ANIMAZIONI MAPPA --- */
.leaflet-interactive {
    stroke-opacity: 1;
    filter: drop-shadow(0 0 2px rgba(255, 253, 1, 0.7));
}

.leaflet-interactive[stroke="#ff4757"] {
    stroke-opacity: 0.6;
    animation: horizonPulse 4s infinite ease-in-out;
}

@keyframes horizonPulse {
    0%   { stroke-opacity: 0.2; stroke-width: 1.5; }
    50%  { stroke-opacity: 0.6; stroke-width: 3;   }
    100% { stroke-opacity: 0.2; stroke-width: 1.5; }
}

/* --- 4. PANNELLO SELETTORI (DENTRO MAPPA) --- */
.map-layers-control {
    background: rgba(15, 15, 15, 0.9);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 8px;
    color: #fff;
    font-family: 'Monaco', monospace;
    font-size: 0.75rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

.map-layers-control label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    margin-bottom: 8px;
    text-transform: uppercase;
    font-weight: bold;
    color: #aaa;
    transition: color 0.2s ease;
}

.map-layers-control label:hover { color: #fff; }
.map-layers-control label:last-child { margin-bottom: 0; }
.map-layers-control input { accent-color: #00ff00; }

.color-indicator {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}
.color-indicator.yellow { background-color: #FFFD01; box-shadow: 0 0 5px #FFFD01; }
.color-indicator.red { background-color: #ff4757; box-shadow: 0 0 5px #ff4757; }

/* --- 5. BARRA TECNICA SOTTO MAPPA --- */
.vhf-tech-bar {
    display: flex;
    align-items: center;
    background: #0a0a0a;
    border-top: 1px solid rgba(255,255,255,0.1); /* Crea solo la riga di separazione dalla mappa */
    padding: 15px 25px;
    gap: 40px; 
    justify-content: center;
}

.tech-item {
    display: flex;
    flex-direction: column;
    align-items: center; /* Modifica: Centra label e valore l'uno sull'altro */
    text-align: center;
}

.tech-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: #555;
    letter-spacing: 1px;
    font-weight: 800;
    margin-bottom: 2px; /* Piccolo respiro tra titolo e dato */
}

.tech-value {
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 1rem;
    color: #eee;
    font-weight: 500;
}

.text-accent {
    color: #FFFD01;
    text-shadow: 0 0 8px rgba(255, 253, 1, 0.3);
}

.text-danger { color: #ff4757 !important; }

#conf-gain-eff {
    color: #FFFD01;
    text-shadow: 0 0 10px rgba(255, 253, 1, 0.4);
}

/* --- Spaziatura Filtri --- */
/* Aggiunge spazio vitale tra la barra tecnica della mappa e il blocco dei filtri */
.radio-card:has(.vhf-filters-container) {
    margin-top: 25px !important; 
    margin-bottom: 20px;
}

/* --- 6. POPUP MARKER STILE SDR (IDENTICO AL 100%) --- */

.vhf-custom-popup .leaflet-popup-content-wrapper {
    background: #1e293b !important;
    color: #fff !important;
    border-radius: 10px !important;
    padding: 0 !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    box-shadow: 0 8px 25px rgba(0,0,0,0.6) !important;
}

.leaflet-popup-content { margin: 0 !important; width: 250px !important; }

.vhf-spot-popup { padding: 15px 18px !important; display: flex; flex-direction: column; }

.vhf-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
	padding-right: 25px;
}

.vhf-popup-loc { font-weight: 800; font-size: 1.2rem; letter-spacing: 0.5px; }

.vhf-popup-dist {
    background: rgba(255,255,255,0.1);
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #cbd5e1;
}

/* La linea orizzontale sottile */
.vhf-popup-hr {
    border: 0;
    height: 1px;
    background: rgba(255,255,255,0.1);
    margin: 0 0 12px 0 !important;
}

.vhf-popup-body {
    background: rgba(15, 23, 42, 0.4); /* Sfondo interno più profondo */
    border-radius: 6px;
    padding: 10px 15px 10px 22px !important; /* Più spazio a sinistra per la barra */
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    border: 1px solid rgba(255,255,255,0.03);
}

/* La barra verticale colorata a sinistra */
.vhf-popup-accent {
    position: absolute;
    left: 8px;
    top: 15%;
    bottom: 15%;
    width: 3px;
    border-radius: 4px;
}

.vhf-popup-call {
    font-size: 1.3rem;
    font-weight: 800;
    color: #fff;
    line-height: 1 !important;
    letter-spacing: -0.5px;
}

.vhf-popup-mode {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 4px !important;
    font-weight: 600;
    text-transform: uppercase;
}

.vhf-popup-snr {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -1px;
}

/* Fix triangolino e X */
.vhf-custom-popup .leaflet-popup-tip { background: #1e293b !important; box-shadow: none !important; border: none !important; }

.vhf-custom-popup .leaflet-popup-close-button {
    top: 14px !important;    /* Allineata verticalmente al centro dell'header */
    right: 12px !important;   /* Distanza dal bordo destro */
    color: #64748b !important;
    font-size: 16px !important;
    font-weight: bold !important;
    transition: color 0.2s !important;
}

.vhf-custom-popup .leaflet-popup-close-button:hover {
    color: #fff !important;
    background: transparent !important;
}

/* --- 7. VHF FILTERS LAYOUT (CENTRATURA PERFETTA SDR STYLE) --- */
.vhf-filters-container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end; /* Allinea la base degli input e dei bottoni */
    justify-content: center; /* CENTRA tutto il blocco nella card */
    gap: 30px; /* Spaziatura generosa tra i gruppi come da screenshot */
    padding: 20px 10px; /* Respiro interno */
}

.vhf-filter-item {
    display: flex;
    flex-direction: column;
    gap: 6px; /* Spazio ridotto tra label e input */
}

.vhf-filter-item label {
    font-size: 0.70rem;
    font-weight: 800;
    color: #8a8d91;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

.vhf-input {
    background: #1a1c23; 
    border: 1px solid #2d3139;
    color: #fff;
    padding: 0 12px;
    border-radius: 6px;
    height: 38px; /* Altezza fissa identica a quella dei bottoni */
    line-height: 36px;
    font-family: 'Monaco', monospace;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.vhf-input:focus { border-color: var(--accent); }

.vhf-dynamic-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    height: 38px; /* Forza i contenitori dei bottoni alla stessa altezza degli input */
}

#reset-container {
    height: 38px; /* Allinea il bottone reset alla riga degli input */
    display: flex;
    align-items: center;
}

/* Stile Bottoni (Generati dal JS) */
.filter-btn {
    border: none;
    padding: 0 16px;
    height: 38px; /* Altezza identica agli input */
    line-height: 38px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 0.75rem;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(var(--rgb-current), 0.1);
    color: var(--btn-color);
    box-shadow: 0 0 0 rgba(var(--rgb-current), 0);
}

.filter-btn.active {
    background: var(--btn-color) !important;
    color: #000 !important;
    box-shadow: 0 0 12px rgba(var(--rgb-current), 0.5);
    transform: translateY(-1px);
}

.filter-btn.reset {
    background: rgba(255, 255, 255, 0.05);
    color: #ff4d4d;
    border: 1px solid rgba(255, 77, 77, 0.2);
}

/* --- 8. TABELLA LOG (SCROLL VERTICALE + HEADER FISSO) --- */
.radio-table-wrapper {
    max-height: 650px; /* Limita l'altezza a circa 15 righe */
    overflow-y: auto; /* Abilita lo scroll verticale */
    overflow-x: hidden; /* UCCIDE lo scroll orizzontale fantasma */
    margin-top: 15px;
    padding-right: 5px; /* Spazio per non far accavallare la scrollbar al testo */
}

/* Stile custom per la barra di scorrimento (invisibile ma elegante) */
.radio-table-wrapper::-webkit-scrollbar {
    width: 6px;
}
.radio-table-wrapper::-webkit-scrollbar-track {
    background: transparent; 
}
.radio-table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1); 
    border-radius: 10px;
}
.radio-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3); 
}

.radio-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 8px;
}

/* Fissa le intestazioni della tabella in alto durante lo scroll */
.radio-table th {
    position: sticky;
    top: 0;
    background: #15171c; /* Colore di sfondo della card per mascherare il testo che scorre sotto */
    z-index: 10;
    padding: 12px 15px;
    text-align: left;
    color: #8a8d91;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.radio-table tbody tr {
    background: #1a1c23; 
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.radio-table tbody tr:hover {
    background: #23262f;
    transform: scale(1.002);
}

.radio-table td {
    padding: 15px;
    color: #eee;
    font-size: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    vertical-align: middle;
}

.radio-table td:first-child { 
    border-left: 1px solid rgba(255, 255, 255, 0.05); 
    border-radius: 6px 0 0 6px; 
}

.radio-table td:last-child { 
    border-right: 1px solid rgba(255, 255, 255, 0.05); 
    border-radius: 0 6px 6px 0; 
}

/* =========================================
   OVERRIDE NUCLEARE LEAFLET (SDR STYLE FIX)
   ========================================= */

/* 1. Uccide i margini fantasma di Leaflet dentro i popup */
.vhf-custom-popup .leaflet-popup-content,
.vhf-custom-popup .leaflet-popup-content p,
.vhf-custom-popup .leaflet-popup-content div {
    margin: 0 !important;
    line-height: normal !important;
}

/* 2. Forza l'accostamento tra Callsign e Modo */
.vhf-custom-popup .vhf-popup-info {
    display: block !important; 
}

.vhf-custom-popup .vhf-popup-call {
    display: block !important;
    font-size: 1.4rem !important;
    line-height: 1 !important;
    margin-bottom: 2px !important; /* Solo 2px di spazio dal modo sotto */
    padding: 0 !important;
}

.vhf-custom-popup .vhf-popup-mode {
    display: block !important;
    font-size: 0.85rem !important;
    line-height: 1 !important;
    margin-top: 0 !important;
    padding: 0 !important;
}

/* 3. Allinea l'SNR a destra e lo centra in altezza */
.vhf-custom-popup .vhf-popup-body {
    align-items: center !important;
    padding: 10px 15px !important; /* Leggermente più stretto */
}

/* 4. Rimuove definitivamente i bordi bianchi dal triangolino */
.vhf-custom-popup .leaflet-popup-tip-container {
    overflow: visible !important;
}

.vhf-custom-popup .leaflet-popup-tip {
    background: #1e293b !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

/* --- CONTATORE SPOT STILE SDR --- */
.spot-counter-badge {
    background: rgba(15, 23, 42, 0.9);
    color: var(--accent-cyan, #ffff00);
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 0.8rem;
    border: 1px solid #334155;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    pointer-events: none; /* Non intralcia i click sulla mappa */
    display: flex;
    align-items: center;
}

.spot-counter-badge i {
    margin-right: 5px;
}

#vhf-total-count {
    font-family: 'Inter', monospace;
}