/* ============================================================
   RAGAI Chatbot — Frontend Widget Styles
   All colours/sizes driven by CSS custom properties injected
   via wp_localize_script → chatbot.js → applyAppearance()
   ============================================================ */

:root {
    --ragai-primary:     #2563eb;
    --ragai-secondary:   #1e293b;
    --ragai-bg:          #ffffff;
    --ragai-text:        #1e293b;
    --ragai-user-bubble: #2563eb;
    --ragai-bot-bubble:  #f1f5f9;
    --ragai-font-family: inherit;
    --ragai-font-size:   14px;
    --ragai-radius:      12px;
    --ragai-width:       380px;
    --ragai-height:      520px;
}

/* ── Launcher button ─────────────────────────────────────── */
#ragai-launcher {
    position: fixed;
    z-index: 99998;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ragai-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s, box-shadow .2s;
    font-size: 22px;
    line-height: 1;
}
#ragai-launcher:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,.3); }

/* Position variants */
#ragai-launcher.pos-bottom-right,
.ragai-chat-window.pos-bottom-right { bottom: 24px; right: 24px; }
#ragai-launcher.pos-bottom-left,
.ragai-chat-window.pos-bottom-left  { bottom: 24px; left: 24px; }
#ragai-launcher.pos-top-right,
.ragai-chat-window.pos-top-right    { top: 24px; right: 24px; }
#ragai-launcher.pos-top-left,
.ragai-chat-window.pos-top-left     { top: 24px; left: 24px; }

/* ── Chat window ──────────────────────────────────────────── */
.ragai-chat-window {
    position: fixed;
    z-index: 99999;
    width: var(--ragai-width);
    height: var(--ragai-height);
    background: var(--ragai-bg);
    color: var(--ragai-text);
    font-family: var(--ragai-font-family);
    font-size: var(--ragai-font-size);
    border-radius: var(--ragai-radius);
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: opacity .25s, transform .25s;
}
.ragai-chat-window.ragai-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
}
.ragai-chat-window.ragai-preview-mode {
    position: relative;
    bottom: auto; right: auto; top: auto; left: auto;
    width: 100%;
    height: 420px;
    box-shadow: 0 2px 12px rgba(0,0,0,.12);
}

/* ── Header ──────────────────────────────────────────────── */
.ragai-chat-header {
    background: var(--ragai-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.ragai-chat-title { font-weight: 600; font-size: 1em; }
.ragai-btn-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    opacity: .8;
    transition: opacity .15s;
}
.ragai-btn-close:hover { opacity: 1; }

/* ── Messages area ───────────────────────────────────────── */
.ragai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
.ragai-chat-messages::-webkit-scrollbar { width: 4px; }
.ragai-chat-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Message rows ────────────────────────────────────────── */
.ragai-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}
.ragai-msg--user { align-self: flex-end; align-items: flex-end; }
.ragai-msg--bot  { align-self: flex-start; align-items: flex-start; }

/* ── Bubbles ─────────────────────────────────────────────── */
.ragai-bubble {
    padding: 10px 14px;
    border-radius: var(--ragai-radius);
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}
.ragai-msg--user .ragai-bubble {
    background: var(--ragai-user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ragai-msg--bot .ragai-bubble {
    background: var(--ragai-bot-bubble);
    color: var(--ragai-text);
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.ragai-typing .ragai-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
}
.ragai-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: ragai-bounce .9s infinite ease-in-out;
}
.ragai-dot:nth-child(2) { animation-delay: .15s; }
.ragai-dot:nth-child(3) { animation-delay: .30s; }
@keyframes ragai-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%         { transform: translateY(-6px); }
}

/* ── Sources ─────────────────────────────────────────────── */
.ragai-sources {
    font-size: .78em;
    color: #64748b;
    margin-top: 4px;
    padding-left: 4px;
}
.ragai-sources summary { cursor: pointer; user-select: none; }
.ragai-sources ul { margin: 4px 0 0 16px; padding: 0; list-style: disc; }
.ragai-cache-badge {
    font-size: .72em;
    background: #e0f2fe;
    color: #0369a1;
    border-radius: 4px;
    padding: 1px 5px;
    margin-top: 3px;
    display: inline-block;
}

/* ── Limit bar ───────────────────────────────────────────── */
.ragai-limit-bar {
    font-size: .78em;
    text-align: center;
    padding: 5px 12px;
    background: #fef9c3;
    color: #92400e;
    flex-shrink: 0;
}

/* ── Input area ──────────────────────────────────────────── */
.ragai-chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e2e8f0;
    background: var(--ragai-bg);
    flex-shrink: 0;
}
.ragai-input {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: calc(var(--ragai-radius) * 2);
    font-size: var(--ragai-font-size);
    font-family: var(--ragai-font-family);
    color: var(--ragai-text);
    background: var(--ragai-bg);
    outline: none;
    transition: border-color .15s;
}
.ragai-input:focus { border-color: var(--ragai-primary); }
.ragai-input:disabled { opacity: .5; cursor: not-allowed; }

.ragai-btn-send {
    background: var(--ragai-primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}
.ragai-btn-send:hover  { background: var(--ragai-secondary); }
.ragai-btn-send:active { transform: scale(.95); }
.ragai-btn-send:disabled { opacity: .4; cursor: not-allowed; }

/* ── Powered by ──────────────────────────────────────────── */
.ragai-powered-by {
    text-align: center;
    font-size: .7em;
    color: #94a3b8;
    padding: 4px;
    flex-shrink: 0;
}

/* ── Header actions (expand + close) ────────────────────── */
.ragai-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.ragai-btn-expand {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    line-height: 1;
    padding: 2px;
    opacity: .8;
    transition: opacity .15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ragai-btn-expand:hover { opacity: 1; }

/* ── Debug toolbar ───────────────────────────────────────── */
.ragai-debug-toolbar {
    background: #fef3c7;
    border-top: 1px solid #fde68a;
    padding: 5px 12px;
    flex-shrink: 0;
    font-size: .78em;
}
.ragai-debug-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: #78350f;
    font-weight: 500;
    user-select: none;
}
.ragai-debug-label input[type="checkbox"] {
    cursor: pointer;
    width: 14px;
    height: 14px;
}

/* ── Debug panel (inside bot message) ───────────────────── */
.ragai-debug-panel {
    margin-top: 8px;
    font-size: .75em;
    background: #1e1e2e;
    color: #cdd6f4;
    border-radius: 6px;
    overflow: hidden;
    max-width: 100%;
}
.ragai-debug-panel > summary {
    padding: 6px 10px;
    cursor: pointer;
    background: #313244;
    color: #cba6f7;
    font-weight: 600;
    user-select: none;
    list-style: none;
}
.ragai-debug-panel > summary::-webkit-details-marker { display: none; }
.ragai-debug-panel > summary::before { content: '▶ '; font-size: .8em; }
.ragai-debug-panel[open] > summary::before { content: '▼ '; }

.ragai-debug-chunk {
    padding: 8px 10px;
    border-top: 1px solid #45475a;
}
.ragai-debug-chunk:first-of-type { border-top: none; }
.ragai-debug-chunk-header {
    margin-bottom: 4px;
    color: #89b4fa;
}
.ragai-debug-score { color: #a6e3a1; }
.ragai-debug-len   { color: #f38ba8; }
.ragai-debug-embed {
    margin-bottom: 4px;
}
.ragai-debug-label-sm { color: #fab387; font-weight: 600; }
.ragai-debug-embed code {
    background: #313244;
    padding: 2px 5px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 1em;
    color: #a6e3a1;
}
.ragai-debug-preview {
    color: #bac2de;
    font-style: italic;
    line-height: 1.4;
    word-break: break-word;
    white-space: pre-wrap;
    margin-top: 4px;
}
.ragai-debug-text-expand {
    display: inline;
}
.ragai-debug-text-expand > summary {
    display: inline;
    cursor: pointer;
    list-style: none;
}
.ragai-debug-text-expand > summary::-webkit-details-marker { display: none; }
.ragai-debug-expand-hint {
    color: #89b4fa;
    font-style: normal;
    font-size: .9em;
}

/* ── Modal overlay ───────────────────────────────────────── */
.ragai-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(2px);
    transition: opacity .25s;
}
.ragai-modal-overlay.ragai-modal-hidden {
    opacity: 0;
    pointer-events: none;
}
.ragai-modal-window {
    background: var(--ragai-bg);
    color: var(--ragai-text);
    font-family: var(--ragai-font-family);
    font-size: var(--ragai-font-size);
    border-radius: var(--ragai-radius);
    box-shadow: 0 16px 48px rgba(0,0,0,.35);
    width: min(860px, 95vw);
    height: min(680px, 90vh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ragai-modal-header {
    flex-shrink: 0;
}
.ragai-modal-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
.ragai-modal-messages::-webkit-scrollbar { width: 4px; }
.ragai-modal-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.ragai-modal-input-area {
    flex-shrink: 0;
}

/* ── Dark mode ───────────────────────────────────────────── */
.ragai-dark {
    --ragai-bg:         #0f172a;
    --ragai-text:       #e2e8f0;
    --ragai-bot-bubble: #1e293b;
}
.ragai-dark .ragai-chat-input-area { border-top-color: #334155; }
.ragai-dark .ragai-input { border-color: #334155; }
.ragai-dark .ragai-limit-bar { background: #1e293b; color: #fbbf24; }
.ragai-dark .ragai-chat-messages::-webkit-scrollbar-thumb { background: #334155; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
    .ragai-chat-window {
        width: 100% !important;
        height: 100% !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        border-radius: 0 !important;
    }
    #ragai-launcher { bottom: 16px !important; right: 16px !important; }
}
