/* ─── Базовая палитра ────────────────────────────────────────── */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e1e4e8;
  --text: #1a1a1a;
  --muted: #6a737d;
  --primary: #2354c7;
  --primary-h: #1c47ad;
  --danger: #c0392b;
  --warn: #d97706;
  --ok: #16a34a;
  --gray: #9ca3af;
  --blue: #3b82f6;
  --green: #16a34a;
  --orange: #f59e0b;
  --red: #dc2626;
  --purple: #7c3aed;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code { background: #eef0f3; padding: 1px 5px; border-radius: 3px; font-size: 12.5px; }

/* ─── Шапка ─────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 32px;
}

.brand a {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}

.topnav { display: flex; gap: 18px; }
.topnav a { color: var(--text); }
.topnav a:hover { color: var(--primary); text-decoration: none; }

/* ─── Контейнер ─────────────────────────────────────────────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
}

h1 { margin: 0 0 16px; font-size: 24px; font-weight: 600; }
h2 { margin: 0 0 12px; font-size: 17px; font-weight: 600; }
h3 { margin: 12px 0 8px; font-size: 14px; }
h3.sub { color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; font-size: 11px; }

.muted { color: var(--muted); }

/* ─── Карточки и сетки ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 16px;
}

@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ─── Формы ─────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 500; font-size: 13px; }
.field small { color: var(--muted); font-size: 12px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

input[type=text], input[type=email], input[type=url], input[type=file], select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  background: white;
  font-family: inherit;
}

input:focus, select:focus { outline: none; border-color: var(--primary); }

.req { color: var(--danger); }

.form-actions { display: flex; gap: 8px; }

/* ─── Кнопки ────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 5px;
  border: 1px solid transparent;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f0f2f5; text-decoration: none; }
.btn-danger { background: white; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }

/* ─── Flash-сообщения ───────────────────────────────────────── */
.flashes { margin-bottom: 16px; }
.flash {
  padding: 10px 14px;
  border-radius: 5px;
  margin-bottom: 6px;
  font-size: 13px;
}
.flash-success { background: #e7f5ec; color: #105a2c; border: 1px solid #b6e0c3; }
.flash-error   { background: #fdebea; color: #7d1c14; border: 1px solid #f4b5b0; }

/* ─── Статистика ────────────────────────────────────────────── */
.stats { display: flex; gap: 24px; margin-top: 8px; }
.stat-num { font-size: 26px; font-weight: 700; }
.stat-lbl { color: var(--muted); font-size: 12px; }

.status-list { list-style: none; padding: 0; margin: 0; }
.status-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
.status-list li:last-child { border-bottom: none; }

/* ─── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  margin-right: 4px;
}
.badge-gray   { background: #e5e7eb; color: #374151; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-orange { background: #fed7aa; color: #9a3412; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ─── Таблицы ───────────────────────────────────────────────── */
.table-compact, .rows {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table-compact th, .table-compact td,
.rows th, .rows td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.rows thead th {
  background: #f9fafb;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--muted);
}

.rows .cell {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-url { max-width: 180px; font-family: monospace; font-size: 12px; }
.cell-url a {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
.cell-url a:hover { text-decoration: underline; }
.cell-domain a {
  text-decoration: none;
  color: var(--primary);
}
.cell-domain a:hover { text-decoration: underline; }

/* Полное название организации — переносится на 2-3 строки */
.rows .cell-org {
  max-width: 280px;
  min-width: 220px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
  line-height: 1.35;
  font-size: 12.5px;
}

/* Адрес — переносится по словам, шире чем дефолтная ячейка */
.rows .cell-addr {
  max-width: 380px;
  min-width: 280px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  /* word-break: break-word резал в любом месте — теперь только по пробелам */
  word-break: normal;
  overflow-wrap: break-word;
  line-height: 1.35;
  font-size: 12.5px;
}

/* Растягиваем таблицу превью на всю ширину экрана */
#rows-table {
  table-layout: auto;
}
#rows-table th, #rows-table td {
  vertical-align: top;
}

.row-ok    { background: white; }
.row-warn  { background: #fffbeb; }
.row-err   { background: #fef2f2; }
.row-issues td { padding: 4px 10px; background: #fafbfc; }

.dot { font-size: 14px; }
.dot-ok   { color: var(--ok); }
.dot-warn { color: var(--warn); }
.dot-err  { color: var(--danger); }

.btn-edit {
  background: transparent;
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.btn-edit:hover { background: #f0f2f5; }

/* ─── Превью: верхняя панель ────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}

.counts {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.cnt {
  background: white;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 12px;
  font-size: 13px;
}
.cnt-ok   { border-left: 4px solid var(--ok); }
.cnt-warn { border-left: 4px solid var(--warn); }
.cnt-err  { border-left: 4px solid var(--danger); }

.generate-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.cbx { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* ─── Модалка ───────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-content {
  background: white;
  padding: 24px;
  border-radius: 8px;
  width: 540px;
  max-width: 95%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ─── Фильтры ───────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  background: white;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.filters input[type=text] { flex: 1; min-width: 220px; }

.warn { color: var(--warn); }

.batch-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: #fffbe6;
  border: 1px solid #f5e1a4;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}

.progress-bar {
  background: #e5e7eb;
  border-radius: 8px;
  height: 12px;
  overflow: hidden;
  margin-bottom: 4px;
}
.progress-fill {
  background: linear-gradient(90deg, var(--primary), #5b8fdd);
  height: 100%;
  transition: width 0.4s ease;
  border-radius: 8px;
}

.btn-blacklist {
  background: transparent;
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.btn-blacklist:hover {
  background: #fee2e2;
  border-color: var(--red);
}

/* Inline-редактируемые ячейки (email) */
.cell-inline {
  cursor: text;
  position: relative;
}
.cell-inline:hover {
  background: #fffae6;
  outline: 1px dashed #d4a017;
  outline-offset: -1px;
}
.cell-inline:empty::before,
.cell-inline:has(input) {
  background: transparent;
}
.inline-input {
  width: 100%;
  padding: 4px 6px;
  border: 2px solid var(--primary);
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: white;
}
/* Подсказка-плейсхолдер «✎ введите email» делаем серым */
.cell-inline {
  color: inherit;
}
.cell-inline:not(:has(input)) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Бейджи в навигации ─────────────────────────────────────── */
.nav-badge {
  display: inline-block;
  padding: 0 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: top;
  margin-left: 4px;
}
.nav-badge-red { background: var(--red); color: white; }

/* ─── Алерты ────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 13px;
}
.alert-red    { background: #fee2e2; border-left: 4px solid var(--red);    color: #7d1c14; }
.alert-orange { background: #fef3c7; border-left: 4px solid var(--orange); color: #78350f; }
.alert-blue   { background: #dbeafe; border-left: 4px solid var(--blue);   color: #1e3a8a; }

/* ─── Дубликаты ─────────────────────────────────────────────── */
.row-dup  { background: #f5f3ff; }
.dot-dup  { color: var(--purple); }
.cnt-dup  { border-left: 4px solid var(--purple); }

.actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.btn-dadata, .btn-scrape {
  background: transparent;
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.btn-dadata:hover, .btn-scrape:hover { background: #f0f2f5; }

/* ─── Воронка ───────────────────────────────────────────────── */
.funnel { display: flex; flex-direction: column; gap: 8px; max-width: 700px; }
.funnel-stage { width: 100%; }
.funnel-bar {
  height: 36px;
  width: var(--w, 100%);
  min-width: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  color: white;
  border-radius: 4px;
  transition: width 0.3s;
  font-size: 13px;
}
.funnel-gray   { background: var(--gray); }
.funnel-blue   { background: var(--blue); }
.funnel-green  { background: var(--green); }
.funnel-orange { background: var(--orange); }
.funnel-red    { background: var(--red); }
.funnel-purple { background: var(--purple); }
.funnel-label  { font-weight: 500; }
.funnel-value  { font-weight: 700; }

/* ─── Карточка одной претензии ──────────────────────────────── */
.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  width: 140px;
  padding: 6px 8px;
  vertical-align: top;
}
.kv td { padding: 6px 8px; word-break: break-word; }

.files { list-style: none; padding: 0; margin: 0; }
.files li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.files li:last-child { border-bottom: none; }

.cases { padding-left: 18px; margin: 0; }
.cases li { padding: 3px 0; font-size: 13px; }

.inbox { list-style: none; padding: 0; margin: 0; }
.inbox li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.inbox li:last-child { border-bottom: none; }

textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
