/* ==========================================================================
   IW0RQH - MASTER GLOBAL CSS
   Ver. 4.0 - Top-Down Logic & Unified Design
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CORE VARIABLES & THEME
   -------------------------------------------------------------------------- */
:root {
    --bg: #0f172a;
    --card: #1e293b;
    --text-main: #ffffff;
    --text-dim: #94a3b8;
    --border: #334155;
    --accent: #10b981;       /* Verde base */
    --status-ok: #10b981;    /* Stato Online */
    --status-ko: #ef4444;    /* Stato Offline */
    --status-warn: #f59e0b;  /* Stato Warning */
    --max-width: 1200px;
    --nav-height: 70px;
}

/* TEMA CHIARO (Light Mode) */
html.light-mode, body.light-mode {
    --bg: #f1f5f9;
    --card: #ffffff;
    --text-main: #0f172a;
    --text-dim: #64748b;
    --border: #e2e8f0;
    --accent: #059669;
    --status-ok: #059669;
}

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

h1, .h1, .hero h1 { margin: 0 !important; padding: 0 !important; }
a { text-decoration: none; color: inherit; transition: 0.2s; }
ul, li { list-style: none; padding: 0; margin: 0; }

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* --------------------------------------------------------------------------
   3. NAVIGATION BAR (Header Sito)
   -------------------------------------------------------------------------- */
nav {
    height: var(--nav-height);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    position: sticky; top: 0; z-index: 1000;
}

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

/* Logo (Sinistra) */
.nav-left-logo {
    font-weight: 800; font-size: 1.8rem; color: var(--text-main);
}
.nav-context {
    margin-left: 8px; font-weight: 400; color: var(--accent);
}

/* Gruppo Destro (Link + Icone) */
.nav-right-actions { display: flex; align-items: center; gap: 15px; }

.nav-links {
    display: flex; gap: 20px; margin-right: 15px;
    border-right: 1px solid var(--border); padding-right: 15px;
}

.nav-link-item {
    color: var(--text-dim); font-size: 0.9rem; font-weight: 600;
    display: flex; align-items: center; gap: 6px;
}
.nav-link-item:hover { color: var(--text-main); }
.nav-link-item.active { color: var(--accent); }

/* Icon Buttons (Tema, Menu) */
.nav-icon-btn {
    background: none; border: none; color: var(--text-main);
    font-size: 1.1rem; cursor: pointer;
    transition: transform 0.2s, color 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.nav-icon-btn:hover { transform: scale(1.1); color: var(--accent); }

/* Logica Icone Sole/Luna */
.sun-icon { display: none; }
.moon-icon { display: block; }
html.light-mode .sun-icon { display: block; }
html.light-mode .moon-icon { display: none; }


/* --------------------------------------------------------------------------
    4. OFF-CANVAS MENU (Stile Verticale Top-Down)
   -------------------------------------------------------------------------- */
.off-canvas {
    position: fixed; 
    top: 0; 
    right: -320px; 
    width: 280px; 
    height: 100vh;
    background: #111; /* Tema Dark */
    box-shadow: -5px 0 25px rgba(0,0,0,0.5);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
    z-index: 1100;
    display: flex; 
    flex-direction: column;
    justify-content: flex-start !important; /* Forza tutto in alto */
}

/* Supporto Light Mode */
.light-mode .off-canvas {
    background: #ffffff;
    border-left: 1px solid #e2e8f0;
}

.off-canvas.active { right: 0; }

/* Header del Menu */
.offcanvas-header {
    padding: 20px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    flex-shrink: 0;
}

.light-mode .offcanvas-header { border-bottom: 1px solid #f1f5f9; }

.offcanvas-header h3 {
    margin: 0;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent, #10b981);
}

/* --- Pulsante X Stilizzato --- */
.close-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 50%;
    color: #888;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    transform: rotate(90deg);
}

.light-mode .close-btn { background: #f1f5f9; border-color: #e2e8f0; }

/* Corpo del Menu - Allineamento in Alto */
.offcanvas-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0; /* Ridotto il padding superiore */
    display: block; /* Rimuove flex per evitare centramenti verticali */
}

.offcanvas-section {
    margin-bottom: 25px;
}

.section-label {
    display: block;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #444;
    padding: 10px 25px;
    letter-spacing: 1.5px;
}

.light-mode .section-label { color: #94a3b8; }

/* Link Singoli */
.nav-link-custom {
    display: flex;
    align-items: center;
    padding: 14px 25px;
    color: #ccc;
    text-decoration: none;
    font-size: 0.95rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.light-mode .nav-link-custom { color: #334155; }

.nav-link-custom i {
    width: 20px;
    margin-right: 15px;
    font-size: 0.8rem;
    color: var(--accent);
    opacity: 0.6;
}

.nav-link-custom:hover {
    background: rgba(16, 185, 129, 0.05);
    color: #fff;
    border-left-color: var(--accent);
    padding-left: 30px;
}

.light-mode .nav-link-custom:hover { background: #f8fafc; color: var(--accent); }

/* --- OFF-CANVAS MENU (Progetti) --- */
.off-canvas {
    position: fixed;
    top: 0;
    right: -300px; /* Nascosto a destra */
    width: 300px;
    height: 100vh;
    background: var(--card);
    border-left: 1px solid var(--border);
    z-index: 1002;
    transition: right 0.3s ease;
    box-shadow: -5px 0 15px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
}

.off-canvas.active {
    right: 0; /* Entra in campo */
}

/* --- OVERLAY OSCURANTE --- */
.offcanvas-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7); /* Scurisce la pagina */
    backdrop-filter: blur(4px);    /* Sfoca lo sfondo */
    z-index: 1001;
    display: none;                 /* Nascosto di default */
    opacity: 0;
    transition: opacity 0.3s ease;
    cursor: pointer;
}

.offcanvas-overlay.active {
    display: block;
    opacity: 1;
}

/* Header del menu */
.offcanvas-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.offcanvas-header h3 { margin: 0; font-size: 1.1rem; text-transform: uppercase; }

.close-btn {
    background: none; border: none; color: var(--text-main);
    font-size: 1.5rem; cursor: pointer;
}

/* --- GESTIONE VISIBILITÀ --- */
.mobile-only {
    display: none !important; /* NASCOSTO SU DESKTOP SEMPRE */
}

@media (max-width: 992px) {
    .mobile-only {
        display: block !important; /* APPARE SOLO SOTTO I 992px */
    }
}


/* ============================================================
   5. UNIVERSAL PAGE HEADER (page_header.php) - STRICT ALIGN
   ============================================================ */
.page-header-strip {
    display: flex;
    justify-content: space-between; /* Sinistra e Destra agli estremi */
    align-items: center;            /* CENTRATURA VERTICALE GENERALE */
    padding: 25px 0 20px 0;
    font-family: 'Inter', sans-serif;
    min-height: 40px;               /* Altezza minima per stabilità */
}

/* --- LATO SINISTRO (TITOLI) --- */
.ph-left {
    display: flex;
    align-items: center; /* Centra il testo dentro il suo contenitore */
    flex-grow: 1;
}

.ph-title-compound {
    margin: 0;
    display: flex;
    align-items: center; /* Centra Titolo, Pipe e Data tra loro */
    gap: 12px;
    flex-wrap: wrap;
    line-height: 1;      /* Fondamentale per eliminare spazi fantasma sopra/sotto */
}

/* Titolo Principale */
.ph-main-text {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: -0.5px;
    /* FIX OTTICO: Spesso i font maiuscoli sembrano alti. 
       Questo padding-top minimo li abbassa visivamente di 1px */
    padding-top: 2px; 
}

/* Separatore Verticale */
.ph-pipe {
    font-size: 1.2rem;
    color: var(--accent);
    font-weight: 300;
    opacity: 0.6;
    margin-top: -1px; /* Ritocco fine */
}

/* Data */
.ph-date-small {
    font-size: 0.95rem;
    color: var(--text-dim);
    font-weight: 500;
    letter-spacing: 0.5px;
    padding-top: 2px; /* Allinea otticamente col titolo */
}


/* --- LATO DESTRO (RADAR) --- */
.ph-right {
    display: flex;
    align-items: center; /* Centra il radar verticalmente */
    height: 100%;        /* Occupa tutta l'altezza disponibile */
}

/* Reset specifico per il Radar nell'header per evitare margini strani */
.ph-right .status-indicator {
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    height: auto !important;
    /* Se sembra ancora alto/basso, gioca con questo transform */
    transform: translateY(1px); 
}

/* Linea divisoria */
.ph-divider {
    height: 1px; width: 100%;
    background: linear-gradient(90deg, var(--accent) 0%, rgba(255,255,255,0.1) 50%, transparent 100%);
    margin-bottom: 30px; opacity: 0.6;
}


/* --------------------------------------------------------------------------
   6. RADAR & STATUS INDICATORS (Shared System)
   -------------------------------------------------------------------------- */
.status-indicator {
    display: flex; align-items: center; gap: 8px;
}

.radar-mini {
    height: 8px; width: 8px; border-radius: 50%;
    display: inline-block; background-color: var(--status-ok);
}

/* Stato Online (Verde Pulsante) */
.radar-online {
    background-color: var(--status-ok);
    box-shadow: 0 0 5px var(--status-ok);
    animation: pulse-glow-green 2s infinite ease-in-out;
}

/* Stato Offline (Rosso Fisso) */
.radar-offline {
    background-color: var(--status-ko) !important;
    box-shadow: 0 0 5px var(--status-ko) !important;
    animation: none !important;
}

/* Testo Status */
.status-label {
    font-size: 0.75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.5px;
}


/* --------------------------------------------------------------------------
   7. DASHBOARD CARDS (Home Gateway)
   -------------------------------------------------------------------------- */
.gateway-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 Colonne fisse */
    
    /* Gap ampio: 50px verticale (stacca le righe), 25px orizzontale */
    gap: 60px 25px; 
    
    /* Margine sotto enorme per proteggere il footer */
    margin-bottom: 100px; 
    
    margin-top: 30px;
    align-items: stretch;
}

/* --- RESPONSIVITÀ --- */
@media (max-width: 1100px) {
    .gateway-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 colonne su tablet */
        gap: 30px 20px;
    }
}

@media (max-width: 768px) {
    .gateway-grid {
        grid-template-columns: 1fr; /* 1 colonna su mobile */
        gap: 30px; /* Spazio uniforme su mobile */
    }
}

/* --- STILE ORIGINALE INVARIATO --- */
.card-gateway {
    background: var(--card); border: 1px solid var(--border); border-radius: 16px;
    padding: 20px; display: flex; flex-direction: column; justify-content: space-between;
    height: 100%; min-height: 220px; text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.card-gateway:hover {
    transform: translateY(-5px); border-color: var(--accent);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

/* Interno Card */
.card-gateway > a { display: flex; flex-direction: column; flex-grow: 1; margin-bottom: 1px; }
.card-icon i { font-size: 2rem; margin-bottom: 10px; color: var(--accent); display: block; }
.card-gateway h3 { margin: 5px 0; font-size: 2.3rem; font-weight: 700; }
.card-desc { color: var(--text-dim); font-size: 0.9rem; margin: 5px 0; line-height: 1.4; }

/* Dati Live Grandi */
.card-value {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    margin: 15px 0;
}
.live-big { font-size: 1.8rem; font-weight: 800; color: var(--text-main); line-height: 1; }
.live-small { font-size: 1rem; font-weight: 500; color: var(--text-dim); margin-top: 8px; text-transform: uppercase; }
/* Supporto specifico per DMR: permette testo misto maiuscolo/minuscolo */
.live-small#dmr-sub-info { text-transform: none; font-size: 0.9rem; }

/* Footer della Card */
.card-divider { height: 1px; background: var(--border); width: 100%; opacity: 0.5; margin: 0; border: 0; }
.card-footer-meta {
    display: flex; justify-content: space-between; align-items: center;
    height: 30px; margin-top: 15px; width: 100%;
}

/* Info Icon Link */
.info-link {
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%;
    transition: all 0.2s ease;
}
.info-link i { color: var(--text-dim); opacity: 0.7; font-size: 1.1rem; }
.info-link:hover { background-color: rgba(255, 255, 255, 0.05); }
.info-link:hover i { color: var(--accent); opacity: 1; }

/* --- ALIAS PER SEZIONI RADIO --- */
.radio-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 25px;
    transition: all 0.3s ease;
    backdrop-filter: none !important; 
}

.radio-card:hover {
    border-color: var(--accent);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

/* --- ANIMAZIONE RADAR DMR (Arancione Pulsante) --- */
.radar-dmr-live {
    background-color: #f59e0b; /* Arancione DMR */
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
    animation: pulse-dmr 1.5s infinite cubic-bezier(0.66, 0, 0, 1);
}

@keyframes pulse-dmr {
    to {
        box-shadow: 0 0 0 10px rgba(245, 158, 11, 0);
    }
}

/* Classi standard per coerenza (se non le hai già) */
.radar-online {
    background-color: #10b981; /* Verde smeraldo (Standby) */
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
}

.radar-offline {
    background-color: #ef4444; /* Rosso (Spento) */
    box-shadow: none;
    animation: none;
}


/* --------------------------------------------------------------------------
   8. FOOTER
   -------------------------------------------------------------------------- */
footer { margin-top: 40px; }
footer .container {
    border-top: 1px solid var(--border); padding: 25px 20px;
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.75rem; color: var(--text-dim);
}
.footer-left strong { color: var(--text-main); font-weight: 800; }
.footer-right i { color: var(--accent); font-size: 0.7rem; }


/* --------------------------------------------------------------------------
   9. ANIMATIONS
   -------------------------------------------------------------------------- */
/* Pulsazione Verde Sottile (Usata da Radar Header e Home) */
@keyframes pulse-glow-green {
    0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); } /* Scale ridotto per eleganza */
    100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Flash Update (Per aggiornamento dati live) */
.flash-update { animation: flash-animation 1.2s ease-out; }
@keyframes flash-animation {
    0% { color: var(--accent); text-shadow: 0 0 20px var(--accent); transform: scale(1.05); }
    100% { color: var(--text-main); text-shadow: none; transform: scale(1); }
}


/* --------------------------------------------------------------------------
   10. RESPONSIVE QUERIES (Fix Margine Superiore)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {

    /* --- 1. FIX SPAZI DASHBOARD & GRID --- */
    
    /* Griglia: Blocco unico, larghezza piena, MA con spazio sopra */
    .gateway-grid, .grid-3 { 
        display: block !important;
        width: 100% !important;
        margin-top: 30px !important;  /* <--- ECCO IL FIX: Stacca il primo box dall'header */
        margin-bottom: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 0 !important;
    }

    /* Card: Spazio sotto, larghezza piena, box-sizing corretto */
    .card, .card-gateway, .radio-card { 
        display: block !important;
        width: 100% !important;
        height: auto !important; 
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 25px !important; /* Spazio tra i box */
        position: relative !important;
        box-sizing: border-box !important;
    }

    /* Rimuove il margine dall'ultima card */
    .card:last-child, .card-gateway:last-child {
        margin-bottom: 0 !important;
    }

    /* --- 2. HEADER PAGINA --- */
    .page-header-strip { 
        flex-direction: column; 
        align-items: center; 
        text-align: center;
        gap: 15px; 
        padding: 20px 0; 
    }
    
    .ph-right { width: 100%; justify-content: center; }
    .ph-main-text { font-size: 1.4rem; }
    .ph-pipe { display: none; } 
    .ph-date-small { display: block; width: 100%; margin-top: 5px; }

    /* --- 3. FOOTER & NAV --- */
    footer .container { flex-direction: column; gap: 15px; text-align: center; }
    .nav-links { display: none; } 
    .mobile-only { display: block !important; }
}

@media (max-width: 480px) {
    :root { --nav-height: 60px; }
    .container { padding: 0 15px; }
    .nav-left-logo { font-size: 1.4rem; }
    /* Margine extra specifico per schermi piccoli se serve */
    .gateway-grid { margin-top: 25px !important; }
}