/* NIKEI CRM — тёмная тема, тот же визуальный язык, что у магазина nikei.io */

:root {
  --bg: #111914;
  --panel: #1a251e;
  --panel-2: #223026;
  --border: #3f5144;
  --accent: #d4edac;
  --accent-dim: rgba(212, 237, 172, 0.12);
  --text: #f3f3ee;
  --muted: #b6c2b4;
  --green: #d4edac;
  --blue: #9fca9f;
  --red: #ff6b6b;
  --yellow: #ffd166;

  --r-sm: 10px;
  --r-md: 12px;
  --r-lg: 14px;

  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Табличные цифры — везде, где есть суммы */
.num, td.num, .kpi-value, .money, table { font-variant-numeric: tabular-nums; }

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

h1, h2, h3 { margin: 0 0 12px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.green { color: var(--green); }
.red { color: var(--red); }
.blue { color: var(--blue); }
.accent { color: var(--accent); }
.hidden { display: none !important; }
.grow { flex: 1; }

/* ─── Логин ──────────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(212, 237, 172, 0.12), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px;
  box-shadow: var(--shadow);
}

.logo {
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.logo span { color: var(--accent); }

/* ─── Каркас приложения ──────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  background: rgba(18, 22, 31, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar .logo { font-size: 20px; margin: 0; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; }

.nav a {
  padding: 7px 13px;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 14px;
  font-weight: 550;
  border: 1px solid transparent;
}
.nav a:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }
.nav a.active { color: var(--accent); background: var(--accent-dim); border-color: rgba(212, 237, 172, 0.32); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.user-chip b { color: var(--text); font-weight: 600; }

.role-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--border);
}
.role-ADMIN { color: var(--accent); border-color: rgba(212, 237, 172, 0.4); background: var(--accent-dim); }
.role-SALE { color: var(--blue); border-color: rgba(159, 202, 159, 0.35); background: rgba(159, 202, 159, 0.10); }

main { padding: 22px 20px 60px; max-width: 1500px; margin: 0 auto; }

.view-head {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

/* ─── Элементы форм ──────────────────────────────────────────────────────── */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 78px; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; min-width: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, border-color 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #16110b; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); border-color: rgba(255, 107, 107, 0.35); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.alert {
  padding: 10px 13px;
  border-radius: var(--r-sm);
  font-size: 14px;
  margin-bottom: 14px;
  border: 1px solid;
}
.alert-error { color: var(--red); border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.09); }
.alert-ok { color: var(--green); border-color: rgba(61, 220, 151, 0.35); background: rgba(61, 220, 151, 0.09); }

/* ─── Панели, таблицы ────────────────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}
.panel + .panel { margin-top: 18px; }

.table-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }

.thumb {
  width: 42px;
  height: 42px;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.thumb-ph {
  display: grid;
  place-items: center;
  font-size: 16px;
  color: var(--muted);
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* ─── Канбан ─────────────────────────────────────────────────────────────── */

.kanban {
  display: grid;
  grid-template-columns: repeat(4, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}
@media (max-width: 1100px) { .kanban { grid-template-columns: repeat(2, minmax(260px, 1fr)); } }
@media (max-width: 640px) { .kanban { grid-template-columns: 1fr; } }

.col {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px;
  min-height: 160px;
  transition: border-color 0.15s, background 0.15s;
}
.col.drag-over { border-color: var(--accent); background: var(--accent-dim); }

.col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.col-title { font-weight: 650; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-NEW { background: var(--blue); }
.dot-IN_PROGRESS { background: var(--yellow); }
.dot-WON { background: var(--green); }
.dot-ARCHIVED { background: var(--muted); }
.col-count { font-size: 12px; color: var(--muted); }
.col-sum { font-size: 12px; color: var(--muted); }

.card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 11px 12px;
  margin-bottom: 9px;
  cursor: grab;
  transition: border-color 0.15s, transform 0.1s;
}
.card:hover { border-color: var(--accent); }
.card:active { cursor: grabbing; }
.card.dragging { opacity: 0.45; transform: rotate(-1deg); }

.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-num { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-name { font-weight: 600; margin: 3px 0 6px; font-size: 14px; }
.card-sum { font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.card-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 7px; }
.card-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }

.src {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.src-SITE_CALC, .src-SITE_FORM { color: var(--blue); border-color: rgba(159, 202, 159, 0.3); }
.src-REFERRAL { color: var(--green); border-color: rgba(61, 220, 151, 0.3); }

/* ─── Модальное окно ─────────────────────────────────────────────────────── */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.72);
  display: grid;
  place-items: start center;
  padding: 32px 16px;
  overflow-y: auto;
  z-index: 100;
}

.modal {
  width: 100%;
  max-width: 880px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.modal-sm { max-width: 480px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body { padding: 20px; }
.modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.x:hover { color: var(--text); }

.block { margin-bottom: 22px; }
.block-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 650;
  margin-bottom: 9px;
}

.status-switch { display: flex; gap: 6px; flex-wrap: wrap; }
.status-switch .btn.on { background: var(--accent); border-color: var(--accent); color: #16110b; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { padding: 9px 0 9px 15px; border-left: 2px solid var(--border); position: relative; }
.feed li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 15px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.feed li.t-STATUS_CHANGED::before { background: var(--accent); }
.feed li.t-CALL::before { background: var(--blue); }
.feed li.t-CREATED::before { background: var(--green); }

.tasklist { list-style: none; margin: 0; padding: 0; }
.tasklist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.tasklist li:last-child { border-bottom: none; }
.tasklist .done { text-decoration: line-through; color: var(--muted); }
.overdue { color: var(--red); }

/* ─── Дашборд ────────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 15px 16px;
}
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 25px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

.chart-svg { width: 100%; height: auto; display: block; }

.bars { display: grid; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 130px; gap: 12px; align-items: center; font-size: 13px; }
@media (max-width: 720px) { .bar-row { grid-template-columns: 110px 1fr; } .bar-row .bar-val { grid-column: 2; text-align: right; } }
.bar-track { height: 9px; background: var(--panel-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }

/* ─── Воронка продаж ─────────────────────────────────────────────────────── */

.funnel { display: flex; flex-direction: column; gap: 0; }

.fn-stage { padding: 2px 0; }

.fn-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.fn-title { font-weight: 600; font-size: 14px; }
.fn-count { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }

.fn-track {
  height: 30px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.fn-fill {
  height: 100%;
  background: linear-gradient(90deg, #527658, var(--accent));
  border-radius: var(--r-sm) 0 0 var(--r-sm);
  min-width: 3px;
  transition: width 0.35s ease;
}
/* Последний этап — продажа: подсвечиваем зелёным, это цель воронки */
.fn-stage:last-of-type .fn-fill { background: linear-gradient(90deg, var(--green), #7ceac0); }

.fn-sub { font-size: 12px; color: var(--muted); margin-top: 5px; }

.fn-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 0 7px 14px;
  margin: 4px 0 4px 12px;
  border-left: 2px dashed var(--border);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.fn-conv { color: var(--green); font-weight: 650; }
.fn-drop { color: var(--red); font-weight: 650; }
.fn-drop-abs { color: var(--muted); }

.note {
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(159, 202, 159, 0.28);
  background: rgba(159, 202, 159, 0.08);
  color: var(--blue);
  font-size: 13px;
  margin-bottom: 14px;
}

.presets { display: flex; gap: 5px; }
.presets .btn.on { background: var(--accent-dim); border-color: rgba(212, 237, 172, 0.35); color: var(--accent); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs .btn.on { background: var(--accent-dim); border-color: rgba(212, 237, 172, 0.3); color: var(--accent); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .f { min-width: 150px; }
.filters .f label { margin-bottom: 4px; }

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px;
  max-width: 380px;
}
.toast.err { border-color: rgba(255, 107, 107, 0.45); color: var(--red); }
.toast.ok { border-color: rgba(61, 220, 151, 0.45); color: var(--green); }

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