:root {
  --bg: #faf9f6; --panel: #f1efe9; --text: #24231f; --muted: #6f6c63; --line: #dedbd2;
  --accent: #2f5d50; --accent-text: #ffffff; --user: #e9e6dc; --code: #efede6; --error: #a8321f;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1d1b; --panel: #262624; --text: #ecebe6; --muted: #a09d94; --line: #3b3a36;
    --accent: #6fae9b; --accent-text: #10201b; --user: #33332f; --code: #2c2c29; --error: #ef8a78;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.65 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
.hidden { display: none !important; }
button, select, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: transparent; border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { background: var(--panel); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { opacity: .9; }
button:disabled { opacity: .5; cursor: default; }
button.link { border: 0; color: var(--muted); padding: 4px 0; text-align: left; }
button.icon { padding: 2px 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.login {
  max-width: 340px; margin: 0 auto; padding: 18vh 16px 0;
  display: flex; flex-direction: column; gap: 10px;
}
.login h1 { font-size: 22px; margin: 0 0 8px; }
.login input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.error { color: var(--error); margin: 0; min-height: 1.4em; }

.app { display: flex; height: 100dvh; }
.sidebar {
  width: 260px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0;
}
.app.no-sidebar .sidebar { display: none; }
.conversations { flex: 1; overflow-y: auto; min-height: 0; }
.conv { display: flex; align-items: center; border-radius: 8px; }
.conv:hover, .conv.active { background: var(--line); }
.conv-open {
  flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 6px 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-open:hover { background: none; }
.conv-del { border: 0; background: none; color: var(--muted); padding: 2px 8px; }
.conv-del:hover { background: none; color: var(--error); }
.outbox { border-top: 1px solid var(--line); padding-top: 8px; max-height: 30%; overflow-y: auto; }
.outbox h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
.outbox a { display: block; color: var(--accent); font-size: 13px; overflow-wrap: anywhere; padding: 2px 0; }
.outbox .empty { color: var(--muted); font-size: 13px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model { color: var(--muted); font-size: 13px; white-space: nowrap; }
.model select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; }

.messages { flex: 1; overflow-y: auto; padding: 20px 16px; }
.msg { max-width: 800px; margin: 0 auto 18px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); border-radius: 12px; padding: 8px 14px; white-space: pre-wrap; width: fit-content; max-width: 100%; margin-left: auto; }
.msg .files { color: var(--muted); font-size: 13px; text-align: right; }
.msg.assistant .content > :first-child { margin-top: 0; }
.msg.assistant .content > :last-child { margin-bottom: 0; }
.msg .error { margin-top: 8px; white-space: pre-wrap; }
.msg .working { color: var(--muted); font-size: 13px; }
.tools { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.tools summary { cursor: pointer; }
.tools div { padding-left: 14px; overflow-wrap: anywhere; }
.content pre { background: var(--code); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.content code { background: var(--code); padding: 1px 4px; border-radius: 4px; font: 13px/1.5 Consolas, "Cascadia Mono", monospace; }
.content pre code { background: none; padding: 0; }
.content table { border-collapse: collapse; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--line); padding: 4px 10px; }
.content a { color: var(--accent); }
.empty-state { color: var(--muted); text-align: center; margin-top: 18vh; }

.composer { border-top: 1px solid var(--line); padding: 10px 16px 12px; }
.composer textarea, .composer-actions, .attachments { display: block; max-width: 800px; margin: 0 auto; width: 100%; }
.composer textarea {
  resize: vertical; min-height: 56px; max-height: 40vh; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.composer-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.hint { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments:not(:empty) { margin-bottom: 6px; }
.chip { font-size: 13px; background: var(--user); border-radius: 6px; padding: 1px 4px 1px 8px; }
.chip button { border: 0; background: none; padding: 0 4px; color: var(--muted); }

@media (max-width: 700px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 2; width: min(280px, 85vw); box-shadow: 2px 0 12px rgba(0,0,0,.25); }
}
