:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2f6fed; --accent-text: #fff; --ok: #1f9d55; --warn: #c77700; --err: #d23c3c;
  --mark: #eef3ff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171d; --panel: #1c2029; --text: #e6e9ef; --muted: #99a1b3; --line: #2c313c; --accent: #5b8cff; --mark: #1f2940; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header.top { display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
header.top h1 { font-size: 18px; margin: 0; font-weight: 600; }
main { max-width: 1400px; margin: 0 auto; padding: 20px 24px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
input[type=text], input[type=url], input[type=password], input[type=email], select { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
button { padding: 9px 16px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); font: inherit; cursor: pointer; white-space: nowrap; }
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; }
/* Формы в строку на узком экране переносятся, а не сжимают поля в ноль. */
form.row { flex-wrap: wrap; }
form.row > input { flex: 1 1 160px; min-width: 160px; }
.muted { color: var(--muted); }
.error { color: var(--err); margin-top: 8px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); color: var(--muted); }
.badge.live { color: var(--ok); border-color: var(--ok); }
.badge.processing, .badge.queued, .badge.starting { color: var(--warn); border-color: var(--warn); }

table.list { width: 100%; border-collapse: collapse; }
table.list td, table.list th { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; }

.meeting { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .meeting { grid-template-columns: 1fr; } }
.transcript { max-height: calc(100vh - 170px); overflow-y: auto; }
.utt { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; padding: 6px 0; }
.utt .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; padding-top: 1px; }
.utt .who { font-weight: 600; margin-right: 6px; }
.share { margin: 8px 0; padding: 10px 12px; background: var(--mark); border-radius: 8px; }
.share .frames { display: flex; gap: 8px; overflow-x: auto; margin-top: 8px; }
.share img { height: 90px; border-radius: 4px; border: 1px solid var(--line); cursor: zoom-in; }
.side .panel p { margin: 0; line-height: 1.5; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { padding: 4px 0; }
.people .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-right: 8px; }
.people .dot.on { background: var(--ok); }
.agreements { margin: 0; padding-left: 20px; }
.agreements li { margin-bottom: 8px; line-height: 1.45; }
.agreements .meta { font-size: 13px; color: var(--muted); }
.agreements li.canceled .text { text-decoration: line-through; color: var(--muted); }
.link-box { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
dialog.zoom { border: 0; padding: 0; max-width: 96vw; max-height: 96vh; background: transparent; }
dialog.zoom img { max-width: 96vw; max-height: 96vh; display: block; }
dialog.zoom::backdrop { background: rgba(0, 0, 0, .75); }
footer.legal { max-width: 1400px; margin: 0 auto; padding: 4px 24px 20px; font-size: 12px; }

/* Навигация */
.nav { display: flex; gap: 14px; margin-left: 8px; }
.nav a { color: var(--muted); }
.nav a.on { color: var(--text); font-weight: 600; }

/* Страница «Граф» */
.graph-page { display: grid; grid-template-columns: 280px minmax(0, 1fr) 380px; gap: 16px; align-items: start; max-width: none; }
@media (max-width: 1200px) { .graph-page { grid-template-columns: 1fr; } }
.small { font-size: 12px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; flex: none; }
.labels, .nodes, .rels { list-style: none; margin: 0; padding: 0; }
.labels li, .nodes li { padding: 5px 6px; border-radius: 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.labels li:hover, .nodes li:hover { background: var(--mark); }
.labels li.on { background: var(--mark); font-weight: 600; }
.nodes { max-height: 420px; overflow-y: auto; margin-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
#cy { height: 520px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: 13px ui-monospace, Consolas, monospace; resize: vertical; }
.center .row { margin-top: 8px; }
.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; margin-top: 8px; }
table.list caption { caption-side: bottom; text-align: left; padding-top: 6px; }
table.list code { font-size: 12px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; color: #fff; font-size: 12px; text-transform: none; letter-spacing: 0; }
.card-title { font-size: 16px; font-weight: 600; margin: 4px 0 12px; word-break: break-word; }
.props { display: grid; grid-template-columns: 1fr; gap: 3px; }
.props label { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; }
.props input, .props textarea { font-size: 13px; }
.props .row { margin-top: 8px; }
.add-prop input { flex: 1; }
h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 8px; }
.rels { max-height: 300px; overflow-y: auto; }
.rels li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; padding: 4px 0; align-items: center; font-size: 13px; }
.rels li a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.x { cursor: pointer; color: var(--muted); padding: 0 4px; }
.x:hover { color: var(--err); }
button.danger { background: transparent; color: var(--err); border: 1px solid var(--err); }
.picker { margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 8px; }
.picker .nodes { max-height: 240px; margin: 0; }

/* Команды агенту и переход к моменту разговора */
.commands { list-style: none; margin: 0; padding: 0; }
.commands li { padding: 6px 0; border-bottom: 1px solid var(--line); line-height: 1.45; }
.commands li:last-child { border-bottom: 0; }
.commands .meta { font-size: 13px; color: var(--muted); }
.commands li.canceled > div:first-child { text-decoration: line-through; color: var(--muted); }
.commands li.failed .meta { color: var(--err); }
.utt.hl { background: var(--mark); border-radius: 6px; }
.setting-label { min-width: 230px; color: var(--muted); font-size: 13px; }

/* Подсказки при вводе (suggest.js) */
.suggest { position: fixed; z-index: 50; list-style: none; margin: 0; padding: 4px; max-width: 520px; max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.suggest li { padding: 7px 10px; border-radius: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.suggest li.on, .suggest li:hover { background: var(--mark); }
.suggest li .hint { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest li.new { color: var(--accent); }

/* Клиент: сведения, проекты, звонки */
.facts, .projects, .calls { list-style: none; margin: 0; padding: 0; }
.facts li, .projects li, .calls li { padding: 6px 0; border-bottom: 1px solid var(--line); line-height: 1.45; }
.facts li:last-child, .projects li:last-child, .calls li:last-child { border-bottom: 0; }
.facts .meta { font-size: 13px; color: var(--muted); }
.facts + h3, #facts h3:first-child { margin-top: 4px; }
#about-form textarea, .projects textarea { font-family: inherit; font-size: 14px; }

/* Чат с агентом (chat.js) */
.chat-log { max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.chat .msg { padding: 8px 11px; border-radius: 10px; line-height: 1.5; max-width: 92%; }
.chat .msg p { margin: 0 0 6px; }
.chat .msg p:last-of-type { margin-bottom: 0; }
.chat .msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); white-space: pre-wrap; }
.chat .msg.assistant { align-self: flex-start; background: var(--mark); }
.chat a.src { display: inline-block; min-width: 18px; padding: 0 4px; margin: 0 1px; border-radius: 4px; font-size: 11px; text-align: center; background: var(--panel); border: 1px solid var(--line); vertical-align: 1px; }
.chat-hints { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chat-hints button, .chat button.small { padding: 4px 10px; font-size: 12px; }
.chat textarea { font-family: inherit; font-size: 14px; }
.chat-form { display: flex; flex-direction: column; gap: 6px; }

/* Подсказки суфлёра */
.hints-panel { border-color: var(--warn); }
.hints { list-style: none; margin: 0 0 6px; padding: 0; max-height: 360px; overflow-y: auto; }
.hints li { padding: 7px 0; border-bottom: 1px solid var(--line); line-height: 1.45; }
.hints li:last-child { border-bottom: 0; }
.hints .meta { font-size: 12px; color: var(--muted); }
.hints .q { font-style: italic; color: var(--muted); }
.hints p { margin: 0; }
.hints a.src { display: inline-block; min-width: 18px; padding: 0 4px; border-radius: 4px; font-size: 11px; text-align: center; border: 1px solid var(--line); }

/* Заметки узнавания по голосу */
.voices { list-style: none; margin: 10px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--mark); font-size: 13px; line-height: 1.45; }
.voices li + li { margin-top: 6px; }
.voices button { margin-top: 4px; padding: 3px 9px; font-size: 12px; }
.utt .was { font-size: 11px; color: var(--warn); margin-right: 6px; }

/* Кто вошёл — справа в шапке */
.user-nav { margin-left: auto; }
.connections { margin: 0; padding-left: 18px; line-height: 1.8; }

/* Раздел в меню, который сейчас не работает (модуль не готов) */
.nav a.off { opacity: .5; }

/* Почта: папки — список — письмо */
.mail-page { display: grid; grid-template-columns: 210px 380px minmax(0, 1fr); gap: 16px; align-items: start; max-width: none; }
@media (max-width: 1100px) { .mail-page { grid-template-columns: 1fr; } }
.mail-page > #not-ready { grid-column: 1 / -1; max-width: 720px; }
.mail-folders ul, #messages { list-style: none; margin: 0; padding: 0; }
.mail-folders li { display: flex; justify-content: space-between; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.mail-folders li:hover, .mail-folders li.on { background: var(--mark); }
.mail-folders li b { font-size: 12px; }
#messages { max-height: calc(100vh - 230px); overflow-y: auto; margin: 10px 0; }
#messages li { padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
#messages li:hover, #messages li.on { background: var(--mark); }
#messages li.unseen .from, #messages li.unseen .subj { font-weight: 600; }
#messages .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
#pager { gap: 6px; }
.mail-reader { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; align-items: start; }
@media (max-width: 1400px) { .mail-reader { grid-template-columns: 1fr; } }
.mail-subject { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 6px; }
.mail-reader .meta { font-size: 13px; color: var(--muted); }
.mail-actions { margin: 10px 0; gap: 6px; }
.mail-actions button, #pager button { padding: 4px 10px; font-size: 12px; }
.attach { display: inline-block; margin: 0 10px 8px 0; font-size: 13px; }
iframe.mail-body { width: 100%; height: calc(100vh - 300px); border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.mail-text { white-space: pre-wrap; line-height: 1.5; overflow-wrap: anywhere; }
.client-card { border-left: 3px solid var(--accent); padding-left: 12px; font-size: 13px; }
.client-card ul { margin: 0; padding-left: 16px; }
.client-card h3 { margin: 12px 0 4px; }
dialog.compose { width: min(760px, 94vw); border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); padding: 18px; }
dialog.compose::backdrop { background: rgba(0, 0, 0, .4); }
dialog.compose textarea { font-family: inherit; font-size: 14px; }

/* Администрирование: вкладки */
main.admin { max-width: 1200px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; color: var(--muted); margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.on { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 600; }

/* Telegram: чаты — переписка */
.tg-page { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; max-width: 1300px; }
@media (max-width: 900px) { .tg-page { grid-template-columns: 1fr; } }
.tg-page > #not-ready { grid-column: 1 / -1; max-width: 720px; }
#chats { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 220px); overflow-y: auto; }
#chats li { padding: 8px 6px; border-bottom: 1px solid var(--line); }
.tg-page #chats li[data-id]:not(.mark-row) { cursor: pointer; }
#chats li.on, .tg-page #chats li[data-id]:not(.mark-row):hover { background: var(--mark); }
#chats form.mark { margin-top: 6px; gap: 6px; }
#chats form.mark input { flex: 1 1 140px; min-width: 120px; padding: 5px 8px; }
#chats form.mark button { padding: 4px 10px; font-size: 12px; }
.tg-messages { list-style: none; margin: 10px 0; padding: 0; max-height: calc(100vh - 330px); overflow-y: auto; }
.tg-messages li { padding: 6px 10px; margin: 4px 0; border-radius: 10px; background: var(--mark); max-width: 85%; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.tg-messages li.out { margin-left: auto; background: var(--bg); border: 1px solid var(--line); }
.tg-chat textarea { font-family: inherit; font-size: 14px; }

/* Агент внутри СУВР (public/embed.js): меню даёт СУВР — своё меню и шапка с названием приложения скрыты,
   шапка с названием страницы (клиент, звонок) остаётся без меню. */
html.embedded header.top .nav { display: none; }
html.embedded header.top:not(:has(h1[id])) { display: none; }
html.embedded .embed-back { padding: 6px 16px; border-bottom: 1px solid var(--line); background: var(--panel); font-size: 14px; }

/* Страница «Граф»: режимы «Таблицы» (простой) и «Граф» (расширенный) */
.mode-bar { display: flex; align-items: center; gap: 8px; padding: 8px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.mode-btn { padding: 5px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); color: var(--muted); cursor: pointer; font-size: 13px; }
.mode-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.graph-page.simple { grid-template-columns: 260px minmax(0, 1fr); }
.labels li.group { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; cursor: default; margin-top: 10px; padding-bottom: 2px; }
.labels li.group:hover { background: none; }
.crumbs { font-size: 14px; margin: 0 0 10px; color: var(--muted); }
.crumbs a { color: var(--accent); }
.crumbs span { color: var(--text); font-weight: 600; }
.table-wrap.tall { max-height: none; }
table.grid td.first a { color: var(--text); font-weight: 500; }
table.grid td { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.fields th { text-align: left; width: 220px; color: var(--text); font-weight: 500; vertical-align: top; }
table.fields td { white-space: pre-wrap; word-break: break-word; }
.related { list-style: none; margin: 0; padding: 0; }
.related li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.related li:last-child { border-bottom: 0; }
.related li a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.related li a b { color: var(--accent); }
.pager { margin-top: 8px; }
.pager .spacer { flex: 1; }
.schema-cy { height: 560px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }

/* Почта: несколько ящиков, действия, вложения */
.bulk { gap: 6px; flex-wrap: wrap; margin: 6px 0; }
#messages li .pick { margin-right: 6px; }
#messages li.flagged .from { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 3px 8px; border: 1px solid var(--line); border-radius: 99px; font-size: 12px; }
label.btn-like { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; color: var(--muted); }
label.btn-like:hover { color: var(--text); }
.panel.hl { outline: 2px solid var(--accent); transition: outline .3s; }
details.panel summary { cursor: pointer; list-style: revert; }
details.panel summary h2 { margin: 0; }
.group-head { margin: 10px 0 2px; font-weight: 600; font-size: 13px; }
.group-head a { color: var(--text); }
.group-head + .commands { margin-left: 12px; }
details.filter { position: relative; font-size: 13px; }
details.filter summary { cursor: pointer; padding: 5px 12px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); list-style: none; }
details.filter[open] summary { color: var(--text); }
.filter-body { position: absolute; right: 0; z-index: 30; margin-top: 6px; width: 320px; padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); display: flex; flex-direction: column; gap: 8px; }
.filter-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.filter-list label { display: flex; gap: 8px; align-items: center; cursor: pointer; }

/* Разделы-инструменты (Граф, Справка) — правее основных, разделитель */
.nav .nav-gap { display: inline-block; width: 14px; }
.nav a.tool { opacity: .8; }

/* Ссылка и подпись, выглядящие кнопкой (скачать/загрузить файл) */
a.button, label.button { display: inline-block; cursor: pointer; text-decoration: none; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); color: var(--text); font: inherit; white-space: nowrap; }

/* Окно входа Яндекса в портале: снимок страницы, по которому кликают и печатают */
.remote-view { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; max-width: 1000px; }
.remote-view img { display: block; width: 100%; height: auto; cursor: text; outline: none; }
.remote-view img:focus { box-shadow: inset 0 0 0 2px var(--accent); }
