:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --side: #1f1d1a;
  --side-fg: #e9e6df;
  --side-muted: #9a958b;
  --fg: #1f1d1a;
  --muted: #6b665c;
  --line: #e2ded5;
  --accent: #c2410c;
  --accent-fg: #ffffff;
  --user: #fff3ea;
  --tool: #8a8478;
  --code: #f0eee8;
  --err: #b91c1c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --panel: #1f1d1a;
    --side: #11100e;
    --fg: #ece9e2;
    --muted: #a39e93;
    --line: #34312c;
    --user: #2b221c;
    --tool: #8f897d;
    --code: #2a2824;
    --err: #f87171;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; cursor: pointer; }
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--fg); border-radius: 8px; padding: 6px 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.icon { display: none; padding: 4px 10px; }
.link { background: none; border: 0; color: var(--side-muted); padding: 0; text-decoration: underline; }

.layout { display: flex; height: 100%; }
.side { width: 270px; flex: none; background: var(--side); color: var(--side-fg); display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.side-head .btn { background: transparent; color: var(--side-fg); border-color: #3a3631; }
.brand { font-weight: 700; letter-spacing: .02em; font-size: 18px; }
.convs { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.convs li { display: flex; align-items: center; border-radius: 8px; }
.convs li.active, .convs li:hover { background: #2e2b27; }
.convs a { flex: 1; color: var(--side-fg); text-decoration: none; padding: 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.convs .del { background: none; border: 0; color: var(--side-muted); padding: 4px 8px; visibility: hidden; }
.convs li:hover .del, .convs li.active .del { visibility: visible; }
.logout { padding: 12px 14px; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head h1 { font-size: 16px; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.model select { font: inherit; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); }

.log { flex: 1; overflow-y: auto; padding: 20px; }
.empty { max-width: 640px; margin: 12vh auto 0; text-align: center; color: var(--muted); }
.empty .hint { font-size: 13px; }
.msg { max-width: 820px; margin: 0 auto 16px; padding: 12px 16px; border-radius: 12px; overflow-wrap: anywhere; }
.msg.user { background: var(--user); white-space: pre-wrap; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); }
.msg .tools { font-size: 12px; color: var(--tool); margin-bottom: 6px; }
.msg .tools div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; }
.msg .error { color: var(--err); font-size: 13px; margin-top: 6px; }
.msg.pending .body:empty::after { content: "…"; color: var(--muted); }
.msg p { margin: .4em 0; }
.msg ul, .msg ol { margin: .4em 0; padding-left: 1.4em; }
.msg h1, .msg h2, .msg h3, .msg h4 { font-size: 1.05em; margin: .8em 0 .3em; }
.msg a { color: var(--accent); }
.msg code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: .92em; }
.msg pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg pre code { background: none; padding: 0; }
.msg table { border-collapse: collapse; margin: .5em 0; font-size: .94em; display: block; overflow-x: auto; }
.msg th, .msg td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.msg blockquote { border-left: 3px solid var(--line); margin: .4em 0; padding-left: 10px; color: var(--muted); }

.ask { display: flex; gap: 10px; padding: 12px 20px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.ask textarea { flex: 1; resize: none; font: inherit; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); max-height: 40vh; }

body.login { display: flex; align-items: center; justify-content: center; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(360px, calc(100% - 32px)); }
.login-box h1 { margin: 0; }
.login-box .sub { color: var(--muted); margin: 2px 0 18px; }
.login-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.login-box input { width: 100%; font: inherit; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
.login-box button { margin-top: 14px; width: 100%; padding: 9px; border-radius: 8px; border: 0; background: var(--accent); color: var(--accent-fg); }
.err { color: var(--err); }

@media (max-width: 760px) {
  .btn.icon { display: inline-block; }
  .side { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .log { padding: 12px 16px; }
  .ask, .chat-head { padding-left: 16px; padding-right: 16px; }
}
