/* ============================================================
   crm-workbench.css — рабочий слой для экранов с данными.

   Грузится после crm-theme.css и говорит на его языке: те же токены,
   волосяные линии, единственный акцент. Отвечает за плотность и за
   элементы, которые дорисовывает crm-workbench.js: сортировку колонок,
   строку итогов, поиск, диапазон дат, чипы статусов и сброс фильтров.
   ============================================================ */

/* ============================================================
   1. Заголовок раздела: заголовок слева, действия одной строкой справа
   ============================================================ */
.crm-section-header {
  flex-wrap: wrap;
  row-gap: 12px;
}

.crm-section-header > :first-child {
  min-width: 0;
}

/* Только в строку: в колонке (мобильный) center увёл бы заголовок к середине
   экрана, а flex-basis стал бы высотой */
@media (min-width: 901px) {
  .crm-section-header {
    align-items: center;
  }

  .crm-section-header > :first-child {
    flex: 1 1 260px;
  }
}

/* У Russo One одно начертание: жирность браузер дорисовывает сам,
   и буквы заголовка расплываются */
.crm-page .crm-section-title,
#section-booking-widget .bw-toolbar h1 {
  color: var(--crm-text);
  font-family: var(--heading-font-family, Inter, sans-serif);
  font-size: 22px;
  font-weight: 400;
  font-synthesis: none;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* Иконка стояла только у части разделов; разделы различает сайдбар */
.crm-section-title > i {
  display: none;
}

/* Надпись над заголовком была у трёх разделов и ничего не добавляла к названию */
.crm-section-header .crm-section-kicker {
  display: none;
}

/* Главная кнопка плоская, как и вся тема: заливка одним акцентом */
.crm-page .btn.primary {
  background: var(--crm-accent);
}

/* Общий стиль кнопок перебивал подсветку: в расписании не было видно,
   какой режим открыт. Тёмный текст на акценте — ради контраста. */
.crm-page .crm-view-toggle .btn.active,
#section-callbacks .crm-view-toggle .btn.active {
  background: var(--crm-accent);
  color: #090909;
}

/* Подсказки не тянутся на всю ширину: 80 знаков читаются, 130 — нет */
.crm-alert > span,
.publication-review-notice > span,
.team-security-note > div,
.crm-section-header .muted {
  max-width: 72ch;
}

.arena-drop__placeholder small {
  font-size: 11px;
}

/* ============================================================
   Дашборд: сначала смена, месяц — тихой строкой под ней
   ============================================================ */
.crm-page .crm-card.crm-dashboard-focus {
  margin-bottom: 10px;
  padding: 12px 16px 14px;
}

.crm-dashboard-focus .crm-card-header {
  margin-bottom: 8px;
  padding: 0;
  border: 0;
}

.crm-dashboard-focus-list {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
}

.crm-dashboard-focus-item {
  min-width: 0;
  min-height: 0;
  padding: 4px 16px;
  border: 0;
  border-radius: 0;
  background: none;
}

.crm-dashboard-focus-item:first-child {
  padding-left: 0;
}

.crm-dashboard-focus-item + .crm-dashboard-focus-item {
  border-left: 1px solid var(--crm-line-soft);
}

.crm-dashboard-focus-item strong {
  font-size: 22px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.crm-dashboard-grid:not(:has(> .crm-dashboard-side)) {
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 1181px) {
  #section-dashboard .crm-kpi-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  #section-dashboard .crm-kpi-card {
    gap: 10px;
    padding: 10px 12px;
  }

  #section-dashboard .crm-kpi-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  #section-dashboard .crm-kpi-value {
    font-size: 18px;
  }
}

@media (max-width: 640px) {
  .crm-dashboard-focus-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    row-gap: 10px;
  }

  .crm-dashboard-focus-item {
    gap: 10px;
    padding: 0 0 0 12px;
  }

  .crm-dashboard-focus-item:nth-child(odd) {
    padding-left: 0;
    border-left: 0;
  }

  .crm-dashboard-focus-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .crm-dashboard-focus-item strong {
    font-size: 18px;
  }
}

.crm-section-actions {
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.crm-section-actions .crm-filter-date {
  flex: 0 0 auto;
}

/* Опасные действия не стоят рядом с главной кнопкой ярким пятном:
   контур в обычном состоянии, заливка — только под курсором. */
.crm-page .crm-section .btn.danger {
  background: transparent;
  border: 1px solid rgba(242, 96, 108, 0.42);
  color: var(--crm-danger);
}

.crm-page .crm-section .btn.danger:hover,
.crm-page .crm-section .btn.danger:focus-visible {
  background: var(--crm-danger);
  border-color: transparent;
  color: #170608;
}

.crm-section-actions .btn.danger {
  margin-left: 8px;
}

/* ============================================================
   2. Панель фильтров
   ============================================================ */
.crm-card:has(> .crm-filters) {
  padding: 10px 12px !important;
}

/* Фильтры и список — один блок, а не две карточки с щелью между ними */
.crm-card:has(> .crm-filters):has(+ .crm-card) {
  margin-bottom: 0 !important;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.crm-card:has(> .crm-filters) + .crm-card {
  border-top: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.crm-filters {
  gap: 8px;
}

/* Поиск с иконкой, очисткой и подсказкой клавиши */
.wb-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 260px;
  min-width: 200px;
  margin: 0;
  cursor: text;
}

.wb-search > .fa-search {
  position: absolute;
  left: 12px;
  color: var(--crm-text-muted);
  font-size: 12px;
  pointer-events: none;
}

.wb-search .crm-filter-input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  padding-left: 34px !important;
  padding-right: 36px !important;
}

.wb-search-clear,
.wb-kbd {
  position: absolute;
  right: 8px;
}

.wb-search-clear {
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--crm-text-muted);
  font-size: 11px;
  cursor: pointer;
}

.wb-search-clear:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--crm-text);
}

.wb-kbd {
  min-width: 20px;
  padding: 1px 6px;
  border: 1px solid var(--crm-card-border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--crm-text-muted);
  font: 600 11px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: center;
  pointer-events: none;
}

.wb-search.has-value .wb-search-clear {
  display: inline-flex;
}

.wb-search.has-value .wb-kbd,
.wb-search:focus-within .wb-kbd {
  display: none;
}

/* Диапазон дат: одно поле «с — по» вместо двух отдельных */
.wb-range {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--crm-card-border);
  border-radius: var(--crm-radius-sm);
  background: var(--crm-input-bg);
}

.wb-range:focus-within {
  border-color: rgba(255, 107, 0, 0.55);
}

.wb-range .crm-filter-date {
  flex: 0 0 auto;
  width: 138px;
  min-width: 0;
  min-height: 36px;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.wb-range-sep {
  color: var(--crm-text-muted);
  font-size: 12px;
}

.wb-range-preset.crm-filter-select {
  flex: 0 0 auto;
  width: auto;
  min-width: 132px;
}

/* Чипы статусов: отдельной строкой под полями */
.wb-chips-source {
  display: none !important;
}

.wb-chips {
  display: flex;
  flex: 1 0 100%;
  flex-wrap: wrap;
  gap: 6px;
  order: 10;
}

.wb-chip {
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid var(--crm-card-border);
  border-radius: 999px;
  background: transparent;
  color: var(--crm-text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: color var(--crm-transition), border-color var(--crm-transition), background var(--crm-transition);
}

.wb-chip:hover {
  border-color: rgba(255, 107, 0, 0.45);
  color: var(--crm-text);
}

.wb-chip.active {
  border-color: rgba(255, 107, 0, 0.6);
  background: var(--crm-accent-soft, rgba(255, 107, 0, 0.12));
  color: var(--crm-text);
}

.wb-chip:focus-visible {
  outline: 2px solid var(--crm-accent);
  outline-offset: 1px;
}

.wb-filter-reset[hidden] {
  display: none !important;
}

.wb-filter-reset {
  flex: 0 0 auto;
  color: var(--crm-text-muted) !important;
}

/* Кнопка «Фильтры» нужна только на телефоне: см. раздел 7 */
.wb-filters-toggle {
  display: none !important;
}

.wb-filters-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--crm-accent);
  color: #150a02;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

.wb-filters-count[hidden] {
  display: none;
}

/* Фильтры внутри разделов говорят одним языком с чипами статусов */
.loyalty-tx-filter-btn,
.promo-posts-filter button {
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid var(--crm-card-border);
  border-radius: 999px;
  background: transparent;
  color: var(--crm-text-muted);
  font-size: 12px;
  font-weight: 700;
}

.loyalty-tx-filter-btn:hover,
.promo-posts-filter button:hover {
  border-color: rgba(255, 107, 0, 0.45);
  background: transparent;
  color: var(--crm-text);
}

.loyalty-tx-filter-btn.active,
.promo-posts-filter button.is-active {
  border-color: rgba(255, 107, 0, 0.6);
  background: var(--crm-accent-soft, rgba(255, 107, 0, 0.12));
  color: var(--crm-text);
}

/* Вкладки разделов — одной линией с подчёркиванием, как в лояльности */
.crm-tabs {
  border-bottom: 1px solid var(--crm-card-border);
}

.crm-tab {
  min-height: 0;
  padding: 10px 18px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  font-weight: 600;
}

.crm-tab:hover {
  border-color: transparent;
  background: none;
  color: var(--crm-text);
}

.crm-tab.active {
  border-color: var(--crm-accent);
  background: none;
  color: var(--crm-accent);
}

/* Поиск без панели фильтров: рядом с чипами уровней и в промокодах */
#section-loyalty .wb-search {
  flex: 0 1 260px;
}

/* ============================================================
   3. Таблицы: плотнее, с сортировкой и итогами
   ============================================================ */
/* Обычная плотность — как «компактная» раньше, но с запасом под две строки */
:root {
  --crm-cell-py: 8px;
  --crm-head-py: 9px;
}

html[data-crm-density="compact"] {
  --crm-cell-py: 5px;
  --crm-head-py: 7px;
}

.crm-section .crm-table tbody td {
  vertical-align: middle;
  line-height: 1.35;
}

/* 10px в шапке таблицы не читается; 11px влезают туда же */
.crm-page .crm-table thead th,
.crm-page .data-table th {
  font-size: 11px;
  letter-spacing: 0.05em;
}

.crm-nav-label {
  font-size: 11px;
  letter-spacing: 0.07em;
}

/* Время и зал не ломаются в столбик */
.crm-section .crm-table td.wb-nowrap {
  white-space: nowrap;
}

/* На ноутбуке колонкам нужен запас, иначе кнопки строки уезжают за край */
@media (min-width: 641px) and (max-width: 1400px) {
  .crm-page .crm-section .crm-table thead th,
  .crm-page .crm-section .crm-table tbody td {
    padding-left: 8px;
    padding-right: 8px;
  }

  .crm-page .crm-section .crm-table td:first-child,
  .crm-page .crm-section .crm-table th:first-child {
    padding-left: 12px;
  }

  /* Длинные подписи вроде «Последний визит» переносятся и не теснят кнопки */
  .crm-page .crm-section .crm-table thead th.wb-sortable {
    white-space: normal;
  }

  .crm-page .crm-section .crm-table td[data-label="Email"] {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Брони сегодняшнего дня заметны в общем списке */
.crm-table tbody tr.wb-today > td:first-child {
  box-shadow: inset 2px 0 0 var(--crm-accent-2);
  color: var(--crm-accent-2);
  font-weight: 700;
}

/* Метка стоит рядом с именем: иначе строка вырастает на треть */
.wb-name-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
}

/* Плавающий помощник не закрывает кнопки последней строки */
.crm-page .crm-section:not(.sb-section) {
  padding-bottom: 96px !important;
}

/* Подписи шкалы расписания: контраст 3.6 был ниже нормы */
.crm-tl-tick {
  color: var(--crm-text-muted);
}

.wb-cell-sub {
  margin-top: 1px;
  color: var(--crm-text-muted);
  font-size: 11px;
}

.wb-cell-sub.is-negative {
  color: var(--crm-danger);
}

.wb-stock-low {
  color: var(--crm-warning);
  font-weight: 800;
}

.wb-stock-low::after {
  content: ' ⚠';
  font-size: 11px;
}

/* На дашборде таблица — витрина последних броней, итоги там лишние */
#section-dashboard .wb-table-foot {
  display: none;
}

/* Кнопки действий в строке не раздувают её высоту */
.crm-page .crm-section .crm-table td .btn-icon,
.crm-page .crm-section .crm-table td .btn.btn-icon {
  width: 30px;
  min-width: 30px;
  height: 30px;
  min-height: 30px;
  font-size: 12px;
}

.crm-page .crm-section .crm-table td .btn.btn-sm:not(.btn-icon) {
  min-height: 30px;
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.crm-section .crm-table td:last-child {
  white-space: nowrap;
}

.crm-section .crm-table td:last-child:has(.btn) {
  width: 1%;
  text-align: right;
}

.crm-section .crm-table td:last-child .btn + .btn {
  margin-left: 4px;
}

/* Второй строкой в ячейке идёт приглушённая деталь (телефон, время) */
.crm-section .crm-table td > div + div,
.crm-section .crm-table td small {
  font-size: 12px;
}

/* Сортировка */
.crm-table th.wb-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.crm-table th.wb-sortable::after {
  content: '↕';
  display: inline-block;
  margin-left: 6px;
  color: var(--crm-text-muted);
  font-size: 11px;
  letter-spacing: 0;
  opacity: 0;
  transition: opacity var(--crm-transition);
}

.crm-table th.wb-sortable:hover::after,
.crm-table th.wb-sortable:focus-visible::after {
  opacity: 0.7;
}

.crm-table th.wb-sortable[aria-sort="ascending"],
.crm-table th.wb-sortable[aria-sort="descending"] {
  color: var(--crm-text);
}

.crm-table th.wb-sortable[aria-sort="ascending"]::after {
  content: '↑';
  color: var(--crm-accent);
  opacity: 1;
}

.crm-table th.wb-sortable[aria-sort="descending"]::after {
  content: '↓';
  color: var(--crm-accent);
  opacity: 1;
}

.crm-table th.wb-sortable:focus-visible {
  outline: 1px solid var(--crm-accent);
  outline-offset: -1px;
}

/* Клик по строке открывает её карточку */
.crm-table tbody tr.wb-row-link {
  cursor: pointer;
}

/* Строка итогов */
.wb-table-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 20px;
  padding: 10px 14px;
  border-top: 1px solid var(--crm-line-soft, rgba(255, 255, 255, 0.07));
  color: var(--crm-text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.wb-table-foot[hidden] {
  display: none;
}

.wb-table-foot b {
  color: var(--crm-text);
  font-weight: 800;
}

.wb-table-foot small {
  font-size: 11px;
  opacity: 0.8;
}

.wb-foot-note {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.75;
}

/* Расписание: сводка и шкала сами держат отступы, карточка — только рамка */
.crm-page .crm-section .crm-card.crm-journal-card {
  padding: 0;
}

/* ============================================================
   4. KPI: компактные плитки, цифра читается с первого взгляда
   ============================================================ */
.crm-section .crm-kpi-grid {
  gap: 10px;
  margin-bottom: 14px;
}

.crm-section .crm-kpi-card {
  min-height: 0;
  padding: 14px 16px;
  align-items: center;
  gap: 12px;
}

.crm-section .crm-kpi-icon {
  width: 36px;
  height: 36px;
  font-size: 15px;
}

.crm-section .crm-kpi-value {
  font-size: 22px;
  line-height: 1.15;
}

/* Плитки без иконки (аналитика): подпись, цифра и пояснение — столбиком */
#analyticsKpis .crm-kpi-card {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 4px;
}

#analyticsKpis .crm-kpi-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
}

#analyticsKpis .crm-kpi-sub {
  font-weight: 600;
  line-height: 1.4;
}

/* ============================================================
   5. Статусы и действия в строках
   ============================================================ */
/* «Завершено» — спокойный архивный цвет: зелёный остаётся только
   у «подтверждено», и два статуса больше не путаются в списке */
.crm-page .crm-status.completed {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--crm-card-border);
  color: var(--crm-text-soft);
}

/* Следующий шаг брони прямо в строке */
.crm-page .crm-section .crm-table td .btn.wb-next-step {
  gap: 6px;
  color: var(--crm-text-soft);
}

.wb-next-step i {
  font-size: 11px;
}

.wb-next-step.is-confirmed i { color: var(--crm-success); }
.wb-next-step.is-in_progress i { color: var(--crm-warning); }
.wb-next-step.is-completed i { color: var(--crm-accent); }

.crm-page .crm-section .crm-table td .btn.wb-next-step:hover {
  border-color: rgba(255, 107, 0, 0.45);
  color: var(--crm-text);
}

/* Телефон: клик копирует (на телефоне — звонит) */
.wb-phone {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: none;
  cursor: copy;
}

.wb-phone i {
  font-size: 10px;
  opacity: 0;
  transition: opacity var(--crm-transition), color var(--crm-transition);
}

.wb-phone:hover,
.wb-phone:focus-visible {
  color: var(--crm-text);
}

.wb-phone:hover i,
.wb-phone:focus-visible i {
  opacity: 0.6;
}

.wb-phone.is-copied i {
  opacity: 1;
  color: var(--crm-success);
}

a.wb-phone {
  color: var(--crm-accent-2);
  cursor: pointer;
}

/* Пустая таблица: одно спокойное сообщение, без зебры и подсветки */
.crm-section .crm-table tbody tr:only-child > td[colspan] {
  padding: 44px 16px !important;
  background: transparent !important;
  box-shadow: none !important;
  color: var(--crm-text-muted) !important;
  font-size: 13px;
}

.crm-section .crm-table tbody tr:only-child > td[colspan] > i:first-child {
  margin-bottom: 10px !important;
  font-size: 26px !important;
  opacity: 0.45;
}

/* Кнопка следующего шага в пустом списке */
.crm-page .crm-section .wb-empty-action {
  display: flex;
  width: fit-content;
  margin: 12px auto 0;
}

/* Строка, выбранная стрелками */
.crm-table tbody tr.is-selected > td:first-child {
  box-shadow: inset 3px 0 0 var(--crm-accent);
}

/* Пустой график: приглушённая сетка и одна понятная подпись */
.crm-chart-card.wb-chart-empty {
  position: relative;
}

.crm-chart-card.wb-chart-empty canvas {
  opacity: 0.22;
}

.crm-chart-card.wb-chart-empty::after {
  content: attr(data-empty);
  position: absolute;
  inset: 48px 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--crm-text-muted);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}

/* ============================================================
   6. Окна
   ============================================================ */
/* Оверлейные окна жёстко держали 560px и игнорировали lg/xl —
   профиль клиента сжимался, имя наезжало на кнопки */
.crm-modal-overlay > .crm-modal.crm-modal-lg {
  width: min(720px, calc(100vw - 32px));
}

.crm-modal-overlay > .crm-modal.crm-modal-xl {
  width: min(960px, calc(100vw - 32px));
}

.crm-modal-overlay > .crm-modal.client360-modal {
  width: min(1040px, calc(100vw - 32px));
  max-width: none;
}

@media (max-width: 760px) {
  .client360-head {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .client360-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

/* Подпись прижата к своему полю: лишняя высота ячейки уходит вниз,
   а не раздвигает подпись и поле (было видно у «Даты» в новой брони) */
.crm-page .form-grid > .form-field {
  align-content: start;
}

/* Кнопка профиля стоит рядом с именем клиента, а не строкой ниже */
#bdClientInfo .form-field:has(#bdOpenClient360) {
  grid-template-columns: auto auto;
  justify-content: start;
  align-items: center;
  column-gap: 8px;
}

#bdClientInfo .form-field:has(#bdOpenClient360) > label {
  grid-column: 1 / -1;
}

#bdOpenClient360 {
  margin-left: 0 !important;
}

/* Карточка брони: главный шаг — заливкой, отмена и неявка — контуром */
#bdStatusActions .btn.danger,
#bdStatusActions .btn.warning {
  background: transparent;
}

#bdStatusActions .btn.danger {
  border: 1px solid rgba(242, 96, 108, 0.45);
  color: var(--crm-danger);
}

#bdStatusActions .btn.warning {
  border: 1px solid rgba(224, 163, 65, 0.45);
  color: var(--crm-warning);
}

#bdStatusActions .btn.danger:hover {
  border-color: transparent;
  background: var(--crm-danger);
  color: #170608;
}

#bdStatusActions .btn.warning:hover {
  border-color: transparent;
  background: var(--crm-warning);
  color: #150e03;
}

/* Расписание: когда данные обновились; клик — обновить сейчас */
.crm-journal-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--crm-card-border);
  border-radius: 999px;
  background: transparent;
  color: var(--crm-text-muted);
  font: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.crm-journal-refresh:hover {
  border-color: rgba(255, 107, 0, 0.45);
  color: var(--crm-text);
}

.crm-journal-refresh i {
  font-size: 10px;
}

/* Шпаргалка горячих клавиш */
.wb-help {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.62);
}

.wb-help.open {
  display: flex;
}

.wb-help-card {
  width: min(480px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 18px 20px 20px;
  border: 1px solid var(--crm-card-border);
  border-radius: var(--crm-radius);
  background: var(--crm-surface-2, #101014);
  box-shadow: var(--crm-shadow-strong);
}

.wb-help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  color: var(--crm-text);
  font-size: 15px;
}

.wb-help-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--crm-card-border);
  border-radius: var(--crm-radius-sm);
  background: transparent;
  color: var(--crm-text-muted);
  cursor: pointer;
}

.wb-help-close:hover {
  color: var(--crm-text);
}

.wb-help dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  align-items: center;
  gap: 10px 16px;
  margin: 0;
}

.wb-help dt {
  display: flex;
  gap: 4px;
  margin: 0;
}

.wb-help dd {
  margin: 0;
  color: var(--crm-text-soft);
  font-size: 13px;
}

.wb-help .wb-kbd {
  position: static;
}

.wb-help p {
  margin: 16px 0 0;
  color: var(--crm-text-muted);
  font-size: 12px;
}

/* ============================================================
   7. Адаптив
   ============================================================ */
@media (max-width: 900px) {
  .crm-section-actions {
    justify-content: flex-start;
  }

  .crm-section-actions .btn.danger {
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  /* В колонке с переносом линия берёт ширину самого широкого элемента —
     без явной ширины поиск растягивал бы её за край экрана */
  .wb-search {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  .wb-chips {
    width: 100%;
  }

  .wb-kbd {
    display: none;
  }

  .wb-range {
    width: 100%;
  }

  .wb-range .crm-filter-date {
    flex: 1 1 0;
    width: auto;
  }

  .wb-range-preset.crm-filter-select {
    width: 100%;
  }

  /* На телефоне чипы листаются, а не переносятся в три строки */
  .wb-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -2px;
    padding: 0 2px 2px;
  }

  .wb-chips::-webkit-scrollbar {
    display: none;
  }

  .wb-chip {
    flex: 0 0 auto;
    min-height: 36px;
  }

  .wb-foot-note {
    margin-left: 0;
  }

  /* --- Заголовок: действия одной строкой, главное первым --- */
  .crm-page .crm-section-title,
  #section-booking-widget .bw-toolbar h1 {
    font-size: 19px;
  }

  .crm-section-header {
    row-gap: 10px;
    margin-bottom: 12px !important;
    padding-bottom: 12px !important;
  }

  .crm-section-actions,
  .crm-dashboard-actions {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 6px;
  }

  .crm-section-actions > .btn,
  .crm-dashboard-actions > .btn {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    min-height: 40px;
    padding: 0 10px;
    white-space: nowrap;
  }

  .crm-section-actions > .btn.primary,
  .crm-dashboard-actions > .btn.primary {
    order: -1;
  }

  /* Опасная кнопка не растягивается на весь экран под главной */
  .crm-section-actions > .btn.danger {
    flex: 0 0 auto;
    margin-left: 0;
  }

  /* Фильтр заявок занимает всю строку: «Обработанные» не влезало в сжатую */
  #section-callbacks .crm-view-toggle {
    flex: 1 1 100%;
  }

  #section-callbacks .crm-view-toggle .btn {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 40px;
    padding: 0 10px;
    white-space: nowrap;
  }

  .crm-section-actions > select.crm-filter-select,
  .crm-section-actions > .wb-range-preset.crm-filter-select {
    flex: 1 1 40%;
    width: auto;
    max-width: none !important;
    margin-left: 0 !important;
  }

  .crm-section-actions .wb-range {
    flex: 1 1 100%;
    order: 1;
  }

  /* Период аналитики — одна лента, а не пять кнопок в столбик */
  .analytic-actions {
    flex-wrap: nowrap;
    align-items: stretch;
  }

  .analytic-presets {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .analytic-presets::-webkit-scrollbar {
    display: none;
  }

  .analytic-presets .preset-btn {
    flex: 0 0 auto;
    width: auto;
    min-height: 40px;
  }

  .analytic-custom-dates {
    flex: 1 1 100%;
  }

  .crm-section-actions.analytic-actions:has(.analytic-custom-dates:not([style*="none"])) {
    flex-wrap: wrap;
  }

  .analytic-presets .preset-btn {
    padding: 0 8px;
  }

  /* Подпись остаётся для скринридера и как title, на экране — только значок */
  .crm-page #analyticsRefreshBtn {
    flex: 0 0 40px;
    width: 40px;
    padding: 0;
    font-size: 0 !important;
    gap: 0;
  }

  .crm-page #analyticsRefreshBtn i {
    margin: 0;
    font-size: 13px;
  }

  /* --- Фильтры: поиск и статусы на виду, остальное по кнопке --- */
  .crm-filters {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .crm-filters .wb-search {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    order: 0;
  }

  .crm-filters.has-wb-toggle > select.crm-filter-select,
  .crm-filters.has-wb-toggle > .wb-range,
  .crm-filters.has-wb-toggle > .wb-filter-reset {
    display: none;
  }

  .crm-filters.has-wb-toggle.wb-filters-open > select.crm-filter-select:not(.wb-chips-source),
  .crm-filters.has-wb-toggle.wb-filters-open > .wb-range,
  .crm-filters.has-wb-toggle.wb-filters-open > .wb-filter-reset:not([hidden]) {
    display: flex;
    flex: 1 1 100%;
    width: 100%;
    order: 5;
  }

  .crm-filters.has-wb-toggle > .wb-filters-toggle {
    display: inline-flex !important;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    order: 1;
  }

  .crm-filters.wb-filters-open > .wb-filters-toggle {
    border-color: rgba(255, 107, 0, 0.6);
    color: var(--crm-text);
  }

  /* --- Показатели: по две плитки в ряд, цифра под иконкой --- */
  .crm-section .crm-kpi-grid,
  #section-dashboard .crm-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
  }

  .crm-section .crm-kpi-card {
    position: relative;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    min-width: 0;
    padding: 12px;
  }

  .crm-section .crm-kpi-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .crm-section .crm-kpi-data {
    min-width: 0;
    width: 100%;
  }

  .crm-section .crm-kpi-value {
    font-size: 19px;
    overflow-wrap: anywhere;
  }

  /* Нечётная последняя плитка занимает ряд целиком, без дыры справа */
  .crm-section .crm-kpi-grid > .crm-kpi-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  /* --- Таблица становится списком карточек ---
     Подписи, главную ячейку и кнопки размечает crm-workbench.js. */
  .crm-section table.wb-cards {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }

  .crm-section table.wb-cards thead {
    display: none;
  }

  .crm-section table.wb-cards tbody {
    display: block;
  }

  .crm-section table.wb-cards tbody tr {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 12px 2px;
    border-bottom: 1px solid var(--crm-line-soft);
    background: none !important;
  }

  .crm-section table.wb-cards tbody tr:last-child {
    border-bottom: 0;
  }

  .crm-section table.wb-cards tbody td {
    display: block;
    flex: 0 0 calc(50% - 6px);
    min-width: 0;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    color: var(--crm-text);
    font-size: 13px;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .crm-section table.wb-cards tbody td[colspan],
  .crm-section table.wb-cards tbody td[data-label="Email"] {
    flex: 1 1 100%;
  }

  .crm-section table.wb-cards tbody td[colspan] {
    text-align: center;
  }

  .crm-section table.wb-cards td[data-label]:not(.wb-cell-title, .wb-cell-status, .wb-cell-actions)::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 1px;
    color: var(--crm-text-muted);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
  }

  .crm-section table.wb-cards tbody td.wb-cell-title {
    flex: 1 1 0;
    min-width: 55%;
    order: -2;
    font-size: 15px;
    font-weight: 600;
  }

  .crm-section table.wb-cards tbody td.wb-cell-status {
    flex: 0 0 auto;
    order: -1;
    margin-left: auto;
  }

  /* У продажи без клиента статус идёт отдельной строкой справа */
  .crm-section table.wb-cards tr:has(.wb-cell-title.wb-cell-empty) td.wb-cell-status {
    flex: 1 1 100%;
    text-align: right;
  }

  .crm-section table.wb-cards tbody td.wb-cell-empty {
    display: none;
  }

  .crm-section table.wb-cards tbody td.wb-cell-actions {
    display: flex;
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    width: auto;
  }

  .crm-section table.wb-cards td.wb-cell-actions .btn + .btn {
    margin-left: 0;
  }

  .crm-page .crm-section table.wb-cards td .btn.btn-sm:not(.btn-icon) {
    height: 40px;
    min-height: 40px;
    padding: 0 14px;
  }

  .crm-page .crm-section table.wb-cards td .btn-icon,
  .crm-page .crm-section table.wb-cards td .btn.btn-icon {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
  }

  /* --- Цели нажатия --- */
  .wb-phone,
  #section-callbacks .cb-phone {
    min-height: 32px;
  }

  .crm-pagination button {
    min-width: 40px;
    min-height: 40px;
  }

  .crm-page .crm-modal-close {
    width: 40px;
    height: 40px;
  }

  .loyalty-tx-filter-btn {
    min-height: 36px;
  }

  /* Лента вкладок листается, а не вылезает за край */
  .loyalty-tabs,
  .crm-tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .loyalty-tabs::-webkit-scrollbar,
  .crm-tabs::-webkit-scrollbar {
    display: none;
  }

  .loyalty-tab,
  .crm-tab {
    flex: 0 0 auto;
    padding: 10px 12px;
  }

  #section-loyalty .wb-search {
    flex: 1 1 100%;
  }

  #loyaltySearch {
    max-width: none;
  }

  .crm-topbar-title {
    max-width: none;
  }
}
