/* agent — минималистичный интерфейс ИИ-агента */
:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --side: #efefec;
  --text: #191919;
  --muted: #82827c;
  --line: #e3e3de;
  --line2: #d6d6d0;
  --bubble: #ebebe6;
  --accent: #111111;
  --link: #2f6fed;
  --ok: #199a4c;
  --err: #d23b3b;
  --warn: #c07f19;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
::selection { background: #d9d9d2; }

/* скроллбары */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d2d2cb; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- вордмарк ---------- */
.wordmark { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; display: inline-flex; align-items: baseline; }
.wm-dot { width: 5px; height: 5px; background: var(--accent); border-radius: 1px; display: inline-block; margin-left: 3px; }

/* ---------- вход ---------- */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 60; }
.login-card {
  width: min(360px, calc(100vw - 40px)); background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 34px 30px 26px;
  box-shadow: 0 18px 50px rgba(20, 20, 18, 0.07);
  display: flex; flex-direction: column; gap: 14px; text-align: left;
}
.login-sub { color: var(--muted); font-size: 13.5px; margin-top: -6px; }
.login-card input {
  font-size: 15px; padding: 11px 13px; border: 1px solid var(--line2); border-radius: 9px;
  background: #fdfdfc; color: var(--text); outline: none; font-family: var(--mono);
}
.login-card input:focus { border-color: #9d9d95; }
.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 9px;
  padding: 11px 16px; font-size: 14.5px; font-weight: 600; transition: opacity .15s;
}
.btn-primary:hover { opacity: .87; }
.login-err { color: var(--err); font-size: 13px; min-height: 18px; }
.shake { animation: shake .3s; }
@keyframes shake { 0%,100%{transform:none} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }

/* ---------- каркас ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- сайдбар ---------- */
.sidebar {
  width: 264px; min-width: 264px; background: var(--side);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: 16px 12px 12px; gap: 8px; transition: margin-left .18s ease;
}
.sidebar.collapsed { margin-left: -264px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.icon-btn {
  background: none; border: none; color: var(--muted); width: 30px; height: 30px;
  border-radius: 7px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,.06); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }
.side-burger { transform: rotate(180deg); }
.btn-new {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--accent); color: #fff; border: none; border-radius: 9px;
  padding: 9px 12px; font-size: 13.5px; font-weight: 600;
}
.btn-new:hover { opacity: .87; }
.btn-new svg { width: 15px; height: 15px; }
.side-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 8px 2px; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px;
  font-size: 13.5px; color: #3c3c38; cursor: pointer; border: none; background: none; text-align: left; width: 100%;
}
.chat-item:hover { background: rgba(0,0,0,.055); }
.chat-item.active { background: #e2e2dc; font-weight: 600; color: var(--text); }
.chat-item .ci-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-del { opacity: 0; color: var(--muted); flex-shrink: 0; }
.chat-item:hover .ci-del { opacity: .8; }
.chat-item .ci-del:hover { color: var(--err); }
.ci-del svg { width: 13px; height: 13px; display: block; }
.side-footer { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.ghost-btn {
  display: flex; align-items: center; gap: 9px; background: none; border: none;
  color: #4a4a45; font-size: 13.5px; padding: 8px 10px; border-radius: 8px; text-align: left;
}
.ghost-btn:hover { background: rgba(0,0,0,.055); }
.ghost-btn svg { width: 16px; height: 16px; }
.badge { background: var(--accent); color: #fff; font-size: 10.5px; border-radius: 9px; padding: 1px 7px; }
.side-show {
  position: fixed; left: 8px; top: 12px; z-index: 30; width: 30px; height: 30px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 8px;
  display: none; align-items: center; justify-content: center;
}
.side-show svg { width: 16px; height: 16px; }
.app.side-hidden .side-show { display: inline-flex; }

/* ---------- основная область ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-header {
  height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 22px 0 50px;
  border-bottom: 1px solid var(--line); background: rgba(246,246,244,.85); backdrop-filter: blur(6px);
}
.app:not(.side-hidden) .chat-header { padding-left: 22px; }
.chat-title { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host-label { color: var(--muted); font-size: 12px; font-family: var(--mono); white-space: nowrap; }

.messages { flex: 1; overflow-y: auto; padding: 26px 0 10px; scroll-behavior: smooth; }
.msg-col { max-width: 780px; margin: 0 auto; padding: 0 22px; display: flex; flex-direction: column; gap: 22px; }

.empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--muted); text-align: center; }
.empty-mark { font-size: 26px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.empty-sub { font-size: 13.5px; line-height: 1.7; }

/* сообщения */
.msg { display: flex; flex-direction: column; gap: 8px; }
.msg.user { align-items: flex-end; }
.msg .bubble {
  background: var(--bubble); border-radius: 16px; padding: 10px 15px;
  max-width: 82%; white-space: pre-wrap; word-break: break-word; font-size: 14.8px;
}
.msg.ai { align-items: stretch; }
.ai-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.ai-head .ai-name { color: var(--text); }
.typing { display: inline-flex; gap: 3px; }
.typing i { width: 4px; height: 4px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,70%,100%{opacity:.25} 35%{opacity:1} }

.ai-body { word-break: break-word; font-size: 14.8px; }
.ai-body p { margin: 0 0 10px; } .ai-body p:last-child { margin-bottom: 0; }
.ai-body h1, .ai-body h2, .ai-body h3 { margin: 14px 0 8px; line-height: 1.3; }
.ai-body h1 { font-size: 19px; } .ai-body h2 { font-size: 17px; } .ai-body h3 { font-size: 15.5px; }
.ai-body ul, .ai-body ol { margin: 6px 0 10px; padding-left: 22px; }
.ai-body li { margin: 3px 0; }
.ai-body a { color: var(--link); text-decoration: none; } .ai-body a:hover { text-decoration: underline; }
.ai-body blockquote { margin: 8px 0; padding: 2px 14px; border-left: 3px solid var(--line2); color: var(--muted); }
.ai-body hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.ai-body table { border-collapse: collapse; margin: 10px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.ai-body th, .ai-body td { border: 1px solid var(--line2); padding: 6px 11px; text-align: left; }
.ai-body code.inline, .ai-body :not(pre) > code { background: #ecebe6; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-family: var(--mono); font-size: .88em; }
.codeblock { margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fbfbf9; }
.codeblock .cb-head {
  display: flex; justify-content: space-between; align-items: center; padding: 5px 12px;
  border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11.5px; font-family: var(--mono);
}
.cb-actions { display: flex; align-items: center; gap: 4px; }
.cb-copy, .cb-run { background: none; border: none; color: var(--muted); font-size: 11.5px; padding: 2px 7px; border-radius: 5px; }
.cb-copy:hover, .cb-run:hover { background: rgba(0,0,0,.05); color: var(--text); }
.cb-run { color: #2f6fed; font-weight: 600; }
.cb-run:hover { background: rgba(47,111,237,.09); color: #2b63d4; }
.cb-run:disabled { opacity: .55; }
.cb-copy:hover { background: rgba(0,0,0,.05); color: var(--text); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 13px; line-height: 1.55; }
.codeblock pre code.hljs { background: transparent; padding: 0; }

/* вывод запущенного кода */
.cb-console { border-top: 1px solid var(--line); background: #14161a; }
.cb-console .cbc-head {
  display: flex; justify-content: space-between; align-items: center; padding: 5px 12px;
  color: #8b8f98; font-size: 11px; font-family: var(--mono); border-bottom: 1px solid #23262c;
}
.cbc-clear { background: none; border: none; color: #8b8f98; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.cbc-clear:hover { background: rgba(255,255,255,.07); color: #e6e6ea; }
.cb-console .cbc-out {
  margin: 0; padding: 9px 13px; font-family: var(--mono); font-size: 12.4px; line-height: 1.5;
  color: #d7d9de; white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow-y: auto;
}
.cb-console .cbc-err { color: #ff8f85; }

/* таблицы */
.ai-body table { border-collapse: collapse; margin: 10px 0; font-size: 13.5px; display: block; overflow-x: auto; max-width: 100%; }
.ai-body th, .ai-body td { border: 1px solid var(--line2); padding: 6px 11px; text-align: left; vertical-align: top; }
.ai-body th { background: #f1f1ec; font-weight: 600; }
.ai-body tbody tr:nth-child(even) { background: #fafaf6; }

/* формулы KaTeX */
.ai-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 3px 0; margin: 8px 0; }
.ai-body .katex { font-size: 1.04em; }

/* предпросмотр HTML */
.preview-content { width: min(960px, 94vw); padding: 0; background: #fff; }
.preview-frame { width: 100%; height: min(78vh, 820px); border: none; display: block; background: #fff; border-radius: 12px; }

/* размышления */
.reasoning { border-left: 3px solid var(--line2); padding: 4px 0 4px 13px; margin: 2px 0 4px; }
.reasoning summary {
  cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 600; user-select: none;
  list-style: none; display: flex; align-items: center; gap: 6px;
}
.reasoning summary::before { content: "▸"; transition: transform .15s; font-size: 10px; }
.reasoning[open] summary::before { transform: rotate(90deg); }
.reasoning .r-body { color: var(--muted); font-size: 13.5px; white-space: pre-wrap; font-style: italic; margin-top: 6px; max-height: 300px; overflow-y: auto; }

/* инструменты */
.tool {
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  overflow: hidden; font-size: 13px;
}
.tool + .tool { margin-top: 8px; }
.tool-head { display: flex; align-items: center; gap: 9px; padding: 8px 12px; cursor: pointer; user-select: none; }
.tool-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.tool-dot.run { background: var(--warn); animation: pulse 1s infinite; }
.tool-dot.ok { background: var(--ok); }
.tool-dot.err { background: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }
.tool-name { font-family: var(--mono); font-weight: 600; font-size: 12.5px; }
.tool-desc { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool-dur { color: var(--muted); font-size: 11.5px; flex-shrink: 0; }
.tool-chev { color: var(--muted); transition: transform .15s; font-size: 10px; }
.tool.open .tool-chev { transform: rotate(90deg); }
.tool-body { display: none; border-top: 1px solid var(--line); }
.tool.open .tool-body { display: block; }
.tool-sec { padding: 8px 12px; }
.tool-sec + .tool-sec { border-top: 1px dashed var(--line); }
.tool-sec .ts-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 4px; }
.tool-sec pre { margin: 0; font-family: var(--mono); font-size: 12.2px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow-y: auto; }

/* вложения */
.attach-row { max-width: 780px; margin: 0 auto 8px; padding: 0 22px; display: flex; flex-wrap: wrap; gap: 7px; }
.attach-row:empty { display: none; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 7px; background: var(--panel);
  border: 1px solid var(--line2); border-radius: 9px; padding: 5px 10px; font-size: 12.5px; max-width: 260px;
}
.attach-chip .ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .ac-x { background: none; border: none; color: var(--muted); font-size: 13px; padding: 0 1px; line-height: 1; }
.attach-chip .ac-x:hover { color: var(--err); }
.attach-chip.uploading { opacity: .55; }
.attach-chip svg { width: 13px; height: 13px; color: var(--muted); flex-shrink: 0; }
.msg .atts { display: flex; flex-wrap: wrap; gap: 8px; }
.msg.user .atts { justify-content: flex-end; }
.att-card {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line2);
  border-radius: 10px; padding: 7px 11px; font-size: 12.5px; cursor: pointer; max-width: 240px;
}
.att-card:hover { border-color: #b9b9b1; }
.att-card svg { width: 15px; height: 15px; color: var(--muted); flex-shrink: 0; }
.att-card .ac-meta { min-width: 0; }
.att-card .ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.att-card .ac-size { color: var(--muted); font-size: 11px; }
.att-thumb { width: 74px; height: 74px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line2); cursor: zoom-in; display: block; }

/* композер */
.composer-wrap { padding: 8px 0 14px; background: linear-gradient(transparent, var(--bg) 30%); }
.composer {
  max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line2);
  border-radius: 14px; display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px 8px 6px;
  box-shadow: 0 4px 24px rgba(20,20,18,.05); transition: border-color .15s;
}
.composer:focus-within { border-color: #a8a8a0; }
.composer textarea {
  flex: 1; border: none; outline: none; resize: none; background: none; color: var(--text);
  font-family: var(--sans); font-size: 14.8px; line-height: 1.5; max-height: 200px; padding: 6px 4px;
}
.composer textarea::placeholder { color: #a3a39b; }
.send-btn {
  width: 34px; height: 34px; border-radius: 9px; border: none; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.send-btn:hover { opacity: .85; }
.send-btn:disabled { opacity: .35; cursor: default; }
.send-btn svg { width: 16px; height: 16px; }
.send-btn.stop { background: var(--err); }
.composer-hint { max-width: 780px; margin: 7px auto 0; text-align: center; color: #a3a39b; font-size: 11.5px; }

/* ---------- терминалы ---------- */
.term-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 92vw); z-index: 40;
  background: #101210; color: #d7d7d2; display: flex; flex-direction: column;
  border-left: 1px solid #2a2c2a; box-shadow: -18px 0 50px rgba(0,0,0,.25);
}
.term-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid #2a2c2a; }
.term-title { font-weight: 600; font-size: 14px; color: #f0f0ec; }
.term-head-actions { display: flex; align-items: center; gap: 8px; }
.term-head .icon-btn { color: #8a8a84; } .term-head .icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.mini-btn {
  display: inline-flex; align-items: center; gap: 6px; background: #1e201e; color: #e6e6e1;
  border: 1px solid #343634; border-radius: 8px; font-size: 12.5px; padding: 5px 11px; text-decoration: none;
}
.mini-btn:hover { background: #282a28; }
.mini-btn svg { width: 13px; height: 13px; }
.term-tabs { display: flex; gap: 6px; padding: 9px 14px 0; flex-wrap: wrap; }
.term-tab {
  display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); font-size: 12px;
  padding: 5px 10px; border-radius: 7px; background: #191b19; color: #9a9a94; border: 1px solid #262826; cursor: pointer;
}
.term-tab.active { background: #242724; color: #f0f0ec; border-color: #3a3d3a; }
.term-tab .tt-x { color: #77776f; font-size: 12px; } .term-tab .tt-x:hover { color: #ff7b6f; }
.term-body { flex: 1; min-height: 0; padding: 10px 14px 14px; display: flex; flex-direction: column; }
.term-view { flex: 1; min-height: 0; display: none; flex-direction: column; }
.term-view.active { display: flex; }
.term-out {
  flex: 1; overflow-y: auto; background: #0c0e0c; border: 1px solid #262826; border-radius: 10px;
  padding: 10px 12px; font-family: var(--mono); font-size: 12.6px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-all; color: #d7d7d2;
}
.term-in { display: flex; gap: 7px; margin-top: 9px; }
.term-in input {
  flex: 1; background: #191b19; border: 1px solid #2e302e; color: #f0f0ec; border-radius: 8px;
  font-family: var(--mono); font-size: 13px; padding: 8px 11px; outline: none;
}
.term-in input:focus { border-color: #4a4d4a; }
.term-in .mini-btn { padding: 5px 9px; }

/* ---------- просмотрщик ---------- */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(15,15,14,.55); display: flex; align-items: center; justify-content: center; padding: 26px; }
.viewer-bar {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  display: flex; align-items: center; gap: 14px; padding: 8px 10px 8px 15px; max-width: min(760px, 90vw);
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.viewer-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.viewer-content { background: var(--panel); border-radius: 13px; max-width: min(820px, 94vw); max-height: 84vh; overflow: auto; border: 1px solid var(--line); margin-top: 70px; }
.viewer-content img.view-img { display: block; max-width: 100%; max-height: 84vh; border-radius: 12px; }
.viewer-content pre.view-text { margin: 0; padding: 16px 18px; font-family: var(--mono); font-size: 12.6px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.viewer-content .view-unknown { padding: 26px; color: var(--muted); font-size: 13.5px; text-align: center; }
.view-frame { width: min(820px, 88vw); height: 80vh; border: none; display: block; }

/* ---------- тосты ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #191919; color: #f4f4f0; border-radius: 10px; padding: 9px 16px; font-size: 13px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); animation: tin .2s ease; max-width: 480px;
}
.toast.err { background: #7e2222; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ---------- адаптив ---------- */
@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 35; top: 0; bottom: 0; left: 0; box-shadow: 14px 0 40px rgba(0,0,0,.14); }
  .sidebar.collapsed { margin-left: -280px; }
  .chat-header { padding-left: 50px; }
  .msg .bubble { max-width: 94%; }
  .term-panel { width: 100vw; }
  .empty-sub br { display: none; }
}
