/*
 * Formula CRM UI system
 *
 * This file is the final visual layer for every live CRM page.  It is linked
 * after page-local styles so old screens keep their layout while typography,
 * controls and action semantics stay consistent.
 */
:root {
  --ui-font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Акцент 15.08.2026: синий → тёмная бирюза. Значения СНЯТЫ ПИКСЕЛЯМИ с
     эталонного макета владельца (`3ff45924-…png`, доминирующий цвет по
     плоским заливкам), а не подобраны на глаз:
       сайдбар #00353d · активный пункт #04535a · кнопка и исходящий
       пузырь #024a50 · выбранная строка #dde8e9 · полотно #fbfbfb.
     Вид ОДИН на всех тенантов — различаются только меню и функции. */
  --ui-primary: #024a50;
  --ui-primary-hover: #013a3f;
  --ui-primary-soft: #dde8e9;
  --ui-text: #0f172a;
  --ui-muted: #64748b;
  --ui-border: #e6eaea;
  --ui-surface: #ffffff;
  --ui-surface-muted: #f7f9f9;
  --ui-danger: #dc2626;
  --ui-danger-soft: #fef2f2;
  --ui-success: #3f7d24;
  --ui-success-soft: #e6f5e2;
  --ui-warning: #9d621d;
  --ui-warning-soft: #feeec3;
  --ui-radius: 10px;
  --ui-control-height: 40px;
  --ui-control-height-sm: 36px;
  --ui-shadow-focus: 0 0 0 3px rgba(15, 118, 110, 0.16);

  /* ── Общий контракт 15.08.2026 ─────────────────────────────────────────
     РЕШЕНИЕ ВЛАДЕЛЬЦА: вид у всех тенантов ОДИН. Различаются только состав
     меню и функции — цвет, навигация, плотность, радиусы общие. Поэтому
     здесь нет и не должно появиться блоков вида `body.sphere-*` с другими
     цветами: класс сферы на `<body>` служит функциональному гейтингу и
     будущему разъезду по доменам, а не второму облику. */
  --ui-bg: #fbfbfb;
  --ui-radius-card: 12px;
  --ui-sidebar-bg: #00353d;
  --ui-sidebar-fg: #c7d6d8;
  --ui-sidebar-muted: #8fa3a6;
  --ui-sidebar-active-bg: #04535a;
  --ui-sidebar-active-fg: #ffffff;
  --ui-sidebar-border: #06424a;
}

html {
  -webkit-text-size-adjust: 100%;
}

body.crm-ui,
body.crm-ui button,
body.crm-ui input,
body.crm-ui select,
body.crm-ui textarea {
  font-family: var(--ui-font) !important;
}

body.crm-ui {
  color: var(--ui-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.crm-ui h1,
body.crm-ui h2,
body.crm-ui h3 {
  color: var(--ui-text);
  letter-spacing: -0.02em;
}

body.crm-ui h1 { font-size: 24px; line-height: 1.25; font-weight: 700; }
body.crm-ui h2 { font-size: 20px; line-height: 1.3; font-weight: 700; }
body.crm-ui h3 { font-size: 16px; line-height: 1.4; font-weight: 650; }

body.crm-ui :where(input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="date"], input[type="tel"], input[type="search"],
  select, textarea) {
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--ui-radius) !important;
  background: var(--ui-surface) !important;
  color: var(--ui-text) !important;
  font-size: 14px !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

body.crm-ui :where(input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="date"], input[type="tel"], input[type="search"], select) {
  min-height: var(--ui-control-height);
  padding: 8px 12px !important;
}

body.crm-ui textarea { padding: 10px 12px !important; }

body.crm-ui :where(input, select, textarea):focus {
  border-color: var(--ui-primary) !important;
  box-shadow: var(--ui-shadow-focus) !important;
  outline: none !important;
}

/* Standard action controls.  :where keeps the selector easy to override by a
   deliberate page-specific modifier; !important beats old inline geometry. */
body.crm-ui :where(
  button.btn, a.btn,
  .btn-primary, .btn-warning, .btn-success,
  .btn-save, .btn-add, .btn-del, .btn-back, .btn-cancel, .btn-refresh,
  .btn-deal, .btn-takeover, .btn-link-contact, .btn-new-deal, .btn-unmute,
  .btn-site-check, .btn-site-deploy, .btn-task-quick, .btn-transcript-wide,
  .btn-secondary, .disp-btn, .back-link, .back,
  button.primary, button.secondary, button.success,
  .toolbar a, .erow .save, .erow .del,
  .business-rules-page button, .prices-misses-page button, .payroll-page button
) {
  min-height: var(--ui-control-height) !important;
  padding: 0 16px !important;
  border-radius: var(--ui-radius) !important;
  border: 1px solid transparent !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  text-decoration: none !important;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: none !important;
  transition: background-color 0.15s ease, border-color 0.15s ease,
              color 0.15s ease, box-shadow 0.15s ease !important;
}

body.crm-ui :where(button.btn, .btn-primary, .btn-save, .btn-deal, .btn-link-contact,
  .btn-new-deal, .btn-site-check, .btn-site-deploy, button.primary,
  .toolbar a.edit, .erow .save, .business-rules-page button,
  .prices-misses-page button, .payroll-page button) {
  background: var(--ui-primary) !important;
  border-color: var(--ui-primary) !important;
  color: #ffffff !important;
}

body.crm-ui :where(button.btn, .btn-primary, .btn-save, .btn-deal, .btn-link-contact,
  .btn-new-deal, .btn-site-check, .btn-site-deploy, button.primary,
  .toolbar a.edit, .erow .save, .business-rules-page button,
  .prices-misses-page button, .payroll-page button):hover:not(:disabled) {
  background: var(--ui-primary-hover) !important;
  border-color: var(--ui-primary-hover) !important;
}

body.crm-ui :where(.btn.btn-sec, .btn-secondary, .btn-cancel, .btn-back,
  .btn-refresh, .btn-add, .btn-task-quick, .btn-transcript-wide,
  .back-link, .back, button.secondary, .toolbar a.done) {
  background: var(--ui-surface) !important;
  border-color: var(--ui-border) !important;
  color: var(--ui-primary) !important;
}

body.crm-ui :where(.btn.btn-sec, .btn-secondary, .btn-cancel, .btn-back,
  .btn-refresh, .btn-add, .btn-task-quick, .btn-transcript-wide,
  .back-link, .back, button.secondary, .toolbar a.done):hover:not(:disabled) {
  background: var(--ui-primary-soft) !important;
  /* Было #93c5fd — синяя рамка осталась бы спорить с бирюзовым акцентом. */
  border-color: color-mix(in srgb, var(--ui-primary) 45%, #ffffff) !important;
  color: var(--ui-primary-hover) !important;
}

body.crm-ui :where(.btn-danger, .danger, .btn-del, .erow .del) {
  background: var(--ui-surface) !important;
  border-color: #fca5a5 !important;
  color: var(--ui-danger) !important;
}

body.crm-ui .payroll-page button.rej {
  background: var(--ui-surface) !important;
  border-color: #fca5a5 !important;
  color: var(--ui-danger) !important;
}

body.crm-ui :where(.btn-danger, .danger, .btn-del, .erow .del):hover:not(:disabled) {
  background: var(--ui-danger-soft) !important;
  border-color: var(--ui-danger) !important;
}

body.crm-ui :where(button.success, .btn-success) {
  background: var(--ui-surface) !important;
  border-color: #86efac !important;
  color: var(--ui-success) !important;
}

body.crm-ui :where(button.success, .btn-success):hover:not(:disabled) {
  background: var(--ui-success-soft) !important;
  border-color: var(--ui-success) !important;
}

body.crm-ui :where(.btn-warning) {
  background: var(--ui-warning-soft) !important;
  border-color: #fbbf24 !important;
  color: var(--ui-warning) !important;
}

body.crm-ui :where(.btn-sm, .btn-sm-del) {
  min-height: var(--ui-control-height-sm) !important;
  padding: 0 12px !important;
  border-radius: 9px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  text-decoration: none !important;
  white-space: nowrap;
}

body.crm-ui .btn-sm-del {
  background: var(--ui-surface) !important;
  border: 1px solid #fca5a5 !important;
  color: var(--ui-danger) !important;
}

body.crm-ui :where(.btn-sm-del.btn-secondary, .btn-sm.btn-secondary) {
  background: var(--ui-surface) !important;
  border-color: #93c5fd !important;
  color: var(--ui-primary) !important;
}

body.crm-ui :where(.btn-sm-del.btn-success, .btn-sm.btn-success) {
  background: var(--ui-surface) !important;
  border-color: #86efac !important;
  color: var(--ui-success) !important;
}

body.crm-ui .btn-icon {
  width: var(--ui-control-height) !important;
  height: var(--ui-control-height) !important;
  min-height: var(--ui-control-height) !important;
  padding: 0 !important;
}

body.crm-ui button:disabled,
body.crm-ui .btn[disabled] {
  cursor: not-allowed !important;
  opacity: 0.52 !important;
}

body.crm-ui :where(button, a, input, select, textarea):focus-visible {
  outline: 2px solid var(--ui-primary) !important;
  outline-offset: 2px;
}

/* Tabs and segmented navigation share one size and one interaction model. */
body.crm-ui :where(.sb-nav, .tab-inner-nav, .settings-subtabs, .bs-tabs, .subnav) {
  scrollbar-width: thin;
}

body.crm-ui :where(.sb-nav-btn, .tab-inner-nav button, .settings-subtabs button,
  .bs-tab, .subtab, .period-btn, .mode-btn) {
  min-height: 42px !important;
  padding: 0 16px !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--ui-radius) !important;
  background: var(--ui-surface) !important;
  color: var(--ui-muted) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  text-decoration: none !important;
  white-space: nowrap;
  box-shadow: none !important;
  transform: none !important;
}

body.crm-ui :where(.sb-nav-btn, .tab-inner-nav button, .settings-subtabs button,
  .bs-tab, .subtab, .period-btn, .mode-btn):hover {
  background: var(--ui-primary-soft) !important;
  border-color: #bfdbfe !important;
  color: var(--ui-primary) !important;
}

body.crm-ui :where(.sb-nav-btn.active, .tab-inner-nav button.active,
  .settings-subtabs button.active, .bs-tab.active, .subtab.active,
  .period-btn.active, .mode-btn.active) {
  background: var(--ui-primary) !important;
  border-color: var(--ui-primary) !important;
  color: #ffffff !important;
}

body.crm-ui .sb-nav {
  padding: 14px 24px !important;
  gap: 8px !important;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap !important;
}

body.crm-ui .sb-nav-btn { flex: 0 0 auto; }

/* Top navigation stays compact; sidebar navigation deliberately keeps its own
   row treatment instead of being turned into a button pill. */
body.crm-ui .topbar-nav button {
  min-height: 38px !important;
  padding: 0 13px !important;
  border-radius: 9px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
}

body.crm-ui :where(.bs-header h1, .bs-header .subtitle) {
  font-family: var(--ui-font) !important;
}

@media (max-width: 720px) {
  body.crm-ui h1 { font-size: 21px; }
  body.crm-ui h2 { font-size: 18px; }

  body.crm-ui :where(.sb-nav, .tab-inner-nav, .settings-subtabs, .bs-tabs, .subnav) {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
  }

  body.crm-ui .sb-nav { padding: 10px 12px !important; }

  body.crm-ui :where(.sb-nav-btn, .tab-inner-nav button, .settings-subtabs button,
    .bs-tab, .subtab, .period-btn, .mode-btn) {
    flex: 0 0 auto;
    min-height: 40px !important;
    padding: 0 13px !important;
    font-size: 13px !important;
  }

  body.crm-ui .kb-breadcrumb {
    align-items: stretch !important;
  }

  body.crm-ui .kb-breadcrumb h3 {
    flex-basis: calc(100% - 64px) !important;
  }

  body.crm-ui .kb-breadcrumb :where(.btn-save, .btn-sm-del) {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.crm-ui *,
  body.crm-ui *::before,
  body.crm-ui *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   ОБЩИЕ ПРИМИТИВЫ СТРАНИЦ (контракт 15.08.2026, согласован с CRM отеля)

   Шесть блоков, из которых собраны экраны обоих тенантов. Имена нейтральны
   к сфере: у отеля те же «Номера»/«Услуги» ложатся на них без своих классов.

   ── КАК РАЗДЕЛИТЬ ТЕНАНТЫ, когда CRM отеля переедет на свой домен ──
   Вид общий, поэтому делить в CSS нечего: `ui-system.css` копируется в оба
   репозитория как есть и дальше живёт своей жизнью в каждом. Разъезд
   касается только ФУНКЦИЙ:
   1. В шаблонах убрать ветки `{% if tenant_sphere … %}` чужой сферы —
      меню и разделы. Стили при этом не трогаются вообще.
   2. Удалить чужие страницы (`hotel_*.html` либо ремонтные).
   3. `_sphere_class()` в `crm/app.py` начнёт возвращать одно значение —
      можно оставить как есть, класс просто перестанет меняться.
   Класс сферы на `<body>` позитивный (`sphere-repair` / `sphere-hotel`), а
   не отрицание вида `:not(.sphere-hotel)`: инвертировать селекторы при
   разъезде не придётся. Использовать его для РАЗНОГО ВИДА нельзя — см.
   решение владельца в :root выше.
   ═══════════════════════════════════════════════════════════════════════ */

/* Шапка страницы: заголовок слева, действия справа, общий отступ снизу. */
body.crm-ui .ui-page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin: 0 0 18px;
}
body.crm-ui .ui-page-head h1,
body.crm-ui .ui-page-head h2 { margin: 0; }
body.crm-ui .ui-page-head .ui-page-actions {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

/* Строка фильтров и поиска над таблицей. */
body.crm-ui .ui-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 14px;
}
body.crm-ui .ui-toolbar > .ui-toolbar-spacer { margin-left: auto; }

/* Таблица-карточка: белое полотно, тонкие разделители, без внешней рамки у
   строк. Скроллится по горизонтали сама — страница не едет. */
body.crm-ui .ui-table {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-card);
  overflow: hidden;
}
body.crm-ui .ui-table-scroll { overflow-x: auto; }
body.crm-ui .ui-table table { width: 100%; border-collapse: collapse; }
body.crm-ui .ui-table thead th {
  background: var(--ui-surface-muted);
  color: var(--ui-muted);
  font-size: 12px; font-weight: 600; text-align: left;
  letter-spacing: 0.02em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ui-border);
  white-space: nowrap;
}
body.crm-ui .ui-table tbody td {
  padding: 12px 14px;
  border-top: 1px solid var(--ui-border);
  vertical-align: middle;
}
body.crm-ui .ui-table tbody tr:first-child td { border-top: 0; }
body.crm-ui .ui-table tbody tr:hover td { background: var(--ui-surface-muted); }

/* Боковая панель деталей справа от списка. */
body.crm-ui .ui-panel {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-card);
  padding: 18px;
}
body.crm-ui .ui-panel + .ui-panel { margin-top: 14px; }
body.crm-ui .ui-panel-title {
  font-size: 13px; font-weight: 600; color: var(--ui-muted);
  margin: 0 0 10px;
}
body.crm-ui .ui-panel-row {
  display: flex; gap: 12px; justify-content: space-between;
  padding: 7px 0; border-top: 1px solid var(--ui-border);
}
body.crm-ui .ui-panel-row:first-of-type { border-top: 0; }
body.crm-ui .ui-panel-row dt { color: var(--ui-muted); margin: 0; }
body.crm-ui .ui-panel-row dd { margin: 0; text-align: right; }

/* Статусный чип. Цвет задаётся модификатором, форма общая. */
body.crm-ui .ui-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.5;
  white-space: nowrap;
  background: var(--ui-surface-muted);
  color: var(--ui-muted);
  border: 1px solid var(--ui-border);
}
body.crm-ui .ui-chip-accent  { background: var(--ui-primary-soft); color: var(--ui-primary); border-color: transparent; }
body.crm-ui .ui-chip-success { background: var(--ui-success-soft); color: var(--ui-success); border-color: transparent; }
body.crm-ui .ui-chip-warning { background: var(--ui-warning-soft); color: var(--ui-warning); border-color: transparent; }
body.crm-ui .ui-chip-danger  { background: var(--ui-danger-soft);  color: var(--ui-danger);  border-color: transparent; }

/* Пустое состояние. Говорит, чего нет и что сделать, а не «нет данных». */
body.crm-ui .ui-empty {
  padding: 36px 20px; text-align: center; color: var(--ui-muted);
}
body.crm-ui .ui-empty-title {
  color: var(--ui-text); font-weight: 600; margin: 0 0 4px;
}

@media (max-width: 640px) {
  body.crm-ui .ui-page-head { align-items: flex-start; flex-direction: column; gap: 10px; }
  body.crm-ui .ui-page-head .ui-page-actions { width: 100%; }
  body.crm-ui .ui-table thead { display: none; }
  body.crm-ui .ui-table tbody td { padding: 10px 12px; }
  body.crm-ui .ui-panel { padding: 14px; }
}

/* ── Список + панель деталей (Звонки у ремонта, Брони у отеля) ─────────── */
body.crm-ui .ui-split {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px; align-items: start;
}
body.crm-ui .ui-split-main { min-width: 0; }
body.crm-ui .ui-split-side { position: sticky; top: 16px; }
body.crm-ui .ui-split-side-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
body.crm-ui .ui-split-side-when { color: var(--ui-muted); font-size: 13px; }
body.crm-ui .ui-split-side-phone {
  display: block; font-size: 18px; font-weight: 700;
  color: var(--ui-text); text-decoration: none;
}
body.crm-ui .ui-split-cta { width: 100%; margin-top: 14px; }
body.crm-ui .ui-toolbar-search { flex: 1 1 240px; min-width: 200px; }
body.crm-ui .ui-toolbar-count { color: var(--ui-muted); font-size: 13px; }

/* Строка таблицы, открывающая панель. */
body.crm-ui .ui-table tbody tr.call-row { cursor: pointer; }
body.crm-ui .ui-table tbody tr.call-row.active td { background: var(--ui-primary-soft); }
body.crm-ui .ui-table .call-time b,
body.crm-ui .ui-table .call-device b { display: block; font-weight: 600; }
body.crm-ui .ui-table .call-time span,
body.crm-ui .ui-table .call-device span {
  display: block; color: var(--ui-muted); font-size: 13px; margin-top: 2px;
}
body.crm-ui .ui-table .call-chevron { width: 32px; color: var(--ui-muted); text-align: right; }
body.crm-ui .ui-table .call-noorder { color: var(--ui-muted); }
body.crm-ui .lead-transcript { padding: 0 14px 14px; }

@media (max-width: 1100px) {
  body.crm-ui .ui-split { grid-template-columns: minmax(0, 1fr); }
  body.crm-ui .ui-split-side { position: static; }
}

/* ── Вкладки внутри страницы: подчёркивание, как в макетах владельца ─────
   Было: плашки-кнопки с заливкой у активной. В макетах («Звонки» — «Все
   звонки | Возможные заказы», «РемСервис» — «Сообщения | Заметки | Задачи»)
   активная вкладка помечена ЛИНИЕЙ под текстом, а не залитым прямоугольником:
   так вкладки не спорят по весу с настоящими кнопками действий рядом. */
body.crm-ui .tab-inner-nav {
  display: flex; gap: 4px; align-items: center;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--ui-border);
}
body.crm-ui .tab-inner-nav button {
  min-height: 40px;
  padding: 0 4px 10px !important;
  margin-right: 20px;
  border: 0 !important;
  border-bottom: 2px solid transparent !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--ui-muted) !important;
  font-size: 14px !important; font-weight: 600 !important;
  display: inline-flex; align-items: center; gap: 7px;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease;
}
body.crm-ui .tab-inner-nav button:hover { color: var(--ui-text) !important; }
body.crm-ui .tab-inner-nav button.active {
  color: var(--ui-primary) !important;
  border-bottom-color: var(--ui-primary) !important;
  background: transparent !important;
}
/* Счётчик у вкладки — нейтральный, чтобы не читался как статус. */
body.crm-ui .tab-inner-nav button .ui-chip {
  padding: 1px 8px; font-size: 12px;
}

/* Список категорий в боковой панели (База знаний). */
body.crm-ui .kb-cat {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 9px 10px; margin-bottom: 2px;
  border: 0; border-radius: var(--ui-radius);
  background: transparent; color: var(--ui-text);
  font-size: 14px; text-align: left; cursor: pointer;
}
body.crm-ui .kb-cat:hover { background: var(--ui-surface-muted); }
body.crm-ui .kb-cat.active { background: var(--ui-primary-soft); color: var(--ui-primary); font-weight: 600; }
body.crm-ui .kb-cat-add { width: 100%; margin-top: 10px; }
body.crm-ui .kb-split { align-items: start; }
@media (min-width: 1101px) {
  /* Категории слева, как в макете: колонку панели ставим первой. */
  body.crm-ui .kb-split { grid-template-columns: 260px minmax(0, 1fr); }
  body.crm-ui .kb-split .ui-split-main { order: 2; }
  body.crm-ui .kb-split .ui-split-side { order: 1; }
}

/* Вкладки страницы настроек (`.bs-tab`) — тот же язык, что и .tab-inner-nav:
   подчёркивание вместо плашек. Раньше это был отдельный набор правил, и
   вкладки на разных страницах выглядели по-разному (15.08.2026). */
body.crm-ui .bs-tabs { border-bottom: 1px solid var(--ui-border); gap: 0; }
body.crm-ui .bs-tab {
  min-height: 40px;
  padding: 0 4px 10px !important;
  margin-right: 20px;
  border: 0 !important;
  border-bottom: 2px solid transparent !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--ui-muted) !important;
  font-weight: 600 !important;
}
body.crm-ui .bs-tab:hover { color: var(--ui-text) !important; }
body.crm-ui .bs-tab.active {
  color: var(--ui-primary) !important;
  border-bottom-color: var(--ui-primary) !important;
  background: transparent !important;
}

/* Сортируемый заголовок таблицы и пагинация под ней. */
body.crm-ui .ui-table th.ui-th-sort { cursor: pointer; user-select: none; }
body.crm-ui .ui-table th.ui-th-sort:hover { color: var(--ui-text); }
body.crm-ui .ui-pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 12px; border-top: 1px solid var(--ui-border);
  color: var(--ui-muted); font-size: 13px;
}
body.crm-ui .is-hidden { display: none !important; }

/* Категории базы знаний: крупнее и с иконкой папки (правка владельца 15.08). */
/* Владелец 15.08: «больше и жирнее» — 16px и полужирный у всех пунктов,
   не только у активного. */
body.crm-ui .kb-cat { font-size: 16px; font-weight: 600; padding: 12px 12px; }
body.crm-ui .kb-cat-name { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
body.crm-ui .kb-cat-name .lucide-icon { width: 19px; height: 19px; flex: 0 0 19px; color: var(--ui-muted); }
body.crm-ui .kb-cat.active .kb-cat-name .lucide-icon { color: var(--ui-primary); }

/* Время внутри пузыря прижато вправо — как в эталоне. */
body.crm-ui .msg .msg-header { justify-content: space-between; align-items: baseline; }
body.crm-ui .msg .msg-time { margin-left: auto; }

/* Звонок раскрывается прямо в таблице — правой панели нет (правка владельца). */
body.crm-ui .ui-table tr.call-detail-row td { background: var(--ui-surface-muted); padding: 0; }
body.crm-ui .call-detail {
  display: grid; grid-template-columns: minmax(260px, 380px) minmax(0, 1fr);
  gap: 22px; padding: 16px 18px;
}
body.crm-ui .call-detail-facts { margin: 0; }
body.crm-ui .call-detail-talk .transcript-text {
  max-height: 320px; overflow: auto; margin: 0;
  background: var(--ui-surface); border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius); padding: 12px;
}
@media (max-width: 900px) {
  body.crm-ui .call-detail { grid-template-columns: minmax(0, 1fr); gap: 14px; }
}

/* Песочница бота: колонка диалога, пузыри те же, что в живых чатах. */
body.crm-ui .sandbox-chat { display: flex; flex-direction: column; gap: 14px; }
body.crm-ui .sandbox-turn { display: flex; flex-direction: column; gap: 8px; }

/* Детали звонка — карточкой под таблицей, во всю ширину. */
body.crm-ui .call-detail-card { margin-top: 14px; }
body.crm-ui .call-detail-card .call-detail { padding: 0; }

/* ── Список-строками (звонки): дни, раскрытие внутри строки ──────────────
   Не таблица намеренно: <tbody> внутри <template x-for> ломает разбор
   страницы, а раскрытие деталей строкой в <table> требует именно этого. */
body.crm-ui .ui-list {
  background: var(--ui-surface); border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-card); overflow: hidden;
}
body.crm-ui .call-grid {
  display: grid;
  grid-template-columns: 92px 150px minmax(220px, 1fr) 150px 130px 120px 36px;
  gap: 14px; align-items: center;
}
body.crm-ui .ui-list-head {
  padding: 10px 16px; background: var(--ui-surface-muted);
  color: var(--ui-muted); font-size: 12px; font-weight: 600;
  letter-spacing: .02em; border-bottom: 1px solid var(--ui-border);
}
body.crm-ui .ui-list-day {
  padding: 8px 16px; background: var(--ui-surface-muted);
  color: var(--ui-text); font-size: 13px; font-weight: 700;
  border-top: 1px solid var(--ui-border); border-bottom: 1px solid var(--ui-border);
}
body.crm-ui .call-day:first-child .ui-list-day { border-top: 0; }
body.crm-ui .ui-list-item + .ui-list-item { border-top: 1px solid var(--ui-border); }
body.crm-ui .ui-list-row { padding: 12px 16px; cursor: pointer; }
body.crm-ui .ui-list-row:hover { background: var(--ui-surface-muted); }
body.crm-ui .ui-list-item.open > .ui-list-row { background: var(--ui-primary-soft); }
body.crm-ui .ui-list .call-time b,
body.crm-ui .ui-list .call-device b { display: block; font-weight: 600; }
body.crm-ui .ui-list .call-time span,
body.crm-ui .ui-list .call-device span {
  display: block; color: var(--ui-muted); font-size: 13px; margin-top: 2px;
}
body.crm-ui .ui-list .call-chevron { color: var(--ui-muted); text-align: right; }
body.crm-ui .ui-list .call-noorder { color: var(--ui-muted); }
body.crm-ui .ui-list .call-detail {
  display: grid; grid-template-columns: minmax(240px, 360px) minmax(0, 1fr);
  gap: 20px; padding: 4px 16px 18px; background: var(--ui-surface-muted);
}
@media (max-width: 1000px) {
  body.crm-ui .call-grid { grid-template-columns: 80px minmax(0,1fr) 110px 34px; }
  body.crm-ui .call-grid > :nth-child(3),
  body.crm-ui .ui-list-row > :nth-child(5),
  body.crm-ui .ui-list-row > :nth-child(6) { display: none; }
  body.crm-ui .ui-list .call-detail { grid-template-columns: minmax(0,1fr); }
}

/* ── Чат по эталону владельца (2026-08-15_184046.jpg) ───────────────────
   Марка канала слева от входящего, подпись роли НАД пузырём справа,
   разделитель дня по центру, время внутри пузыря справа снизу. */
body.crm-ui .msg-block { display: block; }
body.crm-ui .msg-day {
  text-align: center; margin: 14px 0 10px;
  color: var(--ui-muted); font-size: 12px; font-weight: 600;
}
body.crm-ui .msg-line { display: flex; align-items: flex-start; gap: 10px; }
body.crm-ui .msg-block-client .msg-line { justify-content: flex-start; }
body.crm-ui .msg-block-bot .msg-line,
body.crm-ui .msg-block-operator .msg-line,
body.crm-ui .msg-block-employee .msg-line { justify-content: flex-end; }
body.crm-ui .msg-avatar { width: 28px; height: 28px; flex: 0 0 28px; margin-top: 4px; }
body.crm-ui .msg-wrap { max-width: 68%; min-width: 0; }
body.crm-ui .msg-block-bot .msg-wrap,
body.crm-ui .msg-block-operator .msg-wrap { text-align: right; }
body.crm-ui .msg-label {
  color: var(--ui-muted); font-size: 12px; font-weight: 600; margin: 0 2px 4px;
}
body.crm-ui .msg-line .msg {
  max-width: none; display: inline-block; text-align: left;
  padding: 9px 13px 6px;
}
body.crm-ui .msg .msg-meta {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; margin-top: 3px;
}
body.crm-ui .msg .msg-time { font-size: 11px; color: #9aa5b1; }
body.crm-ui .msg .msg-text { font-size: 14px; line-height: 1.55; }
/* Оператор и сотрудник — один цвет: это одна сторона диалога. */
body.crm-ui .msg-employee { background: #ebf6e8; border-color: #d5ebd0; }
body.crm-ui .msg-undelivered {
  color: var(--ui-danger); font-size: 11px; display: inline-flex;
  align-items: center; gap: 6px;
}
body.crm-ui .msg-resend-btn,
body.crm-ui .msg-teach-btn {
  border: 1px solid var(--ui-border); background: var(--ui-surface);
  color: var(--ui-primary); border-radius: 7px; padding: 2px 8px;
  font-size: 11px; font-weight: 600; cursor: pointer;
}

/* ── Ответ бота в сервисном режиме: своя вёрстка srv-*, но наши цвета ───
   Раньше эти теги экранировались и оператор видел «<div class="srv-row">»
   текстом (правка владельца 15.08.2026). */
body.crm-ui .srv-block { margin: 0 0 14px; }
body.crm-ui .srv-title,
body.crm-ui .srv-section {
  font-size: 12px; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ui-muted);
  margin: 12px 0 6px;
}
body.crm-ui .srv-row,
body.crm-ui .srv-row-simple {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 14px; padding: 7px 0;
  border-top: 1px solid var(--ui-border);
}
body.crm-ui .srv-block > .srv-row:first-of-type,
body.crm-ui .srv-block > .srv-row-simple:first-of-type { border-top: 0; }
body.crm-ui .srv-name { font-weight: 600; min-width: 0; }
body.crm-ui .srv-meta-row,
body.crm-ui .srv-meta,
body.crm-ui .srv-meta-q {
  color: var(--ui-muted); font-size: 13px; text-align: right;
  white-space: nowrap;
}
body.crm-ui .srv-text { line-height: 1.55; }
body.crm-ui .srv-source { color: var(--ui-muted); font-size: 12px; margin-top: 4px; }
body.crm-ui .srv-empty { color: var(--ui-muted); font-style: italic; }
body.crm-ui .srv-q { font-weight: 600; margin-bottom: 4px; }
body.crm-ui .srv-opt { color: var(--ui-primary); font-weight: 600; }
@media (max-width: 640px) {
  body.crm-ui .srv-row, body.crm-ui .srv-row-simple { flex-direction: column; gap: 2px; }
  body.crm-ui .srv-meta-row, body.crm-ui .srv-meta { text-align: left; white-space: normal; }
}

/* Блоки сервисного ответа: заголовок секции + содержимое. */
body.crm-ui .srv-block + .srv-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--ui-border); }
body.crm-ui .srv-header { font-weight: 700; }
body.crm-ui .srv-work .srv-title { color: var(--ui-primary); }

/* Ответ сервисного режима — обычная карточка системы. */
body.crm-ui .srv-answer { margin-bottom: 14px; line-height: 1.6; }
body.crm-ui .srv-suppliers-raw {
  margin-bottom: 16px; white-space: pre-wrap;
  font-size: 12px; line-height: 1.5; color: var(--ui-muted);
}
/* Недоступная кнопка должна читаться как «пока нельзя», а не как поломка:
   контур вместо блёклой заливки (правка владельца 15.08.2026). */
body.crm-ui button:disabled,
body.crm-ui .btn-primary:disabled,
body.crm-ui a.btn[aria-disabled="true"] {
  background: var(--ui-surface) !important;
  color: var(--ui-muted) !important;
  border: 1px solid var(--ui-border) !important;
  opacity: 1 !important;
  cursor: not-allowed;
}

/* Строка над историей запросов песочницы. Была жёлтой плашкой — последний
   островок прежней палитры в сервисном режиме (правка владельца 15.08.2026). */
body.crm-ui .srv-history-bar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px; padding: 8px 12px;
  background: var(--ui-surface); border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
}
body.crm-ui .srv-history-note { font-size: 13px; color: var(--ui-muted); font-weight: 500; }
