:root { --bg:#f6f7f9; --panel:#fff; --ink:#1b1f24; --mute:#6b7280; --line:#e3e6ea; --accent:#2457c5; --user:#e8eefc; --tool:#f1f3f5; --err:#b42318; }
@media (prefers-color-scheme: dark) {
  :root { --bg:#0f1115; --panel:#171a20; --ink:#e6e8eb; --mute:#9aa3ad; --line:#2a2f37; --accent:#6c9bff; --user:#1f2a44; --tool:#1d2129; --err:#ff8a80; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.link { border: none; background: none; color: var(--mute); padding: 0; text-decoration: underline; }
#side { width: 260px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.side-head, .side-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.side-foot { border-bottom: none; border-top: 1px solid var(--line); font-weight: 400; color: var(--mute); font-size: 13px; }
#convs { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
#convs li { padding: 8px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; }
#convs li span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
#convs li.on { background: var(--user); }
#convs li button { visibility: hidden; border: none; background: none; padding: 0 4px; color: var(--mute); }
#convs li:hover button { visibility: visible; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#messages { flex: 1; overflow-y: auto; padding: 24px 16px; }
.msg { max-width: 860px; margin: 0 auto 18px; }
.msg.user .bubble { background: var(--user); border-radius: 12px; padding: 10px 14px; display: inline-block; white-space: pre-wrap; }
.msg.user { text-align: right; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.msg .meta { color: var(--mute); font-size: 12px; margin-top: 4px; }
.msg .err { color: var(--err); font-size: 13px; margin-top: 6px; }
.tools { margin: 6px 0; font-size: 13px; color: var(--mute); }
.tools details { background: var(--tool); border-radius: 8px; padding: 4px 10px; margin: 3px 0; }
.tools summary { cursor: pointer; list-style: none; }
.tools summary::before { content: "▸ "; }
.tools details[open] summary::before { content: "▾ "; }
.tools pre { margin: 6px 0 2px; white-space: pre-wrap; word-break: break-all; font-size: 12px; }
.tools .pending::after { content: " …"; }
.tools .bad { color: var(--err); }
.bubble p { margin: 0 0 10px; } .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--tool); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.bubble code { background: var(--tool); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.bubble th { background: var(--tool); }
.bubble ul, .bubble ol { margin: 4px 0 10px; padding-left: 22px; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15px; margin: 12px 0 6px; }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }
#compose { display: flex; gap: 10px; padding: 12px 16px 16px; border-top: 1px solid var(--line); background: var(--panel); max-width: 892px; width: 100%; margin: 0 auto; align-items: flex-end; }
#text { flex: 1; resize: none; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.compose-buttons { display: flex; gap: 6px; }
#send { background: var(--accent); color: #fff; border-color: var(--accent); }
body.login { align-items: center; justify-content: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 340px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { font-size: 18px; margin: 0 0 6px; }
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--mute); }
.card input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
.err { color: var(--err); font-size: 13px; margin: 0; }
.empty { color: var(--mute); text-align: center; margin-top: 20vh; }
@media (max-width: 720px) { #side { display: none; } }
