/* Chatbot Widget Styles */

#chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: system-ui, -apple-system, sans-serif;
}

#chatbot-button {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1F6FEB, #0E7A5F);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(31, 111, 235, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.3s ease;
    animation: pulse-button 2s infinite;
}

#chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(31, 111, 235, 0.6);
}

@keyframes pulse-button {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(31, 111, 235, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(31, 111, 235, 0.7);
    }
}

#chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
    z-index: 9998;
}

#chatbot-window.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#chatbot-header {
    background: linear-gradient(135deg, #1F6FEB, #0E7A5F);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chatbot-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

#chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

#chatbot-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

#chatbot-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #F8FAFC;
}

.chatbot-message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message-bot {
    align-items: flex-start;
}

.chatbot-message-user {
    align-items: flex-end;
}

.chatbot-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 14px;
}

.chatbot-message-bot .chatbot-message-content {
    background: white;
    color: #111827;
    border: 1px solid #E5E7EB;
    border-bottom-left-radius: 4px;
}

.chatbot-message-user .chatbot-message-content {
    background: linear-gradient(135deg, #1F6FEB, #0E7A5F);
    color: white;
    border-bottom-right-radius: 4px;
}

.chatbot-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #6B7280;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-6px);
    }
}

#chatbot-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #E5E7EB;
    display: flex;
    gap: 8px;
}

#chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #E5E7EB;
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#chatbot-input:focus {
    border-color: #1F6FEB;
}

/* Prevent iOS Safari auto-zoom on input focus (requires min 16px) */
@media (max-width: 480px) {
    #chatbot-input {
        font-size: 16px;
    }
}

#chatbot-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1F6FEB, #0E7A5F);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
}

#chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(31, 111, 235, 0.4);
}

#chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-cta-link {
    color: #1F6FEB;
    text-decoration: underline;
    font-weight: 500;
}

.chatbot-cta-link:hover {
    color: #0E7A5F;
}

/* Mobile responsive */
@media (max-width: 480px) {
    #chatbot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height - si adatta quando la tastiera si apre */
        border-radius: 0;
        transition: height 0.2s ease;
    }
    
    #chatbot-button {
        bottom: 20px;
        right: 20px;
    }
    
    #chatbot-header {
        padding: 16px 20px;
        padding-top: max(16px, env(safe-area-inset-top));
    }
    
    #chatbot-close {
        width: 40px;
        height: 40px;
        font-size: 32px;
        font-weight: bold;
    }
    
    #chatbot-messages {
        padding: 16px;
        padding-bottom: 20px;
    }
    
    #chatbot-input-area {
        padding: 16px 20px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* Prevent body scroll when chat is open on mobile (without position:fixed) */
@media (max-width: 480px) {
    body.chatbot-open {
        overflow: hidden;
        touch-action: none;
    }
}
