/* Icona del chatbot */
#chatbot-icon {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: #3498db;
    color: white;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    border: 3px solid transparent;
    animation: glowRotate 3s infinite ease-in-out;
    transition: transform 0.3s ease;
}

#chatbot-icon.animate-robot {
    animation: glowRotate 3s infinite ease-in-out, robotDance 2s ease-in-out;
}

/* Tooltip di saluto */
.greeting-tooltip {
    position: fixed;
    bottom: 140px;
    right: 25px;
    background: linear-gradient(135deg, #667eea 0%, #5a67d8 50%, #4c51bf 100%);
    color: white;
    padding: 18px 24px;
    border-radius: 25px;
    box-shadow: 0 12px 30px rgba(102, 126, 234, 0.35), 0 0 0 3px rgba(255, 255, 255, 0.3);
    z-index: 999;
    max-width: 280px;
    border: 3px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    opacity: 0;
    transform: translateY(20px) scale(0.9);
    pointer-events: none;
    transition: opacity 0.4s ease-out, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.greeting-tooltip.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    animation: float 3s ease-in-out infinite, pulse 2s ease-in-out infinite;
}

.greeting-tooltip::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(76, 81, 191, 0.3));
    border-radius: 28px;
    z-index: -1;
    filter: blur(8px);
}

.greeting-tooltip::after {
    content: '';
    position: absolute;
    bottom: -18px;
    right: 40px;
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 18px solid #4c51bf;
    filter: drop-shadow(0 4px 8px rgba(76, 81, 191, 0.3));
}

.greeting-tooltip p {
    margin: 5px 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.5;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.waving-hand {
    font-size: 28px;
    display: inline-block;
    animation: wave 1s ease-in-out infinite, bounce 0.6s ease-in-out infinite alternate;
    margin-right: 8px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.close-greeting-btn {
    position: absolute;
    top: 10px;
    right: 12px;
    background: rgba(255, 255, 255, 0.25);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.85;
    transition: all 0.3s ease;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    font-weight: 600;
    font-family: Arial, sans-serif;
}

.close-greeting-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.4);
    transform: scale(1.15) rotate(90deg);
}

/* Indicatore "sta scrivendo" */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px !important;
    gap: 4px;
}

.typing-indicator .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #999;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    10%, 30% { transform: rotate(14deg); }
    20% { transform: rotate(-8deg); }
    40%, 60% { transform: rotate(14deg); }
    50% { transform: rotate(-8deg); }
    70% { transform: rotate(0deg); }
}

@keyframes slideInBounce {
    0% {
        transform: translateY(100px);
        opacity: 0;
    }
    60% {
        transform: translateY(-10px);
        opacity: 1;
    }
    80% {
        transform: translateY(5px);
    }
    100% {
        transform: translateY(0);
    }
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-12px);
    }
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 12px 30px rgba(102, 126, 234, 0.35), 0 0 0 3px rgba(255, 255, 255, 0.3);
    }
    50% {
        box-shadow: 0 12px 30px rgba(102, 126, 234, 0.5), 0 0 0 5px rgba(255, 255, 255, 0.5), 0 0 20px rgba(102, 126, 234, 0.3);
    }
}

@keyframes bounce {
    from {
        transform: translateY(0px);
    }
    to {
        transform: translateY(-3px);
    }
}

@keyframes glowRotate {
    0% {
        border-color: rgba(52, 152, 219, 0.2);
        box-shadow: 0 0 10px rgba(52, 152, 219, 0.4);
        transform: rotate(0deg);
    }
    30% {
        border-color: rgba(52, 152, 219, 0.8);
        box-shadow: 0 0 20px rgba(52, 152, 219, 0.6);
        transform: rotate(10deg);
    }
    60% {
        border-color: rgba(52, 152, 219, 0.5);
        box-shadow: 0 0 15px rgba(52, 152, 219, 0.5);
        transform: rotate(-5deg);
    }
    100% {
        border-color: rgba(52, 152, 219, 0.2);
        box-shadow: 0 0 10px rgba(52, 152, 219, 0.4);
        transform: rotate(0deg);
    }
}

@keyframes robotDance {
    0% {
        transform: scale(1) rotate(0deg);
    }
    10% {
        transform: scale(1.1) rotate(-10deg);
    }
    20% {
        transform: scale(1.1) rotate(10deg);
    }
    30% {
        transform: scale(0.95) rotate(-10deg);
    }
    40% {
        transform: scale(1.05) rotate(10deg);
    }
    50% {
        transform: scale(1.1) rotate(0deg) translateY(-10px);
    }
    60% {
        transform: scale(1) rotate(-5deg) translateY(0px);
    }
    70% {
        transform: scale(1.05) rotate(5deg);
    }
    80% {
        transform: scale(0.98) rotate(-3deg);
    }
    90% {
        transform: scale(1.02) rotate(3deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

/* Container del chatbot */
#chatbot-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 45%;
    max-height: 80%;
    overflow-x: hidden;
    overflow-y: auto;

    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    z-index: 1000;
    /* Aggiunta dello smooth scrolling per il body dei messaggi */
    scroll-behavior: smooth;
}

/* Animazione per la comparsa del container */
.slide-in {
    animation: slideUp 0.5s ease;
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Header del chatbot */
#chatbot-header {
    background-color: #3498db;
    color: white;
    padding: 10px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#chatbot-header h3 {
    margin: 0;
}
#chatbot-header button {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

/* Corpo del chatbot */
#chatbot-body {
    padding: 10px;
    flex-grow: 1;
    overflow-y: auto;
}
#chatbot-messages {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
    max-width: 800px;
    margin: 0 auto;
}

/* Suggerimenti con animazioni di fade-in e fade-out */
#chatbot-suggestions {
    margin-bottom: 10px;
    opacity: 1;
    transition: opacity 0.5s ease;
}
#chatbot-suggestions.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Stili dei pulsanti suggeriti */
.suggestion-btn {
    display: block;
    width: 100%;
    padding: 8px;
    margin-bottom: 5px;
    background-color: #f1f1f1;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    transition: background-color 0.3s;
}
.suggestion-btn:hover {
    background-color: #ddd;
}

/* Input e pulsante di invio */
#chatbot-input {
    display: flex;
    padding: 10px;
    border-top: 1px solid #ddd;
}
#chatbot-input-field {
    flex-grow: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-right: 10px;
}
#send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 45px;
}
#send-btn:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
    transform: translateY(-2px);
}
#send-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.4);
}
#send-btn i {
    font-size: 16px;
}

/* Stili per mobile */
@media (max-width: 768px) {
    #chatbot-container {
        width: 90%;
        right: 5%;
        bottom: 70px;
    }

    #chatbot-icon {
        width: 65px;
        height: 65px;
    }

    .greeting-tooltip {
        bottom: 103px;
        right: 13px;
        /* left: 10px; */
        max-width: calc(100% - 20px);
        padding: 16px 20px;
        font-size: 14px;
    }

    .greeting-tooltip::after {
        right: 25px;
        bottom: -15px;
        border-left: 12px solid transparent;
        border-right: 12px solid transparent;
        border-top: 15px solid #4c51bf;
    }

    .greeting-tooltip p {
        font-size: 14px;
    }

    .waving-hand {
        font-size: 24px;
    }
}

/* Stili dei messaggi con animazione di fade-in */
.message {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 88%;
    animation: fadeIn 0.3s ease-out;
    position: relative;
    line-height: 1.4;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Messaggio dell'utente (destra) */
.message.user-message {
    align-self: flex-end;
    background-color: #007bff; /* Blu */
    color: white;
    border-bottom-right-radius: 4px;
}

/* Messaggio del bot (sinistra) */
.message.bot-message {
    align-self: flex-start;
    background-color: #f0f0f0;
    color: #333;
    border-bottom-left-radius: 4px;
}

ul.external {    
    margin-top: 12px;
    display: grid;
    gap: 8px;
    font-size: 18px;
}

ul.external li a i {
    margin-right: 6px;
}

ul.external li a {
    color: black;
    text-decoration: none;
}