:root {
    --primary-color: #003366; /* Blu istituzionale */
    --accent-color: #0f9d58;  /* Verde */
    --bg-color: #f4f7f6;
    --chat-bg: #ffffff;
    --user-msg: #005b96;
    --ai-msg: #f1f3f5;
    --text-main: #333333;
    --text-light: #ffffff;

    /* Variabili aggiuntive per la Sidebar */
    --sidebar-bg: #1e293b;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(255, 255, 255, 0.15);
    --border-color: #eeeeee;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--bg-color);
    height: 100vh;
    overflow: hidden;
}

/* ==========================================
   CONTAINER GENERALE (Layout a 2 Colonne)
   ========================================== */
.chat-app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    background-color: var(--chat-bg);
}

/* ==========================================
   BARRA LATERALE (Cronologia e Controlli)
   ========================================== */
.chat-sidebar {
    width: 300px;
    min-width: 300px;
    background-color: var(--sidebar-bg);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    padding: 20px;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    margin-bottom: 20px;
    text-align: center;
}

.sidebar-logo {
    display: block;
    margin: 0 auto;
}

/* Bottone Nuova Chat */
.btn-new-chat {
    background-color: var(--accent-color);
    color: var(--text-light);
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 25px;
}

.btn-new-chat:hover {
    background-color: #0c854a;
}

.btn-new-chat:active {
    transform: scale(0.98);
}

/* Lista Cronologia */
.chat-history-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 20px;
}

.chat-history-list h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    color: #94a3b8;
    font-weight: 700;
}

#session-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-item {
    padding: 12px;
    background-color: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.session-item:hover {
    background-color: var(--sidebar-hover);
}

.session-item.active {
    background-color: var(--sidebar-active);
    border-color: rgba(255, 255, 255, 0.2);
    font-weight: 600;
}

/* Footer Sidebar & Bottone Logout */
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 15px;
}

.btn-logout {
    background-color: transparent;
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 8px;
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-logout:hover {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* ==========================================
   AREA PRINCIPALE DELLA CHAT
   ========================================== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-bg);
}

/* 🚀 Header della Chat Activa (Modificato per allineare l'hamburger) */
.chat-header {
    background-color: var(--primary-color);
    color: var(--text-light);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: center; /* Centra il testo di default su PC */
    position: relative;
}

.chat-header p {
    font-size: 0.95rem;
    font-weight: 500;
    opacity: 0.9;
    margin: 0;
}

/* Box dei messaggi */
.chat-box {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scroll-behavior: smooth;
    background-color: #f8fafc;
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.98rem;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message.user {
    background-color: var(--user-msg);
    color: var(--text-light);
    align-self: flex-end;
    border-bottom-right-radius: 0;
}

.message.ai {
    background-color: var(--chat-bg);
    color: var(--text-main);
    align-self: flex-start;
    border-bottom-left-radius: 0;
    border: 1px solid #e2e8f0;
}

/* Indicatore di digitazione */
.typing-indicator {
    align-self: flex-start;
    background-color: var(--chat-bg);
    padding: 12px 16px;
    border-radius: 12px;
    border-bottom-left-radius: 0;
    color: #64748b;
    font-style: italic;
    font-size: 0.9rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.hidden {
    display: none !important;
}

/* Area di Input in fondo */
.input-area {
    display: flex;
    padding: 15px 24px;
    background-color: var(--chat-bg);
    border-top: 1px solid var(--border-color);
    gap: 12px;
    align-items: center;
}

.input-area input {
    flex: 1;
    padding: 14px 20px;
    border: 1px solid #cbd5e1;
    border-radius: 24px;
    font-size: 0.98rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-area input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.1);
}

.input-area button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.input-area button:hover {
    background-color: #002244;
}

.input-area button:active {
    transform: scale(0.95);
}

.input-area button svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* --- CHAT DISCLAIMER --- */
.chat-disclaimer {
    font-size: 0.75rem;
    color: #64748b;
    text-align: center;
    padding: 8px 24px 12px 24px;
    background-color: var(--chat-bg);
    border-top: none;
    line-height: 1.4;
}

.chat-disclaimer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.chat-disclaimer a:hover {
    text-decoration: underline;
}

/* --- WIDGET STATO UTENTE NELLA SIDEBAR --- */
.user-status-card {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 15px;
    font-size: 0.85rem;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    color: #cbd5e1;
}

.badge-tier {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-tier.free { background-color: #64748b; color: white; }
.badge-tier.pro { background-color: #f59e0b; color: #1e293b; }

.status-value { font-weight: 600; color: white; }

.btn-upgrade {
    width: 100%;
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.2s;
    margin-top: 4px;
}

.btn-upgrade:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* --- TELECOMANDO FINESTRA MODALE (POP-UP) --- */
.modal {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: white;
    padding: 35px;
    border-radius: 16px;
    width: 90%;
    max-width: 900px;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
    text-align: center;
    /* 🚀 GESTIONE DELLO SCROLL (Risolve il taglio in basso) */
    max-height: 90vh; /* Altezza massima: 90% dello schermo */
    overflow-y: auto; /* Se le carte sono troppo alte, compare la barra di scorrimento! */
}

.close-modal {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    color: #94a3b8;
    cursor: pointer;
}

.close-modal:hover { color: #334155; }

.modal-content h3 { font-size: 1.6rem; color: #0f172a; margin-bottom: 5px; }
.modal-subtitle { color: #64748b; font-size: 0.95rem; margin-bottom: 30px; }

/* Griglia dei Prezzi */
.pricing-grid {
    display: flex;
    gap: 20px;
    justify-content: center;
    align-items: stretch;
}

.pricing-card {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 25px 20px;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: white;
}

.pricing-card h4 { font-size: 1.1rem; color: #334155; margin-bottom: 15px; }

.price { font-size: 1.8rem; font-weight: 700; color: #0f172a; margin-bottom: 20px; }
.price span { font-size: 0.85rem; color: #64748b; font-weight: 400; }

.features { list-style: none; padding: 0; margin-bottom: 30px; text-align: left; flex: 1; }
.features li { font-size: 0.88rem; color: #475569; margin-bottom: 10px; position: relative; padding-left: 20px; }
.features li::before { content: "✓"; position: absolute; left: 0; color: #0f9d58; font-weight: bold; }

/* Bottoni Acquista */
.btn-price-action {
    background-color: #0f172a;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    width: 100%;
}
.btn-price-action:hover { background-color: var(--primary-color); }

.btn-price-disabled {
    background-color: #f1f3f5;
    color: #94a3b8;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
    width: 100%;
}

.pricing-card.premium {
    border: 2px solid var(--primary-color);
    box-shadow: 0 10px 15px -3px rgba(0, 51, 102, 0.1);
}
.pricing-card.premium .btn-price-action { background-color: var(--primary-color); }
.pricing-card.premium .btn-price-action:hover { background-color: #002244; }

.card-ribbon {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--primary-color);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}

/* ==========================================
   📱 STILI RESPONSIVE PER LA SIDEBAR MOBILE E HEADER
   ========================================== */

/* Il bottone Hamburger invisibile su PC */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #ffffff;
    position: absolute;
    left: 20px;
}

/* L'overlay scuro invisibile di default */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 998;
    backdrop-filter: blur(2px);
}

/* 🚀 REGOLE SOLO PER GLI SCHERMI PICCOLI (SMARTPHONE/TABLET) */
@media (max-width: 768px) {
    .hamburger-btn {
        display: block; /* Mostra il bottone hamburger */
    }

    .chat-header {
        justify-content: center; /* Su mobile il testo sta al centro, il bottone a sinistra */
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -100%; /* Nascosta fuori dallo schermo a sinistra */
        height: 100vh;
        z-index: 999;
        transition: left 0.3s ease-in-out;
        box-shadow: 4px 0 15px rgba(0,0,0,0.2);
        display: flex !important; /* Forza il flex per ignorare vecchie regole di display:none */
    }

    /* Quando il JS aggiunge questa classe, la sidebar scorre dentro */
    .sidebar.open {
        left: 0;
    }

    /* Mostra il fondale scuro quando attiva */
    .sidebar-overlay.active {
        display: block;
    }

    /* Le carte prezzo diventano a singola colonna sul telefono */
    .pricing-grid {
        flex-direction: column;
    }
    
    /* 🚀 Ottimizzazioni Modale per Smartphone */
    .modal-content {
        padding: 25px 15px; /* Riduciamo i mega-margini laterali su mobile */
        width: 95%; /* Sfruttiamo tutto lo schermo */
        border-radius: 12px;
    }

    .modal-content h3 {
        font-size: 1.3rem; /* Titolo leggermente più piccolo */
    }

    .pricing-card {
        padding: 20px 15px; /* Riduciamo l'imbottitura dentro le carte */
    }

    .price {
        font-size: 1.5rem; /* Prezzo proporzionato al mobile */
    }
}