#ai-chat-launcher {
    position: fixed;
    border-radius: 50% !important;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.3s ease;
    overflow: visible !important;
    box-sizing: border-box !important;
}

#ai-chat-launcher:hover {
    transform: scale(1.08);
}

.ai-launcher-img {
    width: 100% !important;
    height: 100% !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    aspect-ratio: 1 / 1 !important;
    display: block !important;
}

.ai-launcher-badge {
    font-size: 28px;
}

/* PALLINO STATO ONLINE INTERMITTENTE RIGIDO ANTI-SCHIACCIAMENTO */
.ai-online-pulse-dot {
    position: absolute !important;
    bottom: 2px !important;
    right: 2px !important;
    width: 12px !important;
    height: 12px !important;
    min-width: 12px !important;
    min-height: 12px !important;
    border-radius: 50% !important;
    border: 2px solid #ffffff !important;
    animation: aiPulseDot 2s infinite ease-in-out;
    z-index: 99 !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
}

.ai-avatar-wrapper {
    position: relative !important;
    display: inline-block !important;
    flex-shrink: 0 !important;
}

.ai-avatar-wrapper .ai-online-pulse-dot {
    bottom: 0px !important;
    right: 0px !important;
    width: 10px !important;
    height: 10px !important;
    min-width: 10px !important;
    min-height: 10px !important;
}

.ai-header-text {
    display: flex;
    flex-direction: column;
}

.ai-status-sub {
    font-size: 10px;
    opacity: 0.85;
    font-weight: normal;
}

@keyframes aiPulseDot {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(37, 211, 102, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}

/* PANNELLO ANIMAZIONI DINAMICHE PER LAUNCHER */
.ai-anim-bounce {
    animation: aiBounce 2s infinite;
}

.ai-anim-pulse {
    animation: aiPulse 2s infinite;
}

.ai-anim-wiggle {
    animation: aiWiggle 2.5s infinite;
}

.ai-anim-glow {
    animation: aiGlow 2s infinite;
}

.ai-anim-float {
    animation: aiFloat 3.5s infinite ease-in-out;
}

.ai-anim-fadein {
    animation: aiFadeIn 0.8s ease-out;
}

@keyframes aiBounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-12px); }
    60% { transform: translateY(-6px); }
}

@keyframes aiPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

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

@keyframes aiGlow {
    0% { box-shadow: 0 0 0 0 rgba(0, 124, 186, 0.6); }
    70% { box-shadow: 0 0 0 16px rgba(0, 124, 186, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 124, 186, 0); }
}

@keyframes aiFloat {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(2deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}

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

/* TOOLTIP BUBBLE */
.ai-tooltip-bubble {
    position: fixed;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 3px 10px rgba(0,0,0,0.18);
    z-index: 9998;
    white-space: nowrap;
}

/* FINESTRA CHAT CON LAYOUT VERTICALE FISSO */
#ai-chat-window {
    position: fixed;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
}

/* CONGELAMENTO VIEWPORT MOBILE ISOLATO SOLO CON TASTIERA IN FOCUS */
html.ai-mobile-locked, body.ai-mobile-locked {
    overflow: hidden !important;
}

/* RESPONSIVENESS MOBILI (<600px) CON IOS VISUAL VIEWPORT & STICKY FOOTER */
@media screen and (max-width: 600px) {
    #ai-chat-window {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        width: 100vw !important;
        height: 100vh;
        height: 100dvh;
        border-radius: 0 !important;
    }

    #ai-chat-footer {
        position: sticky !important;
        bottom: 0 !important;
        background: #ffffff !important;
        z-index: 100;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #ai-chat-input {
        font-size: 16px !important;
        touch-action: manipulation !important;
    }

    #ai-chat-body, #ai-faq-directory-view, #ai-faq-single-view {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}

.ai-chat-hidden {
    display: none !important;
}

#ai-chat-main-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

#ai-chat-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    flex-shrink: 0;
}

.ai-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-header-avatar {
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    aspect-ratio: 1 / 1 !important;
    display: block !important;
    flex-shrink: 0 !important;
}

#ai-chat-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
}

#ai-faq-bar {
    padding: 6px 12px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
    text-align: center;
}

#ai-toggle-faqs-btn {
    background: #ffffff;
    border: 1px solid #007cba;
    color: #007cba;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s ease;
}

#ai-toggle-faqs-btn:hover {
    background: #007cba;
    color: #ffffff;
}

/* INDICE FAQ DIRETTORIO NAVIGABILE */
#ai-faq-directory-view, #ai-faq-single-view {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #fdfdfd;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.faq-dir-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 8px;
}

.faq-dir-header h4 {
    margin: 0;
    font-size: 13px;
    color: #333;
}

.ai-btn-sub {
    background: #eef7ff;
    border: 1px solid #007cba;
    color: #007cba;
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
}

#ai-faq-list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 5px;
}

.ai-faq-item-card {
    background: #ffffff;
    border: 1px solid #dcdcdc;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    transition: background 0.2s ease;
}

.ai-faq-item-card:hover {
    background: #f0f7ff;
    border-color: #007cba;
}

#ai-faq-single-content h4 {
    margin: 0 0 10px 0;
    color: #007cba;
    font-size: 14px;
}

/* SESSION RECOVERY BAR */
#ai-session-recovery-bar {
    background: #eef7ff;
    border-bottom: 1px solid #b6d4fe;
    padding: 10px 12px;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.recovery-btn-group {
    display: flex;
    gap: 8px;
}

#ai-resume-session-btn, #ai-new-session-btn {
    border: none;
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
}

#ai-resume-session-btn {
    background: #007cba;
    color: #ffffff;
}

#ai-new-session-btn {
    background: #e0e0e0;
    color: #333333;
}

/* CORPO CHAT CON SCROLLBAR INTERNA GARANTITA */
#ai-chat-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #fdfdfd;
}

.chat-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    max-width: 90%;
    width: 100%;
}

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

.chat-msg-row.user {
    align-self: flex-end;
    justify-content: flex-end;
}

.msg-avatar {
    width: 30px !important;
    height: 30px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    aspect-ratio: 1 / 1 !important;
    flex-shrink: 0 !important;
}

.msg-avatar-placeholder {
    width: 30px !important;
    height: 30px !important;
    border-radius: 50% !important;
    background: #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0 !important;
}

.msg-avatar-placeholder.user-avatar {
    background: #007cba;
    color: #ffffff;
}

.msg-content-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.chat-msg-row.user .msg-content-wrapper {
    align-items: flex-end;
}

.chat-msg-row.bot .msg-content-wrapper {
    align-items: flex-start;
}

.chat-msg {
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-msg p {
    margin: 0 0 8px 0 !important;
    padding: 0 !important;
    line-height: 1.5 !important;
}

.chat-msg p:last-child {
    margin-bottom: 0 !important;
}

.chat-msg ul, .chat-msg ol {
    margin: 6px 0 8px 18px !important;
    padding: 0 !important;
}

.chat-msg li {
    margin-bottom: 4px !important;
}

.chat-msg img {
    max-width: 100% !important;
    height: auto !important;
    border-radius: 6px;
    margin: 6px 0;
    display: block;
}

.mem-cover-img {
    width: 100% !important;
    max-height: 180px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 8px !important;
}

.chat-msg.bot {
    background: #f1f3f5;
    color: #212529;
    border-bottom-left-radius: 2px;
}

.chat-msg.user {
    background: #007cba;
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

.msg-time {
    font-size: 10px;
    color: #888888;
    margin-top: 3px;
    padding: 0 2px;
}

#ai-chat-footer {
    padding: 10px;
    display: flex;
    gap: 8px;
    border-top: 1px solid #e9ecef;
    background: #ffffff;
    flex-shrink: 0;
}

#ai-chat-input {
    flex: 1;
    border: 1px solid #ced4da;
    border-radius: 20px;
    padding: 8px 14px;
    outline: none;
    font-size: 13px;
    box-sizing: border-box;
}

#ai-chat-send {
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-weight: bold;
    cursor: pointer;
}

.feedback-container {
    padding: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#star-rating {
    font-size: 24px;
    cursor: pointer;
}

#star-rating span {
    color: #ccc;
    transition: color 0.2s;
}

#star-rating span.active {
    color: #ffc107;
}

#ai-feedback-comment, #ai-feedback-email {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 12px;
    box-sizing: border-box;
}

.ai-btn-submit {
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}

#ai-cancel-feedback {
    background: transparent;
    border: none;
    color: #6c757d;
    cursor: pointer;
    font-size: 12px;
}

.wa-btn {
    display: inline-block;
    margin-top: 8px;
    background: #25d366;
    color: #ffffff !important;
    padding: 8px 12px;
    border-radius: 6px;
    text-decoration: none !important;
    font-weight: bold;
    font-size: 12px;
}