/* ================================================================
   audit_log.css — стили для бокового drawer «Журнал операций»
   ================================================================ */

/* Overlay (полупрозрачный фон) */
.audit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1100;
  backdrop-filter: blur(2px);
  transition: opacity 0.25s;
}

/* Сам drawer */
.audit-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 42%;
  min-width: 340px;
  max-width: 720px;
  height: 100dvh;
  background: #fff;
  z-index: 1101;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 32px rgba(0, 0, 0, 0.18);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

@media (max-width: 768px) {
  .audit-drawer {
    width: 100%;
    min-width: unset;
  }
}

/* Шапка drawer */
.audit-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 12px;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
  flex-shrink: 0;
}

.audit-drawer-title {
  font-size: 1.08rem;
  font-weight: 700;
  color: #1e293b;
  letter-spacing: 0.01em;
}

.audit-close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
}

.audit-close-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
}

/* Вкладки */
.audit-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
  background: #fff;
  padding: 0 10px;
  gap: 2px;
}

.audit-tab {
  padding: 9px 16px;
  font-size: 0.84rem;
  font-weight: 500;
  color: #64748b;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.audit-tab:hover {
  color: #1e293b;
}

.audit-tab.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 600;
}

/* Статистика */
.audit-stats-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
  background: #f8fafc;
}

.audit-stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 6px;
  border-right: 1px solid #e5e7eb;
}

.audit-stat-item:last-child {
  border-right: none;
}

.audit-stat-label {
  font-size: 0.72rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.audit-stat-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1e293b;
  margin-top: 1px;
}

/* Фильтры */
.audit-filters {
  padding: 10px 14px 8px;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.audit-filters-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.audit-input {
  height: 32px;
  padding: 0 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.84rem;
  color: #1e293b;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  flex: 1;
  min-width: 80px;
}

.audit-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.audit-filter-sep {
  color: #94a3b8;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.audit-filter-apply-btn {
  height: 32px;
  padding: 0 14px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}

.audit-filter-apply-btn:hover {
  background: #1d4ed8;
}

.audit-filter-reset-btn {
  height: 32px;
  width: 32px;
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.audit-filter-reset-btn:hover {
  background: #e2e8f0;
}

/* Список событий */
.audit-log-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scroll-behavior: smooth;
}

.al-empty {
  padding: 32px 20px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.9rem;
}

.al-empty-err {
  color: #dc2626;
}

/* Элемент журнала */
.al-item {
  padding: 10px 16px;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.1s;
}

.al-item:hover {
  background: #f8fafc;
}

.al-item:last-child {
  border-bottom: none;
}

.al-item-header {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.al-action {
  font-size: 0.86rem;
  font-weight: 600;
  color: #1e293b;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.al-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.al-badge-ok {
  background: #dcfce7;
  color: #166534;
}

.al-badge-err {
  background: #fee2e2;
  color: #991b1b;
}

.al-cat {
  font-size: 0.72rem;
  color: #64748b;
  background: #f1f5f9;
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}

.al-time {
  font-size: 0.72rem;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
}

.al-item-body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.al-user {
  font-size: 0.8rem;
  color: #374151;
  font-weight: 500;
}

.al-entity {
  font-size: 0.78rem;
  color: #6b7280;
  background: #f3f4f6;
  padding: 1px 7px;
  border-radius: 8px;
}

.al-detail {
  font-size: 0.79rem;
  color: #475569;
  word-break: break-word;
}

.al-meta {
  margin-top: 3px;
  font-size: 0.71rem;
  color: #94a3b8;
  font-family: 'Courier New', monospace;
  word-break: break-all;
}

/* Sentinel для IntersectionObserver */
.audit-sentinel {
  height: 1px;
}

/* Секция удаления */
.audit-delete-section {
  border-top: 1px solid #e5e7eb;
  background: #fafafa;
  flex-shrink: 0;
}

.audit-delete-summary {
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #b91c1c;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.audit-delete-summary::-webkit-details-marker { display: none; }
.audit-delete-summary::before { content: '▶'; font-size: 0.65rem; transition: transform 0.2s; }
details[open] .audit-delete-summary::before { transform: rotate(90deg); }

.audit-delete-form {
  padding: 0 16px 14px;
}

.audit-del-btn {
  height: 32px;
  padding: 0 14px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.audit-del-btn:hover { background: #b91c1c; }
.audit-del-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.audit-del-result {
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.audit-del-result.audit-del-result-err {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}

/* ── Пилюли для событий start/end/cancel ─────────────────── */
.al-info-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 5px 0 2px;
}

/* ── Блок "чья это запись" (кого редактировал/удалял админ) ──
   Специально визуально отделён от al-user (кто совершил действие),
   чтобы не путать администратора, менявшего запись, с сотрудником,
   чья запись была изменена. */
.al-target {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin: 4px 0 2px;
}

.al-target-label {
  font-size: 0.71rem;
  font-weight: 700;
  color: #1d4ed8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 1px;
}

.al-target-pill {
  display: inline-flex;
  align-items: center;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.al-target-pill.al-target-secondary {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #475569;
  font-weight: 500;
}

.al-info-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 2px 8px 2px 6px;
  font-size: 0.79rem;
  color: #334155;
  white-space: nowrap;
}

.al-info-pill-key {
  font-size: 0.71rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}

/* Особые цвета для пилюли "Причина" */
.al-item:not(.al-item-error) .al-info-pill:has(.al-info-pill-key) {
  background: #f8fafc;
}

/* ── Блок extra / diff ─────────────────────────────────────── */
.al-extra {
  margin: 4px 0 2px;
  padding: 5px 8px;
  background: var(--al-meta-bg, #f1f5f9);
  border-radius: 5px;
  font-size: 0.78rem;
  color: #475569;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.al-extra-kv b { color: #334155; }

.al-extra-raw {
  font-size: 0.78rem;
  color: #64748b;
  font-style: italic;
}

.al-diff {
  margin: 5px 0 2px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.al-diff-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 0.78rem;
  max-width: 100%;
}

.al-diff-key {
  font-weight: 600;
  color: #334155;
  flex: 0 0 auto;
}

.al-diff-old {
  color: #dc2626;
  background: #fef2f2;
  border-radius: 3px;
  padding: 1px 5px;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}

.al-diff-arrow {
  color: #94a3b8;
  padding: 0 2px;
  flex: 0 0 auto;
}

.al-diff-new {
  color: #16a34a;
  background: #f0fdf4;
  border-radius: 3px;
  padding: 1px 5px;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Вкладка «Ошибки» ── */
.audit-tab-errors {
  color: #dc2626;
  font-weight: 600;
}
.audit-tab-errors.active {
  border-bottom-color: #dc2626;
  color: #dc2626;
}

/* ── Запись с ошибкой ── */
.al-item-error {
  border-left: 3px solid #dc2626;
  background: #fff8f8;
}
.al-item-error .al-action {
  color: #dc2626;
}
.al-detail-error {
  color: #b91c1c !important;
  font-weight: 500;
}

/* ── Запись входа/выхода (онлайн) ── */
.al-item-online {
  border-left: 3px solid #16a34a;
  background: #f0fdf4;
}
.al-item-online .al-action {
  color: #15803d;
  font-weight: 600;
}

/* ── Вкладка «Активность» ── */
.audit-period-bar {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid #e2e8f0;
}

.audit-period-btn {
  padding: 4px 12px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #475569;
  transition: all .15s;
}
.audit-period-btn:hover {
  background: #f1f5f9;
}
.audit-period-btn.active {
  background: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

.audit-custom-range {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid #e2e8f0;
}

.audit-activity-table-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}

.al-act-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}
.al-act-table thead th {
  text-align: left;
  padding: 6px 8px;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  color: #64748b;
  font-weight: 600;
  white-space: nowrap;
}
.al-act-row {
  cursor: pointer;
  transition: background .12s;
}
.al-act-row:hover {
  background: #eff6ff;
}
.al-act-row td {
  padding: 7px 8px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
.al-act-name {
  font-weight: 500;
  color: #1e40af;
  text-decoration: underline dotted;
}
.al-act-role {
  color: #64748b;
  font-size: 12px;
}
.al-act-num {
  text-align: center;
  color: #334155;
}
.al-act-total {
  font-weight: 700;
  color: #1e293b;
}

/* ── Детальный просмотр пользователя ── */
.audit-user-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}
.audit-user-back-btn {
  padding: 4px 10px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #475569;
}
.audit-user-back-btn:hover {
  background: #f1f5f9;
}
.audit-user-detail-name {
  font-weight: 600;
  font-size: 14px;
  color: #1e293b;
}

.al-diff-removed {
  color: #dc2626;
  font-style: italic;
}
.al-diff-empty {
  color: #94a3b8;
}
