@font-face { font-family: 'Lexend'; src: url('fonts/Lexend-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Lexend'; src: url('fonts/Lexend-Medium.ttf') format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Lexend'; src: url('fonts/Lexend-SemiBold.ttf') format('truetype'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Lexend'; src: url('fonts/Lexend-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
    --primary: #508cfc;
    --primary-dark: #3a6fd4;
    --primary-light: #6fa3ff;
    --success: #3d8b6e;
    --warning: #c4883a;
    --error: #c44a3f;
    --bg: #f5f0e8;
    --bg-chat: #faf8f4;
    --bg-surface: #ffffff;
    --bg-input: #ffffff;
    --border: #e5ddd0;
    --border-light: #ece6da;
    --text-primary: #2d2a26;
    --text-secondary: #6b6560;
    --text-muted: #9b9490;
    --text-faint: #b8b0a8;
    --accent-bg: rgba(80, 140, 252, 0.08);
    --accent-border: rgba(80, 140, 252, 0.25);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Lexend', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    height: 100vh;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Top bar */
.rag-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.rag-topbar-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.rag-topbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rag-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
}

.rag-dot-green { background: #3d8b6e; box-shadow: 0 0 8px rgba(61, 139, 110, 0.4); }
.rag-dot-amber { background: #c4883a; box-shadow: 0 0 8px rgba(196, 136, 58, 0.4); }
.rag-dot-red { background: #c44a3f; box-shadow: 0 0 8px rgba(196, 74, 63, 0.4); }

.rag-status-text { font-weight: 600; color: var(--text-secondary); font-size: 0.82rem; }
.rag-status-detail { color: var(--text-muted); font-size: 0.8rem; margin-left: auto; }

/* Chat container */
.rag-chat {
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.rag-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Welcome screen */
.rag-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px 20px;
    flex: 1;
}

.rag-welcome-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.rag-welcome-title { color: var(--text-primary); font-size: 1.4rem; font-weight: 700; margin: 0; }

.rag-new-badge {
    background: linear-gradient(135deg, #508cfc, #3a6fd4);
    color: #fff; font-size: 0.7rem; font-weight: 900; letter-spacing: 1px;
    padding: 5px 8px; border-radius: 4px; transform: rotate(-8deg);
    box-shadow: 0 0 14px rgba(80, 140, 252, 0.3);
    animation: badge-pulse 2s ease-in-out infinite;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2); line-height: 1;
}

@keyframes badge-pulse { 0%, 100% { transform: rotate(-8deg) scale(1); } 50% { transform: rotate(-8deg) scale(1.1); } }

.rag-edition-badge {
    background: linear-gradient(135deg, var(--primary), #3a6fd4);
    color: #fff; font-size: 0.7rem; font-weight: 800; letter-spacing: 1.5px;
    padding: 5px 12px; border-radius: 4px;
    box-shadow: 0 0 14px rgba(80, 140, 252, 0.2);
    text-shadow: 0 1px 2px rgba(0,0,0,0.2); line-height: 1;
}

.rag-welcome-desc { color: var(--text-secondary); font-size: 0.85rem; max-width: 580px; line-height: 1.6; margin-bottom: 20px; }

.rag-chips-section { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 660px; }
.rag-chips-label { color: var(--text-muted); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.rag-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 640px; }

.rag-chip {
    background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-secondary);
    padding: 8px 16px; border-radius: 20px; font-size: 0.82rem; font-family: inherit;
    cursor: pointer; transition: all 0.2s;
}
.rag-chip:hover { background: var(--bg); border-color: var(--primary); color: var(--text-primary); }
.rag-chip--new { border-color: var(--accent-border); background: var(--accent-bg); color: var(--primary-dark); }
.rag-chip--new:hover { background: rgba(80, 140, 252, 0.14); border-color: var(--primary); color: var(--primary-dark); }

/* Messages */
.rag-msg { display: flex; max-width: 85%; }
.rag-msg-user { align-self: flex-end; justify-content: flex-end; }
.rag-msg-assistant { align-self: flex-start; justify-content: flex-start; }

.rag-msg-bubble {
    padding: 12px 16px; border-radius: 14px; font-size: 0.9rem;
    line-height: 1.6; word-break: break-word;
}

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

.rag-bubble-assistant {
    background: var(--bg-surface); color: var(--text-primary); border-bottom-left-radius: 4px;
    padding: 16px 20px; user-select: text; cursor: text;
    border: 1px solid var(--border-light);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.rag-msg-text p { margin: 0 0 8px 0; line-height: 1.65; }
.rag-msg-text p:last-child { margin-bottom: 0; }

.rag-msg-text .rag-heading {
    color: var(--text-primary); font-weight: 600; margin: 16px 0 8px 0;
    padding-bottom: 6px; border-bottom: 1px solid var(--border-light);
}
.rag-msg-text h3.rag-heading { font-size: 1rem; }
.rag-msg-text h4.rag-heading { font-size: 0.92rem; }

.rag-msg-text .rag-list { margin: 6px 0 10px 0; padding-left: 22px; }
.rag-msg-text .rag-list li { margin-bottom: 4px; line-height: 1.6; }
.rag-msg-text ul.rag-list { list-style: disc; }
.rag-msg-text ul.rag-list li::marker { color: var(--primary); }
.rag-msg-text ol.rag-list li::marker { color: var(--primary); font-weight: 600; }
.rag-msg-text .rag-para-break { height: 8px; }

.rag-inline-code {
    background: rgba(80, 140, 252, 0.1); color: var(--primary-dark);
    padding: 1px 5px; border-radius: 4px; font-family: 'Courier New', monospace; font-size: 0.85em;
}

.rag-source-ref {
    display: inline-block; background: var(--accent-bg); color: var(--primary-dark);
    padding: 1px 6px; border-radius: 4px; font-size: 0.8em; font-weight: 600;
}

/* Copy button */
.rag-copy-btn {
    display: inline-block; padding: 4px 12px; background: transparent;
    border: 1px solid var(--border); color: var(--text-muted); border-radius: 6px;
    font-size: 0.78rem; font-family: inherit; cursor: pointer; transition: all 0.2s;
}
.rag-copy-btn:hover { border-color: var(--text-secondary); color: var(--text-secondary); }
.rag-copy-btn.rag-copied { border-color: var(--success); color: var(--success); }

/* Typing indicator */
.rag-typing { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.rag-typing-status { color: var(--text-secondary); font-size: 0.85rem; font-style: italic; animation: rag-status-in 0.4s ease-out; }
.rag-status-fade { animation: rag-status-in 0.4s ease-out; }
@keyframes rag-status-in { 0% { opacity: 0; transform: translateY(4px); } 100% { opacity: 1; transform: translateY(0); } }
.rag-typing-elapsed { color: var(--text-faint); font-size: 0.75rem; margin-left: auto; }

/* Sources */
.rag-sources-toggle {
    display: flex; align-items: center; gap: 6px; margin-top: 10px;
    cursor: pointer; color: var(--text-muted); font-size: 0.82rem; user-select: none;
}
.rag-sources-toggle:hover { color: var(--text-secondary); }
.rag-sources-arrow { font-size: 0.7rem; transition: transform 0.2s; display: inline-block; }
.rag-sources-arrow.rag-arrow-open { transform: rotate(90deg); }
.rag-sources-label { font-weight: 500; }

.rag-sources-cards { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.rag-source-card { background: var(--bg-chat); border-left: 3px solid var(--primary-light); padding: 10px 14px; border-radius: 6px; }
.rag-source-title { color: var(--text-primary); font-size: 0.82rem; font-weight: 600; margin-bottom: 4px; }
.rag-source-meta { color: var(--text-muted); font-size: 0.75rem; }
.rag-source-clickable { cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.rag-source-clickable:hover { background: var(--accent-bg); border-left-color: var(--primary); }
.rag-related-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.rag-related-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; display: block; margin-bottom: 8px; }
.rag-related-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.rag-related-pill {
    display: inline-block; padding: 6px 14px; font-size: 0.82rem;
    background: var(--accent-bg); color: var(--primary); border: 1px solid var(--accent-border);
    border-radius: 20px; cursor: pointer; text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.rag-related-pill:hover { background: var(--bg); border-color: var(--primary); color: var(--primary-dark); }
.rag-source-preview {
    color: var(--text-muted); font-size: 0.75rem; font-style: italic; margin-top: 4px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.rag-ai-disclaimer { color: var(--text-faint); font-size: 0.7rem; font-style: italic; margin-top: 10px; opacity: 0.75; }
.rag-meta { color: var(--text-muted); font-size: 0.75rem; margin-top: 10px; }

/* Diagrams */
.rag-diagrams { margin-top: 14px; border-top: 1px solid var(--border-light); padding-top: 10px; }
.rag-diagrams-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.rag-diagram-item { margin-bottom: 10px; }
.rag-diagram-img { display: block; max-width: 100%; width: 420px; border: 1px solid var(--border); border-radius: 6px; cursor: zoom-in; transition: width 0.2s ease; }
.rag-diagram-img.rag-diagram-expanded { width: 100%; cursor: zoom-out; }
.rag-diagram-caption { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }

/* Disclaimer bar */
.rag-disclaimer {
    padding: 8px 20px; background: var(--bg-surface); color: var(--text-muted);
    font-size: 0.75rem; text-align: center; border-top: 1px solid var(--border);
}

/* Input area */
.rag-input-area { display: flex; gap: 10px; padding: 14px 16px; background: var(--bg-surface); border-top: 1px solid var(--border); }

.rag-input-wrap { flex: 1; position: relative; display: flex; align-items: center; }
.rag-input-wrap .rag-input { width: 100%; padding-right: 70px; }

.rag-input {
    padding: 10px 14px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text-primary); font-family: inherit; font-size: 0.9rem;
    outline: none; transition: border-color 0.2s;
}
.rag-input:focus { border-color: var(--primary); }
.rag-input::placeholder { color: var(--text-faint); }
.rag-input:disabled { opacity: 0.5; cursor: not-allowed; }

.rag-send-btn {
    padding: 10px 20px; background: var(--primary); color: #fff; border: none;
    border-radius: 8px; font-family: inherit; font-size: 0.9rem; font-weight: 600;
    cursor: pointer; transition: background 0.2s;
}
.rag-send-btn:hover:not(:disabled) { background: var(--primary-dark); }
.rag-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.rag-clear-btn {
    padding: 10px 16px; background: var(--bg); color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
    font-weight: 600; cursor: pointer; transition: background 0.2s, color 0.2s; white-space: nowrap;
}
.rag-clear-btn:hover { background: var(--border-light); color: var(--text-primary); }

.rag-char-count { position: absolute; right: 12px; font-size: 0.68rem; color: var(--text-faint); pointer-events: none; transition: color 0.2s; }
.rag-char-count.rag-char-warn { color: #c4883a; }
.rag-char-count.rag-char-full { color: #c44a3f; }

/* Shimmer loading */
.rag-shimmer-wrap { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.rag-shimmer-line {
    height: 12px;
    background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
    background-size: 200% 100%; border-radius: 4px; animation: rag-shimmer 1.5s ease-in-out infinite;
}
@keyframes rag-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Stop / retry */
.rag-stop-btn {
    display: inline-block; margin-top: 10px; padding: 5px 14px; background: transparent;
    border: 1px solid var(--border); color: var(--text-muted); border-radius: 6px;
    font-size: 0.78rem; font-family: inherit; cursor: pointer; transition: all 0.2s;
}
.rag-stop-btn:hover { border-color: var(--error); color: var(--error); }

.rag-bubble-error { border-left: 3px solid var(--error); }
.rag-retry-btn {
    display: inline-block; margin-top: 8px; padding: 6px 16px; background: var(--primary);
    color: #fff; border: none; border-radius: 6px; font-size: 0.82rem; font-family: inherit;
    cursor: pointer; transition: background 0.2s;
}
.rag-retry-btn:hover { background: var(--primary-dark); }

.rag-actions-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

/* Fade-in */
.rag-fade-in { animation: rag-fadein 0.3s ease-out; }
@keyframes rag-fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Scrollbar */
.rag-messages::-webkit-scrollbar { width: 6px; }
.rag-messages::-webkit-scrollbar-track { background: transparent; }
.rag-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.rag-messages::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
