:root {
  --bg: #262624;
  --bg2: #1f1e1d;
  --panel: #30302e;
  --line: #3e3d3a;
  --text: #ece9e3;
  --muted: #9c9a94;
  --dim: #6f6d68;
  --accent: #d97757;
  --accent2: #c4653f;
  --user: #3a3936;
  --code: #1a1a19;
  --green: #7fbf7f;
  --red: #e77d7d;
  --yellow: #e0b25c;
  --blue: #7aa7e0;
  --add-bg: rgba(87, 171, 90, .16);
  --del-bg: rgba(229, 83, 75, .16);
  --mono: "JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --side-w: 290px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.grow { flex: 1; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- вход ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 10px; }
.login-card label { font-size: 13px; color: var(--muted); display: block; margin: 8px 0 4px; }
.login-card input { width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card #code { font: 22px var(--mono); letter-spacing: 6px; text-align: center; }
button.primary { width: 100%; margin-top: 12px; padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent2); }
button.primary:disabled { opacity: .6; }
button.link { background: none; border: 0; color: var(--muted); margin-top: 6px; text-decoration: underline; }
.login-msg { min-height: 20px; font-size: 14px; color: var(--muted); }
.login-msg.bad { color: var(--red); }

/* ---------- раскладка ---------- */
#app { display: flex; height: 100%; height: 100dvh; }
#side { width: var(--side-w); flex: none; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#scrim { display: none; }
.brand { font-weight: 600; font-size: 16px; display: flex; align-items: baseline; gap: 6px; padding: 4px 4px 10px; }
.brand.big { font-size: 22px; padding: 0 0 4px; }
.brand .star { color: var(--accent); }
.brand-sub { font-weight: 400; font-size: 12px; color: var(--dim); }
.side-top { padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.side-btn { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); text-align: left; }
.side-btn:hover { border-color: var(--accent); }
.side-search { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); outline: none; font-size: 13px; }
.side-search:focus { border-color: var(--accent); }
.projects { flex: 1; overflow-y: auto; padding: 4px 6px 12px; }
.proj { margin-bottom: 2px; }
.proj-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px; user-select: none; }
.proj-head:hover { background: var(--panel); color: var(--text); }
.proj-head .caret { width: 10px; font-size: 10px; transition: transform .15s; }
.proj.open .proj-head .caret { transform: rotate(90deg); }
.proj-head .pname { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-head .branch { font: 11px var(--mono); color: var(--dim); }
.proj-head .add { margin-left: auto; opacity: 0; border: 0; background: none; color: var(--muted); padding: 0 4px; }
.proj-head:hover .add { opacity: 1; }
.sess-list { display: none; padding-left: 10px; }
.proj.open .sess-list { display: block; }
.sess { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
.sess:hover { background: var(--panel); }
.sess.active { background: var(--user); }
.sess .stitle { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess .stime { font-size: 11px; color: var(--dim); flex: none; }
.sess .sdot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: transparent; }
.sess .sdot.alive { background: var(--dim); }
.sess .sdot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
.sess .sdot.pending { background: var(--yellow); animation: pulse .8s infinite; }
.sess .smenu { opacity: 0; border: 0; background: none; color: var(--muted); padding: 0 2px; }
.sess:hover .smenu { opacity: 1; }
.sess-empty { font-size: 12px; color: var(--dim); padding: 4px 8px; }
.side-foot { display: flex; gap: 4px; padding: 8px 10px; border-top: 1px solid var(--line); }
.side-link { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.side-link:hover { color: var(--text); background: var(--panel); }
.side-link.on { color: var(--accent); }

#top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 52px; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 8px; color: var(--muted); font-size: 16px; }
.icon-btn:hover { border-color: var(--line); color: var(--text); }
.top-titles { min-width: 0; flex: 1; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; }
.path { font: 12px var(--mono); color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- лента ---------- */
.feed { flex: 1; overflow-y: auto; padding: 18px 0 24px; scroll-behavior: auto; }
.feed > * { max-width: 860px; margin-left: auto; margin-right: auto; padding-left: 20px; padding-right: 20px; }
.empty { color: var(--muted); text-align: center; margin-top: 18vh; }
.empty .star { color: var(--accent); font-size: 34px; display: block; margin-bottom: 8px; }
.msg-user { display: flex; justify-content: flex-end; margin: 14px auto; }
.msg-user .bubble { background: var(--user); border-radius: 14px; padding: 9px 14px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg-user.pending .bubble { opacity: .6; }
.msg-ai { margin: 8px auto; }
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .55em 0; }
.md ul, .md ol { padding-left: 1.4em; margin: .4em 0; }
.md li { margin: .15em 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 1em 0 .4em; line-height: 1.3; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.08em; }
.md code { font: .88em var(--mono); background: var(--code); padding: .1em .35em; border-radius: 4px; }
.md pre { position: relative; background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: .6em 0; }
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.md table { border-collapse: collapse; margin: .6em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 10px; text-align: left; }
.md th { background: var(--panel); }
.md blockquote { border-left: 3px solid var(--line); margin: .5em 0; padding: 0 12px; color: var(--muted); }
.md a { color: var(--accent); }
.copy-btn { position: absolute; top: 6px; right: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 5px; font-size: 11px; padding: 1px 6px; opacity: 0; }
.md pre:hover .copy-btn { opacity: 1; }
.streaming { white-space: pre-wrap; }

/* карточки инструментов */
.tool { margin: 6px auto; font: 13px/1.5 var(--mono); }
.tool-head { display: flex; align-items: baseline; gap: 8px; cursor: pointer; padding: 2px 0; }
.tool-head .tdot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; transform: translateY(-1px); }
.tool.run .tdot { background: var(--accent); animation: pulse 1s infinite; }
.tool.ok .tdot { background: var(--green); }
.tool.err .tdot { background: var(--red); }
.tool.ask .tdot { background: var(--yellow); }
.tool-head .tname { font-weight: 700; color: var(--text); }
.tool-head .targ { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.tool-head .tmeta { color: var(--dim); flex: none; }
.tool-head .tmeta .plus { color: var(--green); } .tool-head .tmeta .minus { color: var(--red); }
.tool-body { margin: 4px 0 6px 16px; border-left: 2px solid var(--line); padding-left: 12px; }
.tool.collapsed .tool-body { display: none; }
.tool-sum { color: var(--dim); margin-left: 16px; }
.tool-sum::before { content: "⎿  "; }
.tool pre { margin: 4px 0; white-space: pre-wrap; word-break: break-word; max-height: 420px; overflow: auto; background: var(--code); border-radius: 6px; padding: 8px 10px; }
.tool .err-text { color: var(--red); }
.tool .sub { color: var(--muted); }
.diff { background: var(--code); border-radius: 6px; padding: 6px 0; overflow-x: auto; max-height: 520px; overflow-y: auto; }
.diff div { white-space: pre; padding: 0 10px; min-height: 1.5em; }
.diff .a { background: var(--add-bg); } .diff .a::before { content: "+ "; color: var(--green); }
.diff .d { background: var(--del-bg); } .diff .d::before { content: "- "; color: var(--red); }
.diff .c::before { content: "  "; }
.diff .gap { color: var(--dim); }
.todo { list-style: none; padding: 0; margin: 2px 0; }
.todo li::before { content: "☐ "; color: var(--dim); }
.todo li.done { color: var(--dim); text-decoration: line-through; } .todo li.done::before { content: "☑ "; color: var(--green); }
.todo li.doing { color: var(--accent); } .todo li.doing::before { content: "◐ "; }

/* разрешения, вопросы, план */
.ask-card { margin: 10px auto; }
.ask-inner { border: 1px solid var(--accent); border-radius: 10px; background: var(--panel); padding: 12px 14px; }
.ask-card.done .ask-inner { border-color: var(--line); opacity: .75; }
.ask-title { font-weight: 600; margin-bottom: 6px; }
.ask-title .tname { font-family: var(--mono); color: var(--accent); }
.ask-desc { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.ask-card pre { font: 13px var(--mono); background: var(--code); border-radius: 6px; padding: 8px 10px; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; margin: 6px 0; }
.ask-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.ask-btns button { border: 1px solid var(--line); background: var(--bg2); border-radius: 7px; padding: 6px 12px; }
.ask-btns button:hover { border-color: var(--accent); }
.ask-btns button.yes { background: var(--accent); border-color: var(--accent); color: #fff; }
.ask-btns button.yes:hover { background: var(--accent2); }
.ask-btns button.no:hover { border-color: var(--red); color: var(--red); }
.ask-card textarea { width: 100%; margin-top: 8px; background: var(--bg2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; resize: vertical; min-height: 34px; }
.ask-done { color: var(--muted); font-size: 13px; margin-top: 6px; }
.q-block { margin: 8px 0 12px; }
.q-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.q-text { font-weight: 600; margin: 2px 0 6px; }
.q-opt { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--bg2); border-radius: 8px; padding: 7px 10px; margin: 4px 0; }
.q-opt:hover { border-color: var(--accent); }
.q-opt.sel { border-color: var(--accent); background: rgba(217, 119, 87, .15); }
.q-opt small { display: block; color: var(--muted); }
.q-other { width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; margin-top: 4px; }

.note { margin: 8px auto; font-size: 13px; color: var(--muted); }
.note.warn { color: var(--yellow); } .note.error { color: var(--red); white-space: pre-wrap; font-family: var(--mono); font-size: 12px; }
.turn-end { margin: 2px auto 14px; font-size: 12px; color: var(--dim); }
.working { margin: 8px auto; color: var(--accent); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.working .spin { display: inline-block; animation: spin 2.4s linear infinite; }
.working .wtime { color: var(--dim); }

/* ---------- ввод ---------- */
#composer { padding: 10px 16px 6px; max-width: 900px; width: 100%; margin: 0 auto; }
#composer textarea { width: 100%; resize: none; max-height: 40vh; min-height: 52px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); outline: none; line-height: 1.45; }
#composer textarea:focus { border-color: #5b5a56; }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.chip { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; color: var(--muted); }
.chip:hover { color: var(--text); border-color: #5b5a56; }
select.chip { appearance: none; background: var(--bg); padding-right: 12px; }
#modeBtn.plan { color: #8fb3ff; border-color: #4a5f8a; }
#modeBtn.acceptEdits { color: #c49be8; border-color: #6a4f86; }
#modeBtn.bypassPermissions { color: var(--red); border-color: #8a4a4a; }
.send { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 15px; }
.send:hover { background: var(--accent2); }
.send.stop { background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.send.stop::before { content: "■"; }
.send.stop { font-size: 0; } .send.stop::before { font-size: 14px; }
.hint { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; font-size: 13px; max-height: 220px; overflow-y: auto; }
.hint div { padding: 4px 10px; cursor: pointer; display: flex; gap: 10px; }
.hint div.sel, .hint div:hover { background: var(--user); }
.hint b { font-family: var(--mono); font-weight: 600; color: var(--accent); min-width: 110px; }
.hint span { color: var(--muted); }
.status { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 4px 18px 8px; font: 12px var(--mono); color: var(--dim); max-width: 900px; width: 100%; margin: 0 auto; }
.status .ok { color: var(--green); } .status .bad { color: var(--red); } .status .warn { color: var(--yellow); }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #44433f; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- узкий экран (телефон) ---------- */
@media (max-width: 820px) {
  #side { position: fixed; z-index: 20; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; width: min(86vw, 320px); }
  #app.side-open #side { transform: none; }
  #app.side-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 10; }
  .feed > * { padding-left: 12px; padding-right: 12px; }
  #composer { padding: 8px 10px 4px; }
  #top { padding: 8px 10px; }
  .msg-user .bubble { max-width: 92%; }
  .status { padding: 2px 12px 6px; }
}
@media (min-width: 821px) {
  #app.side-hidden #side { display: none; }
}
