:root {
  --bg:#212121; --bg-side:#171717; --bg-elev:#2f2f2f; --bg-hover:#383838; --bg-input:#2f2f2f;
  --text:#ececec; --text-dim:#a0a0a0; --border:#3a3a3a; --accent:#10a37f; --accent-hover:#0d8a6c;
  --code-bg:#111113; --code-header:#1f1f22; --error:#ff6b6b; --ok:#4ade80; --warn:#fbbf24;
  --scroll:#4a4a4a;
}
:root[data-theme="light"] {
  --bg:#ffffff; --bg-side:#f9f9f9; --bg-elev:#f4f4f4; --bg-hover:#ececec; --bg-input:#f4f4f4;
  --text:#0d0d0d; --text-dim:#65676b; --border:#e5e5e5; --accent:#10a37f; --accent-hover:#0d8a6c;
  --code-bg:#f6f8fa; --code-header:#eef0f2; --error:#d33; --ok:#15803d; --warn:#b45309;
  --scroll:#c9c9c9;
}
* { box-sizing:border-box; }
html,body { height:100%; }
body { margin:0; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif; background:var(--bg); color:var(--text); font-size:16px; line-height:1.6; }
#app { display:flex; height:100vh; overflow:hidden; }
/* ---------- Sidebar ---------- */
#sidebar { width:280px; min-width:280px; background:var(--bg-side); display:flex; flex-direction:column; border-right:1px solid var(--border); transition:margin-left .25s ease; }
#sidebar.collapsed { margin-left:-281px; }
.sidebar-head { display:flex; align-items:center; justify-content:space-between; padding:14px 14px 8px; }
.logo { font-weight:600; font-size:16px; display:flex; align-items:center; gap:8px; }
.new-chat-btn { margin:6px 14px 10px; padding:9px 12px; background:var(--bg-elev); color:var(--text); border:1px solid var(--border); border-radius:10px; cursor:pointer; font-size:14px; text-align:left; }
.new-chat-btn:hover { background:var(--bg-hover); }
#chat-list { flex:1; overflow-y:auto; padding:0 8px 8px; display:flex; flex-direction:column; gap:2px; }
.chat-item { display:flex; align-items:center; gap:6px; padding:8px 10px; border-radius:8px; cursor:pointer; font-size:14px; color:var(--text); border:1px solid transparent; }
.chat-item:hover { background:var(--bg-elev); }
.chat-item.active { background:var(--bg-elev); border-color:var(--border); }
.chat-item .ci-title { flex:1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.chat-item .ci-del { opacity:0; border:none; background:none; color:var(--text-dim); cursor:pointer; font-size:14px; padding:2px 4px; border-radius:6px; }
.chat-item:hover .ci-del { opacity:.8; }
.chat-item .ci-del:hover { color:var(--error); opacity:1; }
.sidebar-foot { padding:10px 14px 14px; border-top:1px solid var(--border); font-size:12px; color:var(--text-dim); }
.model-name { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-bottom:4px; }
.server-status { display:flex; align-items:center; gap:6px; }
.server-status .dot { width:8px; height:8px; border-radius:50%; background:var(--text-dim); display:inline-block; }
.server-status.on .dot { background:var(--ok); }
.server-status.off .dot { background:var(--error); }
.theme-btn { margin-top:8px; width:100%; padding:6px; background:var(--bg-elev); border:1px solid var(--border); color:var(--text); border-radius:8px; cursor:pointer; font-size:13px; }
.theme-btn:hover { background:var(--bg-hover); }
/* ---------- Main ---------- */
.main { flex:1; display:flex; flex-direction:column; min-width:0; position:relative; }
.topbar { display:flex; align-items:center; gap:10px; padding:10px 16px; border-bottom:1px solid var(--border); min-height:56px; }
.topbar h1 { font-size:15px; font-weight:600; flex:1; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin:0; }
#toggle-sidebar { display:none; border:none; background:none; color:var(--text); font-size:20px; cursor:pointer; padding:4px 8px; border-radius:8px; }
#toggle-sidebar:hover { background:var(--bg-elev); }
.stat { font-size:12px; color:var(--text-dim); white-space:nowrap; }
/* ---------- Messages ---------- */
#messages { flex:1; overflow-y:auto; scroll-behavior:smooth; }
.msg-wrap { max-width:780px; margin:0 auto; padding:18px 16px 6px; display:flex; gap:14px; }
.msg-wrap.user { justify-content:flex-end; }
.avatar { flex:0 0 30px; width:30px; height:30px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:16px; background:var(--bg-elev); border:1px solid var(--border); margin-top:2px; user-select:none; }
.msg-col { display:flex; flex-direction:column; min-width:0; max-width:100%; }
.msg-wrap.user .msg-col { align-items:flex-end; max-width:80%; }
.msg-meta { font-size:13px; font-weight:600; margin-bottom:2px; color:var(--text); }
.bubble { background:var(--bg-elev); padding:10px 16px; border-radius:18px; overflow-wrap:break-word; white-space:pre-wrap; font-size:15.5px; }
.msg-body { white-space:pre-wrap; overflow-wrap:break-word; font-size:15.5px; min-width:0; }
.msg-body > *:first-child { margin-top:0; }
.msg-body > *:last-child { margin-bottom:0; }
.msg-body p { margin:0 0 12px; }
.msg-body h1,.msg-body h2,.msg-body h3 { margin:18px 0 8px; line-height:1.3; }
.msg-body h1 { font-size:1.4em; } .msg-body h2 { font-size:1.25em; } .msg-body h3 { font-size:1.1em; }
.msg-body ul,.msg-body ol { margin:0 0 12px; padding-left:24px; }
.msg-body li { margin:4px 0; }
.msg-body blockquote { margin:0 0 12px; padding:4px 14px; border-left:3px solid var(--accent); color:var(--text-dim); background:var(--bg-elev); border-radius:0 8px 8px 0; }
.msg-body a { color:var(--accent); }
.msg-body table { border-collapse:collapse; margin:0 0 12px; display:block; overflow-x:auto; max-width:100%; }
.msg-body th,.msg-body td { border:1px solid var(--border); padding:6px 12px; text-align:left; }
.msg-body th { background:var(--bg-elev); }
.msg-body hr { border:none; border-top:1px solid var(--border); margin:16px 0; }
.inline-code { font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:.88em; background:var(--bg-elev); border:1px solid var(--border); padding:1.5px 6px; border-radius:6px; }
.codeblock { margin:12px 0; border:1px solid var(--border); border-radius:10px; overflow:hidden; background:var(--code-bg); }
.codeblock-head { display:flex; align-items:center; justify-content:space-between; padding:6px 12px; background:var(--code-header); font-size:12px; color:var(--text-dim); }
.copy-btn { border:none; background:none; color:var(--text-dim); cursor:pointer; font-size:12px; padding:3px 8px; border-radius:6px; }
.copy-btn:hover { background:var(--bg-hover); color:var(--text); }
.codeblock pre { margin:0; padding:12px 14px; overflow-x:auto; font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace; font-size:13.5px; line-height:1.55; }
.codeblock code { font-family:inherit; }
.reasoning { margin:0 0 10px; border:1px solid var(--border); border-radius:10px; background:var(--bg-elev); }
.reasoning summary { cursor:pointer; padding:8px 14px; font-size:13px; color:var(--text-dim); user-select:none; list-style:none; display:flex; align-items:center; gap:8px; }
.reasoning summary::-webkit-details-marker { display:none; }
.reasoning summary::before { content:"\25B8 "; transition:transform .15s; font-size:11px; }
.reasoning[open] summary::before { transform:rotate(90deg); }
.reasoning-body { padding:2px 14px 10px; font-size:14px; color:var(--text-dim); white-space:pre-wrap; overflow-wrap:break-word; border-top:1px solid var(--border); }
.err-box { margin:12px 0; padding:10px 14px; border-radius:10px; background:rgba(255,107,107,.12); border:1px solid var(--error); color:var(--error); font-size:14px; }
.cursor { display:inline-block; width:9px; height:18px; background:var(--text); margin-left:2px; vertical-align:text-bottom; animation:blink 1s steps(1) infinite; border-radius:2px; }
@keyframes blink { 50% { opacity:0; } }
.msg-actions { display:flex; gap:4px; margin-top:6px; opacity:0; transition:opacity .15s; }
.msg-wrap:hover .msg-actions { opacity:1; }
.act-btn { border:none; background:none; color:var(--text-dim); cursor:pointer; font-size:13px; padding:4px 8px; border-radius:6px; }
.act-btn:hover { background:var(--bg-elev); color:var(--text); }
/* ---------- Empty state ---------- */
.empty-state { position:absolute; inset:56px 0 auto 0; height:calc(100% - 56px - 130px); display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px; pointer-events:none; }
.empty-state.hidden { display:none; }
.empty-logo { font-size:52px; }
.empty-state h2 { margin:0; font-weight:600; font-size:26px; }
.suggestions { display:flex; flex-wrap:wrap; gap:10px; justify-content:center; max-width:640px; padding:16px; pointer-events:auto; }
.suggestion { padding:10px 16px; border:1px solid var(--border); background:var(--bg-elev); color:var(--text); border-radius:20px; cursor:pointer; font-size:14px; }
.suggestion:hover { background:var(--bg-hover); }
/* ---------- Composer ---------- */
#composer { padding:8px 16px 14px; }
.composer-row { max-width:780px; margin:0 auto; display:flex; align-items:flex-end; gap:10px; background:var(--bg-input); border:1px solid var(--border); border-radius:24px; padding:10px 10px 10px 18px; }
.composer-row:focus-within { border-color:var(--text-dim); }
#input { flex:1; border:none; outline:none; resize:none; background:transparent; color:var(--text); font-family:inherit; font-size:15.5px; line-height:1.5; max-height:200px; padding:4px 0; }
#input::placeholder { color:var(--text-dim); }
.send-btn { flex:0 0 36px; width:36px; height:36px; border-radius:50%; border:none; background:var(--accent); color:#fff; cursor:pointer; font-size:16px; display:flex; align-items:center; justify-content:center; }
.send-btn:hover { background:var(--accent-hover); }
.send-btn:disabled { background:var(--bg-hover); color:var(--text-dim); cursor:default; }
.send-btn.stop { background:var(--bg-hover); color:var(--text); border:1px solid var(--border); }
.composer-foot { max-width:780px; margin:8px auto 0; display:flex; justify-content:space-between; gap:10px; font-size:12px; color:var(--text-dim); }
.disclaimer { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
/* ---------- Toast ---------- */
.toast { position:fixed; left:50%; bottom:24px; transform:translateX(-50%) translateY(80px); background:var(--bg-elev); color:var(--text); border:1px solid var(--border); padding:10px 18px; border-radius:10px; font-size:14px; opacity:0; transition:all .25s; z-index:100; pointer-events:none; }
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); }
/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width:10px; height:10px; }
::-webkit-scrollbar-thumb { background:var(--scroll); border-radius:6px; border:2px solid transparent; background-clip:content-box; }
::-webkit-scrollbar-track { background:transparent; }
/* ---------- Mobile ---------- */
@media (max-width: 780px) {
  #sidebar { position:fixed; z-index:50; height:100vh; box-shadow:4px 0 24px rgba(0,0,0,.4); }
  #sidebar.collapsed { margin-left:-281px; }
  #toggle-sidebar { display:block; }
  .msg-wrap { gap:8px; padding:12px 10px 4px; }
  .msg-wrap.user .msg-col { max-width:88%; }
  .msg-actions { opacity:1; }
  .empty-state h2 { font-size:21px; }
}
