/* FAB Style */
#chatbot-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: #6200ee;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    font-size: 24px;
    transition: all 0.3s ease;
}

#chatbot-fab:hover {
    background: #3700b3;
    transform: scale(1.05);
}

/* Greeting bubble */
#chatbot-greeting {
    position: fixed;
    bottom: 90px;
    right: 20px;
    background: white;
    padding: 10px 16px;
    border-radius: 18px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-width: 200px;
    font-family: "Roboto", sans-serif;
    font-size: 14px;
    z-index: 999;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#chatbot-greeting.visible {
    opacity: 1;
    transform: translateY(0);
}

#chatbot-greeting::after {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid white;
}

/* Chatbot Container */
#chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    height: 400px; /* Default height */
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-family: "Roboto", sans-serif;
    overflow: hidden;
    z-index: 999;
    transform: translateY(0);
    transition: width 0.3s ease, height 0.3s ease, transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* Modalità espansa */
#chatbot-container.expanded {
    width: 50%;
    height: 90vh;
    max-width: 800px; /* Aumenta anche il max-width se necessario */
    max-height: 800px;
}

#chatbot-header {
    background: #6200ee;
    color: white;
    padding: 8px 0px;
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* #chatbot-controls {
    display: flex;
    align-items: center;
} */

.chatbot-controls {
    cursor: pointer;
    padding: 6px 6px;
    border-radius: 50%;
    transition: background 0.2s;
    margin-left: 8px;
    margin-right: 8px;
}

.chatbot-controls:hover {
    background: rgba(255, 255, 255, 0.2);
}

#chatbot-messages {
    padding: 12px;
    flex-grow: 1; /* Takes available space */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 200px; /* Set minimum height for empty container */
}

.chatbot-message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    display: inline-block;
}

.user {
    background: #e8def8;
    align-self: flex-end;
    color: #21005d;
}

.bot {
    background: #d0e4ff;
    align-self: flex-start;
    color: #00214d;
}

/* Stili per il Markdown nella risposta del bot */
.bot p {
    margin: 0 0 8px 0;
}

.bot p:last-child {
    margin-bottom: 0;
}

.bot ul, .bot ol {
    margin: 8px 0;
    padding-left: 20px;
}

.bot code {
    background-color: rgba(0, 0, 0, 0.06);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
}

.bot pre {
    background-color: rgba(0, 0, 0, 0.06);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 8px 0;
}

.bot pre code {
    background-color: transparent;
    padding: 0;
}

.bot a {
    color: #0066cc;
    text-decoration: none;
}

.bot a:hover {
    text-decoration: underline;
}

.bot strong, .bot b {
    font-weight: bold;
}

.bot em, .bot i {
    font-style: italic;
}

/* Stili per il loader */
.loading {
    padding: 16px;
    min-width: 60px;
}

.loading-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.loading-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: #00214d;
    border-radius: 50%;
    animation: loading 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading {
    0%, 80%, 100% { 
        transform: scale(0);
    } 
    40% { 
        transform: scale(1.0);
    }
}

/* Messaggio di errore */
.bot.error {
    background-color: #ffebee;
    color: #c62828;
}

#chatbot-input-container {
    display: flex;
    align-items: flex-end; /* Allinea con il fondo per supportare la textarea dinamica */
    padding: 12px;
    border-top: 1px solid #ddd;
    background: white;
    flex-shrink: 0;
}

#chatbot-input {
    flex: 1;
    padding: 10px;
    border: none;
    outline: none;
    font-size: 14px;
    border-radius: 8px;
    background: #f3f3f3;
    margin-right: 8px;
    resize: none;
    min-height: 24px;
    max-height: 120px;
    overflow-y: hidden;
    transition: height 0.1s ease;
}

#chatbot-send {
    width: 40px;
    height: 40px;
    background: #6200ee;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    border: none;
    flex-shrink: 0;
}

#chatbot-send:hover {
    background: #3700b3;
}

#chatbot-branding {
    text-align: center;
    font-size: 12px;
    padding: 6px;
    color: #666;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
    width: 100%; /* Ensure it's full width */
    max-width: 100%; /* Limit width */
    box-sizing: border-box; /* Include padding in width */
}

#chatbot-branding a {
    color: #6200ee;
    text-decoration: none;
}

#chatbot-branding a:hover {
    text-decoration: underline;
}

/* Responsive per mobile */
@media (max-width: 768px) {
    #chatbot-container, #chatbot-container.expanded {
        width: 100%;
        height: 100%;
        max-height: 100%;
        right: 0;
        left: 0;
        bottom: 0;
        top: 0;
        border-radius: 0;
        max-width: none;
    }

    #chatbot-input-container {
        padding-bottom: calc(10px + env(safe-area-inset-bottom)); /* Add padding for safe area */
    }
    #chatbot-container.visible {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }
    
    #chatbot-fab {
        bottom: 10px;
        right: 10px;
    }

    /* Assicurati che l'header resti nella parte superiore e visibile */
    #chatbot-header {
        position: sticky;
        top: 0;
        z-index: 10;
    }

    #chatbot-expand span {
        display: none; /* Nascondi il pulsante su mobile */
    }

    /* Aggiusta il contenitore dei messaggi per dare più spazio */
    #chatbot-messages {
        flex: 1; /* Changed from fixed height to flex: 1 */
        overflow-y: auto;
        max-height: calc(100% - 120px); /* Added max-height calculation */
    }
    
    /* Rendi sicuro l'input container sul fondo */
    #chatbot-input-container {
        position: sticky;
        bottom: 0;
        background: white;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        z-index: 10;
    }
}

/* Rules for sizing the icon. */
.material-icons.md-18 { font-size: 18px; }
.material-icons.md-24 { font-size: 24px; }
.material-icons.md-36 { font-size: 36px; }
.material-icons.md-48 { font-size: 48px; }

/* Rules for using icons as black on a light background. */
.material-icons.md-dark { color: rgba(0, 0, 0, 0.54); }
.material-icons.md-dark.md-inactive { color: rgba(0, 0, 0, 0.26); }

/* Rules for using icons as white on a dark background. */
.material-icons.md-light { color: rgba(255, 255, 255, 1); }
.material-icons.md-light.md-inactive { color: rgba(255, 255, 255, 0.3); }
