/* ═══════════════════════════════════════════════════════════
   chatbot.css — Bio Med Ingredients Floating Chat Widget
   ═══════════════════════════════════════════════════════════ */

/* ── Chat Toggle Button ──────────────────────────────────── */
#bm-chat-toggle {
    position: fixed;
    bottom: 100px;
    right: 30px;
    z-index: 99999;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    transition: filter 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    filter: drop-shadow(0 6px 14px rgba(0,0,0,0.25));
    animation: bm-premium-float 4s ease-in-out infinite;
    will-change: transform, filter;
}

@keyframes bm-premium-float {
    0%   { transform: translateY(0px) scale(1); filter: drop-shadow(0 6px 14px rgba(0,0,0,0.25)); }
    50%  { transform: translateY(-6px) scale(1.02); filter: drop-shadow(0 12px 24px rgba(0,0,0,0.15)); }
    100% { transform: translateY(0px) scale(1); filter: drop-shadow(0 6px 14px rgba(0,0,0,0.25)); }
}

@keyframes bm-magnetic-pulse {
    0%   { filter: drop-shadow(0 15px 30px rgba(50, 200, 100, 0.4)) brightness(1.1); }
    100% { filter: drop-shadow(0 25px 50px rgba(50, 200, 100, 0.8)) brightness(1.25); }
}

#bm-chat-toggle:hover {
    animation: bm-magnetic-pulse 1s ease-in-out infinite alternate !important;
}

#bm-chat-toggle:active {
    transform: translateY(-2px) scale(1.05) !important;
    filter: drop-shadow(0 5px 15px rgba(50, 200, 100, 0.4)) brightness(1.05) !important;
    transition: filter 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

#bm-chat-toggle .bm-chat-icon-open,
#bm-chat-toggle .bm-chat-icon-close {
    position: absolute;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#bm-chat-toggle .bm-chat-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

#bm-chat-toggle.active .bm-chat-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

#bm-chat-toggle.active .bm-chat-icon-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}


/* ── Chat Window ─────────────────────────────────────────── */
#bm-chat-window {
    position: fixed;
    bottom: 175px;
    right: 30px;
    width: 360px;
    height: 600px;
    max-height: 80vh;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15), 0 5px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99998;
    transform-origin: bottom right;

    /* Hidden state */
    transform: scale(0.6) translateY(30px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.25s ease;
}

#bm-chat-window.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto !important;
}

/* ── Header ──────────────────────────────────────────────── */
#bm-chat-header {
    background: linear-gradient(135deg, #1a6b3c 0%, #0d4225 100%);
    color: #fff;
    padding: 16px 20px;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.bm-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.bm-header-info h6 {
    margin: 0;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.3px;
}

.bm-header-info span {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 5px;
}

.bm-online-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    display: inline-block;
    animation: bm-pulse 2s infinite;
}

.bm-header-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.bm-header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}

.bm-header-btn:hover {
    background: rgba(255,255,255,0.28);
}

/* ── Messages Area ───────────────────────────────────────── */
#bm-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

#bm-messages::-webkit-scrollbar { width: 4px; }
#bm-messages::-webkit-scrollbar-thumb { background: #cde7d6; border-radius: 4px; }

/* ── Message Bubbles ─────────────────────────────────────── */
.bm-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: bm-slide-in 0.3s ease;
}

@keyframes bm-slide-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bm-msg.bot {
    align-self: flex-start;
    max-width: 88%;
}

.bm-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    max-width: 88%;
}

.bm-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a6b3c, #0d4225);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.bm-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    text-align: justify;
    -webkit-hyphens: auto;
    hyphens: auto;
}

/* ── Source Links ────────────────────────────────────────── */
.bm-sources-container {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.1);
}
.bm-sources-container strong {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #1a6b3c;
    display: block;
    margin-bottom: 6px;
}
.bm-msg.user .bm-sources-container strong {
    color: rgba(255,255,255,0.8);
    border-top-color: rgba(255,255,255,0.2);
}
.bm-sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bm-source-link {
    display: inline-block;
    padding: 4px 10px;
    font-size: 12px;
    background: rgba(26, 107, 60, 0.1);
    color: #1a6b3c;
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.2s;
}
.bm-source-link:hover {
    background: #1a6b3c;
    color: #fff;
    text-decoration: none;
}
.bm-msg.user .bm-source-link {
    background: rgba(255,255,255,0.2);
    color: #fff;
}
.bm-msg.user .bm-source-link:hover {
    background: #fff;
    color: #1a6b3c;
}

/* Restrict heading sizes from markdown */
.bm-bubble h1, .bm-bubble h2 {
    font-size: 1.15em !important;
    font-weight: 700 !important;
    margin-top: 12px !important;
    margin-bottom: 8px !important;
    line-height: 1.3 !important;
}

.bm-bubble h3, .bm-bubble h4, .bm-bubble h5, .bm-bubble h6 {
    font-size: 1.05em !important;
    font-weight: 700 !important;
    margin-top: 10px !important;
    margin-bottom: 6px !important;
    line-height: 1.3 !important;
}

.bm-bubble p {
    margin-bottom: 8px;
}
.bm-bubble p:last-child {
    margin-bottom: 0;
}
.bm-bubble ul, .bm-bubble ol {
    margin-bottom: 8px;
    padding-left: 20px;
}
.bm-bubble li {
    margin-bottom: 4px;
}
.bm-bubble table {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin-bottom: 8px;
    font-size: 13px;
}
.bm-bubble th, .bm-bubble td {
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 6px 8px;
    text-align: left;
    white-space: nowrap;
}
.bm-msg.user .bm-bubble th, .bm-msg.user .bm-bubble td {
    border: 1px solid rgba(255, 255, 255, 0.2);
}
.bm-bubble th {
    background: rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

/* Card layout for tables on small screens */
.bm-table-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 12px 0;
}
.bm-table-card {
    background: rgba(255,255,255,0.7);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}
.bm-msg.user .bm-table-card {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.25);
}
.bm-card-row {
    font-size: 13.5px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
}
.bm-card-row:last-child {
    margin-bottom: 0;
}
.bm-card-row strong {
    font-size: 11px;
    text-transform: uppercase;
    color: #1a6b3c;
    margin-bottom: 2px;
    letter-spacing: 0.5px;
}
.bm-msg.user .bm-card-row strong {
    color: rgba(255,255,255,0.9);
}
.bm-card-val {
    color: #333;
}
.bm-msg.user .bm-card-val {
    color: #fff;
}
.bm-msg.user .bm-bubble th {
    background: rgba(255, 255, 255, 0.1);
}

.bm-msg.bot .bm-bubble {
    background: #fff;
    color: #1a202c;
    border-radius: 4px 18px 18px 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.bm-msg.user .bm-bubble {
    background: linear-gradient(135deg, #1a6b3c 0%, #0d4225 100%);
    color: #fff;
    border-radius: 18px 4px 18px 18px;
}

/* ── Typing Indicator ────────────────────────────────────── */
.bm-typing .bm-bubble {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-items: center;
}

.bm-dot {
    width: 7px;
    height: 7px;
    background: #1a6b3c;
    border-radius: 50%;
    animation: bm-bounce 1.2s infinite;
}

.bm-dot:nth-child(2) { animation-delay: 0.2s; }
.bm-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bm-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Welcome Card ────────────────────────────────────────── */
.bm-welcome-card {
    background: linear-gradient(135deg, #e8f5ee 0%, #d1eddc 100%);
    border: 1px solid #b7dfca;
    border-radius: 14px;
    padding: 14px;
    font-size: 13px;
    color: #1a4a2e;
    line-height: 1.5;
}

.bm-welcome-card strong {
    color: #0d4225;
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
}

/* Quick Suggestions */
.bm-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.bm-suggestion-chip {
    background: #fff;
    border: 1.5px solid #1a6b3c;
    color: #1a6b3c;
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-weight: 500;
}

.bm-suggestion-chip:hover {
    background: #1a6b3c;
    color: #fff;
}

/* ── Input Area ──────────────────────────────────────────── */
#bm-chat-footer {
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #e8ede8;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

#bm-input {
    flex: 1;
    border: 1.5px solid #d1d5db;
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    line-height: 1.4;
    background: #f8fafb;
    color: #000 !important;
    caret-color: #000 !important;
    cursor: text !important;
}

#bm-input:focus {
    border-color: #1a6b3c;
    background: #fff;
}

#bm-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1a6b3c, #0d4225);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
}

#bm-send-btn:hover { transform: scale(1.1); }
#bm-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Powered by footer ───────────────────────────────────── */
.bm-powered {
    text-align: center;
    font-size: 10.5px;
    color: #a0aec0;
    padding: 6px 0 8px;
    background: #fff;
}

/* ── Responsive (mobile) ─────────────────────────────────── */
@media (max-width: 991.98px) {
    #bm-chat-toggle {
        bottom: 154px; /* Push above the scroll-to-top button */
        right: 20px;
        width: 60px !important; /* Slightly smaller for mobile */
        height: 60px !important;
    }
}


@media (max-width: 480px) {
    #bm-chat-window {
        width: calc(100vw - 24px);
        right: 12px;
        bottom: 215px;
        height: min(70dvh, calc(100dvh - 230px));
        max-height: 70vh;
    }

}

/* ── Mascot Integration ── */
#bm-mascot-container {
    position: relative;
    width: 85px;
    height: 85px;
    z-index: 10;
    pointer-events: none; /* Let clicks pass through except on the mascot image itself */
    perspective: 1000px;
}

#bm-mascot-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.bm-character {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: bottom center;
    transform-style: preserve-3d;
    transition: filter 0.3s ease;
    pointer-events: auto; /* Catch clicks */
}

#bm-mascot-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
}

.bm-particles-container {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* Animations from Demo */
@keyframes bm-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.02, 0.98); } }
@keyframes bm-sway { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(5deg); } }
@keyframes bm-bounce { 0%, 100% { transform: translateY(0) scale(1.05, 0.95); } 50% { transform: translateY(-20px) scale(0.95, 1.05); } }
@keyframes bm-nod { 0%, 100% { transform: rotate(0deg) translateY(0); } 50% { transform: rotate(0deg) translateY(8px); } }
@keyframes bm-jump { 0%, 100% { transform: translateY(0) scale(1.1, 0.9); } 40% { transform: translateY(-30px) scale(0.9, 1.1); } 50% { transform: translateY(-35px) scale(0.95, 1.05); } 60% { transform: translateY(-30px) scale(0.9, 1.1); } }
@keyframes bm-laugh-shake { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@keyframes bm-loading-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes bm-state-pop { 0% { transform: scale(0.85); opacity: 0.5; } 50% { transform: scale(1.05); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

.bm-pop-anim { animation: bm-state-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }

/* States */
.bm-state-happy .bm-character { animation: bm-sway 4s ease-in-out infinite, bm-breathe 3s ease-in-out infinite; }
.bm-state-greeting .bm-character { animation: bm-bounce 1s cubic-bezier(0.34, 1.56, 0.64, 1) infinite; }
.bm-state-thinking .bm-character { animation: bm-sway 3s ease-in-out infinite; transform: scale(1.05); }
.bm-state-listening .bm-character { transform: rotate(-5deg) scale(1.05); animation: bm-breathe 3s infinite; }
.bm-state-explaining .bm-character { animation: bm-nod 2s ease-in-out infinite; }
.bm-state-excited .bm-character { animation: bm-jump 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) infinite; }
.bm-state-surprised .bm-character { transform: scale(1.1) translateY(-10px); }
.bm-state-confused .bm-character { transform: rotate(10deg); animation: bm-sway 4s infinite; }
.bm-state-sad .bm-character { transform: scaleY(0.9) translateY(10px); }
.bm-state-laughing .bm-character { animation: bm-laugh-shake 0.4s infinite; }
.bm-state-wink .bm-character { transform: scale(1.05); }
.bm-state-love .bm-character { animation: bm-bounce 1.5s infinite; }
.bm-state-proud .bm-character { transform: scale(1.05); animation: bm-breathe 3s infinite; }
.bm-state-processing .bm-loading-ring { position: absolute; top: 50%; left: 50%; width: 140px; height: 140px; margin-left: -70px; margin-top: -70px; border: 4px dashed #3b82f6; border-radius: 50%; animation: bm-loading-spin 3s linear infinite; z-index: 20; pointer-events: none; }
.bm-state-processing .bm-character { animation: bm-breathe 1s infinite; }
.bm-state-success .bm-character { animation: bm-jump 1s cubic-bezier(0.34, 1.56, 0.64, 1) infinite; filter: drop-shadow(0 0 20px rgba(34, 197, 94, 0.6)); }
.bm-state-error .bm-character { transform: scaleY(0.95) translateY(5px); animation: bm-sway 5s infinite; filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.5)); }
.bm-state-sleep .bm-character { animation: bm-breathe 4s ease-in-out infinite; filter: brightness(0.8); }
.bm-state-celebration .bm-character { animation: bm-jump 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) infinite; }

/* Particles */
.bm-particle { position: absolute; pointer-events: none; z-index: 100; opacity: 0; animation: bm-particle-float 1s ease-out forwards; }
.bm-particle-heart::before { content: "❤️"; font-size: 16px; }
.bm-particle-sparkle::before { content: "✨"; font-size: 14px; }
.bm-particle-zzz::before { content: "Z"; font-size: 12px; font-weight: bold; color: #94a3b8; }
.bm-particle-question::before { content: "?"; font-size: 18px; font-weight: bold; color: #475569; }
.bm-particle-confetti { width: 6px; height: 10px; background: #ef4444; border-radius: 2px; }
.bm-particle-confetti:nth-child(even) { background: #3b82f6; }
.bm-particle-confetti:nth-child(3n) { background: #eab308; }
.bm-particle-confetti:nth-child(4n) { background: #10b981; }

@keyframes bm-particle-float { 0% { transform: translateY(0) scale(0.5); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(-50px) scale(1.2); opacity: 0; } }
@keyframes bm-particle-confetti-fall { 0% { transform: translateY(-40px) rotate(0deg); opacity: 1; } 100% { transform: translateY(120px) rotate(360deg); opacity: 0; } }
.bm-particle-confetti { animation: bm-particle-confetti-fall 1.5s ease-out forwards; }

/* Chatbot Enhancements */
.bm-feedback-container {
    display: flex;
    gap: 8px;
    margin-top: 5px;
    justify-content: flex-end;
}
.bm-feedback-btn {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.2s, transform 0.1s;
    padding: 2px;
}
.bm-feedback-btn:hover {
    color: #4a90d9;
    transform: scale(1.1);
}
.bm-feedback-btn.active {
    color: #28a745;
}
.bm-feedback-btn.active-down {
    color: #dc3545;
}

.bm-handoff-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 6px 12px;
    background-color: #f1f3f5;
    color: #2c5f8a;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s;
}
.bm-handoff-btn:hover {
    background-color: #e2e6ea;
    color: #1b4b72;
}
