/* ==========================================================================
   CSS GENERALE (Valido per Desktop e Mobile in stato minimizzato)
   ========================================================================== */

#my-gpt-chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 330px;
    height: 450px; /* Altezza fissa su Desktop */
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    display: flex;
    flex-direction: column; /* Layout verticale: Header -> Messaggi -> Input */
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 999999; /* Per stare sopra tutto */
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Importante per il posizionamento dei figli */
    justify-content: space-between; 
}

/* --- STATO MINIMIZZATO (Desktop e Mobile) --- */
#my-gpt-chatbot-container.minimized {
    height: 50px !important;
    width: 180px; /* Abbastanza largo per "GiGAI" e il tasto + */
    transform: translateY(0);
    cursor: pointer;
}

#my-gpt-chatbot-container.minimized #chat-content-wrapper {
    display: none;
}

#my-gpt-chatbot-container.minimized .chat-header {
    border-radius: 12px; /* Arrotonda tutto quando è chiuso */
}

/* --- HEADER --- */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background-color: #007bff; /* Blu come nello screenshot */
    color: white;
    cursor: pointer;
    user-select: none;
    border-radius: 12px 12px 0 0; /* Arrotonda solo sopra quando aperto */
    flex-shrink: 0; /* Impedisce all'header di rimpicciolirsi */
}

.chat-header span {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#minimize-chat {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    padding: 0;
}

/* --- CONTENUTO (Wrapper per Messaggi + Input) --- */
#chat-content-wrapper {
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Occupa tutto lo spazio rimanente sotto l'header */
    overflow: hidden;
    justify-content: space-between; /* Spinge l'input in fondo */
}

/* --- AREA MESSAGGI --- */
.chat-container {
    flex-grow: 1; /* Prende tutto lo spazio possibile, spingendo l'input giù */
    overflow-y: auto; /* Scrollbar solo qui */
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 15px;
    background-color: #f7f9fb;
}

/* Scrollbar stilizzata */
.chat-container::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-thumb { background-color: #ccc; border-radius: 10px; }

.bot-message, .user-message {
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.bot-message {
    align-self: flex-start;
    background-color: #ffffff;
    color: #333;
    border: 1px solid #edeef0;
    border-radius: 15px 15px 15px 2px;
}

.user-message {
    align-self: flex-end;
    background-color: #007bff;
    color: white;
    border-radius: 15px 15px 2px 15px;
}

/* --- AREA INPUT (La parte che dava problemi) --- */
.input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background-color: #ffffff;
    border-top: 1px solid #eee;
    flex-shrink: 0; /* Impedisce che questa area si comprima */
}

.chat-input {
    flex-grow: 1;
    border: 1px solid #e0e0e0;
    padding: 10px 14px;
    border-radius: 25px;
    font-size: 16px; /* 16px evita lo zoom automatico su iOS */
    outline: none;
    background: #fcfcfc;
}

.send-btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* ==========================================================================
   FIX SPECIFICO PER MOBILE (Smartphone)
   ========================================================================== */

@media screen and (max-width: 767px) {
    
    /* Quando la chat è APERTA su mobile, occupa TUTTO lo schermo */
    #my-gpt-chatbot-container:not(.minimized) {
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important; /* Forza altezza intera */
        border-radius: 0 !important; /* Rimuove angoli arrotondati */
        margin: 0 !important;
        padding: 0 !important;
        
        /* Fix per iOS e barre dei browser: usa l'altezza visibile */
        height: 100vh !important; 
        height: -webkit-fill-available !important; 
    }

    /* Header piatto su mobile aperto */
    #my-gpt-chatbot-container:not(.minimized) .chat-header {
        border-radius: 0;
        padding: 15px; /* Leggermente più grande per le dita */
    }

    /* Assicura che il wrapper occupi tutto lo spazio sotto l'header */
    #my-gpt-chatbot-container:not(.minimized) #chat-content-wrapper {
        height: calc(100% - 50px); /* 100% meno l'altezza dell'header */
    }

    /* Input container tassativamente ancorato al fondo */
    #my-gpt-chatbot-container:not(.minimized) .input-container {
        position: safe; /* Rispetta le aree sicure dei notch */
        margin-top: auto; /* Spinta flex finale */
        border-bottom: none;
    }
}