/* ─── RAG Chat Widget ─────────────────────────────────────────────────── */

:root {
    --rcw-primary:      #2563eb;
    --rcw-primary-dark: #1d4ed8;
    --rcw-radius:       14px;
    --rcw-shadow:       0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
    --rcw-w:            370px;
    --rcw-h:            520px;
    --rcw-z:            99999;
    --rcw-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#rcw-root {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--rcw-z);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font-family: var(--rcw-font);
}

/* ─── Toggle button ─────────────────────────────────────────────────── */

#rcw-toggle {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--rcw-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 16px rgba(37,99,235,.45);
    transition: transform .2s ease, background .15s ease;
    flex-shrink: 0;
}

#rcw-toggle:hover  { background: var(--rcw-primary-dark); transform: scale(1.07); }
#rcw-toggle:active { transform: scale(.96); }

/* ─── Chat window ───────────────────────────────────────────────────── */

#rcw-window {
    width: var(--rcw-w);
    height: var(--rcw-h);
    border-radius: var(--rcw-radius);
    background: #fff;
    box-shadow: var(--rcw-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: rcw-slide-up .22s ease;
    border: 1px solid rgba(0,0,0,.08);
}

@keyframes rcw-slide-up {
    from { opacity: 0; transform: translateY(18px) scale(.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

/* ─── Header ────────────────────────────────────────────────────────── */

#rcw-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--rcw-primary);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: .01em;
    flex-shrink: 0;
}

#rcw-clear {
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,.75);
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color .15s, background .15s;
}
#rcw-clear:hover { color: #fff; background: rgba(255,255,255,.15); }

/* ─── Messages area ─────────────────────────────────────────────────── */

#rcw-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: #f8fafc;
}

#rcw-messages::-webkit-scrollbar       { width: 5px; }
#rcw-messages::-webkit-scrollbar-track { background: transparent; }
#rcw-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ─── Message bubbles ───────────────────────────────────────────────── */

.rcw-msg {
    display: flex;
    flex-direction: column;
    max-width: 86%;
    animation: rcw-msg-in .18s ease;
}

@keyframes rcw-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.rcw-msg.rcw-user  { align-self: flex-end; align-items: flex-end; }
.rcw-msg.rcw-bot   { align-self: flex-start; align-items: flex-start; }

.rcw-bubble {
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.rcw-user .rcw-bubble {
    background: var(--rcw-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.rcw-bot .rcw-bubble {
    background: #fff;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    border: 1px solid #e2e8f0;
}

.rcw-bubble.rcw-error {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}

/* Typing cursor blink */
.rcw-cursor::after {
    content: '▍';
    animation: rcw-blink .6s step-end infinite;
    color: var(--rcw-primary);
    margin-left: 1px;
}
@keyframes rcw-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ─── Input row ─────────────────────────────────────────────────────── */

#rcw-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    flex-shrink: 0;
}

#rcw-input {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: var(--rcw-font);
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color .15s;
    color: #1e293b;
}
#rcw-input:focus { border-color: var(--rcw-primary); }
#rcw-input::placeholder { color: #94a3b8; }

#rcw-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--rcw-primary);
    border: none;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}
#rcw-send:hover   { background: var(--rcw-primary-dark); }
#rcw-send:active  { transform: scale(.94); }
#rcw-send:disabled { background: #94a3b8; cursor: not-allowed; }

/* ─── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 440px) {
    :root {
        --rcw-w: calc(100vw - 24px);
        --rcw-h: 70vh;
    }
    #rcw-root { right: 12px; bottom: 12px; }
}
