/* ══════════════════════════════════════════════════════════
   RAG Chat Widget — KV Electronics
   Semantic Search Chatbot with Knowledge Base
   ══════════════════════════════════════════════════════════ */

/* ── Chat Toggle Button ── */
#rag-chat-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--theme-accent, var(--theme-primary, #0056d6));
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px color-mix(in srgb, var(--theme-accent, var(--theme-primary, #0056d6)) 40%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}
#rag-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px color-mix(in srgb, var(--theme-accent, var(--theme-primary, #0056d6)) 50%, transparent);
}
#rag-chat-toggle svg { pointer-events: none; }

/* Notification dot */
#rag-chat-toggle .rag-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ef4444;
    border: 2px solid #fff;
    animation: rag-pulse 2s infinite;
}
@keyframes rag-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Chat Window ── */
#rag-chat-window {
    position: fixed;
    bottom: 90px;
    right: 24px;
    z-index: 10001;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 200px);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
#rag-chat-window.rag-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ── */
.rag-header {
    background: var(--theme-primary, #0056d6);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.rag-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.rag-header-info h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}
.rag-header-info span {
    font-size: 12px;
    opacity: 0.8;
}
.rag-header-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    padding: 4px;
    flex-shrink: 0;
}
.rag-header-close:hover { opacity: 1; }

/* ── Language Toggle Button ── */
.rag-lang-btn {
    margin-left: auto;
    background: rgba(255,255,255,0.2);
    border: 1.5px solid rgba(255,255,255,0.5);
    color: #fff;
    cursor: pointer;
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
    line-height: 1.4;
}
.rag-lang-btn:hover {
    background: rgba(255,255,255,0.35);
    border-color: rgba(255,255,255,0.8);
}
.rag-lang-btn .rag-lang-label {
    display: inline-block;
    min-width: 20px;
    text-align: center;
}

/* ── Messages Area ── */
.rag-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
}
.rag-messages::-webkit-scrollbar { width: 4px; }
.rag-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ── Message Bubbles ── */
.rag-msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: rag-fadeIn 0.3s ease;
}
@keyframes rag-fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.rag-msg-bot {
    align-self: flex-start;
    background: #fff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}
.rag-msg-user {
    align-self: flex-end;
    background: var(--theme-primary, #0056d6);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Source cards inside bot messages */
.rag-source-card {
    display: block;
    margin-top: 8px;
    padding: 10px 12px;
    background: #f1f5f9;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    color: #1e293b;
    transition: background 0.2s;
}
.rag-source-card:hover {
    background: #e2e8f0;
    text-decoration: none;
    color: #1e293b;
}
.rag-source-card .rag-sc-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--theme-primary, #0056d6);
    display: flex;
    align-items: center;
    gap: 6px;
}
.rag-source-card .rag-sc-meta {
    font-size: 11px;
    color: #64748b;
    margin-top: 4px;
}
.rag-source-card .rag-sc-excerpt {
    font-size: 12px;
    color: #475569;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Score badge */
.rag-score {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    margin-left: 4px;
}
.rag-score-high { background: #dcfce7; color: #166534; }
.rag-score-mid  { background: #fef9c3; color: #854d0e; }
.rag-score-low  { background: #fee2e2; color: #991b1b; }

/* Suggested queries */
.rag-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.rag-suggestion-btn {
    background: #eff6ff;
    color: var(--theme-primary, #0056d6);
    border: 1px solid #bfdbfe;
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}
.rag-suggestion-btn:hover {
    background: #dbeafe;
}

/* Typing indicator */
.rag-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.rag-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: rag-typing 1.2s infinite;
}
.rag-typing span:nth-child(2) { animation-delay: 0.2s; }
.rag-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes rag-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Input Area ── */
.rag-input-area {
    padding: 12px 14px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 8px;
    align-items: center;
    background: #fff;
    flex-shrink: 0;
}
.rag-input-area input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.rag-input-area input:focus {
    border-color: var(--theme-accent, #4ecdc4);
}
.rag-input-area input::placeholder {
    color: #9ca3af;
}
.rag-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--theme-accent, #4ecdc4);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.rag-send-btn:hover {
    filter: brightness(0.9);
}
.rag-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Search Mode Indicator ── */
.rag-search-mode {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 11px;
    color: #64748b;
    background: #f1f5f9;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.rag-search-mode svg { flex-shrink: 0; }

/* ── Mobile Responsive ── */
@media (max-width: 767px) {
    #rag-chat-window {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
        transform-origin: center bottom;
    }
    #rag-chat-window.rag-open {
        transform: translateY(0) scale(1) !important;
    }
    #rag-chat-toggle {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
    }
}
