/**
 * Consterapia — Chatbot CSS
 * Bouton flottant + fenêtre de chat + bulles + animations
 * @since 2.1.0
 */

/* ================================================================
   VARIABLES
   ================================================================ */
:root {
    --chat-color:       #e5b720; /* overridée via JS inline style */
    --chat-color-dk:    #C9A227;
    --chat-bot-bg:      #f5f0e8;
    --chat-user-bg:     var(--chat-color);
    --chat-user-text:   #fff;
    --chat-bot-text:    #3E2723;
    --chat-bg:          #fff;
    --chat-header-bg:   var(--chat-color);
    --chat-header-text: #fff;
    --chat-radius:      18px;
    --chat-shadow:      0 8px 32px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .10);
    --chat-font:        'Nunito Sans', -apple-system, sans-serif;
    --chat-z:           99998;
}

/* ================================================================
   WRAPPER
   ================================================================ */
.cfe-chat {
    position: fixed;
    bottom: 24px;
    z-index: var(--chat-z);
    font-family: var(--chat-font);
    font-size: 14px;
    line-height: 1.5;
}
.cfe-chat--right { right: 24px; }
.cfe-chat--left  { left: 24px; }

/* ================================================================
   BUBBLE BUTTON
   ================================================================ */
.cfe-chat__bubble {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--chat-color);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .22);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s, box-shadow .2s;
    animation: cfe-pulse 2.8s ease-in-out infinite;
    outline: none;
}
.cfe-chat__bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, .28);
    animation: none;
}
.cfe-chat__bubble:focus-visible {
    outline: 3px solid var(--chat-color-dk);
    outline-offset: 3px;
}

.cfe-chat--open .cfe-chat__bubble { animation: none; }

.cfe-chat__bubble-icon svg {
    width: 26px;
    height: 26px;
    color: #fff;
    transition: transform .25s;
}
.cfe-chat--open .cfe-chat__bubble-icon svg {
    transform: rotate(45deg) scale(.8);
}

@keyframes cfe-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0,0,0,.22), 0 0 0 0 rgba(229,183,32,.4); }
    50%       { box-shadow: 0 4px 20px rgba(0,0,0,.22), 0 0 0 10px rgba(229,183,32,0); }
}

/* Unread badge */
.cfe-chat__unread {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #e53935;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #fff;
    animation: cfe-pop .3s ease;
}
@keyframes cfe-pop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

/* ================================================================
   CHAT WINDOW
   ================================================================ */
.cfe-chat__window {
    position: absolute;
    bottom: 70px;
    width: 340px;
    max-height: 520px;
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: cfe-open .25s cubic-bezier(.175,.885,.32,1.275);
}
/* Le hidden attribute ne peut pas écraser display:flex sans !important */
.cfe-chat__window[hidden] { display: none !important; }
.cfe-chat--left .cfe-chat__window {
    left: 0;
    transform-origin: bottom left;
    animation-name: cfe-open-left;
}
.cfe-chat--right .cfe-chat__window { right: 0; }

@keyframes cfe-open {
    from { opacity: 0; transform: scale(.85) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes cfe-open-left {
    from { opacity: 0; transform: scale(.85) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ================================================================
   HEADER
   ================================================================ */
.cfe-chat__header {
    background: var(--chat-color);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
}
.cfe-chat__header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.cfe-chat__avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cfe-chat__avatar img { width: 100%; height: 100%; object-fit: cover; }
.cfe-chat__avatar svg { width: 22px; height: 22px; color: #fff; }
.cfe-chat__bot-name {
    display: block;
    font-weight: 700;
    font-size: .9rem;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cfe-chat__status {
    font-size: .72rem;
    color: rgba(255,255,255,.85);
}

.cfe-chat__header-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.cfe-chat__btn-icon {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    color: #fff;
}
.cfe-chat__btn-icon:hover { background: rgba(255,255,255,.35); }
.cfe-chat__btn-icon svg { width: 14px; height: 14px; }

/* ================================================================
   MESSAGES ZONE
   ================================================================ */
.cfe-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    min-height: 160px;
    max-height: 280px;
}
.cfe-chat__messages::-webkit-scrollbar { width: 4px; }
.cfe-chat__messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 4px; }

/* Bulles */
.cfe-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}
.cfe-msg--bot  { align-self: flex-start; align-items: flex-start; }
.cfe-msg--user { align-self: flex-end;   align-items: flex-end; }

.cfe-msg__bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: .875rem;
    line-height: 1.5;
    word-break: break-word;
    animation: cfe-msg-in .2s ease;
}
@keyframes cfe-msg-in {
    from { opacity: 0; transform: translateY(6px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.cfe-msg--bot .cfe-msg__bubble {
    background: var(--chat-bot-bg);
    color: var(--chat-bot-text);
    border-bottom-left-radius: 4px;
}
.cfe-msg--user .cfe-msg__bubble {
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-bottom-right-radius: 4px;
}
.cfe-msg__bubble a { color: inherit; text-decoration: underline; }

.cfe-msg__ts {
    font-size: .68rem;
    color: #bbb;
    margin-top: 3px;
    padding: 0 4px;
}

/* ================================================================
   TYPING INDICATOR
   ================================================================ */
.cfe-chat__typing {
    padding: 10px 16px;
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}
.cfe-chat__typing span {
    width: 7px;
    height: 7px;
    background: #bbb;
    border-radius: 50%;
    animation: cfe-bounce .9s infinite;
}
.cfe-chat__typing span:nth-child(2) { animation-delay: .2s; }
.cfe-chat__typing span:nth-child(3) { animation-delay: .4s; }
@keyframes cfe-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%            { transform: translateY(-6px); }
}

/* ================================================================
   LEAD CAPTURE FORM
   ================================================================ */
.cfe-chat__lead {
    padding: 12px 14px;
    background: #fdf8ed;
    border-top: 1px solid rgba(229,183,32,.2);
    flex-shrink: 0;
}
.cfe-chat__lead-prompt {
    font-size: .82rem;
    color: #5D4037;
    margin: 0 0 8px;
}
.cfe-chat__lead-input {
    width: 100%;
    padding: 8px 10px;
    border: 1.5px solid #e0d6c8;
    border-radius: 8px;
    font-size: .85rem;
    font-family: inherit;
    margin-bottom: 6px;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s;
}
.cfe-chat__lead-input:focus { border-color: var(--chat-color); }
.cfe-chat__lead-input.cfe-input--error { border-color: #e53935; }
.cfe-chat__lead-btn {
    width: 100%;
    padding: 9px;
    background: var(--chat-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s;
}
.cfe-chat__lead-btn:hover { background: var(--chat-color-dk); }

/* ================================================================
   QUICK REPLIES
   ================================================================ */
.cfe-chat__quick {
    padding: 0 12px 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}
.cfe-quick-btn {
    background: #fff;
    border: 1.5px solid var(--chat-color);
    color: #5D4037;
    border-radius: 20px;
    padding: 5px 13px;
    font-size: .78rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.cfe-quick-btn:hover {
    background: var(--chat-color);
    color: #fff;
}

/* ================================================================
   RGPD NOTICE
   ================================================================ */
.cfe-chat__gdpr {
    padding: 6px 14px;
    font-size: .68rem;
    color: #999;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    background: #fafafa;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    line-height: 1.4;
}
.cfe-chat__gdpr svg { flex-shrink: 0; margin-top: 1px; color: #bbb; }
.cfe-chat__gdpr a { color: #8d6e63; text-decoration: underline; }

/* ================================================================
   FOOTER / INPUT
   ================================================================ */
.cfe-chat__footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}
.cfe-chat__input {
    flex: 1;
    border: 1.5px solid #e0d6c8;
    border-radius: 12px;
    padding: 8px 12px;
    font-size: .875rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color .15s;
    background: #fafafa;
}
.cfe-chat__input:focus { border-color: var(--chat-color); background: #fff; }

.cfe-chat__send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--chat-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .15s, opacity .15s;
    opacity: 1;
}
.cfe-chat__send:disabled {
    background: #d0ccc5;
    cursor: default;
    opacity: .7;
    transform: none;
}
.cfe-chat__send:not(:disabled):hover { background: var(--chat-color-dk); transform: scale(1.06); }
.cfe-chat__send svg { width: 16px; height: 16px; color: #fff; }

/* ================================================================
   RESPONSIVE — Mobile
   ================================================================ */
@media (max-width: 480px) {
    .cfe-chat { bottom: 16px; }
    .cfe-chat--right { right: 16px; }
    .cfe-chat--left  { left: 16px; }

    .cfe-chat__window {
        width: calc(100vw - 32px);
        bottom: 74px;
        /* 90px bottom offset + 110px top clearance (site header ~60px + admin bar 46px + 4px) */
        max-height: calc(100vh - 200px);
    }
    .cfe-chat__messages { max-height: calc(100vh - 390px); }
}

/* When WP admin bar is visible (logged-in users) — extra 46px clearance on mobile */
@media (max-width: 782px) {
    .admin-bar .cfe-chat__window {
        /* admin-bar mobile height = 46px, add on top of the 200px already reserved */
        max-height: calc(100vh - 246px);
    }
    .admin-bar .cfe-chat__messages { max-height: calc(100vh - 436px); }
}

/* ================================================================
   DARK MODE
   ================================================================ */
[data-theme="dark"] .cfe-chat__window {
    background: #241c18;
}
[data-theme="dark"] .cfe-chat__messages {
    background: #241c18;
}
[data-theme="dark"] .cfe-msg--bot .cfe-msg__bubble {
    background: #2d2320;
    color: #e8ddd5;
}
[data-theme="dark"] .cfe-chat__footer {
    border-color: rgba(255,255,255,.08);
    background: #241c18;
}
[data-theme="dark"] .cfe-chat__input {
    background: #2d2320;
    border-color: rgba(255,255,255,.12);
    color: #e8ddd5;
}
[data-theme="dark"] .cfe-chat__gdpr {
    background: #1e1612;
    border-color: rgba(255,255,255,.06);
}
[data-theme="dark"] .cfe-chat__lead {
    background: #2a1f1a;
    border-color: rgba(229,183,32,.15);
}
[data-theme="dark"] .cfe-chat__lead-input {
    background: #3d2c25;
    border-color: rgba(255,255,255,.15);
    color: #e8ddd5;
}
[data-theme="dark"] .cfe-quick-btn {
    background: #2d2320;
    color: #e8ddd5;
}
