/* Hubix AI chat (/cashback/hubix-ai). Tutto e' sotto #hubix-ai: il template stilizza a, button e h* in modo globale. */

#hubix-ai {
    --hai-blue: var(--color-tertiary, #006ef7);
    --hai-navy: var(--color-text, #142c47);
    --hai-muted: var(--hb-gray, #6a7c92);
    --hai-soft: var(--bg-soft, #eef2f9);
    --hai-border: var(--border-soft-2, rgba(0, 70, 143, .15));
    --hai-green: #1f9d55;
    --hai-radius: var(--border-radius-md, 18px);
    color: var(--hai-navy);
    padding: 24px 0 40px;
}

#hubix-ai .cb-hai-container {
    max-width: 960px;
}

/* ----- Intestazione ----- */

#hubix-ai .cb-hai-head {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
}

#hubix-ai .cb-hai-badge,
#hubix-ai .cb-hai-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #036aff 0%, #7b5cff 100%);
}

#hubix-ai .cb-hai-badge {
    width: 52px;
    height: 52px;
    font-size: 24px;
}

#hubix-ai .cb-hai-title {
    font-size: 30px;
    font-weight: 700;
    line-height: 1.1;
    margin: 0 0 6px;
    color: var(--hai-navy);
}

#hubix-ai .cb-hai-title span {
    color: var(--hai-blue);
}

#hubix-ai .cb-hai-subtitle {
    margin: 0;
    /* color: var(--hai-muted); */
    font-size: 15px;
    max-width: 620px;
}

#hubix-ai .cb-hai-reset {
    margin-left: auto;
    flex: 0 0 auto;
    border: 1px solid var(--hai-border);
    background: #fff;
    color: var(--hai-navy);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 14px!important;
    font-weight: 500;
    line-height: 1.4;
    width: auto;
    height: auto;
}

#hubix-ai .cb-hai-reset:hover {
    border-color: var(--hai-blue);
    color: var(--hai-blue);
}

/* ----- Benvenuto ----- */

#hubix-ai .cb-hai-welcome {
    margin: 12px 0 20px;
}

#hubix-ai .cb-hai-welcome-label {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--hai-muted);
    margin-bottom: 10px;
}

#hubix-ai .cb-hai-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#hubix-ai .cb-hai-example {
    border: 1px solid var(--hai-border);
    background: #fff;
    color: var(--hai-navy);
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 14px;
    line-height: 1.3;
    text-align: left;
    width: auto;
    height: auto;
    transition: border-color .2s, color .2s, background .2s;
}

#hubix-ai .cb-hai-example:hover {
    border-color: var(--hai-blue);
    color: var(--hai-blue);
    background: var(--hai-soft);
}

/* ----- Conversazione ----- */

#hubix-ai .cb-hai-thread {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 18px;
}

#hubix-ai .cb-hai-msg p {
    margin: 0 0 8px;
    font-size: 15px;
    line-height: 1.55;
}

#hubix-ai .cb-hai-msg p:last-child {
    margin-bottom: 0;
}

#hubix-ai .cb-hai-msg--user {
    align-self: flex-end;
    max-width: 80%;
    background: var(--hai-blue);
    color: #fff;
    border-radius: var(--hai-radius) var(--hai-radius) 4px var(--hai-radius);
    padding: 10px 16px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#hubix-ai .cb-hai-msg--user p {
    color: #fff;
}

#hubix-ai .cb-hai-msg--assistant,
#hubix-ai .cb-hai-msg--error {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

#hubix-ai .cb-hai-avatar {
    width: 34px;
    height: 34px;
    font-size: 16px;
    margin-top: 2px;
}

#hubix-ai .cb-hai-msg-body {
    flex: 1 1 auto;
    min-width: 0;
}

#hubix-ai .cb-hai-text {
    background: #fff;
    border: 1px solid var(--hai-border);
    border-radius: 4px var(--hai-radius) var(--hai-radius) var(--hai-radius);
    padding: 12px 16px;
    display: inline-block;
    max-width: 100%;
}

#hubix-ai .cb-hai-msg--error .cb-hai-text {
    border-color: rgba(255, 51, 76, .35);
    background: #fff6f7;
}

#hubix-ai .cb-hai-msg--error .cb-hai-avatar {
    background: var(--hai-muted);
}

#hubix-ai .cb-hai-thinking {
    display: inline-flex !important;
    align-items: center;
    gap: 10px;
    color: var(--hai-muted);
    background: #fff;
    border: 1px solid var(--hai-border);
    border-radius: 4px var(--hai-radius) var(--hai-radius) var(--hai-radius);
    padding: 12px 16px;
}

#hubix-ai .cb-hai-dots {
    display: inline-flex;
    gap: 4px;
}

#hubix-ai .cb-hai-dots i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--hai-blue);
    animation: cb-hai-dot 1.2s infinite ease-in-out;
}

#hubix-ai .cb-hai-dots i:nth-child(2) { animation-delay: .15s; }
#hubix-ai .cb-hai-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes cb-hai-dot {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    #hubix-ai .cb-hai-dots i { animation: none; opacity: .6; }
}

#hubix-ai .cb-hai-steps {
    font-size: 13px;
    color: var(--hai-muted);
    margin-bottom: 6px;
}

#hubix-ai .cb-hai-steps summary {
    cursor: pointer;
    width: fit-content;
}

#hubix-ai .cb-hai-steps ul {
    margin: 6px 0 0;
    padding-left: 18px;
}

#hubix-ai .cb-hai-steps li {
    list-style: disc;
}

/* ----- Schede ----- */

#hubix-ai .cb-hai-results {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#hubix-ai .cb-hai-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

#hubix-ai .cb-hai-grid--products {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
}

#hubix-ai .cb-hai-card {
    background: #fff;
    border: 1px solid var(--hai-border);
    border-radius: var(--hai-radius);
    padding: 16px;
    display: flex;
    gap: 14px;
    min-width: 0;
    box-shadow: 0 4px 16px rgba(20, 44, 71, .05);
}

#hubix-ai .cb-hai-card h3 {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    margin: 0 0 6px;
    color: var(--hai-navy);
}

#hubix-ai .cb-hai-muted {
    color: var(--hai-muted);
    font-size: 13px !important;
    margin: 0 0 4px !important;
}

#hubix-ai .cb-hai-product-img {
    flex: 0 0 96px;
    height: 96px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid var(--hai-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--hai-muted);
    font-size: 28px;
}

#hubix-ai .cb-hai-product-img img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#hubix-ai .cb-hai-product-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

#hubix-ai .cb-hai-saving {
    align-self: flex-start;
    background: rgba(31, 157, 85, .1);
    color: var(--hai-green);
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    padding: 3px 10px;
    margin-bottom: 8px;
}

#hubix-ai .cb-hai-product-from {
    font-size: 14px !important;
}

#hubix-ai .cb-hai-calc {
    margin: 0 0 10px;
    font-size: 13.5px;
}

#hubix-ai .cb-hai-calc > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 3px 0;
}

#hubix-ai .cb-hai-calc dt {
    font-weight: 400;
    color: var(--hai-muted);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

#hubix-ai .cb-hai-calc dt small {
    font-size: 11.5px;
}

#hubix-ai .cb-hai-calc dd {
    margin: 0;
    font-weight: 600;
    white-space: nowrap;
}

#hubix-ai .cb-hai-calc .is-voucher dd,
#hubix-ai .cb-hai-calc .is-cashback dd {
    color: var(--hai-green);
}

#hubix-ai .cb-hai-calc .is-pay {
    border-top: 1px dashed var(--hai-border);
}

#hubix-ai .cb-hai-calc .is-net {
    border-top: 1px solid var(--hai-border);
    margin-top: 4px;
    padding-top: 6px;
}

#hubix-ai .cb-hai-calc .is-net dt {
    color: var(--hai-navy);
    font-weight: 600;
}

#hubix-ai .cb-hai-calc .is-net dd {
    color: var(--hai-blue);
    font-size: 17px;
}

#hubix-ai .cb-hai-code {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px dashed var(--hai-blue);
    background: var(--hai-soft);
    color: var(--hai-blue);
    border-radius: 8px;
    padding: 2px 8px;
    font-size: 12.5px;
    font-weight: 600;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    line-height: 1.5;
    width: auto;
    height: auto;
    max-width: 100%;
}

#hubix-ai .cb-hai-code-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#hubix-ai .cb-hai-code.is-copied {
    border-style: solid;
    background: var(--hai-green);
    border-color: var(--hai-green);
    color: #fff;
}

#hubix-ai .cb-hai-code.is-copied .bi-copy::before {
    content: "\F26E"; /* bi-check */
}

#hubix-ai .cb-hai-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin-top: auto;
    padding-top: 6px;
}

#hubix-ai .cb-hai-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--hai-blue);
    color: #fff;
    border: 0;
    border-radius: var(--hb-cta-border-radius, 10px);
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
    width: auto;
    height: auto;
    transition: background .2s;
}

#hubix-ai .cb-hai-cta:hover {
    background: #0057c8;
    color: #fff;
}

#hubix-ai .cb-hai-link {
    color: var(--hai-blue);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

#hubix-ai .cb-hai-link:hover {
    text-decoration: underline;
}

#hubix-ai .cb-hai-merchant {
    flex-direction: column;
    gap: 10px;
}

#hubix-ai .cb-hai-merchant-head {
    display: flex;
    align-items: center;
    gap: 12px;
}

#hubix-ai .cb-hai-merchant-logo {
    flex: 0 0 56px;
    height: 56px;
    border-radius: 12px;
    border: 1px solid var(--hai-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fff;
    color: var(--hai-muted);
    font-size: 22px;
}

#hubix-ai .cb-hai-merchant-logo img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

#hubix-ai .cb-hai-merchant-name {
    margin-bottom: 2px !important;
}

#hubix-ai .cb-hai-merchant-cb {
    margin: 0 !important;
    font-size: 14px !important;
    color: var(--hai-green);
}

#hubix-ai .cb-hai-voucher {
    background: var(--hai-soft);
    border-radius: 12px;
    padding: 10px 12px;
}

#hubix-ai .cb-hai-voucher-title {
    font-size: 14px !important;
    font-weight: 600;
    margin-bottom: 4px !important;
}

#hubix-ai .cb-hai-voucher .cb-hai-code {
    margin: 4px 0;
}

#hubix-ai .cb-hai-gift {
    align-items: center;
}

#hubix-ai .cb-hai-gift-img {
    flex: 0 0 72px;
    height: 48px;
    border-radius: 8px;
    border: 1px solid var(--hai-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fff;
    color: var(--hai-muted);
    font-size: 22px;
}

#hubix-ai .cb-hai-gift-img img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

#hubix-ai .cb-hai-more {
    align-self: flex-start;
    color: var(--hai-blue);
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#hubix-ai .cb-hai-more:hover {
    text-decoration: underline;
}

/* ----- Campo di scrittura ----- */

#hubix-ai .cb-hai-composer {
    position: sticky;
    bottom: 12px;
    z-index: 5;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #fff;
    border: 1.5px solid var(--hai-border);
    border-radius: 26px;
    padding: 8px 8px 8px 18px;
    box-shadow: 0 8px 28px rgba(20, 44, 71, .12);
    transition: border-color .2s;
}

#hubix-ai .cb-hai-composer:focus-within {
    border-color: var(--hai-blue);
}

#hubix-ai .cb-hai-input {
    flex: 1 1 auto;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--hai-navy);
    font-size: 16px; /* sotto i 16px Safari iOS ingrandisce la pagina al focus */
    line-height: 1.45;
    padding: 8px 0;
    max-height: 160px;
    min-height: 24px;
}

#hubix-ai .cb-hai-send {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 0;
    background: var(--hai-blue);
    color: #fff;
    font-size: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background .2s, opacity .2s;
}

#hubix-ai .cb-hai-send:hover {
    background: #0057c8;
}

#hubix-ai .cb-hai-send:disabled {
    opacity: .5;
    cursor: wait;
}

#hubix-ai .cb-hai-disclaimer {
    margin: 10px 4px 0;
    font-size: 12px;
    color: var(--hai-muted);
    /* text-align: center; */
    line-height: 1.6;
}

/* ----- Mobile ----- */

@media (max-width: 767.98px) {
    #hubix-ai {
        padding-top: 12px;
    }

    #hubix-ai .cb-hai-title {
        font-size: 24px;
        margin: 0;
    }

    #hubix-ai .cb-hai-badge {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    #hubix-ai .cb-hai-head {
        flex-wrap: wrap;
        align-items: center;
    }

    #hubix-ai.has-chat .cb-hai-subtitle {
        display: none;
    }

    #hubix-ai .cb-hai-msg--user {
        max-width: 92%;
    }

    #hubix-ai .cb-hai-avatar {
        display: none;
    }

    #hubix-ai .cb-hai-grid,
    #hubix-ai .cb-hai-grid--products {
        grid-template-columns: 1fr;
    }

    #hubix-ai .cb-hai-product-img {
        flex-basis: 76px;
        height: 76px;
    }
}
