/* ─── Roundtable Design System ─── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg-primary: #0a0b0f;
  --bg-secondary: #12131a;
  --bg-tertiary: #1a1b25;
  --bg-elevated: #1e2030;
  --bg-glass: rgba(30, 32, 48, 0.7);
  --surface-hover: rgba(255, 255, 255, 0.04);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(99, 102, 241, 0.3);
  --text-primary: #e2e4f0;
  --text-secondary: #8b8fa8;
  --text-muted: #5c5f78;
  --accent-primary: #6366f1;
  --accent-secondary: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --gradient-brand: linear-gradient(135deg, #6366f1, #8b5cf6, #a78bfa);
  --gradient-surface: linear-gradient(180deg, var(--bg-secondary), var(--bg-primary));
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--bg-primary); color: var(--text-primary); line-height: 1.6; -webkit-font-smoothing: antialiased; }

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ─── Landing Page ─── */
.landing { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-primary); position: relative; overflow: hidden; }
.landing::before { content: ''; position: absolute; width: 600px; height: 600px; background: radial-gradient(circle, var(--accent-glow), transparent 70%); top: -200px; right: -100px; pointer-events: none; }
.landing::after { content: ''; position: absolute; width: 400px; height: 400px; background: radial-gradient(circle, rgba(139,92,246,0.08), transparent 70%); bottom: -100px; left: -100px; pointer-events: none; }

.auth-container { position: relative; z-index: 1; width: 100%; max-width: 420px; padding: 20px; }
.auth-card { background: var(--bg-glass); backdrop-filter: blur(20px); border: 1px solid var(--border-subtle); border-radius: var(--radius-xl); padding: 40px; box-shadow: var(--shadow-lg); }
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 { font-size: 28px; font-weight: 700; background: var(--gradient-brand); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.auth-logo p { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

.auth-tabs { display: flex; gap: 4px; background: var(--bg-tertiary); border-radius: var(--radius-md); padding: 4px; margin-bottom: 24px; }
.auth-tab { flex: 1; padding: 10px; text-align: center; border: none; background: none; color: var(--text-secondary); font-size: 14px; font-weight: 500; cursor: pointer; border-radius: var(--radius-sm); transition: var(--transition-fast); font-family: inherit; }
.auth-tab.active { background: var(--accent-primary); color: white; box-shadow: var(--shadow-glow); }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input { width: 100%; padding: 12px 14px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-size: 14px; font-family: inherit; transition: var(--transition-fast); outline: none; }
.form-group input:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-glow); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 20px; border: none; border-radius: var(--radius-md); font-size: 14px; font-weight: 600; cursor: pointer; transition: var(--transition-fast); font-family: inherit; text-decoration: none; }
.btn-primary { width: 100%; background: var(--gradient-brand); color: white; box-shadow: var(--shadow-glow); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 0 30px var(--accent-glow); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border-subtle); }
.btn-secondary:hover { background: var(--bg-elevated); border-color: var(--border-accent); }
.btn-ghost { background: none; color: var(--text-secondary); padding: 8px 12px; }
.btn-ghost:hover { color: var(--text-primary); background: var(--surface-hover); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-danger { background: var(--error); color: white; }

.auth-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.2); color: var(--error); padding: 10px 14px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 16px; display: none; }
.auth-error.visible { display: block; }

/* ─── App Layout ─── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 280px; min-width: 280px; background: var(--bg-secondary); border-right: 1px solid var(--border-subtle); display: flex; flex-direction: column; transition: width 0.25s ease, min-width 0.25s ease; }
.sidebar-header { padding: 16px 20px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }
.sidebar-brand { font-size: 18px; font-weight: 700; background: var(--gradient-brand); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; white-space: nowrap; overflow: hidden; }
.sidebar-brand-text { transition: opacity 0.2s ease, width 0.25s ease; display: inline-block; }
.sidebar-collapse-btn { transition: transform 0.25s ease; }
.sidebar-rooms { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 10px; overflow: hidden; }
.sidebar-footer .user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--gradient-brand); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.sidebar-footer .user-info { flex: 1; min-width: 0; transition: opacity 0.2s ease; }
.sidebar-footer .user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Collapsed sidebar */
.sidebar.collapsed { width: 56px; min-width: 56px; }
.sidebar.collapsed .sidebar-header { padding: 16px 10px; justify-content: center; }
.sidebar.collapsed .sidebar-brand-text { opacity: 0; width: 0; overflow: hidden; }
.sidebar.collapsed .sidebar-collapse-btn { transform: rotate(180deg); }
.sidebar.collapsed #btn-new-room { display: none; }
.sidebar.collapsed .sidebar-rooms { padding: 4px; }
.sidebar.collapsed .room-item { padding: 10px 0; justify-content: center; }
.sidebar.collapsed .room-item-text { display: none; }
.sidebar.collapsed .sidebar-footer { padding: 12px 0; justify-content: center; gap: 0; }
.sidebar.collapsed .sidebar-footer .user-info,
.sidebar.collapsed .sidebar-footer #btn-settings,
.sidebar.collapsed .sidebar-footer #btn-logout { display: none; }

.room-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-md); cursor: pointer; transition: var(--transition-fast); margin-bottom: 2px; }
.room-item:hover { background: var(--surface-hover); }
.room-item.active { background: var(--accent-glow); border: 1px solid var(--border-accent); }
.room-icon { width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.room-item.active .room-icon { background: var(--accent-primary); }
.room-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { font-size: 11px; color: var(--text-muted); }

/* ─── Main Chat Area ─── */
.main-area { flex: 1; display: flex; flex-direction: row; background: var(--bg-primary); min-width: 0; position: relative; overflow: hidden; }
#chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ─── Code Panel ─── */
.code-panel { width: 0; min-width: 0; overflow: hidden; border-left: 1px solid var(--border-subtle); background: var(--bg-secondary); display: flex; flex-direction: column; transition: width 0.3s ease, min-width 0.3s ease; }
.code-panel.open { width: 420px; min-width: 420px; }
.code-panel-header { padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.code-panel-repo-select { flex: 1; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 12px; padding: 6px 8px; outline: none; }
.code-panel-repo-select:focus { border-color: var(--accent-primary); }
.code-panel-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.file-tree { width: 100%; height: 220px; overflow-y: auto; padding: 4px 0; flex-shrink: 0; }
.file-tree-empty { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.file-tree-loading { padding: 16px; text-align: center; color: var(--text-muted); font-size: 12px; }
.tree-dir, .tree-file { display: flex; align-items: center; gap: 4px; padding: 3px 10px; cursor: pointer; font-size: 12px; white-space: nowrap; transition: background 0.15s; }
.tree-dir:hover, .tree-file:hover { background: var(--surface-hover); }
.tree-file.active { background: var(--accent-glow); border-right: 2px solid var(--accent-primary); }
.tree-toggle { font-size: 9px; width: 14px; text-align: center; color: var(--text-muted); flex-shrink: 0; }
.tree-icon { font-size: 13px; flex-shrink: 0; }
.tree-name { overflow: hidden; text-overflow: ellipsis; }
.tree-size { margin-left: auto; font-size: 10px; color: var(--text-muted); flex-shrink: 0; padding-left: 8px; }
.file-viewer { flex: 1; overflow: auto; }
.file-viewer-empty { padding: 40px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.file-viewer-loading { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 12px; }
.file-viewer-header { padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; background: var(--bg-tertiary); position: sticky; top: 0; z-index: 1; }
.file-viewer-path { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.file-viewer-meta { font-size: 11px; color: var(--text-muted); }
.file-viewer-code { margin: 0; padding: 12px; font-size: 12px; line-height: 1.5; background: var(--bg-primary); border: none; border-radius: 0; }
.file-viewer-code code { font-family: 'SF Mono', Monaco, monospace; }
.file-viewer-media { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; background-image: linear-gradient(45deg, var(--bg-tertiary) 25%, transparent 25%), linear-gradient(-45deg, var(--bg-tertiary) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg-tertiary) 75%), linear-gradient(-45deg, transparent 75%, var(--bg-tertiary) 75%); background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0px; overflow: auto; }
.file-viewer-media img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); }
#btn-code-panel.active { background: var(--accent-glow); color: var(--accent-primary); }

/* Git status indicators */
.git-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; margin-left: 4px; }
.git-dot.git-untracked, .git-dot.git-added { background: #4ade80; }
.git-dot.git-modified { background: #fbbf24; }
.git-dot.git-deleted { background: #f87171; }
.git-dot.git-renamed { background: #60a5fa; }
.tree-file.git-untracked .tree-name, .tree-file.git-added .tree-name { color: #4ade80; }
.tree-file.git-modified .tree-name { color: #fbbf24; }
.tree-file.git-deleted .tree-name { color: #f87171; text-decoration: line-through; }
.tree-file.git-renamed .tree-name { color: #60a5fa; }

/* Resize handles */
.resize-handle-v { width: 4px; cursor: col-resize; background: transparent; transition: background 0.2s; flex-shrink: 0; position: relative; z-index: 5; margin: 0 -2px; }
.resize-handle-v:hover, .resize-handle-v.dragging { background: var(--accent-primary); }
.resize-handle-h { height: 4px; cursor: row-resize; background: transparent; transition: background 0.2s; flex-shrink: 0; }
.resize-handle-h:hover, .resize-handle-h.dragging { background: var(--accent-primary); }

/* Word wrap toggle */
.code-panel-wrap-btn { font-size: 14px !important; }
.code-panel-wrap-btn.active { color: var(--accent-primary); background: var(--accent-glow); }
.file-viewer-code.word-wrap { white-space: pre-wrap; word-break: break-all; }
.file-viewer-code.word-wrap code { white-space: pre-wrap; word-break: break-all; }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.chat-header { padding: 14px 24px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; background: var(--bg-secondary); flex-shrink: 0; }
.chat-header-info h2 { font-size: 16px; font-weight: 600; }
.chat-header-info p { font-size: 12px; color: var(--text-secondary); }
.chat-header-actions { display: flex; gap: 8px; align-items: center; }

.presence-bar { display: flex; gap: -4px; align-items: center; }
.presence-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--bg-tertiary); border: 2px solid var(--bg-secondary); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; margin-left: -6px; position: relative; }
.presence-avatar:first-child { margin-left: 0; }
.presence-dot { position: absolute; bottom: -1px; right: -1px; width: 8px; height: 8px; background: var(--success); border-radius: 50%; border: 2px solid var(--bg-secondary); }

.chat-messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 4px; }

/* ─── Messages ─── */
.message { display: flex; gap: 12px; padding: 8px 0; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } 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: 13px; font-weight: 600; flex-shrink: 0; margin-top: 2px; }
.message-avatar.user { background: var(--gradient-brand); } /* fallback — overridden by inline style per user */
.message-avatar.assistant { background: linear-gradient(135deg, #059669, #10b981); }
.message-body { flex: 1; min-width: 0; }
.message-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.message-sender { font-size: 13px; font-weight: 600; }
.message-time { font-size: 11px; color: var(--text-muted); }
.message-content { font-size: 14px; line-height: 1.65; color: var(--text-primary); word-wrap: break-word; }
.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content code { background: var(--bg-tertiary); padding: 2px 6px; border-radius: 4px; font-size: 13px; font-family: 'SF Mono', Monaco, monospace; }
.message-content pre { background: var(--bg-tertiary); padding: 14px; border-radius: var(--radius-md); overflow-x: auto; margin: 8px 0; border: 1px solid var(--border-subtle); }
.message-content pre code { background: none; padding: 0; }
.mention { background: rgba(99,102,241,0.12); color: var(--accent-secondary); padding: 1px 5px; border-radius: 4px; font-weight: 600; font-size: 0.95em; }
.mention-ai { background: rgba(16,185,129,0.15); color: #10b981; }

/* ─── Tool Call Cards ─── */
.tool-card { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); margin: 8px 0; overflow: hidden; animation: fadeIn 0.3s ease; }
.tool-card-header { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; transition: var(--transition-fast); }
.tool-card-header:hover { background: var(--surface-hover); }
.tool-card-icon { font-size: 14px; }
.tool-card-name { font-size: 13px; font-weight: 600; color: var(--accent-secondary); }
.tool-card-status { margin-left: auto; font-size: 12px; }
.tool-card-status.running { color: var(--warning); }
.tool-card-status.done { color: var(--success); }
.tool-card-status.error { color: var(--error); }
.tool-card-body { padding: 0 14px 12px; font-size: 13px; color: var(--text-secondary); display: none; }
.tool-card.expanded .tool-card-body { display: block; }
.tool-card-args, .tool-card-result { background: var(--bg-primary); padding: 8px 10px; border-radius: var(--radius-sm); margin-top: 6px; font-family: 'SF Mono', Monaco, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 200px; overflow-y: auto; }
.tool-card-body pre { background: var(--bg-primary); padding: 12px; border-radius: var(--radius-sm); margin: 4px 0; overflow-x: auto; border: 1px solid var(--border-subtle); max-height: 400px; overflow-y: auto; }
.tool-card-body pre code { font-size: 12px; font-family: 'SF Mono', Monaco, monospace; }

/* ─── Code Block Wrapper ─── */
.code-block-wrapper { margin: 10px 0; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border-subtle); }
.code-block-header { display: flex; justify-content: space-between; align-items: center; padding: 6px 14px; background: var(--bg-elevated); font-size: 12px; color: var(--text-muted); font-weight: 500; }
.code-copy-btn { background: none; border: 1px solid var(--border-subtle); color: var(--text-secondary); font-size: 11px; padding: 3px 8px; border-radius: 4px; cursor: pointer; font-family: inherit; transition: var(--transition-fast); }
.code-copy-btn:hover { background: var(--surface-hover); color: var(--text-primary); border-color: var(--border-accent); }
.code-block-wrapper pre { margin: 0; border: none; border-radius: 0; }
.code-block-wrapper pre code { font-size: 13px; color: #c9d1d9; font-family: 'SF Mono', Monaco, 'Fira Code', monospace; }

/* ─── Tool Result Cards ─── */
.search-results { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.search-result-item { padding: 6px 10px; background: var(--bg-primary); border-radius: var(--radius-sm); border: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 8px; }
.search-result-title { font-size: 12px; font-weight: 500; }
.search-result-title a { color: var(--accent-secondary); text-decoration: none; }
.search-result-title a:hover { text-decoration: underline; }
.search-result-url { font-size: 11px; color: var(--success); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-snippet { font-size: 12px; color: var(--text-secondary); margin-top: 4px; line-height: 1.4; }
.search-summary { margin-top: 8px; padding: 10px 12px; background: var(--bg-primary); border-radius: var(--radius-sm); border: 1px solid var(--border-subtle); font-size: 13px; line-height: 1.5; color: var(--text-primary); white-space: pre-wrap; }
.search-sources-label { margin-top: 8px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.tool-result-success { margin-top: 8px; padding: 8px 10px; background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.2); border-radius: var(--radius-sm); font-size: 12px; color: var(--success); }
.tool-result-error { margin-top: 8px; padding: 8px 10px; background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.2); border-radius: var(--radius-sm); font-size: 12px; color: var(--error); }
.tool-result-empty { margin-top: 8px; padding: 8px 10px; font-size: 12px; color: var(--text-muted); font-style: italic; }

/* ─── Rendered Markdown (in tool cards + messages) ─── */
.rendered-markdown { margin-top: 8px; padding: 12px 14px; background: var(--bg-primary); border-radius: var(--radius-sm); border: 1px solid var(--border-subtle); font-size: 13px; line-height: 1.6; color: var(--text-primary); max-height: 400px; overflow-y: auto; }
.rendered-markdown h1 { font-size: 1.4em; font-weight: 700; margin: 16px 0 8px; color: var(--text-primary); border-bottom: 1px solid var(--border-subtle); padding-bottom: 4px; }
.rendered-markdown h2 { font-size: 1.2em; font-weight: 600; margin: 14px 0 6px; color: var(--text-primary); }
.rendered-markdown h3 { font-size: 1.05em; font-weight: 600; margin: 12px 0 4px; color: var(--text-secondary); }
.rendered-markdown h4, .rendered-markdown h5, .rendered-markdown h6 { font-size: 1em; font-weight: 600; margin: 10px 0 4px; }
.rendered-markdown p { margin: 6px 0; }
.rendered-markdown ul, .rendered-markdown ol { margin: 6px 0; padding-left: 24px; }
.rendered-markdown li { margin: 3px 0; }
.rendered-markdown blockquote { margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent-primary); color: var(--text-secondary); background: rgba(99,102,241,0.05); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.rendered-markdown table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 12px; }
.rendered-markdown th, .rendered-markdown td { border: 1px solid var(--border-subtle); padding: 6px 10px; text-align: left; }
.rendered-markdown th { background: var(--bg-secondary); font-weight: 600; }
.rendered-markdown a { color: var(--accent-secondary); text-decoration: none; }
.rendered-markdown a:hover { text-decoration: underline; }
.rendered-markdown img { max-width: 100%; border-radius: var(--radius-sm); margin: 8px 0; }
.rendered-markdown hr { border: none; border-top: 1px solid var(--border-subtle); margin: 12px 0; }
.message-content h1 { font-size: 1.3em; font-weight: 700; margin: 12px 0 6px; }
.message-content h2 { font-size: 1.15em; font-weight: 600; margin: 10px 0 4px; }
.message-content h3 { font-size: 1.05em; font-weight: 600; margin: 8px 0 4px; }
.message-content ul, .message-content ol { padding-left: 24px; margin: 4px 0; }
.message-content li { margin: 2px 0; }
.message-content table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.message-content th, .message-content td { border: 1px solid var(--border-subtle); padding: 4px 8px; }
.message-content th { background: var(--bg-secondary); font-weight: 600; }
.message-content blockquote { padding: 4px 12px; border-left: 3px solid var(--accent-primary); color: var(--text-secondary); margin: 6px 0; }
.message-content a { color: var(--accent-secondary); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }

/* ─── Streaming Indicator ─── */
.streaming-indicator { display: inline-flex; align-items: center; gap: 6px; padding: 4px 0; }
.streaming-dot { width: 6px; height: 6px; background: var(--accent-secondary); border-radius: 50%; animation: pulse 1.4s infinite; }
.streaming-dot:nth-child(2) { animation-delay: 0.2s; }
.streaming-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

/* ─── Chat Input ─── */
.typing-bar { height: 20px; padding: 0 24px; font-size: 12px; color: var(--text-muted); display: flex; align-items: center; flex-shrink: 0; overflow: hidden; }
.typing-bar:empty { visibility: hidden; }
.typing-bar .streaming-dot { display: inline-block; width: 4px; height: 4px; margin-right: 6px; }
.chat-input-area { padding: 16px 24px; border-top: 1px solid var(--border-subtle); background: var(--bg-secondary); flex-shrink: 0; }
.chat-input-wrapper { display: flex; gap: 10px; align-items: flex-end; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 8px 12px; transition: var(--transition-fast); }
.chat-input-wrapper:focus-within { border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-glow); }
.chat-input { flex: 1; background: none; border: none; color: var(--text-primary); font-size: 14px; font-family: inherit; resize: none; outline: none; max-height: 120px; min-height: 24px; line-height: 1.5; }
.chat-input::placeholder { color: var(--text-muted); }
.chat-send-btn { width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--gradient-brand); border: none; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition-fast); flex-shrink: 0; }
.chat-send-btn:hover { transform: scale(1.05); box-shadow: var(--shadow-glow); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.chat-send-btn svg { width: 18px; height: 18px; }

/* ─── Empty State ─── */
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px; }
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); font-size: 14px; max-width: 360px; }

/* ─── Modals ─── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 100; animation: fadeIn 0.2s ease; }
.modal-overlay.active { display: flex; }
.modal { background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: var(--radius-xl); padding: 28px; width: 90%; max-width: 480px; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal h3 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ─── Select ─── */
select { width: 100%; padding: 10px 12px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-size: 14px; font-family: inherit; outline: none; cursor: pointer; appearance: none; }
select:focus { border-color: var(--accent-primary); }

/* ─── Toast ─── */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 18px; background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); font-size: 13px; box-shadow: var(--shadow-md); animation: slideIn 0.3s ease; max-width: 360px; }
.toast.error { border-color: rgba(239,68,68,0.3); color: var(--error); }
.toast.success { border-color: rgba(34,197,94,0.3); color: var(--success); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -280px; top: 0; bottom: 0; z-index: 50; transition: var(--transition-normal); }
  .sidebar.open { left: 0; }
  .chat-messages { padding: 16px; }
  .chat-input-area { padding: 12px 16px; }
}

/* ─── Settings Modal (tabbed) ─── */
.modal-lg { max-width: 600px; padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-header h3 { font-size: 18px; font-weight: 600; margin: 0; }
.settings-tabs { display: flex; gap: 2px; padding: 16px 24px 0; border-bottom: 1px solid var(--border-subtle); margin-bottom: 0; }
.settings-tab { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 14px; font-size: 13px; font-weight: 500; color: var(--text-secondary); cursor: pointer; transition: var(--transition-fast); margin-bottom: -1px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.settings-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.settings-tab.active { color: var(--accent-primary); border-bottom-color: var(--accent-primary); }
.settings-tab-panel { display: none; padding: 20px 24px 24px; overflow-y: auto; max-height: 70vh; }
.settings-tab-panel.active { display: block; }
.settings-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; line-height: 1.5; }
.form-group textarea { width: 100%; padding: 12px 14px; background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); color: var(--text-primary); font-size: 14px; font-family: inherit; transition: var(--transition-fast); outline: none; box-sizing: border-box; }
.form-group textarea:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-glow); }

/* ─── Tools Grid ─── */
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tool-group { background: var(--bg-tertiary); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 12px; }
.tool-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 10px; }
.tool-toggle { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; user-select: none; }
.tool-toggle:hover .tool-toggle-label { color: var(--text-primary); }
.tool-checkbox { width: 15px; height: 15px; accent-color: var(--accent-primary); cursor: pointer; flex-shrink: 0; }
.tool-toggle-label { font-size: 13px; color: var(--text-secondary); transition: var(--transition-fast); text-transform: capitalize; }
