/* ============================================================
 *  Sama_Boutique — Widget de chat flottant (Intercom / Crisp)
 *  ------------------------------------------------------------
 *  Bulle fixe bas-droite + panneau en verre dépoli « Pan-African
 *  Tech Chic » : fonds sombres #0F172A/#020617, accents Or
 *  #D97706 / Émeraude #059669 / Terracotta #C25E00, ouverture au
 *  fondu + glissement, badge de non lus pulsé.
 *  Partagé par : dashboard marchand, espace admin, vitrine
 *  publique (variante --vitrine teintée de --principale).
 * ============================================================ */

.wchat {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9990;
    font-family: inherit;
}

/* L'attribut hidden doit toujours l'emporter sur les display
   flex/grid déclarés ci-dessous (panneau, fil, badge...). */
.wchat [hidden] { display: none !important; }

/* ---------- Badge de l'onglet « Messages » (navigation) ---------- */
.nav-badge {
    display: inline-grid;
    place-items: center;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    margin-left: 5px;
    border-radius: 999px;
    background: #e31b23;
    color: #fff;
    font-size: .68rem;
    font-weight: 800;
    line-height: 1;
    vertical-align: 1px;
    animation: wchat-badge-pulse 1.8s infinite;
}

/* ---------- Bulle flottante ---------- */
.wchat__bulle {
    position: relative;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, #d97706, #c25e00);
    box-shadow:
        0 12px 28px -8px rgb(194 94 0 / .65),
        0 0 0 6px rgb(217 119 6 / .12);
    transition: transform .22s cubic-bezier(.2, .7, .3, 1), box-shadow .22s;
}
.wchat__bulle:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow:
        0 18px 34px -8px rgb(194 94 0 / .7),
        0 0 0 9px rgb(217 119 6 / .16);
}
.wchat__bulle:active { transform: scale(.96); }

/* Variante vitrine : la bulle reprend la couleur de la boutique */
.wchat__bulle--theme {
    background: linear-gradient(135deg, var(--principale), color-mix(in srgb, var(--principale) 70%, #000));
    box-shadow:
        0 12px 28px -8px color-mix(in srgb, var(--principale) 60%, transparent),
        0 0 0 6px color-mix(in srgb, var(--principale) 14%, transparent);
}

/* Bascule des icônes ouvrir/fermer selon l'état */
.wchat__icone--fermer { display: none; }
.wchat.est-ouvert .wchat__icone--ouvrir { display: none; }
.wchat.est-ouvert .wchat__icone--fermer { display: block; }

/* ---------- Badge de messages non lus ---------- */
.wchat__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: #e31b23;
    color: #fff;
    font-size: .72rem;
    font-weight: 800;
    line-height: 1;
    border: 2px solid #fff;
    box-shadow: 0 4px 10px rgb(227 27 35 / .5);
    animation: wchat-badge-pop .3s cubic-bezier(.2, 1.4, .4, 1) both;
}
.wchat__badge.est-pulse { animation: wchat-badge-pulse 1.6s infinite; }
@keyframes wchat-badge-pop {
    from { transform: scale(.4); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
@keyframes wchat-badge-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgb(227 27 35 / .45); }
    55%      { box-shadow: 0 0 0 8px rgb(227 27 35 / 0); }
}

/* ---------- Panneau en verre ---------- */
.wchat__panneau {
    position: absolute;
    right: 0;
    bottom: 74px;
    width: min(370px, calc(100vw - 32px));
    height: min(520px, calc(100vh - 130px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgb(148 163 184 / .2);
    border-radius: 22px;
    background: linear-gradient(160deg, rgb(15 23 42 / .94), rgb(2 6 23 / .97));
    -webkit-backdrop-filter: blur(18px) saturate(160%);
    backdrop-filter: blur(18px) saturate(160%);
    box-shadow: 0 30px 60px -20px rgb(2 6 23 / .7);
    color: #e2e8f0;
    opacity: 0;
    transform: translateY(14px) scale(.97);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity .24s ease, transform .24s cubic-bezier(.21, 1.02, .73, 1);
}
.wchat__panneau.est-ouvert {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---------- En-tête du panneau ---------- */
.wchat__entete {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    background: linear-gradient(135deg, rgb(30 41 59 / .9), rgb(2 6 23 / .92));
    border-bottom: 1px solid rgb(148 163 184 / .14);
    flex-shrink: 0;
}
.wchat__titres { flex: 1; min-width: 0; }
.wchat__titres strong {
    display: block;
    font-size: .92rem;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wchat__titres small { color: #94a3b8; font-size: .72rem; }

.wchat__rond {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--principale, #059669), color-mix(in srgb, var(--principale, #047857) 75%, #000));
    color: #fff;
    font-weight: 800;
    box-shadow: 0 0 0 2px rgb(217 119 6 / .3);
}

.wchat__presence {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #059669;
    display: inline-block;
    margin-right: 5px;
    box-shadow: 0 0 0 0 rgb(5 150 105 / .5);
    animation: chat-pulsation 2.2s infinite;
}
.wchat__presence--absent { background: #dc2626; animation: none; }

.wchat__retour,
.wchat__croix,
.wchat__lien-page,
.wchat__whatsapp {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 0;
    background: rgb(148 163 184 / .12);
    color: #cbd5e1;
    font-size: .95rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    flex-shrink: 0;
    transition: background .16s, color .16s;
}
.wchat__retour:hover,
.wchat__croix:hover,
.wchat__lien-page:hover { background: rgb(148 163 184 / .25); color: #fff; }
.wchat__whatsapp { width: auto; padding: 0 10px; border-radius: 999px; font-size: .72rem; background: rgb(37 211 102 / .16); color: #4ade80; }
.wchat__whatsapp:hover { background: rgb(37 211 102 / .3); color: #bbf7d0; }

/* ---------- Onglets (marchand : Clients / Assistance) ---------- */
.wchat__onglets {
    display: flex;
    gap: 6px;
    padding: 10px 12px 0;
    flex-shrink: 0;
}
.wchat__onglet {
    flex: 1;
    border: 1px solid rgb(148 163 184 / .18);
    border-radius: 999px;
    background: rgb(30 41 59 / .5);
    color: #94a3b8;
    font-size: .78rem;
    font-weight: 700;
    padding: 8px 10px;
    cursor: pointer;
    transition: background .16s, color .16s, border-color .16s;
}
.wchat__onglet.est-actif {
    background: linear-gradient(135deg, rgb(217 119 6 / .18), rgb(194 94 0 / .1));
    border-color: rgb(217 119 6 / .5);
    color: #fcd34d;
}
.wchat__mini-badge {
    display: inline-grid;
    place-items: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-left: 4px;
    border-radius: 999px;
    background: #e31b23;
    color: #fff;
    font-size: .66rem;
}

/* ---------- Liste des conversations ---------- */
.wchat__liste {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.wchat__conv {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 1px solid transparent;
    border-radius: 14px;
    background: none;
    padding: 10px;
    text-align: left;
    color: #e2e8f0;
    cursor: pointer;
    transition: background .16s, border-color .16s;
    animation: chat-apparition .3s both;
}
.wchat__conv:hover {
    background: rgb(30 41 59 / .8);
    border-color: rgb(148 163 184 / .2);
}
.wchat__conv-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    background: linear-gradient(135deg, #059669, #047857);
    color: #fff;
    font-weight: 800;
    font-size: .85rem;
}
.wchat__conv-corps { flex: 1; min-width: 0; }
.wchat__conv-corps strong {
    display: block;
    font-size: .85rem;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wchat__conv-corps small {
    display: block;
    color: #94a3b8;
    font-size: .72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wchat__conv-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: #e31b23;
    color: #fff;
    font-size: .68rem;
    font-weight: 800;
    flex-shrink: 0;
}
.wchat__vide {
    margin: auto;
    padding: 22px;
    text-align: center;
    color: #94a3b8;
    font-size: .82rem;
    line-height: 1.55;
}

/* ---------- Fil de discussion ---------- */
.wchat__fil {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background:
        repeating-linear-gradient(45deg, transparent 0 16px, rgb(148 163 184 / .04) 16px 32px),
        rgb(2 6 23 / .3);
}
.wchat__ligne {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: chat-apparition .3s cubic-bezier(.21, 1.02, .73, 1) both;
}
.wchat__ligne--moi { justify-content: flex-end; }
.wchat__ligne--autre { justify-content: flex-start; }

.wchat__avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: .62rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    background: linear-gradient(135deg, #059669, #047857);
}
.wchat__ligne--moi .wchat__avatar {
    background: linear-gradient(135deg, #d97706, #c25e00);
    order: 2;
}

.wchat__msg {
    max-width: 80%;
    padding: 8px 12px 6px;
    border-radius: 16px;
    font-size: .85rem;
    line-height: 1.45;
    word-break: break-word;
}
.wchat__ligne--moi .wchat__msg {
    background: linear-gradient(160deg, #1e3a5f, #172033);
    border: 1px solid rgb(217 119 6 / .35);
    border-bottom-right-radius: 5px;
    color: #f8fafc;
}
.wchat__ligne--autre .wchat__msg {
    background: rgb(30 41 59 / .85);
    border: 1px solid rgb(148 163 184 / .2);
    border-bottom-left-radius: 5px;
    color: #e2e8f0;
}
.wchat__msg p { margin: 1px 0 3px; }
.wchat__meta {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: .66rem;
    opacity: .85;
    margin-bottom: 1px;
}
.wchat__meta small { color: #94a3b8; }

/* ---------- Formulaire de saisie ---------- */
.wchat__saisie {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    background: rgb(30 41 59 / .55);
    border-top: 1px solid rgb(148 163 184 / .14);
    flex-shrink: 0;
}
.wchat__saisie input[type="text"],
.wchat__intro input {
    width: 100%;
    min-height: 40px;
    padding: 9px 15px;
    border: 1.5px solid rgb(148 163 184 / .25);
    border-radius: 999px;
    font-size: .9rem;
    font-family: inherit;
    background: rgb(2 6 23 / .6);
    color: #f1f5f9;
    transition: border-color .18s, box-shadow .18s;
}
.wchat__saisie input[type="text"]:focus,
.wchat__intro input:focus {
    outline: none;
    border-color: #d97706;
    box-shadow: 0 0 0 3px rgb(217 119 6 / .2);
}
.wchat__saisie input::placeholder,
.wchat__intro input::placeholder { color: #64748b; }

.wchat__envoyer {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    cursor: pointer;
    color: #fff;
    font-size: .95rem;
    background: linear-gradient(135deg, #d97706, #c25e00);
    box-shadow: 0 8px 16px -6px rgb(194 94 0 / .6);
    transition: filter .16s, transform .16s;
}
.wchat__envoyer:hover { filter: brightness(1.1); transform: translateY(-1px); }
.wchat__envoyer:disabled { opacity: .5; transform: none; }

/* ---------- Premier contact (vitrine) ---------- */
.wchat__intro {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid rgb(148 163 184 / .14);
    background: rgb(30 41 59 / .4);
    flex-shrink: 0;
}
.wchat__intro p {
    margin: 0;
    font-size: .78rem;
    color: #94a3b8;
    line-height: 1.5;
}
.wchat__intro input { border-radius: 12px; min-height: 38px; font-size: .85rem; }

/* ---------- Responsive & accessibilité ---------- */
@media (max-width: 480px) {
    .wchat { right: 14px; bottom: 14px; }
    .wchat__panneau {
        position: fixed;
        right: 8px;
        left: 8px;
        bottom: 86px;
        width: auto;
        height: min(70vh, 540px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .wchat__panneau { transition: none; }
    .wchat__badge, .wchat__badge.est-pulse, .wchat__presence { animation: none; }
    .wchat__bulle, .wchat__envoyer, .wchat__conv { transition: none; }
    .wchat__ligne { animation: none; }
}
