/* Importa il font Roboto (se non è già presente) */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

/* Utility */
.d-none {
    display: none !important;
}

/* --- WIDGET CONTENITORE --- */
#ai-chat-assistant-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 360px;                 /* più largo rispetto ai 280px */
    max-width: calc(100% - 40px);
    /* Altezza gestita in base allo stato */
    height: auto;
    max-height: 60vh;             /* 60% dell’altezza finestra */
    font-family: 'Roboto', sans-serif;
    z-index: 9999;
    box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.2);
    border-radius: 15px;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* Quando la chat è aperta: prende davvero il 60% di viewport */
#ai-chat-assistant-widget.chat-open-widget {
    height: 60vh;
}

/* --- HEADER --- */
#ai-chat-assistant-header {
    padding: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
    font-weight: 700;
}

#ai-chat-assistant-header h5 {
    margin: 0;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 10px;
    text-transform: none;
}

#ai-chat-assistant-header h5 i {
    margin-right: 8px;
    font-size: 1.3rem;
    vertical-align: middle;
}

/* Pulsanti header (clear + toggle) */
#ai-clear-chat-icon,
#ai-chat-assistant-toggle {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
}

/* Focus visibile per tastiera */
#ai-clear-chat-icon:focus-visible,
#ai-chat-assistant-toggle:focus-visible,
#send-message-button:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Quando il box è aperto: header più sottile (opzionale) */
#ai-chat-assistant-header.chat-open {
    padding: 8px 16px;
    font-size: 0.9rem;
}

/* --- CORPO DELLA CHAT --- */
#ai-chat-assistant-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

/* Stato chiuso (collassato): lo nascondiamo del tutto */
#ai-chat-assistant-body.d-none {
    display: none;
}

/* --- AREA MESSAGGI (SCROLL SEMPRE QUI) --- */
#ai-chat-assistant-messages {
    flex: 1 1 auto;
    padding: 12px;
    overflow-y: auto;
    scrollbar-width: thin;
    min-height: 0;
}

/* Scrollbar style */
#ai-chat-assistant-messages::-webkit-scrollbar {
    width: 8px;
}

#ai-chat-assistant-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

/* --- MESSAGGI --- */
.user-message,
.assistant-message {
    margin: 6px 0;
    display: flex;
    align-items: flex-end;
}

/* Allinea i messaggi del mittente a destra e quelli dell'assistente a sinistra */
.user-message {
    display: flex;
    justify-content: flex-end;
    margin: 6px 0;
}

.assistant-message {
    display: flex;
    justify-content: flex-start;
    margin: 6px 0;
}

.user-message .d-inline-block,
.assistant-message .d-inline-block {
    max-width: 75%;
    padding: 8px 10px;
    border-radius: 15px;
    font-size: 0.8rem;
    line-height: 1.4;
}

/* Messaggi dell'utente (tail in basso a destra) */
.user-message .d-inline-block {
    position: relative;
    background-color: #d0eaff;
    color: #333;
    padding: 10px 14px;
    border-radius: 15px;
    max-width: 75%;
    text-align: right;
}

.user-message .d-inline-block::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: -1px;
    border-width: 10px 0 0 10px;
    border-style: solid;
    border-color: transparent transparent transparent #d0eaff;
}

/* Messaggi dell'assistente (tail in basso a sinistra) */
.assistant-message .d-inline-block {
    position: relative;
    background-color: #fce8d5;
    color: #333;
    padding: 10px 14px;
    border-radius: 15px;
    max-width: 75%;
    text-align: left;
}

.assistant-message .d-inline-block::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: -1px;
    border-width: 10px 10px 0 0;
    border-style: solid;
    border-color: transparent #fce8d5 transparent transparent;
}

.loading-indicator .d-inline-block {
    color: #999999;
    font-style: italic;
}

/* --- INPUT --- */
#ai-chat-assistant-input {
    padding: 10px;
    display: flex;
    align-items: center;
    border-top: 1px solid #e9ecef;
    background-color: #f8f9fa;
}

#ai-chat-assistant-input textarea {
    flex: 1;
    resize: none;
    border-radius: 5px;
    padding: 10px;
    font-size: 0.8rem;
    font-family: 'Roboto', sans-serif;
    border: 1px solid #ced4da;
    transition: border-color 0.2s;
}

#ai-chat-assistant-input textarea:focus {
    border-color: #7bc4b2;
    outline: none;
}

#ai-chat-assistant-input button {
    border: none;
    width: 40px;
    height: 40px;
    background-color: #343a40;
    color: #f7f7f7;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

#ai-chat-assistant-input button:hover {
    background-color: #f7f7f7;
    color: #343a40;
    border: 1px solid #343a40;
}

/* --- LINK --- */
.ai-chat-link {
    text-decoration: underline;
    color: #007cba;
    font-weight: 700;
}

.ai-chat-link:hover {
    color: #005a8e;
}

/* Riduci la dimensione dei link utili */
#ai-chat-assistant-quick-links a {
    font-size: 0.7rem !important;
}

/* --- ADATTAMENTO SCHERMI MOLTO BASSI (per viewport basse) --- */
@media (max-height: 500px) {
    #ai-chat-assistant-widget.chat-open-widget {
        top: 10px;
        bottom: auto;
        max-height: 70vh;
        height: 70vh;
    }
}

/* --- MOBILE / ZOOM FORTE --- */
/* Altezza su mobile quando la chat è aperta */
@media (max-width: 767px) {
    #ai-chat-assistant-widget.chat-open-widget {
        height: 80vh;
        max-height: 80vh;
    }

    /* Quando la tastiera è aperta (classe aggiunta via JS) */
    #ai-chat-assistant-widget.chat-open-widget.keyboard-open {
        height: 45vh;
        max-height: 45vh;
    }
}


/* Schermi stretti / zoom alto (≈ oltre 250–300%) */
@media (max-width: 800px) {

    /* CHAT APERTA: widget normale, grande */
    #ai-chat-assistant-widget.chat-open-widget {
        width: calc(100% - 20px);
        right: 10px;
        bottom: 10px;
        border-radius: 15px;
    }

    #ai-chat-assistant-widget:not(.chat-open-widget) {
    width: 120px;              /* PIÙ STRETTO, REGOLA QUI SE LO VUOI DIVERSO */
    right: 10px;
    bottom: 10px;
    border-radius: 999px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}


    /* Header dentro la pillola: niente spazio inutile */
    #ai-chat-assistant-widget:not(.chat-open-widget) #ai-chat-assistant-header {
        padding: 6px 8px;
        margin: 0;
        width: 100%;
        height: auto;
        display: flex;
        align-items: center;
        justify-content: center;   /* niente space-between */
        gap: 0px;                  /* quasi attaccati */
    }

    /* Nascondi il testo "Chatta con Viktor" da chiuso */
    #ai-chat-assistant-widget:not(.chat-open-widget) #ai-chat-assistant-header h5 {
        display: none;
    }

    /* Avatar */
    #ai-chat-assistant-widget:not(.chat-open-widget) #ai-chat-assistant-bot-image {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        margin: 0;
    }

    /* Contenitore freccia: niente margin-left:auto */
    #ai-chat-assistant-widget:not(.chat-open-widget) #ai-chat-assistant-header > div {
        margin-left: 0 !important;
        display: flex;
        align-items: center;
        gap: 0px;                  /* spazio minimo tra bot e freccia */
    }

    /* Nascondi il cestino quando è chiuso */
    #ai-chat-assistant-widget:not(.chat-open-widget) #ai-clear-chat-icon {
        display: none !important;
    }
}
