/* ==========================================================================
   STILE CHATBOT IDRAULICO H24
   ========================================================================== */

/* Contenitore Principale: z-index a 9999999 per stare sopra OGNI cosa (incluso il tuo header) */
#h24-chatbot-wrapper {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999999;
    font-family: 'Inter', sans-serif;
}

/* Finestra Chat */
#chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 360px;
    height: 550px;
    /* Evita che tocchi il tetto dello schermo calcolando l'altezza massima (100% dello schermo meno 120px di margine) */
    max-height: calc(100vh - 120px); 
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: bottom right;
}

/* Stato Nascosto */
#chatbot-window.chatbot-hidden {
    opacity: 0;
    transform: scale(0.1);
    pointer-events: none;
}

/* Pulsante Flottante (FAB) */
#chatbot-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #0284c7;
    color: white;
    border: none;
    box-shadow: 0 10px 25px rgba(2, 132, 199, 0.4);
    cursor: pointer;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
#chatbot-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 30px rgba(2, 132, 199, 0.5);
}

/* Header Chat (La barra blu in alto) */
.chatbot-header {
    background: #0284c7;
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0; /* Impedisce all'header di schiacciarsi */
}
.chatbot-header-info { display: flex; align-items: center; gap: 12px; }
.chatbot-header-info i { font-size: 24px; }
.chatbot-header-info h4 { margin: 0; font-size: 1.1rem; font-weight: 700; color: white;}
.chatbot-header-info span { font-size: 0.75rem; color: #bae6fd; font-weight: 600;}

#chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.8;
}
#chatbot-close:hover { opacity: 1; }

/* Area Messaggi */
.chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-msg { display: flex; max-width: 85%; }
.msg-bubble { padding: 12px 16px; border-radius: 16px; font-size: 0.95rem; line-height: 1.4; word-wrap: break-word; }
.msg-user { align-self: flex-end; flex-direction: row-reverse; }
.msg-user .msg-bubble { background: #0284c7; color: white; border-bottom-right-radius: 4px; }
.msg-bot { align-self: flex-start; }
.msg-bot .msg-bubble { background: #ffffff; color: #334155; border: 1px solid #e2e8f0; border-bottom-left-radius: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.02); }

/* Input Area */
.chatbot-input-area {
    display: flex;
    padding: 15px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}
#chatbot-input {
    flex: 1;
    border: none;
    padding: 10px 15px;
    background: #f1f5f9;
    border-radius: 20px;
    outline: none;
    font-size: 0.95rem;
    color: #334155;
}
#chatbot-send {
    background: #0284c7;
    color: white;
    border: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    margin-left: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Indicatore Scrittura (Typing) */
.typing-indicator { display: flex; gap: 4px; padding: 5px 10px; }
.typing-indicator span { width: 6px; height: 6px; background: #cbd5e1; border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* NASCONDI LA CHAT SU MOBILE (Sotto gli 800px come avevamo stabilito) */
@media (max-width: 800px) {
    #h24-chatbot-wrapper { display: none !important; }
}