/*
 * PEMBO 2.0 — assistant (specs/009-assistant-chatbot).
 * Bouton flottant et fenêtre de discussion. Utilise les jetons de pembo.css et neutralise
 * localement les styles globaux de Materialize (boutons, listes, champs).
 */

/* Bouton flottant ---------------------------------------------------------- */

.pb-chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--c-primary);
    color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(27, 29, 27, 0.25);
}

.pb-chat-fab:hover { background: var(--c-primary-hover); color: #FFFFFF; }

/* Fenêtre ouverte : le bouton s'efface derrière elle. */
.pb-chat-open .pb-chat-fab { visibility: hidden; }

/* Fenêtre ------------------------------------------------------------------ */

.pb-chat {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 70;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 48px);
    overflow: hidden;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    background: var(--c-surface);
    box-shadow: var(--shadow-float);
    color: var(--c-text);
    font-family: var(--f-text);
    font-size: 14px;
    line-height: 20px;
}

.pb-chat[hidden] { display: none; }

.pb-chat p { margin: 0; }

.pb-chat ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.pb-chat li { list-style: none; }

.pb-chat button,
.pb-chat button:focus {
    margin: 0;
    font-family: var(--f-text);
    cursor: pointer;
}

.pb-chat__head {
    display: flex;
    flex: none;
    align-items: center;
    gap: 12px;
    padding: 14px 12px 14px 16px;
    background: var(--c-primary);
    color: #FFFFFF;
}

.pb-chat__avatar {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
}

.pb-chat__title {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--f-display);
    font-size: 16px;
    font-weight: 600;
    line-height: 20px;
}

.pb-chat__title span {
    display: block;
    font-family: var(--f-text);
    font-size: 12px;
    font-weight: 400;
    line-height: 16px;
    opacity: 0.85;
}

.pb-chat__close,
.pb-chat__close:focus {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #FFFFFF;
}

.pb-chat__close:hover { background: rgba(255, 255, 255, 0.16); }
.pb-chat__close:focus-visible { outline-color: #FFFFFF; }

/* Fil de messages ---------------------------------------------------------- */

.pb-chat__log {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--c-surface-alt);
}

.pb-chat__msg {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 92%;
}

.pb-chat__msg--bot { align-self: flex-start; align-items: flex-start; }
.pb-chat__msg--user { align-self: flex-end; align-items: flex-end; }

.pb-chat__bubble {
    padding: 10px 14px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    background: var(--c-surface);
    overflow-wrap: anywhere;
}

.pb-chat__bubble a { color: var(--c-primary); font-weight: 500; text-decoration: underline; }
.pb-chat__bubble strong { font-weight: 600; }

.pb-chat__msg--user .pb-chat__bubble {
    border-color: var(--c-primary);
    border-radius: var(--radius-lg);
    border-bottom-right-radius: 4px;
    background: var(--c-primary);
    color: #FFFFFF;
}

.pb-chat__msg--wait .pb-chat__bubble { color: var(--c-text-muted); }

/* Produits proposés */

.pb-chat__products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-self: stretch;
}

.pb-chat__product {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px 8px 8px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    background: var(--c-surface);
    color: var(--c-text);
}

.pb-chat__product:hover { border-color: var(--c-primary); color: var(--c-text); }

.pb-chat__product img {
    flex: none;
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    background: var(--c-surface-alt);
    object-fit: contain;
}

.pb-chat__product-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.pb-chat__product-name {
    display: -webkit-box;
    overflow: hidden;
    font-size: 13px;
    font-weight: 500;
    line-height: 18px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.pb-chat__product .pb-price { font-size: 14px; }
.pb-chat__product .pb-icon { color: var(--c-text-muted); }

.pb-chat__more {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    color: var(--c-primary);
    font-weight: 600;
}

.pb-chat__more:hover { color: var(--c-primary-hover); text-decoration: underline; }

.pb-chat__links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Boutons de choix */

.pb-chat__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pb-chat__chip,
.pb-chat__chip:focus {
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--c-primary);
    border-radius: 20px;
    background: var(--c-surface);
    color: var(--c-primary);
    font-size: 13px;
    font-weight: 500;
    line-height: 18px;
    text-align: left;
}

.pb-chat__chip:hover { background: var(--c-primary-tint); }
.pb-chat__chip[disabled] { opacity: 0.55; cursor: default; }

.pb-chat__feedback {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--c-text-muted);
    font-size: 13px;
}

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

.pb-chat__form {
    display: flex;
    flex: none;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--c-border);
    background: var(--c-surface);
}

.pb-chat input.pb-chat__input {
    flex: 1 1 auto;
    box-sizing: border-box;
    min-width: 0;
    height: 44px;
    margin: 0;
    padding: 0 14px;
    border: 1px solid var(--c-border);
    border-radius: 22px;
    box-shadow: none;
    background: var(--c-surface);
    color: var(--c-text);
    font-family: var(--f-text);
    font-size: 14px;
}

.pb-chat input.pb-chat__input:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 1px var(--c-primary);
    outline: none;
}

.pb-chat__input::placeholder { color: var(--c-text-muted); opacity: 1; }

.pb-chat__send,
.pb-chat__send:focus {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--c-primary);
    color: #FFFFFF;
}

.pb-chat__send:hover { background: var(--c-primary-hover); }
.pb-chat__send[disabled] { opacity: 0.55; cursor: default; }

/* Lien vers un conseiller, toujours visible. */
.pb-chat__human {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 12px calc(env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--c-border);
    background: var(--c-surface);
    color: var(--c-primary);
    font-size: 13px;
    font-weight: 600;
}

.pb-chat__human:hover { background: var(--c-primary-tint); color: var(--c-primary-hover); }

/* Téléphone : plein écran, ouvert depuis la barre du bas -------------------- */

@media (max-width: 767px) {
    .pb-chat-fab { display: none; }

    .pb-chat {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 90;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        border: 0;
        border-radius: 0;
    }

    /* 16 px : l'écran ne zoome pas à la saisie. */
    .pb-chat input.pb-chat__input { font-size: 16px; }

    .pb-chat__human { min-height: calc(48px + env(safe-area-inset-bottom, 0px)); }

    html.pb-chat-open,
    html.pb-chat-open body { overflow: hidden; }
}
