:root {
  --bg: #0e1015;
  --panel: #161922;
  --panel-2: #1c202b;
  --input-bg: #11141c;
  --border: #262b38;
  --text: #e7eaf1;
  --muted: #8b93a7;
  --accent: #4f7cff;
  --green: #2fbf71;
  --red: #f2545b;
  --amber: #f5a524;
  --violet: #a06bff;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --input-bg: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
[hidden] { display: none !important; }

/* ---------- элементы ---------- */

button, .btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:hover, .btn:hover { background: color-mix(in srgb, var(--panel-2) 90%, var(--text)); }
button:disabled { opacity: .5; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 80%, white); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 10px; font-size: 13px; }
.btn--danger { color: var(--red); }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(79, 124, 255, .45); outline-offset: -1px; }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row--wrap { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grid { display: grid; gap: 14px; }

/* ---------- вход ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(900px 500px at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%);
}
.login__box { width: 100%; max-width: 360px; }
.login__logo { font-size: 22px; font-weight: 700; margin-bottom: 4px; }

/* ---------- каркас ---------- */

.layout { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand { font-weight: 700; font-size: 16px; padding: 0 10px 16px; display: flex; align-items: center; gap: 8px; }
.sidebar__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.sidebar a.nav-link {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.sidebar a.nav-link:hover { background: var(--panel-2); color: var(--text); }
.sidebar a.nav-link.active { background: var(--panel-2); color: var(--text); }
.sidebar__spacer { flex: 1; }
.sidebar__user { border-top: 1px solid var(--border); padding-top: 12px; font-size: 13px; }
.badge-count {
  background: var(--accent); color: #fff; border-radius: 20px;
  padding: 1px 7px; font-size: 11px; font-weight: 600;
}
.badge-count--warn { background: var(--red); }

.content { padding: 22px 26px 60px; max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- фильтры и таблица ---------- */

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 130px; }
.filters input[type="search"] { min-width: 220px; }

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--panel-2); }
.table .nowrap { white-space: nowrap; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 500;
  border: 1px solid transparent; white-space: nowrap;
}
.pill--new { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.pill--in_work { background: color-mix(in srgb, var(--amber) 15%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.pill--callback { background: color-mix(in srgb, var(--violet) 15%, transparent); color: var(--violet); border-color: color-mix(in srgb, var(--violet) 30%, transparent); }
.pill--won { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, transparent); }
.pill--lost { background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--muted); border-color: color-mix(in srgb, var(--muted) 30%, transparent); }
.pill--overdue { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.pill--dupe { background: color-mix(in srgb, var(--amber) 12%, transparent); color: var(--amber); }

/* оценка ИИ: балл 8–10 — зелёный «горячий», 5–7 — жёлтый, 1–4 — серый */
.pill--ai-hot { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); border-color: color-mix(in srgb, var(--green) 30%, transparent); }
.pill--ai-warm { background: color-mix(in srgb, var(--amber) 15%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.pill--ai-cold { background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--muted); border-color: color-mix(in srgb, var(--muted) 30%, transparent); }
.pill--ai-tag { background: color-mix(in srgb, var(--violet) 12%, transparent); color: var(--violet); border-color: color-mix(in srgb, var(--violet) 25%, transparent); font-size: 11px; }
.pill--ai-tag--warn { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); border-color: color-mix(in srgb, var(--red) 25%, transparent); }
.pill--ai-tag--hot { background: color-mix(in srgb, var(--amber) 12%, transparent); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 25%, transparent); }

/* ---------- доска ---------- */

.board { display: grid; grid-template-columns: repeat(5, minmax(210px, 1fr)); gap: 12px; align-items: start; }
.board__col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.board__col.drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.board__head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 10px; padding: 0 2px; }
.board__card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; margin-bottom: 8px; cursor: grab; font-size: 13px;
}
.board__card:hover { border-color: var(--accent); }
.board__card b { display: block; margin-bottom: 2px; }

/* ---------- карточка заявки ---------- */

.lead-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 9px 0 9px 16px; border-left: 2px solid var(--border); position: relative; font-size: 13px; }
.timeline li::before {
  content: ''; position: absolute; left: -5px; top: 15px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--border);
}
.timeline li.comment::before { background: var(--accent); }
.timeline li.ai::before { background: var(--violet); }
.timeline .when { color: var(--muted); font-size: 12px; }

/* ---------- аналитика ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat__value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.stat__label { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bar { height: 6px; border-radius: 4px; background: var(--accent); min-width: 2px; }

/* ---------- код подключения ---------- */

pre.snippet {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px;
  color: var(--text); margin: 8px 0;
}
pre.snippet .tag { color: var(--accent); }
pre.snippet .str { color: var(--green); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 18px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--red); }

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

/* Переписка из мессенджеров: клиент слева, наши ответы справа */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.chat__msg {
  max-width: 78%; padding: 8px 12px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--border); word-break: break-word;
}
.chat__msg--in { align-self: flex-start; border-bottom-left-radius: 4px; }
.chat__msg--out {
  align-self: flex-end; border-bottom-right-radius: 4px;
  background: color-mix(in srgb, var(--accent) 16%, var(--panel-2));
}
.chat__msg .when { color: var(--muted); font-size: 11px; margin-top: 4px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar__brand { padding-bottom: 0; }
  .sidebar__spacer { display: none; }
  .sidebar__user { border: 0; padding: 0; }
  .lead-grid, .board { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}
