/* BP Assistant — Widget CSS v3.1 | Boutik Pam */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --bp-green:       #075E54;
    --bp-green-2:     #128C7E;
    --bp-green-3:     #25D366;
    --bp-green-light: #DCF8C6;
    --bp-gray-bg:     #ECE5DD;
    --bp-white:       #FFFFFF;
    --bp-shadow:      0 4px 20px rgba(0,0,0,.18);
    --bp-r:           18px;
    --bp-z:           999999;
    --bp-font:        'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

#bpa-root *, #bpa-root *::before, #bpa-root *::after {
    box-sizing: border-box; margin: 0; padding: 0;
}

/* ── Bouton flottant ── */
#bpa-toggle {
    position: fixed;
    bottom: 24px; right: 24px;
    z-index: var(--bp-z);
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--bp-green-2);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(18,140,126,.5);
    transition: transform .2s, box-shadow .2s;
    color: #fff;
}
#bpa-toggle:hover  { transform: scale(1.08); box-shadow: 0 6px 24px rgba(18,140,126,.6); }
#bpa-toggle:active { transform: scale(.94); }
#bpa-toggle svg    { width: 26px; height: 26px; transition: transform .25s; }
.bpa-icon-close    { display: none; }
#bpa-root.open .bpa-icon-open  { display: none; }
#bpa-root.open .bpa-icon-close { display: flex; }

/* Badge */
.bpa-badge {
    position: absolute; top: 2px; right: 2px;
    min-width: 18px; height: 18px; padding: 0 4px;
    background: #FF3B30; border-radius: 9px;
    font-size: 10px; font-weight: 700; color: #fff;
    display: none; align-items: center; justify-content: center;
    border: 2px solid #fff; font-family: var(--bp-font);
}
.bpa-badge.show { display: flex; }

/* ── Fenèt chat ── */
#bpa-window {
    position: fixed;
    bottom: 88px; right: 24px;
    z-index: var(--bp-z);
    width: 340px;
    max-width: calc(100vw - 32px);
    height: 480px;
    max-height: calc(100vh - 104px);
    border-radius: var(--bp-r);
    box-shadow: var(--bp-shadow);
    display: flex; flex-direction: column;
    overflow: hidden;
    font-family: var(--bp-font);
    opacity: 0; transform: translateY(16px) scale(.97);
    pointer-events: none;
    transition: opacity .22s cubic-bezier(.4,0,.2,1), transform .22s cubic-bezier(.4,0,.2,1);
    background: var(--bp-gray-bg);
}
#bpa-root.open #bpa-window {
    opacity: 1; transform: none; pointer-events: all;
}

/* ── Header ── */
#bpa-header {
    background: var(--bp-green);
    padding: 8px 12px;
    display: flex; align-items: center; gap: 8px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    min-height: 56px;
}

/* Bouton fèmen X — kwen anlè adwat, absoli nan header */
#bpa-close-btn {
    margin-left: auto;
    flex-shrink: 0;
    width: 30px; height: 30px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    border: 1.5px solid rgba(255,255,255,.35);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    transition: background .15s, transform .12s;
}
#bpa-close-btn:hover  { background: rgba(255,255,255,.35); transform: scale(1.08); }
#bpa-close-btn:active { transform: scale(.9); }
#bpa-close-btn svg    { width: 14px; height: 14px; }

.bpa-avatar-wrap { position: relative; flex-shrink: 0; }
.bpa-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--bp-green-2);
    border: 2px solid rgba(255,255,255,.3);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.bpa-online-dot {
    position: absolute; bottom: 1px; right: 1px;
    width: 10px; height: 10px;
    background: var(--bp-green-3);
    border-radius: 50%;
    border: 2px solid var(--bp-green);
}

.bpa-header-info { flex: 1; min-width: 0; }
.bpa-header-name {
    color: #fff;
    font-size: 14px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.2;
}
.bpa-header-sub {
    color: rgba(255,255,255,.75);
    font-size: 11px; margin-top: 1px;
}
#bpa-typing-indicator { display: none; }
#bpa-typing-indicator.show { display: inline; }

/* Switch lang — ti bouton anlè close-btn */
.bpa-lang-switch {
    display: flex; gap: 2px; flex-shrink: 0;
}
.bpa-lang {
    padding: 2px 7px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,.25);
    background: transparent;
    color: rgba(255,255,255,.65);
    font-size: 10px; font-weight: 500;
    cursor: pointer; transition: all .15s;
    font-family: var(--bp-font);
}
.bpa-lang.active {
    background: rgba(255,255,255,.2);
    color: #fff;
    border-color: rgba(255,255,255,.5);
}

/* ── Zone mesaj ── */
#bpa-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 8px 4px;
    display: flex; flex-direction: column; gap: 2px;
    scroll-behavior: smooth;
    background-color: #ECE5DD;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c8b8aa' fill-opacity='0.18'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
#bpa-messages::-webkit-scrollbar { width: 4px; }
#bpa-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 2px; }

/* ── Boul mesaj ── */
.bpa-msg {
    display: flex; flex-direction: column;
    max-width: 80%;
    margin-bottom: 1px;
}
.bpa-msg.user  { align-self: flex-end;   align-items: flex-end; }
.bpa-msg.bot   { align-self: flex-start; align-items: flex-start; }

.bpa-bubble {
    padding: 7px 11px 5px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,.1);
}

.bpa-msg.user .bpa-bubble {
    background: var(--bp-green-light);
    color: #1a1a1a;
    border-bottom-right-radius: 4px;
}
.bpa-msg.user .bpa-bubble::after {
    content: '';
    position: absolute;
    bottom: 0; right: -6px;
    border: 6px solid transparent;
    border-bottom-color: var(--bp-green-light);
    border-right: none; border-top: none;
}

.bpa-msg.bot .bpa-bubble {
    background: var(--bp-white);
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}
.bpa-msg.bot .bpa-bubble::after {
    content: '';
    position: absolute;
    bottom: 0; left: -6px;
    border: 6px solid transparent;
    border-bottom-color: var(--bp-white);
    border-left: none; border-top: none;
}

/* Mesaj eskalasyon */
.bpa-msg.bot .bpa-bubble.bpa-escalate {
    background: #FFF8E7;
    border-left: 3px solid #EF9F27;
}
.bpa-msg.bot .bpa-bubble.bpa-escalate::after {
    border-bottom-color: #FFF8E7;
}
.bpa-mail-link {
    color: #854F0B !important;
    font-weight: 600;
    text-decoration: underline;
    word-break: break-all;
}

/* Timestamp */
.bpa-time {
    font-size: 10px;
    color: rgba(0,0,0,.4);
    margin-top: 2px;
    padding: 0 3px;
    display: flex; align-items: center; gap: 3px;
}
.bpa-msg.user .bpa-time { justify-content: flex-end; }
.bpa-check { color: #53bdeb; font-size: 11px; }

/* Typing dots */
.bpa-bubble.bpa-loading {
    padding: 9px 12px;
    display: flex; align-items: center; gap: 4px;
    min-width: 48px;
}
.bpa-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #aaa;
    animation: bpaDot 1.3s infinite;
}
.bpa-dot:nth-child(2) { animation-delay: .2s; }
.bpa-dot:nth-child(3) { animation-delay: .4s; }
@keyframes bpaDot {
    0%,60%,100% { transform: translateY(0); opacity: .5; }
    30%          { transform: translateY(-4px); opacity: 1; }
}

/* Date separator */
.bpa-date-sep {
    align-self: center;
    background: rgba(225,200,178,.85);
    color: #5a4a3a;
    font-size: 11px; font-weight: 500;
    padding: 3px 10px;
    border-radius: 8px;
    margin: 4px 0;
}

/* ── Bouton rapid ── */
#bpa-quick {
    padding: 5px 8px 3px;
    display: flex; flex-wrap: wrap; gap: 4px;
    background: transparent;
    flex-shrink: 0;
}
.bpa-qbtn {
    padding: 5px 11px;
    border-radius: 16px;
    border: 1.5px solid var(--bp-green-2);
    background: rgba(255,255,255,.9);
    color: var(--bp-green);
    font-size: 11.5px; font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--bp-font);
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(0,0,0,.07);
}
.bpa-qbtn:hover {
    background: var(--bp-green-2);
    color: #fff;
    border-color: var(--bp-green-2);
}

/* ── Zone saisie ── */
#bpa-input-area {
    padding: 6px 8px;
    display: flex; align-items: flex-end; gap: 6px;
    background: #F0F0F0;
    flex-shrink: 0;
    border-top: 1px solid rgba(0,0,0,.08);
}

#bpa-input-wrap {
    flex: 1;
    background: #fff;
    border-radius: 20px;
    border: none;
    display: flex; align-items: flex-end;
    padding: 6px 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    min-height: 36px;
    max-height: 100px;
    transition: box-shadow .15s;
}
#bpa-input-wrap:focus-within {
    box-shadow: 0 1px 6px rgba(18,140,126,.25);
}

#bpa-input {
    flex: 1;
    resize: none;
    border: none; outline: none;
    font-size: 13.5px;
    font-family: var(--bp-font);
    background: transparent;
    color: #1a1a1a;
    line-height: 1.45;
    max-height: 88px;
    overflow-y: auto;
}
#bpa-input::placeholder { color: #aaa; }

#bpa-send {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--bp-green-2);
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .12s;
    box-shadow: 0 2px 6px rgba(18,140,126,.4);
}
#bpa-send:hover  { background: var(--bp-green); }
#bpa-send:active { transform: scale(.91); }
#bpa-send:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
#bpa-send svg { width: 18px; height: 18px; fill: #fff; }

/* ── Mobile full screen ── */
@media (max-width: 480px) {
    #bpa-window {
        bottom: 0; right: 0;
        width: 100vw; max-width: 100vw;
        height: 100dvh; max-height: 100dvh;
        border-radius: 0;
    }
    #bpa-toggle { bottom: 16px; right: 16px; }
}
