/* ═══════════════════════════════════════════════════════════════
   Facebook Messenger Chatbot — chatbot.css
   ═══════════════════════════════════════════════════════════════ */

/* ── Base font ──────────────────────────────────────────────── */
.fmb-embedded-wrap,
.fmb-widget-container {
    font-family: -apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    box-sizing: border-box;
}
.fmb-embedded-wrap *,
.fmb-widget-container * {
    box-sizing: border-box;
}

/* ══════════════════════════════════════════════════════════════
   EMBEDDED MODE
   ══════════════════════════════════════════════════════════════ */

.fmb-embedded-wrap {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    background: #f0f2f5 !important;
    z-index: 2147483647 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Kill EVERYTHING else on the page */
html, body {
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    height: 100% !important;
    width: 100% !important;
}

/* ── Chat inner (shared between embedded + widget panel) ────── */
.fmb-chat-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: #f0f2f5;
}

/* ── Header ─────────────────────────────────────────────────── */
.fmb-header {
    /* bg set via inline style (theme_color) */
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}

.fmb-header-avatar-wrap {
    position: relative;
    flex-shrink: 0;
    width: 42px;
    height: 42px;
}

.fmb-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    font-size: 15px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.4);
}

.fmb-avatar-img { padding: 0; border: 2px solid rgba(255,255,255,0.5); }
.fmb-avatar-img img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }

/* Active green ring */
.fmb-online-ring {
    position: absolute;
    bottom: 1px; right: 1px;
    width: 11px; height: 11px;
    border-radius: 50%;
    background: #44c767;
    border: 2px solid #fff;
    animation: fmbRingPulse 2.5s ease-in-out infinite;
}

@keyframes fmbRingPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(68,199,103,0.6); }
    50%       { box-shadow: 0 0 0 4px rgba(68,199,103,0); }
}

.fmb-header-info { flex: 1; }
.fmb-agent-name  { color: #fff; font-weight: 700; font-size: 16px; line-height: 1.2; }
.fmb-agent-status { color: rgba(255,255,255,0.82); font-size: 12.5px; margin-top: 2px; }

/* ── Messages area ──────────────────────────────────────────── */
.fmb-messages {
    flex: 1;
    padding: 16px 14px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: #ccc transparent;
}
.fmb-messages::-webkit-scrollbar { width: 4px; }
.fmb-messages::-webkit-scrollbar-track { background: transparent; }
.fmb-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* ── Message groups ─────────────────────────────────────────── */
.fmb-msg-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 6px;
    animation: fmbSlideIn 0.22s cubic-bezier(.2,.8,.4,1) both;
}
.fmb-msg-group.fmb-bot  { align-items: flex-start; padding-left: 38px; position: relative; }
.fmb-msg-group.fmb-user { align-items: flex-end; }

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

/* Bot avatar beside messages */
.fmb-msg-avatar {
    position: absolute;
    left: 0; bottom: 0;
    width: 28px; height: 28px;
    border-radius: 50%;
    background: #0084ff;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 700; color: #fff;
    overflow: hidden;
    flex-shrink: 0;
}
.fmb-msg-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ── Bubbles ─────────────────────────────────────────────────── */
.fmb-bubble {
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.45;
    word-break: break-word;
    max-width: 75%;
    position: relative;
}

/* Bot bubbles */
.fmb-bot .fmb-bubble {
    background: #fff;
    color: #050505;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 2px;
}
/* First bot bubble in group — square bottom-left corner */
.fmb-bot .fmb-bubble:first-of-type { border-bottom-left-radius: 4px; }
/* Middle */
.fmb-bot .fmb-bubble:not(:first-of-type):not(:last-of-type) { border-radius: 4px 18px 18px 4px; }
/* Last */
.fmb-bot .fmb-bubble:last-of-type { border-radius: 4px 18px 18px 18px; }

/* User bubbles — themed color */
.fmb-user .fmb-bubble {
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    margin-bottom: 2px;
    /* background set via JS with theme color */
}
.fmb-user .fmb-bubble:not(:first-of-type):not(:last-of-type) { border-radius: 18px 4px 4px 18px; }
.fmb-user .fmb-bubble:last-of-type { border-radius: 18px 4px 18px 18px; }

/* Timestamp */
.fmb-timestamp {
    font-size: 11px;
    color: #8a8d91;
    margin: 3px 4px 8px;
    text-align: right;
}
.fmb-bot + .fmb-timestamp,
.fmb-msg-group.fmb-bot .fmb-timestamp { text-align: left; margin-left: 4px; }

/* Seen indicator */
.fmb-seen {
    font-size: 11px;
    color: #8a8d91;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}
.fmb-seen-avatar {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #0084ff;
    display: inline-flex;
    align-items: center; justify-content: center;
    font-size: 8px; color: #fff; font-weight: 700;
    overflow: hidden;
}
.fmb-seen-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* ── Quick reply buttons ─────────────────────────────────────── */
.fmb-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0 4px;
    padding-left: 38px;
    animation: fmbSlideIn 0.3s cubic-bezier(.2,.8,.4,1) both;
    animation-delay: 0.05s;
}

.fmb-qr-btn {
    background: #fff;
    border: 1.5px solid; /* color set via JS */
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.fmb-qr-btn:hover,
.fmb-qr-btn:active {
    color: #fff !important;
    border-color: transparent !important;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

/* ── Typing indicator ────────────────────────────────────────── */
.fmb-typing-row {
    display: none;
    align-items: flex-end;
    gap: 8px;
    padding: 4px 14px 10px;
    flex-shrink: 0;
}
.fmb-typing-row.active {
    display: flex;
    animation: fmbSlideIn 0.2s ease;
}

.fmb-typing-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: #0084ff;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 700; color: #fff;
    flex-shrink: 0;
    overflow: hidden;
}
.fmb-typing-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.fmb-typing-bubble {
    background: #fff;
    border-radius: 18px 18px 18px 4px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.fmb-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #bcc0c4;
    animation: fmbDotBounce 1.3s ease-in-out infinite;
}
.fmb-dot:nth-child(1) { animation-delay: 0s; }
.fmb-dot:nth-child(2) { animation-delay: 0.18s; }
.fmb-dot:nth-child(3) { animation-delay: 0.36s; }

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

/* ══════════════════════════════════════════════════════════════
   WIDGET MODE — floating bubble
   ══════════════════════════════════════════════════════════════ */

.fmb-widget-container {
    position: fixed;
    bottom: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.fmb-widget-right { right: 24px; align-items: flex-end; }
.fmb-widget-left  { left: 24px;  align-items: flex-start; }

/* Chat panel */
.fmb-widget-panel {
    width: 360px;
    height: 500px;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 12px;
    transform: scale(0.85) translateY(20px);
    transform-origin: bottom right;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), opacity 0.25s ease;
    display: flex;
    flex-direction: column;
}
.fmb-widget-left .fmb-widget-panel {
    transform-origin: bottom left;
}

.fmb-widget-container.fmb-open .fmb-widget-panel {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

.fmb-widget-panel .fmb-chat-inner {
    height: 100%;
}

/* Launcher button */
.fmb-launcher {
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 28px;
    padding: 12px 20px 12px 14px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    user-select: none;
}
.fmb-launcher:hover {
    transform: scale(1.04);
    box-shadow: 0 6px 26px rgba(0,0,0,0.3);
}
.fmb-launcher:active { transform: scale(0.98); }

.fmb-launcher-icon {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(.34,1.56,.64,1);
}
.fmb-launcher-icon svg { width: 28px; height: 28px; }

.fmb-launcher-label {
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    transition: opacity 0.2s, max-width 0.3s;
    max-width: 160px;
    overflow: hidden;
}

.fmb-launcher-close {
    color: #fff;
    font-size: 18px;
    font-weight: 400;
    transition: transform 0.25s ease;
}

.fmb-widget-container.fmb-open .fmb-launcher-icon { display: none; }
.fmb-widget-container.fmb-open .fmb-launcher-label { display: none; }
.fmb-widget-container.fmb-open .fmb-launcher-close { display: block !important; }

/* Unread badge */
.fmb-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: #e41e3f;
    color: #fff;
    border-radius: 50%;
    width: 18px; height: 18px;
    font-size: 11px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #fff;
    animation: fmbBadgePop 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes fmbBadgePop {
    from { transform: scale(0); }
    to   { transform: scale(1); }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 400px) {
    .fmb-widget-panel { width: calc(100vw - 16px); }
    .fmb-widget-right { right: 8px; }
    .fmb-widget-left  { left: 8px; }
}
