:root {
  --navy: #253878;
  --aqua: #0eb9c1;
  --blue: #1853a5;
  --teal: #18b78d;
  --bg: #f4f7fb;
  --card: #ffffff;
  --border: #dde4ee;
  --text: #1c2333;
  --text-muted: #6b7690;
  --danger: #e0554f;
  --warning: #e2a53a;
}

* { box-sizing: border-box; }

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

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

/* ---------- layout ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: linear-gradient(180deg, var(--navy) 0%, #1a2a5e 100%);
  color: #fff;
  padding: 24px 0;
  flex-shrink: 0;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 16px;
}
.sidebar .brand img { height: 32px; }
.sidebar .brand span { font-size: 13px; opacity: 0.8; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255,255,255,0.82);
  padding: 11px 20px;
  font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.sidebar nav a.active {
  background: rgba(14,185,193,0.15);
  border-left-color: var(--aqua);
  color: #fff;
  font-weight: 600;
}

.sidebar .nav-group {
  padding: 18px 20px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.45);
  font-weight: 600;
}
.sidebar .nav-group:first-child { padding-top: 4px; }

.sidebar .dry-run-badge {
  margin: -6px 20px 14px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(226,165,58,0.16);
  border: 1px solid rgba(226,165,58,0.4);
  color: #f2d49a;
  font-size: 11px;
  line-height: 1.35;
}

.sidebar .user-box {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 13px;
}
.sidebar .user-box .role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--aqua);
  color: #06333a;
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
}

.main {
  flex: 1;
  padding: 28px 36px;
  max-width: 1200px;
}
.main.main-wide { max-width: none; padding-top: 14px; }

h1 { font-size: 22px; margin: 0 0 20px; color: var(--navy); }
h2 { font-size: 17px; color: var(--navy); }

/* ---------- cards / stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--navy); margin-top: 6px; }
.stat-card.danger .value { color: var(--danger); }
.stat-card.ok .value { color: var(--teal); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 20px;
}

/* ---------- table ---------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 9px 10px; color: var(--text-muted); font-weight: 600; border-bottom: 2px solid var(--border); font-size: 12px; text-transform: uppercase; }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: #fafcff; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 9px; font-size: 11px; font-weight: 600; }
.badge.done, .badge.ok, .badge.success, .badge.won, .badge.paid { background: #e3f7f0; color: var(--teal); }
.badge.failed, .badge.error, .badge.lose { background: #fcecea; color: var(--danger); }
.badge.queued, .badge.received, .badge.pending, .badge.in_progress, .badge.shipped { background: #fef4e2; color: var(--warning); }
.badge.skipped_todo, .badge.skipped_no_deal, .badge.done_partial { background: #eef0f5; color: var(--text-muted); }

/* ---------- buttons / forms ---------- */

.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--aqua);
  background: var(--aqua);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #0da3aa; text-decoration: none; }
.btn.secondary { background: #fff; color: var(--navy); border-color: var(--border); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn-round {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--aqua); background: var(--aqua); color: #fff;
  font-size: 18px; line-height: 1; cursor: pointer; flex-shrink: 0;
}
.btn-round:hover { background: #0da3aa; }
.btn.small { padding: 5px 12px; font-size: 12px; }

input[type=text], input[type=email], input[type=password] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
}

select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Форма в одну строку: поля равной ширины и одной высоты.
   Глобальный input задаёт margin-bottom, из-за него поля вставали выше select
   и кнопки — здесь margin снимается, а высота выравнивается явно. */
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form > input { flex: 1 1 190px; min-width: 0; }
.inline-form > select,
.inline-form > .btn { flex: 0 0 auto; }
.inline-form input,
.inline-form select,
.inline-form .btn {
  height: 40px;
  box-sizing: border-box;
  margin: 0;
}
.inline-form .btn { display: inline-flex; align-items: center; justify-content: center; }
.inline-form input[type=hidden] { display: none; }

.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.filter-bar > div:not(.filter-actions) { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.filter-bar label { font-size: 12px; color: var(--text-muted); }
.filter-bar input[type=date],
.filter-bar select {
  height: 38px;
  box-sizing: border-box;
  padding: 0 12px;
  font-size: 13px;
  width: 100%;
}
.filter-bar .filter-actions { display: flex; flex-direction: row; gap: 8px; justify-content: flex-end; margin-top: 4px; flex-wrap: wrap; }
.filter-bar .filter-actions .btn { height: 38px; box-sizing: border-box; padding: 0 18px; display: inline-flex; align-items: center; flex: 0 0 auto; width: auto; }

/* ---------- дашборд «Лиды» ---------- */

.period-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.period-nav .btn.secondary.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.period-nav .period-label { font-weight: 700; min-width: 190px; text-align: center; color: var(--navy); }
.period-divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.kpi-delta { font-size: 12px; font-weight: 700; margin-top: 4px; }
.kpi-delta.up { color: var(--teal); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.flat { color: var(--text-muted); }

.dash-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: stretch; }
.dash-2col > .card { display: flex; flex-direction: column; }
@media (max-width: 900px) { .dash-2col { grid-template-columns: 1fr; } }

.funnel-row { display: grid; grid-template-columns: 170px 1fr 90px 44px 44px; align-items: center; gap: 10px; margin-bottom: 8px; }
.funnel-row .funnel-track { background: #f4f6fa; border-radius: 6px; overflow: hidden; height: 22px; }
.funnel-row .funnel-fill { height: 100%; border-radius: 6px 0 0 6px; }
.funnel-row .funnel-fill.won { background: var(--teal); }
.funnel-row .funnel-fill.lose { background: var(--danger); }
.funnel-row .funnel-fill.in_progress { background: var(--warning); }

.leaderboard-row { display: grid; grid-template-columns: 26px 130px 1fr auto; align-items: center; gap: 10px; margin-bottom: 8px; }
.leaderboard-row .rank { font-weight: 700; color: var(--text-muted); }
.leaderboard-row .bar-track { background: #f4f6fa; border-radius: 6px; overflow: hidden; height: 20px; }
.leaderboard-row .bar-fill { height: 100%; background: var(--blue); border-radius: 6px 0 0 6px; }
.leaderboard-row .amount { font-size: 13px; font-weight: 600; white-space: nowrap; }

.clickable { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.clickable:hover { box-shadow: 0 2px 10px rgba(37,56,120,0.12); transform: translateY(-1px); }

.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(20,26,46,0.45);
  z-index: 1000; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card); border-radius: 12px; max-width: 900px; width: 100%;
  padding: 24px; max-height: 85vh; display: flex; flex-direction: column;
}
.modal-box h2 { margin: 0 0 4px; }
.modal-close { position: absolute; top: 16px; right: 20px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); }
.modal-filters { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.modal-filters select, .modal-filters input { height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; font-size: 13px; }
.modal-body { overflow-y: auto; }
.modal-summary { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; font-size: 13px; }
.kv b { color: var(--text-muted); font-weight: 600; }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #163a6b 60%, var(--blue) 100%);
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 36px 34px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(10,20,50,0.35);
}
.login-card { text-align: center; }
.login-card img.logo { height: 40px; margin: 0 auto 6px; display: block; }
.login-card .tagline { color: var(--text-muted); font-size: 12px; margin-bottom: 24px; }
.login-card form, .login-card .tabs, .login-card .btn, .login-card .vk-btn { text-align: left; }
.login-card .btn, .login-card .vk-btn { text-align: center; }

.tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg); border-radius: 8px; padding: 4px; }
.tabs a { flex: 1; text-align: center; padding: 8px 0; border-radius: 6px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.tabs a.active { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert.error { background: #fcecea; color: var(--danger); }
.alert.success { background: #e3f7f0; color: var(--teal); }

.vk-btn { display: flex; align-items: center; justify-content: center; gap: 8px; background: #0077ff; color: #fff; }
.vk-btn:hover { background: #0066dd; }

.notice { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ---------- дедупликация: конфликты ---------- */

/* Список конфликтов не должен растягивать страницу: заголовок и пояснение закреплены,
   прокручивается только сам список — примерно пять карточек в видимой области. */
.conflicts-card { display: flex; flex-direction: column; max-height: 640px; }
.conflicts-head { flex-shrink: 0; }
.conflicts-head h2 { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 0; }
.conflicts-head h2 .badge { font-weight: 600; }
.conflicts-scroll { overflow-y: auto; margin-top: 12px; padding-right: 6px; }

.conflict {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--card);
}
.conflict:last-child { margin-bottom: 2px; }
.conflict.is-resolved { opacity: 0.55; background: #fbfcfe; }
.conflict.is-resolved:hover { opacity: 0.85; }

.conflict-top { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 12px; }
.conflict-top .conflict-type { font-weight: 600; color: var(--navy); }
.conflict-top .conflict-ts { color: var(--text-muted); }
.conflict-top .conflict-reason { color: var(--text-muted); flex: 1 1 200px; min-width: 0; }
.conflict-top .conflict-actions { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }

.conflict-sides {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
@media (max-width: 700px) { .conflict-sides { grid-template-columns: 1fr; } }

.conflict-side {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fafcff;
  min-width: 0;
}
.conflict-side-head { display: flex; align-items: baseline; gap: 6px; font-size: 13px; margin-bottom: 6px; }
.conflict-side-head .side-label {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.conflict-id { color: var(--text-muted); font-size: 12px; }

.conflict-kv { display: grid; grid-template-columns: 118px 1fr; gap: 4px 8px; font-size: 12px; line-height: 1.5; }
.conflict-kv > span { color: var(--text-muted); }
.conflict-kv > b { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
/* отличие между сторонами — главное, ради чего сюда смотрят */
.conflict-kv > b.is-diff {
  background: #fef4e2;
  color: #a9741d;
  border-radius: 5px;
  padding: 0 5px;
  box-shadow: inset 0 0 0 1px rgba(226,165,58,0.45);
}
.conflict-sub { color: var(--text-muted); font-weight: 400; }

.conflict-cache-note { margin-top: 8px; font-size: 11px; color: var(--text-muted); font-style: italic; }
