:root {
    /* --- TAVOLOZZA --- */
    --bg-light: #ffffff;
    --text-light: #0d1117;
    --header-light: #91c3ff;
    --border-light: #6ea3df;
    --primary: #0000ff;

    --bg-dark: #0f172a;
    --text-dark: #e2e8f0;
    --header-dark: #1a237e;
    --border-dark: #475569;
    --link-dark: #60a5fa;

    --container: 1200px;
    --radius: 12px;
    --transition: all 0.3s ease;
}

/* --- LOGICA PONTE --- */
body.theme-light {
    --bg-current: var(--bg-light);
    --text-current: var(--text-light);
    --header-current: var(--header-light);
    --border-current: var(--border-light);
    --accent-current: var(--primary);
    --card-bg: var(--bg-light);
    --phone-color: var(--primary);
}

body.theme-dark {
    --bg-current: var(--bg-dark);
    --text-current: var(--text-dark);
    --header-current: var(--header-dark);
    --border-current: var(--border-dark);
    --accent-current: var(--link-dark);
    --card-bg: #1e293b;
    --phone-color: var(--link-dark);
}

/* --- RESET & BASE --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body { 
    font-family: 'Inter', sans-serif; 
    line-height: 1.6; 
    background-color: var(--bg-current);
    color: var(--text-current);
    transition: background 0.3s ease, color 0.3s ease; 
}

.container { max-width: var(--container); margin: 0 auto; padding: 0 1.5rem; }
.text-center { text-align: center; }

/* --- HEADER --- */

header {
    position: sticky;
    top: 0;
    z-index: 10000; /* Superiore ai pannelli e ai sottomenu */
    background: var(--header-current);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.gs-header { 
    padding: 1.2rem 0; 
    border-bottom: 2px solid var(--border-current); 
    background: var(--header-current);
    transition: var(--transition);
}
body.theme-dark .gs-header { box-shadow: 0 4px 10px rgba(0,0,0,0.3); }

.header-flex { display: flex; justify-content: space-between; align-items: center; }
.main-logo { height: 55px; width: auto; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }

.main-nav ul { display: flex; list-style: none; gap: 2rem; }
.main-nav a { 
    text-decoration: none; 
    color: inherit; 
    font-weight: 700; 
    text-transform: uppercase; 
    font-size: 0.9rem; 
}
.main-nav a:hover { color: var(--accent-current); }

/* --- CONTATTI & LINKS --- */
.btn-phone, .phone-text, .footer-contact-rapid a, .footer-bottom a, .social-links a, #open-cookie-settings, .gs-cookie-details summary { 
    color: var(--phone-color) !important; 
    text-decoration: none; 
    font-weight: 700; 
}

/* --- HERO --- */
.hero-section { padding: 6rem 0 4rem; }
.main-title { 
    font-size: 2.8rem;
    line-height: 1.2;
    margin-bottom: 1.5rem; 
    font-weight: 850;
    color: var(--accent-current); 
    margin-left: auto; 
    margin-right: auto;
    max-width: 900px;
}
.main-subtitle { 
    font-size: 1.4rem;
    line-height: 1.6;
    color: var(--text-current);
    opacity: 0.85; 
    max-width: 750px; 
    margin: 0 auto;
    font-weight: 400;
}

/* Separatore tra main-title e main-subtitle */
.main-title::after {
    content: "";
    display: block;
    width: 60px;
    height: 4px;
    background: var(--accent-current);
    margin: 1.5rem auto 0;
    border-radius: 2px;
    opacity: 0.3;
}

/* --- TILE GRID --- */
.tile-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); 
    gap: 2.5rem; 
    margin: 4rem 0; 
}

.tile-card { 
    position: relative; 
    display: flex;
    flex-direction: column; 
    height: 100%; 
    border: 1px solid var(--border-current); 
    border-radius: var(--radius);
    background: var(--card-bg); 
    overflow: hidden; 
    transition: var(--transition); 
}

.tile-card:hover { transform: translateY(-10px); box-shadow: 0 20px 30px rgba(0,0,0,0.15); }

.tile-full-link {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10;
    text-indent: -9999px;
}

.tile-img-wrapper { width: 100%; overflow: hidden; background: #fff; line-height: 0; }
body.theme-dark .tile-img-wrapper { background: #f8fafc; border-bottom: 1px solid var(--border-dark); }
.tile-img { width: 100%; height: auto; display: block; transition: transform 0.3s ease; }

.tile-body {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    padding: 1.5rem 1.5rem 4.5rem 1.5rem; 
    text-align: center;
    position: relative;
    z-index: 1;
}

.tile-title {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 4rem; 
    margin: 0 0 1rem 0;
    font-size: 1.6rem; 
    color: var(--accent-current); 
    font-weight: 800;
    text-align: center;
}

.tile-body p {
    flex-grow: 1;
    margin-bottom: 1.5rem;
    text-align: center;
}

.tile-read-more {
    margin-top: auto; 
    padding-bottom: 0.5rem; 
    font-weight: 700;
    color: var(--accent-current);
    display: block;
    text-align: center;
}

.tile-claim {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center; /* Forza allineamento anche su più righe */
    height: 4.5rem; 
    padding: 0 1.2rem;
    background: var(--accent-current);
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 800;
    text-transform: uppercase;
    line-height: 1.2;
    letter-spacing: 1px;
}
body.theme-dark .tile-claim { color: var(--bg-dark); }

/* --- FAQ & FOOTER --- */
.faq-aeo-section { margin-top: 6rem; padding: 4rem; background: rgba(145, 195, 255, 0.1); border-radius: 20px; }
body.theme-dark .faq-aeo-section { background: rgba(30, 41, 59, 0.5); }
.faq-item h3 { color: var(--accent-current); margin-top: 1.25rem; margin-bottom: 0.5rem; }

.gs-footer { padding: 1.5rem 0 1rem; background: var(--header-current); border-top: 2px solid var(--border-current); margin-top: 3rem; }
.footer-grid { display: flex; justify-content: space-between; align-items: center; }

/* --- COOKIE BANNER (FIX CONTRASTO DARK) --- */
.gs-cookie-banner {
    position: fixed; bottom: 25px; left: 25px; max-width: 450px; width: calc(100% - 50px);
    z-index: 10000; background: var(--card-bg); border: 1px solid var(--border-current);
    border-radius: 15px; padding: 1.5rem; color: var(--text-current); animation: slideUp 0.4s ease-out;
}
@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.gs-cookie-btn {
    flex: 1; padding: 0.5rem 1rem; font-size: 0.8rem; border-radius: 8px; cursor: pointer;
    font-weight: 700; border: 1px solid var(--border-current); background: transparent;
    color: var(--text-current); /* Assicura che il testo segua il tema */
}
.gs-cookie-btn-primary { background: var(--accent-current); color: #fff; border: none; }
body.theme-dark .gs-cookie-btn-primary { color: var(--bg-dark); }

/* Fix per pulsante secondario e "X" in modalità dark */
body.theme-dark .gs-cookie-btn:not(.gs-cookie-btn-primary) { 
    color: var(--text-dark); 
    border-color: var(--border-dark); 
}
.gs-cookie-close {
    position: absolute; top: 10px; right: 15px; background: none; border: none;
    font-size: 1.5rem; font-weight: bold; cursor: pointer; 
    color: var(--text-current); /* Segue il tema: nero su light, bianco su dark */
    opacity: 0.7; transition: var(--transition);
}
.gs-cookie-close:hover { opacity: 1; transform: scale(1.1); }

/* --- NOTICE CONTENUTI BLOCCATI (GDPR) --- */
.gs-blocked-content-notice {
    background: rgba(145, 195, 255, 0.1);
    padding: 2.5rem;
    text-align: center;
    border: 2px dashed var(--border-current);
    margin: 2rem auto;
    border-radius: var(--radius);
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

body.theme-dark .gs-blocked-content-notice {
    background: rgba(30, 41, 59, 0.5);
}

.gs-blocked-content-notice p {
    font-weight: 600;
    color: var(--text-current);
    margin: 0;
}

.gs-blocked-content-notice button {
    cursor: pointer;
    background: var(--accent-current);
    border: none;
    color: #fff;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    transition: var(--transition);
}

body.theme-dark .gs-blocked-content-notice button {
    color: var(--bg-dark);
}

.gs-blocked-content-notice button:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* --- FIX DISALLINEAMENTO MOBILE (<500px) --- */
@media (max-width: 500px) {
    .container { 
        padding: 0 1rem !important; 
        width: 100% !important;
        margin: 0 !important; /* Evita spostamenti laterali */
    }
    .main-title { 
        margin-left: 0 !important; 
        margin-right: 0 !important; 
        text-align: center; 
    }
    .tile-body, .hero-section, .tile-card {
            text-align: center !important;
        }
    .tile-title {
            justify-content: center !important;
        }
}

/* --- MENU MOBILE: SCROLL & SOTTOMENU --- */

.menu-trigger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    z-index: 2000;
    position: relative;
}

.menu-trigger .bar {
    width: 25px;
    height: 3px;
    background-color: var(--accent-current);
    border-radius: 2px;
    transition: var(--transition);
}

.menu-trigger.active { z-index: 1499; } /* altrimenti la X della chiusura menù mobile resta SOPRA il menù stesso che ha z-index 1500 */
.menu-trigger.active .bar:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.menu-trigger.active .bar:nth-child(2) { opacity: 0; }
.menu-trigger.active .bar:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

.nav-next-trigger, 
.nav-prev-trigger {
    display: none !important; 
}

@media (max-width: 992px) {
  
    .nav-panel {
      display: block !important; /* Mostra tutto in verticale */
      width: 100%;
      animation: none !important; /* Rimuovi animazioni desktop */
    }
    
    /* Rimuovi eventuali spaziature eccessive tra i pannelli su mobile */
    .nav-viewport {
        display: block;
        height: auto;
    }
  
    .menu-trigger { display: flex !important; }
    
    .main-nav {
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: var(--card-bg);
        z-index: 1500;
        padding: 80px 1.5rem 2rem;
        overflow-y: auto; 
        -webkit-overflow-scrolling: touch;
        transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .main-nav.active { right: 0; }
    .main-nav ul { flex-direction: column; gap: 0; }
    .main-nav li { width: 100%; border-bottom: 1px solid rgba(0,0,0,0.05); }

    .menu-item-wrapper {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .main-nav a { padding: 1rem 0; display: block; flex-grow: 1; }

    /* Stato iniziale sottomenu Mobile: Chiuso */
    .submenu {
        display: none; 
        visibility: hidden;
        height: 0;
        overflow: hidden;
        background: rgba(0, 0, 0, 0.03);
        padding-left: 1.5rem !important;
        list-style: none;
    }

    /* Classe attivata dal JS */
    .submenu.open { 
        display: block; 
        visibility: visible;
        height: auto;
    }

    .submenu-toggle {
        background: transparent;
        border: none;
        font-size: 1.8rem;
        color: var(--accent-current);
        width: 50px;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        flex-shrink: 0;
    }
}

@media (min-width: 993px) {
    /* Reset & Layout Base */
    .submenu-toggle { display: none !important; }

    .main-nav {
        flex: 1;
        margin: 0 2rem;
        position: relative;
        overflow: visible !important;
    }

    .nav-viewport {
        position: relative;
        min-height: 55px;
        display: flex;
        align-items: center;
    }

    /* Logica dei Pannelli */
    .nav-panel {
        display: none; /* Default: chiusi */
        width: 100%;
        list-style: none;
        gap: 2rem;
        align-items: center;
        justify-content: center;
    }

    /* Fallback: Se JS è spento o è il primo caricamento, mostra il Panel 0 */
    .nav-panel[data-panel="0"] {
        display: flex;
    }

    /* Se JS è attivo, la classe .active comanda su tutto */
    .main-nav.js-active .nav-next-trigger, 
    .main-nav.js-active .nav-prev-trigger { /* Mostro questi SOLO su desktop e SOLO se il JS è attivo */
        display: flex !important; /* flex per allineare bene freccia e testo */
        align-items: center;
        justify-content: center;
        cursor: pointer;
        color: var(--accent-current);
        font-weight: 800;
        font-size: 0.7rem;
        padding: 4px 8px;
        border: 1px solid var(--border-current);
        border-radius: 4px;
        background: rgba(145, 195, 255, 0.1);
        text-transform: uppercase;
        white-space: nowrap;
    }

    /* pannelli su mobile tutti visibili se non c'è JS */
    .main-nav.no-js .nav-panel {
        display: block;
    }

    .main-nav.js-active .nav-panel {
        display: none;
    }
    .main-nav.js-active .nav-panel.active {
        display: flex;
        animation: panelFade 0.4s ease;
    }

    .nav-next-trigger:hover, .nav-prev-trigger:hover {
        background: var(--accent-current);
        color: #fff;
    }

    /* Nascondi bottoni se JS è spento */
    .main-nav.no-js .nav-next-trigger,
    .main-nav.no-js .nav-prev-trigger {
        display: none !important;
    }

    /* Sottomenu & Hover */
    .has-submenu { position: relative; }
    
    .submenu {
        display: none !important;
        position: absolute;
        top: 100%;
        left: 0;
        min-width: 240px;
        background: var(--card-bg);
        border: 1px solid var(--border-current);
        border-radius: 0 0 8px 8px;
        box-shadow: 0 8px 20px rgba(0,0,0,0.15);
        z-index: 9999;
        padding: 0.5rem 0;
        list-style: none;
    }

    /* Ponte per non perdere il focus */
    .has-submenu::after {
        content: "";
        position: absolute;
        top: 100%; width: 100%; height: 20px;
    }

    .has-submenu:hover > .submenu { display: block !important; }

    .submenu li a {
        padding: 0.8rem 1.5rem !important;
        text-transform: none;
        font-weight: 500;
        display: block;
        color: var(--text-current);
    }

    .submenu li a:hover {
        background: rgba(145, 195, 255, 0.15);
        color: var(--accent-current) !important;
    }

    .has-submenu > .menu-item-wrapper a::after {
        content: ' ▼';
        font-size: 0.6rem;
    }
}

@keyframes panelFade {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}