:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #6b7280; --border: #e3e6eb;
  --accent: #b3261e; --accent-2: #8f1d17; --user: #eef3ff; --code: #f1f3f6;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; }
a { color: var(--accent); }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; background: #1f2430; color: #fff; }
.topbar a { color: #fff; text-decoration: none; margin-right: 16px; }
.topbar .brand { font-weight: 700; }
.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topbar .muted { color: #aab; margin: 0 10px; }
.topbar .link { color: #fff; }
.container { max-width: 1100px; margin: 20px auto; padding: 0 16px; width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--accent); }
.inline { display: inline; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.narrow { max-width: 420px; margin: 40px auto; }
label { display: block; margin: 10px 0; }
input[type=email], input[type=password], input[type=text], input[type=number], textarea, input:not([type]) {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
.btn { display: inline-block; background: var(--accent); color: #fff; border: 0; padding: 9px 16px; border-radius: 8px; font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--accent-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.light { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.full { display: block; text-align: center; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.link.danger { color: var(--muted); font-size: 13px; }
.flash { max-width: 1100px; margin: 10px auto 0; padding: 0 16px; width: 100%; }
.flash div { padding: 10px 14px; border-radius: 8px; background: #e8f5e9; }
.errorlist { color: var(--accent); margin: 0; padding-left: 18px; }

/* chat */
.chat-layout { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
.sidebar { border-right: 1px solid var(--border); background: var(--panel); padding: 14px; overflow-y: auto; }
.conv-search { width: 100%; margin-top: 12px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: 14px; box-sizing: border-box; }
.conv-list { margin: 10px 0 14px; }
.conv-list ul { list-style: none; padding: 0; margin: 0 0 6px; }
.conv-group summary { cursor: pointer; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 6px 4px 4px; }
.conv-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-more { display: block; margin: 4px auto; font-size: 13px; }
.conv-empty { font-size: 14px; padding: 4px; }
.conv-list li { margin: 2px 0; }
.conv-list a { display: block; padding: 7px 9px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 14px; }
.conv-list li { display: flex; align-items: center; border-radius: 6px; }
.conv-list li a { flex: 1; min-width: 0; }
.conv-list li.active, .conv-list li:hover { background: var(--bg); }
.conv-delete { margin: 0; }
.conv-list .conv-delete button { padding: 4px 8px; font-size: 16px; line-height: 1; color: var(--muted); visibility: hidden; }
.conv-list li:hover .conv-delete button, .conv-list li.active .conv-delete button, .conv-list .conv-delete button:focus { visibility: visible; }
.conv-list .conv-delete button:hover { color: var(--accent); }
@media (hover: none) { .conv-list .conv-delete button { visibility: visible; } }
.chat { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 20px max(20px, calc(50% - 440px)); }
.empty { text-align: center; margin-top: 12vh; }
.msg { margin: 14px 0; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.bubble { max-width: 100%; padding: 12px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--border); }
.msg.user .bubble { background: var(--user); max-width: 80%; }
.answer.streaming { white-space: pre-wrap; }
.answer p:first-child { margin-top: 0; }
.answer p:last-child { margin-bottom: 0; }
.answer code { background: var(--code); padding: 1px 4px; border-radius: 4px; }
.cite { display: inline-block; font-size: 11px; line-height: 1; padding: 3px 5px; margin: 0 2px; border-radius: 4px; background: #fdecea; color: var(--accent); text-decoration: none; vertical-align: 2px; }
.cite:hover { background: var(--accent); color: #fff; }
.status { font-size: 13px; margin-bottom: 6px; }
/* ход идёт: мигающая точка перед текстом этапа (chat.js снимает класс с первым токеном) */
.status.working::before { content: "●"; margin-right: 6px; animation: status-pulse 1.2s ease-in-out infinite; }
@keyframes status-pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.sources { margin-top: 8px; font-size: 13px; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources li { margin: 6px 0; }
.snippet { color: var(--muted); font-size: 12px; white-space: pre-line; max-height: 4.5em; overflow: hidden; }
.ask-form { display: flex; flex-wrap: wrap; gap: 8px 10px; padding: 12px max(20px, calc(50% - 440px)); border-top: 1px solid var(--border); background: var(--panel); }
.ask-form textarea { resize: vertical; flex: 1 1 260px; min-width: 0; }
.ask-options { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
.ask-form select { flex: 0 1 auto; min-width: 0; max-width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
.ask-form select[hidden] { display: none; }
.model-tag { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.model-tag:empty { display: none; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.choices.held { display: none; }
.incomplete { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-top: 6px; }
.incomplete .btn { padding: 4px 10px; }
.choices .btn { padding: 6px 12px; }
.machine-chip { padding: 6px max(20px, calc(50% - 440px)); font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); background: var(--panel); }
.machine-chip[hidden] { display: none; }
.machine-label { color: var(--text); font-weight: 600; }
.applies { font-size: 12px; color: #8a5a00; }
.parts { margin-top: 8px; font-size: 13px; }
.parts summary { cursor: pointer; color: var(--muted); }
.parts li { margin: 6px 0; }
.parts .tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #e7f5ea; color: #1e6b33; }
.parts .tag.doc { background: #fff4e0; color: #8a5a00; }
.parts .small { font-size: 12px; margin-top: 4px; }
.parts-table { border-collapse: collapse; margin-top: 4px; font-size: 12px; }
.parts-table td { padding: 2px 8px 2px 0; vertical-align: top; }
.parts-table tr.matched td { font-weight: 600; }
.cite.catalog { background: #e7f5ea; color: #1e6b33; }
.cite.catalog:hover { background: #1e6b33; color: #fff; }
.support-refs { margin-top: 10px; font-size: 13px; color: var(--muted); }
.support-refs a.support { color: var(--accent); }
.outside-refs { margin-top: 10px; padding: 8px 12px; border-left: 3px solid var(--muted); font-size: 13px; }
.outside-refs ul { margin: 4px 0 0; }
.outside-found { margin: 0 0 12px; padding: 10px 14px; border-left: 4px solid var(--accent); }
.outside-found ul { margin: 4px 0 8px; }
.answer table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.answer th, .answer td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.balance { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; }
.balance-title { font-weight: 600; margin-bottom: 4px; }
.balance-value + .balance-title { margin-top: 8px; }
.balance-value b { font-size: 16px; color: var(--text); }
.balance-value.low b { color: var(--accent); }
.balance summary { cursor: pointer; color: var(--muted); margin-top: 6px; }
.balance-form { display: grid; gap: 6px; margin-top: 6px; }
.balance-form label { display: grid; gap: 2px; color: var(--muted); }
.balance-form input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font: inherit; }

/* documents */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; }
.pager { display: flex; gap: 8px; align-items: center; }
.page-input { width: 90px !important; }

@media (max-width: 760px) {
  .chat-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .ask-form { flex-wrap: wrap; }
  .ask-form select { flex: 1 1 100%; padding: 8px 10px; }
}
/* эксперт: оценка ответа и знания (expert.js, rag/knowledge_*.html) */
.expert { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.expert .btn { padding: 3px 10px; font-size: 13px; }
.expert .btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.expert-form { flex-basis: 100%; }
.expert-card { display: flex; flex-direction: column; gap: 8px; padding: 14px; margin-top: 4px; }
.expert-card label.radio, .expert-card label.check { display: block; font-size: 14px; }
.expert-card textarea, .expert-card input:not([type]), .expert-card select, .note-form input, .note-form textarea, .note-form select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; box-sizing: border-box; }
.note-fields { display: flex; flex-direction: column; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.note-fields[hidden], .row2[hidden] { display: none; }
.expert-materials { flex-basis: 100%; }
.expert-materials ul { margin: 4px 0 0; padding-left: 18px; }
.expert-card input[type=file] { display: block; margin-top: 4px; }
.expert-intro { font-size: 14px; padding: 8px 10px; border-left: 3px solid var(--accent); }
.expert-materials .check { margin-top: 4px; }
.expert-materials .check.ok { color: #1b7f3b; }
.expert-materials .check.bad { color: var(--accent); }
.note-page { max-width: 860px; }
.note-status { margin: 10px 0; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.note-status.current { background: #e7f5ea; color: #1e6b33; }
.note-status.replaced, .note-status.pending { background: #fff4e0; color: #8a5a00; }
.note-status.retired { background: #fdecea; color: var(--accent); }
.note-form { display: flex; flex-direction: column; gap: 10px; max-width: 860px; }
.knowledge-search { margin: 10px 0 14px; max-width: 420px; }
.knowledge-search input { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; font: inherit; box-sizing: border-box; }

/* раздел «Документы» деревом техники (static/js/documents.js) */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.tree-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 8px; }
.tree-tools input[type=search] { flex: 1 1 260px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
#tree-extra, #tree-root { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; }
#tree-extra:empty { display: none; }
.tree-node > summary { cursor: pointer; padding: 4px 0; }
.tree-children, .tree-model { margin-left: 18px; border-left: 1px solid var(--border); padding-left: 10px; }
.tree-node.model > summary .tree-title { font-weight: 600; }
.tree-badges { margin-left: 8px; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; margin-left: 6px; background: var(--code); color: var(--text); text-decoration: none; }
.badge.docs { background: var(--user); }
.badge.catalog { background: #eaf6ec; color: #1e6b32; }
a.badge.catalog:hover { text-decoration: underline; }
.doc-machines { margin-top: 4px; }
.doc-machines .badge { margin: 2px 4px 0 0; }
.tree-docs { margin: 4px 0 8px; padding-left: 18px; }
.tree-doc { margin: 3px 0; }
.tree-variants ul { margin: 4px 0 8px; padding-left: 18px; }
.tree-variants li { margin: 3px 0; }
.tree-variants > summary { cursor: pointer; color: var(--muted); }

/* «Документы»: ход индексации и загрузки (documents_status.js) */
.doc-progress-line { font-size: 13px; margin: 4px 0; }
.doc-progress-line.working::before { content: "●"; margin-right: 6px; animation: status-pulse 1.2s ease-in-out infinite; }
.upload-progress { margin-top: 8px; font-size: 13px; }
.activity-filter { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin: 10px 0 14px; }
.activity-filter label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.activity-filter select, .activity-filter input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font: inherit; }
.activity-text { white-space: pre-wrap; }
.activity-kind { white-space: nowrap; font-weight: 600; }
.activity-bot .activity-kind { font-weight: 400; color: var(--muted); }
/* «Pyrus update» на странице «Документы» */
.pyrus { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem; }
.pyrus p, .pyrus #pyrus-state { flex-basis: 100%; margin: 0; }
.pagination { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.pagination a, .pagination b { padding: 2px 8px; }
#upload-form { margin-bottom: 16px; }
