#bchat-root {
    position: fixed;
    bottom: var(--bchat-bottom, 24px);
    z-index: 9000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    pointer-events: none; /* l'area del contenitore può essere più estesa del visibile (es. su mobile) — non deve bloccare click sotto di sé */
}
#bchat-root > * { pointer-events: auto; } /* ma i suoi figli visibili (bottone, pannello) restano cliccabili normalmente */
#bchat-root.bchat--right { right: var(--bchat-side, 24px); }
#bchat-root.bchat--left  { left:  var(--bchat-side, 24px); }

.bchat-toggle {
    position: relative;
    width: 60px; height: 60px; border-radius: 50%;
    background: var(--bchat-bubble-bg, #7a1f2b); color: var(--bchat-bubble-icon, #fff); border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    transition: transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease;
    overflow: visible;
}
.bchat-toggle:hover { transform: scale(1.07); box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.bchat-toggle:active { transform: scale(.95); }
.bchat-toggle img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Pallino "online" sul pulsante flottante: visibile anche a chat chiusa,
   non solo nell'intestazione del pannello (prima scompariva del tutto
   finché non si apriva la chat). */
.bchat-toggle-status {
    position: absolute;
    bottom: 2px; right: 2px;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--bchat-online, #3ecf6e);
    border: 2.5px solid #fff;
    animation: bchat-pulse 2.2s infinite;
}

.bchat-panel {
    position: absolute;
    bottom: 76px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: 70vh;
    background: var(--bchat-bot-bg, #fff);
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.96);
    transform-origin: bottom right;
    transition: opacity .25s cubic-bezier(.16,1,.3,1), transform .25s cubic-bezier(.16,1,.3,1);
}
.bchat-panel[hidden] { display: none; }
#bchat-root.bchat--right .bchat-panel { right: 0; transform-origin: bottom right; }
#bchat-root.bchat--left  .bchat-panel { left: 0; transform-origin: bottom left; }
.bchat-panel.bchat-open { opacity: 1; transform: translateY(0) scale(1); }

.bchat-header {
    background: var(--bchat-primary, #7a1f2b); color: var(--bchat-text, #fff);
    padding: 14px 16px;
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 600;
}
.bchat-header-title-wrap { display: flex; flex-direction: column; gap: 2px; }
.bchat-status {
    display: flex; align-items: center; gap: 5px;
    font-size: 11px; font-weight: 500; color: rgba(255,255,255,.75);
    text-transform: uppercase; letter-spacing: .03em;
}
.bchat-status-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--bchat-online, #3ecf6e);
    box-shadow: 0 0 0 rgba(62,207,110,.6);
    animation: bchat-pulse 2.2s infinite;
}
@keyframes bchat-pulse {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bchat-online, #3ecf6e) 60%, transparent); }
    70%  { box-shadow: 0 0 0 6px color-mix(in srgb, var(--bchat-online, #3ecf6e) 0%, transparent); }
    100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bchat-online, #3ecf6e) 0%, transparent); }
}
.bchat-header-actions { display: flex; align-items: center; gap: 6px; }
.bchat-icon-btn { background: none; border: none; color: var(--bchat-text, #fff); font-size: 18px; cursor: pointer; line-height: 1; opacity: .8; padding: 2px 4px; }
.bchat-icon-btn:hover { opacity: 1; }
.bchat-close { background: none; border: none; color: var(--bchat-text, #fff); font-size: 22px; cursor: pointer; line-height: 1; opacity: .8; }
.bchat-close:hover { opacity: 1; }

.bchat-footer-links { text-align: center; padding: 6px 0 10px; background: var(--bchat-bot-bg, #fff); }
.bchat-terms-link { background: none; border: none; color: #999; font-size: .75rem; text-decoration: underline; cursor: pointer; padding: 2px; }
.bchat-terms-link:hover { color: #666; }

/* Modale termini e condizioni: prima appariva/spariva di scatto (solo
   l'attributo [hidden], nessuna transizione) — ora dissolvenza sull'overlay
   e leggero effetto di scala sulla box, stessa cura del pannello chat. */
.bchat-terms-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 9001; display: flex; align-items: center; justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity .25s cubic-bezier(.16,1,.3,1);
}
.bchat-terms-overlay[hidden] { display: none; }
.bchat-terms-overlay.bchat-open { opacity: 1; }
.bchat-terms-box {
    background: var(--bchat-bot-bg, #fff); border-radius: 12px; max-width: 480px; max-height: 70vh; width: 100%;
    display: flex; flex-direction: column; overflow: hidden;
    transform: scale(.92) translateY(10px);
    transition: transform .25s cubic-bezier(.16,1,.3,1);
}
.bchat-terms-overlay.bchat-open .bchat-terms-box { transform: scale(1) translateY(0); }
.bchat-terms-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid #eee; }
.bchat-terms-header .bchat-close { color: var(--bchat-dark, #1a1a1a); }
.bchat-terms-body { padding: 16px 18px; overflow-y: auto; font-size: .875rem; line-height: 1.6; color: #333; }

.bchat-legal-link { background: none; border: none; padding: 0; font: inherit; font-size: .8125rem; color: var(--bchat-primary, #7a1f2b); text-decoration: underline; cursor: pointer; }
.bchat-legal-link:hover { opacity: .8; }
.bchat-legal-links { margin-top: 14px; padding-top: 12px; border-top: 1px solid #eee; text-align: center; }

/* Modale "sopra quella generale": stesso overlay/box dei termini, z-index
   più alto per impilarsi visivamente sopra #bchat-terms-modal invece di
   sostituirlo — chiudendola si torna alla modale sottostante, ancora aperta. */
.bchat-legal-overlay { z-index: 9002; }
#bchat-legal-modal .bchat-terms-box { max-width: 560px; max-height: 80vh; }

.bchat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--bchat-bg, #faf9f7);
}

.bchat-msg {
    max-width: 85%; padding: 10px 14px; border-radius: 14px; font-size: .9rem; line-height: 1.45;
    animation: bchat-msg-in .28s cubic-bezier(.16,1,.3,1);
}
@keyframes bchat-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.bchat-msg.bchat-user { align-self: flex-end; background: var(--bchat-primary, #7a1f2b); color: var(--bchat-text, #fff); border-bottom-right-radius: 4px; }
.bchat-msg.bchat-bot  { align-self: flex-start; background: var(--bchat-bot-bg, #fff); color: var(--bchat-bot-text, #222); border: 1px solid var(--bchat-border, #e5e0db); border-bottom-left-radius: 4px; }
.bchat-msg.bchat-typing { align-self: flex-start; color: #999; font-style: italic; font-size: .85rem; }

.bchat-product-card {
    align-self: flex-start; max-width: 85%; width: 240px;
    background: var(--bchat-bot-bg, #fff); border: 1px solid var(--bchat-border, #e5e0db); border-radius: 12px; overflow: hidden;
    display: block !important;
}
.bchat-product-card img { width: 100%; height: 120px; object-fit: cover; display: block !important; }
.bchat-product-body { padding: 10px 12px; display: block !important; min-height: 60px; background: var(--bchat-bot-bg, #fff); }
.bchat-product-name { display: block !important; font-weight: 600; font-size: .875rem; margin: 0 0 2px; color: var(--bchat-dark, #1a1a1a) !important; line-height: 1.3; }
.bchat-product-price { display: block !important; color: var(--bchat-accent, #b5862e) !important; font-weight: 700; font-size: .9375rem; margin: 0 0 8px; }
.bchat-qty-wrap { display: inline-block; vertical-align: middle; margin-right: 8px; }
.bchat-qty-input {
    width: 52px; padding: 7px 6px; text-align: center;
    border: 1px solid var(--bchat-border, #d8d2ca); border-radius: 8px; font-size: .8125rem;
}
.bchat-qty-input:disabled { opacity: .4; }
.bchat-product-btn {
    width: calc(100% - 62px); padding: 8px; border: none; border-radius: 8px;
    background: var(--bchat-dark, #1a1a1a); color: #fff; font-size: .8125rem; font-weight: 600; cursor: pointer;
    vertical-align: middle;
    transition: background .15s ease;
}
.bchat-product-btn:hover { background: color-mix(in srgb, var(--bchat-dark, #1a1a1a) 80%, white); }
.bchat-product-btn:disabled { background: #4a9d5f; cursor: default; }

.bchat-quick-replies { display: flex; flex-direction: column; gap: 8px; align-self: stretch; margin-top: 4px; }
.bchat-quick-btn {
    display: flex; align-items: center; gap: 8px;
    text-align: left; padding: 10px 16px; border-radius: 20px;
    background: color-mix(in srgb, var(--bchat-primary, #7a1f2b) 10%, white);
    border: 1.5px solid color-mix(in srgb, var(--bchat-primary, #7a1f2b) 25%, transparent);
    color: var(--bchat-primary, #7a1f2b);
    font-size: .8438rem; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.bchat-quick-btn::before { content: "💬"; font-size: .75rem; opacity: .7; flex-shrink: 0; }
.bchat-quick-btn:hover { background: var(--bchat-primary, #7a1f2b); border-color: var(--bchat-primary, #7a1f2b); color: var(--bchat-text, #fff); }

.bchat-cart-summary { align-self: flex-start; max-width: 90%; background: var(--bchat-bot-bg, #fff); border: 1px solid var(--bchat-border, #e5e0db); border-radius: 12px; padding: 12px; font-size: .875rem; }
.bchat-cart-summary table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.bchat-cart-summary td { padding: 4px 0; border-bottom: 1px solid #f0ede8; }
.bchat-cart-actions { display: flex; gap: 8px; }
.bchat-cart-actions a {
    flex: 1; text-align: center; padding: 8px; border-radius: 8px; font-size: .8125rem; font-weight: 600;
    text-decoration: none; background: #f0ede8; color: var(--bchat-dark, #1a1a1a);
}
.bchat-cart-actions a.bchat-checkout-btn { background: var(--bchat-primary, #7a1f2b); color: var(--bchat-text, #fff); }

.bchat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid #eee; background: var(--bchat-bot-bg, #fff); }
.bchat-form input { flex: 1; padding: 10px 12px; border: 1px solid var(--bchat-border, #ddd); border-radius: 20px; font-size: .9rem; }
.bchat-form input:focus { outline: none; border-color: var(--bchat-primary, #7a1f2b); }
.bchat-form button { width: 38px; height: 38px; border-radius: 50%; background: var(--bchat-primary, #7a1f2b); color: var(--bchat-text, #fff); border: none; cursor: pointer; font-size: 1rem; transition: background .15s ease; }
.bchat-form button:hover { background: color-mix(in srgb, var(--bchat-primary, #7a1f2b) 85%, black); }

@media (max-width: 480px) {
    /* Contenitore a tutta larghezza (così il pannello si espande), ma la
       bolla resta sul LATO scelto nelle impostazioni e usa gli offset
       configurati (variabili --bchat-side / --bchat-bottom). Nessun valore
       fisso qui: comandano le impostazioni. */
    #bchat-root.bchat--right,
    #bchat-root.bchat--left {
        left: var(--bchat-side, 16px);
        right: var(--bchat-side, 16px);
        bottom: var(--bchat-bottom, 16px);
        display: flex;
    }
    #bchat-root.bchat--right { justify-content: flex-end; }
    #bchat-root.bchat--left  { justify-content: flex-start; }

    .bchat-panel { width: auto; left: 0; right: 0; }
}

/* ---- Bubble wrap: posiziona label + pallino ---- */
.bchat-bubble-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto; /* eredita il none del parent #bchat-root, va rimesso esplicitamente */
}
.bchat--right .bchat-bubble-wrap { flex-direction: row; }
.bchat--left  .bchat-bubble-wrap { flex-direction: row-reverse; }

/* ---- Label accanto al pallino ---- */
.bchat-bubble-label {
    background: var(--bchat-bot-bg, #fff);
    color: var(--bchat-bot-text, #222);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 2px 12px rgba(0,0,0,.15);
    cursor: pointer;
    user-select: none;
    opacity: 1;
    transform: scale(1);
    transition: opacity .2s ease, transform .2s ease;
    animation: bchat-label-in .3s ease;
}
.bchat-bubble-label.bchat-label-hide {
    opacity: 0;
    transform: scale(.92);
    pointer-events: none;
}
@keyframes bchat-label-in {
    from { opacity: 0; transform: scale(.88); }
    to   { opacity: 1; transform: scale(1); }
}

/* ---- CSS vars per colori e z-index (impostati via PHP, vedi widget.php) ---- */
#bchat-root {
    --bchat-primary:     #7a1f2b;
    --bchat-text:        #ffffff;
    --bchat-bubble-bg:   #7a1f2b;
    --bchat-bubble-icon: #ffffff;
    --bchat-bg:          #faf9f7;
    --bchat-bot-bg:      #ffffff;
    --bchat-bot-text:    #222222;
    --bchat-border:      #e5e0db;
    --bchat-accent:      #b5862e;
    --bchat-dark:        #1a1a1a;
    --bchat-online:      #3ecf6e;
}
