/* ========================================
   CHATBOT STUDIO TUCCILLO - STYLE
   ======================================== */

#chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99998;
    font-family: 'Inter', sans-serif;
}

/* Pulsante per aprire chat */
#chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00395d 0%, #55bcb5 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 57, 93, 0.4);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 57, 93, 0.6);
}

#chatbot-toggle.hidden {
    display: none;
}

.chatbot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    font-size: 12px;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

/* Finestra chat */
#chatbot-window {
    display: none;
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    height: 580px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    flex-direction: column;
    animation: chatSlideUp 0.3s ease;
}

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

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

/* Header chat */
.chatbot-header {
    background: linear-gradient(135deg, #00395d 0%, #55bcb5 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    background: white;
    color: #55bcb5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-title {
    font-weight: 700;
    font-size: 1rem;
}

.chatbot-status {
    font-size: 0.8rem;
    opacity: 0.9;
}

#chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.3s;
}

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

/* Area messaggi */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: msgFadeIn 0.3s ease;
}

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

.bot-msg {
    align-self: flex-start;
}

.user-msg {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #00395d 0%, #55bcb5 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.msg-content {
    background: white;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #00395d;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.user-msg .msg-content {
    background: linear-gradient(135deg, #00395d 0%, #55bcb5 100%);
    color: white;
}

.msg-content a {
    color: #00395d;
    text-decoration: underline;
    font-weight: 600;
}

.user-msg .msg-content a {
    color: white;
}

/* Typing indicator */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 10px 14px !important;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #00395d;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

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

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

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

/* Suggerimenti */
.chatbot-suggestions {
    padding: 8px 16px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    background: white;
    border-top: 1px solid #f0f0f0;
}

.suggestion-btn {
    background: #f0f9ff;
    color: #55bcb5;
    border: 1px solid #b3e5fc;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.suggestion-btn:hover {
    background: #00395d;
    color: white;
    border-color: #00395d;
}

/* Input area */
.chatbot-input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #f0f0f0;
    gap: 8px;
}

#chatbot-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    padding: 10px 14px;
    border-radius: 24px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s;
    font-family: 'Inter', sans-serif;
}

#chatbot-input:focus {
    border-color: #00395d;
}

#chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #00395d 0%, #55bcb5 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
}

#chatbot-send:hover {
    transform: scale(1.1);
}

/* Footer */
.chatbot-footer {
    padding: 8px 16px;
    background: #f8f9fa;
    font-size: 0.7rem;
    color: #999;
    text-align: center;
    border-top: 1px solid #f0f0f0;
}

/* Mobile */
@media (max-width: 480px) {
    #chatbot-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        bottom: 80px;
        right: 10px;
    }
    
    #chatbot-widget {
        bottom: 15px;
        right: 15px;
    }
}

/* Scrollbar custom */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 3px;
}

/* Accessibilità chatbot */
#chatbot-toggle:focus {
    outline: 3px solid #00395d;
    outline-offset: 3px;
    box-shadow: 0 0 0 5px rgba(0, 57, 93, 0.2);
}

.chatbot-suggestions button:focus,
#chatbot-send:focus,
#chatbot-close:focus,
#chatbot-input:focus {
    outline: 3px solid #00395d;
    outline-offset: 2px;
}

/* ========================================
   CHATBOT MOBILE - Schermo intero + 
   Accessibilità preservata
   SOLO QUANDO ATTIVO (.active)
   ======================================== */

@media (max-width: 768px) {
    
    /* Finestra chat a schermo intero - SOLO quando .active */
    #chatbot-window.active {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important; /* dvh per gestire bene la barra browser mobile */
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 99999 !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Header del chatbot fisso in alto - solo quando attivo */
    #chatbot-window.active .chatbot-header {
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    /* Area messaggi: prende tutto lo spazio disponibile - solo quando attivo */
    #chatbot-window.active .chatbot-messages {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch; /* Scroll fluido iOS */
        padding: 1rem !important;
        scroll-behavior: smooth;
    }
    
    /* Input area fissa in basso - solo quando attivo */
    #chatbot-window.active .chatbot-input-area {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        background: white;
        z-index: 10;
        padding: 0.75rem 1rem !important;
        border-top: 1px solid #e0e0e0;
    }
    
    /* Suggerimenti rapidi compatti - solo quando attivo */
    #chatbot-window.active .chatbot-suggestions {
        flex-shrink: 0;
        padding: 0.5rem 1rem !important;
    }
    
    /* Disabilita scroll body quando chat aperta */
    body.chatbot-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* ========================================
   ACCESSIBILITÀ - Focus chat su mobile
   ======================================== */

#chatbot-window:focus-within {
    outline: none; /* L'outline è sui singoli elementi */
}

/* Migliora il bottone di chiusura per accessibilità */
#chatbot-close {
    min-width: 44px; /* WCAG: tap target minimo 44x44px */
    min-height: 44px;
}