/* ==========================================================================
   1. RESET, VARIABILI E TEMA
   ========================================================================== */
:root {
    --bg: #0f172a;
    --card: #1e293b;
    --text-main: #ffffff;
    --text-dim: #94a3b8;
    --border: #334155;
    --accent: #10b981;
    --status-ok: #10b981;
    --max-width: 1200px;
}

/* Gestione Tema Chiaro */
html.light-mode, 
body.light-mode {
    --bg: #f1f5f9 !important;
    --card: #ffffff !important;
    --text-main: #0f172a !important;
    --text-dim: #64748b !important;
    --border: #e2e8f0 !important;
    --accent: #059669 !important;
    --status-ok: #059669 !important;
}

body {
    font-family: 'Inter', sans-serif !important;
    background-color: var(--bg) !important;
    color: var(--text-main) !important;
    transition: background-color 0.3s ease, color 0.3s ease;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

/* Formattazione numeri tabelle/dati */
[id^="live-"], .card span, .value {
    font-variant-numeric: tabular-nums;
    -moz-font-feature-settings: "tnum";
    -webkit-font-feature-settings: "tnum";
    font-feature-settings: "tnum";
}

/* ==========================================================================
   2. LAYOUT E CONTENITORI (Struttura)
   ========================================================================== */
.container { 
    width: 100%; 
    max-width: var(--max-width); 
    margin-left: auto !important; 
    margin-right: auto !important; 
    padding: 0 5px; 
    box-sizing: border-box; 
}

main { 
    padding: 30px 0; 
    /* padding-top non serve più massiccio con sticky */
}

/* ==========================================================================
   3. NAVBAR E LOGO (Corretta per Light Mode)
   ========================================================================== */
nav { 
    background: var(--card); 
    border-bottom: 1px solid var(--border); 
    height: 80px; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    padding: 0 20px; 
    position: sticky; 
    top: 0; 
    z-index: 1100 !important;
}

.nav-container { 
    width: 100%; 
    max-width: var(--max-width); 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

/* LOGO BASE */
.nav-left-logo { 
    text-decoration: none;
    display: flex;
    align-items: center;
    white-space: nowrap;
    transition: all 0.4s ease;
}

/* Stile comune per i testi del logo (Desktop e Mobile) */
.nav-left-logo .d-desktop, 
.nav-left-logo .d-mobile {
    font-weight: 800; 
    font-size: 1.6rem; 
    letter-spacing: -1.2px;
    /* Gradiente Tema Scuro: Verde -> Bianco */
    background: linear-gradient(to right, var(--accent) 0%, #ffffff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

/* FIX LIGHT MODE: Forza il gradiente verso un colore scuro */
body.light-mode .nav-left-logo .d-desktop,
body.light-mode .nav-left-logo .d-mobile {
    /* Gradiente Tema Chiaro: Verde -> Grigio Antracite */
    background: linear-gradient(to right, var(--accent) 0%, #1e293b 100%) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    /* Forza la trasparenza se qualche altra regola tenta di mettere colore */
    color: transparent !important; 
}

/* Hover effect */
.nav-left-logo:hover { opacity: 0.8; transform: translateY(-1px); }

/* BOTTONI AZIONI */
.nav-right-actions { display: flex; align-items: center; gap: 0px; }
.nav-icon-btn { 
    cursor: pointer; font-size: 1.4rem; color: var(--text-dim); 
    background: transparent; border: none; padding: 8px; 
    display: flex; align-items: center; transition: 0.3s;
}
.nav-icon-btn:hover { color: var(--accent); }

/* ==========================================================================
   4. SIDEBAR E MENU LATERALE
   ========================================================================== */
.sidebar {
    height: 100%; width: 0; position: fixed; z-index: 2000;
    top: 0; right: 0; background-color: var(--card);
    overflow-x: hidden; overflow-y: auto; transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 1px solid var(--border); display: flex; flex-direction: column;
}

.sidebar.open { width: 320px; box-shadow: -10px 0 30px rgba(0,0,0,0.5); }

#sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0;
    width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1999;
}

.sidebar-header { padding: 25px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); font-weight: 800; color: var(--accent); }
.sidebar-content { padding: 10px 0 40px 0; }
.sidebar-section { padding: 20px 25px 10px 25px; font-size: 0.75rem; color: var(--text-dim); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.sidebar-content a, .sidebar-link-toggle { padding: 15px 25px; text-decoration: none; font-size: 1rem; color: var(--text-main); display: flex; align-items: center; justify-content: space-between; transition: 0.2s; cursor: pointer; }
.sidebar-content a:hover, .sidebar-link-toggle:hover { background: rgba(16, 185, 129, 0.1); color: var(--accent); }
.sidebar-link-inner { display: flex; align-items: center; gap: 12px; }

.submenu { max-height: 0; overflow: hidden; background: rgba(0, 0, 0, 0.1); transition: max-height 0.3s ease-out; }
.sidebar-item.active .submenu { max-height: 400px; }
.sidebar-item.active .arrow { transform: rotate(180deg); }
.submenu a { padding-left: 55px; font-size: 0.9rem; color: var(--text-dim); }
.arrow { font-size: 0.7rem; transition: 0.3s; }

/* ==========================================================================
   5. TITOLI DASHBOARD E RADAR STATUS
   ========================================================================== */
header { 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-end; 
    margin-bottom: 30px; 
    padding-bottom: 15px; 
    border-bottom: 1px solid var(--border); 
}

.main-page-title {
    margin: 0 !important; padding: 0 !important; line-height: 1.2 !important;
    font-size: 1.4rem !important; font-weight: 800 !important;
    text-transform: uppercase !important; letter-spacing: 1px !important;
    color: var(--text-main) !important; display: flex; align-items: center;
}

.main-page-date {
    font-size: 0.95rem !important; font-weight: 400 !important;
    color: var(--text-dim) !important; text-transform: none !important;
    margin-left: 10px; letter-spacing: 0;
}

.header-titles h1 { margin: 0; font-size: 1.8rem; }
.date-sub { color: var(--text-dim); text-transform: none; letter-spacing: 1px; font-weight: bold; font-size: 0.85rem; }

/* Radar Status Online - Effetto Glow Potenziato */
.status-container { 
    display: flex; align-items: center; gap: 8px; padding: 6px 12px; 
    border-radius: 50px; background: rgba(16, 185, 129, 0.1); 
    border: 1px solid rgba(16, 185, 129, 0.2); margin-bottom: 5px; 
}

.radar-dot { 
    height: 10px; /* Leggermente più grande */
    width: 10px; 
    background-color: var(--status-ok); 
    border-radius: 50%; 
    /* Base luminosa costante */
    box-shadow: 0 0 8px var(--status-ok);
    animation: pulse-glow-green 2s infinite ease-in-out; 
}

.status-text { 
    font-size: 0.8rem; 
    font-weight: 800; 
    color: var(--status-ok); 
    text-shadow: 0 0 5px rgba(16, 185, 129, 0.3); /* Leggero glow anche sul testo */
}

@keyframes pulse-glow-green { 
    0% { 
        transform: scale(0.9); 
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7), 0 0 5px var(--status-ok); 
    } 
    50% { 
        transform: scale(1.2); 
        /* Esplosione di luce esterna */
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0), 0 0 12px var(--status-ok); 
    } 
    100% { 
        transform: scale(0.9); 
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0), 0 0 5px var(--status-ok); 
    } 
}

/* ==========================================================================
   6. ALMANACCO (Scrolling Text)
   ========================================================================== */
.almanacco-container { 
    width: 100%; background: var(--card); border-bottom: 1px solid var(--border); 
    overflow: hidden; position: relative; height: 50px; display: flex; 
    align-items: center; margin-bottom: 25px; padding: 0 !important;
}

.almanacco-container::before, .almanacco-container::after {
    content: ""; position: absolute; top: 0; width: 100px; height: 100%; z-index: 10; pointer-events: none;
}
.almanacco-container::before { left: 0; background: linear-gradient(to right, var(--card), transparent); }
.almanacco-container::after { right: 0; background: linear-gradient(to left, var(--card), transparent); }

.scrolling-text { 
    display: inline-block; white-space: nowrap; padding-left: 100%; 
    animation: marquee 120s linear infinite; font-size: 0.95rem; 
    line-height: 50px; margin: 0 !important; list-style: none !important;
}

.scrolling-text .label { color: var(--text-dim); text-transform: uppercase; font-size: 0.75rem; font-weight: 700; letter-spacing: 1px; margin-right: 8px; }
.scrolling-text .value { color: var(--text-main); font-weight: 800; margin-right: 60px; }
.almanacco-container:hover .scrolling-text { animation-play-state: paused; }

@keyframes marquee { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } }

/* ==========================================================================
   7. GRID E CARD (Componenti Dati)
   ========================================================================== */
.grid-3 { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 30px; }

.card { 
    background: var(--card); border-radius: 20px; padding: 20px; 
    border: 1px solid var(--border); display: flex; flex-direction: column; 
    transition: transform 0.2s; min-height: 150px;
}

.card h3.date-sub {
    font-size: 0.85rem !important; text-transform: uppercase !important;
    color: var(--text-dim) !important; font-weight: 700 !important; margin: 0 0 15px 0 !important;
}

/* ==========================================================================
   8. FOOTER
   ========================================================================== */
footer { width: 100%; margin-top: 20px; }

footer .container {
    border-top: 1px solid var(--border); padding: 20px 20px;
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.75rem !important; color: var(--text-dim);
}

.cmx-badge {
    background: var(--border); padding: 3px 8px; border-radius: 4px;
    color: var(--text-main); font-family: monospace; font-size: 0.7rem;
}

/* ==========================================================================
   9. RESPONSIVE (Tutti gli adattamenti)
   ========================================================================== */

/* Tablet & Desktop ridotto */
@media (max-width: 992px) { 
    .grid-3 { grid-template-columns: 1fr; }
    header { flex-direction: column; align-items: flex-start; gap: 15px; }
}

/* Mobile & Tablet piccolo */
@media (max-width: 768px) {
    .scrolling-text { animation-duration: 60s; }
    .almanacco-container::before, .almanacco-container::after { width: 50px; }
    .scrolling-text .value { margin-right: 40px; }
}

/* Smartphone */
@media (max-width: 480px) {
    /* Header: Gestione Titolo Breve */
    .d-desktop { display: none !important; }
    .d-mobile { display: inline !important; }

    .nav-left-logo { 
        font-size: 1.2rem !important; 
        white-space: nowrap;
    }

    .nav-right-actions { gap: 0px; }
    .nav-icon-btn { font-size: 1.2rem !important; }

    /* Footer: Copyright unito in un'unica riga fluida */
    footer .container {
        flex-direction: column !important;
        gap: 8px !important;
        text-align: center !important;
        padding: 20px 10px !important;
    }

    .copyright {
        display: inline !important; 
        width: 100%;
        line-height: 1.6;
        font-size: 0.8rem !important;
    }

    /* Mantiene tutto sulla stessa riga (strong, span, ID) finché c'è spazio */
    .copyright strong, 
    .copyright span, 
    #station-type {
        display: inline !important;
        margin: 0 4px !important;
    }

    /* Gestione spazi per badge e sorgente sotto il copyright */
    .cmx-badge {
        display: inline-block;
        margin-top: 5px !important;
    }
}

/* Default per Desktop: Nasconde il titolo mobile */
@media (min-width: 481px) {
    .d-mobile { display: none !important; }
    .d-desktop { display: inline !important; }
}