/* ══════════════════════════════════════════════════════════════
   Issue #128 Блок 4 / Issue #129 Шаг 3+4 — Theme Manager Tab CSS
   Добавлено: .tm-active-badge, .tm-row--active, .tm-builtin-note,
              .tm-policy-file-row, .tm-policy-file-status,
              .tm-form-tabs, .tm-form-tab-btn, .tm-form-tab-panel,
              .tm-policy-toolbar, .tm-policy-textarea, .tm-policy-status,
              .tm-rules-*, .btn-sm, .btn-outline, .btn-primary-sm
   Issue #173 Шаг 2: .tm-rules-mode-*, .tm-rules-builtin-banner,
              .tm-rules-preview, .tm-rule-card, .tm-rule-card-*,
              .tm-rule-chip-*, .tm-rules-empty, .tm-rules-loading
   fix(#194): Добавлена полная поддержка тёмной темы через [data-theme="dark"]
              и @media (prefers-color-scheme: dark) fallback
══════════════════════════════════════════════════════════════ */

/* ── Шапка вкладки ─────────────────────────────────────────── */
.tm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.tm-header-left h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 700;
}
.tm-subtitle {
  font-size: 13px;
  color: var(--muted, #888);
}
.tm-subtitle code {
  font-size: 12px;
  background: rgba(0,0,0,.06);
  padding: 1px 5px;
  border-radius: 4px;
}
.tm-header-right {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Таблица тем ───────────────────────────────────────────── */
.tm-table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,.08);
  background: #fff;
}
.tm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tm-table thead tr {
  background: #f7f8fa;
  border-bottom: 2px solid #e8eaed;
}
.tm-table th {
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: #555;
  font-size: 13px;
  white-space: nowrap;
}
.tm-table td {
  padding: 11px 14px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.tm-row:last-child td { border-bottom: none; }
.tm-row:hover td { background: #fafbfc; }

/* Issue #129 Шаг 3: подсветка активной темы */
.tm-row--active td {
  background: #f0faf4;
}
.tm-row--active:hover td {
  background: #e8f7ee;
}

/* ── Ячейки ────────────────────────────────────────────────── */
.tm-cell-id code {
  font-size: 13px;
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
}
.tm-cell-thr { text-align: center; }
.tm-cell-actions { white-space: nowrap; }
.tm-muted { color: #aaa; font-size: 13px; }

/* ── Бэджи ─────────────────────────────────────────────────── */
.tm-builtin-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  background: #e8eaf6;
  color: #5c6bc0;
  border: 1px solid #d2d6f0;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  vertical-align: middle;
  margin-left: 4px;
}

/* Issue #129 Шаг 3: бэдж активной темы */
/* fix(Раздел 36): .tm-active-badge/.tm-tag-badge/.tm-thr-badge переведены
   на капсульную форму (border-radius:999px) + тонкую рамку в тон текста —
   тот же язык, что у .status-badge/.mode-badge вкладки «Процессы»
   (Раздел 35) и .role-pill Панели администратора (Раздел 34.9). */
.tm-active-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  background: #d4edda;
  color: #1a7a3a;
  border: 1px solid #b9dfc4;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  vertical-align: middle;
  margin-left: 4px;
}

.tm-tag-badge {
  display: inline-block;
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #c3ddf5;
  border-radius: 999px;
  padding: 2px 11px;
  font-size: 12px;
  font-weight: 600;
}
.tm-tag-badge--empty {
  background: #f5f5f5;
  color: #aaa;
  border-color: #e6e6e6;
}
.tm-policy-chip {
  font-size: 12px;
  background: #fff8e1;
  color: #f57f17;
  padding: 2px 7px;
  border-radius: 4px;
  font-family: monospace;
}
.tm-thr-badge {
  display: inline-block;
  background: #f5f5f5;
  border: 1px solid #e6e6e6;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.tm-thr-badge--pos {
  background: #e8f5e9;
  color: #2e7d32;
  border-color: #c9e6cb;
}
.tm-thr-badge--neg {
  background: #fce4ec;
  color: #c62828;
  border-color: #f3cddb;
}

/* ── Кнопки действий ───────────────────────────────────────── */
.tm-btn-detail,
.tm-btn-edit,
.tm-btn-toggle,
.tm-btn-delete {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 16px;
  transition: background .15s;
  margin-right: 2px;
}
.tm-btn-detail:hover { background: #e3f2fd; }
.tm-btn-edit:hover   { background: #fff8e1; }
.tm-btn-toggle:hover { background: #f3f4f6; }
.tm-btn-delete:hover { background: #fce4ec; }
.tm-btn-delete:disabled {
  opacity: .35;
  cursor: not-allowed;
}

/* ── Пустое состояние ──────────────────────────────────────── */
.tm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  color: #999;
  gap: 8px;
}
.tm-empty-icon { font-size: 32px; }
.tm-empty--err { color: #c62828; }

/* ── Панель деталей ────────────────────────────────────────── */
.tm-detail-panel {
  margin-top: 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,.1);
  overflow: hidden;
}
.tm-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #f7f8fa;
  border-bottom: 1px solid #e8eaed;
}
.tm-detail-header h3 { margin: 0; font-size: 16px; }
.tm-detail-close {
  background: none; border: none; cursor: pointer;
  font-size: 18px; color: #888;
  padding: 2px 6px; border-radius: 6px;
  transition: background .15s;
}
.tm-detail-close:hover { background: #eee; color: #333; }

.tm-detail-body { padding: 20px; }
.tm-detail-section { margin-bottom: 20px; }
.tm-detail-section:last-child { margin-bottom: 0; }
.tm-detail-section-title {
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: #888; margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.tm-tag-count {
  font-size: 12px; font-weight: 600;
  background: #e3f2fd; color: #1565c0;
  border-radius: 10px; padding: 1px 8px;
}
.tm-tags-grid {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.tm-tag-chip {
  background: #f3f4f6; color: #374151;
  border-radius: 12px; padding: 3px 10px;
  font-size: 13px;
}
.tm-thresholds-row {
  display: flex; gap: 16px; flex-wrap: wrap;
}
.tm-detail-thr {
  display: flex; align-items: center; gap: 8px;
}
.tm-detail-thr-label {
  font-size: 13px; color: #555;
}
.tm-policy-file {
  display: block; font-size: 13px;
  background: #fff8e1; padding: 6px 10px;
  border-radius: 6px; font-family: monospace;
  color: #f57f17;
}

/* ── Оверлей / модал ───────────────────────────────────────── */
.tm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.tm-overlay[hidden] { display: none; }
.tm-modal {
  background: #fff;
  border-radius: 16px;
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
}
.tm-modal--narrow { max-width: 380px; }

.tm-modal-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 18px 24px 0;
}
.tm-modal-header h3 { margin: 0; font-size: 18px; font-weight: 700; }
.tm-modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 20px; color: #888;
  padding: 4px 8px; border-radius: 8px;
  transition: background .15s;
}
.tm-modal-close:hover { background: #f0f0f0; color: #333; }

.tm-modal-form { padding: 20px 24px 24px; }
.tm-modal-body { padding: 16px 24px; }

/* Issue #129 Шаг 3: блок предупреждения для встроенных тем */
.tm-builtin-note {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #7a5000;
  margin-bottom: 16px;
  line-height: 1.5;
}
.tm-builtin-note[hidden] { display: none; }

/* ── Вкладки внутри модала (Issue #129 Шаг 4) ──────────────── */
.tm-form-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 24px 0;
  border-bottom: 2px solid #e5e7eb;
  flex-wrap: wrap;
}
.tm-form-tab-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
}
.tm-form-tab-btn:hover {
  color: #374151;
  background: #f3f4f6;
}
.tm-form-tab-btn.active {
  color: var(--brand, #C32125);
  border-bottom-color: var(--brand, #C32125);
  background: transparent;
}
.tm-form-tab-btn[hidden] { display: none; }

.tm-form-tab-panel {
  display: none;
}
.tm-form-tab-panel.active {
  display: block;
}

/* ── Поля формы ─────────────────────────────────────────────── */
.tm-form-row { margin-bottom: 16px; }
.tm-form-label {
  display: block;
  font-size: 14px; font-weight: 600;
  color: #374151; margin-bottom: 6px;
}
.tm-form-hint {
  display: block;
  font-size: 12px; font-weight: 400;
  color: #9ca3af; margin-top: 2px;
}
.tm-required { color: #dc2626; }
.tm-form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  background: #fff;
  color: #1f2937;
}
.tm-form-input:focus {
  border-color: var(--brand, #C32125);
  box-shadow: 0 0 0 3px rgba(195,33,37,.12);
}
.tm-form-input[readonly] {
  background: #f9fafb;
  color: #9ca3af;
  cursor: default;
}

/* ── Поле "Файл политики тегов" с кнопкой загрузки (Issue #129 Шаг 4) ── */
.tm-policy-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tm-policy-file-row .tm-form-input {
  flex: 1 1 auto;
  min-width: 0;
}
.tm-policy-file-upload-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Строка статуса загрузки файла политики */
.tm-policy-file-status {
  margin-top: 6px;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  background: #f3f4f6;
  color: #374151;
  line-height: 1.4;
}
.tm-policy-file-status[hidden] { display: none; }
.tm-policy-file-status.ok {
  background: #d1fae5;
  color: #065f46;
}
.tm-policy-file-status.err {
  background: #fee2e2;
  color: #991b1b;
}

/* ── Слайдеры порогов ───────────────────────────────────────── */
.tm-form-fieldset {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px 16px;
  margin: 0 0 16px;
}
.tm-form-fieldset legend {
  font-size: 13px; font-weight: 600;
  color: #6b7280; padding: 0 6px;
}
.tm-threshold-grid { display: flex; flex-direction: column; gap: 12px; }
.tm-threshold-row {
  display: grid;
  grid-template-columns: 140px 1fr 48px;
  align-items: center;
  gap: 10px;
}
.tm-threshold-label { font-size: 13px; color: #374151; }
.tm-threshold-val {
  font-size: 14px; font-weight: 700;
  color: var(--brand, #C32125); text-align: right;
  font-variant-numeric: tabular-nums;
}
input[type="range"] { cursor: pointer; width: 100%; }

/* ── Вкладка 3: редактор политики тегов (Issue #129 Шаг 4) ──── */
.tm-policy-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.tm-policy-editor-wrap {
  width: 100%;
}
.tm-policy-textarea {
  width: 100%;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.55;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  resize: vertical;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fafafa;
  color: #1f2937;
}
.tm-policy-textarea:focus {
  border-color: var(--brand, #C32125);
  box-shadow: 0 0 0 3px rgba(195,33,37,.10);
  background: #fff;
}
.tm-policy-status {
  margin-top: 8px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  background: #f3f4f6;
  color: #374151;
  line-height: 1.4;
}
.tm-policy-status[hidden] { display: none; }
.tm-policy-status.ok  { background: #d1fae5; color: #065f46; }
.tm-policy-status.err { background: #fee2e2; color: #991b1b; }

/* ── Вкладка 4: бизнес-правила (Issue #129 Шаг 4) ──────────── */
.tm-rules-superadmin-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #1e3a5f;
  margin-bottom: 14px;
  line-height: 1.5;
}
.tm-rules-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.tm-rules-editor-wrap { width: 100%; }
.tm-rules-textarea {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  resize: vertical;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fafafa;
  color: #1f2937;
}
.tm-rules-textarea:focus {
  border-color: var(--brand, #C32125);
  box-shadow: 0 0 0 3px rgba(195,33,37,.10);
  background: #fff;
}
.tm-rules-status {
  margin-top: 8px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  background: #f3f4f6;
  color: #374151;
  line-height: 1.4;
}
.tm-rules-status[hidden] { display: none; }
.tm-rules-status.ok   { background: #d1fae5; color: #065f46; }
.tm-rules-status.err  { background: #fee2e2; color: #991b1b; }
.tm-rules-status.info { background: #eff6ff; color: #1e40af; }

/* ── Ошибка в форме ─────────────────────────────────────────── */
.tm-form-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #dc2626;
  margin-bottom: 16px;
}
.tm-form-error[hidden] { display: none; }

/* ── Кнопки в модале ────────────────────────────────────────── */
.tm-modal-actions {
  display: flex; gap: 10px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* Предупреждение в модале удаления */
.tm-delete-warn {
  margin-top: 10px;
  font-size: 13px;
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 8px 12px;
}

/* fix(Раздел 36): .btn-sm/.btn-outline/.btn-primary-sm ниже дублировали
   (с другими значениями — indigo вместо var(--accent), другой padding/
   радиус) те же классы, уже определённые в style.css. Поскольку этот файл
   подключается ПОСЛЕ style.css, его версии побеждали в каскаде для ЭТИХ
   классов на ВСЕЙ странице, а не только во вкладке «Темы» — в частности,
   кнопка «💾 Сохранить» в модалке «Настройки» и другие праймари-кнопки
   вне этой вкладки рендерились фирменным индиго вместо акцентного красного
   var(--accent). Определения убраны — используется единая версия из
   style.css (та же категория скрытого конфликта каскада, что и
   .btn-danger/.btn-sm в Разделе 34.8). Локальные .tm-* классы ниже не
   затронуты — конфликтов с style.css у них нет. */


/* ══════════════════════════════════════════════════════════════
   Issue #173 Шаг 2 — CSS для режима-переключателя, builtin-баннера,
   карточек правил, chip-тегов группированных, accordion-секций,
   состояний загрузки и пустого рендера
══════════════════════════════════════════════════════════════ */

/* ── Переключатель режимов «Редактор / Просмотр» ─────────────── */
.tm-rules-mode-switcher {
  display: inline-flex;
  align-items: center;
  background: #f3f4f6;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 12px;
}
.tm-rules-mode-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
  border-radius: 8px;
  transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
  line-height: 1.5;
}
.tm-rules-mode-btn:hover {
  color: #374151;
  background: #e5e7eb;
}
.tm-rules-mode-btn.active {
  background: #fff;
  color: var(--brand, #C32125);
  box-shadow: 0 1px 4px rgba(0,0,0,.10);
}
.tm-rules-mode-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ── Баннер для встроенных тем (builtin) ─────────────────────── */
.tm-rules-builtin-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: #0c4a6e;
  margin-bottom: 12px;
  line-height: 1.5;
}
.tm-rules-builtin-banner[hidden] { display: none; }
.tm-rules-builtin-banner-icon {
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ── Обёртка превью-рендера правил ──────────────────────────── */
.tm-rules-preview-wrap {
  width: 100%;
}
.tm-rules-preview-wrap[hidden] { display: none; }

/* ── Состояние загрузки превью ───────────────────────────────── */
.tm-rules-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 0;
  font-size: 13px;
  color: #9ca3af;
}
.tm-rules-loading[hidden] { display: none; }
.tm-rules-loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--brand, #C32125);
  border-radius: 50%;
  animation: tmRulesSpin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes tmRulesSpin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .tm-rules-loading-spinner { animation: none; opacity: .5; }
}

/* ── Пустое состояние превью ─────────────────────────────────── */
.tm-rules-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  color: #9ca3af;
  font-size: 13px;
  text-align: center;
}
.tm-rules-empty[hidden] { display: none; }
.tm-rules-empty-icon {
  font-size: 28px;
  line-height: 1;
}

/* ── Сетка карточек правил ───────────────────────────────────── */
.tm-rules-preview {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tm-rules-preview[hidden] { display: none; }

/* ── Карточка одного правила (accordion) ─────────────────────── */
.tm-rule-card {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  transition: box-shadow .15s;
}
.tm-rule-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
}

/* Заголовок-кнопка accordion */
.tm-rule-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 11px 14px;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  transition: background .12s;
  border-radius: 0;
}
.tm-rule-card-header:hover {
  background: #f9fafb;
}
.tm-rule-card.open > .tm-rule-card-header {
  background: #f3f4f6;
  border-bottom: 1px solid #e5e7eb;
}

/* Иконка accordion стрелки */
.tm-rule-card-arrow {
  margin-left: auto;
  font-size: 11px;
  color: #9ca3af;
  transition: transform .18s cubic-bezier(.4,0,.2,1);
  flex-shrink: 0;
}
.tm-rule-card.open > .tm-rule-card-header .tm-rule-card-arrow {
  transform: rotate(180deg);
}

/* Цветовой индикатор-полоска слева */
.tm-rule-card-indicator {
  width: 4px;
  height: 20px;
  border-radius: 2px;
  flex-shrink: 0;
}
.tm-rule-card--neutral   > .tm-rule-card-header .tm-rule-card-indicator { background: #9ca3af; }
.tm-rule-card--group1    > .tm-rule-card-header .tm-rule-card-indicator { background: var(--brand, #C32125); }
.tm-rule-card--group2cat > .tm-rule-card-header .tm-rule-card-indicator { background: #f59e0b; }
.tm-rule-card--group2uni > .tm-rule-card-header .tm-rule-card-indicator { background: #10b981; }
.tm-rule-card--tone      > .tm-rule-card-header .tm-rule-card-indicator { background: #ef4444; }

/* Тело accordion (схлопывается) */
.tm-rule-card-body {
  display: none;
  padding: 12px 14px 14px;
  font-size: 13px;
  color: #374151;
  line-height: 1.6;
}
.tm-rule-card.open > .tm-rule-card-body {
  display: block;
}

/* ── Описание и код нарушения внутри карточки ────────────────── */
.tm-rule-desc {
  margin-bottom: 10px;
  color: #4b5563;
  font-size: 13px;
}
.tm-rule-violation-code {
  display: inline-block;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  background: #f3f4f6;
  color: #6b7280;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 600;
  letter-spacing: .2px;
  vertical-align: middle;
}

/* ── Секция тегов внутри карточки ────────────────────────────── */
.tm-rule-tags-section {
  margin-top: 10px;
}
.tm-rule-tags-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #9ca3af;
  margin-bottom: 6px;
}
.tm-rule-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 24px;
}

/* ── Chip-теги внутри карточек правил ────────────────────────── */

/* Базовый chip */
.tm-rc-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  transition: opacity .12s;
}

/* Группа 1 — синий */
.tm-rc-chip--g1 {
  background: #ede9fe;
  color: #4c1d95;
  border: 1px solid #c4b5fd;
}

/* Группа 2 позитивная — зелёный */
.tm-rc-chip--g2pos {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

/* Группа 2 негативная — красный */
.tm-rc-chip--g2neg {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* Нейтральный / без группы */
.tm-rc-chip--neutral {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
}

/* Приоритетный (победитель при конфликте) */
.tm-rc-chip--priority {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
}
.tm-rc-chip--priority::before {
  content: '★';
  font-size: 10px;
  margin-right: 2px;
  color: #3b82f6;
}

/* Форсирование тональности — иконка замка */
.tm-rc-chip--lock::after {
  content: '🔒';
  font-size: 10px;
  margin-left: 3px;
}

/* Пустой список тегов */
.tm-rc-chip--empty {
  background: none;
  color: #9ca3af;
  border: 1px dashed #d1d5db;
  font-weight: 400;
  font-style: italic;
}

/* ── Строка «Нарушение» с кодом-бэджем ───────────────────────── */
.tm-rule-violation-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: #6b7280;
}
.tm-rule-violation-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  border-radius: 5px;
  padding: 1px 7px;
  font-size: 11px;
  font-family: 'Courier New', monospace;
  font-weight: 700;
  letter-spacing: .2px;
}

/* ── Разделитель внутри карточки ─────────────────────────────── */
.tm-rule-divider {
  height: 1px;
  background: #f3f4f6;
  margin: 10px 0;
}

/* ── Инфо-строка с иконкой (приоритет, форсирование и т.п.) ──── */
.tm-rule-info-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 12px;
  color: #4b5563;
  margin-top: 8px;
  line-height: 1.5;
}
.tm-rule-info-icon {
  flex-shrink: 0;
  font-size: 13px;
  margin-top: 1px;
}

/* ── Адаптивность: в узком модале убираем лишние отступы ─────── */
@media (max-width: 480px) {
  .tm-rules-mode-switcher {
    width: 100%;
    justify-content: stretch;
  }
  .tm-rules-mode-btn {
    flex: 1;
    text-align: center;
  }
  .tm-rule-card-header {
    padding: 10px 11px;
  }
  .tm-rule-card-body {
    padding: 10px 11px 12px;
  }
}


/* ══════════════════════════════════════════════════════════════
   fix(#194): ТЁМНАЯ ТЕМА — [data-theme="dark"] overrides
   Покрывает: таблица тем, панель деталей, модал, формы,
   редакторы политик и правил, чипы, бэджи, кнопки.
══════════════════════════════════════════════════════════════ */

/* ── Таблица тем ─────────────────────────────────────────────── */
[data-theme="dark"] .tm-table-wrap {
  background: #1c1b19;
  box-shadow: 0 1px 6px rgba(0,0,0,.3);
}
[data-theme="dark"] .tm-table {
  color: #cdccca;
}
[data-theme="dark"] .tm-table thead tr {
  background: #22211f;
  border-bottom-color: #393836;
}
[data-theme="dark"] .tm-table th {
  color: #797876;
}
[data-theme="dark"] .tm-table td {
  border-bottom-color: #262523;
}
[data-theme="dark"] .tm-row:hover td {
  background: #22211f;
}
[data-theme="dark"] .tm-row--active td {
  background: #1e2d20;
}
[data-theme="dark"] .tm-row--active:hover td {
  background: #243325;
}

/* ── Ячейки ──────────────────────────────────────────────────── */
[data-theme="dark"] .tm-cell-id code {
  background: #2d2c2a;
  color: #cdccca;
}
[data-theme="dark"] .tm-muted {
  color: #5a5957;
}
[data-theme="dark"] .tm-subtitle code {
  background: rgba(255,255,255,.08);
  color: #cdccca;
}

/* ── Бэджи ───────────────────────────────────────────────────── */
[data-theme="dark"] .tm-builtin-badge {
  background: #2a2a40;
  color: #9fa8da;
}
[data-theme="dark"] .tm-active-badge {
  background: #1a3321;
  color: #6daa45;
}
[data-theme="dark"] .tm-tag-badge {
  background: #1a2e40;
  color: #5591c7;
}
[data-theme="dark"] .tm-tag-badge--empty {
  background: #2d2c2a;
  color: #5a5957;
}
[data-theme="dark"] .tm-policy-chip {
  background: #2d2310;
  color: #fdab43;
}
[data-theme="dark"] .tm-thr-badge {
  background: #2d2c2a;
  color: #cdccca;
}
[data-theme="dark"] .tm-thr-badge--pos {
  background: #1a3321;
  color: #6daa45;
}
[data-theme="dark"] .tm-thr-badge--neg {
  background: #3a1a24;
  color: #dd6974;
}

/* ── Кнопки действий в таблице ───────────────────────────────── */
[data-theme="dark"] .tm-btn-detail:hover { background: #1a2e40; }
[data-theme="dark"] .tm-btn-edit:hover   { background: #2d2310; }
[data-theme="dark"] .tm-btn-delete:hover { background: #3a1a24; }

/* ── Пустое состояние ────────────────────────────────────────── */
[data-theme="dark"] .tm-empty {
  color: #5a5957;
}
[data-theme="dark"] .tm-empty--err {
  color: #dd6974;
}

/* ── Панель деталей ──────────────────────────────────────────── */
[data-theme="dark"] .tm-detail-panel {
  background: #1c1b19;
  box-shadow: 0 1px 6px rgba(0,0,0,.3);
}
[data-theme="dark"] .tm-detail-header {
  background: #22211f;
  border-bottom-color: #393836;
}
[data-theme="dark"] .tm-detail-header h3 {
  color: #cdccca;
}
[data-theme="dark"] .tm-detail-close {
  color: #797876;
}
[data-theme="dark"] .tm-detail-close:hover {
  background: #2d2c2a;
  color: #cdccca;
}
[data-theme="dark"] .tm-detail-section-title {
  color: #5a5957;
}
[data-theme="dark"] .tm-tag-count {
  background: #1a2e40;
  color: #5591c7;
}
[data-theme="dark"] .tm-tag-chip {
  background: #2d2c2a;
  color: #cdccca;
}
[data-theme="dark"] .tm-detail-thr-label {
  color: #797876;
}
[data-theme="dark"] .tm-policy-file {
  background: #2d2310;
  color: #fdab43;
}

/* ── Оверлей и модал ─────────────────────────────────────────── */
[data-theme="dark"] .tm-modal {
  background: #1c1b19;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
[data-theme="dark"] .tm-modal-header h3 {
  color: #cdccca;
}
[data-theme="dark"] .tm-modal-close {
  color: #797876;
}
[data-theme="dark"] .tm-modal-close:hover {
  background: #2d2c2a;
  color: #cdccca;
}

/* ── Вкладки модала ──────────────────────────────────────────── */
[data-theme="dark"] .tm-form-tabs {
  border-bottom-color: #393836;
}
[data-theme="dark"] .tm-form-tab-btn {
  color: #797876;
}
[data-theme="dark"] .tm-form-tab-btn:hover {
  color: #cdccca;
  background: #22211f;
}
[data-theme="dark"] .tm-form-tab-btn.active {
  color: var(--brand, #E0575B);
  border-bottom-color: var(--brand, #E0575B);
}

/* ── Поля формы ──────────────────────────────────────────────── */
[data-theme="dark"] .tm-form-label {
  color: #cdccca;
}
[data-theme="dark"] .tm-form-hint {
  color: #5a5957;
}
[data-theme="dark"] .tm-form-input {
  background: #22211f;
  border-color: #393836;
  color: #cdccca;
}
[data-theme="dark"] .tm-form-input::placeholder {
  color: #5a5957;
}
[data-theme="dark"] .tm-form-input:focus {
  border-color: var(--brand, #E0575B);
  box-shadow: 0 0 0 3px rgba(168,111,223,.15);
}
[data-theme="dark"] .tm-form-input[readonly] {
  background: #1c1b19;
  color: #5a5957;
}
[data-theme="dark"] .tm-form-fieldset {
  border-color: #393836;
}
[data-theme="dark"] .tm-form-fieldset legend {
  color: #797876;
}
[data-theme="dark"] .tm-threshold-label {
  color: #cdccca;
}
[data-theme="dark"] .tm-threshold-val {
  color: var(--brand, #E0575B);
}

/* ── Статус файла политики ───────────────────────────────────── */
[data-theme="dark"] .tm-policy-file-status {
  background: #22211f;
  color: #cdccca;
}
[data-theme="dark"] .tm-policy-file-status.ok {
  background: #1a3321;
  color: #6daa45;
}
[data-theme="dark"] .tm-policy-file-status.err {
  background: #3a1a24;
  color: #dd6974;
}

/* ── Редактор политики тегов ─────────────────────────────────── */
[data-theme="dark"] .tm-policy-textarea {
  background: #22211f;
  border-color: #393836;
  color: #cdccca;
}
[data-theme="dark"] .tm-policy-textarea:focus {
  border-color: var(--brand, #E0575B);
  box-shadow: 0 0 0 3px rgba(168,111,223,.15);
  background: #1c1b19;
}
[data-theme="dark"] .tm-policy-status {
  background: #22211f;
  color: #cdccca;
}
[data-theme="dark"] .tm-policy-status.ok  { background: #1a3321; color: #6daa45; }
[data-theme="dark"] .tm-policy-status.err { background: #3a1a24; color: #dd6974; }

/* ── Редактор бизнес-правил ──────────────────────────────────── */
[data-theme="dark"] .tm-rules-superadmin-notice {
  background: #1a2535;
  border-color: #2a3f58;
  color: #7ab8e8;
}
[data-theme="dark"] .tm-rules-textarea {
  background: #22211f;
  border-color: #393836;
  color: #cdccca;
}
[data-theme="dark"] .tm-rules-textarea:focus {
  border-color: var(--brand, #E0575B);
  box-shadow: 0 0 0 3px rgba(168,111,223,.15);
  background: #1c1b19;
}
[data-theme="dark"] .tm-rules-status {
  background: #22211f;
  color: #cdccca;
}
[data-theme="dark"] .tm-rules-status.ok   { background: #1a3321; color: #6daa45; }
[data-theme="dark"] .tm-rules-status.err  { background: #3a1a24; color: #dd6974; }
[data-theme="dark"] .tm-rules-status.info { background: #1a2535; color: #5591c7; }

/* ── Переключатель режимов ───────────────────────────────────── */
[data-theme="dark"] .tm-rules-mode-switcher {
  background: #22211f;
}
[data-theme="dark"] .tm-rules-mode-btn {
  color: #797876;
}
[data-theme="dark"] .tm-rules-mode-btn:hover {
  color: #cdccca;
  background: #2d2c2a;
}
[data-theme="dark"] .tm-rules-mode-btn.active {
  background: #2d2c2a;
  color: var(--brand, #E0575B);
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* ── Баннер встроенных тем ───────────────────────────────────── */
[data-theme="dark"] .tm-rules-builtin-banner {
  background: #1a2535;
  border-color: #2a3f58;
  color: #7ab8e8;
}
[data-theme="dark"] .tm-builtin-note {
  background: #2d2310;
  border-color: #4d3a10;
  color: #fdab43;
}

/* ── Карточки правил ─────────────────────────────────────────── */
[data-theme="dark"] .tm-rule-card {
  background: #1c1b19;
  border-color: #393836;
}
[data-theme="dark"] .tm-rule-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
[data-theme="dark"] .tm-rule-card-header {
  color: #cdccca;
}
[data-theme="dark"] .tm-rule-card-header:hover {
  background: #22211f;
}
[data-theme="dark"] .tm-rule-card.open > .tm-rule-card-header {
  background: #22211f;
  border-bottom-color: #393836;
}
[data-theme="dark"] .tm-rule-card-arrow {
  color: #5a5957;
}
[data-theme="dark"] .tm-rule-card-body {
  color: #cdccca;
}
[data-theme="dark"] .tm-rule-desc {
  color: #797876;
}
[data-theme="dark"] .tm-rule-violation-code {
  background: #2d2c2a;
  color: #797876;
}
[data-theme="dark"] .tm-rule-divider {
  background: #262523;
}
[data-theme="dark"] .tm-rule-info-row {
  color: #797876;
}
[data-theme="dark"] .tm-rule-tags-label {
  color: #5a5957;
}
[data-theme="dark"] .tm-rule-violation-badge {
  background: #2d2310;
  color: #fdab43;
  border-color: #4d3a10;
}
[data-theme="dark"] .tm-rule-violation-row {
  color: #5a5957;
}

/* ── Chip-теги карточек правил ───────────────────────────────── */
[data-theme="dark"] .tm-rc-chip--g1 {
  background: #2a2040;
  color: var(--brand, #E0575B);
  border-color: #5937a0;
}
[data-theme="dark"] .tm-rc-chip--g2pos {
  background: #1a3321;
  color: #6daa45;
  border-color: #3a6635;
}
[data-theme="dark"] .tm-rc-chip--g2neg {
  background: #3a1a24;
  color: #dd6974;
  border-color: #7a3040;
}
[data-theme="dark"] .tm-rc-chip--neutral {
  background: #2d2c2a;
  color: #cdccca;
  border-color: #393836;
}
[data-theme="dark"] .tm-rc-chip--priority {
  background: #1a2535;
  color: #5591c7;
  border-color: #2a3f58;
}
[data-theme="dark"] .tm-rc-chip--priority::before {
  color: #5591c7;
}
[data-theme="dark"] .tm-rc-chip--empty {
  color: #5a5957;
  border-color: #393836;
}

/* fix(Раздел 36): переопределение .btn-outline для тёмной темы убрано
   вместе со светлым — см. комментарий выше про дубль каскада; тёмная
   версия .btn-outline уже определена в style.css. */

/* ── Предупреждение в модале удаления ────────────────────────── */
[data-theme="dark"] .tm-delete-warn {
  background: #2d2310;
  border-color: #4d3a10;
  color: #fdab43;
}

/* ── Ошибка в форме ──────────────────────────────────────────── */
[data-theme="dark"] .tm-form-error {
  background: #3a1a24;
  border-color: #7a3040;
  color: #dd6974;
}

/* ══════════════════════════════════════════════════════════════
   fix(#194): FALLBACK — системные предпочтения без ручного выбора
   Дублирует [data-theme="dark"] для пользователей, у которых
   тема не была явно переключена (localStorage пуст).
══════════════════════════════════════════════════════════════ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .tm-table-wrap { background: #1c1b19; }
  :root:not([data-theme]) .tm-table { color: #cdccca; }
  :root:not([data-theme]) .tm-table thead tr { background: #22211f; border-bottom-color: #393836; }
  :root:not([data-theme]) .tm-table th { color: #797876; }
  :root:not([data-theme]) .tm-table td { border-bottom-color: #262523; }
  :root:not([data-theme]) .tm-row:hover td { background: #22211f; }
  :root:not([data-theme]) .tm-row--active td { background: #1e2d20; }
  :root:not([data-theme]) .tm-row--active:hover td { background: #243325; }
  :root:not([data-theme]) .tm-cell-id code { background: #2d2c2a; color: #cdccca; }
  :root:not([data-theme]) .tm-detail-panel { background: #1c1b19; }
  :root:not([data-theme]) .tm-detail-header { background: #22211f; border-bottom-color: #393836; }
  :root:not([data-theme]) .tm-detail-header h3 { color: #cdccca; }
  :root:not([data-theme]) .tm-tag-chip { background: #2d2c2a; color: #cdccca; }
  :root:not([data-theme]) .tm-modal { background: #1c1b19; }
  :root:not([data-theme]) .tm-modal-header h3 { color: #cdccca; }
  :root:not([data-theme]) .tm-form-input { background: #22211f; border-color: #393836; color: #cdccca; }
  :root:not([data-theme]) .tm-form-label { color: #cdccca; }
  :root:not([data-theme]) .tm-policy-textarea { background: #22211f; border-color: #393836; color: #cdccca; }
  :root:not([data-theme]) .tm-rules-textarea { background: #22211f; border-color: #393836; color: #cdccca; }
  :root:not([data-theme]) .tm-rule-card { background: #1c1b19; border-color: #393836; }
  :root:not([data-theme]) .tm-rule-card-header { color: #cdccca; }
  :root:not([data-theme]) .tm-rule-card-body { color: #cdccca; }
}

/* Раздел 203: таблица фильтров BA и отключённые темы */
.tm-filters-table { width: 100%; border-collapse: collapse; margin: 6px 0; font-weight: 400; }
.tm-filters-table th { font-size: 12px; font-weight: 600; text-align: left; padding: 4px 6px; color: #6b7280; }
.tm-filters-table td { padding: 3px 6px; vertical-align: middle; }
.tm-filters-table td:nth-child(1) { width: 130px; }
.tm-filters-table td:nth-child(3) { width: 110px; text-align: center; }
.tm-filters-table td:nth-child(4) { width: 36px; }
.tm-filters-table .tm-form-input { margin: 0; }
.tm-check-label { display: flex; align-items: center; justify-content: flex-start; gap: 8px; font-weight: 400; }
.tm-check-label input[type="checkbox"], .tm-filters-table input[type="checkbox"] { width: auto; flex: none; margin: 0; }
.tm-row--disabled td { opacity: .55; }
.tm-row--disabled td.tm-cell-actions { opacity: 1; }
.tm-disabled-badge { background: #f3f4f6 !important; color: #6b7280 !important; border-color: #e5e7eb !important; }
[data-theme="dark"] .tm-filters-table th { color: #8a8987; }
[data-theme="dark"] .tm-disabled-badge { background: #2a2927 !important; color: #a3a2a0 !important; border-color: #393836 !important; }

/* Раздел 209: темы целиком (группы моделей) над таблицей */
.tm-topics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -8px 0 16px;
}
.tm-topics-title { font-weight: 600; margin-right: 4px; }
.tm-topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 12px;
  border: 1px solid var(--color-border, #e3e0d8);
  border-radius: 999px;
  font-size: 13px;
}
.tm-topic-chip--off { opacity: .6; border-style: dashed; }
/* Раздел 542: сервер темы */
.tm-topic-server {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--color-text-muted, var(--muted));
}
.tm-topic-server input {
  width: 4.5em;
  padding: 2px 6px;
  font-size: 12px;
  border: 1px solid var(--color-border, #e3e0d8);
  border-radius: 6px;
  background: transparent;
  color: inherit;
}
.tm-topic-toggle {
  border: 0;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  background: var(--color-surface-2, #f4f2ed);
  color: inherit;
}
.tm-form-row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 560px) {
  .tm-form-row2 { grid-template-columns: 1fr; }
}

/* ══ Раздел 217: окно «Новая тема» / «Изменить тему» ══════════════
   Форма стояла вплотную к краям окна, подписи слипались с полями. */
.tm-modal:has(#tmEditForm) { max-width: 760px; }
#tmEditForm.tm-form { padding: 0 24px 0; }
#tmEditForm .tm-form-tabs { margin: 0 -24px 18px; padding: 10px 24px 0; }
#tmEditOverlay .tm-builtin-note { margin: 12px 24px 0; }
#tmEditForm .tm-form-label:not(.tm-check-label) {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 14px; font-size: 13px;
}
#tmEditForm .tm-check-label { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
#tmEditForm .tm-form-row2 { gap: 14px; }
#tmEditForm .tm-form-footer {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; justify-content: flex-end; gap: 10px;
  margin: 8px -24px 0; padding: 14px 24px;
  background: #fff; border-top: 1px solid #e5e7eb;
}
[data-theme="dark"] #tmEditForm .tm-form-footer { background: #1c1b19; border-top-color: #393836; }
#tmEditOverlay .tm-modal-header { padding-bottom: 4px; }
.tm-cell-kind { white-space: nowrap; }
.tm-kind { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .03em; }
.tm-kind--llm { background: var(--brand-soft, #FBEEEE); color: var(--brand, #C32125); border: 1px solid var(--brand-line, #EFC9CA); }
.tm-kind--bert { background: #eef1f4; color: #4b5563; border: 1px solid #dde2e8; }
[data-theme="dark"] .tm-kind--bert { background: #262523; color: #a8a7a4; border-color: #393836; }
.tm-cell-actions { white-space: nowrap; }

/* Раздел 460: название темы — фильтр карточек и таблицы */
.tm-topic-chip { padding: 0 6px 0 0; gap: 6px; transition: border-color .15s, background .15s; }
.tm-topic-chip--all { padding: 0; }
.tm-topic-pick {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: none; color: inherit; font: inherit; cursor: pointer;
  padding: 5px 6px 5px 12px; border-radius: 999px;
}
.tm-topic-chip--all .tm-topic-pick { padding: 5px 14px; }
.tm-topic-pick:hover b { color: var(--brand, #C32125); }
.tm-topic-pick:focus-visible { outline: 2px solid var(--brand, #C32125); outline-offset: 1px; }
.tm-topic-chip.is-on { border-color: var(--brand, #C32125); background: color-mix(in srgb, var(--brand, #C32125) 9%, transparent); }
.tm-topic-chip.is-on b { color: var(--brand, #C32125); }

/* ══ Раздел 556: «Служебные теги темы» — сетка полей ══════════════ */
#tmEditForm fieldset.tm-service-tags {
  border: 1px solid #e5e7eb; border-radius: 10px; padding: 10px 14px 12px; min-width: 0;
}
#tmEditForm fieldset.tm-service-tags legend { padding: 0 6px; font-weight: 600; }
.tm-service-tags-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px;
}
.tm-service-tags-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.tm-service-tags-grid small { font-size: 12px; font-weight: 400; }
[data-theme="dark"] #tmEditForm fieldset.tm-service-tags { border-color: #393836; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) #tmEditForm fieldset.tm-service-tags { border-color: #393836; }
}

/* ══ Раздел 621: «Что размечать» — галочки в строку ═══════════════ */
.tm-label-parts-row { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 2px 0 6px; }
.tm-label-parts-row label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 500; cursor: pointer; min-height: 32px; }
.tm-label-parts-row input { width: 16px; height: 16px; accent-color: var(--brand, #C32125); }

/* ══ Раздел 589: темы — карточки с логотипом ══════════════════════════ */
.tm-topics { display: block; margin: 4px 0 18px; }
.tm-topics-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 10px; }
.tm-topics-head .tm-topics-title { margin: 0; font-size: 15px; font-weight: 650; }
.tm-topics-head .tm-muted { font-size: 12.5px; }
.tm-tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 10px; }
.tm-tcard.tm-topic-chip {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto;
  align-items: center; gap: 10px 12px; padding: 12px 12px 10px; border-radius: 14px;
  border: 1px solid var(--border, #e3e0d8); background: var(--surface, #fff);
  transition: border-color .15s, box-shadow .15s, transform .15s, background .15s;
}
.tm-tcard.tm-topic-chip:hover { border-color: var(--brand-line, #EFC9CA); box-shadow: 0 6px 18px -10px rgba(0,0,0,.25); transform: translateY(-1px); }
.tm-tcard.tm-topic-chip.is-on { border-color: var(--brand, #C32125); background: var(--brand-soft, #FBEEEE); box-shadow: 0 0 0 3px var(--brand-soft, #FBEEEE); }
.tm-tcard.is-off { opacity: 1; border-style: dashed; }
.tm-tcard.is-off .tm-tcard-ava, .tm-tcard.is-off .tm-tcard-text { opacity: .55; filter: grayscale(.6); }
.tm-tcard .tm-topic-pick {
  grid-column: 2; grid-row: 1; padding: 0; border-radius: 8px; min-width: 0; text-align: left; justify-content: flex-start;
}
.tm-tcard .tm-topic-pick::after { content: ""; position: absolute; inset: 0; border-radius: 14px; } /* вся карточка — фильтр */
.tm-tcard-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; line-height: 1.25; }
.tm-tcard-text b { font-size: 14.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-tcard-text span { font-size: 12px; color: var(--muted); }
.tm-tcard .tm-topic-toggle { grid-column: 3; grid-row: 1; position: relative; z-index: 1; }
.tm-tcard-logo {
  grid-column: 1; grid-row: 1; position: relative; z-index: 1; padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 12px; line-height: 0;
}
.tm-tcard-logo:focus-visible { outline: 2px solid var(--brand, #C32125); outline-offset: 2px; }
.tm-tcard-ava, .tm-logo-drop-ava {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand, #C32125); color: #fff; font-weight: 700; font-size: 18px; line-height: 1;
}
.tm-tcard-ava--all { background: var(--color-surface-2, #f3f0ec); color: var(--muted); }
.tm-tcard-edit {
  position: absolute; right: -5px; bottom: -5px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface, #fff); color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.25); opacity: 0; transform: scale(.8); transition: opacity .15s, transform .15s;
}
.tm-tcard:hover .tm-tcard-edit, .tm-tcard-logo:focus-visible .tm-tcard-edit { opacity: 1; transform: scale(1); }
.tm-tcard-logo.is-over .tm-tcard-ava { outline: 2px dashed var(--brand, #C32125); outline-offset: 3px; }
.tm-tcard-server.tm-topic-server {
  grid-column: 1 / -1; grid-row: 2; position: relative; z-index: 1; display: flex; align-items: center; gap: 8px;
  padding-top: 8px; border-top: 1px solid var(--border, #eee); font-size: 12px; color: var(--muted);
}
.tm-tcard-server input {
  width: auto; flex: 1; min-width: 0; max-width: 110px; padding: 4px 8px; font-size: 12.5px;
  border: 1px solid transparent; border-radius: 8px; background: var(--color-surface-2, #f4f2ed); color: var(--text);
}
.tm-tcard-server input:hover { border-color: var(--border); }
.tm-tcard-server input:focus { outline: none; border-color: var(--brand, #C32125); background: var(--surface, #fff); }
.tm-tcard--all.tm-topic-chip { grid-template-columns: auto 1fr; grid-template-rows: auto; }
.tm-tcard--all .tm-topic-pick { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }

/* окно логотипа */
.tm-logo-pop {
  position: absolute; z-index: 1000; width: 300px; padding: 14px; border-radius: 16px;
  background: var(--surface, #fff); border: 1px solid var(--border, #e3e0d8);
  box-shadow: 0 18px 50px -12px rgba(0,0,0,.35); animation: tm-pop .14s ease-out;
}
@keyframes tm-pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.tm-logo-pop-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.tm-logo-pop-h b { font-size: 14px; }
.tm-logo-pop-h span { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm-logo-drop {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; cursor: pointer;
  border: 1.5px dashed var(--border, #d8d4ca); background: var(--color-surface-2, #f7f5f0); font-size: 13px;
  transition: border-color .15s, background .15s;
}
.tm-logo-drop:hover, .tm-logo-drop:focus-visible, .tm-logo-drop.is-over { border-color: var(--brand, #C32125); background: var(--brand-soft, #FBEEEE); outline: none; }
.tm-logo-drop small { display: block; margin-top: 3px; font-size: 11.5px; color: var(--muted); }
.tm-logo-drop u { text-decoration-color: var(--brand, #C32125); text-underline-offset: 2px; }
.tm-logo-drop-ava { flex: none; width: 48px; height: 48px; }
.tm-logo-pop-l { margin: 12px 0 8px; font-size: 12px; color: var(--muted); }
.tm-logo-sws { display: flex; flex-wrap: wrap; gap: 8px; }
.tm-logo-sw {
  width: 26px; height: 26px; padding: 0; border-radius: 50%; cursor: pointer; border: 0;
  background: var(--sw); box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); transition: transform .12s;
}
.tm-logo-sw:hover { transform: scale(1.12); }
.tm-logo-sw.is-on { box-shadow: 0 0 0 2px var(--surface, #fff), 0 0 0 4px var(--sw); }
.tm-logo-sw:focus-visible { outline: 2px solid var(--brand, #C32125); outline-offset: 2px; }
.tm-logo-sw--custom {
  position: relative; overflow: hidden;
  background: conic-gradient(#f03e3e, #fab005, #40c057, #15aabf, #4c6ef5, #be4bdb, #f03e3e);
}
.tm-logo-sw--custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.tm-logo-reset.tm-link { margin-top: 12px; padding: 0; font-size: 12.5px; }

/* логотип в карточке и таблице моделей */
.tm-card-avatar.has-logo { background: #fff; padding: 3px; box-shadow: inset 0 0 0 1px var(--border); overflow: hidden; }
.tm-cell-label .topic-mini-ava { margin-right: 8px; }

[data-theme="dark"] .tm-tcard.tm-topic-chip:hover { box-shadow: 0 6px 18px -10px rgba(0,0,0,.7); }
[data-theme="dark"] .tm-logo-pop { box-shadow: 0 18px 50px -12px rgba(0,0,0,.8); }
[data-theme="dark"] .tm-tcard-edit { background: #2a2927; }
.tm-tcard-ava.has-logo, .tm-logo-drop-ava.has-logo { background: #fff; padding: 3px; box-shadow: inset 0 0 0 1px var(--border, #e3e0d8); overflow: hidden; }
.tm-tcard-ava.has-logo > img, .tm-logo-drop-ava.has-logo > img { border-radius: 9px; }
.tm-card-avatar[style*="background"] { color: #fff; }
.tm-logo-pop { width: 344px; max-width: calc(100vw - 16px); }
.tm-logo-sws { gap: 6px; }
.tm-logo-reset.tm-link { display: block; white-space: nowrap; }
@media (max-width: 640px) { .tm-tgrid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); } .tm-tcard--all { grid-column: 1 / -1; } }
