/* ── Global Chatbot Variables ── */
:root {
    --chat-accent: #00C9A7;
    --chat-accent-gradient: linear-gradient(135deg, #00C9A7, #008B74);
    --chat-header-bg: linear-gradient(135deg, #00C9A7, #F4A261);
    --chat-bg-popup: rgba(255, 255, 255, 0.7);
    --chat-body-bg: rgba(243, 244, 246, 0.6);
    --chat-border: 1px solid rgba(255, 255, 255, 0.4);
    --chat-text-bot: #2b2d42;
    --chat-bubble-bot: #ffffff;
    --chat-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

body.dark-mode {
    --chat-accent: #00C9A7;
    --chat-accent-gradient: linear-gradient(135deg, #00C9A7, #0d1f1a);
    --chat-header-bg: linear-gradient(135deg, #1f2937, #111827);
    --chat-bg-popup: rgba(17, 24, 39, 0.75);
    --chat-body-bg: rgba(10, 15, 26, 0.8);
    --chat-border: 1px solid rgba(255, 255, 255, 0.08);
    --chat-text-bot: #f3f4f6;
    --chat-bubble-bot: #1f2937;
    --chat-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

/* ── Floating Widget Icon ── */
.chatbot-floating-icon {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: var(--chat-header-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white !important;
    font-size: 1.8rem;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 10px 30px rgba(0, 201, 167, 0.35);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chatbot-floating-icon:hover {
    transform: scale(1.1) translateY(-3px);
    box-shadow: 0 15px 35px rgba(0, 201, 167, 0.5);
}

.chatbot-floating-icon .glowing-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--chat-accent);
    animation: ring-pulse 2s infinite ease-out;
    pointer-events: none;
}

@keyframes ring-pulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.4); opacity: 0; }
}

/* ── Floating Notification Bubble ── */
.chat-bubble {
    position: absolute;
    bottom: 85px;
    right: -5px;
    background: var(--chat-bubble-bot);
    color: var(--chat-text-bot);
    padding: 10px 18px;
    border-radius: 20px;
    white-space: nowrap;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: var(--chat-shadow);
    border: var(--chat-border);
    animation: bubble-entrance 0.5s ease forwards;
}

@keyframes bubble-entrance {
    0% { opacity: 0; transform: translateY(10px) scale(0.9); }
    100% { opacity: 0.95; transform: translateY(0) scale(1); }
}

/* ── Premium Popup Drawer ── */
.chat-popup.premium-popup {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 390px;
    height: 580px;
    background: var(--chat-bg-popup);
    border-radius: 24px;
    border: var(--chat-border);
    box-shadow: var(--chat-shadow);
    display: none;
    flex-direction: column;
    z-index: 9988;
    overflow: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
}

.chat-popup.premium-popup.active {
    display: flex;
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ── Header ── */
.chat-popup-header {
    padding: 18px 20px;
    background: var(--chat-header-bg);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: var(--chat-border);
}

.chat-header-action {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.chat-header-action:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.pulse-orb-mini {
    width: 8px;
    height: 8px;
    background-color: #2ecc71;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px #2ecc71;
    animation: mini-pulse 1.8s infinite;
}

@keyframes mini-pulse {
    0%, 100% { opacity: 0.6; transform: scale(0.9); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* ── Message Board ── */
.chat-popup-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chat-body-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-popup-body::-webkit-scrollbar {
    width: 5px;
}

.chat-popup-body::-webkit-scrollbar-track {
    background: transparent;
}

.chat-popup-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

/* Messages styling */
.message {
    display: flex;
    max-width: 85%;
    animation: fade-slide-up 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes fade-slide-up {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.message.user-msg {
    align-self: flex-end;
}

.message.bot-msg {
    align-self: flex-start;
}

.message .bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.45;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.user-msg .bubble {
    background: var(--chat-accent);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 201, 167, 0.2);
}

.bot-msg .bubble {
    background: var(--chat-bubble-bot);
    color: var(--chat-text-bot);
    border-bottom-left-radius: 4px;
    border: var(--chat-border);
}

/* ── Suggestion Chips ── */
.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
    max-width: 100%;
}

.chip {
    background: var(--chat-bubble-bot);
    border: 1.5px solid var(--chat-accent);
    color: var(--chat-accent);
    padding: 7px 14px;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(0,0,0,0.02);
}

.chip:hover {
    background: var(--chat-accent);
    color: white;
    transform: translateY(-1.5px);
    box-shadow: 0 4px 10px rgba(0, 201, 167, 0.25);
}

/* ── Footer / Input ── */
.chat-popup-footer {
    padding: 14px 20px 20px;
    background: var(--chat-bg-popup);
    border-top: var(--chat-border);
}

.chat-input-wrapper-popup {
    display: flex;
    align-items: center;
    background: var(--chat-bubble-bot);
    border: var(--chat-border);
    border-radius: 50px;
    padding: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
}

.chat-input-wrapper-popup input.form-control-pill {
    flex: 1;
    border: none !important;
    background: transparent !important;
    color: var(--chat-text-bot) !important;
    padding: 8px 18px;
    outline: none !important;
    font-size: 0.9rem;
    box-shadow: none !important;
}

.btn-chat-send {
    background: var(--chat-accent-gradient);
    color: white;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-chat-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 10px rgba(0, 201, 167, 0.3);
}

/* ── Mobile Layout Overrides ── */
@media (max-width: 768px) {
    .chat-popup.premium-popup {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
        z-index: 9999;
        display: none;
        flex-direction: column;
    }

    .chat-popup.premium-popup.active {
        display: flex;
    }

    /* Bigger close button on mobile header */
    .chat-popup-header .chat-header-action {
        width: 42px;
        height: 42px;
        font-size: 1.1rem;
    }

    /* Mobile bottom close strip */
    .chat-mobile-close-strip {
        display: flex !important;
    }

    /* Compact floating icon on mobile to avoid blocking content */
    .chatbot-floating-icon {
        width: 48px !important;
        height: 48px !important;
        bottom: 16px !important;
        right: 16px !important;
        font-size: 1.3rem !important;
        box-shadow: 0 6px 20px rgba(0, 201, 167, 0.35) !important;
    }

    /* Hide the static 'Need support?' bubble on mobile to avoid obstructing clinical cards */
    .chat-bubble {
        display: none !important;
    }
}

/* Mobile close strip - hidden on desktop */
.chat-mobile-close-strip {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: var(--chat-bg-popup);
    border-top: var(--chat-border);
}

.chat-mobile-close-btn {
    background: rgba(231, 76, 60, 0.12);
    border: 1.5px solid rgba(231, 76, 60, 0.3);
    color: #e74c3c;
    border-radius: 50px;
    padding: 10px 30px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    max-width: 280px;
}

.chat-mobile-close-btn:hover {
    background: rgba(231, 76, 60, 0.2);
    transform: scale(1.02);
}

/* ── Typing Indicator Dots ── */
.typing-indicator .bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
}

.typing-indicator .bubble span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-accent);
    display: inline-block;
    animation: typing-bounce 1.3s infinite ease-in-out both;
}

.typing-indicator .bubble span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator .bubble span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator .bubble span:nth-child(3) { animation-delay: 0s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40%           { transform: scale(1); opacity: 1; }
}
