/**
 * AI Chatbot — Widget Frontend Styles
 *
 * @package AIChatbot
 * @since   1.0.0
 */

/* ──────────────────────────────────────────
   VARIABILI
   ────────────────────────────────────────── */
:root {
    --chatbot-widget-primary: #0073aa;
    --chatbot-widget-primary-dark: #005a87;
    --chatbot-widget-font: 'Inter', sans-serif;
    --chatbot-widget-radius: 14px;
    --chatbot-widget-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    --chatbot-widget-z: 999999;
    --chatbot-mobile-width: 95;
    --chatbot-mobile-height: 85;
}

/* ──────────────────────────────────────────
   RESET SCOPING
   ────────────────────────────────────────── */
#ai-chatbot-widget,
#ai-chatbot-widget * {
    box-sizing: border-box;
    font-family: var(--chatbot-widget-font);
    line-height: 1.5;
}

/* ──────────────────────────────────────────
   FIX WEBVIEW / IN-APP BROWSER
   Instagram, Facebook, TikTok ecc. iniettano layer trasparenti che
   rubano i tap. Garantiamo pointer-events e ottimizzazioni touch
   senza creare nuovi stacking context che comprometterebbero z-index.
   NOTA: NON usare `isolation: isolate` qui né `transform` baseline,
   altrimenti il z-index 999999 viene confinato e altre sezioni del
   sito possono sovrapporsi al widget durante lo scroll.
   ────────────────────────────────────────── */
#ai-chatbot-widget {
    pointer-events: auto;
}
.chatbot-floating-btn,
.chatbot-close-btn,
.chatbot-whatsapp-btn,
.chatbot-quick-reply-btn,
.chatbot-consent-btn-accept,
.chatbot-consent-btn-exit,
#chatbot-send-btn {
    pointer-events: auto !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    -webkit-touch-callout: none;
}

/* ──────────────────────────────────────────
   PULSANTE FLOATING
   ────────────────────────────────────────── */
.chatbot-floating-btn {
    /* HARDENING ANTI-COLLISIONE (cookie banner, WhatsApp btn, sticky theme).
       Usiamo !important + z-index al massimo int32 per blindare il click
       contro temi/plugin che mettono fixed elements sopra al launcher.
       Casi reali risolti: Iubenda banner (z 2147483646), WhatsApp Click-to-Chat,
       sticky banner Elementor, scroll-to-top theme buttons. */
    position: fixed !important;
    bottom: 24px;
    right: 24px;
    /* Scala launcher: --chatbot-launcher-scale (default 1) impostata da admin */
    width: calc(60px * var(--chatbot-launcher-scale, 1));
    height: calc(60px * var(--chatbot-launcher-scale, 1));
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-widget-primary) 0%, var(--chatbot-widget-primary-dark) 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    /* Max valore z-index possibile (int32). I cookie banner usano fino a 2147483646. */
    z-index: 2147483647 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    /* Anti-overflow tema: forza pointer events anche se un genitore li disabilita */
    pointer-events: auto !important;
    /* Anti-conflitto stacking: il launcher è sempre la sua bolla, ma SENZA isolation
       che lo confinerebbe in un context inferiore. Margin e transform safe. */
    transform: translateZ(0);
}

/* Launcher nascosto quando la chat è aperta in overlay mobile (bottom-sheet
   / fullscreen): evita che il bottone flottante con la X copra l'area input.
   display:none vince sul z-index inline impostato dal detector anti-collisione. */
.chatbot-floating-btn.chatbot-launcher-hidden {
    display: none !important;
}

.chatbot-floating-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.3);
}

.chatbot-floating-btn:active {
    transform: scale(0.95);
}

/* Variante pill (con testo) */
.chatbot-floating-btn.has-label {
    width: auto;
    height: calc(56px * var(--chatbot-launcher-scale, 1));
    border-radius: calc(28px * var(--chatbot-launcher-scale, 1));
    padding: 0 calc(20px * var(--chatbot-launcher-scale, 1));
    gap: calc(10px * var(--chatbot-launcher-scale, 1));
    min-width: calc(60px * var(--chatbot-launcher-scale, 1));
}

/* Icona custom launcher (immagine rotonda) */
.chatbot-launcher-icon {
    width: calc(38px * var(--chatbot-launcher-scale, 1));
    height: calc(38px * var(--chatbot-launcher-scale, 1));
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* Testo sul launcher */
.chatbot-launcher-text {
    font-weight: 600;
    font-size: calc(15px * var(--chatbot-launcher-scale, 1));
    white-space: nowrap;
    color: #fff;
}

/* Badge messaggi non letti */
.chatbot-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 2px solid #fff;
    pointer-events: none;
}

/* ──────────────────────────────────────────
   CTA TOOLTIP
   ────────────────────────────────────────── */
.chatbot-cta-tooltip {
    position: fixed;
    bottom: 32px;
    right: 94px;
    background: #fff;
    color: #1d1d1f;
    padding: 10px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: calc(var(--chatbot-widget-z) - 1);
    font-family: var(--chatbot-widget-font);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: chatbotTooltipSlide 0.4s ease;
    max-width: 300px;
    cursor: pointer;
}

.chatbot-cta-tooltip.hidden {
    display: none !important;
}

.chatbot-cta-tooltip::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid #fff;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

.chatbot-cta-tooltip-text {
    color: var(--chatbot-widget-primary);
    font-weight: 600;
}

.chatbot-cta-tooltip-close {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chatbot-cta-tooltip-close:hover {
    background: #f0f0f0;
    color: #333;
}

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

/* ──────────────────────────────────────────
   FINESTRA CHAT — apertura/chiusura con animazione smooth
   ────────────────────────────────────────── */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-height: 580px;
    height: calc(100vh - 140px);
    background: #fff;
    border-radius: var(--chatbot-widget-radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    z-index: var(--chatbot-widget-z);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Stato nascosto default */
    visibility: hidden;
    opacity: 0;
    transform: translateY(24px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s linear 0.28s;
}

.chatbot-window.open {
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s linear 0s;
}

.chatbot-window.closing {
    visibility: hidden;
    opacity: 0;
    transform: translateY(24px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s linear 0.28s;
}

/* ──────────────────────────────────────────
   HEADER con gradiente
   ────────────────────────────────────────── */
.chatbot-header {
    background: linear-gradient(135deg, var(--chatbot-widget-primary) 0%, var(--chatbot-widget-primary-dark) 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 10px;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

/* Blocco testo (nome + status) centrato nello spazio tra avatar e azioni */
.chatbot-header-text {
    flex: 1;
    min-width: 0;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.chatbot-avatar-default {
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-header-name {
    display: block;
    font-weight: 600;
    font-size: 15px;
    color: var(--chatbot-widget-header-text, #fff);
}

/* Punto verde "Online" animato */
.chatbot-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    opacity: 0.9;
    color: var(--chatbot-widget-header-text, #fff);
}

.chatbot-header-status::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
    animation: chatbotOnlinePulse 2s infinite;
}

@keyframes chatbotOnlinePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(0.85); }
}

/* Gruppo pulsanti destra dell'header (WhatsApp + Chiudi) */
.chatbot-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.chatbot-close-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.chatbot-close-btn svg { width: 20px; height: 20px; }

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

/* ──────────────────────────────────────────
   PULSANTE WHATSAPP — nell'header della chat
   Dimensione allineata all'avatar (36px) per equilibrio visivo,
   ma con icona interna leggermente più piccola.
   ────────────────────────────────────────── */
.chatbot-whatsapp-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.92);
    text-decoration: none;
    flex-shrink: 0;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.chatbot-whatsapp-btn svg {
    width: 24px;
    height: 24px;
}

.chatbot-whatsapp-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    transform: scale(1.1);
}

.chatbot-whatsapp-btn:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.25);
}

/* ──────────────────────────────────────────
   AREA MESSAGGI
   ────────────────────────────────────────── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: #f8f9fa;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

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

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

/* ──────────────────────────────────────────
   BOLLE MESSAGGIO
   ────────────────────────────────────────── */
.chatbot-msg {
    max-width: 88%;
    word-wrap: break-word;
    animation: chatbotMsgFade 0.3s ease;
}

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

/* Messaggio bot: wrapper con avatar + bubble */
.chatbot-msg-bot {
    align-self: flex-start;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Mini avatar nel messaggio bot */
.chatbot-msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-bottom: 18px; /* allinea con il fondo della bolla */
}

/* Quando l'avatar è un'IMMAGINE (il logo del cliente) il box quadrato con
   object-fit:cover ritaglia il centro: di "Burger Studio" si leggeva "er Stu",
   e con una tela quadrata quasi vuota restava una macchia. Un marchio è quasi
   sempre orizzontale: box proporzionato, immagine intera, allineata a sinistra
   come nell'intestazione. Il ripiego disegnato (.chatbot-msg-avatar-default)
   resta il cerchietto di prima, che quadrato ci sta bene. */
img.chatbot-msg-avatar {
    width: 40px;
    height: 15px;
    border-radius: 3px;
    object-fit: contain;
    object-position: left center;
    background: transparent;
}

.chatbot-msg-avatar-default {
    background: var(--chatbot-widget-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

/* Bolla messaggio (usata sia per bot che utente) */
.chatbot-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
}

.chatbot-msg-bot .chatbot-msg-bubble {
    background: #fff;
    color: #1d1d1f;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

/* Link nei messaggi bot */
.chatbot-msg-bot .chatbot-msg-bubble a {
    color: var(--chatbot-widget-primary);
    text-decoration: underline;
}

.chatbot-msg-user {
    background: linear-gradient(135deg, var(--chatbot-widget-primary) 0%, var(--chatbot-widget-primary-dark) 100%);
    color: #fff;
    border-radius: 14px;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.55;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Il .chatbot-msg-bubble dentro i messaggi utente non deve aggiungere padding extra
   (il padding è già sul wrapper .chatbot-msg-user) */
.chatbot-msg-user .chatbot-msg-bubble {
    padding: 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
}

/* Timestamp */
.chatbot-msg-time {
    font-size: 11px;
    opacity: 0.55;
    margin-top: 4px;
    display: block;
}

.chatbot-msg-user .chatbot-msg-time {
    text-align: right;
    color: rgba(255,255,255,0.8);
    opacity: 1;
}

/* ── Suggested Link Cards (rich cards consigliate dal chatbot) ── */
.chatbot-suggested-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.chatbot-suggested-card {
    display: flex;
    align-items: stretch;
    gap: 10px;
    padding: 10px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    text-decoration: none !important;
    color: inherit !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
    overflow: hidden;
    max-width: 100%;
}

.chatbot-suggested-card:hover {
    border-color: var(--chatbot-widget-primary, #0073aa);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.chatbot-suggested-card:active {
    transform: translateY(0);
}

.chatbot-suggested-card-image {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 10px;
    overflow: hidden;
    background: #f3f4f6;
}

.chatbot-suggested-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chatbot-suggested-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
}

.chatbot-suggested-card-title {
    font-size: 13px;
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.chatbot-suggested-card-desc {
    font-size: 12px;
    color: #4b5563;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.chatbot-suggested-card-cta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 600;
    color: var(--chatbot-widget-primary, #0073aa);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.chatbot-suggested-card-cta svg {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.chatbot-suggested-card:hover .chatbot-suggested-card-cta svg {
    transform: translateX(2px);
}

/* Quando la card non ha immagine, compattala un po' */
.chatbot-suggested-card:not(:has(.chatbot-suggested-card-image)) {
    padding: 10px 12px;
}

.chatbot-msg-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    font-size: 13px;
    text-align: center;
    align-self: center;
    padding: 8px 14px;
    border-radius: 8px;
}

/* ──────────────────────────────────────────
   TYPING INDICATOR
   ────────────────────────────────────────── */
.chatbot-typing {
    padding: 0 16px 8px;
    flex-shrink: 0;
    background: #f8f9fa;
}

.chatbot-typing-dots {
    display: inline-flex;
    gap: 4px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.chatbot-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #bbb;
    animation: chatbotTypingDot 1.4s infinite both;
}

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

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

@keyframes chatbotTypingDot {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ──────────────────────────────────────────
   QUICK REPLY BUTTONS — carosello orizzontale
   I pulsanti restano in fila e scorrono lateralmente quando sono molti.
   Quando ne resta uno solo: niente scroll, posizione fissa.
   ────────────────────────────────────────── */
.chatbot-quick-replies-wrapper {
    position: relative;
    flex-shrink: 0;
    background: #f8f9fa;
    /* Il padding sta QUI (sul wrapper non-scrollabile) così i pulsanti
       restano sempre staccati dai bordi del popup, anche durante lo
       scroll orizzontale. Mettere il padding sul container scrollabile
       NON funziona: i browser "mangiano" il padding-right in overflow. */
    padding: 10px 14px;
}

/* Fade gradient lato dx — indica visivamente "scorri per altri".
   Allineato al padding del wrapper (14px) così non copre i pulsanti
   né tocca il bordo del popup. */
.chatbot-quick-replies-wrapper::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 10px;
    bottom: 10px;
    width: 24px;
    background: linear-gradient(90deg, rgba(248, 249, 250, 0) 0%, rgba(248, 249, 250, 1) 100%);
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.2s;
    border-radius: 0 4px 4px 0;
}
.chatbot-quick-replies-wrapper.no-overflow::after {
    opacity: 0;
}

.chatbot-quick-replies {
    padding: 0;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scroll-padding: 0 4px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    /* Nascondi scrollbar */
    scrollbar-width: none;
}
.chatbot-quick-replies::-webkit-scrollbar { display: none; }

/* Desktop: cursore "grab" per indicare drag-to-scroll. Sui pulsanti
   resta "pointer" (regola sui .chatbot-quick-reply-btn). Su touch
   device (no hover) non mostriamo grab perché lì lo scroll è naturale. */
@media (hover: hover) and (pointer: fine) {
    .chatbot-quick-replies {
        cursor: grab;
    }
    .chatbot-quick-replies:active {
        cursor: grabbing;
    }
}

.chatbot-quick-replies.hidden {
    display: none;
}

/*
 * Pulsanti Quick Reply — stile RAFFORZATO contro override dei temi.
 *
 * Doppia difesa contro CSS aggressivi (es. tema con `button { background:red }`):
 * 1. Selettore con #ai-chatbot-widget → +1 ID di specificità (vince sui temi normali).
 * 2. !important sui valori critici (colori, bordo, raggio, font) → vince anche su
 *    eventuali `button { ...!important }` del tema.
 *
 * I default qui sono il colore primario del widget. L'utente può sovrascriverli
 * dalle impostazioni Aspetto Widget → Stile pulsanti Quick Reply.
 */
#ai-chatbot-widget .chatbot-quick-reply-btn,
.chatbot-quick-reply-btn {
    appearance: none !important;
    -webkit-appearance: none !important;
    background: var(--chatbot-qr-bg, #fff) !important;
    color: var(--chatbot-qr-text, var(--chatbot-widget-primary)) !important;
    border: var(--chatbot-qr-border-width, 1px) solid var(--chatbot-qr-border-color, var(--chatbot-widget-primary)) !important;
    border-radius: var(--chatbot-qr-border-radius, 24px) !important;
    padding: 8px 16px !important;
    margin: 0 !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    line-height: 1.3 !important;
    font-family: var(--chatbot-qr-font, var(--chatbot-widget-font)) !important;
    text-transform: none !important;
    text-decoration: none !important;
    letter-spacing: normal !important;
    box-shadow: none !important;
    cursor: pointer !important;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, opacity 0.25s ease, margin 0.25s ease !important;
    white-space: nowrap;
    flex-shrink: 0;
    scroll-snap-align: start;
    min-height: 0 !important;
    height: auto !important;
    width: auto !important;
}

#ai-chatbot-widget .chatbot-quick-reply-btn:hover,
.chatbot-quick-reply-btn:hover {
    background: var(--chatbot-widget-primary) !important;
    color: #fff !important;
    border-color: var(--chatbot-widget-primary) !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12) !important;
}

#ai-chatbot-widget .chatbot-quick-reply-btn:focus,
.chatbot-quick-reply-btn:focus {
    outline: 2px solid var(--chatbot-widget-primary) !important;
    outline-offset: 2px;
}

#ai-chatbot-widget .chatbot-quick-reply-btn:active,
.chatbot-quick-reply-btn:active {
    transform: translateY(0);
}

/* Animazione di rimozione del pulsante cliccato */
#ai-chatbot-widget .chatbot-quick-reply-btn.removing,
.chatbot-quick-reply-btn.removing {
    opacity: 0 !important;
    transform: scale(0.85);
    margin-right: -120px !important;
    pointer-events: none !important;
}

/* ──────────────────────────────────────────
   INPUT AREA
   ────────────────────────────────────────── */
.chatbot-input-area {
    padding: 12px 16px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    background: #fff;
}

.chatbot-input-area form {
    display: flex;
    gap: 8px;
    align-items: center;
}

#chatbot-input {
    flex: 1;
    border: 1.5px solid #e0e0e0;
    border-radius: 24px;
    padding: 11px 16px;
    font-size: 14px;
    font-family: var(--chatbot-widget-font);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    background: #f8f9fa;
}

#chatbot-input:focus {
    border-color: var(--chatbot-widget-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

#chatbot-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-widget-primary) 0%, var(--chatbot-widget-primary-dark) 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

#chatbot-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#chatbot-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Powered by footer */
.chatbot-powered-by {
    text-align: center;
    font-size: 11px;
    color: #aaa;
    padding: 4px 0 2px;
    letter-spacing: 0.01em;
}

/* ──────────────────────────────────────────
   CONSENT OVERLAY GDPR
   ────────────────────────────────────────── */

/* Il .chatbot-header ha z-index 2 → rimane visibile sopra l'overlay */
.chatbot-header {
    position: relative;
    z-index: 2;
}

/* L'overlay copre tutta la finestra (compreso header visibile sopra) */
.chatbot-consent-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-radius: inherit;
    /* padding-top: altezza header (header ≈ 64px) */
    padding-top: 64px;
    -webkit-overflow-scrolling: touch;
}

.chatbot-consent-body {
    padding: 20px 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

.chatbot-consent-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--chatbot-widget-primary);
    margin: 0;
    line-height: 1.4;
}

.chatbot-consent-text {
    font-size: 13px;
    color: #444;
    line-height: 1.65;
    flex: 1;
}

.chatbot-consent-text p {
    margin: 0 0 10px;
}

.chatbot-consent-text p:last-child {
    margin-bottom: 0;
}

.chatbot-consent-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    font-size: 12px;
}

.chatbot-consent-links a {
    color: var(--chatbot-widget-primary);
    text-decoration: underline;
    font-weight: 500;
}

.chatbot-consent-sep {
    color: #ccc;
}

.chatbot-consent-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chatbot-consent-btn-accept {
    width: 100%;
    padding: 13px 20px;
    background: linear-gradient(135deg, var(--chatbot-widget-primary) 0%, var(--chatbot-widget-primary-dark) 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--chatbot-widget-font);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.chatbot-consent-btn-accept:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.chatbot-consent-btn-accept:active {
    transform: translateY(0);
}

.chatbot-consent-btn-exit {
    width: 100%;
    padding: 10px 20px;
    background: none;
    color: #888;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    font-size: 13px;
    font-family: var(--chatbot-widget-font);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.chatbot-consent-btn-exit:hover {
    background: #f5f5f5;
    color: #555;
}

/* ──────────────────────────────────────────
   MOBILE RESPONSIVE — bottom sheet style
   ────────────────────────────────────────── */
@media (max-width: 480px) {
    .chatbot-window {
        width: 100%;
        max-height: 85vh;
        height: 85vh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 16px 16px 0 0;
        transform: translateY(100%) scale(1);
    }

    .chatbot-window.open {
        transform: translateY(0) scale(1);
    }

    .chatbot-window.closing {
        transform: translateY(100%) scale(1);
    }

    .chatbot-floating-btn {
        width: calc(54px * var(--chatbot-launcher-scale, 1));
        height: calc(54px * var(--chatbot-launcher-scale, 1));
        bottom: 16px;
        right: 16px;
    }

    .chatbot-floating-btn.has-label {
        width: auto;
        height: calc(50px * var(--chatbot-launcher-scale, 1));
        border-radius: calc(25px * var(--chatbot-launcher-scale, 1));
    }

    /* CTA tooltip su mobile */
    .chatbot-cta-tooltip {
        right: 80px;
        bottom: 24px;
        max-width: calc(100vw - 120px);
        font-size: 13px;
    }

    /* Quick replies su mobile */
    .chatbot-quick-reply-btn {
        font-size: 12px;
        padding: 5px 12px;
    }

    /* Previene zoom automatico su iOS/Android quando si tocca l'input */
    #chatbot-input {
        font-size: 16px;
    }
}

@media (max-width: 380px) {
    .chatbot-msg {
        max-width: 92%;
    }

    .chatbot-msg-bubble {
        font-size: 13px;
    }

    #chatbot-input {
        font-size: 16px; /* Previene zoom su iOS */
    }
}

/* ──────────────────────────────────────────
   FULLSCREEN MOBILE
   ────────────────────────────────────────── */
.chatbot-window.fullscreen-mobile {
    /* Usa z-index superiore all'admin bar WP (99999) */
    z-index: 9999999 !important;
    /* Posizione: sovrascritta dinamicamente via JS (visualViewport) */
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    /* Altezza fallback; JS la sovrascrive con visualViewport.height */
    height: 100vh !important;
    height: 100dvh !important;
    max-height: none !important;
    border-radius: 0 !important;
    transform: translateY(100%) !important;
    /* Blocca scroll rubber-band iOS sull'intera finestra */
    overflow: hidden !important;
    overscroll-behavior: none;
}

.chatbot-window.fullscreen-mobile.open {
    transform: translateY(0) !important;
}

.chatbot-window.fullscreen-mobile.closing {
    transform: translateY(100%) !important;
}

/* Header: fisso e ridotto del 10% in altezza (solo spazio verticale, testo invariato) */
.chatbot-window.fullscreen-mobile .chatbot-header {
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    padding: 11px 16px;
    /* Safe area iOS notch — ridotta proporzionalmente */
    padding-top: max(11px, env(safe-area-inset-top));
    /* Impedisce che il gesto di scroll sul header scrolli la finestra */
    touch-action: none;
}

/* Area messaggi: solo questo elemento scorre, il resto rimane fermo */
.chatbot-window.fullscreen-mobile .chatbot-messages {
    flex: 1;
    min-height: 0;
    overflow-y: scroll; /* 'scroll' è più affidabile di 'auto' su iOS */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain; /* isola lo scroll: non propaga al parent */
}

/* Input stabile in fondo - non viene nascosto dalla tastiera
   perché JS ridimensiona la finestra in base a visualViewport.height */
.chatbot-window.fullscreen-mobile .chatbot-input-area {
    flex-shrink: 0;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #eee;
}

/* Overlay consenso: padding-top aggiornato in base alla nuova altezza header (~58px) */
.chatbot-window.fullscreen-mobile .chatbot-consent-overlay {
    padding-top: 58px;
}

/* ──────────────────────────────────────────
   SIDEBAR WIDGET
   ────────────────────────────────────────── */
.chatbot-sidebar-open-btn {
    display: inline-block;
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 8px;
}

.chatbot-sidebar-open-btn:hover {
    opacity: 0.9;
}

/* ──────────────────────────────────────────
   MEMORIA CONVERSAZIONI — messaggi storici
   ────────────────────────────────────────── */
.chatbot-msg.is-historical {
    opacity: 0.78;
}
.chatbot-history-separator {
    user-select: none;
}

/* ──────────────────────────────────────────
   MODALITÀ SIDEBAR ESPANSA (desktop, opt-in)
   Attiva solo quando <html> ha .cbx-sidebar-open (aggiunta via JS solo
   su desktop ≥ soglia). Push layout: il sito si restringe accanto.
   ────────────────────────────────────────── */

/* Pulsante espandi/comprimi nell'header */
.chatbot-expand-btn {
    background: none;
    border: none;
    color: var(--chatbot-widget-header-text, #fff);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.chatbot-expand-btn:hover { background: rgba(255,255,255,0.2); }

/* Il sito si restringe: margine sul body verso il lato della sidebar */
html.cbx-sidebar-open body {
    transition: margin 0.25s ease;
}
html.cbx-sidebar-open.cbx-sidebar-right body {
    margin-right: var(--cb-sidebar-w) !important;
}
html.cbx-sidebar-open.cbx-sidebar-left body {
    margin-left: var(--cb-sidebar-w) !important;
}

/* La finestra chat diventa barra laterale a tutta altezza */
html.cbx-sidebar-open .chatbot-window.open {
    top: 0 !important;
    bottom: 0 !important;
    height: 100vh !important;
    max-height: 100vh !important;
    width: var(--cb-sidebar-w) !important;
    max-width: var(--cb-sidebar-w) !important;
    border-radius: 0 !important;
    box-shadow: 0 0 24px rgba(0,0,0,0.15) !important;
}
html.cbx-sidebar-open.cbx-sidebar-right .chatbot-window.open {
    right: 0 !important;
    left: auto !important;
}
html.cbx-sidebar-open.cbx-sidebar-left .chatbot-window.open {
    left: 0 !important;
    right: auto !important;
}

/* Nascondi il pulsante floating mentre la sidebar è aperta (è già visibile) */
html.cbx-sidebar-open .chatbot-floating-btn { display: none !important; }

/* Solo desktop: sotto soglia la modalità non si applica mai (fail-safe lato CSS) */
@media (max-width: 1199px) {
    html.cbx-sidebar-open body { margin-right: 0 !important; margin-left: 0 !important; }
    html.cbx-sidebar-open .chatbot-window.open {
        width: auto !important; max-width: 420px !important; height: auto !important;
        border-radius: var(--chatbot-widget-radius, 14px) !important;
    }
    html.cbx-sidebar-open .chatbot-floating-btn { display: flex !important; }
}

/* ──────────────────────────────────────────
   CARD PRODOTTO (token [[product:ID]] in chat)
   ────────────────────────────────────────── */
#ai-chatbot-widget .chatbot-product-card {
    display: flex;
    align-items: center;
    gap: 12px;
    box-sizing: border-box;
    width: 100%;
    border: 1px solid #e6e6e6;
    border-radius: 12px;
    padding: 10px;
    margin: 8px 0;
    background: #fff;
}
#ai-chatbot-widget .chatbot-product-card-img {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #eee;
    background: #f5f5f5;
}
#ai-chatbot-widget .chatbot-product-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#ai-chatbot-widget .chatbot-product-card-name {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    color: #222;
    overflow-wrap: anywhere;
}
#ai-chatbot-widget .chatbot-product-card-price {
    font-size: 13px;
    color: #555;
}
#ai-chatbot-widget .chatbot-product-card-btn {
    align-self: flex-start;
    display: inline-block;
    box-sizing: border-box;
    text-decoration: none !important;
    text-align: center;
    background: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
    border-radius: 8px;
    padding: 8px 14px !important;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2 !important;
    white-space: normal !important;
}
#ai-chatbot-widget .chatbot-product-card-btn:hover { opacity: 0.92; }

/* ── Assistente operativo: riquadro di conferma azione (2.6.0) ────────────── */
.chatbot-action {
    margin: 10px 12px;
    padding: 12px 14px;
    border: 1px solid rgba(0, 0, 0, .12);
    border-left: 3px solid #2563eb;
    border-radius: 10px;
    background: #f8fafc;
    font-size: 14px;
}
.chatbot-action-title { font-weight: 700; margin-bottom: 8px; color: #111827; }
.chatbot-action-params { margin: 0 0 10px; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.chatbot-action-params dt { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: #6b7280; }
.chatbot-action-params dd { margin: 0; color: #111827; overflow-wrap: anywhere; }
.chatbot-action-buttons { display: flex; gap: 8px; }
.chatbot-action-buttons button {
    flex: 0 0 auto; padding: 7px 16px; border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer; border: 1px solid transparent;
    white-space: normal; /* il reset di alcuni temi mette nowrap sui button */
}
.chatbot-action-confirm { background: #2563eb; color: #fff; }
.chatbot-action-confirm:disabled { opacity: .6; cursor: default; }
.chatbot-action-cancel { background: #fff; color: #374151; border-color: #d1d5db; }

/* ── Dettatura vocale (2.7.0) ─────────────────────────────────────────────── */
#chatbot-mic-btn {
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0 8px;
    display: flex;
    align-items: center;
    transition: color .15s ease;
}
#chatbot-mic-btn:hover { color: var(--chatbot-widget-primary, #0073aa); }
#chatbot-mic-btn.registrando {
    color: #dc2626;
    animation: chatbot-mic-pulse 1.2s ease-in-out infinite;
}
#chatbot-mic-btn.trascrivendo { color: var(--chatbot-widget-primary, #0073aa); opacity: .6; }
@keyframes chatbot-mic-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .55; transform: scale(1.12); }
}
@media (prefers-reduced-motion: reduce) {
    #chatbot-mic-btn.registrando { animation: none; }
}

/* ── Casella multi-riga che cresce (2.7.1) ────────────────────────────────── */
#chatbot-input {
    resize: none;
    overflow-y: hidden;
    line-height: 1.45;
    font-family: inherit;
    max-height: calc(1.45em * 6 + 20px);
}

/* ── Onde della voce durante la registrazione (2.7.1) ─────────────────────── */
/* NASCOSTO di default. Serve display:none esplicito: un selettore ID batte
   l'attributo `hidden`, e senza questa regola l'indicatore restava sempre in
   pagina rubando spazio alla casella di scrittura. Compare SOLO durante la
   registrazione, prendendo esattamente il posto della casella. */
#chatbot-voice-live { display: none; }
#chatbot-voice-live.cb-attivo {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    align-self: stretch;
    position: relative;
}
#chatbot-voice-live .cb-onda {
    display: block;
    width: 3px;
    height: 4px;
    border-radius: 2px;
    background: var(--chatbot-widget-primary, #0073aa);
    opacity: .75;
    transition: height .08s ease-out;
}
#chatbot-voice-live .cb-voice-hint {
    position: absolute;
    left: 0; right: 0; bottom: 1px;
    font-size: 10px;
    font-style: normal;
    text-align: center;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* ── Richiesta di assistenza, come un ticket (2.22.0) ─────────────────────────
   Chi scrive deve sapere due cose senza pensarci: che una richiesta è aperta, e
   a CHI andrà il prossimo messaggio. La seconda cambia colore, perché è quella
   che si sbaglia. */
.chatbot-ticket-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    font-size: 12.5px;
    color: #374151;
}
.chatbot-ticket-chip.a-persona {
    background: #eef4ff;
    border-bottom-color: #d6e2fb;
    color: #1e3a8a;
}
.chatbot-ticket-pallino {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
}
.chatbot-ticket-chip.a-persona .chatbot-ticket-pallino { background: #2563eb; }
.chatbot-ticket-testo { flex: 1 1 auto; font-weight: 600; }
.chatbot-ticket-azione {
    flex: 0 0 auto;
    background: none; border: none; padding: 2px 4px;
    font: inherit; font-size: 12px; color: inherit;
    text-decoration: underline; cursor: pointer; opacity: .85;
}
.chatbot-ticket-azione:hover { opacity: 1; }

/* La domanda citata dentro la risposta della persona. */
.chatbot-persona-citazione {
    margin: 6px 0 8px;
    padding: 6px 10px;
    border-left: 3px solid #c7d2fe;
    background: rgba(99,102,241,.06);
    border-radius: 0 6px 6px 0;
    font-size: 12.5px;
    color: #4b5563;
    font-style: italic;
}

/* Le due strade, esplicite. */
.chatbot-persona-scelte { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chatbot-persona-scelta {
    padding: 7px 14px;
    border: 1px solid var(--chatbot-widget-primary, #0073aa);
    border-radius: 999px;
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff;
    font: inherit; font-size: 12.5px; font-weight: 600;
    cursor: pointer;
}
.chatbot-persona-scelta.secondaria { background: none; color: var(--chatbot-widget-primary, #0073aa); }
.chatbot-persona-scelta:hover { opacity: .9; }

/* ⚠️ HELLO + ELEMENTOR TINGE DI ROSSO OGNI <button> NATIVO su hover E su focus
   (reset.css del tema: button:hover,button:focus{background-color:#CC3366}).
   Le regole qui sopra definiscono lo sfondo solo sullo stato base, quindi al
   primo clic i pulsanti nuovi diventavano rossi. È il difetto ricorrente già
   noto: si chiude ridichiarando lo sfondo anche su :hover e :focus. */
.chatbot-ticket-azione:hover,
.chatbot-ticket-azione:focus,
.chatbot-lavoro-esci:hover,
.chatbot-lavoro-esci:focus {
    background: none !important;
    background-color: transparent !important;
}
.chatbot-persona-scelta:hover,
.chatbot-persona-scelta:focus {
    background-color: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
}
.chatbot-persona-scelta.secondaria:hover,
.chatbot-persona-scelta.secondaria:focus {
    background-color: transparent !important;
    color: var(--chatbot-widget-primary, #0073aa) !important;
}
.chatbot-giudizio-voto:hover,
.chatbot-giudizio-voto:focus {
    background-color: #fff !important;
}
.chatbot-esito-aggiorna:hover,
.chatbot-esito-aggiorna:focus {
    background-color: #15803d !important;
    color: #fff !important;
}

/* Il giudizio sulla risposta di una persona. */
.chatbot-giudizio {
    margin: 10px 12px;
    padding: 10px 12px;
    border: 1px solid rgba(0,0,0,.08);
    border-radius: 12px;
    background: #f9fafb;
    text-align: center;
}
.chatbot-giudizio-domanda { margin: 0; font-size: 13px; color: #374151; }
.chatbot-giudizio-voti { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.chatbot-giudizio-voto {
    width: 40px; height: 34px;
    border: 1px solid #d1d5db; border-radius: 9px;
    background: #fff; font-size: 17px; cursor: pointer;
}
.chatbot-giudizio-voto:hover { border-color: var(--chatbot-widget-primary, #0073aa); }

/* ── Lavoro in corso + esito (2.17.0) ─────────────────────────────────────────
   Un'azione che finisce fuori dalla richiesta (portare un file da Drive nel piano
   editoriale) prima non si vedeva: il modello diceva "sto importando" e poi
   silenzio. Qui il lavoro si vede mentre gira e si chiude con una ✓ che dice cosa
   e' finito nel piano di chi. Il quadrato che ruota e' lo stesso segnale del
   pulsante di invio: un solo linguaggio per "sto lavorando, aspetta". */
.chatbot-lavoro {
    display: flex;
    align-items: center;
    /* Su telefono stretto il nome del file e l'uscita non stanno sulla stessa
       riga: va a capo l'uscita, non il testo spezzato a meta'. */
    flex-wrap: wrap;
    gap: 9px;
    margin: 10px 12px;
    padding: 10px 12px;
    border: 1px solid rgba(0, 0, 0, .08);
    border-radius: 12px;
    background: #f9fafb;
    font-size: 13px;
    color: #374151;
}
.chatbot-lavoro-spin {
    flex: 0 0 auto;
    width: 13px;
    height: 13px;
    border-radius: 3px;
    background: var(--chatbot-widget-primary, #0073aa);
    animation: chatbotLavoroGira 1.1s linear infinite;
}
@keyframes chatbotLavoroGira {
    0%   { transform: rotate(0deg);   border-radius: 3px; }
    50%  { transform: rotate(180deg); border-radius: 6px; }
    100% { transform: rotate(360deg); border-radius: 3px; }
}
.chatbot-lavoro-testo { flex: 1 1 auto; line-height: 1.4; }
.chatbot-lavoro-esci {
    flex: 0 0 auto;
    margin-left: auto;
    background: none;
    border: none;
    padding: 2px 4px;
    font: inherit;
    font-size: 12px;
    color: var(--chatbot-widget-primary, #0073aa);
    text-decoration: underline;
    cursor: pointer;
}
.chatbot-lavoro-esci:hover { color: var(--chatbot-widget-primary-dark, #005a87); }

.chatbot-esito {
    margin: 10px 12px;
    padding: 11px 12px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-size: 13.5px;
    line-height: 1.45;
}
.chatbot-esito.is-ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.chatbot-esito.is-ko { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.chatbot-esito-riga { display: flex; align-items: flex-start; gap: 9px; }
.chatbot-esito-segno {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}
.chatbot-esito.is-ok .chatbot-esito-segno { background: #16a34a; }
.chatbot-esito.is-ko .chatbot-esito-segno { background: #dc2626; }
.chatbot-esito-testo { flex: 1 1 auto; }
.chatbot-esito-img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 260px;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(255, 255, 255, .7);
    margin-top: 9px;
}
/* Il pulsante per ricaricare: chiude il giro "fatto" → "ma non lo vedo". */
.chatbot-esito-aggiorna {
    display: inline-block;
    margin-top: 10px;
    padding: 7px 13px;
    border: 1px solid #16a34a;
    border-radius: 999px;
    background: #16a34a;
    color: #fff;
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}
.chatbot-esito-aggiorna:hover { background: #15803d; border-color: #15803d; }
.chatbot-esito-aggiorna:disabled { opacity: .6; cursor: default; }

.chatbot-esito-cap {
    margin: 7px 2px 0;
    font-size: 12.5px;
    opacity: .85;
}

/* Il pulsante di invio mentre un lavoro gira: la freccia lascia il posto al
   quadrato che ruota, e finche' e' cosi' non si puo' inviare. */
#chatbot-send-btn.cb-lavorando { opacity: 1; cursor: progress; }
#chatbot-send-btn.cb-lavorando svg { display: none; }
#chatbot-send-btn.cb-lavorando::after {
    content: '';
    width: 13px;
    height: 13px;
    border-radius: 3px;
    background: #fff;
    animation: chatbotLavoroGira 1.1s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
    .chatbot-lavoro-spin,
    #chatbot-send-btn.cb-lavorando::after { animation-duration: 3s; }
}

/* ── Anteprima del contenuto generato + giudizio (2.7.1) ──────────────────── */
.chatbot-preview {
    margin: 10px 12px;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: 12px;
    background: #fff;
}
.chatbot-preview img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 320px;
    object-fit: contain;
    border-radius: 8px;
    background: #f3f4f6;
}
.chatbot-preview-cap {
    margin: 8px 2px 0;
    font-size: 13px;
    line-height: 1.45;
    color: #374151;
}
.chatbot-preview-actions { display: flex; gap: 8px; margin-top: 10px; }
.chatbot-preview-actions .cb-voto {
    flex: 0 0 auto;
    font-size: 18px;
    line-height: 1;
    padding: 6px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
}
.chatbot-preview-actions .cb-voto:hover { border-color: var(--chatbot-widget-primary, #0073aa); }
.chatbot-preview-fix { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.chatbot-preview-fix textarea {
    width: 100%;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
    padding: 7px 9px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
}
.cb-voto-invia {
    align-self: flex-end;
    padding: 6px 16px;
    border: none;
    border-radius: 8px;
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    white-space: normal;
}

/* La casella riempie lo spazio disponibile: senza questo, aggiungendo elementi
   nel form (microfono, indicatore voce) si restringe invece di adattarsi. */
#chatbot-input { flex: 1 1 auto; min-width: 0; }

/* Con la casella che cresce, microfono e invio restano in BASSO invece di
   fluttuare a metà altezza: è il comportamento delle chat a cui si è abituati. */
.chatbot-input-area form { align-items: flex-end; }
#chatbot-mic-btn, #chatbot-send-btn { flex: 0 0 auto; align-self: flex-end; }

/* ── Header sempre raggiungibile + nuova conversazione (2.7.3) ────────────── */
.chatbot-reset-btn {
    background: transparent;
    border: none;
    color: currentColor;
    opacity: .85;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 6px;
}
.chatbot-reset-btn:hover { opacity: 1; background: rgba(255, 255, 255, .15); }
.chatbot-reset-btn:disabled { opacity: .4; cursor: default; }

/* Cintura di sicurezza: se per qualsiasi motivo il layout a colonna cedesse
   (un tema che inietta CSS, un browser che si comporta diversamente), l'header
   resta comunque agganciato in cima invece di scorrere via con i messaggi. */
.chatbot-window.fullscreen-mobile .chatbot-header {
    position: sticky;
    top: 0;
}
/* Il rimbalzo di fine lista non deve propagarsi e muovere la finestra. */
.chatbot-window.fullscreen-mobile .chatbot-messages {
    overscroll-behavior: none;
}

/* ── Avviso IA sotto la casella (2.7.4) ───────────────────────────────────── */
.chatbot-ai-disclosure {
    font-size: 9px;
    line-height: 1.3;
    color: #6b7280;
    padding: 6px 12px 0;
    text-align: center;
    /* niente nowrap: su schermi stretti il testo va a capo invece di essere tagliato */
    white-space: normal;
}

/* ── Allegare un'immagine (2.8.0) ─────────────────────────────────────────── */
#chatbot-attach-btn {
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0 6px;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    align-self: flex-end;
    transition: color .15s ease;
}
#chatbot-attach-btn:hover { color: var(--chatbot-widget-primary, #0073aa); }
#chatbot-attach-btn.caricando { opacity: .5; cursor: default; }
.chatbot-allegato {
    position: relative;
    margin: 8px 12px;
    align-self: flex-end;
    max-width: 60%;
}
.chatbot-allegato img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, .1);
}
.chatbot-allegato-via {
    position: absolute;
    top: -6px; right: -6px;
    width: 24px; height: 24px;
    border-radius: 50%;
    border: none;
    background: #111827;
    color: #fff;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    white-space: normal;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PIEDE DELLA CHAT — due righe (2.9.0)
   La casella occupa tutta la larghezza, i comandi stanno sotto. Su telefono la
   casella divideva lo spazio con tre pulsanti e ne restava poco più di metà.
   ═══════════════════════════════════════════════════════════════════════════ */
.chatbot-input-area form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
    padding: 10px 12px 8px;
    border: 1.5px solid rgba(0, 0, 0, .08);
    border-radius: 26px;              /* morbido, come da riferimento */
    background: #f8f9fa;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.chatbot-input-area form:focus-within {
    border-color: var(--chatbot-widget-primary, #0073aa);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, .04);
}

/* La casella non ha più bordo proprio: il bordo è quello del contenitore. */
#chatbot-input {
    width: 100%;
    flex: 1 1 auto;
    min-width: 0;
    border: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    padding: 4px 6px !important;
    resize: none;
    overflow-y: hidden;
    line-height: 1.45;
    font-family: inherit;
    outline: none;
    box-shadow: none !important;
}
#chatbot-input:focus { border: none !important; box-shadow: none !important; }

.chatbot-azioni {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.chatbot-azioni-sx, .chatbot-azioni-dx { display: flex; align-items: center; gap: 6px; }

/* Comandi tondi, coerenti fra loro. */
.chatbot-azioni button {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, .05);
    color: #4b5563;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background .15s ease, color .15s ease, transform .12s ease;
    white-space: normal;
}
.chatbot-azioni button:hover { background: rgba(0, 0, 0, .09); color: #111827; }
.chatbot-azioni button:active { transform: scale(.94); }

#chatbot-send-btn {
    background: var(--chatbot-widget-primary, #0073aa) !important;
    color: #fff !important;
}
#chatbot-send-btn:hover { background: var(--chatbot-widget-primary-dark, #005a87) !important; }
#chatbot-mic-btn.registrando { color: #dc2626; }
#chatbot-attach-btn.caricando { opacity: .5; cursor: default; }

/* ── Riga della dettatura: prende il posto di tutto ──────────────────────── */
#chatbot-voice-live { display: none; }
#chatbot-voice-live.cb-attivo {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
}
#chatbot-voice-live .cb-onde {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    overflow: hidden;
}
#chatbot-voice-live .cb-onda {
    display: block;
    width: 3px;
    height: 4px;
    border-radius: 3px;
    background: #4b5563;
    opacity: .7;
    transition: height .08s ease-out;
}
#chatbot-voice-annulla, #chatbot-voice-conferma {
    flex: 0 0 auto;
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    padding: 0;
    white-space: normal;
}
#chatbot-voice-annulla { background: rgba(0, 0, 0, .06); color: #374151; }
#chatbot-voice-annulla:hover { background: rgba(0, 0, 0, .11); }
#chatbot-voice-conferma { background: var(--chatbot-widget-primary, #0073aa); color: #fff; }
#chatbot-voice-conferma:active, #chatbot-voice-annulla:active { transform: scale(.94); }

/* Su schermi stretti i comandi restano comodi da toccare. */
@media (max-width: 480px) {
    .chatbot-input-area form { border-radius: 24px; padding: 10px 10px 8px; }
    .chatbot-azioni button { width: 40px; height: 40px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LOGO INTERO, NON RITAGLIATO (2.9.4)
   `object-fit: cover` dentro un cerchio riempie il box tagliando via i lati:
   con un logo rettangolare si vedeva solo la parte centrale. `contain` lo
   mostra tutto, e il box si adatta alla sua forma invece di imporgliela.
   ═══════════════════════════════════════════════════════════════════════════ */
/* MISURA UNICA DEL LOGO NELL'INTESTAZIONE (30/07/2026).
   Il logo è la prima cosa che dice al cliente con chi sta parlando, quindi
   dev'essere leggibile; ma su un marchio ORIZZONTALE la dimensione che conta è
   la LARGHEZZA, non l'altezza — fissando l'altezza, un logo 5:1 arrivava a
   toccare il titolo. C'era anche una seconda regola più in basso che alzava
   l'altezza a 34px: due regole per la stessa cosa, e vinceva l'ultima. Ora è
   una sola.
   ⚠️ E vale più di qualunque numero scritto qui: se il FILE del logo è una tela
   quadrata con la scritta piccola al centro, `contain` fa entrare la tela e la
   scritta resta minuscola (era alta 3px dentro un box da 30). Il logo va
   consegnato già rifilato. */
.chatbot-header .chatbot-avatar {
    width: auto;
    max-width: 112px;
    height: 22px;
    border-radius: 0;
    object-fit: contain;
    object-position: left center;
}
@media (max-width: 360px) {
    .chatbot-header .chatbot-avatar { max-width: 92px; height: 18px; }
}
/* Accanto ai messaggi il logo resta piccolo, ma intero. */
.chatbot-msg .chatbot-avatar,
.chatbot-avatar:not(.chatbot-avatar-default) {
    object-fit: contain;
}
.chatbot-msg .chatbot-avatar {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: transparent;
}

/* ── Pulsante "nuova conversazione": tondo e della stessa misura della X ──── */
.chatbot-header-actions .chatbot-reset-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.chatbot-header-actions .chatbot-reset-btn:hover { background: rgba(255, 255, 255, .3); }
.chatbot-header-actions .chatbot-reset-btn svg { width: 17px; height: 17px; }

/* Stessa identica misura per tutti i comandi dell'header. */
.chatbot-header-actions .chatbot-close-btn,
.chatbot-header-actions .chatbot-reset-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    flex: 0 0 auto;
}
.chatbot-header-actions { display: flex; align-items: center; gap: 8px; }

/* ── Intestazione compatta (2.9.5) ────────────────────────────────────────── */
/* Il titolo resta su UNA riga: se non ci sta si accorcia con i puntini invece
   di andare a capo facendo crescere l'intestazione. */
.chatbot-header-text { min-width: 0; }
.chatbot-header-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}
.chatbot-header-status { line-height: 1.2; }
.chatbot-header { padding-top: 10px; padding-bottom: 10px; }
.chatbot-window.fullscreen-mobile .chatbot-header {
    padding-top: max(9px, env(safe-area-inset-top));
    padding-bottom: 9px;
}

/* ── Risposta scritta da una PERSONA (referente dell'agenzia) ─────────────────
   Deve leggersi come "ti ha risposto qualcuno", non come un'altra frase
   dell'assistente: bordo colorato a sinistra e nome di chi scrive in cima.
   Se il cliente non distingue i due, l'assistenza perde il suo senso. */
.chatbot-msg-persona .chatbot-msg-bubble {
    border-left: 3px solid var(--chatbot-primary, #2563eb);
    background: var(--chatbot-persona-bg, #eef4ff);
}
.chatbot-persona-chi {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
    opacity: .75;
    margin-bottom: 4px;
}
@media (prefers-color-scheme: dark) {
    .chatbot-msg-persona .chatbot-msg-bubble { background: rgba(37, 99, 235, .16); }
}

/* Trascinare un'immagine dentro la chat (2.24.0): il bordo dice dove lasciarla. */
.chatbot-trascina { outline: 2px dashed var(--chatbot-primary, #4f46e5); outline-offset: -6px; }
.chatbot-trascina::after {
    content: 'Lascia qui l\'immagine';
    position: absolute; inset: auto 0 12px 0; text-align: center;
    font-size: 13px; color: var(--chatbot-primary, #4f46e5); pointer-events: none;
}
