:root {
  color-scheme: dark;
  --sidebar-bg:#080809;
  --main-bg:#101012;
  --surface:#161618;
  --surface-2:#1d1d20;
  --surface-3:#26262a;
  --text:#ececf1;
  --muted:#9b9ba4;
  --faint:#64646d;
  --line:rgba(255,255,255,.07);
  --line-strong:rgba(255,255,255,.13);
  --hover:rgba(255,255,255,.055);
  --accent:#f1f1f3;
  --accent-text:#0c0c0d;
  --blue:#3b82f6;
  --danger:#f07878;
  --success:#68d39b;
  --user-bubble:#1e1e21;
  --shadow:0 14px 50px rgba(0,0,0,.45);
  --code-bg:#0a0a0c;
}
body.light {
  color-scheme: light;
  --sidebar-bg:#f7f7f5;
  --main-bg:#ffffff;
  --surface:#ffffff;
  --surface-2:#f3f3f1;
  --surface-3:#e8e8e5;
  --text:#1c1c1f;
  --muted:#6d6d76;
  --faint:#a3a3ab;
  --line:rgba(15,15,18,.08);
  --line-strong:rgba(15,15,18,.16);
  --hover:rgba(15,15,18,.05);
  --accent:#17171a;
  --accent-text:#fff;
  --blue:#2563eb;
  --danger:#d9534f;
  --success:#2f9e63;
  --user-bubble:#f1f1ee;
  --shadow:0 14px 50px rgba(20,20,25,.12);
  --code-bg:#0d1117;
}
* { box-sizing:border-box; }
html, body { width:100%; height:100%; margin:0; overflow:hidden; background:var(--main-bg); color:var(--text); font-family:"Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", sans-serif; font-size:15px; }
button, input, textarea, select { font:inherit; color:inherit; }
button { cursor:pointer; background:none; border:0; padding:0; }
button, a { -webkit-tap-highlight-color:transparent; }
.hidden { display:none !important; }
svg { fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }

.app { display:flex; width:100%; height:100%; }

/* ============ Sidebar ============ */
.sidebar-backdrop { position:fixed; z-index:900; inset:0; display:none; background:rgba(0,0,0,.5); }
.sidebar { position:relative; z-index:950; display:flex; flex-direction:column; flex:none; width:264px; padding:10px 12px 12px; overflow:hidden; background:var(--sidebar-bg); border-right:1px solid var(--line); transition:width .22s ease, transform .22s ease, opacity .22s ease; }
.app.sidebar-collapsed .sidebar { width:0; padding-inline:0; border-right:0; opacity:0; pointer-events:none; }
.sb-top { display:flex; align-items:center; justify-content:space-between; min-height:38px; margin-bottom:6px; }
.sb-top-actions { display:flex; gap:2px; }
.icon-button { display:grid; width:34px; height:34px; place-items:center; flex:none; border-radius:9px; color:var(--muted); transition:background .12s ease, color .12s ease; }
.icon-button:hover { background:var(--hover); color:var(--text); }
.icon-button svg { width:19px; height:19px; }
.sb-search { position:relative; display:flex; align-items:center; margin-bottom:10px; }
.sb-search svg { position:absolute; left:11px; width:16px; height:16px; color:var(--faint); pointer-events:none; }
.sb-search input { width:100%; height:36px; padding:0 10px 0 33px; border:1px solid transparent; border-radius:10px; outline:0; background:transparent; color:var(--text); font-size:13.5px; transition:background .12s ease, border-color .12s ease; }
.sb-search input:hover { background:var(--hover); }
.sb-search input:focus { border-color:var(--line-strong); background:var(--surface-2); }
.sb-search input::placeholder { color:var(--faint); }
.sb-nav { display:flex; flex-direction:column; gap:1px; margin-bottom:10px; }
.sb-nav-item { display:flex; align-items:center; gap:11px; min-height:37px; padding:0 10px; border-radius:9px; color:var(--muted); font-size:13.5px; text-align:left; transition:background .12s ease, color .12s ease; }
.sb-nav-item:hover { background:var(--hover); color:var(--text); }
.sb-nav-item svg { width:17px; height:17px; flex:none; }
.sb-nav-item.provider-nav { margin-top:4px; border:1px solid color-mix(in srgb, #8b5cf6 25%, var(--line)); }
.sb-nav-item.provider-nav.active { background:var(--surface-2); color:var(--text); }
.provider-nav-badge { margin-left:auto; color:#a78bfa; font-size:10px; }
.sb-chats { flex:1; min-height:0; overflow-y:auto; overscroll-behavior:contain; padding-bottom:8px; scrollbar-width:thin; scrollbar-color:var(--surface-3) transparent; }
.sb-chats::-webkit-scrollbar { width:6px; }
.sb-chats::-webkit-scrollbar-thumb { border-radius:3px; background:var(--surface-3); }
.chat-group-label { margin:14px 10px 5px; color:var(--faint); font-size:11px; font-weight:650; letter-spacing:.02em; }
.chat-group-label:first-child { margin-top:2px; }
.chat-item { position:relative; display:flex; align-items:center; width:100%; min-height:37px; padding:0 30px 0 10px; border-radius:9px; color:var(--muted); font-size:13.5px; text-align:left; transition:background .12s ease, color .12s ease; }
.chat-item:hover, .chat-item.active { background:var(--hover); color:var(--text); }
.chat-item span.title { overflow:hidden; min-width:0; flex:1; text-overflow:ellipsis; white-space:nowrap; }
.chat-item .chat-menu-trigger { position:absolute; right:4px; display:none; width:24px; height:24px; place-items:center; border-radius:6px; color:var(--muted); letter-spacing:1px; }
.chat-item:hover .chat-menu-trigger, .chat-item.menu-open .chat-menu-trigger { display:grid; }
.chat-item .chat-menu-trigger:hover { background:var(--surface-3); color:var(--text); }
.chat-menu { position:fixed; z-index:2000; min-width:150px; padding:5px; border:1px solid var(--line-strong); border-radius:11px; background:var(--surface); box-shadow:var(--shadow); }
.chat-menu button { display:flex; align-items:center; gap:9px; width:100%; min-height:32px; padding:0 9px; border-radius:7px; color:var(--muted); font-size:13px; text-align:left; }
.chat-menu button:hover { background:var(--hover); color:var(--text); }
.chat-menu button.danger:hover { color:var(--danger); }
.chat-menu svg { width:15px; height:15px; flex:none; }
.chat-empty { padding:16px 10px; color:var(--faint); font-size:13px; }
.sb-bottom { display:flex; align-items:center; padding-top:8px; border-top:1px solid var(--line); }
.sb-user { display:flex; align-items:center; gap:10px; width:100%; min-height:44px; padding:0 8px; border-radius:10px; color:var(--text); text-decoration:none; }
.sb-user:hover { background:var(--hover); }
.avatar { display:grid; width:28px; height:28px; place-items:center; flex:none; border-radius:50%; background:linear-gradient(135deg,#3b82f6,#8b5cf6); color:#fff; font-size:12px; font-weight:750; }
.sb-user-text { display:grid; min-width:0; gap:1px; }
.sb-user-text strong { overflow:hidden; font-size:13px; text-overflow:ellipsis; white-space:nowrap; }
.sb-user-text small { color:var(--faint); font-size:11px; }

/* ============ Main column ============ */
.main { position:relative; z-index:1; display:flex; flex-direction:column; flex:1; min-width:0; height:100%; background:var(--main-bg); }
.chat-header { position:relative; z-index:800; display:flex; align-items:center; gap:6px; flex:none; height:56px; padding:0 14px; }
.header-center { position:relative; }
.model-selector { display:flex; align-items:center; gap:7px; min-height:36px; padding:0 11px 0 14px; border-radius:11px; color:var(--text); transition:background .12s ease; }
.model-selector:hover, .model-selector.open { background:var(--hover); }
.model-selector strong { max-width:260px; overflow:hidden; font-size:14.5px; font-weight:600; text-overflow:ellipsis; white-space:nowrap; }
.model-selector .chevron { width:16px; height:16px; color:var(--muted); transition:transform .15s ease; }
.model-selector.open .chevron { transform:rotate(180deg); }
.model-menu { position:absolute; z-index:1200; top:calc(100% + 6px); left:0; width:320px; max-height:430px; overflow:auto; padding:7px; border:1px solid var(--line-strong); border-radius:14px; background:var(--surface); box-shadow:var(--shadow); scrollbar-width:thin; scrollbar-color:var(--surface-3) transparent; }
.model-menu-search { position:sticky; top:0; z-index:1; display:flex; align-items:center; gap:8px; margin:-1px -1px 6px; padding:6px 6px 8px; border-bottom:1px solid var(--line); background:var(--surface); }
.model-menu-search svg { width:15px; height:15px; color:var(--faint); }
.model-menu-search input { width:100%; height:32px; border:0; outline:0; background:transparent; color:var(--text); font-size:13.5px; }
.model-provider-filter { display:flex; gap:4px; margin:0 -1px 6px; padding:0 2px 7px; border-bottom:1px solid var(--line); }
.model-provider-filter button { min-height:28px; padding:0 9px; border:1px solid transparent; border-radius:8px; color:var(--muted); font-size:11.5px; }
.model-provider-filter button:hover { background:var(--hover); color:var(--text); }
.model-provider-filter button.active { border-color:var(--line-strong); background:var(--surface-2); color:var(--text); }
.model-option { display:grid; width:100%; gap:2px; padding:9px 11px; border-radius:10px; color:var(--text); text-align:left; }
.model-option:hover { background:var(--hover); }
.model-option.selected { background:var(--surface-2); }
.model-option .row { display:flex; align-items:center; gap:8px; }
.model-option strong { flex:1; overflow:hidden; font-size:13.5px; text-overflow:ellipsis; white-space:nowrap; }
.model-option .check { width:16px; height:16px; color:var(--text); }
.model-option small { overflow:hidden; color:var(--muted); font-size:11.5px; text-overflow:ellipsis; white-space:nowrap; }
.model-provider { margin-left:auto; color:var(--faint); font-size:9px; font-style:normal; font-weight:600; letter-spacing:.04em; text-transform:uppercase; }
.header-actions { display:flex; align-items:center; gap:4px; margin-left:auto; }

/* Empty state: hero + composer vertically centered */
.empty-spacer-top, .empty-spacer-bottom { flex:0 0 auto; }
.main.empty .empty-spacer-top, .main.empty .empty-spacer-bottom { flex:1 1 0; min-height:24px; }
.messages { display:none; flex:1; min-height:0; flex-direction:column; gap:6px; overflow-y:auto; overscroll-behavior:contain; padding:18px max(22px, calc((100% - 52rem) / 2)) 30px; scroll-behavior:smooth; scrollbar-width:thin; scrollbar-color:var(--surface-3) transparent; }
.main:not(.empty) .messages { display:flex; }
.welcome-state { display:flex; flex-direction:column; align-items:center; gap:10px; padding-bottom:26px; text-align:center; }
.welcome-mark { display:grid; width:54px; height:54px; place-items:center; border-radius:16px; background:linear-gradient(135deg,#3b82f6,#8b5cf6); color:#fff; font-size:23px; font-weight:850; box-shadow:0 12px 40px rgba(59,130,246,.25); }
.welcome-state h1 { margin:8px 0 0; font-size:27px; font-weight:650; letter-spacing:-.03em; }
.welcome-state p { margin:0; color:var(--muted); font-size:14px; }
.suggestions { display:flex; flex-wrap:wrap; justify-content:center; gap:8px; margin-top:14px; }
.suggestions button { min-height:34px; padding:0 14px; border:1px solid var(--line); border-radius:999px; background:var(--surface); color:var(--muted); font-size:12.5px; transition:border-color .12s ease, color .12s ease; }
.suggestions button:hover { border-color:var(--line-strong); color:var(--text); }

/* ============ Messages ============ */
.msg { display:flex; flex-direction:column; padding:10px 0; }
.msg.user { align-items:flex-end; }
.msg.user .bubble { max-width:min(78%, 42rem); padding:11px 16px; border-radius:22px; background:var(--user-bubble); color:var(--text); font-size:15.5px; line-height:1.65; overflow-wrap:anywhere; white-space:pre-wrap; }
.msg.assistant { align-items:stretch; }
.msg.assistant .content { min-width:0; font-size:15.5px; line-height:1.75; overflow-wrap:anywhere; }
.msg-actions { display:flex; gap:2px; margin-top:5px; opacity:0; transition:opacity .12s ease; }
.msg.user .msg-actions { justify-content:flex-end; }
.msg:hover .msg-actions, .msg.actions-visible .msg-actions { opacity:1; }
.msg-action { display:grid; width:29px; height:29px; place-items:center; border-radius:7px; color:var(--faint); }
.msg-action:hover { background:var(--hover); color:var(--text); }
.msg-action svg { width:15.5px; height:15.5px; }
.cursor { display:inline-block; width:9px; height:17px; margin-left:2px; vertical-align:-3px; background:var(--text); animation:blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity:0; } }
.error-banner { margin:6px 0; padding:11px 14px; border:1px solid rgba(240,120,120,.35); border-radius:12px; background:rgba(240,120,120,.09); color:var(--danger); font-size:13.5px; line-height:1.55; overflow-wrap:anywhere; }
.search-citations { display:flex; flex-wrap:wrap; gap:6px; margin:4px 0 8px; }
.search-citations a { display:inline-flex; max-width:230px; align-items:center; gap:6px; padding:5px 10px; border:1px solid var(--line); border-radius:999px; color:var(--muted); font-size:11.5px; text-decoration:none; }
.search-citations a:hover { border-color:var(--line-strong); color:var(--text); }
.search-citations span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* Markdown */
.md > :first-child { margin-top:0; }
.md > :last-child { margin-bottom:0; }
.md h1, .md h2, .md h3, .md h4 { margin:1.15em 0 .5em; font-weight:650; line-height:1.35; letter-spacing:-.01em; }
.md h1 { font-size:1.45em; } .md h2 { font-size:1.28em; } .md h3 { font-size:1.12em; } .md h4 { font-size:1em; }
.md p { margin:.65em 0; }
.md ul, .md ol { margin:.65em 0; padding-left:1.5em; }
.md li { margin:.3em 0; }
.md li > p { margin:.25em 0; }
.md a { color:var(--blue); text-decoration:none; }
.md a:hover { text-decoration:underline; }
.md blockquote { margin:.8em 0; padding:.1em 0 .1em 1em; border-left:3px solid var(--line-strong); color:var(--muted); }
.md hr { margin:1.2em 0; border:0; border-top:1px solid var(--line); }
.md table { display:block; max-width:100%; margin:.8em 0; overflow-x:auto; border-collapse:collapse; font-size:.92em; }
.md th, .md td { padding:7px 12px; border:1px solid var(--line); text-align:left; }
.md th { background:var(--surface-2); font-weight:650; }
.md code:not(pre code) { padding:.15em .4em; border-radius:6px; background:var(--surface-3); font-family:ui-monospace, SFMono-Regular, Consolas, monospace; font-size:.86em; }
.md pre { position:relative; margin:.85em 0; padding:14px 16px; overflow-x:auto; border:1px solid var(--line); border-radius:12px; background:var(--code-bg); font-size:13px; line-height:1.6; }
.md pre code { padding:0; background:transparent; font-family:ui-monospace, SFMono-Regular, Consolas, monospace; }
.code-header { position:absolute; top:0; right:0; left:0; display:flex; align-items:center; justify-content:space-between; padding:6px 10px 6px 14px; border-bottom:1px solid rgba(255,255,255,.06); color:#8b8b93; font-size:11px; }
.code-copy { display:flex; align-items:center; gap:5px; padding:3px 8px; border-radius:6px; color:#b8b8bf; font-size:11px; }
.code-copy:hover { background:rgba(255,255,255,.08); color:#fff; }
.code-copy svg { width:13px; height:13px; }
.md pre { padding-top:38px; }
.md img { max-width:100%; border-radius:10px; }

/* ============ Composer ============ */
.composer-zone { position:relative; z-index:700; flex:none; width:100%; padding:6px max(22px, calc((100% - 52rem) / 2)) 12px; }
.composer { padding:11px 12px 9px 16px; border:1px solid var(--line-strong); border-radius:26px; background:var(--surface); box-shadow:0 6px 28px rgba(0,0,0,.14); transition:border-color .15s ease; }
.composer:focus-within { border-color:color-mix(in srgb, var(--text) 30%, transparent); }
.composer textarea { display:block; width:100%; min-height:26px; max-height:190px; resize:none; border:0; outline:0; background:transparent; color:var(--text); font-size:15.5px; line-height:1.55; }
.composer textarea::placeholder { color:var(--faint); }
.composer-row { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-top:7px; }
.composer-left, .composer-right { display:flex; align-items:center; gap:5px; }
.round-button { display:grid; width:34px; height:34px; place-items:center; border:1px solid var(--line); border-radius:50%; color:var(--muted); transition:background .12s ease, color .12s ease, border-color .12s ease; }
.round-button:hover { background:var(--hover); color:var(--text); }
.round-button svg { width:17px; height:17px; }
.ghost-select { max-width:92px; min-height:32px; padding:0 4px; border:0; border-radius:8px; outline:0; background:transparent; color:var(--muted); font-size:12px; cursor:pointer; }
.ghost-select:hover, .ghost-select:focus { background:var(--hover); color:var(--text); }
.tool-pill { display:flex; align-items:center; gap:6px; min-height:32px; padding:0 11px; border:1px solid var(--line); border-radius:999px; color:var(--muted); font-size:12px; transition:all .12s ease; }
.tool-pill svg { width:14px; height:14px; }
.tool-pill:hover { background:var(--hover); color:var(--text); }
.tool-pill.active { border-color:color-mix(in srgb, var(--blue) 55%, transparent); background:color-mix(in srgb, var(--blue) 14%, transparent); color:var(--blue); }
.send-button { display:grid; width:36px; height:36px; place-items:center; border-radius:50%; background:var(--accent); color:var(--accent-text); transition:opacity .12s ease, filter .12s ease; }
.send-button:hover { filter:brightness(1.08); }
.send-button:disabled { opacity:.3; cursor:default; }
.send-button svg { width:18px; height:18px; }
.composer-hint { margin-top:7px; color:var(--faint); font-size:11px; text-align:center; }
.attachment-preview { display:flex; flex-wrap:wrap; gap:6px; padding-bottom:8px; }
.attachment-chip { display:flex; align-items:center; gap:7px; max-width:220px; padding:7px 8px 7px 11px; border:1px solid var(--line); border-radius:10px; background:var(--surface); font-size:12px; }
.attachment-chip span { overflow:hidden; color:var(--muted); text-overflow:ellipsis; white-space:nowrap; }
.attachment-chip button { display:grid; width:18px; height:18px; flex:none; place-items:center; border-radius:50%; background:var(--surface-3); color:var(--muted); font-size:12px; line-height:1; }
.dropzone { position:absolute; z-index:750; inset:8px; display:grid; place-items:center; border:2px dashed var(--line-strong); border-radius:20px; background:color-mix(in srgb, var(--surface) 88%, transparent); color:var(--muted); font-size:14px; backdrop-filter:blur(4px); }
.advanced-settings { display:flex; gap:14px; justify-content:center; margin-top:8px; }
.advanced-settings label { display:flex; align-items:center; gap:6px; color:var(--muted); font-size:12px; }
.advanced-settings input { width:52px; height:28px; padding:0 6px; border:1px solid var(--line); border-radius:7px; outline:0; background:var(--surface); color:var(--text); font-size:12px; }

/* ============ Details panel ============ */
.details-panel { position:fixed; z-index:1100; top:0; right:0; bottom:0; display:flex; width:min(370px, 94vw); flex-direction:column; border-left:1px solid var(--line); background:var(--surface); box-shadow:var(--shadow); transform:translateX(102%); transition:transform .22s ease; }
.details-panel.open { transform:translateX(0); }
.details-head { display:flex; align-items:center; justify-content:space-between; padding:16px 16px 12px; }
.details-head div { display:grid; gap:2px; }
.details-head strong { font-size:14.5px; }
.details-head small { color:var(--faint); font-size:11.5px; }
.details-tabs { display:flex; gap:2px; padding:0 12px; border-bottom:1px solid var(--line); }
.details-tabs button { min-height:36px; padding:0 12px; border-bottom:2px solid transparent; color:var(--faint); font-size:12.5px; font-weight:600; }
.details-tabs button.active { border-bottom-color:var(--text); color:var(--text); }
.details-body { flex:1; min-height:0; overflow-y:auto; padding:14px; }
.state-pill { display:inline-flex; padding:5px 10px; border-radius:999px; background:var(--surface-2); color:var(--muted); font-size:10.5px; font-weight:750; letter-spacing:.07em; }
.state-pill.success { color:var(--success); }
.state-pill.error { color:var(--danger); }
.route-trace { display:grid; gap:7px; margin-top:12px; }
.route-item { padding:10px 11px; border:1px solid var(--line); border-radius:11px; background:var(--surface-2); }
.route-item.success { border-color:color-mix(in srgb, var(--success) 45%, var(--line)); }
.route-item.error { border-color:color-mix(in srgb, var(--danger) 50%, var(--line)); }
.route-item strong, .route-item small { display:block; }
.route-item strong { font-size:12px; }
.route-item small { margin-top:4px; color:var(--muted); font-size:11px; line-height:1.55; }
.algorithm-card { display:grid; gap:5px; margin-top:13px; padding:11px 12px; border:1px solid var(--line); border-radius:11px; background:var(--surface-2); }
.algorithm-card small { color:var(--faint); font-size:10.5px; }
.algorithm-card strong { font-size:11.5px; line-height:1.5; }
.details-body form label { display:grid; gap:5px; margin-bottom:11px; color:var(--muted); font-size:11.5px; }
.details-body form input { width:100%; height:34px; padding:0 10px; border:1px solid var(--line); border-radius:9px; outline:0; background:var(--surface-2); color:var(--text); font-size:13px; }
.check-row { display:flex !important; align-items:center; justify-content:space-between; }
.check-row input { width:15px !important; height:15px !important; }
.secondary-button { width:100%; min-height:34px; border:1px solid var(--line-strong); border-radius:9px; background:var(--surface-2); color:var(--text); font-size:12.5px; }
.agent-output { min-height:160px; max-height:340px; margin:13px 0 0; padding:11px; overflow:auto; border:1px solid var(--line); border-radius:11px; background:var(--surface-2); color:var(--muted); font:11px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; white-space:pre-wrap; }
.files-list { display:grid; gap:6px; }
.file-row { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:9px 10px; border:1px solid var(--line); border-radius:10px; background:var(--surface-2); font-size:12px; }
.file-row span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.file-row a { flex:none; color:var(--text); }
.muted { color:var(--faint); font-size:12px; line-height:1.6; }

/* Rename input inside chat item */
.rename-input { width:100%; min-height:28px; padding:0 8px; border:1px solid var(--line-strong); border-radius:7px; outline:0; background:var(--surface-2); color:var(--text); font-size:13px; }

/* ============ Responsive ============ */
@media (max-width:900px) {
  .model-selector strong { max-width:170px; }
}
@media (max-width:680px) {
  .sidebar { position:fixed; z-index:1000; top:0; bottom:0; left:0; width:min(300px, 84vw); transform:translateX(-102%); opacity:1; }
  .app.sidebar-open-mobile .sidebar { transform:translateX(0); }
  .app.sidebar-open-mobile .sidebar-backdrop { display:block; }
  .app.sidebar-collapsed .sidebar { width:min(300px, 84vw); padding:10px 12px 12px; border-right:1px solid var(--line); opacity:1; pointer-events:auto; }
  #collapseButton { display:none; }
  #openSidebarButton.hidden { display:grid !important; }
  .chat-header { height:52px; padding:0 10px; }
  .messages, .composer-zone { padding-inline:14px; }
  .msg.user .bubble { max-width:88%; }
  .tool-pill { padding:0 9px; }
  .tool-pill em, .tool-pill .pill-label { display:none; }
  .details-panel { width:100vw; border-left:0; }
}
