/* Assistant HEOP public: widget HTMX mobile-first, reutilisable par surface. */

/* LA BULLE D'AIDE PREND UNE PLACE, ET ELLE LA DECLARE (13/09).
 *
 * Elle flottait au bord droit sans rien dire de sa taille : a 393x852 elle se
 * posait sur le prix du premier produit de l'accueil, a 1440x900 sur « Trier
 * autour de moi » dans l'en-tete de la section des produits. Une bulle qui
 * cache un geste ou un prix fait perdre ce qu'elle pretend aider.
 *
 * TROIS REGLES DU COMPOSANT, AUCUNE PAGE NOMMEE :
 *   1. sa geometrie est DEUX JETONS, `--assistant-bord` (sa distance au bord
 *      droit) et `--assistant-taille` (sa largeur) : ronde de 44 points a 8 du
 *      bord au pouce, pilule « Aide » de 96 points a 24 du bord a partir de 760 ;
 *   2. elle se cale au-dessus de la barre basse par le jeton de la barre
 *      (`--hp-bottom-nav-height`, 0 quand la barre n'est pas la), a toutes
 *      les largeurs — la tablette tactile garde sa barre jusqu'a 900 points ;
 *   3. tant qu'elle flotte, elle publie `--assistant-reserve` = bord + taille :
 *      la colonne qu'elle occupe au bord droit. Les sections qui passent
 *      dessous la lisent et laissent cette colonne vide
 *      (home/contract-moment.css). Fermee (`is-hidden`), le jeton disparait et
 *      la place revient au contenu. La bulle d'inscription vit dans le flux de
 *      sa page : elle ne reserve rien.
 * Deplacee a la main (chat.js), elle suit le visiteur : c'est son choix. */
:root {
    --assistant-bord: 8px;
    --assistant-taille: 44px;
}

.assistant-widget {
    position: fixed;
    right: max(var(--assistant-bord), env(safe-area-inset-right));
    bottom: calc(var(--hp-bottom-nav-height, 0px) + 20px + env(safe-area-inset-bottom));
    z-index: 190;
    color: var(--text);
    user-select: none;
}

body:has(.assistant-widget:not(.is-hidden):not(.assistant-widget--signup)) {
    --assistant-reserve: calc(max(var(--assistant-bord), env(safe-area-inset-right)) + var(--assistant-taille));
}

.assistant-widget.is-hidden {
    display: none;
}

.assistant-widget__toggle {
    display: inline-flex;
    width: var(--assistant-taille);
    min-width: var(--assistant-taille);
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--accent);
    color: var(--cream);
    font-weight: 700;
    box-shadow: 0 12px 28px color-mix(in srgb, var(--accent-strong) 24%, transparent);
    touch-action: none;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.assistant-widget__toggle:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--cream);
    text-decoration: none;
}

.assistant-widget--signup .assistant-widget__toggle {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
}

.assistant-widget.is-dragging .assistant-widget__toggle {
    cursor: grabbing;
    transform: scale(.98);
    box-shadow: 0 18px 34px color-mix(in srgb, var(--accent-strong) 30%, transparent);
}

.assistant-widget__dismiss {
    position: absolute;
    top: -8px;
    right: -7px;
    z-index: 3;
    width: 24px;
    min-width: 24px;
    min-height: 24px;
    padding: 0;
    border: 1px solid rgba(223, 212, 195, .86);
    border-radius: 999px;
    background: rgba(255, 253, 247, .94);
    color: var(--muted);
    box-shadow: 0 8px 18px color-mix(in srgb, var(--text) 10%, transparent);
}

.assistant-widget__dismiss:hover {
    color: var(--accent);
    background: var(--surface);
}

/* Au pouce, le libelle reste pour le lecteur d'ecran ; le glyphe dit l'aide. */
.assistant-widget__toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.assistant-widget__toggle-icon {
    display: inline-grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border-radius: 999px;
    background: var(--cream);
    color: var(--brand);
}

.assistant-panel[hidden] {
    display: none;
}

.assistant-panel {
    position: absolute;
    right: 0;
    bottom: 56px;
    display: grid;
    width: min(348px, calc(100vw - 28px));
    max-height: min(600px, calc(100svh - 120px));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 22px 58px color-mix(in srgb, var(--text) 20%, transparent);
}

.assistant-widget.is-left-side .assistant-panel {
    right: auto;
    left: 0;
}

.assistant-widget.is-top-side .assistant-panel {
    top: 56px;
    bottom: auto;
}

.assistant-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--line);
    background:
        linear-gradient(135deg, var(--surface) 0%, var(--accent-soft) 56%, var(--brand-soft) 100%);
}

.assistant-panel__brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    color: var(--brand-strong);
    font-size: .78rem;
    font-weight: 700;
}

.assistant-panel__brand .heop-logo {
    width: 72px;
}

.assistant-panel__close {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border-color: var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
}

.assistant-thread {
    display: grid;
    gap: 10px;
    max-height: min(360px, calc(100svh - 280px));
    overflow: hidden auto;
    padding: 12px;
    background:
        linear-gradient(180deg, var(--surface) 0%, var(--accent-soft) 100%);
    scroll-behavior: smooth;
}

.assistant-message {
    display: flex;
}

.assistant-message--user {
    justify-content: flex-end;
}

.assistant-message__bubble {
    display: grid;
    gap: 6px;
    max-width: 88%;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 8px 20px color-mix(in srgb, var(--text) 7%, transparent);
}

.assistant-message--user .assistant-message__bubble {
    border-color: var(--brand);
    background: var(--brand);
    color: var(--cream);
}

.assistant-message__title {
    color: var(--brand-strong);
    font-size: .9rem;
    line-height: 1.2;
}

.assistant-message--user .assistant-message__title {
    color: var(--cream);
}

.assistant-message__bubble p {
    margin: 0;
    font-size: .86rem;
    line-height: 1.36;
}

.assistant-message__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 2px;
}

.assistant-message__action {
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    padding: 0 10px;
    border: 1px solid var(--accent);
    border-radius: 999px;
    background: var(--accent);
    color: var(--cream);
    font-size: .78rem;
    font-weight: 600;
}

.assistant-message__action:hover {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--cream);
    text-decoration: none;
}

.assistant-message__resources {
    display: grid;
    gap: 6px;
    padding-top: 2px;
}

.assistant-resource {
    display: grid;
    gap: 2px;
    padding: 8px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--text);
}

.assistant-resource:hover {
    border-color: var(--accent);
    color: var(--brand-strong);
    text-decoration: none;
}

.assistant-resource__title {
    font-size: .8rem;
    font-weight: 700;
    line-height: 1.2;
}

.assistant-resource__subtitle {
    color: var(--muted);
    font-size: .72rem;
    font-weight: 500;
    line-height: 1.25;
}

.assistant-suggestions {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 10px 12px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.assistant-suggestion {
    min-height: var(--tap-size);
    padding: 5px 10px;
    border-color: var(--line);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--brand-strong);
    font-size: .76rem;
    font-weight: 600;
}

.assistant-form {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.assistant-form__input {
    width: 100%;
    min-height: 38px;
    max-height: 92px;
    resize: none;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: .86rem;
    line-height: 1.25;
}

.assistant-form__input::placeholder {
    color: var(--muted);
}

.assistant-form__submit {
    width: 38px;
    min-width: 38px;
    min-height: 38px;
    padding: 0;
    border-color: var(--brand);
    border-radius: 999px;
    background: var(--brand);
    color: var(--cream);
}

.assistant-widget--signup .assistant-panel__close,
.assistant-widget--signup .assistant-suggestion,
.assistant-widget--signup .assistant-form__submit,
.assistant-widget--signup .assistant-message__action {
    min-width: var(--tap-size);
    min-height: var(--tap-size);
}

.assistant-widget--signup .assistant-message__action {
    border-color: var(--accent-strong);
    background: var(--accent-strong);
    color: var(--cream);
}

.assistant-widget--signup .assistant-panel__close,
.assistant-widget--signup .assistant-form__submit {
    width: var(--tap-size);
}

.assistant-widget--signup .assistant-form {
    grid-template-columns: minmax(0, 1fr) var(--tap-size);
}

.assistant-widget--signup .assistant-suggestions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    overflow-x: hidden;
}

.assistant-widget--signup .assistant-suggestion {
    width: 100%;
    min-width: 0;
    height: auto;
    padding-block: 8px;
    line-height: 1.25;
    white-space: normal;
    overflow-wrap: anywhere;
}

.assistant-widget--signup .assistant-form__input {
    min-height: var(--tap-size);
}

.assistant-form__indicator {
    position: absolute;
    right: 60px;
    bottom: 24px;
    width: 14px;
    height: 14px;
    border: 2px solid color-mix(in srgb, var(--accent) 18%, transparent);
    border-top-color: var(--accent);
    border-radius: 999px;
    opacity: 0;
}

.assistant-form.htmx-request .assistant-form__indicator {
    opacity: 1;
    animation: assistant-spin 700ms linear infinite;
}

@keyframes assistant-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-height: 430px) and (orientation: landscape) {
    .assistant-widget {
        bottom: calc(var(--hp-bottom-nav-height, 0px) + 12px + env(safe-area-inset-bottom));
    }

    .assistant-panel {
        bottom: 52px;
        max-height: calc(100svh - 68px);
    }

    .assistant-widget.is-top-side .assistant-panel {
        top: 52px;
        bottom: auto;
    }

    .assistant-thread {
        max-height: calc(100svh - 218px);
    }

    .assistant-panel__header,
    .assistant-suggestions,
    .assistant-form {
        padding-block: 7px;
    }
}

@media (min-width: 760px) {
    :root {
        --assistant-bord: 24px;
        --assistant-taille: 96px;
    }

    .assistant-widget {
        bottom: calc(var(--hp-bottom-nav-height, 0px) + 24px + env(safe-area-inset-bottom));
    }

    .assistant-widget__toggle {
        min-height: 44px;
        padding: 0 14px 0 10px;
    }

    .assistant-widget--signup .assistant-widget__toggle {
        width: auto;
    }

    .assistant-widget__toggle-label {
        position: static;
        width: auto;
        height: auto;
        overflow: visible;
        clip: auto;
        clip-path: none;
    }

    .assistant-panel {
        bottom: 58px;
        width: 372px;
        max-height: min(620px, calc(100svh - 92px));
    }

    .assistant-thread {
        max-height: 390px;
    }
}
