:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #1f2b37);
  --card: var(--tg-theme-section-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #e7ecf2);
  --muted: var(--tg-theme-hint-color, #8a9bad);
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --mine: #2b5278;
  --line: rgba(127, 140, 155, .18);
  --ok-bg: #1d4a2f; --ok: #6ee7a0;
  --wait-bg: #4a3a14; --wait: #ffcf5c;
  --err-bg: #4a1d1d; --err: #ff8a80;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
#app { height: 100%; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }
.center { margin: auto; text-align: center; padding: 24px; }
.muted { color: var(--muted); }
.banner { position: fixed; top: 0; left: 0; right: 0; background: var(--wait-bg); color: var(--wait); text-align: center; padding: 6px; font-size: 13px; z-index: 50; }

/* список */
.top { padding: 14px 16px 8px; display: flex; justify-content: space-between; align-items: center; }
.top h1 { font-size: 24px; line-height: 1.1; }
.btn { background: var(--accent); color: var(--accent-text); border-radius: 12px; padding: 0 16px; min-height: 44px; font-weight: 600; }
.btn.wide { width: 100%; }
.search { margin: 0 16px 10px; background: var(--card); border-radius: 12px; padding: 0 12px; min-height: 40px; width: calc(100% - 32px); color: var(--text); border: 0; font: inherit; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.s { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: center; width: 100%; text-align: left; }
.s:active { opacity: .72; }
.av { width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; background: var(--card); }
.s .t { flex: 1; min-width: 0; }
.s .n { font-weight: 600; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.s .n span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s .n .time { font-weight: 400; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.s .p { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 8px; margin-top: 5px; display: inline-block; }
.tag.run { background: var(--ok-bg); color: var(--ok); }
.tag.wait { background: var(--wait-bg); color: var(--wait); }
.tag.err { background: var(--err-bg); color: var(--err); }
.tag.idle { background: var(--card); color: var(--muted); }
.tabs { display: flex; border-top: 1px solid var(--line); background: var(--bg2); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 13px; color: var(--muted); gap: 2px; }
.tabs .on { color: var(--accent); }
.tabs i { font-style: normal; font-size: 20px; position: relative; }
.badge { position: absolute; top: -6px; right: -14px; background: #e5534b; color: #fff; font-size: 12px; border-radius: 9px; padding: 0 6px; line-height: 17px; }

/* розмова */
.head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.head .av { width: 38px; height: 38px; font-size: 18px; }
.head .info { flex: 1; min-width: 0; }
.head .n { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head .p { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head .p.run { color: var(--ok); }
.stop { background: var(--err-bg); color: var(--err); font-size: 14px; padding: 0 12px; border-radius: 10px; min-height: 36px; }
.more { min-width: 44px; min-height: 44px; font-size: 20px; color: var(--muted); }
.chips { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { font-size: 13px; padding: 0 12px; min-height: 32px; border-radius: 16px; background: var(--card); color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.chip .ct { max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.chip.on { background: var(--accent); color: var(--accent-text); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; }
.msgs { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.me { align-self: flex-end; background: var(--mine); color: #fff; padding: 9px 12px; border-radius: 16px 16px 4px 16px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.ai { align-self: flex-start; background: var(--card); padding: 9px 12px; border-radius: 16px 16px 16px 4px; max-width: 92%; word-wrap: break-word; overflow-x: auto; }
.ai p + p, .ai ul, .ai ol, .ai pre, .ai table { margin-top: 6px; }
.ai ul, .ai ol { padding-left: 20px; }
.ai pre { background: rgba(0,0,0,.25); padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.ai code { font-size: 13px; }
.ai table { border-collapse: collapse; font-size: 13px; }
.ai td, .ai th { border: 1px solid var(--line); padding: 4px 6px; }
.ai a { color: var(--accent); }
.act { align-self: flex-start; max-width: 92%; background: rgba(0,0,0,.15); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 13px; color: var(--muted); }
.act summary { color: var(--text); font-weight: 600; cursor: pointer; min-height: 28px; display: flex; align-items: center; }
.act li { list-style: none; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err-msg { align-self: stretch; background: var(--err-bg); color: var(--err); padding: 8px 12px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; }
.notice { align-self: center; color: var(--muted); font-size: 13px; }
.img { align-self: flex-start; max-width: 92%; border-radius: 12px; display: block; }
.file { align-self: flex-start; background: var(--card); border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; min-height: 44px; }
.typing { color: var(--ok); font-size: 13px; padding: 0 4px; }
.attach { display: flex; gap: 6px; padding: 6px 12px 0; flex-wrap: wrap; background: var(--bg2); }
.attach span { background: var(--card); border-radius: 10px; padding: 4px 8px; font-size: 13px; }
.input { display: flex; gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--bg2); align-items: flex-end; }
.input textarea { flex: 1; background: var(--card); border: 0; border-radius: 18px; padding: 10px 14px; color: var(--text); font: inherit; resize: none; max-height: 140px; min-height: 42px; }
.ic { width: 42px; height: 42px; border-radius: 50%; background: var(--card); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.ic.primary { background: var(--accent); color: var(--accent-text); }
.ic.rec { background: var(--err); color: #fff; }

/* нова сесія */
.dim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; background: var(--bg2); border-radius: 22px 22px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); z-index: 21; max-height: 90%; overflow-y: auto; }
.sheet h2 { font-size: 20px; margin-bottom: 4px; }
.sheet .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.proj { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--card); margin-bottom: 8px; width: 100%; text-align: left; min-height: 56px; }
.proj.on { outline: 2px solid var(--accent); }
.proj .av { width: 38px; height: 38px; font-size: 18px; }
.proj small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.field { width: 100%; background: var(--card); border: 0; border-radius: 12px; padding: 0 12px; min-height: 44px; color: var(--text); font: inherit; margin: 6px 0 12px; }

/* скелетон */
.sk { background: linear-gradient(90deg, var(--card) 0%, var(--bg2) 50%, var(--card) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }

/* задачі агентів і знання */
.sec { padding: 14px 16px 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.more-row { width: 100%; min-height: 48px; color: var(--accent); font-weight: 600; border-bottom: 1px solid var(--line); }
.hint { margin: 0 16px 8px; color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.s .p.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }
.btn.ghost { background: var(--card); color: var(--text); }
.field.area { padding: 10px 12px; resize: none; line-height: 1.4; margin: 0 0 10px; display: block; }
.sheet .field.area { margin-top: 2px; }
.task-head { align-items: flex-start; padding: 10px 12px; }
.task-head .av { margin-top: 2px; }
.task-head .req { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.task-head .tag { margin-top: 6px; }
.cancel { min-width: 44px; min-height: 44px; font-size: 18px; padding: 0; }
.blk-h { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: 4px; }
.steps { list-style: none; background: var(--card); border-radius: 12px; padding: 4px 12px; }
.steps li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.steps li:last-child { border-bottom: 0; }
.steps .si { width: 18px; text-align: center; flex-shrink: 0; }
.steps .muted { font-size: 13px; min-width: 0; overflow-wrap: anywhere; }
.wide-card { align-self: stretch; max-width: none; }
.ai.wide-card { border-radius: 12px; }
.chips.flat { padding: 0; border-bottom: 0; flex-shrink: 0; }
.act.wide-card summary { min-height: 44px; }
.act[open] summary { margin-bottom: 6px; }
.ai.flat-card { background: none; padding: 0; color: var(--text); font-size: 14px; max-width: none; }
.warn { background: var(--wait-bg); color: var(--wait); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.warn ul { padding-left: 18px; margin-top: 6px; }
.warn li + li { margin-top: 4px; }
.row .ic { width: 44px; height: 44px; }
.wide-card h1 { font-size: 20px; line-height: 1.25; margin: 4px 0 6px; }
.wide-card h2 { font-size: 17px; margin: 10px 0 4px; }
.wide-card h3, .wide-card h4 { font-size: 15px; margin: 8px 0 4px; }
.attach .att-img { height: 56px; width: auto; max-width: 96px; border-radius: 8px; object-fit: cover; display: block; }
.attach .att { position: relative; padding: 0; min-height: 44px; display: flex; align-items: center; }
.attach .att-x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--err-bg); color: var(--err); font-size: 12px; display: flex; align-items: center; justify-content: center; }
button:disabled { opacity: .5; }
