:root {
  --bg: #f6f5f1; --panel: #ffffff; --text: #1d1f1e; --muted: #6b706d; --line: #e2e0d9;
  --accent: #2f5d50; --accent-text: #ffffff; --user: #e6efe9; --code: #f0eee8; --error: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161817; --panel: #1f2221; --text: #e8eae8; --muted: #9aa19d; --line: #333836;
    --accent: #6fae99; --accent-text: #0f1211; --user: #24332d; --code: #2a2e2c; --error: #ff8a80; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
input, textarea, select { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; width: 100%; }
code { background: var(--code); border-radius: 4px; padding: 1px 4px; font-size: .9em; }
pre { background: var(--code); border-radius: 8px; padding: 10px; overflow-x: auto; }
pre code { padding: 0; background: none; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--error); }

.login { display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: grid; gap: 12px; text-align: center; }
.card h1 { margin: 0; font-size: 1.3rem; }
.card details { text-align: left; display: grid; gap: 8px; }
.card details > * + * { margin-top: 8px; }

.app { display: flex; height: 100dvh; overflow: hidden; }
#sidebar { width: 270px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 12px; gap: 10px; }
#convs { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#convs li { display: flex; gap: 4px; border-radius: 8px; }
#convs li.active { background: var(--user); }
#convs li button { border: 0; background: none; text-align: left; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 8px; }
#convs li .del { flex: none; color: var(--muted); }
.side-foot { display: flex; gap: 8px; }
.side-foot button { flex: 1; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
header h1 { flex: 1; font-size: 1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header select { width: auto; padding: 6px; }
#menu { display: none; }
#log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 760px; width: 100%; margin: 0 auto; overflow-wrap: anywhere; }
.msg.user .body { background: var(--user); border-radius: 12px; padding: 10px 14px; margin-left: auto; width: fit-content; max-width: 85%; }
.msg.pending .body:empty::after { content: "Working…"; color: var(--muted); }
.tools { display: grid; gap: 2px; margin-bottom: 4px; }
.tool { font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#composer { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); max-width: 792px; width: 100%; margin: 0 auto; }
#composer textarea { resize: none; max-height: 200px; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; width: min(440px, calc(100% - 32px)); }
dialog ul { padding-left: 18px; }
dialog > * + * { margin-top: 8px; display: block; }

@media (max-width: 760px) {
  #sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: min(80%, 320px); z-index: 2; transform: translateX(-105%); transition: transform .2s; }
  .menu-open #sidebar { transform: none; box-shadow: 0 0 40px #0006; }
  #menu { display: block; }
}
