:root {
  --bg: #ffffff;
  --side: #f9f9f8;
  --hover: #efeeeb;
  --active: #e8e6e1;
  --border: #e6e4df;
  --text: #1f1e1c;
  --muted: #8b8984;
  --accent: #d97757;
  --code-bg: #f3f2ef;
  --code-text: #b4442a;
  --user-bg: #f1f0ec;
  --ok: #2f9e64;
  --bad: #d4513b;
  --radius: 12px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1e1d; --side: #191817; --hover: #2a2927; --active: #33312e; --border: #33312e;
    --text: #ecebe8; --muted: #9a978f; --code-bg: #2b2a28; --code-text: #f0a58f; --user-bg: #2b2a28;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* атрибут hidden сильнее любых display в правилах ниже */
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { margin-left: auto; }

#app { display: grid; grid-template-columns: 290px 1fr 320px; height: 100vh; }
#app.no-side { grid-template-columns: 0 1fr 320px; }
#app.no-panel { grid-template-columns: 290px 1fr 0; }
#app.no-side.no-panel { grid-template-columns: 0 1fr 0; }
#app.no-side #sidebar, #app.no-panel #panel { display: none; }

/* ------------------------------------------------------------- слева */
#sidebar { background: var(--side); border-right: 1px solid var(--border); display: flex;
           flex-direction: column; padding: 14px 10px; min-width: 0; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border);
          border-radius: 10px; padding: 7px 10px; background: var(--bg); color: var(--muted); margin-bottom: 10px; }
.search input { border: 0; outline: 0; background: none; color: var(--text); font: inherit; width: 100%; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
            padding: 7px 10px; border-radius: 8px; }
.nav-item:hover:not(:disabled) { background: var(--hover); }
.soon { margin-left: auto; font-size: 11px; color: var(--muted); border: 1px solid var(--border);
        border-radius: 6px; padding: 0 6px; }
.side-section { margin: 18px 10px 6px; font-size: 13px; color: var(--muted); }
#chats { flex: 1; overflow-y: auto; min-height: 0; }
.chat-group { font-size: 12px; color: var(--muted); margin: 12px 10px 4px; }
.chat-item { display: block; width: 100%; text-align: left; padding: 7px 10px; border-radius: 8px;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); font-weight: 600; }
.chat-item.busy::after { content: " •"; color: var(--accent); }
.side-bottom { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border);
               padding: 12px 6px 2px; margin-top: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--active); display: grid;
          place-items: center; font-size: 13px; font-weight: 600; }
.who { flex: 1; min-width: 0; line-height: 1.3; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }

/* ------------------------------------------------------------- центр */
#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; gap: 2px; }
#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#scroller { flex: 1; overflow-y: auto; }
#messages { max-width: 860px; margin: 0 auto; padding: 8px 32px 24px; }

.msg { margin: 18px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bg); border-radius: 14px; padding: 9px 14px; max-width: 80%;
                    white-space: pre-wrap; word-wrap: break-word; }
.activity { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px;
            padding: 2px 0; cursor: pointer; user-select: none; }
.activity:hover { color: var(--text); }
.activity .chev { transition: transform .15s; width: 14px; height: 14px; }
.activity.open .chev { transform: rotate(90deg); }
.reasoning { color: var(--muted); font-size: 14px; border-left: 2px solid var(--border);
             padding: 2px 0 2px 12px; margin: 6px 0 10px; white-space: pre-wrap; }
.msg-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.msg .error-text { color: var(--bad); }

.md p { margin: 0 0 12px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 24px; }
.md li { margin: 4px 0; }
.md h3, .md h4, .md h5, .md h6 { margin: 18px 0 8px; line-height: 1.35; }
.md h3 { font-size: 19px; } .md h4 { font-size: 17px; } .md h5, .md h6 { font-size: 15px; }
.md code { font-family: var(--mono); font-size: 13.5px; background: var(--code-bg); color: var(--code-text);
           padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--code-bg); border-radius: 0 0 10px 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 12px;
          max-height: 520px; }
.code-bar { display: flex; align-items: center; gap: 6px; background: var(--code-bg); border-radius: 10px 10px 0 0;
            padding: 6px 10px 0; border-bottom: 1px solid var(--border); }
.code-lang { margin-right: auto; }
.code-btn { font-size: 12px; color: var(--muted); padding: 2px 8px; border-radius: 6px; }
.code-btn:hover { background: var(--hover); color: var(--text); }
.md pre code { background: none; color: var(--text); padding: 0; }
.md a { color: var(--accent); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.table-wrap { overflow-x: auto; margin: 0 0 12px; }
.md table, #audit { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td, #audit th, #audit td { border-bottom: 1px solid var(--border); padding: 6px 10px; text-align: left;
                                       vertical-align: top; }
.md th, #audit th { font-weight: 600; }

.working { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; margin: 8px 0; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.empty { max-width: 680px; margin: 14vh auto 0; text-align: center; padding: 0 24px; }
.empty h1 { font-weight: 500; font-size: 30px; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.chip { border: 1px solid var(--border); border-radius: 18px; padding: 7px 14px; font-size: 14px; }
.chip:hover { background: var(--hover); }

#composer { max-width: 860px; width: 100%; margin: 0 auto; padding: 0 32px 14px; }
.composer-box { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border);
                border-radius: 16px; padding: 8px 8px 8px 10px; background: var(--bg);
                box-shadow: 0 2px 10px rgba(0, 0, 0, .04); }
.composer-box:focus-within { border-color: #c9c6bf; }
#input { flex: 1; border: 0; outline: 0; resize: none; background: none; color: var(--text); font: inherit;
         padding: 5px 2px; max-height: 240px; }
.round-btn { width: 34px; height: 34px; border-radius: 50%; background: var(--text); color: var(--bg);
             display: grid; place-items: center; }
.round-btn.stop { background: var(--accent); color: #fff; }
.composer-meta { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 0; font-size: 13px; }
.mode { color: var(--muted); padding: 2px 8px; border-radius: 6px; }
.mode:hover { background: var(--hover); color: var(--text); }
.mode[aria-pressed="true"] { color: var(--accent); }

#audit-view, #files-view { flex: 1; overflow-y: auto; padding: 8px 32px 24px; }
body.guest .owner-only { display: none !important; }

/* температуры в боковой панели */
.temps { display: flex; gap: 6px; margin: 8px 6px 0; }
.temp { flex: 1; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; padding: 4px 6px;
        border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.temp.ok { color: var(--ok); }
.temp.warm { color: #c98a12; border-color: #e7c773; }
.temp.hot { color: #fff; background: var(--bad); border-color: var(--bad); }

/* файлы сервера */
.disk { margin: 6px 0 14px; }
.disk .bar { height: 8px; }
#disk-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.file-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.file-tab { border: 1px solid var(--border); border-radius: 8px; padding: 4px 12px; font-size: 14px; }
.file-tab:hover { background: var(--hover); }
.file-tab.active { background: var(--active); font-weight: 600; }
.file-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; min-width: 0; }
.crumb { padding: 2px 6px; border-radius: 6px; }
.crumb:hover { background: var(--hover); }
.ftable { border-collapse: collapse; width: 100%; font-size: 14px; }
.ftable td { border-bottom: 1px solid var(--border); padding: 5px 8px; vertical-align: middle; white-space: nowrap; }
.ftable td:first-child { white-space: normal; word-break: break-all; width: 100%; }
.fname { text-align: left; }
a.code-btn { text-decoration: none; }
.audit-head { display: flex; align-items: center; justify-content: space-between; }
.audit-head h2 { font-weight: 600; font-size: 20px; }
.ghost { border: 1px solid var(--border); border-radius: 8px; padding: 5px 12px; }
.ghost:hover { background: var(--hover); }
#audit td.bad { color: var(--bad); }
#audit td.args { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }

/* ------------------------------------------------------------- справа */
#panel { padding: 14px 14px; overflow-y: auto; border-left: 1px solid var(--border); background: var(--side); }
.card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
        padding: 12px 14px; margin-bottom: 10px; }
.card-title { display: flex; align-items: center; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }
.bar { height: 6px; border-radius: 3px; background: var(--hover); overflow: hidden; margin-bottom: 6px; }
#ctx-bar { height: 100%; width: 0; background: #3b7be8; transition: width .3s; }
.checks { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.checks li::before { content: "✓ "; color: var(--ok); }
.mini-audit { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.mini-audit li { display: flex; gap: 8px; padding: 3px 0; }
.mini-audit .t { color: var(--muted); flex: none; }
.mini-audit .bad { color: var(--bad); }
.link { color: var(--muted); font-size: 12px; font-weight: 400; }
.link:hover { color: var(--text); }

/* ------------------------------------------------------------- картинки, интернет, подтверждения */
.modes { display: flex; gap: 4px; }
.mode[data-mode="ask"] { color: #c08a1e; }
.mode[data-mode="auto"] { color: var(--accent); }
#composer.drag .composer-box { border-color: var(--accent); border-style: dashed; }
.thumbs { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden;
         border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-x { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%;
           background: rgba(0, 0, 0, .6); color: #fff; font-size: 14px; line-height: 20px; padding: 0; }
.user-col { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: 80%; }
.user-col .bubble { max-width: 100%; }
.user-images { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.user-images img { max-width: 220px; max-height: 180px; border-radius: 10px; border: 1px solid var(--border);
                   cursor: zoom-in; }
.activity-body { font-size: 14px; border-left: 2px solid var(--border); padding: 2px 0 4px 12px; margin: 4px 0 8px; }
.activity-body a { color: var(--text); }
.result { padding: 2px 0; }
.bad-text { color: var(--bad); }
.approval { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0;
            background: var(--side); }
.approval b { word-break: break-all; }
.approval-row { display: flex; gap: 8px; margin-top: 10px; }
.primary-btn { background: var(--text); color: var(--bg); border-radius: 8px; padding: 5px 14px; font-weight: 600; }
.mono { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.activity.notice { color: #c08a1e; cursor: default; }
.shots { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.shots figure { margin: 0; }
.shots img { width: 240px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.files { list-style: none; margin: 0 0 6px; padding: 0; font-size: 14px; }
.files li { padding: 3px 0; }
.files a { color: var(--accent); }
.mode[data-mode="ask"]#sandbox { color: #c08a1e; }

/* ------------------------------------------------------------- вход */
.login-body { display: grid; place-items: center; background: var(--side); }
.login-card { width: 340px; background: var(--bg); border: 1px solid var(--border); border-radius: 16px;
              padding: 28px; display: flex; flex-direction: column; gap: 12px; }
#tg-guest { display: flex; flex-direction: column; gap: 12px; }
.login-card { max-width: calc(100vw - 32px); }
.login-card h1 { margin: 0; font-size: 22px; font-weight: 600; }
.login-card p { margin: 0; }
.login-card input { border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; font: inherit;
                    background: var(--bg); color: var(--text); }
.login-card button { background: var(--text); color: var(--bg); border-radius: 10px; padding: 9px; font-weight: 600; }
.error { color: var(--bad); min-height: 1.2em; }

/* Узкое окно: только чат. Боковые панели скрыты, поэтому колонка одна (иначе чат попадал в колонку нулевой ширины). */
@media (max-width: 1100px) {
  #app, #app.no-side, #app.no-panel, #app.no-side.no-panel { grid-template-columns: 1fr; }
  #sidebar, #panel { display: none; }
  #app.mobile-side #sidebar, #app.mobile-panel #panel { display: flex; flex-direction: column; position: fixed;
    top: 0; bottom: 0; width: min(300px, 85vw); z-index: 20; box-shadow: 0 0 24px rgba(0, 0, 0, .25); }
  #app.mobile-side #sidebar { left: 0; }
  #app.mobile-panel #panel { right: 0; display: block; }
  #messages, #composer { padding-left: 16px; padding-right: 16px; }
  #audit-view, #files-view { padding: 8px 16px 24px; }
  .ftable td:nth-child(3) { display: none; }
}
