#ticino-ai-chatbot-container, 
#ticino-ai-chatbot-container * {
    box-sizing: border-box;
}

#ticino-ai-chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 100vw;
}

/* OVERLAY MOBILE OPZIONALE */
#ticino-ai-chatbot-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.25);
    z-index: 999998;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.ticino-ai-chatbot-open #ticino-ai-chatbot-overlay {
    display: block;
    opacity: 1;
}

#ticino-ai-chatbot-trigger {
    position: relative;
    z-index: 999999;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--ticino-ai-main, #1a1a1a);
    color: #fff;
    border: 2px solid var(--ticino-ai-accent, #cebdad);
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2), 0 0 15px rgba(206, 189, 173, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    animation: ticinoPulse 3s infinite ease-in-out;
}

@keyframes ticinoPulse {
    0%, 100% {
        box-shadow: 0 8px 24px rgba(0,0,0,0.2), 0 0 0 0 rgba(206, 189, 173, 0.4);
    }
    50% {
        box-shadow: 0 8px 24px rgba(0,0,0,0.25), 0 0 0 10px rgba(206, 189, 173, 0);
    }
}

#ticino-ai-chatbot-trigger:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 28px rgba(0,0,0,0.3), 0 0 20px rgba(206, 189, 173, 0.5);
}

#ticino-ai-chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 100px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    border: 1px solid rgba(255,255,255,0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform-origin: bottom right;
    z-index: 999999;
}

.ticino-ai-chatbot-open #ticino-ai-chatbot-window {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.ticino-ai-chatbot-header {
    background: var(--ticino-ai-main, #1a1a1a);
    color: #fff;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 0 0 auto;
}

.ticino-ai-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden; /* per text-overflow */
}

.ticino-ai-bot-avatar {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    background: var(--ticino-ai-accent, #cebdad);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ticino-ai-main, #1a1a1a);
}

.ticino-ai-header-text {
    overflow: hidden;
    white-space: nowrap;
}

.ticino-ai-header-info strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
    text-overflow: ellipsis;
    overflow: hidden;
}

.ticino-ai-status {
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    display: flex;
    align-items: center;
    gap: 5px;
}
.ticino-ai-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
}

#ticino-ai-chatbot-minimize {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.7;
    padding: 8px;
}
#ticino-ai-chatbot-minimize:hover {
    opacity: 1;
}

#ticino-ai-chatbot-messages {
    flex: 1 1 auto;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 15px;
    line-height: 1.5;
}

.ticino-ai-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    min-width: 0;
    word-break: normal;
    overflow-wrap: break-word;
    animation: ticinoFadeInUp 0.3s ease forwards;
}

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

.ticino-ai-msg-bot {
    background: #f1f3f5;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.ticino-ai-msg-user {
    background: var(--ticino-ai-accent, #cebdad);
    color: #1a1a1a;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* QUICK REPLIES */
#ticino-ai-chatbot-quick-replies {
    padding: 6px 16px 16px 16px;
    display: flex;
    flex: 0 0 auto;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap; /* Sempre su una riga con scroll */
}

/* Nascondi la scrollbar orizzontale per estetica */
#ticino-ai-chatbot-quick-replies::-webkit-scrollbar {
    display: none;
}
#ticino-ai-chatbot-quick-replies {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.ticino-ai-qr {
    flex: 0 0 auto;
    background: transparent;
    border: 1px solid var(--ticino-ai-accent, #cebdad);
    color: var(--ticino-ai-main, #1a1a1a);
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 14px;
    line-height: 1.4;
    height: auto;
    min-height: 38px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: max-content;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ticino-ai-qr:hover {
    background: var(--ticino-ai-accent, #cebdad);
}

/* INPUT */
.ticino-ai-chatbot-input {
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    align-items: center;
    flex: 0 0 auto;
}

#ticino-ai-user-input {
    flex: 1;
    min-width: 0; /* previene rottura flex */
    border: 1px solid #ddd;
    border-radius: 999px;
    padding: 0 16px;
    height: 48px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}
#ticino-ai-user-input:focus {
    border-color: var(--ticino-ai-accent, #cebdad);
}

#ticino-ai-send-btn {
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    background: var(--ticino-ai-main, #1a1a1a);
    color: #fff;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.3s;
    padding: 0;
}
#ticino-ai-send-btn:hover {
    background: var(--ticino-ai-accent, #cebdad);
}
#ticino-ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Form Guidato Prenotazione */
#ticino-ai-booking-form {
    position: absolute;
    top: 72px; /* Sotto l'header */
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.ticino-ai-booking-header {
    padding: 15px 20px;
    font-weight: 600;
    border-bottom: 1px solid #eee;
    background: #f9f9f9;
}

.ticino-ai-booking-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ticino-ai-booking-body input,
.ticino-ai-booking-body select,
.ticino-ai-booking-body textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: inherit;
    font-size: 15px;
}

.ticino-ai-privacy {
    font-size: 12px;
    color: #666;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.ticino-ai-privacy input {
    width: auto;
    margin-top: 2px;
}

#ticino-ai-submit-booking {
    background: var(--ticino-ai-main, #1a1a1a);
    color: #fff;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}

#ticino-ai-cancel-booking {
    background: transparent;
    border: 1px solid #ddd;
    color: #666;
    padding: 14px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
}

/* Typing Indicator */
.ticino-ai-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #f1f3f5;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    align-self: flex-start;
}
.ticino-ai-typing span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: ticinoTyping 1.4s infinite ease-in-out both;
}
.ticino-ai-typing span:nth-child(1) { animation-delay: -0.32s; }
.ticino-ai-typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes ticinoTyping {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}


/* ==================================================
   RESPONSIVE MOBILE
================================================== */

@media (max-width: 768px) {
    /* 1. Chat aperta quasi full-screen, centrata/staccata dai bordi */
    #ticino-ai-chatbot-window {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 12px;
        top: auto;
        width: calc(100vw - 24px);
        max-width: none;
        height: min(78vh, 680px); /* Usa vh base, se supportato sotto aggiorneremo a dvh */
        max-height: calc(100vh - 32px);
        border-radius: 24px;
        transform-origin: bottom center;
        /* Rimuovo override scale per usare la stessa logica desktop */
    }

    #ticino-ai-chatbot-trigger {
        bottom: 18px;
        right: 18px;
    }

    .ticino-ai-chatbot-header {
        height: 72px; /* Header un po' più grande per touch */
        padding: 0 16px;
    }
}

/* Supporto per dvh se disponibile (previene problemi barra URL mobile) */
@supports (height: 100dvh) {
    @media (max-width: 768px) {
        #ticino-ai-chatbot-window {
            height: min(78dvh, 680px);
            max-height: calc(100dvh - 32px);
        }
    }
}

@media (max-width: 480px) {
    /* 2. Variante mobile bottom sheet premium */
    #ticino-ai-chatbot-window {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        border-radius: 24px 24px 0 0;
        height: 85vh;
        max-height: 85vh;
        border: none;
        border-bottom: 0;
    }
    
    @supports (height: 100dvh) {
        #ticino-ai-chatbot-window {
            height: 85dvh;
            max-height: 85dvh;
        }
    }
}

@media (max-width: 380px) {
    /* Layout per schermi molto piccoli (bottoni rapidi in colonna se necessario) */
    #ticino-ai-chatbot-quick-replies {
        flex-direction: column;
        overflow-x: visible;
        padding-bottom: 12px;
    }
    .ticino-ai-qr {
        width: 100%;
        text-align: center;
        white-space: normal;
    }
}

/* Gestione accessibilità animazioni ridotte */
@media (prefers-reduced-motion: reduce) {
    #ticino-ai-chatbot-window {
        transition: none;
        transform: none !important;
    }
    .ticino-ai-chatbot-open #ticino-ai-chatbot-window {
        transform: none !important;
    }
    #ticino-ai-chatbot-trigger {
        transition: none;
    }
    .ticino-ai-msg {
        animation: none;
    }
}
