/* =====================================================================
   ASSISTANT DE CONVERSATION — coin bas-droit
   =====================================================================

   La couleur de fond est choisie en administration (--cb-fond). L'encre
   (--cb-encre) ne l'est PAS : elle est calculée côté serveur par
   App\Support\Couleur, blanche ou sombre selon ce qui contraste le mieux.
   L'icône de la bulle est son seul contenu, elle relève donc du critère
   WCAG 1.4.11 et doit atteindre 3:1.

   Le fil de conversation garde un fond neutre quelle que soit cette couleur :
   seules la bulle, l'en-tête et les messages du visiteur la portent.
   ===================================================================== */

.cb {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1070;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.6rem;
}

/* Le bandeau de consentement (z-index 1080) occupe tout le bas de l'écran.
   Tant qu'il est là, l'assistant s'efface plutôt que d'être à moitié couvert :
   le bandeau doit rester la seule chose à traiter.

   Sans prise en charge de :has(), l'assistant passe simplement derrière —
   même résultat visible. */
body:has(#consentement:not([hidden])) .cb {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ---------- Accroche ---------- */

.cb-accroche {
    position: relative;
    max-width: 15rem;
    margin: 0;
    padding: 0.6rem 2rem 0.6rem 0.9rem;
    border-radius: 0.8rem 0.8rem 0.2rem 0.8rem;
    background: #fff;
    color: #12202F;
    font-size: 0.88rem;
    font-weight: 700;
    line-height: 1.35;
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.18);
}

.cb-accroche-x {
    position: absolute;
    top: 0.25rem;
    right: 0.35rem;
    width: 1.4rem;
    height: 1.4rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #5A6472;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.cb-accroche-x:hover {
    background: #EDE9E1;
    color: #12202F;
}

.cb--ouvert .cb-accroche {
    display: none;
}

/* ---------- La bulle ---------- */

.cb-bulle {
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: var(--cb-fond, #128C7E);
    color: var(--cb-encre, #fff);
    font-size: 1.6rem;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cb-bulle:hover {
    transform: scale(1.07);
    box-shadow: 0 10px 26px rgba(16, 24, 40, 0.38);
}

.cb-bulle:focus-visible {
    outline: 3px solid #12202F;
    outline-offset: 3px;
}

/* ---------- Le panneau ---------- */

.cb-panneau {
    display: flex;
    flex-direction: column;
    width: 22rem;
    max-width: calc(100vw - 2rem);
    height: 30rem;
    max-height: calc(100vh - 7rem);
    overflow: hidden;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 20px 50px rgba(16, 24, 40, 0.3);
}

.cb-panneau[hidden] {
    display: none;
}

.cb-tete {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--cb-fond, #128C7E);
    color: var(--cb-encre, #fff);
}

.cb-tete-txt {
    display: grid;
    min-width: 0;
}

.cb-tete-txt strong {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.2;
}

.cb-tete-txt span {
    font-size: 0.78rem;
    font-weight: 600;
    opacity: 0.85;
}

.cb-tete-act {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
}

.cb-icone {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

.cb-icone:hover {
    /* Un voile plutôt qu'une couleur fixe : il fonctionne aussi bien sur un
       en-tête sombre que clair, l'administration choisissant la couleur. */
    background: rgba(127, 127, 127, 0.28);
}

.cb-icone:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 1px;
}

/* ---------- Le fil ---------- */

.cb-fil {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
    background: #F4F1EB;
    scrollbar-width: thin;
}

.cb-fil::-webkit-scrollbar {
    width: 8px;
}

.cb-fil::-webkit-scrollbar-thumb {
    background: #CFC8BC;
    border-radius: 4px;
}

.cb-msg {
    max-width: 85%;
    margin: 0 0 0.55rem;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-line;
}

/* #12202F sur #fff : 16,49:1. */
.cb-msg--bot {
    border-radius: 0.9rem 0.9rem 0.9rem 0.2rem;
    background: #fff;
    color: #12202F;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.1);
}

.cb-msg--moi {
    margin-left: auto;
    border-radius: 0.9rem 0.9rem 0.2rem 0.9rem;
    background: var(--cb-fond, #128C7E);
    color: var(--cb-encre, #fff);
    font-weight: 600;
}

/* ---------- Points de frappe ---------- */

.cb-frappe {
    display: flex;
    gap: 0.28rem;
    width: max-content;
    padding: 0.75rem 0.85rem;
}

.cb-frappe span {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: #9AA3AF;
    animation: cb-rebond 1.2s infinite ease-in-out;
}

.cb-frappe span:nth-child(2) { animation-delay: 0.15s; }
.cb-frappe span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cb-rebond {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.55; }
    30%           { transform: translateY(-0.28rem); opacity: 1; }
}

/* ---------- Les choix ---------- */

.cb-choix {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    max-height: 9.5rem;
    overflow-y: auto;
    padding: 0.7rem;
    border-top: 1px solid #E6E1D8;
    background: #fff;
}

.cb-choix:empty {
    display: none;
}

/* Bordure #5A6472 sur #fff : 5,74:1, bien au-delà des 3:1 demandés pour un
   contour de commande. */
.cb-choix-b {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.85rem;
    border: 1px solid #5A6472;
    border-radius: 999px;
    background: #fff;
    color: #12202F;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.3;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.cb-choix-b:hover,
.cb-choix-b:focus-visible {
    border-color: #12202F;
    background: #EDE9E1;
    color: #12202F;
}

.cb-choix-b:focus-visible {
    outline: 2px solid #12202F;
    outline-offset: 2px;
}

.cb-choix-b--lien {
    border-color: var(--cb-fond, #128C7E);
    color: var(--cb-fond, #128C7E);
}

.cb-choix-b--rejouer {
    border-style: dashed;
}

/* ---------- Saisie libre ---------- */

.cb-saisie {
    display: flex;
    gap: 0.4rem;
    padding: 0.7rem;
    border-top: 1px solid #E6E1D8;
    background: #fff;
}

.cb-saisie input {
    flex: 1;
    min-width: 0;
    padding: 0.55rem 0.8rem;
    border: 1px solid #5A6472;
    border-radius: 999px;
    color: #12202F;
    font-family: inherit;
    font-size: 0.9rem;
}

.cb-saisie input:focus {
    outline: none;
    border-color: var(--cb-fond, #128C7E);
    box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.18);
}

.cb-saisie button {
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    border: 0;
    border-radius: 50%;
    background: var(--cb-fond, #128C7E);
    color: var(--cb-encre, #fff);
    font-size: 0.9rem;
    cursor: pointer;
}

.cb-saisie button:hover {
    filter: brightness(1.1);
}

.cb-saisie button:focus-visible {
    outline: 2px solid #12202F;
    outline-offset: 2px;
}

/* ---------- Téléphone ----------
   Le panneau occupe tout l'écran : à 22 rem sur un écran de 360 px, les
   propositions se replieraient sur trois lignes chacune. */
@media (max-width: 575px) {
    .cb {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .cb-panneau {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
    }

    .cb-choix {
        max-height: 11rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cb-bulle,
    .cb-choix-b {
        transition: none;
    }

    .cb-bulle:hover {
        transform: none;
    }

    .cb-frappe span {
        animation: none;
    }
}

@media print {
    .cb {
        display: none;
    }
}
