/* DemoBot — дизайн-система консолей: токены + компоненты.
   Светлая тема в :root, тёмная — в [data-theme="dark"] на <html>.
   Оболочка (меню, шапка, сетка страницы) — отдельно, в console.css. */

:root{
  color-scheme:light;
  /* поверхности */
  --bg:#f7f8fa;
  --surface:#ffffff;
  --surface-2:#f2f4f7;
  --surface-3:#e9ecf1;
  --border:#e6e8ec;
  --border-strong:#d3d7de;
  /* текст */
  --text:#111827;
  --text-2:#4b5563;
  --text-3:#6b7280;
  --text-4:#9aa1ab;
  /* акцент — один, для главных действий и активных состояний */
  --accent:#3b82f6;
  --accent-hover:#2f6fe0;
  --accent-contrast:#ffffff;
  --accent-soft:#eaf2fe;
  --accent-text:#1d5fd0;
  /* статусы */
  --success:#15803d;
  --success-soft:#e8f7ee;
  --warning:#b45309;
  --warning-soft:#fdf3e0;
  --warning-line:#f0dcb2;
  --danger:#dc2626;
  --danger-soft:#fdecec;
  --danger-hover:#b91c1c;
  --danger-ring:rgba(220,38,38,.35);
  /* форма */
  --radius-xs:5px;
  --radius-s:8px;
  --radius:10px;
  --radius-l:14px;
  --shadow-s:0 1px 2px rgba(16,24,40,.06);
  --shadow-m:0 6px 20px rgba(16,24,40,.10);
  --shadow-l:0 24px 64px rgba(16,24,40,.20);
  --ring:0 0 0 3px rgba(59,130,246,.28);
  --overlay:rgba(17,24,39,.45);
  --font:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  --mono:ui-monospace,"SF Mono",Consolas,"Liberation Mono",monospace;
  --chevron:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");

  /* прежние имена токенов: для разметки и скриптов, которые ещё не переведены на новые */
  --card:var(--surface);
  --muted:var(--text-3);
  --acc:var(--accent);
  --acc2:var(--accent-hover);
  --line:var(--border);
  --ok:var(--success);
  --err:var(--danger);
  --warn:var(--warning);
  --soft:var(--surface-2);
}

[data-theme="dark"]{
  color-scheme:dark;
  --bg:#0f1115;
  --surface:#16191f;
  --surface-2:#1c2027;
  --surface-3:#262b34;
  --border:#252a33;
  --border-strong:#353b46;
  --text:#e7e9ee;
  --text-2:#b6bcc8;
  --text-3:#8b93a4;
  --text-4:#5d6575;
  --accent:#5b9dff;
  --accent-hover:#74aeff;
  --accent-contrast:#0b1220;
  --accent-soft:#152538;
  --accent-text:#8dbcff;
  --success:#3fd68f;
  --success-soft:#0f2a1f;
  --warning:#f5b544;
  --warning-soft:#2d2210;
  --warning-line:#5a4514;
  --danger:#f37373;
  --danger-soft:#3a191b;
  --danger-hover:#ff8a8a;
  --danger-ring:rgba(243,115,115,.4);
  --shadow-s:0 1px 2px rgba(0,0,0,.5);
  --shadow-m:0 6px 20px rgba(0,0,0,.45);
  --shadow-l:0 24px 64px rgba(0,0,0,.6);
  --ring:0 0 0 3px rgba(91,157,255,.35);
  --overlay:rgba(0,0,0,.6);
  --chevron:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238b93a4' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
}

/* ---------- база ---------- */
*,*::before,*::after{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;background:var(--bg);color:var(--text);font:14px/1.5 var(--font);-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}
h1,h2,h3,h4,p{margin:0}
a{color:var(--accent-text);text-decoration:none}
a:hover{text-decoration:underline}
code{padding:1px 5px;border-radius:var(--radius-xs);background:var(--surface-2);font:12.5px var(--mono)}
img,svg{display:block}
*{scrollbar-width:thin;scrollbar-color:var(--border-strong) transparent}
::selection{background:var(--accent-soft)}
:focus-visible{outline:none;box-shadow:var(--ring)}
.spacer{flex:1}

/* ---------- кнопки ---------- */
/* базовые правила обёрнуты в :where() — нулевая специфичность, чтобы классы-компоненты их переопределяли */
:where(button),.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:32px;padding:0 12px;border:1px solid transparent;border-radius:var(--radius-s);background:var(--accent);color:var(--accent-contrast);font:600 13px/1 var(--font);white-space:nowrap;cursor:pointer;text-decoration:none;transition:background .15s,border-color .15s,color .15s}
:where(button:hover),.btn:hover{background:var(--accent-hover);text-decoration:none}
:where(button:active),.btn:active{transform:translateY(.5px)}
:where(button:disabled),.btn:disabled,.btn[aria-disabled="true"]{opacity:.55;cursor:default;transform:none}
:where(button.ghost),.btn-ghost{background:var(--surface);border-color:var(--border-strong);color:var(--text)}
:where(button.ghost:hover),.btn-ghost:hover{background:var(--surface-2);border-color:var(--text-4)}
/* опасное второстепенное действие (удалить в строке таблицы): без заливки */
:where(button.danger),.btn-danger-ghost{background:var(--surface);color:var(--danger)}
:where(button.danger:hover),.btn-danger-ghost:hover{background:var(--danger-soft)}
/* опасное главное действие (подтвердить удаление): заливка */
.btn-danger{background:var(--danger);color:#fff}
.btn-danger:hover{background:var(--danger-hover)}
.btn-sm{height:26px;padding:0 9px;border-radius:var(--radius-xs);font-size:12px}
.btn-lg{height:38px;padding:0 16px;font-size:14px}
.btn-block{width:100%}
button svg,.btn svg{flex:none;width:15px;height:15px}
/* в таблицах кнопки компактные */
td button{height:26px;padding:0 9px;border-radius:var(--radius-xs);font-size:12px}
.icon-btn{width:32px;height:32px;padding:0;border-color:transparent;background:transparent;color:var(--text-3)}
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
.icon-btn.sm{width:26px;height:26px;border-radius:var(--radius-xs)}

/* ---------- поля ---------- */
:where(input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]):not([type=range]):not([type=hidden])),select,textarea{
  width:100%;height:32px;padding:0 10px;border:1px solid var(--border-strong);border-radius:var(--radius-s);background:var(--surface);color:var(--text);font:inherit;font-size:13.5px;transition:border-color .15s,box-shadow .15s
}
textarea{height:auto;min-height:80px;padding:8px 10px;line-height:1.5;resize:vertical}
input::placeholder,textarea::placeholder{color:var(--text-4)}
input:hover,select:hover,textarea:hover{border-color:var(--text-4)}
input:focus,select:focus,textarea:focus{outline:none;border-color:var(--accent);box-shadow:var(--ring)}
input:disabled,select:disabled,textarea:disabled{background:var(--surface-2);color:var(--text-3);cursor:not-allowed}
select{padding-right:28px;background-image:var(--chevron);background-repeat:no-repeat;background-position:right 9px center;background-size:14px;appearance:none}
input[type=date]{padding-right:6px}
input[type=date]::-webkit-calendar-picker-indicator{opacity:.55;cursor:pointer}
input[type=color]{width:40px;height:32px;padding:2px;border:1px solid var(--border-strong);border-radius:var(--radius-s);background:var(--surface);cursor:pointer}
input[type=file]{font-size:12.5px;color:var(--text-3)}
input[type=file]::file-selector-button{height:26px;margin-right:10px;padding:0 10px;border:1px solid var(--border-strong);border-radius:var(--radius-xs);background:var(--surface);color:var(--text);font:600 12px var(--font);cursor:pointer}
input[type=checkbox],input[type=radio]{width:15px;height:15px;margin:0;accent-color:var(--accent);cursor:pointer}
label{display:block;margin:0 0 12px;font-size:12.5px;font-weight:500;color:var(--text-2)}
label > input,label > select,label > textarea,label > div{margin-top:5px}
label.check{display:flex;align-items:center;gap:8px;color:var(--text);font-size:13px;font-weight:400;cursor:pointer}
.snippet,textarea.snippet{font:12px/1.5 var(--mono)}

/* ---------- таблицы ---------- */
.table-wrap{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:13px}
th{padding:8px 10px;border-bottom:1px solid var(--border);text-align:left;font-size:11.5px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--text-3);white-space:nowrap}
td{padding:9px 10px;border-bottom:1px solid var(--border);vertical-align:top;text-align:left}
tbody tr:last-child td{border-bottom:0}
tbody tr:hover td{background:var(--surface-2)}
tr.clickable{cursor:pointer}
td select{height:26px;padding:0 22px 0 8px;font-size:12px;background-position:right 6px center}
td input[type=date]{width:132px;height:26px;padding:0 6px;font-size:12px}
.sub,.muted{color:var(--text-3);font-size:12.5px}
.sub.err{color:var(--danger)}
.sub.warn{color:var(--warning)}
/* ячейка-ссылка на ветку сессии */
td.session{cursor:pointer;text-decoration:underline dotted;text-underline-offset:3px}
td.session:hover{color:var(--accent-text)}
.vote{display:inline-flex;color:var(--text-4)}
.vote.up{color:var(--success)}
.vote.down{color:var(--danger)}
.vote svg{width:14px;height:14px}
.num{text-align:right;font-variant-numeric:tabular-nums}
.nowrap{white-space:nowrap}
.pre{white-space:pre-wrap;word-break:break-word}
.pre-line{white-space:pre-line}
.cell-actions{display:flex;flex-wrap:wrap;gap:6px}
/* компактные действия в таблице: иконки в одну строку */
.cell-tools{display:flex;align-items:center;justify-content:flex-end;gap:4px;white-space:nowrap}
.cell-tools input[type=checkbox]{margin:0 4px}
.icon-btn.danger{color:var(--danger)}
.icon-btn.danger:hover{background:var(--danger-soft);color:var(--danger)}
/* в таблицах блоку действий нужна опорная ширина, иначе кнопки переносятся по одной */
td .cell-actions{min-width:270px}
.cell-actions label.check{margin:0;font-size:11.5px}
/* длинный текст в ячейке — двумя строками, целиком в подсказке */
.clamp{display:-webkit-box;overflow:hidden;max-width:420px;-webkit-line-clamp:2;-webkit-box-orient:vertical}
/* статус заявки: селект, который выглядит как бейдж */
td .status-sel{width:auto;min-width:92px;height:24px;padding:0 24px 0 9px;border:0;border-radius:999px;background-color:var(--surface-3);background-image:var(--chevron);background-repeat:no-repeat;background-position:right 8px center;background-size:12px;font-size:12px;font-weight:600;color:var(--text-2);cursor:pointer}
td .status-sel.st-new{background-color:var(--accent-soft);color:var(--accent-text)}
td .status-sel.st-in_progress{background-color:var(--warning-soft);color:var(--warning)}
td .status-sel.st-done{background-color:var(--success-soft);color:var(--success)}
td .status-sel.st-lost{background-color:var(--surface-3);color:var(--text-3)}
.reminder-btn{gap:6px}
td .reminder-btn.late{color:var(--danger)}

/* ---------- карточки и сетки ---------- */
.card{min-width:0;padding:16px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-l);box-shadow:var(--shadow-s)}
.card > h2{margin-bottom:12px;font-size:13.5px;font-weight:650}
.card-head{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}
.card-head h2{font-size:13.5px;font-weight:650}
.card-head .muted{margin-top:2px}
.card-foot{margin-top:12px}
.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}
.grid > .wide,.card.wide{grid-column:1/-1}
.stack > * + *{margin-top:16px}
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:12px}
.card .cards{gap:10px}
.toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
.toolbar > input,.toolbar > select{width:auto;min-width:120px;max-width:220px}
.toolbar > input[type=date]{min-width:138px;max-width:150px}
.toolbar > input.grow{flex:1;min-width:180px;max-width:none}
.toolbar > .push{margin-left:auto}

.stat{min-width:0;padding:12px 14px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow-s)}
.stat b{display:block;font-size:20px;font-weight:650;line-height:1.2;letter-spacing:-.01em;font-variant-numeric:tabular-nums}
.stat span{display:block;margin-top:2px;font-size:12px;color:var(--text-3)}

/* ---------- показатели и графики: столбики на flex, без библиотек ---------- */
.kpi{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:end;column-gap:12px;row-gap:6px}
.kpi .label{grid-column:1/-1;margin:0;font-size:12.5px;font-weight:500;color:var(--text-2)}
.kpi b{font-size:24px}
.kpi .note{grid-column:1/-1;margin:0}
.bars{display:flex;align-items:flex-end;gap:2px;width:88px;height:28px}
.bars > span{flex:1;min-height:2px;border-radius:2px;background:var(--accent)}
.bars > span:first-child{border-radius:2px 0 0 2px}
.bars > span:last-child{border-radius:0 2px 2px 0}
.bars.success > span{background:var(--success)}
.bars.danger > span{background:var(--danger)}
.chart{position:relative;display:flex;align-items:flex-end;gap:3px;height:200px;padding-left:38px}
.chart-y{position:absolute;top:0;bottom:22px;left:0;width:30px;display:flex;flex-direction:column;justify-content:space-between;font-size:11px;color:var(--text-4);text-align:right}
.chart-grid{position:absolute;top:0;right:0;bottom:22px;left:38px;display:flex;flex-direction:column;justify-content:space-between;pointer-events:none}
.chart-grid i{border-top:1px dashed var(--border)}
.chart-col{position:relative;z-index:1;flex:1;display:flex;flex-direction:column;justify-content:flex-end;gap:1px;height:calc(100% - 22px);border-radius:4px}
.chart-col:hover{background:var(--surface-2)}
.chart-col .seg{display:block}
.chart-col .found{background:var(--accent)}
.chart-col:not(.has-missed) .found{border-radius:3px 3px 0 0}
.chart-col .missed{background:var(--danger);border-radius:3px 3px 0 0}
.chart-col .x{position:absolute;top:100%;left:0;right:0;text-align:center;font-size:11px;color:var(--text-4)}
.legend{display:flex;flex-wrap:wrap;gap:14px;font-size:12.5px;color:var(--text-2)}
.legend i{display:inline-block;width:10px;height:10px;margin-right:6px;border-radius:3px;background:var(--accent)}
.legend i.missed{background:var(--danger)}
.metrics{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;margin:0}
.metrics > div{padding:10px 12px;border:1px solid var(--border);border-radius:var(--radius)}
.metrics dt{font-size:12px;color:var(--text-3)}
.metrics dd{margin:2px 0 0;font-size:16px;font-weight:650;font-variant-numeric:tabular-nums}
.metrics dd small{display:block;font-size:12px;font-weight:400;color:var(--text-3)}

/* ---------- бейджи и статусы ---------- */
.badge{display:inline-flex;align-items:center;gap:4px;height:20px;padding:0 8px;border-radius:999px;background:var(--surface-3);color:var(--text-2);font-size:11.5px;font-weight:600;line-height:1;white-space:nowrap}
.badge svg{width:12px;height:12px}
.badge.ok{background:var(--success-soft);color:var(--success)}
.badge.err{background:var(--danger-soft);color:var(--danger)}
.badge.warn{background:var(--warning-soft);color:var(--warning)}
.badge.info{background:var(--accent-soft);color:var(--accent-text)}
.badge.wait{background:var(--danger-soft);color:var(--danger);animation:waitPulse 1.6s ease-in-out infinite}
@keyframes waitPulse{0%,100%{box-shadow:0 0 0 0 var(--danger-ring)}50%{box-shadow:0 0 0 5px transparent}}

.pill{display:inline-flex;align-items:center;gap:6px;height:24px;padding:0 10px;border-radius:999px;background:var(--surface-2);color:var(--text-3);font-size:12px;font-weight:500;white-space:nowrap}
.pill::before{content:"";width:6px;height:6px;border-radius:50%;background:var(--text-4)}
.pill.ok{background:var(--success-soft);color:var(--success)} .pill.ok::before{background:var(--success)}
.pill.err{background:var(--danger-soft);color:var(--danger)} .pill.err::before{background:var(--danger)}
.pill.site::before{display:none}

/* ---------- подписи, пустые состояния ---------- */
.hint{min-height:16px;margin-top:8px;font-size:12px;color:var(--text-3)}
.hint.ok{color:var(--success)}
.hint.err{color:var(--danger)}
.empty{padding:14px 0;text-align:center;font-size:13px;color:var(--text-3)}
.alerts{display:flex;flex-direction:column;margin:0;padding:0;list-style:none;font-size:13px;color:var(--text-2)}
.alerts li{display:flex;align-items:center;gap:10px;padding:9px 0;border-bottom:1px solid var(--border)}
.alerts li:last-child{border-bottom:0}
.alerts .dot{flex:none;width:8px;height:8px;border-radius:50%;background:var(--text-4)}
.alerts .dot.err{background:var(--danger)}
.alerts .dot.warn{background:var(--warning)}
.alerts .dot.info{background:var(--accent)}
.alerts .dot.ok{background:var(--success)}
.alerts a{flex:none;margin-left:auto;font-size:12.5px;font-weight:600;white-space:nowrap}
.alerts.ok{color:var(--text-3);align-items:center;padding:14px 0}
.pane.is-refreshing{opacity:.6;pointer-events:none;transition:opacity .15s}
.section-title{margin:14px 0 6px;font-size:11.5px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--text-3)}
.modal-body > .section-title:first-child{margin-top:0}

.row{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
.row > *{min-width:0;margin-bottom:0}
.row > input{flex:1}
.row > button{flex:none}
.row > select{flex:none;width:auto;min-width:150px;max-width:240px}
.actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-top:12px}
.actions > .hint{margin:0 0 0 4px}

.tabs{display:inline-flex;gap:2px;padding:3px;background:var(--surface-2);border-radius:var(--radius-s)}
.tab{height:28px;padding:0 12px;border:0;border-radius:var(--radius-xs);background:transparent;color:var(--text-3);font:600 12.5px var(--font);cursor:pointer}
.tab:hover{background:var(--surface-3);color:var(--text)}
.tab.active{background:var(--surface);color:var(--text);box-shadow:var(--shadow-s)}

.kv{display:grid;grid-template-columns:130px minmax(0,1fr);gap:7px 12px;margin:0;font-size:13px}
.kv dt{color:var(--text-3)}
.kv dd{margin:0;white-space:pre-wrap;word-break:break-word}

.skeleton{border-radius:var(--radius-xs);background:linear-gradient(90deg,var(--surface-2) 25%,var(--surface-3) 50%,var(--surface-2) 75%);background-size:200% 100%;animation:shimmer 1.4s linear infinite}
@keyframes shimmer{from{background-position:200% 0}to{background-position:-200% 0}}

/* ---------- модалки и боковые панели ---------- */
.modal{position:fixed;inset:0;z-index:100;display:none;align-items:center;justify-content:center;padding:24px;background:var(--overlay);animation:fadeIn .15s ease-out}
.modal.open{display:flex}
.modal-card{display:flex;flex-direction:column;width:100%;max-width:720px;max-height:min(90vh,900px);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-l);box-shadow:var(--shadow-l);animation:popIn .18s ease-out}
.modal-card.sm{max-width:440px}
/* .right — та же модалка, но выезжает справа и на всю высоту; лента переписки внутри скроллится, ответ заклёпан снизу */
.modal.right{justify-content:flex-end;padding:0}
.modal.right .modal-card{max-width:640px;height:100%;max-height:none;border:0;border-radius:0;animation:slideIn .22s ease-out}
.modal.right .modal-body{display:flex;flex:1;flex-direction:column;min-height:0}
.modal.right .modal-body.thread{overflow:hidden}
.modal.right .dlgmsgs{flex:1;min-height:0;max-height:none}
.modal.right .th-reply{margin-top:10px;padding-top:10px;border-top:1px solid var(--border)}
.modal-head{display:flex;flex-wrap:wrap;align-items:flex-start;justify-content:space-between;gap:12px;padding:16px 20px;border-bottom:1px solid var(--border)}
.modal-head h2{font-size:15px;font-weight:650}
.modal-head .muted{margin-top:2px}
/* заголовок сжимается под длинный текст — крестик всегда остаётся справа, а не переносится вниз */
.modal-head > div:first-child,.panel-head > div:first-child{flex:1 1 0;min-width:0}
.modal-body{padding:16px 20px;overflow:auto}
.modal-foot{display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:8px;padding:12px 20px;border-top:1px solid var(--border)}
.modal-foot:empty{display:none}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
@keyframes popIn{from{opacity:0;transform:translateY(8px) scale(.985)}to{opacity:1;transform:none}}
@keyframes slideIn{from{transform:translateX(32px)}to{transform:none}}

/* выпадающее меню действий */
.menu-pop{position:fixed;z-index:150;min-width:190px;padding:4px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow-m);animation:popIn .12s ease-out}
.menu-item{display:flex;align-items:center;gap:8px;width:100%;height:32px;padding:0 10px;border:0;border-radius:var(--radius-xs);background:transparent;color:var(--text);font:500 13px var(--font);text-align:left;text-decoration:none;cursor:pointer}
.menu-item:hover{background:var(--surface-2);text-decoration:none}
.menu-item.danger{color:var(--danger)}

.toasts{position:fixed;right:20px;bottom:20px;z-index:200;display:flex;flex-direction:column;gap:8px;width:min(380px,calc(100vw - 40px));pointer-events:none}
.toast{display:flex;align-items:center;gap:10px;padding:10px 8px 10px 14px;background:var(--surface);border:1px solid var(--border);border-left:3px solid var(--border-strong);border-radius:var(--radius);box-shadow:var(--shadow-m);color:var(--text);font-size:13px;pointer-events:auto;animation:toastIn .2s ease-out}
.toast.ok{border-left-color:var(--success)}
.toast.err{border-left-color:var(--danger)}
.toast > span{min-width:0;overflow-wrap:anywhere}
.toast .icon-btn{margin-left:auto}
.toast.leaving{opacity:0;transform:translateX(12px);transition:opacity .25s,transform .25s}
@keyframes toastIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}

/* ---------- операторская: очередь слева, переписка справа ---------- */
.split{display:grid;grid-template-columns:minmax(300px,380px) minmax(0,1fr);gap:16px;align-items:stretch}
.list-card{overflow:hidden}
.split-thread{position:relative}
.split-thread .dlgmsgs{max-height:calc(100dvh - 215px)}
.tabcount{margin-left:5px;font-size:11px;font-weight:600;color:var(--text-3);font-variant-numeric:tabular-nums}
.btn-link{height:auto;padding:0 0 0 4px;border:0;border-radius:0;background:transparent;color:var(--accent-text);font:600 12.5px var(--font);text-decoration:underline;text-underline-offset:3px}
.btn-link:hover{background:transparent;text-decoration:none}
.thread-blank{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;min-height:320px;padding:24px;text-align:center;font-size:13px;color:var(--text-3)}
.thread-blank svg{width:28px;height:28px;color:var(--text-4)}
.thread-blank b{display:block;margin-bottom:4px;color:var(--text);font-size:14px}
.inboxchat{padding:10px 14px;margin:0 -16px;border-bottom:1px solid var(--border);cursor:pointer;transition:background .12s}
.inboxchat:hover{background:var(--surface-2)}
.inboxchat.active{background:var(--accent-soft)}
.inboxchat.leaving{opacity:0;transition:opacity .3s}
.inboxchat .head{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-bottom:4px}
.inboxchat .preview{display:-webkit-box;overflow:hidden;margin:0 0 8px;font-size:13px;white-space:pre-wrap;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.inboxchat .actions{margin-top:0}
.inboxchat .actions button{height:26px;padding:0 8px;font-size:12px}

/* ---------- ветка переписки: скроллится только лента, поле ответа заклёпано под ней ---------- */
.thread{position:relative}
.dlgmsgs{max-height:calc(100dvh - 250px);overflow-y:auto;padding:4px 4px 4px 0;scroll-behavior:smooth}
.dlgmsgs > *{flex-shrink:0}
.th-turn{margin-bottom:16px}
.th-line{display:flex;margin-bottom:4px}
.th-line.user{justify-content:flex-end}
.th-bubble{display:inline-block;max-width:80%;padding:8px 12px;border-radius:12px;font-size:13.5px;line-height:1.45;white-space:pre-wrap;word-break:break-word}
.th-line.user .th-bubble{background:var(--accent-soft);border-bottom-right-radius:4px}
.th-line.bot .th-bubble{background:var(--surface-2);border:1px solid var(--border);border-bottom-left-radius:4px}
.th-line.mgr .th-bubble{background:var(--warning-soft);border:1px solid var(--warning-line);border-bottom-left-radius:4px}
.th-bubble .who{display:block;margin-bottom:2px;font-size:11.5px;font-weight:600;color:var(--text-3)}
.th-meta{height:auto;margin-top:2px;padding:0;border:0;background:transparent;color:var(--text-3);font:400 11.5px var(--font)}
button.th-meta:hover{background:transparent}
.th-meta.link{cursor:pointer;text-decoration:underline dotted;text-underline-offset:3px}
.th-meta.link:hover{color:var(--accent-text)}
.th-reply{display:flex;align-items:flex-start;gap:8px;margin-top:14px}
.th-reply textarea{flex:1;min-height:44px}
.downbtn{position:absolute;right:10px;z-index:5;width:34px;height:34px;padding:0;border:1px solid var(--border);border-radius:50%;background:var(--surface);color:var(--text-2);box-shadow:var(--shadow-m);opacity:0;pointer-events:none;transition:opacity .2s}
.downbtn:hover{background:var(--surface-2)}
.downbtn.on{opacity:1;pointer-events:auto}

/* ---------- выносная панель (тест-чат): без подложки; на широком экране страница под неё отступает (console.css, .docked) ---------- */
:root{--panel-w:400px}
.side-panel{position:fixed;top:calc(var(--top-h) + 12px);right:16px;bottom:16px;z-index:40;display:none;flex-direction:column;width:min(var(--panel-w),calc(100vw - 32px));background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-l);box-shadow:var(--shadow-l);animation:slideIn .22s ease-out}
.side-panel.open{display:flex}
.panel-head{display:flex;flex-wrap:wrap;align-items:flex-start;justify-content:space-between;gap:12px;padding:14px 16px;border-bottom:1px solid var(--border)}
.panel-head h2{font-size:14px;font-weight:650}
.panel-body{flex:1;min-height:0;padding:14px 16px;overflow:auto}

/* ---------- тест-чат ---------- */
.testbox{display:flex;flex-direction:column;gap:10px}
.answer{min-height:56px;padding:12px 14px;background:var(--surface-2);border:1px solid var(--border);border-radius:var(--radius);white-space:pre-wrap}
.srcs{display:flex;flex-direction:column;gap:4px;font-size:12.5px;color:var(--text-3)}

/* ---------- настройки: подменю разделов, форма секциями, превью сбоку, панель сохранения ---------- */
.settings{display:grid;grid-template-columns:200px minmax(0,1fr) 320px;gap:16px;align-items:start}
.settings-nav{position:sticky;top:calc(var(--top-h) + 16px);display:flex;flex-direction:column;gap:2px}
.settings-nav button{height:32px;padding:0 10px;border:0;border-radius:var(--radius-s);background:transparent;color:var(--text-2);font:500 13px var(--font);text-align:left;cursor:pointer}
.settings-nav button:hover{background:var(--surface-2);color:var(--text)}
.settings-nav button.active{background:var(--accent-soft);color:var(--accent-text);font-weight:600}
.settings-form{display:flex;flex-direction:column;gap:16px;min-width:0}
.settings-form .card{scroll-margin-top:calc(var(--top-h) + 16px)}
.settings-form .grid > label.check{align-self:end;padding-bottom:10px}
.sticky{position:sticky;top:calc(var(--top-h) + 16px)}
.scopebar .row{flex-wrap:nowrap}
.scopebar h2{font-size:14px;font-weight:650}
.scopebar .row select{max-width:320px}
.scopebar .muted{margin-top:8px}
.savebar{position:sticky;bottom:12px;z-index:15;display:none;align-items:center;flex-wrap:wrap;gap:10px;margin-top:16px;padding:12px 14px 12px 16px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);box-shadow:var(--shadow-m)}
.is-dirty .savebar{display:flex}
.dirty-note{display:inline-flex;align-items:center;gap:8px;margin-right:auto;font-size:13px;color:var(--text-2)}
.dirty-note i{width:8px;height:8px;border-radius:50%;background:var(--warning)}
.savebar .hint{margin:0}
@media (max-width:1100px){
  .settings{grid-template-columns:minmax(0,1fr) 300px}
  .settings-nav{grid-column:1/-1;position:static;flex-direction:row;flex-wrap:wrap}
}

/* ---------- прочее ---------- */
.srcItem{padding:8px 10px;border:1px solid var(--border);border-radius:var(--radius-s);font-size:12.5px}
.srcItem b{font-weight:600}
.srcItem .sub{margin-top:2px;white-space:pre-wrap}
.steps{display:flex;flex-direction:column;gap:8px}
.step{display:flex;align-items:flex-start;gap:10px;padding:9px 10px;border:1px solid var(--border);border-radius:var(--radius);background:var(--surface-2)}
.step .dot{display:grid;place-items:center;flex:none;width:20px;height:20px;border:1px solid var(--border-strong);border-radius:50%;background:var(--surface);color:var(--text-3);font-size:11px}
.step.done .dot{background:var(--success-soft);border-color:transparent;color:var(--success)}
.step b{font-size:12.5px;font-weight:600}
.step p{margin-top:2px;font-size:12px;color:var(--text-3)}
.step a{font-size:12px;font-weight:600}
.warnBox{margin:10px 0;padding:10px 12px;border-radius:var(--radius);background:var(--warning-soft);color:var(--warning);font-size:12.5px}
.impBanner{display:none;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px;margin-bottom:16px;padding:10px 14px;border-radius:var(--radius);background:var(--warning-soft);color:var(--warning);font-size:13px}
.impBanner.open{display:flex}
.impBanner button{background:var(--surface);color:var(--warning)}
.impBanner button:hover{background:var(--surface-3)}
.docPre{max-height:62vh;margin:0;padding:12px 14px;overflow:auto;white-space:pre-wrap;word-break:break-word;background:var(--surface-2);border:1px solid var(--border);border-radius:var(--radius);font:13px/1.55 var(--font)}

/* превью виджета: настоящее окно чата (iframe /chat?preview=1 — см. shared/widget-preview.js).
   Окно показывается в масштабе, чтобы влезло в колонку, и живёт в своей теме — тема консоли на него не влияет.
   Кнопка чата — имитация (настоящая живёт в странице клиента), красится скриптом по акценту. */
.wp{overflow:hidden;border:1px solid var(--border);border-radius:var(--radius);background:var(--surface-2)}
.wp-win{padding:12px 12px 0}
.wp-win iframe{display:block;width:400px;height:600px;border:0;border-radius:16px;background:#fff;box-shadow:var(--shadow-m);zoom:.66}
@supports not (zoom:1){.wp-win iframe{width:100%;height:400px}}
.wp-site{display:flex;justify-content:flex-end;padding:10px 12px 12px}
.wp-fab{display:flex;align-items:center;justify-content:center;width:48px;height:48px;border-radius:50%;background:#4f8cff;color:#fff;box-shadow:0 6px 18px rgba(79,140,255,.38);transition:background .15s,box-shadow .15s}
.wp-fab svg{width:21px;height:21px}

/* ---------- узкие экраны ---------- */
@media (max-width:768px){
  /* поля 16px+, иначе iOS приближает страницу при фокусе */
  :where(input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=file]):not([type=range]):not([type=hidden])),select,textarea{font-size:16px}
  td select,td input[type=date]{font-size:13px}
  .grid{grid-template-columns:minmax(0,1fr)}
  .split{grid-template-columns:minmax(0,1fr)}
  .cards{grid-template-columns:repeat(2,minmax(0,1fr))}
  /* широкие таблицы не сжимаем в кашу — они прокручиваются внутри карточки */
  .table-wrap table{min-width:640px}
  .modal{padding:12px}
  .modal-card{max-height:92dvh}
  .modal.right .modal-card{max-width:100%}
  .toasts{right:12px;bottom:12px;left:12px;width:auto}
  .side-panel{left:12px;right:12px;top:auto;bottom:12px;width:auto;max-height:72dvh}
  .hide-sm{display:none}
  .settings{grid-template-columns:minmax(0,1fr)}
  .settings-side{grid-column:1}
  .sticky{position:static}
  .scopebar .row{flex-wrap:wrap}
  .dlgmsgs{max-height:calc(100dvh - 300px)}
}

@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:.01ms!important;transition-duration:.01ms!important;scroll-behavior:auto!important}
}
