/* CRM → «Автоматизации» (public/panel/crm-automation.js). Токены — из panel.css, классы с префиксом crm-auto-.
   Динамика — только классы и data-атрибуты. Телефон (до 700px): строки правил и журнала — карточки, блоки конструктора — в колонку. */

.crm-auto { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.crm-auto-head { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.crm-auto-head .crm-back { margin-bottom: 4px; align-self: flex-start; }
.crm-auto-headrow { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.crm-auto-titles { min-width: 0; flex: 1 1 280px; }
.crm-auto-h1 { margin: 0; font-size: 26px; line-height: 1.2; font-weight: 600; letter-spacing: -.01em; }
.crm-auto-sub { margin: 6px 0 0; color: var(--ink-2); font-size: 14px; line-height: 1.45; }
.crm-auto-h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }
.crm-auto-h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; color: var(--ink); }
.crm-auto-muted { margin: 0; font-size: 13px; line-height: 1.45; color: var(--ink-3); }
.crm-auto-note {
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.45;
}
.crm-auto-note[hidden] { display: none; }

/* Вкладки */
.crm-auto-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.crm-auto-tab {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.crm-auto-tab:hover { background: var(--surface-2); }
.crm-auto-tab[aria-pressed="true"] { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.crm-auto-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.crm-auto-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.crm-auto-pane { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.crm[data-tab="rules"] .crm-auto-pane[data-pane="journal"] { display: none; }
.crm[data-tab="journal"] .crm-auto-pane[data-pane="rules"] { display: none; }
.crm-auto-listbox, .crm-auto-editorbox { min-width: 0; }
.crm-auto-editorbox:empty { display: none; }

/* Список правил */
.crm-auto-list, .crm-auto-jlist, .crm-auto-tplgrid, .crm-auto-lines, .crm-auto-matches { margin: 0; padding: 0; list-style: none; }
.crm-auto-list { display: flex; flex-direction: column; gap: 10px; }
.crm-auto-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 190px auto;
  align-items: center;
  gap: 8px 16px;
  padding: 14px 16px;
  min-width: 0;
}
.crm-auto-row[data-enabled="false"] .crm-auto-main { opacity: .72; }
.crm-auto-switch { min-width: 0; }
.crm-auto-main { min-width: 0; }
.crm-auto-name { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.crm-auto-sum { margin-top: 2px; font-size: 13px; line-height: 1.4; color: var(--ink-2); overflow-wrap: anywhere; }
.crm-auto-stat { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--ink-3); }
.crm-auto-acts { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.crm-auto-move { min-width: 34px; padding: 0 10px; }
.crm-auto-confirm { font-size: 13px; color: var(--danger-ink); font-weight: 500; }

/* Шаблоны */
.crm-auto-templates { min-width: 0; }
.crm-auto-tplgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.crm-auto-tpl { display: flex; flex-direction: column; gap: 6px; padding: 16px; min-width: 0; }
.crm-auto-tpl-title { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.crm-auto-tpl-desc { margin: 0; flex: 1 1 auto; font-size: 13px; line-height: 1.45; color: var(--ink-2); }
.crm-auto-tpl-foot { display: flex; align-items: center; gap: 8px; min-height: 34px; margin-top: 6px; }

/* Конструктор */
.crm-auto-editor { display: flex; flex-direction: column; gap: 16px; padding: 20px; min-width: 0; }
.crm-auto-blocks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: start; min-width: 0; }
.crm-auto-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 14px 16px 16px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--bg);
}
.crm-auto-legend { padding: 0 6px; font-size: 13px; font-weight: 600; color: var(--accent); }
.crm-auto-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.crm-auto-field-wide { width: 100%; }
.crm-auto-label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.crm-auto-select, .crm-auto-name-input, .crm-auto-text, .crm-auto-text-input { width: 100%; min-width: 0; max-width: 100%; }
.crm-auto-num { width: 100%; min-width: 0; max-width: 100%; }
.crm-auto-duration { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 8px; min-width: 0; }
.crm-auto-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  min-width: 0;
  padding: 12px;
  padding-right: 48px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
}
.crm-auto-rm { position: absolute; top: 6px; right: 6px; min-width: 34px; padding: 0 10px; font-size: 18px; line-height: 1; }
.crm-auto-block > .btn { align-self: flex-start; }
.crm-auto-text { resize: vertical; min-height: 84px; }
.crm-auto-textfoot { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.crm-auto-hint { margin: 0; font-size: 12px; line-height: 1.4; color: var(--ink-3); }
.crm-auto-count { flex: none; font-size: 12px; color: var(--ink-3); }
.crm-auto-check { display: inline-flex; align-items: center; gap: 10px; min-height: 40px; font-size: 14px; cursor: pointer; }
.crm-auto-check input { width: 20px; height: 20px; accent-color: var(--accent); }

.crm-auto-preview, .crm-auto-dry {
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  min-width: 0;
}
.crm-auto-lines { display: flex; flex-direction: column; gap: 6px; font-size: 14px; line-height: 1.45; }
.crm-auto-line { overflow-wrap: anywhere; }
.crm-auto-line-k { color: var(--accent); font-weight: 600; }
.crm-auto-dry-sum { margin: 0 0 4px; font-size: 14px; font-weight: 500; }
.crm-auto-safe { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--ok-ink); }
.crm-auto-matches { display: flex; flex-direction: column; gap: 8px; }
.crm-auto-match { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-radius: var(--r-sm); background: var(--surface); font-size: 13px; }
.crm-auto-match-when { color: var(--ink-3); }
.crm-auto-match-would { color: var(--ink); overflow-wrap: anywhere; }
.crm-auto-error, .crm-auto-error-inline { margin: 0; font-size: 13.5px; font-weight: 500; color: var(--danger-ink); }
.crm-auto-error[hidden] { display: none; }
.crm-auto-formacts { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Журнал */
.crm-auto-jbar { display: flex; gap: 12px; flex-wrap: wrap; }
.crm-auto-jbar .crm-auto-field { flex: 0 1 320px; }
.crm-auto-jlist { display: flex; flex-direction: column; gap: 8px; }
.crm-auto-jrow {
  display: grid;
  grid-template-columns: 150px minmax(0, 1.2fr) 120px 80px minmax(0, 2fr);
  align-items: center;
  gap: 8px 16px;
  padding: 12px 16px;
  min-width: 0;
}
.crm-auto-jcell { min-width: 0; font-size: 13.5px; overflow-wrap: anywhere; }
.crm-auto-jwhen { color: var(--ink-3); font-size: 13px; }
.crm-auto-jrule { font-weight: 500; }
.crm-auto-jcodes { color: var(--ink-2); font-size: 12.5px; }
.crm-auto-morerow { display: flex; justify-content: center; }

@media (max-width: 1100px) {
  .crm-auto-blocks { grid-template-columns: minmax(0, 1fr); }
  .crm-auto-tplgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crm-auto-row { grid-template-columns: 96px minmax(0, 1fr); }
  .crm-auto-stat { grid-column: 2; flex-direction: row; flex-wrap: wrap; gap: 4px 16px; }
  .crm-auto-acts { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 700px) {
  .crm-auto-h1 { font-size: 22px; }
  .crm-auto-tplgrid { grid-template-columns: minmax(0, 1fr); }
  .crm-auto-editor { padding: 16px; }
  .crm-auto-headrow .btn { width: 100%; }
  .crm-auto-formacts .btn { flex: 1 1 100%; height: 44px; }
  .crm-auto-row { grid-template-columns: minmax(0, 1fr); padding: 14px; }
  .crm-auto-stat { grid-column: auto; }
  .crm-auto-acts .btn { min-height: 44px; flex: 1 1 auto; }
  .crm-auto-confirm { flex: 1 1 100%; }
  .crm-auto-jrow { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .crm-auto-jcell { display: flex; justify-content: space-between; gap: 12px; }
  .crm-auto-jcell::before { content: attr(data-label); flex: none; color: var(--ink-3); font-size: 12px; }
  .crm-auto-jcodes { text-align: right; }
  .crm-auto-jbar .crm-auto-field { flex: 1 1 100%; }
  .crm-auto-more { width: 100%; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .crm-auto * { transition: none; }
}
