/* Тема берётся из Telegram (--tg-theme-*); в браузере — запасные цвета по системной теме. */
:root {
  --fb-bg: #ffffff;
  --fb-bg2: #f2f2f7;
  --fb-text: #111111;
  --fb-hint: #8a8a8e;
  --fb-link: #2481cc;
  --fb-btn: #2481cc;
  --fb-btn-text: #ffffff;
  --fb-danger: #e53935;
  --fb-section: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #17212b;
    --fb-bg2: #0e1621;
    --fb-text: #f5f5f5;
    --fb-hint: #8b98a5;
    --fb-link: #6ab3f3;
    --fb-btn: #5288c1;
    --fb-btn-text: #ffffff;
    --fb-danger: #ef5350;
    --fb-section: #17212b;
  }
}
:root {
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--fb-bg2));
  --section: var(--tg-theme-section-bg-color, var(--fb-section));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --btn: var(--tg-theme-button-color, var(--fb-btn));
  --btn-text: var(--tg-theme-button-text-color, var(--fb-btn-text));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));
  --border: color-mix(in srgb, var(--hint) 25%, transparent);
  --soft: color-mix(in srgb, var(--hint) 12%, transparent);
  --warn: #e0a100;
  --good: #2e9d4a;
  --radius: 12px;
  --vh: var(--tg-viewport-stable-height, 100dvh);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0; padding: 8px 10px; background: var(--soft); border-radius: 8px; max-height: 360px; overflow: auto; }
code { background: var(--soft); padding: 1px 4px; border-radius: 4px; }
h2 { margin: 4px 0 12px; font-size: 20px; }

.app { max-width: 760px; margin: 0 auto; }
.screen { padding: 12px 16px 96px; min-height: var(--vh); }
.hint { color: var(--hint); font-size: 13px; }
.small { font-size: 12px; margin: 6px 2px; }
.empty { color: var(--hint); text-align: center; padding: 32px 0; }
.label { color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; margin: 16px 2px 6px; }
.back { background: none; border: 0; color: var(--link); padding: 10px 16px 0; cursor: pointer; }

.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.runners { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip { border: 1px solid var(--border); background: var(--section); border-radius: 20px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.sel { border-color: var(--btn); }
.chip.off { color: var(--hint); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--good); }
.dot.off { background: var(--hint); }
.icon-btn { border: 1px solid var(--border); background: var(--section); border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 18px; }

.search, .input, .select {
  width: 100%; border: 1px solid var(--border); background: var(--section); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font: inherit; outline: none;
}
.search:focus, .input:focus { border-color: var(--btn); }
.select { padding: 8px 10px; font-size: 14px; min-width: 0; }
textarea.input { resize: none; }
textarea.big { min-height: 110px; resize: vertical; }

.group { margin-top: 16px; }
.group-head { padding: 0 4px 6px; display: flex; gap: 8px; align-items: baseline; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row {
  display: block; width: 100%; text-align: left; background: var(--section); border: 0;
  border-bottom: 1px solid var(--border); padding: 10px 12px; cursor: pointer;
}
.group .row:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.group .row:last-of-type { border-radius: 0 0 var(--radius) var(--radius); border-bottom: 0; }
.group .row:only-of-type { border-radius: var(--radius); }
.row.compact { border-radius: 10px; margin-bottom: 4px; border: 1px solid var(--border); }
.row.sel { border-color: var(--btn); box-shadow: 0 0 0 1px var(--btn) inset; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--hint); font-size: 12px; margin-top: 4px; }
.branch { color: var(--hint); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--soft); color: var(--hint); white-space: nowrap; }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge.st-running, .badge.st-starting { background: color-mix(in srgb, var(--btn) 18%, transparent); color: var(--btn); }
.badge.st-waiting { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.badge.st-idle { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.badge.st-error { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.pending-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.pending-row { text-align: left; border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--section)); border-radius: 10px; padding: 9px 12px; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.notice { margin: 10px 0; padding: 10px 12px; border-radius: 10px; background: var(--section); border: 1px solid var(--border); font-size: 14px; }
.notice.err { border-color: var(--danger); color: var(--danger); }
.notice.warn { border-color: var(--warn); }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--btn); color: var(--btn-text); border: 0; border-radius: 24px; padding: 12px 22px;
  font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.18); cursor: pointer;
}
.fab:disabled { opacity: .5; }

.btn { border: 1px solid var(--border); background: var(--section); border-radius: 10px; padding: 9px 14px; cursor: pointer; }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.btn.ghost { background: none; border: 0; color: var(--link); }
.btn.wide { width: 100%; margin-top: 14px; padding: 12px; }
.btn:disabled { opacity: .45; cursor: default; }
.more { display: block; margin: 0 auto 8px; }

/* чат */
.chat { display: flex; flex-direction: column; height: var(--vh); padding: 0; }
.chat-head { padding: 10px 14px 8px; background: var(--bg); border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--hint); font-size: 12px; margin-top: 2px; }
.controls { display: grid; grid-template-columns: 1.3fr 1fr 1.3fr; gap: 6px; margin-top: 8px; }
.chat .notice { margin: 8px 12px 0; }
.feed { flex: 1; overflow-y: auto; padding: 10px 12px 16px; -webkit-overflow-scrolling: touch; }
.msg { margin: 8px 0; padding: 8px 12px; border-radius: 14px; max-width: 92%; word-wrap: break-word; }
.msg.user { margin-left: auto; background: color-mix(in srgb, var(--btn) 16%, var(--section)); border-bottom-right-radius: 4px; }
.msg.bot { background: var(--section); border-bottom-left-radius: 4px; }
.msg.sub { opacity: .75; font-size: 14px; }
.rich .para { white-space: pre-wrap; }
.tool, .collapsible { margin: 4px 0; max-width: 100%; }
.tool.sub { margin-left: 14px; }
.tool-head {
  display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; cursor: pointer;
  background: var(--soft); border: 0; border-radius: 8px; padding: 6px 10px; font-size: 13px; color: var(--hint);
}
.tool-name { color: var(--text); font-weight: 500; white-space: nowrap; }
.tool-preview { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.tool-state.good { color: var(--good); }
.tool-state.bad, pre.bad { color: var(--danger); }
.tool-body { padding: 2px 0 2px 10px; border-left: 2px solid var(--border); margin: 4px 0 4px 6px; }
.tool-res-label { font-size: 12px; color: var(--hint); margin-top: 4px; }
pre.soft { color: var(--hint); }
.divider { text-align: center; color: var(--hint); font-size: 12px; margin: 10px 0; }
.divider.bad { color: var(--danger); }
.typing { color: var(--hint); font-size: 13px; padding: 4px 2px; }

.req { margin: 10px 0; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 8%, var(--section)); }
.req.done { border-color: var(--border); background: var(--section); opacity: .85; }
.req-head { font-weight: 600; margin-bottom: 4px; }
.req-preview { max-height: 200px; }
.req-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.req-actions .btn { flex: 1; }
.req-actions .btn.wide { flex-basis: 100%; margin-top: 0; text-align: left; }
.req-result { margin-top: 6px; font-weight: 500; }
.qform .q { margin-top: 8px; }
.q-text { margin-bottom: 6px; }
.opt { display: block; width: 100%; text-align: left; border: 1px solid var(--border); background: var(--section); border-radius: 10px; padding: 8px 12px; margin-bottom: 6px; cursor: pointer; }
.opt.sel { border-color: var(--btn); box-shadow: 0 0 0 1px var(--btn) inset; }

.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border);
}
.composer .input { flex: 1; max-height: 160px; }
.composer .btn { padding: 10px 14px; }

.projects { max-height: 42vh; overflow-y: auto; margin-top: 8px; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.modal { background: var(--bg); border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); width: 100%; max-width: 560px; }
.modal-title { font-weight: 600; font-size: 17px; margin-bottom: 8px; }
.modal-text { color: var(--hint); margin-bottom: 14px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.8); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; transition: all .2s; pointer-events: none; z-index: 20; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
