:root {
  --bg: #f6f7f5; --panel: #ffffff; --side: #eef1ee; --text: #1b2420; --muted: #66726c;
  --line: #dde3df; --accent: #1f6f5c; --accent-text: #ffffff; --user: #e3efe9; --tool: #f3efe2;
  --err: #b3261e; --ok: #2e7d32; --warn: #b26a00;
  --radius: 12px; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615; --panel: #1a1f1d; --side: #161b19; --text: #e4ebe7; --muted: #94a19a;
    --line: #2a322e; --accent: #4fb69a; --accent-text: #0d1311; --user: #1f2b26; --tool: #2a2618;
    --err: #ff8a80; --ok: #81c784; --warn: #ffb74d; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: 0; background: none; color: var(--muted); padding: 4px 0; }
button:disabled { opacity: .5; cursor: default; }
input, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .pad { padding: 0 16px; }
.err { color: var(--err); min-height: 1.5em; margin: 0; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); padding: 28px; border-radius: var(--radius); box-shadow: var(--shadow); width: min(360px, 100%);
  display: grid; gap: 12px; justify-items: center; border: 1px solid var(--line); }
.card h1 { font-size: 20px; margin: 0; }

.app { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 12px; } .side-head button { width: 100%; }
.tabs { display: flex; gap: 4px; padding: 0 12px 8px; }
.tab { flex: 1; padding: 6px 4px; font-size: 13px; background: transparent; }
.tab.active { background: var(--panel); border-color: var(--accent); }
.conv-list { list-style: none; margin: 0; padding: 0 8px; overflow: auto; flex: 1; }
.conv-list li { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.conv-list li:hover { background: var(--panel); }
.conv-list li.active { background: var(--panel); box-shadow: inset 3px 0 0 var(--accent); }
.conv-list .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list .x { visibility: hidden; border: 0; background: none; color: var(--muted); padding: 0 4px; }
.conv-list li:hover .x { visibility: visible; }
.side-foot { margin-top: auto; padding: 10px 12px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.nodes { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.busy { background: var(--warn); } .dot.down { background: var(--err); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.top h2 { font-size: 16px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { display: none; border: 0; background: none; font-size: 20px; padding: 2px 6px; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: auto; }
#view-chat { overflow: hidden; }

.messages { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: min(760px, 92%); padding: 10px 14px; border-radius: var(--radius); background: var(--panel);
  border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); border-color: transparent; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; }
.msg p { margin: 0 0 .6em; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: .2em 0 .6em; padding-left: 1.3em; }
.msg code { background: var(--side); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.msg pre { background: var(--side); padding: 8px; border-radius: 8px; overflow: auto; }
.meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.tool { align-self: flex-start; font-size: 13px; background: var(--tool); border-radius: 8px; padding: 4px 10px; color: var(--muted); max-width: 92%; }
.status-line { align-self: flex-start; font-size: 13px; color: var(--muted); }
.status-line::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; }

.composer { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { resize: none; max-height: 200px; }
.composer button { min-width: 48px; }

.toolbar { display: flex; gap: 8px; padding: 12px 16px 0; }
.toolbar button { white-space: nowrap; }
.list { list-style: none; margin: 0; padding: 12px 16px; display: grid; gap: 8px; }
.list li { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; }
.list .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .sub { font-size: 12px; color: var(--muted); }
.list .acts { display: flex; gap: 4px; }
.list .acts button { padding: 2px 8px; font-size: 13px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--side); color: var(--muted); margin-right: 6px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 24px rgba(0,0,0,.25); }
  .side.open { transform: none; }
  .icon-btn { display: block; }
  .toolbar { flex-wrap: wrap; }
}
