/* Modern floating chat widget CSS - Inspire Capitals Theme */
:root {
    --chat-primary: #d4af37; /* Accent Gold */
    --chat-primary-hover: #e2c158;
    --chat-bg: #00122c; /* Primary Blue */
    --chat-bg-light: #0d2850; /* Primary Blue Light */
    --chat-text: #ffffff;
    --chat-text-dark: #00122c;
    --chat-text-muted: #94a3b8;
    --chat-border: rgba(212, 175, 55, 0.3); /* Transparent gold border */
    --chat-user-msg: linear-gradient(135deg, #d4af37, #e2c158);
    --chat-bot-msg: #0d2850;
    --chat-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
    --chat-font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Chat Toggle Button */
#rag-chat-toggle {
    position: fixed;
    bottom: calc(30px + var(--ic-banner-h, 0px));
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-user-msg);
    color: var(--chat-text-dark);
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(212, 175, 55, 0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
}

#rag-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 28px rgba(212, 175, 55, 0.6);
}

#rag-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    transition: transform 0.3s ease;
}

#rag-chat-toggle.chat-open svg {
    transform: rotate(90deg) scale(0);
    opacity: 0;
    position: absolute;
}

#rag-chat-toggle .close-icon {
    position: absolute;
    transform: rotate(-90deg) scale(0);
    opacity: 0;
}

#rag-chat-toggle.chat-open .close-icon {
    transform: rotate(0) scale(1);
    opacity: 1;
}

/* Chat Invitation Popup */
#rag-chat-invitation {
    position: fixed;
    bottom: calc(110px + var(--ic-banner-h, 0px));
    right: 30px;
    background: var(--chat-bg);
    border: 1px solid var(--chat-border);
    box-shadow: var(--chat-shadow);
    border-radius: 12px;
    padding: 16px 20px;
    z-index: 9997; /* Below window, above other stuff */
    cursor: pointer;
    font-family: var(--chat-font);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    
    /* Animation defaults */
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#rag-chat-invitation.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#rag-chat-invitation .invitation-content h4 {
    color: var(--chat-primary);
    margin: 0 0 4px 0;
    font-size: 1rem;
    font-weight: 600;
}

#rag-chat-invitation .invitation-content p {
    color: var(--chat-text);
    margin: 0;
    font-size: 0.85rem;
    opacity: 0.9;
}

#rag-chat-invitation .invitation-close {
    background: none;
    border: none;
    color: var(--chat-text-muted);
    cursor: pointer;
    padding: 0;
    margin-left: 8px;
    display: flex;
    transition: color 0.2s;
}

#rag-chat-invitation .invitation-close:hover {
    color: var(--chat-text);
}

/* Chat Window */
#rag-chat-window {
    position: fixed;
    bottom: calc(110px + var(--ic-banner-h, 0px));
    right: 30px;
    width: 420px;
    height: 640px;
    max-height: calc(100vh - 130px);

    background: var(--chat-bg);
    border-radius: 20px;
    box-shadow: var(--chat-shadow);
    border: 1px solid var(--chat-border);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--chat-font);
    
    /* Animation defaults */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom right;
}

#rag-chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Chat Header */
.rag-chat-header {
    background: var(--chat-bg-light);
    color: var(--chat-text);
    padding: 20px;
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--chat-border);
}

.rag-chat-header-icon {
    width: 36px;
    height: 36px;
    background: rgba(212, 175, 55, 0.15);
    color: var(--chat-primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rag-chat-header-info {
    display: flex;
    flex-direction: column;
}

.rag-chat-header-status {
    font-size: 0.75rem;
    color: var(--chat-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
}

.rag-chat-header-status::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
}

/* Chat Messages Area */
.rag-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: transparent;
    scroll-behavior: smooth;
    overscroll-behavior: contain; /* Prevents scroll chaining to background */
}

/* Scrollbar */
.rag-chat-messages::-webkit-scrollbar {
    width: 6px;
}
.rag-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.rag-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.3);
    border-radius: 10px;
}

/* Message Bubbles */
.rag-message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    animation: ragFadeInUp 0.3s ease forwards;
}

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

.rag-message.user {
    align-self: flex-end;
}

.rag-message.bot {
    align-self: flex-start;
}

.rag-message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.rag-message.user .rag-message-content {
    background: var(--chat-user-msg);
    color: var(--chat-text-dark);
    font-weight: 500;
    border-bottom-right-radius: 4px;
}

.rag-message.bot .rag-message-content {
    background: var(--chat-bot-msg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255,255,255,0.05);
}

/* Markdown Rendering Styles */
.rag-message-content p {
    margin: 0 0 10px 0;
}
.rag-message-content p:last-child {
    margin-bottom: 0;
}
.rag-message-content strong {
    color: var(--chat-primary);
    font-weight: 600;
}
.rag-message-content ul, 
.rag-message-content ol {
    margin: 0 0 10px 0;
    padding-left: 20px;
}
.rag-message-content li {
    margin-bottom: 4px;
}
.rag-message-content a {
    color: var(--chat-primary);
    text-decoration: underline;
    font-weight: 500;
    transition: opacity 0.2s;
}
.rag-message-content a:hover {
    opacity: 0.8;
}
.rag-message-content code {
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}
.rag-message-content pre {
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
}
.rag-message-content pre code {
    background: transparent;
    padding: 0;
}

/* Loading Indicator */
.rag-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 16px;
    background: var(--chat-bot-msg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255,255,255,0.05);
    align-self: flex-start;
    width: max-content;
}

.rag-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-primary);
    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); }
}

/* Chat Input Area */
.rag-chat-input-area {
    padding: 16px;
    background: var(--chat-bg-light);
    border-top: 1px solid var(--chat-border);
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.rag-chat-textarea {
    flex: 1;
    background: var(--chat-bg);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 12px 16px;
    font-family: var(--chat-font);
    font-size: 0.95rem;
    resize: none;
    max-height: 120px;
    height: 44px;
    box-sizing: border-box;
    outline: none;
    color: var(--chat-text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    
    /* Hide scrollbar */
    overflow-y: auto;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.rag-chat-textarea::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

.rag-chat-textarea:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

.rag-chat-textarea::placeholder {
    color: var(--chat-text-muted);
}

.rag-chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--chat-user-msg);
    color: var(--chat-text-dark);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.rag-chat-send:hover {
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.4);
}

.rag-chat-send:active {
    transform: scale(0.95);
}

.rag-chat-send svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    margin-left: 2px; /* slight visual offset for the send arrow */
}

.rag-chat-send:disabled {
    background: #475569;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
}

/* Header close button — hidden on desktop, shown only on mobile */
.rag-chat-header-close {
    display: none;
    background: none;
    border: none;
    color: var(--chat-text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    flex-shrink: 0;
}
.rag-chat-header-close:hover {
    color: var(--chat-text);
    background: rgba(255,255,255,0.08);
}


/* ── Tablet (481–768px): comfortable floating size ── */

@media (min-width: 481px) and (max-width: 768px) {
    #rag-chat-window {
        width: 380px;
        height: 560px;
        right: 20px;
        bottom: calc(100px + var(--ic-banner-h, 0px));
    }

    #rag-chat-invitation {
        right: 20px;
        bottom: calc(100px + var(--ic-banner-h, 0px));
    }
}

/* ── Mobile (≤480px): true full-screen chat ── */
@media (max-width: 480px) {
    /* Hide the floating toggle when full-screen chat is open — prevents it
       overlapping the send button and input area */
    #rag-chat-toggle.chat-open {
        display: none;
    }

    /* Show the in-header close button on mobile */
    .rag-chat-header-close {
        display: flex;
    }

    /* Full-screen chat window */
    #rag-chat-window {
        position: fixed;
        inset: 0;                          /* top/right/bottom/left all 0 */
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        right: 0;
        bottom: 0;
        border: none;

        /* Safe area support (notch phones) */
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Larger header on mobile */
    .rag-chat-header {
        padding: 16px 20px;
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }

    /* More breathing room for messages */
    .rag-chat-messages {
        padding: 16px;
        gap: 12px;
    }

    /* Slightly larger font for readability */
    .rag-message-content {
        font-size: 0.97rem;
        line-height: 1.6;
    }

    /* Input area sits above home bar */
    .rag-chat-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    /* Invitation popup stays small & positioned above toggle */
    #rag-chat-invitation {
        right: 16px;
        bottom: calc(82px + var(--ic-banner-h, 0px));
        width: calc(100vw - 32px);
        box-sizing: border-box;
    }
}

