/* RAG Chatbot CSS - Modern Polished UI */

:root {
    --rag-primary: #266fe0;
    /* Override by JS */
    --rag-bg: #ece5dd;
    /* WhatsApp-like warm grey */
    --rag-white: #ffffff;
    --rag-incoming: #ffffff;
    --rag-outgoing: #dcf8c6;
    --rag-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    --rag-radius: 16px;
    --rag-bubble-radius: 12px;
}

#rag-chatbot-widget {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Toggle Button with Pulse Animation */
#rag-chatbot-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--rag-primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    color: white;
    font-size: 32px;
}

#rag-chatbot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

#rag-chatbot-widget.active #rag-chatbot-toggle {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* Chat Container with Slide Up */
#rag-chatbot-container {
    display: flex;
    flex-direction: column;
    width: 380px;
    height: 600px;
    max-height: 80vh;
    max-width: 90vw;
    background-color: #f7f7f7;
    border-radius: var(--rag-radius);
    box-shadow: var(--rag-shadow);
    overflow: hidden;
    position: absolute;
    bottom: 0;
    right: 0;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    pointer-events: none;
    visibility: hidden;
}

#rag-chatbot-widget.active #rag-chatbot-container {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

/* Header */
#rag-chatbot-header {
    background: var(--rag-primary);
    background: linear-gradient(135deg, var(--rag-primary) 0%, #1a4f9c 100%);
    /* Subtle gradient */
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

#rag-chatbot-header h4 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: inherit;
}

#rag-chatbot-close {
    cursor: pointer;
    font-size: 18px;
    opacity: 0.8;
    transition: opacity 0.2s;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}

#rag-chatbot-close:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

/* Body & Messages */
#rag-chatbot-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    /* Soft pattern background */
    background-color: var(--rag-bg);
    background-image: radial-gradient(#d1cfcd 1px, transparent 1px);
    background-size: 20px 20px;
    scroll-behavior: smooth;
}

/* Custom Scrollbar */
#rag-chatbot-body::-webkit-scrollbar {
    width: 6px;
}

#rag-chatbot-body::-webkit-scrollbar-track {
    background: transparent;
}

#rag-chatbot-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

#rag-chatbot-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

.rag-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    animation: fadeUp 0.3s ease-out forwards;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rag-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--rag-bubble-radius);
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    word-wrap: break-word;
}

/* Bot Message */
.rag-message-bot {
    align-items: flex-start;
}

.rag-message-bot .rag-bubble {
    background-color: var(--rag-white);
    color: #333;
    border-top-left-radius: 2px;
    border-bottom-left-radius: var(--rag-bubble-radius);
}

/* User Message */
.rag-message-user {
    align-items: flex-end;
}

.rag-message-user .rag-bubble {
    background-color: var(--rag-outgoing);
    color: #111;
    border-top-right-radius: 2px;
    border-bottom-right-radius: var(--rag-bubble-radius);
    background: linear-gradient(135deg, #dcf8c6 0%, #d4f4b9 100%);
}

/* Footer & Input */
#rag-chatbot-footer {
    background-color: #ffffff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    border-top: 1px solid #eee;
    gap: 10px;
}

#rag-chatbot-input {
    flex: 1;
    border: 1px solid #ddd;
    padding: 12px 16px;
    border-radius: 24px;
    outline: none;
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f9f9f9;
}

#rag-chatbot-input:focus {
    border-color: var(--rag-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(38, 111, 224, 0.1);
}

#rag-chatbot-send {
    background: var(--rag-primary);
    border: none;
    color: white;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: transform 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#rag-chatbot-send:hover {
    transform: scale(1.05);
}

#rag-chatbot-send:active {
    transform: scale(0.95);
}

/* Typing Indicator (Dots) */
.rag-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px !important;
    min-width: 50px;
}

.rag-dot {
    width: 8px;
    height: 8px;
    background-color: #999;
    border-radius: 50%;
    animation: ragBounce 1.4s infinite ease-in-out both;
}

.rag-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.rag-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes ragBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Markdown Content Styling */
.rag-bubble strong {
    font-weight: 600;
    color: #222;
}

.rag-bubble a {
    color: var(--rag-primary);
    text-decoration: none;
    font-weight: 500;
}

.rag-bubble a:hover {
    text-decoration: underline;
}

.rag-bubble ul {
    margin: 8px 0 8px 18px;
    padding-left: 0;
}

.rag-bubble li {
    margin-bottom: 4px;
}

.rag-bubble p {
    margin: 0 0 8px 0;
}

.rag-bubble p:last-child {
    margin-bottom: 0;
}