/* =========================================================
   EMAPI Chatbot Widget
   ========================================================= */

/* ── Floating toggle button ──────────────────────────────── */
#emapi-chat-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, #CC0000, #990000);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 6px 24px rgba(204,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), box-shadow 0.3s ease, opacity 0.3s ease;
}
#emapi-chat-toggle:hover {
    transform: scale(1.12);
    box-shadow: 0 10px 32px rgba(204,0,0,0.55);
}
#emapi-chat-toggle .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #fff;
    color: #CC0000;
    font-size: 0.65rem;
    font-weight: 800;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #CC0000;
    animation: none;
}
@keyframes badge-pulse {
    0%,100% { transform: scale(1); }
    50%      { transform: scale(1.2); }
}

/* ── Chat window ─────────────────────────────────────────── */
#emapi-chat-window {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 360px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 4px 16px rgba(204,0,0,0.12);
    display: flex;
    flex-direction: column;
    z-index: 9998;
    overflow: hidden;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transform-origin: bottom right;
    transition: transform 0.35s cubic-bezier(.34,1.56,.64,1),
                opacity 0.25s ease;
}
#emapi-chat-window.is-open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ── Header ──────────────────────────────────────────────── */
.chat-header {
    background: linear-gradient(135deg, #CC0000, #990000);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-info strong {
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
}
.chat-header-info span {
    font-size: 0.75rem;
    opacity: 0.85;
}
.chat-header-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    margin-right: 5px;
    box-shadow: 0 0 6px #4ade80;
    animation: status-pulse 2s ease infinite;
}
@keyframes status-pulse {
    0%,100% { opacity: 1; }
    50%      { opacity: 0.5; }
}
.chat-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
    line-height: 1;
}
.chat-close-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* ── Messages area ───────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 4px; }

/* Bubbles */
.chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: msg-in 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-msg.bot { justify-content: flex-start; }
.chat-msg.user { justify-content: flex-end; }

.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #CC0000, #990000);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    flex-shrink: 0;
}
.chat-bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.875rem;
    line-height: 1.5;
}
.chat-msg.bot .chat-bubble {
    background: #f4f4f4;
    color: #1a1a1a;
    border-bottom-left-radius: 4px;
}
.chat-msg.user .chat-bubble {
    background: linear-gradient(135deg, #CC0000, #990000);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.chat-typing .chat-bubble {
    padding: 12px 16px;
}
.chat-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    height: 16px;
}
.chat-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #aaa;
    animation: dot-bounce 1.2s ease infinite;
}
.chat-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%         { transform: translateY(-6px); background: #CC0000; }
}

/* ── Quick replies ───────────────────────────────────────── */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px;
}
.chat-quick-btn {
    background: #fff;
    border: 1.5px solid #CC0000;
    color: #CC0000;
    border-radius: 50px;
    padding: 5px 14px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
.chat-quick-btn:hover {
    background: #CC0000;
    color: #fff;
}

/* ── Input area ──────────────────────────────────────────── */
.chat-input-area {
    padding: 12px 14px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}
.chat-input-area input {
    flex: 1;
    border: 1.5px solid #e0e0e0;
    border-radius: 50px;
    padding: 9px 16px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: 'Inter', sans-serif;
}
.chat-input-area input:focus { border-color: #CC0000; }
.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #CC0000, #990000);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(204,0,0,0.3);
}
.chat-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(204,0,0,0.45);
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 480px) {
    #emapi-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 75vh;
        border-radius: 20px 20px 0 0;
    }
    #emapi-chat-toggle {
        bottom: 20px;
        right: 20px;
    }
}
