/* ============================================================
   GitHub RAG AI Assistant — Premium UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
    --bg:          #060810;
    --bg-2:        #0d111f;
    --bg-3:        #131929;
    --surface:     rgba(255,255,255,0.04);
    --surface-2:   rgba(255,255,255,0.07);
    --border:      rgba(255,255,255,0.08);
    --border-2:    rgba(255,255,255,0.14);

    --accent:      #4f8ef7;
    --accent-2:    #7c6df8;
    --accent-glow: rgba(79,142,247,0.35);
    --green:       #22d3a0;
    --amber:       #f59e0b;
    --red:         #f87171;

    --text:        #f0f4ff;
    --text-2:      #8b96b0;
    --text-3:      #566079;

    --font:        'Inter', system-ui, sans-serif;
    --mono:        'JetBrains Mono', monospace;

    --radius-sm:   6px;
    --radius:      12px;
    --radius-lg:   18px;
    --radius-xl:   24px;

    --shadow-glow: 0 0 40px rgba(79,142,247,0.15);
    --shadow-card: 0 4px 24px rgba(0,0,0,0.4);

    --sidebar-w:   300px;
    --header-h:    60px;

    --transition:  0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ──────────────────────────────────────────────────── */
html { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Animated background orbs */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    filter: blur(80px);
    animation: drift 20s ease-in-out infinite alternate;
}
body::before {
    width: 600px; height: 600px;
    background: radial-gradient(circle, rgba(79,142,247,0.12), transparent 70%);
    top: -200px; right: -100px;
}
body::after {
    width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(124,109,248,0.1), transparent 70%);
    bottom: -150px; left: -100px;
    animation-delay: -10s;
}

@keyframes drift {
    0%   { transform: translate(0,0) scale(1); }
    100% { transform: translate(40px, 30px) scale(1.1); }
}

/* ── Layout ─────────────────────────────────────────────────── */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    gap: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 10;
}

.sidebar::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(180deg,
        rgba(79,142,247,0.04) 0%,
        transparent 40%,
        rgba(124,109,248,0.03) 100%);
}

/* Brand */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 8px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
}

.brand-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 0 16px var(--accent-glow);
}

.brand-icon svg {
    width: 18px;
    height: 18px;
    color: white;
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-size: 0.95rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a5c4fb, #c4baff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

.brand-sub {
    font-size: 0.68rem;
    color: var(--text-3);
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Section labels */
.sidebar-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-3);
    padding: 0 8px;
}

/* Profile loader */
.profile-loader {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.profile-loader p {
    font-size: 0.8rem;
    color: var(--text-2);
    line-height: 1.5;
    padding: 0 8px;
}

/* Input */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    outline: none;
}

input[type="text"]::placeholder { color: var(--text-3); }

input[type="text"]:focus {
    border-color: var(--accent);
    background: var(--surface-2);
    box-shadow: 0 0 0 3px rgba(79,142,247,0.18), 0 0 20px rgba(79,142,247,0.08);
}

/* Buttons */
.btn-primary {
    padding: 10px 16px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    border: none;
    font-weight: 600;
    font-size: 0.875rem;
    font-family: var(--font);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 2px 16px var(--accent-glow);
    position: relative;
    overflow: hidden;
}

.btn-primary::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
    opacity: 0;
    transition: opacity var(--transition);
}

.btn-primary:hover:not(:disabled)::after { opacity: 1; }

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 24px var(--accent-glow);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

/* Status message */
.status-message {
    font-size: 0.8rem;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    display: none;
    line-height: 1.4;
    animation: slideIn 0.25s ease;
}

.status-message:not(:empty) { display: block; }

.status-message.success {
    background: rgba(34,211,160,0.1);
    border: 1px solid rgba(34,211,160,0.25);
    color: var(--green);
}

.status-message.error {
    background: rgba(248,113,113,0.1);
    border: 1px solid rgba(248,113,113,0.25);
    color: var(--red);
}

.status-message.loading {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-2);
}

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

/* Context card */
.context-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: slideIn 0.3s ease;
}

.context-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
}

.context-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(79,142,247,0.06), transparent);
    pointer-events: none;
}

.context-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.context-avatar-wrap img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: block;
    border: 2px solid var(--border-2);
}

.avatar-online {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    border: 2px solid var(--bg-2);
    box-shadow: 0 0 8px rgba(34,211,160,0.6);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 6px rgba(34,211,160,0.6); }
    50%       { box-shadow: 0 0 12px rgba(34,211,160,1); }
}

.context-details { flex: 1; min-width: 0; }

.context-details h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.context-details span {
    font-size: 0.72rem;
    color: var(--text-3);
}

.context-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    text-align: center;
}

.stat-pill .val {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
}

.stat-pill .lbl {
    display: block;
    font-size: 0.65rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 3px;
    font-weight: 500;
}

/* ── Chat Area ──────────────────────────────────────────────── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
    position: relative;
}

/* Header */
.chat-header {
    height: var(--header-h);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: rgba(6,8,16,0.8);
    backdrop-filter: blur(20px);
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.header-model-badge {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-3);
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-model-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent-glow);
    display: inline-block;
}

/* Status badge */
.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 20px;
    transition: all var(--transition);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    transition: background var(--transition);
}

.status-badge.waiting {
    background: rgba(245,158,11,0.12);
    border: 1px solid rgba(245,158,11,0.22);
    color: var(--amber);
}
.status-badge.waiting .status-dot {
    background: var(--amber);
}

.status-badge.ready {
    background: rgba(34,211,160,0.12);
    border: 1px solid rgba(34,211,160,0.25);
    color: var(--green);
}
.status-badge.ready .status-dot {
    background: var(--green);
    box-shadow: 0 0 6px rgba(34,211,160,0.6);
    animation: pulse 2s infinite;
}

.status-badge.thinking {
    background: rgba(79,142,247,0.12);
    border: 1px solid rgba(79,142,247,0.25);
    color: var(--accent);
}
.status-badge.thinking .status-dot {
    background: var(--accent);
    animation: pulse 1s infinite;
}

/* ── Chat History ────────────────────────────────────────────── */
.chat-history {
    flex: 1;
    padding: 32px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
}

/* Scrollbar */
.chat-history::-webkit-scrollbar { width: 4px; }
.chat-history::-webkit-scrollbar-track { background: transparent; }
.chat-history::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: 2px;
}

/* Welcome screen */
.welcome-screen {
    margin: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 480px;
    animation: fadeUp 0.6s ease both;
}

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

.welcome-orb {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 40px var(--accent-glow);
    animation: float 4s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50%       { transform: translateY(-8px); }
}

.welcome-orb svg { width: 32px; height: 32px; color: white; }

.welcome-screen h1 {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--text) 0%, #8ba4d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

.welcome-screen p {
    font-size: 0.9rem;
    color: var(--text-2);
    line-height: 1.6;
}

.welcome-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 8px;
}

.chip {
    font-size: 0.78rem;
    padding: 6px 14px;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-2);
    cursor: pointer;
    transition: all var(--transition);
    font-weight: 500;
}

.chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(79,142,247,0.08);
    transform: translateY(-1px);
}

/* ── Messages ───────────────────────────────────────────────── */
.message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    animation: msgIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    max-width: 820px;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Bot */
.message.bot {
    align-self: flex-start;
    width: 100%;
}

.message-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2px;
    box-shadow: 0 0 12px var(--accent-glow);
}

.message-avatar svg { width: 14px; height: 14px; color: white; }

.message.bot .message-bubble {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    max-width: 100%;
    position: relative;
    overflow: hidden;
}

.message.bot .message-bubble::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(79,142,247,0.4), transparent);
}

/* User */
.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.user .message-avatar {
    background: var(--bg-3);
    border: 1px solid var(--border-2);
    box-shadow: none;
}

.message.user .message-avatar svg { color: var(--text-2); }

.message.user .message-bubble {
    background: linear-gradient(135deg, rgba(79,142,247,0.18), rgba(124,109,248,0.12));
    border: 1px solid rgba(79,142,247,0.25);
    border-bottom-right-radius: 4px;
    max-width: 70%;
}

/* Bubble base */
.message-bubble {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--text);
    word-wrap: break-word;
}

/* Content formatting */
.message-bubble .content p { margin-bottom: 0.6em; }
.message-bubble .content p:last-child { margin-bottom: 0; }

.message-bubble .content strong { font-weight: 600; color: var(--text); }

.message-bubble .content code {
    font-family: var(--mono);
    font-size: 0.82em;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255,255,255,0.07);
    border: 1px solid var(--border);
    color: #93c5fd;
}

.message-bubble .content pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    overflow-x: auto;
    margin: 10px 0;
}

.message-bubble .content pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.85em;
    color: #cbd5e1;
}

.message-bubble .content ul, .message-bubble .content ol {
    padding-left: 20px;
    margin: 6px 0;
}

.message-bubble .content li { margin-bottom: 4px; }

/* Sources */
.sources {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.sources-label {
    font-size: 0.72rem;
    color: var(--text-3);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-right: 4px;
}

.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(79,142,247,0.08);
    border: 1px solid rgba(79,142,247,0.2);
    font-size: 0.75rem;
    transition: all var(--transition);
}

.source-chip:hover {
    background: rgba(79,142,247,0.18);
    border-color: var(--accent);
}

.source-chip a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.source-chip svg {
    width: 11px;
    height: 11px;
    color: var(--text-3);
    flex-shrink: 0;
}

/* ── Typing Indicator ────────────────────────────────────────── */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 6px 2px;
    align-items: center;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    animation: typingBounce 1.4s ease-in-out infinite both;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.32s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%            { transform: translateY(-6px); opacity: 1; background: var(--accent); }
}

/* ── Chat Input ─────────────────────────────────────────────── */
.chat-input-wrapper {
    padding: 16px 24px 20px;
    background: linear-gradient(to top, var(--bg) 60%, transparent);
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

#chat-input-form {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 8px 8px 8px 20px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

#chat-input-form:focus-within {
    border-color: rgba(79,142,247,0.5);
    box-shadow: 0 0 0 3px rgba(79,142,247,0.12), 0 0 30px rgba(79,142,247,0.06);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 0.95rem;
    color: var(--text);
    font-family: var(--font);
    box-shadow: none;
    padding: 6px 0;
    min-width: 0;
}

#chat-input::placeholder { color: var(--text-3); }
#chat-input:disabled { opacity: 0.5; cursor: not-allowed; }

#send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
    box-shadow: 0 2px 12px var(--accent-glow);
    font-family: var(--font);
}

#send-btn svg { width: 16px; height: 16px; color: white; }

#send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 4px 20px var(--accent-glow);
}

#send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    box-shadow: none;
}

.input-hint {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-3);
    margin-top: 10px;
}

/* ── Utility ────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Loader Spinner ─────────────────────────────────────────── */
.loader-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.25);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Divider ────────────────────────────────────────────────── */
hr.sidebar-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 4px 0;
}

/* ── Responsive tweaks ──────────────────────────────────────── */
@media (max-width: 640px) {
    .sidebar { width: 260px; }
    .chat-header { padding: 0 16px; }
    .chat-history { padding: 20px 16px; }
    .chat-input-wrapper { padding: 12px 16px 16px; }
}