/*
 * Assistente AI AllTours - widget di chat
 * Stili isolati sotto il prefisso .at-ai per non interferire con il resto del sito.
 */

.at-ai {
    --at-ai-orange: var(--orange-color, #ff7900);
    --at-ai-orange-dark: var(--orange-dark-color, #e3730e);
    --at-ai-blue: var(--blue-dark-color, #003366);
    --at-ai-bg: #ffffff;
    --at-ai-surface: #f4f6f8;
    --at-ai-border: #e3e7eb;
    --at-ai-text: #23272b;
    --at-ai-muted: #6c757d;
    --at-ai-radius: 16px;

    position: fixed;
    right: 20px;
    bottom: 20px;
    /* Sopra l'header sticky (1030) ma sotto offcanvas (1045) e modali (1055):
       il menu mobile e le modali del sito devono restare in primo piano. */
    z-index: 1040;
    font-family: var(--bs-font-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
    font-size: 15px;
    line-height: 1.5;
    color: var(--at-ai-text);
}

/* Il "torna su" del sito vive nello stesso angolo: lo alziamo sopra il launcher.
   Questo foglio di stile viene incluso solo quando l'assistente e attivo. */
.tornasu {
    bottom: 78px;
}

/* ---------- Bottone flottante ---------- */

.at-ai__launcher {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px 12px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--at-ai-orange);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.at-ai__launcher:hover {
    background: var(--at-ai-orange-dark);
    transform: translateY(-1px);
}

.at-ai__launcher:focus-visible {
    outline: 3px solid var(--at-ai-blue);
    outline-offset: 2px;
}

.at-ai__launcher svg {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
}

.at-ai.is-open .at-ai__launcher {
    display: none;
}

/* ---------- Pannello ---------- */

.at-ai__panel {
    display: none;
    flex-direction: column;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 120px));
    background: var(--at-ai-bg);
    border-radius: var(--at-ai-radius);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.26);
    overflow: hidden;
}

.at-ai.is-open .at-ai__panel {
    display: flex;
}

.at-ai__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--at-ai-blue);
    color: #fff;
}

.at-ai__avatar {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--at-ai-orange);
}

.at-ai__avatar svg {
    width: 20px;
    height: 20px;
}

.at-ai__title {
    flex: 1 1 auto;
    min-width: 0;
}

.at-ai__title strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
}

.at-ai__title span {
    display: block;
    font-size: 12px;
    opacity: 0.8;
}

.at-ai__iconbtn {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #fff;
    cursor: pointer;
    opacity: 0.85;
}

.at-ai__iconbtn:hover {
    background: rgba(255, 255, 255, 0.14);
    opacity: 1;
}

.at-ai__iconbtn svg {
    width: 18px;
    height: 18px;
}

/* ---------- Conversazione ---------- */

.at-ai__log {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    background: var(--at-ai-surface);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.at-ai__msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.at-ai__msg--bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--at-ai-border);
    border-bottom-left-radius: 4px;
}

.at-ai__msg--user {
    align-self: flex-end;
    background: var(--at-ai-blue);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.at-ai__msg--errore {
    align-self: stretch;
    max-width: 100%;
    background: #fff4e5;
    border: 1px solid #ffd9a8;
    color: #8a4b00;
    font-size: 14px;
}

.at-ai__msg p {
    margin: 0 0 8px;
}

.at-ai__msg p:last-child {
    margin-bottom: 0;
}

.at-ai__msg ul {
    margin: 0 0 8px;
    padding-left: 20px;
}

.at-ai__msg li {
    margin-bottom: 4px;
}

/* I link generati dall'assistente sono azioni ("vai alla scheda", "guarda
   questa data"): resi come bottoni arancioni a tutta larghezza si distinguono
   dal testo e restano comodi da toccare su mobile. */
.at-ai__cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin: 10px 0 2px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--at-ai-orange);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.at-ai__cta:hover,
.at-ai__cta:focus {
    background: var(--at-ai-orange-dark);
    color: #fff;
    text-decoration: none;
}

.at-ai__cta:focus-visible {
    outline: 3px solid var(--at-ai-blue);
    outline-offset: 2px;
}

.at-ai__cta svg {
    width: 15px;
    height: 15px;
    flex: 0 0 auto;
    opacity: 0.85;
}

/* Seconda strada, meno accesa del bottone arancione. */
.at-ai__cta--secondario {
    border: 1px solid var(--at-ai-blue);
    background: #fff;
    color: var(--at-ai-blue);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.at-ai__cta--secondario:hover,
.at-ai__cta--secondario:focus {
    background: var(--at-ai-surface);
    color: var(--at-ai-blue);
}

.at-ai__cta--secondario:disabled {
    opacity: 0.6;
    cursor: default;
}

/* Link in mezzo a una frase: resta testo, non bottone. */
.at-ai__link {
    color: var(--at-ai-orange-dark);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.at-ai__link:hover,
.at-ai__link:focus {
    color: var(--at-ai-blue);
}

/* Un bottone da solo nel paragrafo non deve trascinarsi dietro il margine. */
.at-ai__msg p:has(> .at-ai__cta:only-child) {
    margin-bottom: 0;
}

/* Eventuali link non convertiti in bottone restano nei colori del brand. */
.at-ai__msg a:not(.at-ai__cta) {
    color: var(--at-ai-orange-dark);
    font-weight: 600;
    text-decoration: underline;
}

.at-ai__msg--user a {
    color: #ffd9ab;
}

/* ---------- Stato "sta lavorando" ---------- */

.at-ai__attivita {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--at-ai-muted);
    padding: 4px 2px;
}

.at-ai__dots {
    display: inline-flex;
    gap: 3px;
}

.at-ai__dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--at-ai-orange);
    animation: at-ai-bounce 1.1s infinite ease-in-out;
}

.at-ai__dots i:nth-child(2) { animation-delay: 0.15s; }
.at-ai__dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes at-ai-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .at-ai__dots i { animation: none; }
    .at-ai__launcher { transition: none; }
    .at-ai { transition: none; }
}

/* ---------- Suggerimenti ---------- */

.at-ai__suggerimenti {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
    background: var(--at-ai-surface);
}

.at-ai__suggerimento {
    padding: 7px 12px;
    border: 1px solid var(--at-ai-border);
    border-radius: 999px;
    background: #fff;
    font-size: 13px;
    color: var(--at-ai-blue);
    cursor: pointer;
}

.at-ai__suggerimento:hover {
    border-color: var(--at-ai-orange);
    color: var(--at-ai-orange-dark);
}

/* ---------- Composer ---------- */

.at-ai__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--at-ai-border);
    background: #fff;
}

.at-ai__input {
    flex: 1 1 auto;
    max-height: 120px;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--at-ai-border);
    border-radius: 12px;
    font: inherit;
    color: inherit;
    resize: none;
    background: #fff;
}

.at-ai__input:focus {
    outline: none;
    border-color: var(--at-ai-orange);
    box-shadow: 0 0 0 3px rgba(255, 121, 0, 0.15);
}

.at-ai__send {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 12px;
    background: var(--at-ai-orange);
    color: #fff;
    cursor: pointer;
}

.at-ai__send:disabled {
    background: #c9ced3;
    cursor: default;
}

.at-ai__send svg {
    width: 20px;
    height: 20px;
}

.at-ai__disclaimer {
    padding: 0 12px 10px;
    background: #fff;
    font-size: 11px;
    line-height: 1.4;
    color: var(--at-ai-muted);
    text-align: center;
}

/* ---------- Mobile ---------- */

@media (max-width: 575.98px) {
    /* --at-ai-sopra: altezza della barra fissa del preventivo (#atSticky),
       impostata dal widget quando la barra c'e. */
    .at-ai {
        right: 12px;
        bottom: calc(12px + var(--at-ai-sopra, 0px));
        left: 12px;
        transition: bottom 0.2s ease;
    }

    /* Solo icona: su un telefono la pillola con il nome copre troppo. */
    .at-ai__launcher {
        width: 48px;
        height: 48px;
        padding: 0;
        margin-left: auto;
        justify-content: center;
        border-radius: 50%;
        transition: transform 0.25s ease, opacity 0.25s ease, background-color 0.15s ease;
    }

    .at-ai__launcher span {
        display: none;
    }

    .at-ai__launcher svg {
        width: 24px;
        height: 24px;
    }

    /* Mentre si scorre verso il basso sparisce; da fermi o risalendo ricompare. */
    .at-ai.is-nascosto .at-ai__launcher {
        transform: translateY(90px);
        opacity: 0;
        pointer-events: none;
    }

    .at-ai.is-open {
        inset: 0;
    }

    .at-ai__panel {
        width: 100%;
        max-width: none;
        height: 100%;
        border-radius: 0;
    }
}

/* ---------- Schede struttura ---------- */

/* Un link a una struttura che i tool hanno appena restituito si disegna come
   card: foto, stelle, prezzo di partenza e il bottone originale. I dati
   arrivano su un evento a parte, il testo del modello non cambia. */
.at-ai__card {
    margin: 10px 0 4px;
    border: 1px solid var(--at-ai-border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.at-ai__msg li .at-ai__card {
    margin-top: 6px;
}

.at-ai__msg li.at-ai__li-card {
    list-style: none;
    margin-left: -1.1em;
}

.at-ai__card-img {
    display: block;
    aspect-ratio: 16 / 9;
    background: var(--at-ai-surface);
}

.at-ai__card-img img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.at-ai__card-body {
    padding: 10px 12px 12px;
}

.at-ai__card-nome {
    font-weight: 600;
    line-height: 1.3;
    color: var(--at-ai-blue);
}

.at-ai__card-meta {
    margin-top: 2px;
    font-size: 12.5px;
    color: var(--at-ai-muted);
    letter-spacing: 0.02em;
}

.at-ai__card-prezzo {
    margin-top: 6px;
    font-size: 13px;
    color: var(--at-ai-text);
}

.at-ai__card-prezzo strong {
    font-size: 16px;
    color: var(--at-ai-orange-dark);
}

.at-ai__card-prezzo span {
    color: var(--at-ai-muted);
}

.at-ai__card .at-ai__cta {
    margin: 10px 0 0;
}

/* ---------- Pollici ---------- */

/* Sotto l'ultima risposta: "Sei soddisfatto della risposta?" con i due
   pollici. Sulle risposte precedenti restano solo i pollici, piccoli. */
.at-ai__voto {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--at-ai-surface);
}

.at-ai__voto-domanda {
    font-size: 13px;
    color: var(--at-ai-text);
}

.at-ai__voto-bottoni {
    display: inline-flex;
    gap: 2px;
}

.at-ai__voto-btn {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--at-ai-border);
    border-radius: 8px;
    background: #fff;
    color: var(--at-ai-muted);
    cursor: pointer;
}

.at-ai__voto-btn svg {
    width: 15px;
    height: 15px;
}

.at-ai__voto-btn:hover {
    background: var(--at-ai-surface);
    color: var(--at-ai-blue);
}

.at-ai__voto-btn:focus-visible {
    outline: 2px solid var(--at-ai-orange);
    outline-offset: 1px;
}

.at-ai__voto-btn.is-attivo {
    color: var(--at-ai-orange-dark);
    border-color: var(--at-ai-orange);
    background: #fff4e5;
}

.at-ai__voto.is-compatto {
    margin-top: 6px;
    padding-top: 4px;
    border-top: 0;
    justify-content: flex-end;
}

.at-ai__voto.is-compatto .at-ai__voto-domanda {
    display: none;
}

.at-ai__voto.is-compatto .at-ai__voto-btn {
    width: 24px;
    height: 24px;
    border-color: transparent;
    background: transparent;
    opacity: 0.7;
}

.at-ai__voto.is-compatto .at-ai__voto-btn svg {
    width: 12px;
    height: 12px;
}

.at-ai__voto.is-compatto .at-ai__voto-btn.is-attivo {
    opacity: 1;
    color: var(--at-ai-orange-dark);
}
