/* Панель B2HIRE — тёмная тема в тонах ночного Telegram: сине-серые поверхности, синий акцент.
   Правила системы:
   - цвета только из переменных ниже; акцент один (синий), красный — только для разрушающих
     действий и ошибок, зелёный и жёлтый — только для статусов;
   - контраст: основной текст ≥ 12:1, вторичный ≥ 6:1, белый на синей кнопке ≈ 5:1;
   - шаг отступов 4/8, поля и кнопки 36 px (маленькие 30), скругления 8 / 12 / 16;
   - один шрифт (Inter), размеры 12 / 13 / 14 / 16 / 20, без капса. */

:root {
  color-scheme: dark;
  --bg: #0E1621;
  --surface: #17212B;
  --surface-2: #1E2C3A;
  --surface-3: #26394C;
  --border: #243241;
  --border-strong: #33475C;
  --text: #E9EEF3;
  --text-2: #93A4B5;
  --text-3: #6B7F92;

  --accent: #64B5F6;        /* ссылки, иконки, фокус, активное */
  --accent-fill: #3272B8;   /* заливка основных кнопок */
  --accent-hover: #3B7FC7;
  --accent-soft: rgba(100, 181, 246, .14);

  --ok: #5CC28E;   --ok-bg: rgba(92, 194, 142, .13);
  --warn: #E3B24F; --warn-bg: rgba(227, 178, 79, .13);
  --bad: #F07272;  --bad-bg: rgba(240, 114, 114, .13);

  /* выделение тегов — три оттенка, проверены валидатором палитры на surface-2/3 (все пары) */
  --tag-1: #3987E5; --tag-2: #D95926; --tag-3: #199E70;

  /* инбокс — цвета Telegram Desktop (ночная тема) */
  --chat-bg: #0E1621;
  --bubble-in: #182533;
  --bubble-out: #2B5278;
  --selected: #2B5278;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --h-control: 36px;
  --h-control-sm: 30px;
  --r-control: 8px;
  --r-card: 12px;
  --r-modal: 16px;
  --shadow: 0 16px 48px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
/* Полосы прокрутки — тонкие и тёмные: системные (со стрелками) выбиваются из темы. */
* { scrollbar-width: thin; scrollbar-color: #2E3F52 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2E3F52; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #3B5068; }
::-webkit-scrollbar-button { display: none; height: 0; width: 0; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14px/1.5 var(--font); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
h1 { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: -0.2px; }
h2 { margin: 0; font-size: 16px; line-height: 1.35; font-weight: 600; }
h3 { margin: 0; font-size: 14px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; color: var(--text-2); }
.brand:hover { text-decoration: none; }
.brand img { height: 20px; width: auto; }
.brand span { font-size: 12px; font-weight: 500; padding-left: 10px; border-left: 1px solid var(--border-strong); }
.topbar nav { display: flex; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topbar nav a {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 11px; border-radius: var(--r-control);
  color: var(--text-2); font-weight: 500; white-space: nowrap;
  transition: background-color .12s, color .12s;
}
.topbar nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar nav a.active { color: var(--text); background: var(--surface-3); }
.me { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; color: var(--text-2); font-size: 13px; white-space: nowrap; }
/* Переключатель направлений: сегменты на утопленной подложке, как вкладки, но крупнее по смыслу. */
/* С переключателем подпись «Messaging» лишняя: место нужно меню. */
.brand:has(+ .ws-switch:not(.hidden)) span { display: none; }
.ws-switch { display: flex; flex: 0 0 auto; gap: 2px; padding: 3px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.ws-switch a {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: 7px;
  color: var(--text-2); font-size: 13px; font-weight: 500; white-space: nowrap; transition: background-color .12s, color .12s;
}
.ws-switch a:hover { color: var(--text); text-decoration: none; }
.ws-switch a.active { background: var(--surface-3); color: var(--text); }

.banner { padding: 8px 24px; background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid var(--border); font-size: 13px; text-align: center; }

main { max-width: 1280px; margin: 0 auto; padding: 28px 24px 56px; }

.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 36px; margin-bottom: 20px; }
.page-head h1 { flex: 1 1 auto; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-head .actions select { width: auto; min-width: 200px; }
.lead { max-width: 760px; margin: -8px 0 20px; color: var(--text-2); }

/* ---------- вкладки ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab {
  height: 40px; padding: 0 14px; margin-bottom: -1px; flex: 0 0 auto;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-2); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.card + .card, .notice + .card, .card + .notice { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 60px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.card-head .title { display: flex; flex-direction: column; gap: 2px; flex: 1 1 260px; min-width: 0; }
.card-head .meta { color: var(--text-2); font-size: 13px; }
.card-head .meta .seg { white-space: nowrap; }
.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 12px; line-height: 20px; white-space: nowrap; }
.chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.card-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card-head .actions select { width: auto; height: var(--h-control-sm); font-size: 13px; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }
.card-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid var(--border); }
.section-title { margin: 32px 0 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 16px; }
.cards > .card { margin-top: 0; }
.stat { padding: 16px 20px; text-align: center; }
.stat .value { font-size: 26px; line-height: 1.2; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .value.bad { color: var(--bad); }
.stat .label { margin-top: 4px; color: var(--text-2); font-size: 13px; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { color: var(--text-2); font-size: 12px; font-weight: 500; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, .015); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.check, th.check { width: 48px; padding-right: 0; }
td.check input, th.check input { display: block; }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions .row { justify-content: flex-end; flex-wrap: nowrap; }
.cell-sub { margin-top: 2px; color: var(--text-2); font-size: 12px; }
.empty { padding: 40px 20px; color: var(--text-2); text-align: center; }
.empty p { margin: 0 auto; max-width: 560px; }
.empty .form-actions { justify-content: center; margin-top: 16px; }
.pager { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); color: var(--text-2); font-size: 13px; }

/* ---------- формы ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; min-width: 0;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-control);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
input:not([type=checkbox]):not([type=radio]):not([type=file]), select { height: var(--h-control); padding: 0 12px; }
textarea { padding: 10px 12px; min-height: 120px; resize: vertical; line-height: 1.5; }
textarea.tall { min-height: 220px; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:hover, select:hover, textarea:hover { border-color: #41586F; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled, select:disabled, textarea:disabled, input[readonly], textarea[readonly] { opacity: .6; cursor: default; }
/* Стрелка списка — SVG (data:), как у системных списков. */
select {
  -webkit-appearance: none; appearance: none; padding-right: 34px !important; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%2393A4B5' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px 16px;
}
select option { background: var(--surface-2); color: var(--text); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-fill); cursor: pointer; flex: 0 0 auto; }
/* Галочка в цветах панели: системная — серый квадрат, выбивается из тёмной темы. */
input[type=checkbox] {
  -webkit-appearance: none; appearance: none; outline: none;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--surface-2) center / 12px 12px no-repeat;
  transition: background-color .12s, border-color .12s, box-shadow .12s;
}
input[type=checkbox]:hover { border-color: #41586F; }
input[type=checkbox]:focus { border-color: var(--border-strong); box-shadow: none; }
input[type=checkbox]:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox]:checked {
  border-color: var(--accent-fill); background-color: var(--accent-fill);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.3 2.3 4.7-4.9' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
input[type=checkbox]:checked:hover { border-color: var(--accent-hover); background-color: var(--accent-hover); }
input[type=checkbox]:disabled { opacity: .5; cursor: default; }
input[type=search]::-webkit-search-cancel-button { filter: invert(.7); cursor: pointer; }
input[type=time]::-webkit-calendar-picker-indicator { filter: invert(.75); cursor: pointer; }
/* Без стрелок ±1: случайный щелчок или прокрутка меняли лимиты. Колесо гасится в app.js. */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; font-weight: 400; color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* В окнах действия справа — как в подвале окна. */
.modal-body .form-actions { justify-content: flex-end; }
.check-line { display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; line-height: 1.4; }
/* Квадрат — по середине первой строки текста. */
.check-line input { margin-top: 2px; margin-top: calc((1lh - 16px) / 2); }
/* Пояснение под галочкой — вровень с текстом, его можно выделить и скопировать. */
.check-field { display: flex; flex-direction: column; gap: 2px; }
.check-hint { padding-left: 26px; font-size: 13px; line-height: 1.4; color: var(--text-3); }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.day {
  display: inline-flex; align-items: center; gap: 8px;
  height: var(--h-control); padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--r-control);
  background: var(--surface-2); cursor: pointer; user-select: none; font-weight: 500;
}
.day:hover { border-color: #41586F; }
.day:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search input { padding-left: 34px !important; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.toolbar .search { flex: 1 1 240px; }
.toolbar select { width: auto; min-width: 170px; }
.selection-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 20px; background: var(--accent-soft); border-bottom: 1px solid var(--border); }

/* Зона загрузки файла: клик, перетаскивание, подсветка при наведении и при переносе файла. */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 132px; padding: 20px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-card);
  background: var(--surface-2); color: var(--text-2);
  transition: border-color .12s, background-color .12s, color .12s;
}
.dropzone svg { color: var(--text-3); transition: color .12s; }
.dropzone strong { color: var(--text); font-weight: 600; }
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); color: var(--text); outline: none; }
.dropzone:hover svg, .dropzone.over svg { color: var(--accent); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone.filled { border-style: solid; }
.dropzone input[type=file] { display: none; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--h-control); padding: 0 14px; flex: 0 0 auto;
  border: 1px solid transparent; border-radius: var(--r-control);
  font-weight: 500; white-space: nowrap; cursor: pointer; text-decoration: none; user-select: none;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover { text-decoration: none; }
.btn.primary { background: var(--accent-fill); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-3); border-color: #41586F; }
.btn.danger { background: transparent; color: var(--bad); border-color: rgba(240, 114, 114, .45); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn.danger.solid { background: #C24848; color: #fff; border-color: #C24848; }
.btn.danger.solid:hover { background: #D05252; }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: var(--h-control-sm); padding: 0 10px; font-size: 13px; }
.btn.icon { width: var(--h-control); padding: 0; }
.btn.icon.sm { width: var(--h-control-sm); }
.btn:disabled { opacity: .45; cursor: default; pointer-events: none; }
.link { padding: 0; border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: 500; }
.link:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

/* ---------- метки, уведомления ---------- */
.pill {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent-fill); color: #fff; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.badge.muted { background: var(--surface-3); color: var(--text-2); }
.notice { padding: 10px 14px; border-radius: var(--r-control); background: var(--warn-bg); color: var(--warn); line-height: 1.45; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice + .notice { margin-top: 12px; }
.err-text { color: var(--bad); font-size: 12px; line-height: 1.4; }
td.err-cell { min-width: 260px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { width: 150px; }
.inline-form + .err-text, .inline-form ~ .notice { margin-top: 6px; }

/* Сворачиваемая подсказка «Как заполнять». */
details.help { border: 1px solid var(--border); border-radius: var(--r-control); background: var(--surface-2); }
details.help > summary { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; color: var(--text-2); font-weight: 500; list-style: none; }
details.help > summary::-webkit-details-marker { display: none; }
details.help > summary::before { content: "▸"; color: var(--text-3); }
details.help[open] > summary::before { content: "▾"; }
details.help .help-body { padding: 0 14px 14px; font-size: 13px; line-height: 1.55; color: var(--text-2); }
details.help .help-body p { margin: 8px 0 0; }
details.help .help-body ol { margin: 6px 0 0; padding-left: 22px; }
details.help .help-body li + li { margin-top: 3px; }
details.help .help-body b { color: var(--text); font-weight: 600; }
details.help .help-grid { display: grid; grid-template-columns: max-content 1fr; gap: 5px 16px; margin-top: 8px; }
details.help .help-grid > b { font-weight: 500; }
/* Пример — целиком: «socks5://логин:пароль@хост:порт», разорванный посередине, читается плохо. */
details.help code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; padding: 1px 5px; border-radius: 4px; background: var(--surface-3); white-space: nowrap; }

/* ---------- окна, меню, тосты ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 30; overflow-y: auto;
  display: flex; align-items: flex-start; justify-content: center; padding: 72px 16px;
  background: rgba(6, 10, 15, .72);
}
.modal { width: 100%; max-width: 680px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-modal); box-shadow: var(--shadow); }
.modal.narrow { max-width: 440px; }
.modal.wide { max-width: 980px; }
/* Боковая панель: справа на всю высоту, доска за ней видна. */
.modal-back.drawer-back { align-items: stretch; justify-content: flex-end; padding: 0; background: rgba(6, 10, 15, .45); }
.modal.drawer { display: flex; flex-direction: column; max-width: 460px; min-height: 100vh; border-radius: 0; border-width: 0 0 0 1px; }
.modal.drawer .modal-body { flex: 1 1 auto; overflow-y: auto; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1 1 auto; font-size: 17px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-body h3 { margin-top: 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

.menu {
  position: fixed; z-index: 40; min-width: 180px; padding: 6px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow);
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px;
  background: none; border: 0; border-radius: 6px; color: var(--text); cursor: pointer; text-align: left;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-3); outline: none; }
.menu button.danger { color: var(--bad); }
.menu button svg { color: var(--text-2); }
.menu button.danger svg { color: var(--bad); }

.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 420px;
  padding: 12px 16px; border-radius: 10px;
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
}
.toast.bad { border-color: rgba(240, 114, 114, .55); color: var(--bad); }

.login { max-width: 380px; margin: 12vh auto 0; }
.login .card-body { display: flex; flex-direction: column; gap: 16px; padding: 32px 28px; }
.login .logo { display: flex; justify-content: center; }
.login .logo img { height: 28px; }
.login h1 { text-align: center; font-size: 18px; }
.login .btn { width: 100%; height: 40px; }

pre.raw {
  margin: 0; padding: 12px 14px; white-space: pre-wrap; word-wrap: break-word;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-control);
  font: inherit; font-size: 13.5px; line-height: 1.55; color: var(--text);
}

/* ---------- шаблоны: группы слева, как папки ---------- */
.tpl-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.folders { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 2px; padding: 8px; }
.folder {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 0 10px;
  background: none; border: 0; border-radius: 8px; color: var(--text-2); text-align: left; cursor: pointer; font-weight: 500;
}
.folder:hover { background: var(--surface-2); color: var(--text); }
.folder.active { background: var(--surface-3); color: var(--text); }
.folder .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder .count { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.folder.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.folder.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.folder[draggable] { cursor: grab; }
.folders hr { border: 0; border-top: 1px solid var(--border); margin: 8px 4px; }

/* ---------- каналы ---------- */
.channel-main > * + * { margin-top: 16px; }
.folder.add { color: var(--accent); }
.folder.add svg { flex: 0 0 auto; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.card-tabs .tabs { margin: 0; padding: 0 12px; }
.run-note { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- шаблоны ---------- */
.tpl { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.tpl:last-child { border-bottom: 0; }
.tpl.off .tpl-title, .tpl.off pre.raw { color: var(--text-2); }
.tpl-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-weight: 600; }
.tpl-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.tpl-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; align-content: start; }
.tpl-stats > div { padding: 10px 4px; border-radius: var(--r-control); background: var(--surface-2); text-align: center; }
.tpl-stats b { display: block; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tpl-stats span { font-size: 11.5px; color: var(--text-2); }
details.archive > summary { display: flex; align-items: center; gap: 8px; padding: 16px 20px; cursor: pointer; color: var(--text-2); font-weight: 500; list-style: none; }
details.archive > summary::-webkit-details-marker { display: none; }
details.archive > summary::before { content: "▸"; color: var(--text-3); }
details.archive[open] > summary::before { content: "▾"; }
details.archive[open] > summary { border-bottom: 1px solid var(--border); }

/* ---------- время ---------- */
.time-field { display: flex; align-items: center; gap: 6px; }
.time-field select { width: auto; min-width: 76px; }
.time-field span { color: var(--text-2); font-weight: 600; }

/* ---------- сортировка таблиц ---------- */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted { color: var(--text); }
.sort-mark { display: inline-block; width: 12px; margin-left: 4px; color: var(--accent); }

/* ---------- обзор ---------- */
.overview-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; margin-top: 16px; align-items: start; }
.overview-grid > .card { margin-top: 0; }
.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: flex; align-items: flex-start; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.attention li:last-child { border-bottom: 0; }
.attention .dot { flex: 0 0 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--warn); }
.attention .dot.bad { background: var(--bad); }
.attention .dot.info { background: var(--accent); }
.attention .dot.ok { background: var(--ok); }
.attention a { color: var(--text); }
.attention .sub { color: var(--text-2); font-size: 13px; }

/* ---------- график ---------- */
.chart { position: relative; }
.chart-legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; color: var(--text-2); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.chart-legend b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart svg text { fill: var(--text-3); font: 400 11px var(--font); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .band { fill: transparent; }
.chart .band.hover { fill: rgba(255, 255, 255, .04); }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 150px; padding: 8px 10px;
  background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow);
  font-size: 13px; color: var(--text);
}
.chart-tip .t { margin-bottom: 4px; color: var(--text-2); font-size: 12px; }
.chart-tip .r { display: flex; align-items: center; gap: 6px; }
.chart-tip .r b { margin-left: auto; font-variant-numeric: tabular-nums; }
.chart-tip .sw { width: 8px; height: 8px; border-radius: 2px; }
.chart-table { margin-top: 12px; }

/* ---------- источники ---------- */
.src-row td { vertical-align: middle; }
.order-cell { display: flex; align-items: center; gap: 6px; }
/* Колонка «#» — по содержимому: иначе таблица растягивает её и название источника уезжает вправо. */
td:has(> .order-cell) { width: 1%; white-space: nowrap; }
.src-row.dragging td { opacity: .4; }
.src-row.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
.src-row.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }
.grip { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: 0; background: none; color: var(--text-3); cursor: grab; border-radius: 4px; }
.grip:hover { color: var(--text); background: var(--surface-3); }
.pos { color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 16px; line-height: 24px; }

/* ---------- инбокс (Telegram Desktop, ночная тема) ---------- */
.inbox {
  display: grid; grid-template-columns: 340px minmax(0, 1fr);
  /* Окно минус шапка (56), отступы страницы (28 + 56) и заголовок (56): страница не прокручивается. */
  height: calc(100vh - 196px); min-height: 520px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden;
}
body.has-banner .inbox { height: calc(100vh - 196px - 37px); }
.inbox-side { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.chat-back { display: none; }
/* Высота блока поиска задана: на её уровне — черта под «Все чаты» в колонке папок. */
.inbox { --inbox-head: 99px; }
.inbox-tools { display: flex; flex-direction: column; justify-content: center; gap: 8px; flex: 0 0 var(--inbox-head); padding: 0 12px; border-bottom: 1px solid var(--border); }
.inbox-tools .search input { border-radius: 18px; background: var(--bg); border-color: transparent; }
.inbox-tools .search input:focus { border-color: var(--accent); }
.inbox-tools select { height: 32px; font-size: 13px; background-color: var(--bg); border-color: transparent; }
.dialogs { flex: 1 1 auto; overflow-y: auto; padding-bottom: 8px; }
.list-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; color: var(--text-2); font-size: 12px; font-weight: 600; }
.list-empty { padding: 8px 16px 12px; color: var(--text-3); font-size: 13px; }
.dialogs-empty { display: flex; flex-direction: column; gap: 6px; padding: 48px 28px; text-align: center; line-height: 1.5; }
.dialogs-empty strong { color: var(--text-2); font-size: 14px; font-weight: 600; }
.dialogs-empty p { margin: 0; color: var(--text-3); font-size: 13px; }
.list-note { padding: 10px 16px 0; color: var(--text-3); font-size: 12px; }
/* Папки, как в Telegram Desktop: узкая колонка слева, под чертой — этапы итога. */
.inbox-folders { display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); border-right: 1px solid var(--border); }
.folders-top { position: relative; flex: 0 0 var(--inbox-head); display: flex; align-items: center; }
.folders-top::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 0; height: 1px; background: var(--border-strong); }
.folders-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 0; scrollbar-width: none; }
.folder-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; padding: 10px 4px 9px; border: 0; background: none; color: var(--text-3); font: inherit; font-size: 11px; line-height: 1.25; cursor: pointer; }
.folder-btn:hover { background: var(--surface-3); color: var(--text-2); }
.folder-btn.active { background: var(--surface); color: var(--accent); }
.folder-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.folder-icon { position: relative; display: inline-flex; }
.folder-badge { position: absolute; top: -7px; left: 15px; min-width: 18px; height: 18px; padding: 0 5px; font-size: 11px; line-height: 18px; box-shadow: 0 0 0 2px var(--surface-2); }
.folder-btn.active .folder-badge { box-shadow: 0 0 0 2px var(--surface); }
/* Название — до двух строк, переносы по словам; целиком — во всплывающей подсказке. */
.folder-name { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; max-width: 100%; overflow: hidden; text-align: center; }
.folder-name > span { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: top; }
.folder-sep { flex: 0 0 auto; height: 1px; margin: 6px 14px; background: var(--border-strong); }
.inbox-filters .folder-select { display: none; }
.dialog-item { display: flex; gap: 12px; padding: 8px 10px; margin: 0 6px; border-radius: 10px; cursor: pointer; }
.dialog-item:hover { background: var(--surface-2); }
.dialog-item.active { background: var(--selected); }
.avatar { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 17px; font-weight: 600; }
.avatar.sm { width: 38px; height: 38px; font-size: 15px; }
.avatar.xs { width: 24px; height: 24px; font-size: 11px; }
.avatar.xxs { width: 18px; height: 18px; font-size: 9px; }
.av-0 { background: linear-gradient(#FF885E, #FF516A); } .av-1 { background: linear-gradient(#FFCD6A, #FFA85C); }
.av-2 { background: linear-gradient(#82B1FF, #665FFF); } .av-3 { background: linear-gradient(#A0DE7E, #54CB68); }
.av-4 { background: linear-gradient(#53EDD6, #28C9B7); } .av-5 { background: linear-gradient(#72D5FD, #2A9EF1); }
.av-6 { background: linear-gradient(#E0A2F3, #D669ED); }
.dialog-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
.dialog-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dialog-line .who { flex: 1 1 auto; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-line .time { flex: 0 0 auto; color: var(--text-3); font-size: 12px; }
.dialog-line .preview { flex: 1 1 auto; min-width: 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-line .preview .you { color: var(--accent); }
.dialog-item.unread .preview { color: var(--text); }
.dialog-line .reaction { flex: 0 0 auto; font-size: 15px; line-height: 20px; }
.dialog-meta { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--text-3); font-size: 12px; }
.dialog-meta .meta-who { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Плашки не сжимаются: не помещаются рядом — переносятся под первую. */
.dialog-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; min-width: 0; margin-top: 3px; }
.dialog-tags .pill { display: block; flex: 0 0 auto; max-width: 100%; line-height: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-item.active .time, .dialog-item.active .preview, .dialog-item.active .preview .you, .dialog-item.active .dialog-meta { color: rgba(233, 238, 243, .78); }
.dialog-item.active .badge { background: #fff; color: var(--selected); }
mark { background: rgba(227, 178, 79, .38); color: inherit; border-radius: 3px; padding: 0 1px; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
/* Сжимается только лента: иначе при длинной переписке шапка и поле ввода теряют отступы. */
.chat > :not(.messages) { flex: 0 0 auto; }
.chat-empty { margin: auto; padding: 6px 14px; border-radius: 14px; background: var(--surface); color: var(--text-2); font-size: 13px; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 8px 16px; min-height: 58px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chat-head .title { flex: 1 1 auto; min-width: 0; }
.chat-head .title strong { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .title .muted { font-size: 13px; overflow: hidden; }
.chat-alert { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); color: var(--bad); font-size: 13px; }
.messages { flex: 1 1 auto; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.date-sep { align-self: center; margin: 10px 0 6px; padding: 3px 10px; border-radius: 12px; background: rgba(23, 33, 43, .9); color: var(--text-2); font-size: 12px; font-weight: 500; }
.msg-row { display: flex; align-items: flex-end; gap: 4px; max-width: 100%; }
.msg-row.out { justify-content: flex-end; }
.msg-row.first-in-group { margin-top: 6px; }
.msg { position: relative; max-width: min(540px, 76%); padding: 6px 10px 6px 12px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.42; }
.msg-row.in .msg { background: var(--bubble-in); border-bottom-left-radius: 4px; }
.msg-row.out .msg { background: var(--bubble-out); border-bottom-right-radius: 4px; }
.msg .meta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 7px 0 -4px 12px; font-size: 11px; color: rgba(233, 238, 243, .5); white-space: nowrap; user-select: none; }
.msg-row.out .msg .meta { color: rgba(140, 200, 255, .8); }
.msg-row.pending .msg { opacity: .7; }
.msg-row.deleting .msg { opacity: .4; text-decoration: line-through; }
.msg-row.failed .msg { box-shadow: inset 0 0 0 1px rgba(240, 114, 114, .6); }
.msg-row.failed .msg .meta { color: var(--bad); }
.msg-more {
  flex: 0 0 auto; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text-3); cursor: pointer; opacity: 0; transition: opacity .1s, background-color .1s;
}
.msg-row:hover .msg-more, .msg-more:focus-visible, .msg-more.open { opacity: 1; }
.msg-more:hover, .msg-more.open { background: var(--surface-2); color: var(--text); }
.msg-note { max-width: min(540px, 76%); margin: 2px 0 4px; font-size: 12px; color: var(--bad); }
.msg-row.out + .msg-note, .msg-note.out { align-self: flex-end; text-align: right; }
.msg-note .link { font-size: 12px; margin-left: 6px; }
.composer-wrap { background: var(--surface); border-top: 1px solid var(--border); }
.edit-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px 0; }
.edit-bar .bar { width: 2px; align-self: stretch; background: var(--accent); border-radius: 1px; }
.edit-bar .what { flex: 1 1 auto; min-width: 0; font-size: 13px; }
.edit-bar .what strong { display: block; color: var(--accent); font-weight: 600; }
.edit-bar .what span { display: block; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 16px; }
.composer textarea { min-height: 40px; max-height: 200px; height: 40px; padding: 9px 14px; border-radius: 20px; resize: none; background: var(--bg); border-color: transparent; overflow-y: hidden; }
.composer .send { width: 40px; height: 40px; border-radius: 50%; padding: 0; }
.composer-note { padding: 0 16px 8px; color: var(--text-3); font-size: 12px; text-align: center; }

/* Вложения в переписке */
.msg a { color: var(--accent); }
.msg-row.out .msg a { color: #BFE0FF; }
.msg.has-media { display: flex; flex-direction: column; gap: 6px; }
.msg.has-media .meta { align-self: flex-end; margin-top: 0; }
.msg-media { display: block; max-width: 100%; }
.msg-media img, video.msg-media { display: block; max-width: min(360px, 100%); max-height: 360px; border-radius: 8px; background: rgba(0, 0, 0, .2); }
.msg-media img.sticker { max-width: 160px; max-height: 160px; background: transparent; }
video.msg-media.round { width: 220px; height: 220px; max-width: 220px; object-fit: cover; border-radius: 50%; }
.msg-audio audio { display: block; width: 300px; max-width: 100%; height: 40px; }
.msg-file { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; white-space: normal; }
a.msg-file:hover strong { text-decoration: underline; }
.msg-file-icon { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .1); color: var(--text); }
.msg-file-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.msg-file-text strong { font-weight: 600; overflow-wrap: anywhere; }
.msg-file-text span { font-size: 12px; color: var(--text-2); }
.msg-row.out .msg-file-text span { color: rgba(200, 225, 255, .8); }
.attach-bar img.attach-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.attach-bar .what strong { color: var(--text); }
.chat.drop .messages { box-shadow: inset 0 0 0 2px var(--accent); }
/* Реакции: в нижнем левом углу пузыря, время справа на той же строке (как в Telegram) */
.msg-foot { display: flex; align-items: flex-end; gap: 8px; margin-top: 2px; }
.msg-foot .meta { float: none; margin: 0 0 -2px auto; }
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; }
.react-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 4px 0 8px; border: 0; border-radius: 13px;
  background: rgba(100, 181, 246, .16); color: var(--text); font: inherit; font-size: 15px; line-height: 1; cursor: pointer;
}
.msg-row.out .react-chip { background: rgba(255, 255, 255, .14); }
.react-chip .who { display: inline-flex; }
.react-chip .who .avatar + .avatar { margin-left: -5px; }
.react-chip .avatar { box-shadow: 0 0 0 1.5px rgba(23, 33, 43, .9); }
/* Своя реакция — заливка; на своём сообщении — другого цвета, как в Telegram */
.react-chip.mine { background: var(--accent-fill); }
.msg-row.out .react-chip.mine { background: #6AB2F2; }
.react-chip.pending { opacity: .6; }
/* Цитата в ответе: на что ответили; клик — к исходному сообщению */
.msg-quote {
  display: flex; flex-direction: column; min-width: 0; padding: 3px 8px; border-left: 3px solid var(--accent); border-radius: 4px;
  background: rgba(100, 181, 246, .1); font-size: 13px; line-height: 1.35; cursor: pointer; white-space: normal;
}
.msg-row.out .msg-quote { border-left-color: #BFE0FF; background: rgba(255, 255, 255, .1); }
.msg-quote strong { color: var(--accent); font-weight: 600; }
.msg-row.out .msg-quote strong { color: #BFE0FF; }
.msg-quote span { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.msg-row.out .msg-quote span { color: rgba(233, 238, 243, .8); }
.msg-quote.gone { cursor: default; }
.msg-row.flash .msg { animation: msg-flash 1.2s ease-out; }
@keyframes msg-flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px transparent; } }
.reply-bar .bar-icon { display: inline-flex; color: var(--accent); }

/* Столбик реакций растёт вверх из кнопки-сердечка: нижний пункт встаёт на её место, видно
   четыре, остальные — прокруткой вверх (как в Telegram Desktop) */
.react-picker {
  position: fixed; z-index: 35; display: flex; flex-direction: column-reverse; gap: 2px; width: 36px; height: 140px; padding: 4px;
  overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow); animation: viewer-in .1s ease-out;
}
.react-picker::-webkit-scrollbar { display: none; }
/* Пятая реакция выглядывает наполовину и тает вместе с верхом столбика: видно, что список
   листается вверх. Долистали до конца — показываем целиком. */
.react-picker:not(.at-end) {
  -webkit-mask-image: linear-gradient(to top, #000 calc(100% - 30px), transparent);
  mask-image: linear-gradient(to top, #000 calc(100% - 30px), transparent);
}
.react-picker.hidden { display: none; }
.react-opt {
  flex: 0 0 auto; width: 26px; height: 27px; padding: 0; border: 0; border-radius: 50%; background: transparent;
  font-size: 18px; line-height: 1; cursor: pointer; transition: transform .1s, background-color .1s;
}
.react-opt:hover { transform: scale(1.2); }
.react-opt.mine { background: var(--accent-soft); }
/* Кнопка-сердечко у нижнего угла сообщения со стороны середины чата: чуть заходит на пузырь
   и выступает снизу не больше зазора между сообщениями — соседнее не перекрывает (как в Telegram) */
.react-btn {
  position: absolute; bottom: -3px; width: 24px; height: 24px; padding: 0; border: 1px solid var(--border-strong); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  font-size: 13px; line-height: 1; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .12s;
}
.msg-row.in .react-btn { right: -17px; }
.msg-row.out .react-btn { left: -17px; }
.msg-row:hover .react-btn, .react-btn.open, .react-btn:focus-visible { opacity: 1; pointer-events: auto; }

/* Сообщения подряд с одной стороны: углы, где они смыкаются, маленькие (верхний — у всех, кроме
   первого); у последнего вместо нижнего угла «хвостик» — со стороны отправителя, как в Telegram */
.msg-row.in:not(.first-in-group) .msg { border-top-left-radius: 4px; }
.msg-row.out:not(.first-in-group) .msg { border-top-right-radius: 4px; }
.msg-row.in.last-in-group .msg { border-bottom-left-radius: 0; }
.msg-row.out.last-in-group .msg { border-bottom-right-radius: 0; }
.msg-row.last-in-group .msg::before {
  content: ""; position: absolute; bottom: 0; width: 9px; height: 17px; background: inherit;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='17'%3E%3Cpath d='M9 0C9 8 6.6 13.6 0 17h9z'/%3E%3C/svg%3E") no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='17'%3E%3Cpath d='M9 0C9 8 6.6 13.6 0 17h9z'/%3E%3C/svg%3E") no-repeat;
}
.msg-row.in.last-in-group .msg::before { left: -8px; }
.msg-row.out.last-in-group .msg::before { right: -8px; transform: scaleX(-1); }

.msg-media img { cursor: zoom-in; }
.msg-media img.sticker { cursor: default; }

/* Просмотр фото поверх переписки, как в Telegram Desktop */
.viewer { position: fixed; inset: 0; z-index: 45; display: flex; flex-direction: column; background: rgba(0, 0, 0, .95); animation: viewer-in .12s ease-out; }
@keyframes viewer-in { from { opacity: 0; } to { opacity: 1; } }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; color: #fff; }
.viewer-who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.viewer-who strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-who span { font-size: 13px; color: rgba(255, 255, 255, .6); }
.viewer-count { margin-right: 8px; font-size: 14px; color: rgba(255, 255, 255, .7); }
.viewer-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: transparent; color: rgba(255, 255, 255, .8); cursor: pointer; }
.viewer-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.viewer-stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 72px 24px; overflow: hidden; }
.viewer-stage.zoomed { display: block; overflow: auto; padding: 0; text-align: center; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; cursor: zoom-in; user-select: none; }
.viewer-img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-nav { position: absolute; top: 50%; width: 56px; height: 56px; margin-top: -28px; border: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .08); color: #fff; cursor: pointer; }
.viewer-nav:hover { background: rgba(255, 255, 255, .18); }
.viewer-nav.prev { left: 12px; }
.viewer-nav.next { right: 12px; }
.viewer-nav.hidden { display: none; }
@media (max-width: 560px) {
  .viewer-stage { padding: 0 0 16px; }
  .viewer-nav { width: 44px; height: 44px; margin-top: -22px; }
}

@media (max-width: 900px) {
  main { padding: 16px 12px 40px; }
  /* Меню — отдельной строкой во всю ширину, чтобы пункты не обрезались о «Выйти». */
  .topbar { flex-wrap: wrap; gap: 4px 12px; height: auto; padding: 8px 12px 6px; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .brand { flex: 1 1 auto; }
  .brand span, #me-name { display: none; }
  .tpl { grid-template-columns: 1fr; }
  .tpl-layout, .overview-grid { grid-template-columns: 1fr; }
  .folders { position: static; }
  .form-grid.two { grid-template-columns: 1fr; }
  /* На телефоне — как в Telegram: список или переписка на весь экран, с кнопкой «назад». */
  .inbox, body.has-banner .inbox { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 190px); height: calc(100dvh - 190px); }
  .inbox.has-current .inbox-side { display: none; }
  .inbox:not(.has-current) .chat { display: none; }
  .inbox-side { border-right: 0; min-width: 0; }
  .chat-back { display: inline-flex; }
  .msg, .msg-note { max-width: 86%; }
  .chat-head .pill, .composer-note { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* История контакта: лента событий и сообщений по времени. */
.history { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.history li { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; }
.hist-at { font-size: 12px; padding-top: 8px; }
.hist-item { padding: 8px 12px; border-radius: var(--r-control); background: var(--surface-2); }
.hist-item.msg.in { background: var(--bubble-in); border: 1px solid var(--border); }
.hist-item.msg.out { background: var(--bubble-out); }
.hist-text { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.hist-text.deleted { color: var(--text-3); text-decoration: line-through; }
@media (max-width: 560px) {
  .history li { grid-template-columns: 1fr; gap: 2px; }
  .hist-at { padding-top: 0; }
}

/* ---------- CRM: карточка кандидата ---------- */
.inbox.with-crm { position: relative; grid-template-columns: 76px 300px minmax(0, 1fr) 320px; }
.inbox-filters { display: grid; grid-template-columns: 1fr; gap: 8px; }
.crm-side { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border); }
.crm-side-head { display: flex; align-items: center; gap: 8px; min-height: 58px; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--border); }
.crm-side-head h2 { flex: 1 1 auto; font-size: 15px; }
.crm-side-head .btn, .crm-toggle { display: none; }
.crm-empty { margin: auto; padding: 24px; color: var(--text-3); font-size: 13px; text-align: center; }
.cand { display: flex; flex-direction: column; }
.cand-head { display: flex; align-items: flex-start; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cand-head strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand-sec { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cand-sec:last-child { border-bottom: 0; }
.cand-label { color: var(--text-2); font-size: 12px; font-weight: 600; }
.cand textarea { min-height: 72px; }
.cand .row.nowrap { flex-wrap: nowrap; }
.quick-days { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cand .form-actions { justify-content: flex-end; }
.modal .cand { margin: -4px -20px -20px; }
.modal .cand-head, .modal .cand-sec { padding-left: 20px; padding-right: 20px; }
.modal .cand details.help { margin-left: 20px; margin-right: 20px; }
input[type=date] { color-scheme: dark; }
input[type=date]::-webkit-calendar-picker-indicator { filter: invert(.75); cursor: pointer; }
input.overdue { border-color: rgba(240, 114, 114, .6); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags:empty { display: none; }
.tag {
  display: inline-flex; align-items: center; gap: 2px; height: 24px; padding: 0 9px; border-radius: 12px;
  background: var(--surface-3); color: var(--text); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.tag:has(.tag-x) { padding-right: 3px; }
/* На карточке (surface-2) чип темнее не бывает: светлее фон и основной цвет текста — иначе тег сливается. */
.tag.sm { height: 20px; gap: 5px; padding: 0 7px; background: var(--surface-3); color: var(--text); font-size: 11.5px; }
.tag-dot { flex: 0 0 auto; width: 8px; height: 8px; margin-right: 3px; border-radius: 50%; }
.tag.sm .tag-dot { margin-right: 0; }
.tag-dot.c1 { background: var(--tag-1); }
.tag-dot.c2 { background: var(--tag-2); }
.tag-dot.c3 { background: var(--tag-3); }
.tag-dot.none { border: 1.5px solid var(--text-3); }
.color-pick { gap: 6px; }
.menu .tag-dot { margin-right: 8px; }
.tag-x { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--text-3); cursor: pointer; }
.tag-x:hover { background: var(--surface-2); color: var(--text); }
.notes { display: flex; flex-direction: column; gap: 8px; }
.note { position: relative; padding: 8px 10px; border-radius: var(--r-control); background: var(--surface-2); }
.note-meta { padding-right: 24px; color: var(--text-2); font-size: 12px; }
.note-text { margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-text .form-actions { margin-top: 6px; }
.note-more { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; }
.note:hover .note-more { opacity: 1; }
dl.origin { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: 13px; }
dl.origin dt { color: var(--text-2); }
dl.origin dd { margin: 0; overflow-wrap: anywhere; }
dl.notify-facts { font-size: 14px; gap: 6px 16px; }
.notify-link { padding: 12px 14px; border-radius: var(--r-control); background: var(--surface-2); }
.notify-link ol { margin: 0; padding-left: 20px; line-height: 1.5; }
.notify-link li + li { margin-top: 12px; }
.notify-link li .row, .notify-link .cmd-line { margin-top: 8px; }
.notify-link p { margin: 12px 0 0; }
.cmd-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cmd { font-family: ui-monospace, Consolas, monospace; font-size: 13px; padding: 4px 8px; border-radius: 4px; background: var(--surface-3); overflow-wrap: anywhere; user-select: all; }
.cand details.help { margin: 12px 16px 16px; }
.stage-history { margin: 0; padding: 0 14px 12px 32px; font-size: 13px; color: var(--text-2); }
.stage-history li + li { margin-top: 4px; }
.reason-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.reason-list .btn { justify-content: flex-start; }
.hist-item.crm { background: var(--accent-soft); }

/* Быстрые ответы над полем ввода. */
.composer .quick { width: 40px; height: 40px; border-radius: 50%; }
.qr-menu { width: 380px; max-width: calc(100vw - 16px); display: flex; flex-direction: column; gap: 6px; padding: 8px; }
.qr-list { display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.menu .qr-list button { flex-direction: column; align-items: flex-start; gap: 2px; height: auto; padding: 8px 10px; }
.qr-list button span {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  color: var(--text-2); font-size: 12px; line-height: 1.4; white-space: normal;
}
.qr-empty { padding: 8px 10px; color: var(--text-2); font-size: 13px; }
.qr-body { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; max-width: 760px; white-space: pre-wrap; }

/* ---------- CRM: доска ---------- */
.card.filters { margin-bottom: 16px; }
.card.filters .toolbar { border-bottom: 0; }
.toolbar-check { align-items: center; height: var(--h-control); padding: 0 4px; }
.toolbar.bare { padding: 0 0 16px; border-bottom: 0; }
/* Над доской: «Сегодня», счётчики исходов, «Этапы» — в строке фильтров, без отдельных блоков. */
.toolbar-extra { display: flex; align-items: center; gap: 8px; flex: 1 1 100%; flex-wrap: wrap; }
.chip-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: none; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.chip-toggle b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip-toggle:hover { color: var(--text); border-color: #41586F; }
.chip-toggle.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.outcome-link {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 0; border-radius: var(--r-control);
  background: none; color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer;
}
.outcome-link b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.outcome-link:hover { background: var(--surface-2); color: var(--text); }

.board { display: flex; gap: 12px; align-items: stretch; overflow-x: auto; padding-bottom: 8px; min-height: 360px; }
.kcol {
  flex: 0 0 272px; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  transition: border-color .12s, background-color .12s, opacity .12s;
}
.kcol.drop { border-color: var(--accent); background: #1A2836; }
.kcol.dragging { opacity: .45; }
.kcol.drop-before { box-shadow: -3px 0 0 var(--accent); }
.kcol.drop-after { box-shadow: 3px 0 0 var(--accent); }
.kcol-head { display: flex; align-items: center; gap: 6px; min-height: 48px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--border); font-weight: 600; }
.kcol-head[draggable="true"] { cursor: grab; }
.kcol-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcol-entry { padding: 0 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 500; line-height: 18px; }
.kcol-more { width: 26px; height: 26px; }
.kcol-head:hover .kcol-more, .kcol-more.open, .kcol-more:focus-visible { opacity: 1; }
.kcol-head .inline-edit { flex: 1 1 auto; height: 30px; font-weight: 600; }
.kcol-body { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-height: 0; padding: 8px; overflow-y: auto; }
.kcol-empty { padding: 14px 8px; border: 1px dashed var(--border); border-radius: var(--r-control); color: var(--text-3); font-size: 12px; text-align: center; }
.kcol-new { border-style: dashed; border-color: var(--accent); }
.kcol-new .kcol-head input { height: 32px; }
.kcol-new .kcol-body p { margin: 4px 6px; }
.kcol-add {
  flex: 0 0 160px; display: flex; align-items: center; justify-content: center; gap: 6px; align-self: flex-start; height: 48px;
  border: 1px dashed var(--border-strong); border-radius: var(--r-card); background: none; color: var(--text-3); font: inherit; font-weight: 500; cursor: pointer;
}
.kcol-add:hover { border-color: var(--accent); color: var(--text); }

/* Карточка: кто — откуда — теги; внизу следующий шаг и сколько дней на этапе. */
.kcard {
  display: flex; flex-direction: column; gap: 8px; padding: 10px 10px 10px 12px; cursor: grab;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 10px;
}
.kcard:hover { border-color: #41586F; }
.kcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.kcard.dragging { opacity: .4; }
.kcard-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.kcard-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcard-more { width: 24px; height: 24px; }
.kcard:hover .kcard-more, .kcard:focus-within .kcard-more { opacity: 1; }
.unread-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.kcard-meta { margin-top: -4px; overflow: hidden; color: var(--text-3); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.kcard-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.kcard-foot { display: flex; align-items: center; gap: 6px; min-width: 0; padding-top: 8px; border-top: 1px solid var(--border); }
.kcard-foot:not(:has(.pill, .kcard-age)) { display: none; }
.kcard-foot .pill { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 22px; }
.kcard-age { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Исходы — панель внизу экрана, пока карточка в руке. */
.outcome-bar {
  position: fixed; left: 50%; bottom: 20px; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow);
  transform: translate(-50%, 140%); opacity: 0; pointer-events: none; transition: transform .16s ease-out, opacity .16s;
}
.outcome-bar.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.outcome-hint { padding: 0 6px; color: var(--text-3); font-size: 13px; }
.outcome {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 150px; height: 56px; padding: 0 18px;
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-card); color: var(--text-2); font-weight: 500;
  transition: border-color .12s, background-color .12s, color .12s;
}
.outcome b { color: var(--text-3); font-weight: 500; font-variant-numeric: tabular-nums; }
.outcome.drop { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.outcome.ok.drop { border-color: var(--ok); background: var(--ok-bg); }
.outcome.bad.drop { border-color: var(--bad); background: var(--bad-bg); }

/* Правка на месте. */
.inline-edit { height: 28px; padding: 0 8px; font: inherit; }

/* Редактор этапов (панель «Этапы» и «Настройки → CRM»). */
.stage-editor { display: flex; flex-direction: column; gap: 24px; }
.se-head h3 { margin: 0; }
.se-head p { margin: 2px 0 0; }
.se-list { display: flex; flex-direction: column; margin-top: 8px; border: 1px solid var(--border); border-radius: var(--r-control); }
.se-row { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.se-row:last-child { border-bottom: 0; }
.se-row.off .se-name { color: var(--text-3); }
.se-row.dragging { opacity: .4; }
.se-row.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.se-row.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.se-name { padding: 2px 4px; border-radius: 4px; font-weight: 500; }
.se-name[title] { cursor: text; }
.se-name[title]:hover { background: var(--surface-3); }
.se-row .inline-edit { flex: 1 1 auto; }
.se-count { min-width: 22px; padding: 0 6px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-size: 12px; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.se-add { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 6px 4px; border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.se-add:hover { text-decoration: underline; }
.se-add-form { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.se-add-form input { flex: 1 1 auto; height: var(--h-control-sm); }
.se-add-form select { width: auto; height: var(--h-control-sm); }

/* ---------- отчёт «Воронка» ---------- */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.fbar { display: grid; grid-template-columns: 150px minmax(0, 1fr) 120px 56px; align-items: center; gap: 12px; }
.fbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.fbar-track { height: 20px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.fbar-fill { height: 100%; border-radius: 6px; background: #3987E5; }
.fbar-val { font-size: 13px; text-align: right; }
.fbar-days { font-size: 12px; text-align: right; }
tr.total td { font-weight: 600; border-top: 1px solid var(--border-strong); }
tr.off td { color: var(--text-2); }

@media (max-width: 1180px) {
  .inbox.with-crm { grid-template-columns: 76px 300px minmax(0, 1fr); }
  .inbox.with-crm .crm-side { display: none; }
  .inbox.with-crm.show-crm .crm-side {
    display: flex; position: absolute; top: 0; right: 0; bottom: 0; z-index: 6; width: min(360px, 100%);
    box-shadow: var(--shadow);
  }
  .crm-side-head .btn, .crm-toggle { display: inline-flex; }
}
@media (max-width: 900px) {
  .inbox.with-crm { grid-template-columns: minmax(0, 1fr); }
  .inbox-folders { display: none; }
  .inbox-filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .inbox-filters .folder-select { display: block; }
  .kcol { flex-basis: 82vw; }
  .fbar { grid-template-columns: 110px minmax(0, 1fr) 90px; }
  .fbar-days { display: none; }
  .reason-list { grid-template-columns: 1fr; }
}

/* Телефон: логотип, переключатель направлений и «Выйти» — в одну строку. */
@media (max-width: 560px) {
  .topbar { gap: 4px 8px; }
  .brand img { height: 18px; }
  .ws-switch a { padding: 0 8px; font-size: 12px; }
  .me .btn { padding: 0 6px; }
}

/* Архивный этап в истории: нынешнее название + пометка. */
.hist-archived { margin-left: 6px; padding: 0 6px; border-radius: 5px; background: var(--surface-3); color: var(--text-2); font-size: 11px; font-weight: 500; line-height: 18px; vertical-align: 1px; }

/* Плашка типа исхода в редакторе этапов — кнопка с меню. */
button.pill.kind-pill { border: 0; font: inherit; cursor: pointer; }
button.pill.kind-pill:hover { filter: brightness(1.15); }
