/* Пульт агента: тёмная тема как в Claude Code, светлая — если Telegram в светлой */
:root {
  --bg: #1e1f22; --panel: #26272b; --panel2: #2d2f34; --line: #3a3c42; --text: #e7e7ea; --muted: #9a9ca3;
  --accent: #d97757; --accent2: #e8a17f; --ok: #5bb98b; --err: #e5534b; --warn: #d6a144; --code: #17181b;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f5f2; --panel: #ffffff; --panel2: #f0eeea; --line: #e2dfd8; --text: #1f1f1f; --muted: #6f6c66; --code: #f1efea;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* 30.10: display:flex у .sheet и .working перебивал атрибут hidden — пустое окно и «Работаю…» висели всегда */
[hidden] { display: none !important; }
/* 30.10: страница целиком не листается (у окна Telegram на ПК своя полоса прокрутки съедала место — кнопка отправки уезжала за край);
   листается только лента чата */
html, body { overflow: hidden; height: 100%; }
#app { width: 100%; }
.composer, .top, .limits, .feed, .working { max-width: 100%; min-width: 0; }
.bar-row { min-width: 0; }
.bar-row .pill { flex: 0 1 auto; min-width: 0; }
.bar-row .send, .bar-row .icon { flex: 0 0 auto; }
#btnModel { max-width: 34%; }
#btnMode { max-width: 38%; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; max-width: 860px; margin: 0 auto; }

.top { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; border-bottom: 1px solid var(--line); }
.title { flex: 1; min-width: 0; text-align: left; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 6px 4px; }
.top-actions { display: flex; gap: 2px; }
.icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.icon:hover, .icon:active { background: var(--panel2); color: var(--text); }
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon svg circle[r="1.3"] { fill: currentColor; }
.icon.small { width: 34px; height: 34px; }
.icon.small svg { width: 20px; height: 20px; }

.limits { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 7px 14px; border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--muted); text-align: left; width: 100%; }
.limits .acc { flex-basis: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.limits .lim { display: inline-flex; align-items: center; gap: 6px; }
.limits b { color: var(--text); font-weight: 600; }
.bar { display: inline-block; width: 56px; height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; vertical-align: middle; }
.bar > i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 3px; transition: width .4s; }
.bar > i.mid { background: var(--warn); } .bar > i.hi { background: var(--err); }

.feed { flex: 1; overflow-y: auto; padding: 12px 14px 8px; overscroll-behavior: contain; }
.empty { text-align: center; margin-top: 18vh; color: var(--muted); }
.empty .logo { font-size: 42px; color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }

.msg { margin: 10px 0; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; }
.msg.assistant { padding: 2px 2px; }
.msg.assistant p { margin: 6px 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { font-size: 15px; margin: 12px 0 6px; }
.msg.assistant ul, .msg.assistant ol { margin: 6px 0; padding-left: 22px; }
.msg.assistant a { color: var(--accent2); }
.msg code { background: var(--code); border-radius: 5px; padding: 1px 5px; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.msg pre { background: var(--code); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; margin: 8px 0; }
.msg pre code { background: none; padding: 0; white-space: pre; }
.msg table { border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; }
.msg td, .msg th { border: 1px solid var(--line); padding: 4px 8px; }

.tool { position: relative; margin: 2px 0 2px 4px; padding: 3px 0 3px 18px; color: var(--muted); font-size: 13px; cursor: pointer; }
.tool::before { content: ""; position: absolute; left: 3px; top: 10px; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.tool.ok::before { background: var(--ok); } .tool.bad::before { background: var(--err); }
.tool .name { color: var(--text); font-weight: 600; }
.tool .line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.tool .det { display: none; margin-top: 6px; }
.tool.open .det { display: block; }
.tool.open .line { white-space: normal; }
.tool pre { background: var(--code); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 260px; overflow: auto; font-size: 12px; white-space: pre-wrap; color: var(--text); }
.tool .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin: 6px 0 2px; }
.tool .line { cursor: pointer; }
.tool pre.diff del { display: block; text-decoration: none; background: rgba(229,83,75,.16); color: var(--text); }
.tool pre.diff ins { display: block; text-decoration: none; background: rgba(91,185,139,.16); color: var(--text); }
.tool .todo div { padding: 2px 0; color: var(--text); }
.node .tok { color: var(--accent2); font-size: 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.card.err { border-color: var(--err); color: var(--err); white-space: pre-wrap; }
.card.perm { border-color: var(--warn); }
.card.perm ul { margin: 6px 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.card.file { display: flex; align-items: center; gap: 10px; }
.card.file .fi { font-size: 22px; } .card.file .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.sys { color: var(--muted); font-size: 13px; text-align: center; background: none; border: 0; display: flex; align-items: center; gap: 10px; }
.card.sys::before, .card.sys::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.btn { background: var(--accent); color: #fff; border-radius: 10px; padding: 8px 14px; font-weight: 600; }
.btn.ghost { background: var(--panel2); color: var(--text); }
.btn.red { background: var(--err); }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.working { display: flex; align-items: center; gap: 8px; padding: 6px 16px; color: var(--accent2); font-size: 13px; }
.working .timer { color: var(--muted); margin-left: auto; }
.spin { display: inline-block; animation: spin 2.4s linear infinite; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.composer { margin: 6px 10px calc(10px + var(--safe-b)); width: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 8px 6px; }
.composer:focus-within { border-color: var(--muted); }
.composer textarea { width: 100%; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: 4px 6px; max-height: 40vh; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 8px; font-size: 12px; max-width: 220px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { color: var(--muted); padding: 0 2px; }
.chip.up { opacity: .6; }
.chip .mini { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; cursor: zoom-in; }
.att { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.att .thumb { max-width: 160px; max-height: 120px; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; object-fit: cover; }
.msg.user.injected { border-style: dashed; }
/* кружок контекста (как в VS Code) и микрофон */
.ctx-ring { flex: 0 0 auto; position: relative; width: 30px; height: 30px; display: grid; place-items: center; }
.ctx-ring svg { position: absolute; inset: 0; width: 30px; height: 30px; transform: rotate(-90deg); }
.ctx-ring circle { fill: none; stroke-width: 3.5; }
.ctx-ring .bg { stroke: var(--line); }
.ctx-ring .fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset .4s; }
.ctx-ring.hi .fg { stroke: var(--err); }
.ctx-ring span { font-size: 9px; font-weight: 700; color: var(--muted); }
.mic.rec { color: #fff; background: var(--err); animation: recpulse 1.2s infinite; }
@keyframes recpulse { 50% { opacity: .65; } }
.rec-line { display: flex; align-items: center; gap: 8px; color: var(--err); font-size: 13px; padding: 2px 6px; }
/* значок «сколько агентов работает» и дерево помощников */
.agents-badge { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 9px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); font-size: 13px; }
.agents-badge b { font-weight: 700; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(91,185,139,.6); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(91,185,139,.55); } 70% { box-shadow: 0 0 0 7px rgba(91,185,139,0); } 100% { box-shadow: 0 0 0 0 rgba(91,185,139,0); } }
.tree { margin: 4px 0 8px; }
.node { border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; margin: 6px 0; background: var(--bg); }
.node.child { margin-left: 18px; position: relative; }
.node.child::before { content: ""; position: absolute; left: -12px; top: -8px; bottom: 50%; width: 10px; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); border-bottom-left-radius: 6px; }
.node .nh { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.node .nh b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .nt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.node .ns { color: var(--muted); font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .nlog { display: none; margin-top: 8px; font-size: 12px; color: var(--muted); max-height: 220px; overflow: auto; }
.node.open .nlog { display: block; }
.node .nlog div { padding: 2px 0; border-bottom: 1px dashed var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .nres { white-space: pre-wrap; color: var(--text); margin-top: 6px; }
/* дописанное по ходу, пока агент не взял — над полем ввода, как очередь в VS Code */
.pending { padding: 0 10px; display: flex; flex-direction: column; gap: 6px; max-height: 30vh; overflow-y: auto; }
.pending:empty { display: none; }
.pend { background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 8px 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word; opacity: .85; }
.pend small { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }
.inj { font-size: 11px; color: var(--muted); margin-top: 4px; }
.lb { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.88); display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
.lb img { max-width: 96vw; max-height: 86vh; transform-origin: center; cursor: grab; user-select: none; transition: transform .05s; }
.lb-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 8px 10px; color: #fff; font-size: 13px; background: rgba(0,0,0,.4); }
.lb-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-bar button { color: #fff; background: rgba(255,255,255,.12); border-radius: 8px; min-width: 34px; height: 30px; padding: 0 8px; }
.bar-row { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.grow { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 9px; font-size: 13px; color: var(--muted); max-width: 46vw; }
.pill span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill:hover, .pill:active { background: var(--panel2); color: var(--text); }
.send { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.send svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.send.stop { background: var(--panel2); color: var(--text); }
.send.stop svg { fill: currentColor; stroke: none; }
.send:disabled { opacity: .45; }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 82vh; max-width: 860px; margin: 0 auto; background: var(--panel); border-radius: 18px 18px 0 0;
  border: 1px solid var(--line); z-index: 11; display: flex; flex-direction: column; padding-bottom: var(--safe-b); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 2px; }
.sheet-head { display: flex; align-items: center; padding: 4px 10px 6px 16px; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 16px; }
.sheet-body { overflow-y: auto; padding: 4px 12px 14px; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 11px 10px; border-radius: 10px; }
.opt:hover, .opt:active { background: var(--panel2); }
.opt .oi { width: 22px; text-align: center; font-size: 17px; }
.opt .ot { flex: 1; min-width: 0; }
.opt .ot b { display: block; font-weight: 600; }
.opt .ot small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt.sel { background: var(--panel2); }
.opt .ok { color: var(--accent); }
.sep { height: 1px; background: var(--line); margin: 6px 0; }
.section { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 10px 4px; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px 6px; }
.seg button { padding: 6px 10px; border-radius: 8px; background: var(--panel2); font-size: 13px; }
.seg button.sel { background: var(--accent); color: #fff; }
.field { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 10px 12px; font: inherit; outline: 0; }
.field:focus { border-color: var(--accent); }
.usage { padding: 4px 6px; }
.usage .u { margin: 10px 0; }
.usage .u .h { display: flex; justify-content: space-between; font-weight: 600; }
.usage .u .bar { width: 100%; height: 7px; margin: 6px 0 3px; }
.usage .u small { color: var(--muted); }
.status { background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; font-size: 14px; white-space: pre-wrap; }
.status.ok { border-color: var(--ok); color: var(--ok); } .status.bad { border-color: var(--err); color: var(--err); }
.jr { padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
.jr .jh { display: flex; gap: 8px; color: var(--muted); font-size: 12px; }
.jr .jp { margin: 3px 0; color: var(--text); }
.jr .jres { color: var(--muted); white-space: pre-wrap; max-height: 4.5em; overflow: hidden; }
.chatrow { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; }
.chatrow:hover, .chatrow.sel { background: var(--panel2); }
.chatrow .ct { flex: 1; min-width: 0; }
.chatrow .ct b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.chatrow .ct small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatrow .cs { font-size: 12px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; z-index: 20; font-size: 14px; max-width: 90vw; }
.gate { text-align: center; padding: 30vh 24px 0; color: var(--muted); }
