/* ================================================================
   ЭТАП 9 — раздел «Контроль»: журнал действий и архив.
   Только новые классы crm-au-*. Общие стили crm/crm.css не
   изменяются, поэтому crm 2.1.html продолжает работать как раньше.
   ================================================================ */

.crm-au-wrap { display: flex; flex-direction: column; gap: 16px; }

/* ---- Шапка и вкладки ---- */
.crm-au-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.crm-au-title { margin: 0; font-size: 20px; font-weight: 700; color: var(--text); }
.crm-au-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

.crm-au-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.crm-au-tab {
  padding: 9px 16px; font-size: 14px; font-weight: 500; color: var(--text-secondary);
  background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; margin-bottom: -1px; white-space: nowrap; min-height: 40px;
}
.crm-au-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.crm-au-tab:hover:not(.active) { color: var(--text); }
.crm-au-tab:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: -2px; }

/* ---- Фильтры ---- */
.crm-au-filters {
  background: #f8fafc; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
}
.crm-au-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.crm-au-chip {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 16px;
  background: #fff; font-size: 12px; color: var(--text-secondary);
  cursor: pointer; white-space: nowrap; min-height: 36px;
}
.crm-au-chip.active { background: var(--accent, #2563eb); border-color: var(--accent, #2563eb); color: #fff; font-weight: 600; }
.crm-au-chip:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: 2px; }

.crm-au-custom { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.crm-au-custom label {
  display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em;
}
.crm-au-custom input {
  padding: 7px 10px; font-size: 13px; border: 1px solid var(--border);
  border-radius: 6px; outline: none; min-height: 36px;
}

.crm-au-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.crm-au-field { display: flex; flex-direction: column; gap: 3px; min-width: 150px; flex: 0 1 185px; }
.crm-au-field-wide { flex: 1 1 260px; }
.crm-au-field > span {
  font-size: 11px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em;
}
.crm-au-field > select, .crm-au-field > input {
  padding: 7px 10px; font-size: 13px; border: 1px solid var(--border);
  border-radius: 6px; outline: none; background: #fff; min-height: 36px;
  width: 100%; box-sizing: border-box;
}
.crm-au-field > select:focus-visible, .crm-au-field > input:focus-visible {
  border-color: var(--accent, #2563eb); outline: 2px solid #bfdbfe;
}
.crm-au-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.crm-au-btn { min-height: 36px; padding: 8px 14px; font-size: 13px; }

.crm-au-skel { padding: 24px 12px; text-align: center; color: var(--text-muted, #94a3b8); font-size: 13px; }
.crm-au-note { font-size: 12px; color: var(--text-muted, #94a3b8); line-height: 1.5; margin-top: 8px; }
.crm-au-muted { color: var(--text-muted, #94a3b8); }

.crm-au-warn {
  margin-top: 12px; padding: 10px 14px; border: 1px solid #fde68a;
  background: #fffbeb; color: #92400e; border-radius: 10px; font-size: 13px; line-height: 1.5;
}
.crm-au-warn ul { margin: 6px 0 0; padding-left: 20px; }

/* ---- Таблицы ---- */
.crm-au-table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.crm-au-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.crm-au-table th, .crm-au-table td {
  padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border);
}
.crm-au-table th {
  font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase;
  letter-spacing: .03em; white-space: nowrap; background: #f8fafc;
}
.crm-au-table tbody tr:last-child td { border-bottom: none; }
.crm-au-row { cursor: pointer; }
.crm-au-row:hover { background: #f8fafc; }
.crm-au-row:focus-visible { outline: 2px solid var(--accent, #2563eb); outline-offset: -2px; }

/* Тип действия различается подписью, а не только цветом (§52). */
.crm-au-act {
  display: inline-block; font-size: 11px; font-weight: 600; white-space: nowrap;
  padding: 2px 8px; border-radius: 12px; background: #f1f5f9; color: #475569;
  border: 1px solid #e2e8f0;
}
.crm-au-act-create   { background: #e8f5ec; color: #15803d; border-color: #bbf7d0; }
.crm-au-act-archive  { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.crm-au-act-restore  { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.crm-au-act-export   { background: #fdf3e3; color: #b45309; border-color: #fde68a; }
.crm-au-act-bulk_action { background: #f5f3ff; color: #7c3aed; border-color: #ddd6fe; }

.crm-au-arch {
  display: inline-block; font-size: 10px; font-weight: 600; background: #f1f5f9;
  color: #64748b; padding: 1px 6px; border-radius: 8px; white-space: nowrap;
}

.crm-au-pager {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 10px; font-size: 12px; color: var(--text-secondary); flex-wrap: wrap;
}

/* ---- Панель подробностей ---- */
.crm-audit-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 950;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.crm-audit-overlay.open { opacity: 1; pointer-events: auto; }
.crm-audit-panel {
  position: fixed; top: 0; right: 0; width: min(620px, 94vw); max-width: 100vw; height: 100vh;
  background: #fff; box-shadow: -4px 0 24px rgba(0,0,0,.12); z-index: 951;
  display: flex; flex-direction: column; transform: translateX(100%);
  transition: transform .25s; overflow: hidden;
}
.crm-audit-panel.open { transform: translateX(0); }
@media (max-width: 768px) { .crm-audit-panel { width: 100vw; } }

.crm-au-panel-head {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.crm-au-panel-title { flex: 1; min-width: 0; font-weight: 700; font-size: 16px; color: var(--text); word-break: break-word; }
.crm-au-panel-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.crm-au-panel-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.crm-au-h4 { margin: 18px 0 8px; font-size: 13px; font-weight: 700; color: var(--text);
  text-transform: uppercase; letter-spacing: .04em; }
.crm-au-dl { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.crm-au-dl > div { display: flex; gap: 10px; align-items: baseline; }
.crm-au-dl dt { flex: 0 0 42%; font-size: 12px; color: var(--text-secondary); }
.crm-au-dl dd { flex: 1; margin: 0; font-size: 13px; color: var(--text); word-break: break-word; }

.crm-au-diff td { font-size: 13px; }
.crm-au-diff td:nth-child(2) { color: var(--text-secondary); }
.crm-au-diff td:nth-child(3) { font-weight: 600; }

/* ================================================================
   МОБИЛЬНАЯ ВЕРСИЯ (§51): таблицы становятся карточками, фильтры
   разворачиваются в столбец, крупные кнопки, без горизонтальной
   прокрутки всей страницы.
   ================================================================ */
@media (max-width: 820px) {
  .crm-au-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .crm-au-chip { flex: 1 1 calc(50% - 6px); text-align: center; min-height: 42px; }
  .crm-au-fields { flex-direction: column; align-items: stretch; }
  .crm-au-field { flex: 1 1 auto; min-width: 0; }
  .crm-au-actions { margin-left: 0; }
  .crm-au-actions .crm-au-btn { flex: 1 1 calc(50% - 4px); min-height: 44px; }
  .crm-au-custom { flex-direction: column; align-items: stretch; }
  .crm-au-custom input { width: 100%; box-sizing: border-box; }

  .crm-au-table-scroll { overflow-x: visible; border: none; background: none; }
  .crm-au-table { display: block; }
  .crm-au-table thead { display: none; }
  .crm-au-table tbody, .crm-au-table tr, .crm-au-table td { display: block; width: 100%; }
  .crm-au-table tr {
    border: 1px solid var(--border); border-radius: 12px; background: #fff;
    padding: 10px 12px; margin-bottom: 10px;
  }
  .crm-au-table td { border-bottom: none; padding: 3px 0; white-space: normal; }
  .crm-au-table td[data-l]:not([data-l=""])::before {
    content: attr(data-l) ': '; font-size: 11px; font-weight: 600; color: var(--text-secondary);
  }
  .crm-au-table td:first-child { font-weight: 600; font-size: 15px; }
  .crm-au-table td:last-child { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
  .crm-au-table td:last-child .crm-btn-sm { flex: 1 1 auto; min-height: 44px; }

  .crm-au-pager .crm-au-btn { min-height: 44px; }
  .crm-au-dl > div { flex-direction: column; gap: 2px; }
  .crm-au-dl dt { flex: none; }
  /* Основное действие формы остаётся на виду (§51). */
  .crm-au-panel-actions .crm-au-btn { flex: 1 1 100%; min-height: 46px; }
}
