/* Чат с командой агентов. Нейтральная палитра без цветных заливок: светлая и тёмная тема по системе или вручную (data-theme). */
:root {
  --bg: #ffffff;
  --bg-alt: #f5f5f3;
  --bg-hover: #ecece9;
  --border: #e3e3df;
  --border-strong: #cfcfca;
  --text: #1c1c1a;
  --text-2: #6a6a65;
  --danger: #b3261e;
  --add-bg: #e8f1e6;
  --del-bg: #f6e4e2;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 268px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161615; --bg-alt: #1e1e1c; --bg-hover: #282826; --border: #2e2e2b; --border-strong: #42423e;
    --text: #ececea; --text-2: #9b9b94; --danger: #f0a39d; --add-bg: #1f3320; --del-bg: #3a2220; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161615; --bg-alt: #1e1e1c; --bg-hover: #282826; --border: #2e2e2b; --border-strong: #42423e;
  --text: #ececea; --text-2: #9b9b94; --danger: #f0a39d; --add-bg: #1f3320; --del-bg: #3a2220; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
input, textarea, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100dvh; }
.side { background: var(--bg-alt); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.side-top { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.side h1 { font-size: 15px; margin: 4px 4px 0; font-weight: 650; letter-spacing: .1px; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border-strong); background: var(--bg); border-radius: var(--radius); padding: 7px 12px; min-height: 36px; }
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover:not(:disabled) { background: var(--text); opacity: .88; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { padding: 0; width: 36px; justify-content: center; }
.search { width: 100%; border: 1px solid transparent; background: var(--bg); border-radius: 999px; padding: 7px 14px; min-height: 36px; }
.search:focus { outline: none; border-color: var(--border-strong); }
.chat-list { overflow: auto; padding: 4px 8px 12px; flex: 1; min-height: 0; }
.chat-item { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 8px 10px; }
.chat-item:hover { background: var(--bg-hover); }
.chat-item.on { background: var(--bg-hover); font-weight: 600; }
.chat-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .x { opacity: 0; border: 0; background: transparent; color: var(--text-2); padding: 2px 6px; border-radius: 6px; }
.chat-item:hover .x, .chat-item.on .x { opacity: 1; }
.chat-item .x:hover { color: var(--danger); }
.side-foot { border-top: 1px solid var(--border); padding: 10px 12px; font-size: 13px; color: var(--text-2); display: flex; gap: 8px; align-items: center; justify-content: space-between; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.top { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--border); min-height: 52px; }
.top .title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; background: transparent; padding: 4px 6px; border-radius: 6px; text-align: left; }
.top .title:hover { background: var(--bg-alt); }
.tag { font-size: 12px; color: var(--text-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.menu-btn { display: none; }
#plan.on { background: var(--text); color: var(--bg); border-color: var(--text); }
select.proj { border: 1px solid var(--border-strong); background: var(--bg); border-radius: 999px; padding: 4px 10px; font-size: 13px; }

.scroll { flex: 1; overflow: auto; min-height: 0; scroll-behavior: auto; overscroll-behavior: contain; }
.thread { max-width: 860px; margin: 0 auto; padding: 18px 16px 28px; display: flex; flex-direction: column; gap: 18px; }
.empty { margin: 14vh auto 0; max-width: 520px; text-align: center; color: var(--text-2); padding: 0 16px; }
.empty h2 { color: var(--text); font-size: 20px; margin: 0 0 8px; }
.empty .hints { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }

.msg-user { align-self: stretch; border-left: 3px solid var(--border-strong); padding: 2px 0 2px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-user .lbl { font-size: 12px; color: var(--text-2); display: block; margin-bottom: 2px; }
.msg-asst { align-self: stretch; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.who { font-size: 12px; color: var(--text-2); }
.say { overflow-wrap: anywhere; }
.say p { margin: 0 0 8px; }
.say p:last-child { margin-bottom: 0; }
.say ul { margin: 0 0 8px; padding-left: 22px; }
.say code { font-family: var(--mono); font-size: 13px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; }
.say pre { margin: 6px 0; padding: 10px 12px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 8px; overflow: auto; }
.say pre code { background: none; border: 0; padding: 0; }
.say h3, .say h4 { margin: 10px 0 4px; font-size: 15px; }
.note { font-size: 13px; color: var(--text-2); }
.note.err { color: var(--danger); }

.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; text-align: left; padding: 7px 10px; font-family: var(--mono); font-size: 13px; }
.card-head:hover { background: var(--bg-alt); }
.card-head .nm { font-weight: 600; flex: none; }
.card-head .br { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.card-head .st { flex: none; color: var(--text-2); font-size: 12px; }
.card-head .chev { transition: transform .12s; width: 14px; height: 14px; }
.card.open .chev { transform: rotate(90deg); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); flex: none; }
.card.run .dot { animation: pulse 1s ease-in-out infinite; background: var(--text); }
.card.fail .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .25; } }
.card-body { display: none; border-top: 1px solid var(--border); padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; max-height: 380px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.card.open .card-body { display: block; }
.card-body .sec { color: var(--text-2); font-size: 11.5px; margin: 6px 0 2px; font-family: var(--sans); }
.card-body .sec:first-child { margin-top: 0; }
.diff-l { display: block; padding: 0 4px; }
.diff-l.a { background: var(--add-bg); }
.diff-l.d { background: var(--del-bg); }
.diff-l.h { color: var(--text-2); }

.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); }
.swipes { display: inline-flex; align-items: center; gap: 2px; }
.swipes button { border: 0; background: transparent; padding: 2px 6px; border-radius: 6px; color: var(--text-2); }
.swipes button:hover:not(:disabled) { background: var(--bg-alt); color: var(--text); }
.linkbtn { border: 0; background: transparent; color: var(--text-2); padding: 2px 6px; border-radius: 6px; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:hover { color: var(--text); background: var(--bg-alt); }
.run-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.spin { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--text); border-radius: 50%; animation: rot .8s linear infinite; flex: none; }
@keyframes rot { to { transform: rotate(360deg); } }

.composer-wrap { padding: 8px 14px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer { max-width: 860px; margin: 0 auto; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--bg); display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px 8px 14px; position: relative; }
.composer:focus-within { border-color: var(--text-2); }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; max-height: 220px; min-height: 28px; padding: 4px 0; line-height: 1.45; font-size: 16px; }
.slash { position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.12); overflow: hidden; max-height: 260px; overflow-y: auto; }
.slash button { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 12px; }
.slash button:hover, .slash button.on { background: var(--bg-alt); }
.slash .c { font-family: var(--mono); min-width: 120px; }
.slash .d { color: var(--text-2); font-size: 13px; }
.hint { max-width: 860px; margin: 6px auto 0; font-size: 12px; color: var(--text-2); display: flex; justify-content: space-between; gap: 8px; }

.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: var(--bg); border-left: 1px solid var(--border-strong); box-shadow: -8px 0 28px rgba(0,0,0,.1); display: flex; flex-direction: column; z-index: 20; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.drawer-head b { flex: 1; }
.drawer-body { padding: 14px; overflow: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.field input[type=text], .field textarea { width: 100%; border: 1px solid var(--border-strong); background: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.field textarea { min-height: 96px; resize: vertical; }
.mem-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.mem-item .h { display: flex; gap: 8px; align-items: center; }
.mem-item .h b { flex: 1; overflow-wrap: anywhere; }
.mem-item .k { font-size: 12px; color: var(--text-2); }
.mem-item.off { opacity: .55; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; z-index: 50; max-width: 90vw; }
.scrim { display: none; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 30; transform: translateX(-102%); transition: transform .18s; }
  .side.open { transform: none; box-shadow: 8px 0 28px rgba(0,0,0,.2); }
  .scrim.on { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .menu-btn { display: inline-flex; }
  .hint .kbd { display: none; }
  .tag.cost { display: none; }
  .lbl-d { display: none; }
  #memory { padding: 0; width: 36px; justify-content: center; }
  #hint { display: none; }
  .thread { padding: 14px 12px 22px; }
}

/* вход */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login input { border: 1px solid var(--border-strong); background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 16px; }
.login .err { color: var(--danger); font-size: 14px; min-height: 20px; }
