/* ============================================================================
   Мини-CRM — оформление рабочего интерфейса.

   Файл собран по разделам в том порядке, в каком они встречаются на экране:
   токены → каркас → примитивы → прозвон → воронка → карточка → админка.
   Раньше правила росли хронологически и одни и те же блоки лежали в трёх
   несмежных местах, а drawer был объявлен дважды с противоположными
   значениями. Если добавляете правило — кладите его в свой раздел, а не в
   конец файла.

   Печатное КП оформляется отдельным offer.css и этого файла не касается.
   ========================================================================= */

/* --- Токены ------------------------------------------------------------- */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Поверхности: три уровня вместо семнадцати оттенков «почти белого». */
  --surface: #ffffff;
  --surface-sunken: #f7f8fa;
  --surface-muted: #eef1f5;
  --canvas: #f3f5f8;

  /* Текст: четыре уровня контраста, все проходят AA на своих фонах. */
  --ink: #101828;
  --ink-2: #475467;
  --ink-3: #667085;
  --ink-4: #98a2b3;
  --muted: var(--ink-3); /* историческое имя, встречается в разметке */

  /* Границы. */
  --line: #e4e7ec;
  --line-strong: #d0d5dd;

  /* Акцент — один синий на всё приложение. */
  --accent: #2f5bd7;
  --accent-hover: #2749b4;
  --accent-ink: #24439e;
  --accent-soft: #eef2fe;
  --accent-line: #c7d4f7;

  /* Семантика: заливка, контур и текст для каждого смысла. */
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --danger-line: #f4c7c3;
  --success: #067647;
  --success-soft: #ecfdf3;
  --success-line: #a9d6bf;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --warning-line: #f0c987;

  /* Грейды: A — самые перспективные, C — самые слабые из показываемых. */
  --grade-a: #067647;
  --grade-b: #dc9a06;
  --grade-c: #98a2b3;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 64px rgba(16, 24, 40, 0.24);
  --overlay: rgba(16, 24, 40, 0.55);

  /* Слои. Раньше это были магические числа в четырёх местах. */
  --z-topbar: 20;
  --z-drawer: 60;
  --z-modal: 90;
  --z-toast: 100;

  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  font-size: 13px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }

h1, h2, h3, h4 { letter-spacing: -0.011em; }

/* Табличные цифры: суммы и телефоны выстраиваются в колонку по разрядам. */
.money-cell,
.phone-number,
.day-count,
.stat-value,
.card-sum,
.violation-fine { font-variant-numeric: tabular-nums; }

[x-cloak] { display: none !important; }

/* --- Шапка -------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: 40px;
  height: 56px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark, .login-logo {
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #4268e8, #2544a5);
  border-radius: 8px;
  font-weight: 700;
}

.brand-mark { width: 28px; height: 28px; font-size: 14px; }

.nav-tabs { display: flex; align-items: center; gap: 4px; }

.nav-tabs a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-weight: 500;
  text-decoration: none;
}

.nav-tabs a:hover { background: var(--surface-sunken); color: var(--ink); }
.nav-tabs a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.user-menu {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.role {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-sunken);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 500;
}

.link-button {
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
}

.link-button:hover { color: var(--accent-hover); text-decoration: underline; }

/* --- Каркас страницы ---------------------------------------------------- */

.workspace { padding: 20px 20px 48px; }

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.page-heading h1 { margin: 0 0 3px; font-size: 22px; font-weight: 600; }
.page-heading p { margin: 0; color: var(--ink-3); font-size: 13px; }

/* --- Кнопки ------------------------------------------------------------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); }

.button.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
}

.button.secondary:hover { background: var(--surface-sunken); border-color: var(--ink-4); }

.button.wide { width: 100%; }
.button.compact { min-height: 30px; padding: 5px 10px; font-size: 12px; }

/* --- Поля ввода --------------------------------------------------------- */

.filters input,
.filters select,
.stack-form input,
.stack-form textarea,
.drawer-form input,
.drawer-form select,
.drawer-form textarea,
.note-form textarea,
.file-upload select,
.file-upload input,
.manager-filter select,
.admin-inline-form input,
.admin-inline-form select,
.status-admin-row input,
.status-admin-row select,
.reset-form input,
.contacts-form input,
.admin-stack-form input,
.admin-stack-form select,
.company-grid input,
.review-grid input,
.status-select,
.move-day-form input[type=date],
.move-lead-form input[type=date] {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
}

.filters input:focus,
.filters select:focus,
.stack-form input:focus,
.stack-form textarea:focus,
.drawer-form input:focus,
.drawer-form textarea:focus,
.status-select:focus,
.note-form textarea:focus {
  outline: 2px solid var(--accent-line);
  outline-offset: -1px;
  border-color: var(--accent);
}

/* --- Фильтры ------------------------------------------------------------ */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.filters label { display: flex; flex-direction: column; gap: 4px; min-width: 108px; }

.filters label span,
.stack-form label,
.drawer-form label,
.admin-inline-form label,
.company-grid label,
.review-grid label {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 500;
}

/* Подпись всегда над полем: иначе она встаёт слева и съедает ширину ввода.
   Остальные формы задают это в своих разделах. */
.admin-inline-form label,
.company-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filters .search-field { min-width: 220px; flex: 1; }
.filters select { max-width: 170px; }

.clear-filter {
  align-self: center;
  margin: 18px 2px 0;
  color: var(--ink-3);
  font-size: 12px;
}

.active-filter {
  display: inline-flex;
  gap: 10px;
  padding: 6px 10px;
  margin: 0 0 12px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.active-filter a { color: inherit; text-decoration: none; font-weight: 700; }

/* --- Списки прозвона по дням -------------------------------------------- */

.day-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
}

.day-tabs { display: flex; flex-wrap: wrap; gap: 6px; }

.day-tab {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 78px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-2);
  text-decoration: none;
}

.day-tab:hover { border-color: var(--line-strong); background: var(--surface-sunken); }

.day-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.day-tab.done { opacity: 0.5; }
.day-name { font-size: 11px; font-weight: 500; }
.day-count { font-size: 16px; font-weight: 600; line-height: 1.2; }
.day-count small { font-size: 11px; font-weight: 400; color: var(--ink-4); }

.day-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.move-day-form, .move-lead-form { display: flex; align-items: center; gap: 6px; }
.move-day-form label { display: flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: 12px; }
.move-day-form input[type=date] { min-height: 30px; font-size: 12px; }

/* --- Таблица прозвона --------------------------------------------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.lead-table { width: 100%; min-width: 1080px; border-collapse: collapse; }

.lead-table th {
  padding: 9px 12px;
  text-align: left;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.lead-table td {
  padding: 10px 12px;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.lead-table tr:last-child td { border-bottom: 0; }
.lead-table tbody tr:hover td { background: var(--surface-sunken); }
.lead-table a { color: var(--accent); text-decoration: none; }
.lead-table a:hover { text-decoration: underline; }

/* Ширины: нарушения занимают всё свободное место, остальное — по содержимому. */
.lead-table th:nth-child(1), .lead-table td:nth-child(1) { width: 196px; }
.lead-table th:nth-child(2), .lead-table td:nth-child(2) { width: 210px; }
.lead-table th:nth-child(3), .lead-table td:nth-child(3) { width: 206px; }
.lead-table th:nth-child(5), .lead-table td:nth-child(5) { width: 124px; }

/* Состояния строки. Заливка бледная: цвет здесь — метка, а не акцент. */
.lead-table tr.row-callback td { background: var(--warning-soft); }
.lead-table tr.row-callback:hover td { background: #fff4d6; }
.lead-table tr.row-overdue td { background: var(--danger-soft); }
.lead-table tr.row-overdue:hover td { background: #fde8e6; }
.lead-table tr.row-processed td { color: var(--ink-3); }
.lead-table tr.row-processed .company-name { color: var(--ink-2); font-weight: 500; }

/* --- Ячейка «Статус / действие» (первая) -------------------------------- */

.status-cell { min-width: 196px; }

.current-status {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 500;
}

.current-status.is-new { background: transparent; padding-left: 0; color: var(--ink-4); }
.current-status.behavior-ndz { background: var(--warning-soft); color: var(--warning); }
.current-status.behavior-callback { background: var(--accent-soft); color: var(--accent-ink); }
.current-status.behavior-interest { background: var(--success-soft); color: var(--success); }
.current-status.behavior-refused { background: var(--danger-soft); color: var(--danger); }

.status-flags { display: flex; flex-wrap: wrap; gap: 4px; }
.status-flags:not(:empty) { margin-top: 5px; }

/* Выпадающий список результата звонка: одно поле вместо четырёх кнопок. */
.status-select {
  width: 100%;
  margin-top: 8px;
  cursor: pointer;
  font-weight: 500;
}

.move-lead-form { margin-top: 6px; }
.move-lead-form input[type=date] { min-height: 28px; padding: 2px 6px; font-size: 11px; }
.move-lead-form .link-button { color: var(--ink-3); font-size: 11px; }

/* --- Ячейка компании ---------------------------------------------------- */

.grade-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  margin-right: 6px;
  padding: 0 5px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

.grade-a { background: var(--grade-a); }
.grade-b { background: var(--grade-b); color: #4a3600; }
.grade-c { background: var(--grade-c); }
.grade-d { background: var(--surface-muted); color: var(--ink-4); }

/* Грейд и название — соседние колонки, иначе длинное название заворачивается
   под бейдж и строка теряет левый край. Флекс живёт на обёртке, а не на самой
   ячейке: `display:flex` у <td> выбивает её из табличной раскладки и границы
   строки начинают рисоваться по высоте содержимого. */
.company-line { display: flex; align-items: flex-start; gap: 6px; }
.company-line .grade-tag { flex: 0 0 auto; margin-right: 0; }

.company-name { min-width: 0; font-weight: 600; font-size: 13px; color: var(--ink); }
.meta { display: block; margin: 3px 0 0 25px; color: var(--ink-4); font-size: 11px; }

/* Цветная засечка слева повторяет грейд — список читается по краю. */
tr:has(.grade-a) td:first-child { box-shadow: inset 3px 0 0 var(--grade-a); }
tr:has(.grade-b) td:first-child { box-shadow: inset 3px 0 0 var(--grade-b); }
tr:has(.grade-c) td:first-child { box-shadow: inset 3px 0 0 var(--grade-c); }

/* --- Ячейка контактов --------------------------------------------------- */

.contacts-cell { min-width: 206px; }

/* Кнопка копирования переносится под номер, а не выдавливает его из колонки. */
.phone-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.phone-number { font-size: 14px; font-weight: 600; color: var(--ink) !important; }
.phone-number:hover { color: var(--accent) !important; }

.copy-button {
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
}

.copy-button:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.row-site {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  color: var(--ink-3) !important;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-action {
  display: inline-flex;
  align-items: center;
  margin-top: 5px;
  padding: 3px 8px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-ink) !important;
  font-size: 11px;
  font-weight: 500;
  text-decoration: none !important;
}

.site-action:hover { background: #e2e9fd; border-color: var(--accent); }

/* --- Бейджи ------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
}

.badge.duplicate { margin-top: 5px; background: var(--surface-muted); color: var(--ink-2) !important; }
.badge.no-phone { background: var(--surface-muted); color: var(--ink-3); }
.badge.ndz { background: var(--warning-soft); color: var(--warning); }
.badge.web-form { background: var(--success-soft); color: var(--success); }

/* --- Нарушения ---------------------------------------------------------- */

/* Блок рендерится в двух местах: узкая ячейка таблицы и широкая секция
   карточки. Поэтому здесь только вертикальный ритм, без фиксированных ширин. */
.violations-cell { min-width: 340px; }

.violations { display: flex; flex-direction: column; gap: 8px; }
.violations-group { display: flex; flex-direction: column; gap: 2px; }

.violations-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.violations-label.serious { color: var(--danger); }
.violations-label.additional { color: var(--warning); }

.violation-item { margin: 0 0 2px; font-size: 12px; line-height: 1.5; color: var(--ink-2); }
.violation-title { color: var(--ink); font-weight: 600; }
.violation-fine { color: var(--danger); font-weight: 700; white-space: nowrap; }
.violation-article { color: var(--ink-3); font-size: 11px; }
.violation-note { color: var(--ink-4); font-size: 11px; }

.violation-proof {
  margin-left: 5px;
  color: var(--accent) !important;
  font-size: 10px;
  text-decoration: none;
  border-bottom: 1px dotted var(--accent-line);
}

.violations-raw { margin: 0; font-size: 12px; line-height: 1.45; white-space: pre-wrap; color: var(--ink-2); }
.violations-empty { color: var(--ink-4); }

/* --- Сумма штрафов ------------------------------------------------------ */

/* Второй акцент экрана после грейда: разговор строится вокруг этой цифры. */
.money-cell {
  text-align: right;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

th.money-cell { text-align: right; }

/* --- Пагинация и пустое состояние --------------------------------------- */

.pagination { display: flex; justify-content: center; align-items: center; gap: 16px; margin: 18px; }

.pagination a {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}

.pagination a:hover { border-color: var(--line-strong); background: var(--surface-sunken); }
.pagination span { font-size: 12px; color: var(--ink-3); }

.empty-state {
  display: flex;
  min-height: 340px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.empty-state h2 { margin: 10px 0 4px; font-size: 17px; font-weight: 600; }
.empty-state p { margin: 0 0 16px; color: var(--ink-3); }
.empty-icon { font-size: 26px; color: var(--accent); }

/* --- Модальные окна ----------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--overlay);
}

#modal .modal-backdrop { z-index: var(--z-modal); }

.modal-card {
  position: relative;
  width: min(540px, 96vw);
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-card.small { width: min(420px, 96vw); }
.modal-card h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.modal-card > p { margin: 0 0 16px; color: var(--ink-3); }

.modal-close {
  position: absolute;
  right: 12px;
  top: 10px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-3);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover { background: var(--surface-sunken); color: var(--ink); }

.modal-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stack-form { display: flex; flex-direction: column; gap: 12px; }
.stack-form label { display: flex; flex-direction: column; gap: 5px; }
.stack-form textarea { min-height: 70px; resize: vertical; }

.file-drop {
  padding: 20px !important;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  text-align: center;
  color: var(--ink) !important;
}

.file-drop input { border: 0; margin-top: 8px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.htmx-indicator { display: none; color: var(--ink-3); font-size: 12px; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

/* Недозвон: инструкция «оставьте заявку на сайте» перед закрытием лида. */
.ndz-modal .stack-form { gap: 10px; }
.ndz-modal .stack-form + .stack-form { margin-top: 8px; }

.ndz-steps {
  margin: 0 0 16px;
  padding-left: 20px;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.6;
}

.ndz-modal .button.secondary[href] { margin-bottom: 14px; }

.ndz-no-site {
  margin: 0 0 14px;
  padding: 9px 11px;
  border: 1px solid var(--warning-line);
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12px;
}

.ndz-skip { align-self: center; color: var(--ink-3); font-size: 12px; }

/* --- Отчёт импорта ------------------------------------------------------ */

.import-summary { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.import-summary h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }

.summary-grid div {
  display: flex;
  flex-direction: column;
  padding: 10px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
}

.summary-grid strong { font-size: 21px; font-weight: 600; }
.summary-grid span { font-size: 11px; color: var(--ink-3); }

/* --- Сообщения ---------------------------------------------------------- */

.alert { padding: 10px 12px; margin: 12px 0; border-radius: var(--radius-sm); font-size: 13px; }
.alert-error { background: var(--danger-soft); border: 1px solid var(--danger-line); color: var(--danger); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--z-toast);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  transform: translateY(16px);
  opacity: 0;
  transition: 0.18s;
  pointer-events: none;
}

.toast.show { transform: none; opacity: 1; }
.toast.error { background: var(--danger); }

.hint { font-size: 12px; color: var(--ink-3); }
.hint.error { color: var(--danger); }
.muted { color: var(--ink-3); font-size: 11px; }

/* --- Вход --------------------------------------------------------------- */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top, #e8eefc 0, var(--canvas) 46%, var(--canvas) 100%);
}

.login-card {
  width: min(380px, 100%);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.login-logo { width: 44px; height: 44px; margin-bottom: 18px; font-size: 20px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; }
.login-card > p { margin: 0 0 20px; color: var(--ink-3); }

/* --- Воронка ------------------------------------------------------------ */

.funnel-workspace { padding: 20px 0 32px; }
.funnel-heading { padding: 0 20px; }
.manager-filter label { display: flex; align-items: center; gap: 8px; color: var(--ink-3); font-size: 12px; }

.kanban-board {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 0 20px 20px;
  overflow-x: auto;
  min-height: calc(100vh - 190px);
}

.kanban-column {
  flex: 0 0 286px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.kanban-column > header { padding: 12px 12px 10px; background: var(--surface-sunken); border-bottom: 1px solid var(--line); }
.kanban-column h2 { margin: 0 0 6px; font-size: 13px; font-weight: 600; }
.kanban-column header div { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); }
.kanban-column header strong { color: var(--ink); font-weight: 600; }

.kanban-list { min-height: 170px; padding: 8px; }

.kanban-card {
  position: relative;
  margin-bottom: 8px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.kanban-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); }
.kanban-card.overdue { border-color: var(--danger-line); background: var(--danger-soft); }
.kanban-card h3 { margin: 0 22px 3px 0; font-size: 13px; font-weight: 600; }

.drag-handle { position: absolute; right: 8px; top: 7px; color: var(--ink-4); font-size: 16px; cursor: grab; }

.card-city { margin: 0; color: var(--ink-3); font-size: 11px; }
.card-sum { margin: 10px 0 8px; font-size: 14px; font-weight: 600; }

.next-action {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-size: 10px;
}

.next-action span, .next-action.empty { color: var(--ink-3); }
.next-action strong { font-size: 11px; font-weight: 600; }
.next-action time { color: var(--ink-2); }
.next-action.late { background: var(--danger-soft); color: var(--danger); }
.next-action.late time { color: var(--danger); }

.card-files { display: flex; gap: 4px; margin-top: 8px; }

.card-files span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 19px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 8px;
  font-weight: 700;
}

.kanban-empty {
  padding: 24px 8px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-4);
  font-size: 11px;
  text-align: center;
}

.card-ghost { opacity: 0.35; transform: rotate(1deg); }

/* --- Карточка лида ------------------------------------------------------ */

/* Открывается по центру экрана: в воронке менеджер работает с ней как с
   основным окном, а не как со справкой сбоку. */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
}

.lead-drawer {
  position: relative;
  width: min(980px, 96vw);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--canvas);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.drawer-close {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 3;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-3);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.drawer-close:hover { color: var(--ink); }

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 64px 20px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.drawer-kicker {
  display: block;
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.drawer-header h2 { margin: 5px 0 3px; font-size: 21px; font-weight: 600; }
.drawer-header p { margin: 0; color: var(--ink-3); }

.drawer-fines { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.drawer-fines span { font-size: 10px; color: var(--ink-3); }
.drawer-fines strong { margin-top: 3px; font-size: 17px; font-weight: 600; }

.drawer-fines em {
  margin-top: 6px;
  padding: 3px 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 10px;
  font-style: normal;
}

.drawer-section {
  margin: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.drawer-section h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title h3 { margin: 0; }
.section-title p { margin: 0; color: var(--ink-3); font-size: 12px; }

.contact-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.contact-strip > div { padding: 9px; background: var(--surface-sunken); border-radius: var(--radius-sm); }
.contact-strip span { display: block; margin-bottom: 3px; color: var(--ink-3); font-size: 10px; }
.contact-strip a { color: var(--accent); text-decoration: none; font-size: 13px; }

/* В карточке кнопка копирования — глиф ⧉, а не подпись: место на строке одно. */
.contact-strip .copy-button { padding: 0 4px; border: 0; background: none; font-size: 14px; }

.form-grid { display: grid; gap: 10px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }

.drawer-form label { display: flex; flex-direction: column; gap: 4px; }
.drawer-form input, .drawer-form select, .drawer-form textarea { width: 100%; }

.next-action-form {
  display: grid;
  grid-template-columns: 1fr 210px;
  gap: 10px;
  margin-top: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}

.next-action-form.overdue { background: var(--danger-soft); }

.violations-section h4 { margin: 12px 0 6px; color: var(--danger); font-size: 12px; font-weight: 600; }
.violations-section h4 + ul { margin: 0; padding-left: 18px; }
.violations-section li { margin: 4px 0; font-size: 12px; line-height: 1.45; }

.raw-requisites { margin-bottom: 12px; }
.requisites-grid { align-items: start; }
.field-inline { display: flex; gap: 5px; }
.field-inline input { min-width: 0; }

.small-action, .registry-link {
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--accent-ink) !important;
  font-size: 10px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.small-action:hover, .registry-link:hover { border-color: var(--accent); background: var(--accent-soft); }

.file-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }

.file-list > div {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.file-kind { min-width: 60px; color: var(--ink-3); font-size: 9px; text-transform: uppercase; }
.file-list a { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--accent); text-decoration: none; }
.file-list small { margin-left: auto; color: var(--ink-3); white-space: nowrap; }
.file-list form { display: inline; }
.file-list button { border: 0; background: none; color: var(--danger); font-size: 16px; cursor: pointer; }

.file-upload { display: grid; grid-template-columns: 120px 1fr auto; gap: 7px; align-items: center; }
.file-upload input { padding: 5px; }

.note-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.note-form textarea { width: 100%; min-height: 56px; resize: vertical; }

.timeline { display: flex; flex-direction: column; }

.timeline article {
  position: relative;
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 8px;
  padding-bottom: 14px;
}

.timeline article:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 11px;
  bottom: 0;
  width: 1px;
  background: var(--line);
}

.timeline-dot {
  z-index: 1;
  width: 11px;
  height: 11px;
  margin-top: 3px;
  border: 3px solid var(--accent-line);
  border-radius: 50%;
  background: var(--surface);
}

.timeline strong { display: block; font-size: 12px; font-weight: 600; }
.timeline p { margin: 3px 0; font-size: 12px; line-height: 1.4; white-space: pre-wrap; }
.timeline small { color: var(--ink-3); font-size: 10px; }

/* --- Документы и КП ----------------------------------------------------- */

.drawer-doc-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.drawer-doc-action.primary { background: var(--accent-soft); border-color: var(--accent-line); }
.drawer-doc-action > div { display: flex; flex-direction: column; gap: 3px; }
.drawer-doc-action strong { font-size: 14px; font-weight: 600; }
.drawer-doc-action span { font-size: 11px; color: var(--ink-3); }

.drawer-action-buttons { display: flex; gap: 8px; flex-shrink: 0; }

.document-modal { width: min(720px, 96vw); max-height: 92vh; overflow-y: auto; }
.document-modal textarea { min-height: 180px; resize: vertical; }

.review-modal { width: min(820px, 96vw); }
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.review-grid label { display: flex; flex-direction: column; gap: 4px; }
.review-grid input.missing { border-color: var(--warning-line); background: var(--warning-soft); }
/* Пустое обязательное поле — не «жёлтое, посмотри», а «красное, без него
   документы не сформируются». Оттенок отличает две разные ситуации: КПП у ИП
   пуст законно, а ИНН пустым быть не может. */
.review-grid .required-field input.missing { border-color: var(--danger-line); background: var(--danger-soft); }
.required-mark { color: var(--danger); font-weight: 600; }

/* Исходный текст под катом: он нужен для правки и повторного разбора, но
   занимать собой всё окно проверки не должен. */
.raw-details { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 11px; }
.raw-details summary { cursor: pointer; font-size: 12px; color: var(--ink-3); }
.raw-details textarea { min-height: 120px; margin-top: 8px; }
.raw-details .button { margin-top: 8px; }

/* Объяснение ожидания. Показывается тем же механизмом htmx-indicator, что и
   многоточие на кнопке, поэтому display переопределяем на block. */
.htmx-request .wait-hint.htmx-indicator { display: block; }
.wait-hint { margin: 8px 0 0; font-size: 12px; color: var(--ink-3); }

.field-hint { font-size: 11px; color: var(--ink-3); font-weight: 400; }
.modal-subject { font-size: 13px; color: var(--ink-2); margin: 0 0 4px; }

.alert-warning { background: var(--warning-soft); border: 1px solid var(--warning-line); color: var(--warning); }

.modal-hint {
  margin: -4px 0 12px;
  padding: 9px 11px;
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
}

.modal-hint.warning { border-color: var(--warning-line); background: var(--warning-soft); color: var(--warning); }

.kp-text {
  margin: 0;
  padding: 12px;
  max-height: 260px;
  overflow: auto;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.kp-modal .checkbox-line { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; }
.kp-modal .checkbox-line input { min-height: auto; }

.kp-findings { border-top: 1px solid var(--line); padding-top: 12px; }

.kp-findings-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kp-findings-list li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  font-size: 12px;
  line-height: 1.4;
}

.kp-findings-list li.severity-serious { background: var(--danger-soft); }
.kp-findings-list li.severity-info { background: var(--surface-muted); color: var(--ink-3); }

.kp-finding-law { flex-shrink: 0; color: var(--ink-3); font-size: 10px; font-weight: 600; text-transform: uppercase; }

/* --- Настройки ---------------------------------------------------------- */

.admin-workspace { max-width: 1440px; margin: 0 auto; }

.admin-notice {
  margin: -4px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--success-line);
  border-radius: var(--radius-sm);
  background: var(--success-soft);
  color: var(--success);
  font-size: 13px;
  font-weight: 500;
}

.admin-notice.warning { border-color: var(--warning-line); background: var(--warning-soft); color: var(--warning); }

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }

.admin-panel {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.admin-panel.admin-wide { grid-column: 1 / -1; }
.admin-panel h2 { margin: 0 0 3px; font-size: 16px; font-weight: 600; }

.admin-inline-form {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.1fr auto;
  gap: 9px;
  align-items: end;
  padding: 12px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.admin-inline-form.status-create { grid-template-columns: 1.6fr 1fr 120px auto; }
/* Форма создания менеджера шире прочих: имя, логин, телефон, почта, пароль
   и кнопка. Без своей сетки поля переносились бы по базовым четырём колонкам. */
.admin-inline-form.user-create { grid-template-columns: 1.1fr 0.9fr 1fr 1.3fr 1fr auto; }

.admin-list, .status-admin-list { display: flex; flex-direction: column; }

.admin-user {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 78px minmax(240px, 1.7fr) minmax(150px, 0.9fr) 96px;
  gap: 12px;
  align-items: center;
  padding: 10px 4px;
  border-top: 1px solid var(--line);
}

.admin-user:first-child { border-top: 0; }
.admin-user.inactive { opacity: 0.6; }
.admin-user > div { display: flex; flex-direction: column; }
.admin-user span { color: var(--ink-3); font-size: 11px; }

.state-pill {
  justify-self: start;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink-3) !important;
  font-size: 10px !important;
  font-weight: 600;
}

.state-pill.on { background: var(--success-soft); color: var(--success) !important; }

.reset-form { display: flex; gap: 6px; }
.reset-form input { min-width: 0; flex: 1; }
/* Контакты менеджера: телефон и почта в столбик, кнопка под ними слева. Два
   поля в одну строку на 240px не помещаются, а грид строки центрирует ячейку
   по вертикали — разная высота с формой пароля рядом не мешает. */
.contacts-form { display: flex; flex-direction: column; gap: 5px; }
.contacts-form input { min-width: 0; }
.contacts-form button { align-self: start; }
.danger-link { color: var(--danger); }

.status-admin-row {
  display: grid;
  grid-template-columns: minmax(240px, 1.5fr) 160px 90px 110px 80px auto;
  gap: 8px;
  align-items: center;
  padding: 8px 4px;
  border-top: 1px solid var(--line);
}

.status-admin-row:first-child { border-top: 0; }

.check-label, .checkbox-label { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12px; }
.check-label input, .checkbox-label input { min-height: auto; width: auto; }

/* Флажок и его подпись стоят в строку. Без этого более «сильный» селектор
   подписи поля (.admin-inline-form label) разворачивает их в столбик. */
.admin-inline-form .checkbox-label,
.admin-inline-form .check-label { flex-direction: row; align-items: center; }

.system-mark { color: var(--ink-3); font-size: 10px; }

.admin-stack-form { display: flex; flex-direction: column; gap: 9px; }

.admin-stack-form label {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 160px 15px;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 12px;
}

.admin-stack-form label em { color: var(--ink-3); font-style: normal; }
.admin-stack-form .button { margin-top: 4px; }

.template-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.template-list div { display: flex; flex-direction: column; padding: 9px; background: var(--surface-sunken); border-radius: var(--radius-sm); }
.template-list strong { font-size: 12px; font-weight: 600; }
.template-list span { margin-top: 2px; color: var(--ink-3); font-size: 10px; }

.template-upload label { display: flex; flex-direction: column; align-items: stretch; gap: 5px; }

.company-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.company-grid .button { grid-column: 1 / -1; justify-self: end; margin-top: 4px; }

/* --- Сбор лидов --------------------------------------------------------- */

.run-progress { margin: 12px 0; }
.run-bar { height: 8px; border-radius: 4px; background: var(--surface-muted); overflow: hidden; }
.run-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #5b8bff); transition: width 0.4s ease; }

.run-numbers { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 10px; font-size: 13px; color: var(--ink-2); }

.run-log summary { margin-top: 8px; color: var(--accent); font-size: 13px; cursor: pointer; }

.run-log pre {
  max-height: 220px;
  overflow: auto;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #0f172a;
  color: #d8e3f5;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.pick-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 12px; }
.pick-group { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.pick-group legend { padding: 0 6px; font-size: 13px; font-weight: 600; }
.pick-item { display: block; padding: 3px 0; font-size: 13px; cursor: pointer; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

.stat-tile {
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.stat-label { display: block; font-size: 12px; color: var(--ink-3); }
.stat-value { display: block; margin: 4px 0; font-size: 22px; font-weight: 600; color: var(--ink); }
.stat-note { font-size: 11px; color: var(--ink-4); }

.order-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.order-main { flex: 1 1 380px; display: flex; flex-direction: column; gap: 3px; }
.order-main span { font-size: 12px; color: var(--ink-3); }

/* --- Узкие экраны ------------------------------------------------------- */

/* Раньше у body стоял min-width:1180px и вся страница, включая шапку, ездила
   по горизонтали. Теперь скроллится только таблица — внутри своей рамки. */
@media (max-width: 1100px) {
  .topbar { gap: 16px; padding: 0 12px; }
  .workspace { padding: 16px 12px 40px; }
  .funnel-heading, .kanban-board { padding-left: 12px; padding-right: 12px; }
  .admin-grid, .contact-strip, .form-grid.two, .company-grid, .review-grid { grid-template-columns: 1fr; }
  .next-action-form { grid-template-columns: 1fr; }
  .admin-user, .status-admin-row { grid-template-columns: 1fr; gap: 6px; }
  /* Форма создания менеджера тоже сворачивается в столбик, иначе шесть полей
     не помещаются в узкую колонку и разъезжаются. */
  .admin-inline-form.user-create { grid-template-columns: 1fr; }
}
