/* ============================================================
   BSBella Chatbot — Widget front-end
   Design : luxe minimaliste, noir #1a1a1a / or #c9a84c
   ============================================================ */

:root {
    --bb-dark:        #1a1a1a;
    --bb-gold:        #c9a84c;
    --bb-gold-dim:    rgba(201,168,76,0.15);
    --bb-white:       #ffffff;
    --bb-light:       #f7f7f7;
    --bb-grey-1:      #f0f0f0;
    --bb-grey-2:      #e0e0e0;
    --bb-grey-3:      #999999;
    --bb-grey-4:      #555555;
    --bb-font:        'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bb-radius:      14px;
    --bb-radius-sm:   8px;
    --bb-shadow:      0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.10);
    --bb-transition:  0.25s ease;
    --bb-bubble:      50px;
    --bb-w:           400px;
    --bb-h:           540px;
    --bb-bottom:      20px;
    --bb-right:       20px;
}

/* ── Conteneur racine ──────────────────────────────────────── */
#bsbella-chatbot-root {
    position:    fixed;
    bottom:      var(--bb-bottom);
    right:       var(--bb-right);
    z-index:     999999;
    font-family: var(--bb-font);
    line-height: normal;
}

/* ── Bulle flottante ───────────────────────────────────────── */
#bsbella-bubble {
    width:           var(--bb-bubble);
    height:          var(--bb-bubble);
    border-radius:   50%;
    background:      var(--bb-dark);
    border:          none;
    cursor:          pointer;
    display:         flex;
    align-items:     center;
    justify-content: center;
    box-shadow:      var(--bb-shadow);
    transition:      transform var(--bb-transition), box-shadow var(--bb-transition);
    outline:         none;
    position:        relative;
    margin-left:     auto;
}

/* Animation d'entrée de la bulle (ajoutée par JS après 5 s) */
#bsbella-bubble.bb-bubble-intro {
    animation: bbBubbleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

#bsbella-bubble:hover {
    transform:  scale(1.08);
    box-shadow: 0 12px 36px rgba(0,0,0,0.25);
}

#bsbella-bubble:focus-visible {
    outline:        2px solid var(--bb-gold);
    outline-offset: 3px;
}

/* Icône de chat dans la bulle */
.bb-bubble-icon {
    width:             22px;
    height:            22px;
    stroke:            var(--bb-gold);
    fill:              none;
    stroke-width:      2;
    stroke-linecap:    round;
    stroke-linejoin:   round;
    transition:        opacity var(--bb-transition);
    flex-shrink:       0;
}

/* Icône fermeture */
.bb-bubble-close {
    display:     none;
    font-size:   22px;
    color:       var(--bb-white);
    line-height: 1;
}

#bsbella-chatbot-root.is-open .bb-bubble-icon  { display: none; }
#bsbella-chatbot-root.is-open .bb-bubble-close { display: block; }

/* ── Badge notification ────────────────────────────────────── */
.bb-notification {
    position:       absolute;
    bottom:         calc(var(--bb-bubble) + 12px);
    right:          0;
    background:     var(--bb-white);
    border:         1.5px solid var(--bb-gold);
    color:          var(--bb-dark);
    font-size:      12px;
    font-weight:    500;
    font-family:    var(--bb-font);
    padding:        8px 14px;
    border-radius:  20px;
    white-space:    nowrap;
    box-shadow:     0 4px 16px rgba(0,0,0,0.12);
    opacity:        0;
    transform:      translateY(6px);
    pointer-events: none;
    transition:     opacity 0.3s ease, transform 0.3s ease;
    cursor:         pointer;
}

.bb-notification::after {
    content:        '';
    position:       absolute;
    bottom:         -7px;
    right:          16px;
    width:          12px;
    height:         7px;
    background:     var(--bb-white);
    border-right:   1.5px solid var(--bb-gold);
    border-bottom:  1.5px solid var(--bb-gold);
    clip-path:      polygon(0 0, 100% 0, 50% 100%);
}

.bb-notification.is-visible {
    opacity:        1;
    transform:      translateY(0);
    pointer-events: auto;
    /* Respiration douce toutes les 3 s — attire l'œil sans agresser */
    animation:      bbNotifBreath 3s ease-in-out 1s infinite;
}

/* ── Fenêtre du chat ───────────────────────────────────────── */
#bsbella-window {
    position:        absolute;
    bottom:          calc(var(--bb-bubble) + 16px);
    right:           0;
    width:           var(--bb-w);
    max-width:       calc(100vw - var(--bb-right) - 8px);
    height:          min(var(--bb-h), 80vh);
    max-height:      80vh;
    background:      var(--bb-white);
    border-radius:   var(--bb-radius);
    box-shadow:      var(--bb-shadow);
    display:         flex;
    flex-direction:  column;
    overflow:        hidden;
    transform-origin: bottom right;
    transform:       scale(0.9);
    opacity:         0;
    pointer-events:  none;
    transition:      transform var(--bb-transition), opacity var(--bb-transition);
}

#bsbella-chatbot-root.is-open #bsbella-window {
    transform:      scale(1);
    opacity:        1;
    pointer-events: all;
}

/* ── En-tête ───────────────────────────────────────────────── */
#bsbella-header {
    display:     flex;
    align-items: center;
    gap:         12px;
    padding:     14px 18px;
    background:  var(--bb-dark);
    flex-shrink: 0;
}

.bb-avatar {
    width:           38px;
    height:          38px;
    border-radius:   50%;
    background:      rgba(255,255,255,0.10);
    display:         flex;
    align-items:     center;
    justify-content: center;
    flex-shrink:     0;
    overflow:        hidden;
}

.bb-avatar-icon {
    width:           22px;
    height:          22px;
    stroke:          var(--bb-white);
    fill:            none;
    stroke-width:    1.8;
    stroke-linecap:  round;
    stroke-linejoin: round;
}

.bb-avatar-logo {
    width:      38px;
    height:     38px;
    object-fit: cover;
    display:    block;
}

.bb-header-info {
    flex:           1;
    display:        flex;
    flex-direction: column;
    gap:            2px;
}

.bb-bot-name {
    font-size:   14px;
    font-weight: 600;
    color:       var(--bb-white);
    line-height: 1.2;
}

.bb-status {
    font-size:      11px;
    color:          var(--bb-gold);
    letter-spacing: 0.03em;
    line-height:    1;
}

/* ── Zone de messages ──────────────────────────────────────── */
#bsbella-messages {
    flex:                    1;
    overflow-y:              auto;
    padding:                 14px 14px;
    background:              var(--bb-light);
    display:                 flex;
    flex-direction:          column;
    gap:                     10px;
    scroll-behavior:         smooth;
    min-height:              0; /* important pour que flex-shrink fonctionne */
    /* Scroll fluide sur iOS Safari */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior:     contain;
}

#bsbella-messages::-webkit-scrollbar       { width: 4px; }
#bsbella-messages::-webkit-scrollbar-track { background: transparent; }
#bsbella-messages::-webkit-scrollbar-thumb { background: var(--bb-grey-2); border-radius: 4px; }

/* ── Bulles de messages ────────────────────────────────────── */
.bb-msg {
    display:        flex;
    flex-direction: column;
    max-width:      88%;
    gap:            6px;
    animation:      bbFadeIn 0.2s ease;
}

@keyframes bbFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);   }
}

/* ── Animation entrée de la bulle ──────────────────────────────────────── */
@keyframes bbBubbleIn {
    0%   { opacity: 0; transform: scale(0.4); }
    70%  { opacity: 1; transform: scale(1.08); }
    100% { opacity: 1; transform: scale(1); }
}

/* ── Animation douce de la notification ────────────────────────────────── */
@keyframes bbNotifBreath {
    0%, 100% { transform: translateY(0)    scale(1);    box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
    50%       { transform: translateY(-3px) scale(1.03); box-shadow: 0 6px 20px rgba(201,168,76,0.30); }
}

.bb-msg.bb-user {
    align-self:  flex-end;
    align-items: flex-end;
}

.bb-msg.bb-bot {
    align-self:  flex-start;
    align-items: flex-start;
}

.bb-msg-bubble {
    padding:     10px 14px;
    border-radius: 0;
    font-size:   13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break:  break-word;
}

.bb-user .bb-msg-bubble {
    background: var(--bb-dark);
    color:      var(--bb-white);
}

.bb-bot .bb-msg-bubble {
    background:  var(--bb-white);
    color:       var(--bb-dark);
    border-left: 3px solid var(--bb-gold);
}

/* ── Boutons dans les réponses ─────────────────────────────── */
.bb-msg-buttons {
    display:    flex;
    flex-wrap:  wrap;
    gap:        6px;
    margin-top: 4px;
}

.bb-btn {
    background-color: #fbfbfb;
    padding:          3px 10px;
    font-size:        13px;
    border-radius:    3px;
    margin:           4px;
    border:           1px solid var(--bb-grey-2);
    color:            var(--bb-dark);
    font-family:      var(--bb-font);
    font-weight:      500;
    cursor:           pointer;
    text-decoration:  none;
    display:          inline-block;
    line-height:      1.6;
    white-space:      normal;
    transition:       background var(--bb-transition), color var(--bb-transition), border-color var(--bb-transition);
}

.bb-btn:hover,
.bb-btn:focus {
    background-color: var(--bb-dark);
    color:            var(--bb-white);
    border-color:     var(--bb-dark);
    outline:          none;
}

.bb-btn.bb-btn-primary {
    background-color: #fbfbfb;
    border-color:     var(--bb-grey-2);
    color:            var(--bb-dark);
    font-weight:      600;
}

.bb-btn.bb-btn-primary:hover {
    background-color: var(--bb-dark);
    color:            var(--bb-white);
    border-color:     var(--bb-dark);
}

/* ── Indicateur de frappe ──────────────────────────────────── */
#bsbella-typing {
    display:                   none;
    align-self:                flex-start;
    padding:                   10px 14px;
    background:                var(--bb-white);
    border-radius:             10px;
    border-left:               3px solid var(--bb-gold);
    border-bottom-left-radius: 3px;
    gap:                       4px;
    align-items:               center;
}

#bsbella-typing.is-visible { display: flex; }

.bb-typing-dot {
    width:         6px;
    height:        6px;
    border-radius: 50%;
    background:    var(--bb-grey-3);
    animation:     bbTyping 1.2s infinite ease-in-out;
}

.bb-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.bb-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bbTyping {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
    30%           { transform: translateY(-4px);  opacity: 1;   }
}

/* ── Boutons d'accueil rapide ──────────────────────────────── */
#bsbella-quick-actions {
    display:     flex;
    flex-wrap:   wrap;
    gap:         0;
    padding:     8px 10px 6px;
    background:  var(--bb-light);
    flex-shrink: 0;
}

#bsbella-quick-actions.is-hidden { display: none; }

/* bb-btn-quick hérite de .bb-btn — aucune surcharge nécessaire */
button.bb-btn.bb-btn-quick {
    text-align: left;
}

/* ── Zone de saisie ────────────────────────────────────────── */
#bsbella-input-area {
    display:     flex;
    align-items: center;
    gap:         8px;
    padding:     10px 12px;
    background:  var(--bb-white);
    flex-shrink: 0;
    border-top:  1px solid var(--bb-grey-1);
}

#bsbella-input {
    flex:          1;
    padding:       8px 12px;
    border:        1px solid var(--bb-grey-2);
    border-radius: 20px;
    /* 16px minimum obligatoire — en dessous Safari/iOS zoome automatiquement */
    font-size:     16px;
    font-family:   var(--bb-font);
    color:         var(--bb-dark);
    background:    var(--bb-light);
    outline:       none;
    transition:    border-color var(--bb-transition), background var(--bb-transition);
    min-height:    36px;
    resize:        none;
    /* Désactive le zoom sur double-tap iOS */
    touch-action:  manipulation;
}

#bsbella-input:focus {
    border-color: var(--bb-gold);
    background:   var(--bb-white);
}

#bsbella-input::placeholder { color: var(--bb-grey-3); }

#bsbella-send {
    width:           34px;
    height:          34px;
    border-radius:   50%;
    background:      var(--bb-dark);
    border:          none;
    cursor:          pointer;
    display:         flex;
    align-items:     center;
    justify-content: center;
    flex-shrink:     0;
    transition:      background var(--bb-transition), transform var(--bb-transition);
    outline:         none;
}

#bsbella-send:hover   { background: #333; transform: scale(1.05); }
#bsbella-send:focus-visible { outline: 2px solid var(--bb-gold); }
#bsbella-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.bb-send-icon {
    width:           16px;
    height:          16px;
    fill:            none;
    stroke:          var(--bb-white);
    stroke-width:    2;
    stroke-linecap:  round;
    stroke-linejoin: round;
}

/* ── Responsive tablette ───────────────────────────────────── */
@media (max-width: 768px) {
    :root {
        --bb-w:      360px;
        --bb-bottom: 16px;
        --bb-right:  16px;
    }
}

/* ── Responsive mobile ─────────────────────────────────────── */
@media (max-width: 480px) {
    :root {
        --bb-bubble: 46px;
        --bb-bottom: 12px;
        --bb-right:  12px;
        --bb-h:      68vh;  /* plus compact sur mobile */
        --bb-w:      calc(100vw - 32px);
    }

    #bsbella-window {
        right:      0;
        left:       auto;
        max-height: 68vh;
        height:     68vh;
    }

    .bb-notification {
        font-size: 11px;
        padding:   7px 12px;
    }
}

/* ── Très petits écrans (≤360px) ───────────────────────────── */
@media (max-width: 360px) {
    :root {
        --bb-w:      calc(100vw - 16px);
        --bb-right:  8px;
    }
}

/* ── Safari iOS — gestion du clavier virtuel ───────────────── */
/*
   Quand le clavier s'ouvre sur iOS, le viewport rétrécit.
   On utilise dvh (dynamic viewport height) si disponible,
   sinon on limite la hauteur pour éviter le débordement.
*/
@supports (height: 100dvh) {
    #bsbella-window {
        max-height: 80dvh;
    }

    @media (max-width: 480px) {
        #bsbella-window {
            max-height: 78dvh;
            height:     78dvh;
        }
    }
}

/* Empêche le zoom sur tous les éléments interactifs du widget sur iOS */
#bsbella-chatbot-root button,
#bsbella-chatbot-root input,
#bsbella-chatbot-root a {
    touch-action: manipulation;
}
