:root {
    --trek-accent: #10b981; /* Verde */
    --trek-warn: #f59e0b;   /* Arancio */
    --trek-info: #3b82f6;   /* Blu */
    --trek-bg: #1e293b;     /* Background Card */
}

/* GRIGLIE */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 20px; }

/* STILE CARD GENERALE */
.card-trek {
    background: var(--trek-bg);
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 15px;
    border-left: 4px solid #444; /* Default spento */
    display: flex; flex-direction: column; justify-content: space-between;
}

/* CODIFICA COLORI (Bordo Sinistro) */
.status-box { border-left-color: var(--trek-accent); }
.location-box { border-left-color: var(--trek-info); }
.tech-box { border-left-color: var(--trek-warn); }
.info-box { border-left-color: #64748b; } /* Grigio per info statiche */

/* TYPOGRAPHY */
h3.date-sub {
    font-size: 0.75rem; text-transform: uppercase; color: #94a3b8;
    margin: 0 0 10px 0; border-bottom: 1px solid #334155; padding-bottom: 8px;
    display: flex; align-items: center; gap: 8px;
}

.label { font-size: 0.65rem; text-transform: uppercase; color: #64748b; font-weight: 700; margin-bottom: 2px; }
.hero-value { font-family: 'Inter', monospace; font-size: 2rem; font-weight: 800; color: #fff; line-height: 1; }
.hero-value.medium { font-size: 1.4rem; }
.val { font-weight: 800; color: #fff; font-size: 1.1rem; }
small { font-size: 0.7rem; color: #94a3b8; margin-left: 2px; }

/* LAYOUT INTERNI CARD */
.big-data-center { text-align: center; margin: 10px 0; }
.data-row-split { display: flex; justify-content: space-around; align-items: center; margin-top: 5px; }
.status-pill { background: rgba(255,255,255,0.05); text-align: center; padding: 5px; border-radius: 6px; font-weight: 800; font-size: 0.8rem; letter-spacing: 1px; }

/* TELEMETRIA */
.main-tech { font-size: 1.5rem; font-weight: 700; margin-bottom: 10px; }
.tech-item i { margin-right: 8px; font-size: 1rem; color: #64748b; }
.aprs-row { font-size: 0.75rem; display: flex; justify-content: space-between; padding-top: 8px; border-top: 1px solid #334155; }

/* INFO STATICHE (BOTTOM) */
.info-value { font-size: 1.1rem; font-weight: 700; color: #fff; }
.info-sub { font-size: 0.85rem; color: #94a3b8; font-style: italic; margin-top: 4px; }
.blue-text { color: var(--trek-info); font-family: monospace; }

/* TELEMETRIA LIVE */
.telemetry-bar {
    display: flex;
    justify-content: flex-end;
    gap: 20px;
    padding: 8px 15px;
    background: rgba(15, 23, 42, 0.8);
    border-radius: 8px 8px 0 0; /* Arrotondato solo sopra per unirsi alla mappa */
    border: 1px solid #334155;
    border-bottom: none;
    font-size: 0.85rem;
    font-weight: 700;
}

.tel-item { display: flex; align-items: center; gap: 8px; }

/* STATI COLORE */
.status-ok { color: var(--trek-accent); }
.status-warn { color: var(--trek-warn); }
.status-crit { color: #ef4444; } /* Rosso critico */

.tel-val { font-family: 'Inter', monospace; color: #fff; }

/* MAPPA */
.map-wrapper { 
    height: 500px; width: 100%; position: relative; 
    border: 2px solid #334155; border-radius: 12px; overflow: hidden; margin-bottom: 20px;
}
#map { height: 100%; width: 100%; background: #0f172a; }
#btn-recenter {
    position: absolute; top: 15px; right: 15px; z-index: 999;
    background: var(--trek-accent); border: none; padding: 8px 15px; border-radius: 20px;
    font-weight: 800; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

/* Forza l'header in cima a tutto */
header, .header-bar {
    position: sticky;
    top: 0;
    z-index: 1000 !important;
}

/* Regola il tasto ricentra per stare sotto l'header */
#btn-recenter {
    z-index: 900 !important;
}

/* Assicurati che anche i controlli Leaflet stiano sotto l'header */
.leaflet-top, .leaflet-bottom {
    z-index: 800 !important;
}

/* --- ADATTAMENTO TEMA CHIARO --- */
[data-theme='light'] {
    --trek-bg: #ffffff;
    --trek-accent: #059669; /* Verde leggermente più scuro per contrasto su bianco */
    --trek-warn: #d97706;
    --trek-info: #2563eb;
}

[data-theme='light'] .card-trek {
    border-color: #e2e8f0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

[data-theme='light'] .hero-value, 
[data-theme='light'] .val, 
[data-theme='light'] .info-value,
[data-theme='light'] .tel-val {
    color: #1e293b; /* Testo scuro su fondo chiaro */
}

[data-theme='light'] .label,
[data-theme='light'] .info-sub,
[data-theme='light'] small,
[data-theme='light'] h3.date-sub {
    color: #64748b;
}

[data-theme='light'] .status-pill {
    background: #f1f5f9;
}

[data-theme='light'] .telemetry-bar {
    background: rgba(255, 255, 255, 0.9);
    border-color: #e2e8f0;
}

/* MOBILE RESPONSIVE */
@media (max-width: 900px) {
    .grid-3 { grid-template-columns: 1fr; gap: 10px; }
    .map-wrapper { height: 400px; }
    .hero-value { font-size: 2.5rem; }
}

/* Fix altezza mappa per mobile */
@media (max-width: 768px) {
    #map {
        height: 400px !important; /* Forza l'altezza minima su mobile */
        width: 100%;
        display: block !important;
    }
    
    .card-map {
        height: 400px !important;
        min-height: 400px !important;
        margin-bottom: 15px;
    }

    /* Opzionale: riduce i margini per guadagnare spazio */
    .grid-3 {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }
}

.tel-section {
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.lora-border {
    border-bottom: none;
    padding-bottom: 0;
}

.section-label {
    font-size: 0.55rem;
    text-transform: uppercase;
    color: #94a3b8;
    letter-spacing: 1px;
    display: block;
    margin-bottom: 8px;
}

.tel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 10px;
    text-align: center;
}

.tel-val-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.tel-val {
    font-size: 1.4rem;
    font-weight: 800;
    color: #fff;
}

.relay-badge {
    font-size: 0.6rem;
    background: rgba(168, 85, 247, 0.2);
    color: #a855f7;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.aprs-status-box {
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: rgba(59, 130, 246, 0.1); 
    padding: 8px 12px; 
    border-radius: 6px; 
    border-left: 3px solid #3b82f6;
}

.lora-full-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 2 righe da 3 colonne su mobile */
    gap: 8px;
    background: rgba(168, 85, 247, 0.1);
    padding: 10px;
    border-radius: 8px;
    margin-top: 12px;
    border: 1px solid rgba(168, 85, 247, 0.3);
}

@media (min-width: 768px) {
    .lora-full-row { grid-template-columns: repeat(6, 1fr); } /* Riga singola su desktop */
}

.tech-tag {
    font-size: 0.8rem; /* Font aumentato */
    color: #94a3b8;
    font-family: 'JetBrains Mono', monospace;
    text-align: center;
}

.tech-tag span {
    color: #fff;
    font-weight: 800;
    display: block; /* Mette il valore sotto l'etichetta per chiarezza */
    font-size: 0.9rem;
}

.lora-main-header {
    width: 100%;
    margin-top: 30px;
    margin-bottom: 5px;
    padding: 0 5px;
    font-size: 0.75rem;
    font-weight: 800;
    color: #a855f7; /* Viola caratteristico LoRa */
    text-transform: uppercase;
    letter-spacing: 1.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0.8;
}

.lora-main-header i {
    font-size: 0.9rem;
}

.trek-main-header {
    width: 100%;
    margin-top: 30px;
    margin-bottom: 5px;
    padding: 0 5px;
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--trek-accent); /* Il verde #10b981 che usi per Locus */
    text-transform: uppercase;
    letter-spacing: 1.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0.8;
}

.trek-main-header i {
    font-size: 0.9rem;
}

.aprs-label { font-size: 0.7rem; font-weight: 700; color: #60a5fa; text-transform: uppercase; }
.aprs-val { font-size: 0.8rem; font-weight: 800; color: #fff; }