:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e3e6eb;
  --text: #1d2330;
  --muted: #6b7380;
  --accent: #c2622d;
  --accent-soft: #fbeee6;
  --ok: #2f8f5b;
  --warn: #c48a16;
  --bad: #c43d3d;
  --code: #f2f4f7;
  --user: #e9eefc;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --panel: #1d2027;
    --line: #2d313b;
    --text: #e6e8ec;
    --muted: #9aa2ae;
    --accent: #e08a55;
    --accent-soft: #3a2a20;
    --code: #252933;
    --user: #26304a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 6px 12px; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.danger-outline { color: var(--bad); border-color: var(--bad); }
button.link { border: none; background: none; color: var(--accent); padding: 0 6px; }
button.block { width: 100%; }
button.icon { border: none; background: none; font-size: 18px; padding: 4px 8px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; }
textarea { resize: vertical; min-height: 44px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 160px; }
.muted { color: var(--muted); }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); margin: 2px 4px 2px 0; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }

.app { display: grid; grid-template-columns: 290px 1fr; height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column;
  padding: 12px; gap: 10px; min-height: 0; }
.brand .host { font-weight: 600; font-size: 16px; }
.conn { font-size: 12px; }
.conn.ok { color: var(--ok); } .conn.warn { color: var(--warn); } .conn.bad { color: var(--bad); }
.sessions { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.session-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.session-item:hover { background: var(--bg); }
.session-item.on { background: var(--accent-soft); border-color: var(--accent); }
.si-top { display: flex; justify-content: space-between; gap: 6px; }
.si-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-cwd, .si-preview { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.status.running { color: var(--ok); } .status.waiting { color: #fff; background: var(--warn); }
.status.error { color: #fff; background: var(--bad); }
.status.small { font-size: 11px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: none; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
.welcome { margin: auto; text-align: center; color: var(--muted); }
.session { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.session-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.session-title { min-width: 0; }
.session-title .title { font-weight: 600; }
.session-title .cwd { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-actions { display: flex; gap: 8px; align-items: center; }
.timeline { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.timeline > * { max-width: 920px; width: 100%; margin-left: auto; margin-right: auto; }
.empty-hint { color: var(--muted); text-align: center; padding: 20px; font-size: 13px; }
.more { align-self: center; width: auto; }

.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user); padding: 8px 12px; border-radius: 12px 12px 2px 12px; white-space: pre-wrap;
  max-width: 85%; word-break: break-word; }
.msg.user.sending .bubble { opacity: .6; }
.msg.user.failed .bubble { border: 1px solid var(--bad); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg.assistant { line-height: 1.7; word-break: break-word; }
.msg.assistant .plain { white-space: pre-wrap; }
.msg.live { opacity: .9; }
.md p { margin: .4em 0; }
.md pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md code { background: var(--code); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md pre code { padding: 0; background: none; }
.md table { border-collapse: collapse; } .md td, .md th { border: 1px solid var(--line); padding: 4px 8px; }
.md a { color: var(--accent); }
.thinking { color: var(--muted); font-size: 13px; }
.thinking.live, .thinking-text { white-space: pre-wrap; border-left: 3px solid var(--line); padding-left: 10px; }
.typing { color: var(--muted); font-size: 13px; }
.result-line { font-size: 12px; color: var(--muted); text-align: center; }
.result-line.err { color: var(--bad); }
.notice { font-size: 13px; padding: 6px 10px; border-radius: 8px; background: var(--bg); }
.notice.warn { color: var(--warn); } .notice.error { color: var(--bad); }

.tool { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.tool summary { display: flex; gap: 8px; align-items: center; padding: 6px 10px; cursor: pointer; font-size: 13px; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool-name { font-weight: 600; color: var(--accent); white-space: nowrap; }
.tool-sum { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; font-family: Consolas, monospace; font-size: 12px; }
.tool-state { font-size: 12px; color: var(--muted); }
.tool.error .tool-state { color: var(--bad); }
.tool-body { padding: 0 10px 10px; }
.code { background: var(--code); padding: 8px 10px; border-radius: 8px; overflow-x: auto; font: 12px/1.5 Consolas, "Cascadia Mono", monospace;
  white-space: pre-wrap; word-break: break-all; max-height: 420px; overflow-y: auto; margin: 6px 0; }
.code.del { border-left: 3px solid var(--bad); } .code.add { border-left: 3px solid var(--ok); }
.code.result.err { color: var(--bad); }
.kv { font-size: 12px; color: var(--muted); }
.sub { border-left: 2px solid var(--line); padding-left: 8px; margin: 6px 0; font-size: 12px; color: var(--muted); }
.sub-text { white-space: pre-wrap; }
.todos { margin: 4px 0; padding-left: 4px; list-style: none; font-size: 13px; }
.todo.completed { color: var(--muted); text-decoration: line-through; }

.perm { border-radius: var(--radius); padding: 10px 12px; }
.perm.open { border: 2px solid var(--warn); background: var(--panel); }
.perm.done { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); padding: 4px 10px; background: var(--bg); }
.perm.done.deny .perm-result, .perm.done.cancelled .perm-result { color: var(--bad); }
.perm.done.allow .perm-result, .perm.done.allow-always .perm-result { color: var(--ok); }
.perm-head { font-weight: 600; margin-bottom: 6px; }
.perm-tool { font-weight: 600; }
.perm-reason { font-size: 12px; color: var(--muted); }
.ask-q { margin-bottom: 10px; }
.ask-title { font-weight: 500; margin-bottom: 6px; }
.ask-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { display: flex; flex-direction: column; align-items: flex-start; text-align: left; max-width: 260px; }
.opt small { color: var(--muted); font-size: 12px; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.ask-other { margin-top: 6px; width: 100%; }

.composer { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; }
.composer .send { align-self: flex-end; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 12px; }
.modal { background: var(--panel); border-radius: 12px; padding: 18px; width: 560px; max-width: 100%; max-height: 90vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; }
.modal h3 { margin: 0 0 6px; }
.modal label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.recent { display: flex; flex-wrap: wrap; }
.browser { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.browser-cur { font-family: Consolas, monospace; font-size: 12px; }
.browser-list { max-height: 260px; overflow-y: auto; border-top: 1px solid var(--line); }
.dir { padding: 4px 6px; cursor: pointer; border-radius: 6px; font-size: 13px; }
.dir:hover { background: var(--bg); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel);
  padding: 8px 14px; border-radius: 8px; z-index: 20; max-width: 90vw; cursor: pointer; }
.toast.error { background: var(--bad); color: #fff; }

.pair { max-width: 520px; margin: 10vh auto; background: var(--panel); border-radius: 14px; padding: 24px; border: 1px solid var(--line); }
.pair h2 { margin-top: 0; }
.pair .code-big { font: 600 28px/1.2 Consolas, monospace; letter-spacing: 4px; text-align: center; padding: 10px; background: var(--code); border-radius: 8px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 5; transform: translateX(-102%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .app.drawer-open .sidebar { transform: none; }
  .topbar { display: flex; }
  .timeline { padding: 10px; }
  .session-head { padding: 8px 10px; }
  .composer { padding: 8px; }
}
.forget { font-size: 12px; color: var(--muted); align-self: flex-start; }
@media (max-width: 760px) { .session-title .title { display: none; } }
