:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --line: #d9e0ea;
  --text: #1f2937;
  --muted: #64748b;
  --accent: #7c3aed;
  --accent-strong: #6d28d9;
  --accent-soft: #ede9fe;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #0369a1;
  --info-soft: #e0f2fe;
  --shadow: 0 18px 35px rgba(15, 23, 42, 0.08);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  /* строгая тема держит ровный фон (background: var(--bg) !important) —
     фиолетовый градиент здесь всё равно не рисовался */
  background: var(--bg);
  color: var(--text);
}
.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}
.hero, .filters, .stats, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.hero {
  padding: 24px 28px;
  margin-bottom: 20px;
}
.hero h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.1;
}
.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 920px;
  line-height: 1.55;
}
.filters {
  padding: 18px;
  margin-bottom: 20px;
}
.filters form {
  display: grid;
  grid-template-columns: 220px minmax(320px, 1fr) auto auto auto;
  gap: 14px;
  align-items: end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.field input,
.field select {
  width: 100%;
  min-height: 46px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 0 13px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  text-decoration: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn:hover {
  transform: translateY(-1px);
}
.btn-primary {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 12px 24px rgba(124, 58, 237, 0.16);
}
.btn-secondary {
  color: var(--text);
  background: transparent;
  border-color: var(--line);
}
.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
  margin-bottom: 20px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.96));
}
.stat-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
  font-weight: 700;
}
.stats-duplicates {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stat-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  font-weight: 700;
}
.error {
  display: none;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(185, 28, 28, 0.18);
  background: var(--bad-soft);
  color: var(--bad);
}
.notice {
  display: none;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(124, 58, 237, 0.18);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.panel {
  overflow: hidden;
  margin-bottom: 20px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.9));
}
.panel-head h2 {
  margin: 0;
  font-size: 18px;
}
.meta {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.table-wrap {
  overflow: auto;
}
table {
  width: 100%;
  min-width: 1260px;
  border-collapse: separate;
  border-spacing: 0;
}
.journal-table { min-width: 1060px; }
th, td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
th {
  background: #f8fafc;
  color: #57708f;
  font-size: 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
}
tbody tr {
  transition: background 0.12s ease;
}
tbody tr:hover {
  background: #fbfdff;
}
td a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}
td a:hover { text-decoration: underline; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
}
.badge-pending { color: var(--warn); background: var(--warn-soft); }
.badge-phone { color: var(--info); background: var(--info-soft); }
.badge-manual { color: #7c2d12; background: #ffedd5; }
.badge-merged { color: var(--ok); background: var(--ok-soft); }
.badge-dismissed { color: var(--muted); background: #f1f5f9; }
.lead-cell {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 210px;
}
.lead-title {
  line-height: 1.35;
}
.lead-meta,
.muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.lead-phones {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}
.lead-phone-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.lead-phone {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.lead-phone-note {
  color: var(--muted);
  font-size: 11px;
  border-bottom: 1px dotted var(--line);
  cursor: help;
}
.reason-cell {
  min-width: 250px;
  max-width: 380px;
  line-height: 1.45;
}
.text-cell {
  min-width: 320px;
  max-width: 460px;
  color: #334155;
  line-height: 1.45;
}
.text-preview {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}
.text-details {
  margin-top: 6px;
}
.text-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  list-style-position: inside;
}
.text-details div {
  margin-top: 8px;
  padding: 12px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  max-height: 340px;
  overflow: auto;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 300px;
}
.attempt-tag {
  display: inline-flex;
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
tr.is-previous-attempt {
  background: #fbfcfe;
}
tr.is-previous-attempt td {
  color: #526174;
}
.analysis-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: #f8fafc;
}
.analysis-card {
  display: grid;
  grid-template-columns: minmax(210px, 280px) minmax(230px, 320px) minmax(0, 1fr);
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.04);
}
.analysis-card:last-child { border-bottom: 1px solid var(--line); }
.analysis-card-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.analysis-card-title {
  color: var(--accent);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.3;
  text-decoration: none;
}
.analysis-card-title:hover { text-decoration: underline; }
.analysis-card-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.analysis-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.analysis-result {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
  color: #172033;
}
.analysis-reason {
  max-width: 720px;
  color: #334155;
  line-height: 1.45;
}
.analysis-text-preview {
  margin-top: 10px;
  max-width: 860px;
  color: #475569;
  font-size: 13px;
  line-height: 1.45;
}
.analysis-details,
.analysis-attempts {
  margin-top: 10px;
}
.analysis-details summary,
.analysis-attempts summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  list-style-position: inside;
}
.analysis-details-body {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  color: #334155;
  line-height: 1.35;
}
.attempt-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  max-width: 860px;
}
.attempt-row {
  display: grid;
  grid-template-columns: 120px 170px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-size: 13px;
  color: #475569;
}
.inline-kv {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.kv-pill {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #526174;
  font-size: 12px;
  font-weight: 700;
}
.empty-row td,
.loading-row td {
  color: var(--muted);
  padding-top: 18px;
  padding-bottom: 18px;
}
.empty-state,
.loading-state {
  padding: 18px 20px;
  color: var(--muted);
  font-size: 14px;
}
@media (max-width: 900px) {
  .filters form { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-head { flex-direction: column; align-items: flex-start; }
  .analysis-card { grid-template-columns: 1fr; }
  .attempt-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .page { padding: 18px 12px 28px; }
  .hero, .filters, .stats, .panel { border-radius: 14px; }
  .hero h1 { font-size: 24px; }
  .stats { grid-template-columns: 1fr; }
}
