/*
 * IN.LEAP Chatbot — Widget Styles v1.5.0 — tema GeIAS (geias.it), copia della v1.4.0 CNCP
 * Colori e carattere dal tema WordPress «dsweb» di geias.it (css/style.css e pagina vera, letti il 07/10):
 * blu #2D527F (fondo della testata della home, .bg-header), verde acqua #40B498 (link, linea del tempo),
 * rosso #B45465 (voci dei menu a tendina, .bg-red), giallo #FFD27F (.bg-yellow), testo #303030;
 * carattere Lato (Google Fonts 300/400/700), caricato dal tema su ogni pagina del sito.
 * Banner cookie (plugin Cookie Notice, in basso, sopra tutto): finché è aperto il launcher sale (fondo del file).
 */

/* ── Design tokens ──────────────────────────────────────────────────────── */
#inleap-chat-root {
    /* Palette GeIAS */
    --cb-primary:       #40B498;   /* verde acqua GeIAS — bordi, pulsanti, focus */
    --cb-dark:          #2D527F;   /* blu GeIAS — intestazione, testi dei pulsanti */
    --cb-lime:          #FFD27F;   /* giallo GeIAS — dettagli */
    --cb-accent:        #B45465;   /* rosso GeIAS — launcher, invio, CTA */
    --cb-accent-dim:    rgba(180, 84, 101, 0.12);
    --cb-accent-hover:  #9A4152;   /* rosso scurito hover */
    --cb-primary-dim:   rgba(64, 180, 152, 0.10); /* sfondo bubble utente, hover pulsanti */
    --cb-primary-glow:  rgba(64, 180, 152, 0.20);

    /* Neutri */
    --cb-bg:            #FFFFFF;
    --cb-bg-alt:        #F4F6F8;
    --cb-bg-bubble:     #F2F9F7;   /* bubble bot — bianco con tocco verde acqua */
    --cb-border:        #E0E0E0;
    --cb-border-bubble: #C4E6DD;
    --cb-border-primary:rgba(64, 180, 152, 0.35);
    --cb-text:          #303030;   /* testo del sito */
    --cb-text-muted:    #616567;
    --cb-text-light:    #9A9A9B;

    /* Struttura */
    --r:               6px;
    --rl:              12px;
    --ease:            cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans:       "Lato", "Helvetica Neue", Arial, sans-serif;
    --font-display:    "Lato", "Helvetica Neue", Arial, sans-serif;
    --font-mono:       SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    --chat-w:          380px;
    --chat-h:          570px;
    --launcher-size:   48px;
    --offset-right:    24px;
    --offset-bottom:   24px;  /* geias.it: nessun pulsante fisso in basso a destra (misurato 07/10) */
    --z:               9998;  /* sotto il banner cookie (100000), sopra la barra del sito (1030) */
}

/* ── Reset isolato ──────────────────────────────────────────────────────── */
#inleap-chat-root *,
#inleap-chat-root *::before,
#inleap-chat-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

#inleap-chat-root {
    position: fixed;
    right: var(--offset-right);
    bottom: var(--offset-bottom);
    z-index: var(--z);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--cb-text);
}

/* ── Launcher ───────────────────────────────────────────────────────────── */
.inleap-launcher {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--launcher-size);
    height: var(--launcher-size);
    padding: 0;
    background: var(--cb-accent);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow:
        0 4px 20px rgba(180, 84, 101, 0.40),
        0 2px 8px rgba(0, 0, 0, 0.15);
    transition:
        transform 0.2s var(--ease),
        box-shadow 0.2s var(--ease),
        background 0.2s var(--ease);
}
.inleap-launcher:hover {
    background: var(--cb-accent-hover);
    transform: translateY(-2px);
    box-shadow:
        0 6px 28px rgba(180, 84, 101, 0.50),
        0 3px 12px rgba(0, 0, 0, 0.15);
}
.inleap-launcher:focus-visible {
    outline: 2px solid var(--cb-accent);
    outline-offset: 3px;
}

.inleap-launcher__icon {
    flex-shrink: 0;
    transition: opacity 0.2s var(--ease), transform 0.25s var(--ease);
}
.inleap-launcher__icon--close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}
.inleap-launcher[aria-expanded="true"] .inleap-launcher__icon--chat {
    opacity: 0;
    transform: rotate(90deg);
}
.inleap-launcher[aria-expanded="true"] .inleap-launcher__icon--close {
    opacity: 1;
    transform: rotate(0);
}

.inleap-launcher__label { display: none; }

/* Unread badge */
.inleap-launcher__badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--cb-primary);
    border: 2px solid #ffffff;
    opacity: 0;
    transform: scale(0);
    transition: opacity 0.2s, transform 0.2s;
}
.inleap-launcher__badge.visible {
    opacity: 1;
    transform: scale(1);
}

/* ── Panel ──────────────────────────────────────────────────────────────── */
.inleap-panel {
    position: absolute;
    bottom: calc(var(--launcher-size) + 12px);
    right: 0;
    width: var(--chat-w);
    /* v1.5.0: mai più alto dello spazio sopra il launcher (con il banner cookie aperto il launcher sale) */
    max-height: min(var(--chat-h), calc(100vh - var(--offset-bottom) - var(--launcher-size) - 28px));
    display: flex;
    flex-direction: column;
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: var(--rl);
    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(45, 82, 127, 0.08);
    overflow: hidden;
    transform-origin: bottom right;
    transition:
        opacity 0.22s var(--ease),
        transform 0.22s var(--ease);
    opacity: 0;
    transform: scale(0.94) translateY(10px);
    pointer-events: none;
}
.inleap-panel.open {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

/* ── Panel header ───────────────────────────────────────────────────────── */
.inleap-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px !important;
    flex-shrink: 0;
    background: var(--cb-dark);
    color: #ffffff;
}
.inleap-panel__header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.inleap-panel__avatar {
    position: relative;
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Logo nell'header — contenitore senza sfondo */
.inleap-panel__logo {
    position: relative;
    width: 44px;
    height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.inleap-panel__logo-svg {
    width: 72px;
    height: 44px;
    display: block;
}
/* v1.5.0 GeIAS — logo PNG (la «G» ritagliata da logo-footer.png del sito, bianca su trasparente) */
.inleap-panel__logo-img {
    width: 40px;
    height: auto;
    max-height: 40px;
    display: block;
}

.inleap-panel__pip {
    position: absolute;
    bottom: 2px;
    right: -3px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--cb-lime);
    border: 2px solid var(--cb-dark);
    animation: inleap-pip 2.5s ease infinite;
    z-index: 1;
}
@keyframes inleap-pip {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(1.3); }
}
.inleap-panel__title {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 700;   /* titoli del sito: Lato 700 */
    color: #ffffff;
    letter-spacing: -0.01em;
}
.inleap-panel__subtitle {
    font-family: var(--font-sans);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.78);
    letter-spacing: 0.02em;
    margin-top: 2px;
}
.inleap-panel__close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.70);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--r);
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}
.inleap-panel__close:hover { color: #ffffff; background: rgba(255, 255, 255, 0.12); }
.inleap-panel__close:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.5); outline-offset: 2px; }

/* ── Messages area ──────────────────────────────────────────────────────── */
.inleap-messages {
    flex: 1;
    min-height: 72px;   /* v1.5.0: l'ultima risposta resta visibile anche con molti pulsanti */
    overflow-y: auto;
    padding: 16px 16px 8px !important;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--cb-border) transparent;
    background: var(--cb-bg);
}
.inleap-messages::-webkit-scrollbar { width: 4px; }
.inleap-messages::-webkit-scrollbar-track { background: transparent; }
.inleap-messages::-webkit-scrollbar-thumb { background: var(--cb-border); border-radius: 2px; }

.inleap-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: inleap-msg-in 0.2s var(--ease) both;
}
@keyframes inleap-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Bubble bot — sfondo verde tenue, bordo sinistro verde acqua GeIAS */
.inleap-msg--bot { align-self: flex-start; }
.inleap-msg--bot .inleap-msg__bubble {
    background: var(--cb-bg-bubble) !important;
    border: 0.5px solid var(--cb-border-bubble) !important;
    border-left: 3px solid var(--cb-primary) !important;
    color: var(--cb-text) !important;
    border-radius: 2px var(--rl) var(--rl) var(--rl) !important;
    padding: 10px 13px !important;
    font-size: 13px !important;
    line-height: 1.6 !important;
    word-break: break-word !important;
    white-space: pre-wrap !important;
}
.inleap-msg--bot .inleap-msg__bubble::before { display: none; }

/* Bubble utente — sfondo verde acqua tenue, testo blu GeIAS */
.inleap-msg--user { align-self: flex-end; }
.inleap-msg--user .inleap-msg__bubble {
    background: var(--cb-primary-dim) !important;
    border: 1px solid var(--cb-border-primary) !important;
    color: var(--cb-dark) !important;
    border-radius: var(--rl) 2px var(--rl) var(--rl) !important;
    padding: 10px 16px !important;
    font-size: 14px !important;
    line-height: 1.65 !important;
    word-break: break-word !important;
    font-weight: 500;
}

.inleap-msg__time {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--cb-text-muted);
    letter-spacing: 0.04em;
    margin-top: 4px;
    padding: 0 4px;
}
.inleap-msg--user .inleap-msg__time { text-align: right; }

/* ── Typing indicator ───────────────────────────────────────────────────── */
.inleap-typing {
    display: none;
    align-items: center;
    gap: 5px;
    padding: 0 16px 10px !important;
    flex-shrink: 0;
    background: var(--cb-bg);
}
.inleap-typing.visible { display: flex; }
.inleap-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--cb-primary);
    animation: inleap-bounce 1.2s ease infinite;
}
.inleap-typing span:nth-child(2) { animation-delay: 0.15s; }
.inleap-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes inleap-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Quick replies ──────────────────────────────────────────────────────── */
.inleap-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px !important;
    /* v1.5.0: con poco spazio (telefono piccolo, banner cookie aperto, menu P.A. a 9 pulsanti) i pulsanti
       scorrono invece di spingere fuori dal pannello il campo di scrittura (misurato 320×640, 07/10) */
    flex-shrink: 1;
    min-height: 64px;
    overflow-y: auto;
    background: var(--cb-bg);
}
.inleap-quick-replies:empty { display: none; }

/* Default: outline verde acqua GeIAS, testo blu, pill arrotondato */
.inleap-qr {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px !important;
    background: var(--cb-bg);
    border: 1px solid var(--cb-primary);
    border-radius: 50px;
    color: var(--cb-dark);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 400;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}
.inleap-qr:hover {
    border-color: var(--cb-dark);
    color: var(--cb-dark);
    background: var(--cb-primary-dim);
}
.inleap-qr:focus-visible { outline: 2px solid var(--cb-primary); outline-offset: 2px; }

/* CTA principale — arancio pieno */
.inleap-qr--cta-call {
    background: var(--cb-accent);
    border-color: var(--cb-accent);
    color: #ffffff;
    font-weight: 700;
}
.inleap-qr--cta-call:hover {
    background: var(--cb-accent-hover);
    border-color: var(--cb-accent-hover);
    color: #ffffff;
}

/* CTA form — outline arancio */
.inleap-qr--cta-form {
    border-color: var(--cb-accent);
    color: var(--cb-accent);
    font-weight: 600;
}
.inleap-qr--cta-form:hover {
    background: var(--cb-accent-dim);
    color: var(--cb-accent-hover);
}

/* Link esterni (email, form, calendario) — verde evidenziato */
.inleap-qr--calendar {
    border: 1.5px solid var(--cb-primary);
    color: var(--cb-dark);
    font-weight: 700;
    box-shadow: 0 0 6px var(--cb-primary-glow);
}
.inleap-qr--calendar:hover {
    background: var(--cb-primary-dim);
    border-color: var(--cb-dark);
    box-shadow: 0 0 10px var(--cb-primary-glow);
}

/* ── Privacy notice ─────────────────────────────────────────────────────── */
.inleap-privacy {
    margin: 0 16px 10px !important;
    padding: 16px !important;
    background: var(--cb-bg-alt);
    border: 1px solid var(--cb-border);
    border-radius: var(--r);
    flex-shrink: 0;
}
.inleap-privacy p { font-size: 12px; color: var(--cb-text-muted); line-height: 1.55; margin-bottom: 10px; }
.inleap-privacy__title { font-weight: 700; color: var(--cb-text) !important; }
.inleap-privacy a { color: var(--cb-primary); text-decoration: none; }
.inleap-privacy a:hover { color: var(--cb-dark); text-decoration: underline; }
.inleap-privacy__consent { font-size: 11px; color: var(--cb-text-muted); }
.inleap-privacy__actions { display: flex; gap: 8px; margin-top: 12px; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.inleap-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 50px;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
    transition: opacity 0.15s, transform 0.15s, background 0.15s;
}
.inleap-btn:focus-visible { outline: 2px solid var(--cb-primary); outline-offset: 2px; }
/* Acconsento → arancio */
.inleap-btn--primary {
    background: var(--cb-accent);
    color: #ffffff;
    border-color: var(--cb-accent);
}
.inleap-btn--primary:hover { background: var(--cb-accent-hover); transform: translateY(-1px); }
/* Non acconsento → ghost */
.inleap-btn--ghost {
    background: transparent;
    color: var(--cb-text-muted);
    border-color: var(--cb-border);
}
.inleap-btn--ghost:hover { color: var(--cb-text); border-color: var(--cb-text-muted); }
.inleap-btn--decline {
    background: transparent;
    color: var(--cb-text-muted);
    border: none;
    font-weight: 400;
    padding: 9px 10px;
}
.inleap-btn--decline:hover { color: #dc3545; }

/* ── Input area ─────────────────────────────────────────────────────────── */
.inleap-input-area {
    border-top: 1px solid var(--cb-border);
    padding: 10px 16px !important;
    background: var(--cb-bg-alt);
    flex-shrink: 0;
}
.inleap-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--cb-bg);
    border: 1px solid var(--cb-border);
    border-radius: var(--r);
    padding: 9px 10px 9px 14px !important;
    transition: border-color 0.15s var(--ease);
}
.inleap-input-wrap:focus-within { border-color: var(--cb-primary); }

.inleap-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--cb-text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    max-height: 100px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--cb-border) transparent;
}
.inleap-input::placeholder { color: var(--cb-text-muted); }

/* Tasto invio — arancio (CTA principale) */
.inleap-send-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cb-accent);
    color: #ffffff;
    border: none;
    border-radius: var(--r);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s, transform 0.15s;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    font-family: var(--font-sans);
}
.inleap-send-btn:disabled {
    background: var(--cb-accent);
    color: rgba(255, 255, 255, 0.45);
    cursor: default;
    opacity: 0.6;
}
.inleap-send-btn:not(:disabled):hover {
    background: var(--cb-accent-hover);
    transform: translateY(-1px);
}
.inleap-send-btn:focus-visible { outline: 2px solid var(--cb-accent); outline-offset: 2px; }

.inleap-input-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 6px;
    padding: 0 2px;
}
.inleap-input-footer__brand {
    font-family: var(--font-sans);
    font-size: 9px;
    color: var(--cb-text-light);
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0.8;
}
.inleap-input-footer__brand a {
    color: var(--cb-primary);
    text-decoration: none;
}
.inleap-input-footer__brand a:hover {
    text-decoration: underline;
}

/* ── Error ──────────────────────────────────────────────────────────────── */
.inleap-msg--error .inleap-msg__bubble {
    background: rgba(220, 53, 69, 0.06) !important;
    border-color: #dc3545 !important;
    color: #dc3545 !important;
}
.inleap-msg--error .inleap-msg__bubble::before { background: #dc3545; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #inleap-chat-root {
        --chat-w:        calc(100vw - 16px);
        --offset-right:  8px;
        --offset-bottom: 16px;
    }
    .inleap-panel {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(var(--offset-bottom) + var(--launcher-size) + 12px);
        width: auto;
        max-height: min(70vh, calc(100vh - var(--offset-bottom) - var(--launcher-size) - 28px));
    }
    /* Previene zoom automatico Safari iOS su focus input (soglia: 16px) */
    .inleap-input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .inleap-panel, .inleap-launcher, .inleap-msg,
    .inleap-typing span, .inleap-panel__pip, .inleap-launcher--pulse {
        animation: none;
        transition: opacity 0.1s;
    }
}

/* ── Scroll trigger — pulse launcher (mobile) ───────────────────────────── */
@keyframes inleap-pulse {
    0%   { box-shadow: 0 0 0 0  rgba(180, 84, 101, 0.50); }
    70%  { box-shadow: 0 0 0 14px rgba(180, 84, 101, 0); }
    100% { box-shadow: 0 0 0 0  rgba(180, 84, 101, 0); }
}
.inleap-launcher--pulse {
    animation: inleap-pulse 0.9s ease-out 3;
}

/* ── v1.5.0 GeIAS — banner cookie aperto ─────────────────────────────────
 * Il banner del plugin Cookie Notice sta in basso su tutta la larghezza, sopra tutto (z-index 100000),
 * finché il visitatore non preme «Ok» o la X; intanto il body ha la classe «cookies-not-set», che il plugin
 * toglie appena il banner si chiude. Altezza del banner misurata il 07/10 su geias.it:
 * 320 px → 166 · 375 → 146 · 480 e 600 → 126 · 768 e 1024 → 106 · 1280 e 1366 → 86 · 1440 → 61.
 * Il launcher sta 16 px sopra il banner; senza il banner torna al suo posto. */
body.cookies-not-set #inleap-chat-root { --offset-bottom: 77px; }
@media (max-width: 1439px) { body.cookies-not-set #inleap-chat-root { --offset-bottom: 122px; } }
@media (max-width: 767px)  { body.cookies-not-set #inleap-chat-root { --offset-bottom: 142px; } }
@media (max-width: 480px)  { body.cookies-not-set #inleap-chat-root { --offset-bottom: 182px; } }
