/* ─── CSS Variables ─────────────────────────────── */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;
    --agent-claude: #cc785c;
    --agent-kimi: #8b5cf6;
    --agent-deepseek: #06b6d4;
    --agent-gemini: #10b981;
    --agent-perplexity: #f59e0b;
    --agent-llama: #6b7280;
    --radius: 12px;
    --radius-sm: 6px;
    --shadow: 0 4px 12px rgba(0,0,0,0.3);
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #eaeef2;
    --bg-hover: #d0d7de;
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-muted: #8c959f;
    --border-color: #d0d7de;
    --accent: #0969da;
    --accent-hover: #0550ae;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* ─── Reset & Base ────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

#app {
    display: flex;
    height: 100vh;
}

/* ─── Sidebar ──────────────────────────────────────── */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.logo-icon { font-size: 24px; }
.logo-text { font-size: 18px; font-weight: 700; }

.btn-new-chat {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-new-chat:hover { background: var(--accent-hover); }

.sidebar-section {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.sidebar-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.history-list { display: flex; flex-direction: column; gap: 4px; }

.history-item {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    transition: background 0.2s;
}

.history-item:hover { background: var(--bg-hover); }
.history-item.active { background: var(--bg-tertiary); color: var(--text-primary); }

.history-icon { font-size: 14px; }
.history-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
}

.stats { display: flex; justify-content: space-between; }

/* ─── Main Content ────────────────────────────────── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ─── Header ──────────────────────────────────────── */
.header {
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
}

.agent-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.agent-selector label { font-size: 13px; color: var(--text-secondary); }

.agent-selector select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

.agent-selector select:focus { border-color: var(--accent); }

.header-actions { display: flex; gap: 8px; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── Chat Container ─────────────────────────────── */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

.messages {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ─── Welcome Message ─────────────────────────────── */
.welcome-message {
    text-align: center;
    padding: 60px 20px;
}

.welcome-message h1 {
    font-size: 42px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--accent), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-message p {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.quick-btn {
    padding: 10px 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.quick-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}

/* ─── Message Bubbles ─────────────────────────────── */
.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.message-author {
    font-size: 14px;
    font-weight: 600;
}

.message-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
}

.message-body {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    font-size: 14px;
    line-height: 1.6;
}

.message-body pre {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

.message-body code {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
}

.message-body p { margin-bottom: 8px; }
.message-body p:last-child { margin-bottom: 0; }

.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions { opacity: 1; }

.msg-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.msg-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── Streaming indicator ──────────────────────────── */
.streaming .message-body::after {
    content: "▋";
    animation: blink 1s infinite;
    color: var(--accent);
    margin-left: 2px;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ─── Input Area ──────────────────────────────────── */
.input-area {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px 12px;
}

.input-wrapper:focus-within { border-color: var(--accent); }

.btn-attach {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.btn-attach:hover { background: var(--bg-hover); }

#message-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    max-height: 200px;
    min-height: 20px;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
    padding: 4px 0;
}

#message-input::placeholder { color: var(--text-muted); }

.btn-send {
    background: var(--accent);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.file-preview {
    max-width: 800px;
    margin: 8px auto 0;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 12px;
}

.file-chip .remove { cursor: pointer; color: var(--error); }

.input-hints {
    max-width: 800px;
    margin: 6px auto 0;
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: var(--text-muted);
}

/* ─── Status Messages ─────────────────────────────── */
.status-message {
    text-align: center;
    padding: 8px;
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

/* ─── Mobile ──────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }

    .sidebar.open { transform: translateX(0); }

    .menu-toggle { display: block; }

    .welcome-message h1 { font-size: 28px; }

    .quick-actions { flex-direction: column; }
    .quick-btn { width: 100%; }

    .message-actions { opacity: 1; }
}

/* ─── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Code Highlighting ───────────────────────────── */
.hljs { background: var(--bg-primary) !important; border-radius: var(--radius-sm); }
