:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #17202e;
  --muted: #6b7788;
  --line: #e2e8f0;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --primary-soft: #d9f3ef;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --shadow: 0 10px 30px rgba(20, 35, 55, .07);
  --radius: 16px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d141d;
    --surface: #151e2a;
    --surface-2: #1b2633;
    --ink: #e8eef7;
    --muted: #96a3b5;
    --line: #2a3645;
    --primary: #2dd4bf;
    --primary-strong: #5eead4;
    --primary-soft: #123a37;
    --danger: #f87171;
    --danger-soft: #3b1d21;
    --warn: #fbbf24;
    --warn-soft: #3b2f12;
    --ok: #4ade80;
    --ok-soft: #14331f;
    --shadow: 0 10px 30px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.1; margin-bottom: 8px; letter-spacing: -.02em; }
h2 { font-size: 19px; margin-bottom: 0; letter-spacing: -.01em; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.eyebrow { margin: 0 0 6px; color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 10px clamp(14px, 3vw, 32px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 800; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #22c55e); color: #fff; font-size: 18px;
  box-shadow: 0 6px 16px rgba(15, 118, 110, .25);
}
.brand-text span { color: var(--primary); }
.main-nav { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  color: var(--muted); padding: 7px 11px; border-radius: 9px; font-weight: 600; white-space: nowrap;
}
.main-nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.main-nav a.active { background: var(--primary-soft); color: var(--primary-strong); }
.userbox { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.user-name { font-weight: 600; font-size: 13px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.role-badge {
  font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  padding: 4px 7px; border-radius: 20px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.role-badge.dev { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.role-badge.client { background: var(--primary-soft); color: var(--primary-strong); border-color: transparent; }

.content { width: min(1240px, 100%); margin: 0 auto; padding: clamp(18px, 3vw, 34px) clamp(14px, 3vw, 32px) 48px; flex: 1; }
.footer {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  width: min(1240px, 100%); margin: 0 auto; padding: 18px clamp(14px, 3vw, 32px) 24px;
  color: var(--muted); font-size: 12px;
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin-bottom: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }


/* ---------- кнопки, формы, сообщения ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 650;
  cursor: pointer; white-space: nowrap; transition: .15s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary-strong); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(15, 118, 110, .18); }
.btn-primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); color: #fff; }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); background: var(--danger-soft); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 9px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.inline-form { display: inline-flex; margin: 0; }
.form-stack, .stack-form { display: flex; flex-direction: column; gap: 14px; }
.form-row, .settings-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 650; }
.field > span { color: var(--muted); }
.field input, .field select, .field textarea, .filter-bar input, .filter-bar select, .dict-add input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 400; outline: none;
}
.field textarea { resize: vertical; min-height: 90px; }
.field input:focus, .field select:focus, .field textarea:focus, .filter-bar input:focus, .filter-bar select:focus, .dict-add input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.field.compact { min-width: 170px; }
.field.grow { flex: 1; }
.field small { font-weight: 400; color: var(--muted); }
.check-field { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; padding-bottom: 10px; }
.check-field input { width: 18px; height: 18px; accent-color: var(--primary); }
.filter-bar {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 14px; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.flash { margin-bottom: 16px; padding: 12px 15px; border-radius: var(--radius-sm); font-weight: 600; border: 1px solid transparent; }
.flash.success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.small-flash { margin-top: 12px; font-size: 12.5px; }
.empty { padding: 26px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: var(--radius-sm); }
.empty.large { padding: 52px 24px; margin-top: 18px; background: var(--surface); border: 1px dashed var(--line); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.empty p { margin-bottom: 0; }
.divider { display: flex; align-items: center; gap: 12px; margin: 22px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }


/* ---------- панели, таблицы, бейджи ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(15px, 2.4vw, 22px); box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head a { font-size: 13px; font-weight: 600; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric-card {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 17px 18px; box-shadow: var(--shadow);
}
.metric-card.accent { background: linear-gradient(135deg, var(--primary), #0d9488); border: 0; color: #fff; }
.metric-card.accent .metric-label, .metric-card.accent .metric-note { color: rgba(255,255,255,.8); }
.metric-label { color: var(--muted); font-size: 12.5px; font-weight: 650; }
.metric-value { font-size: 32px; line-height: 1.15; letter-spacing: -.03em; }
.metric-note { color: var(--muted); font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; margin-bottom: 18px; align-items: start; }
.two-col.wide-right { grid-template-columns: 1.35fr .65fr; }
.two-col.wide-left { grid-template-columns: 1.4fr .6fr; }
.side-stack { display: flex; flex-direction: column; gap: 18px; }
.chart { display: flex; align-items: flex-end; gap: clamp(5px, 2vw, 14px); height: 190px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; }
.chart-value { font-size: 12px; font-weight: 700; color: var(--muted); }
.chart-track { width: 100%; flex: 1; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.chart-bar { width: 100%; min-height: 3px; border-radius: 8px 8px 0 0; background: linear-gradient(180deg, #2dd4bf, var(--primary)); }
.chart-label { font-size: 11px; color: var(--muted); }
.status-list { display: flex; flex-direction: column; gap: 8px; }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 10px; border-radius: 9px; background: var(--surface-2); color: var(--ink); }
.status-row:hover { text-decoration: none; background: var(--primary-soft); }
.status-row strong { font-size: 17px; }
.mini-title { margin: 18px 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip { padding: 5px 9px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.active, .badge.in_work { background: var(--ok-soft); color: var(--ok); }
.badge.paused, .badge.pending, .badge.new, .badge.contact { background: var(--warn-soft); color: var(--warn); }
.badge.error, .badge.spam, .badge.irrelevant { background: var(--danger-soft); color: var(--danger); }
.badge.joined, .badge.left { background: var(--primary-soft); color: var(--primary-strong); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table th { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.table-title { font-weight: 700; color: var(--ink); }
.row-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

/* ---------- заявки ---------- */
.lead-list { display: flex; flex-direction: column; gap: 12px; }
.lead-card {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.lead-topline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.score { margin-left: auto; font-size: 11.5px; font-weight: 700; color: var(--muted); background: var(--surface-2); border-radius: 20px; padding: 3px 8px; }
.lead-text { margin: 10px 0; font-size: 15.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.lead-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 12.5px; }
.lead-side { display: flex; flex-direction: column; gap: 12px; align-items: flex-end; justify-content: space-between; min-width: 190px; }
.lead-links, .lead-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.action-take { color: var(--ok); }
.action-irrelevant { color: var(--warn); }
.action-spam { color: var(--danger); }
.lead-mini-list { display: flex; flex-direction: column; gap: 10px; }
.lead-mini { padding: 11px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.lead-mini-top, .lead-mini-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.lead-mini p { margin: 7px 0; font-size: 13.5px; }
.lead-mini-meta { color: var(--muted); font-size: 12px; }
.rank-list { margin: 0; padding: 0; list-style: none; counter-reset: rank; display: flex; flex-direction: column; gap: 8px; }
.rank-list li { counter-increment: rank; display: flex; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 9px; background: var(--surface-2); font-size: 13.5px; }
.rank-list li::before { content: counter(rank); color: var(--muted); font-weight: 700; margin-right: 4px; }
.rank-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-links { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.quick-links a { padding: 10px 12px; border-radius: 9px; background: var(--surface-2); color: var(--ink); font-weight: 600; }
.quick-links a:hover { background: var(--primary-soft); color: var(--primary-strong); text-decoration: none; }

/* ---------- карточка чата ---------- */
.detail-list { display: flex; flex-direction: column; gap: 0; margin: 0 0 16px; }
.detail-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 12.5px; }
.detail-list dd { margin: 0; text-align: right; font-weight: 600; font-size: 13px; }
.stacked-actions { display: flex; flex-direction: column; gap: 9px; }
.stacked-actions .inline-form { display: block; }

/* ---------- фильтр ---------- */
.profile-panel { margin-bottom: 18px; }
.profile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.threshold-pill { padding: 7px 12px; border-radius: 20px; background: var(--primary-soft); color: var(--primary-strong); font-size: 13px; white-space: nowrap; }
.settings-row { padding: 13px; background: var(--surface-2); border-radius: var(--radius-sm); margin-bottom: 16px; }
.dict-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.dict-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.dict-card summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; cursor: pointer; font-weight: 700; list-style: none; }
.dict-card summary::-webkit-details-marker { display: none; }
.dict-card summary::after { content: "+"; color: var(--muted); font-weight: 400; }
.dict-card[open] summary::after { content: "−"; }
.count-pill { margin-left: auto; padding: 2px 8px; border-radius: 20px; background: var(--surface-2); color: var(--muted); font-size: 11.5px; }
.dict-body { padding: 0 12px 13px; border-top: 1px solid var(--line); }
.dict-add { display: flex; gap: 7px; margin: 11px 0; }
.dict-add input { flex: 1; min-width: 0; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 230px; overflow: auto; }
.word-chip { display: inline-flex; align-items: center; gap: 2px; padding: 4px 5px 4px 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 20px; font-size: 12px; }
.chip-remove { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 3px; }
.chip-remove:hover { color: var(--danger); }

/* ---------- получатели ---------- */
.recipient-list { display: flex; flex-direction: column; }
.recipient-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.recipient-row:last-child { border-bottom: 0; }
.recipient-row > div:first-child { flex: 1; min-width: 0; }
.recipient-row .row-actions { flex-wrap: wrap; }
.note-panel h2 { margin-bottom: 8px; }

/* ---------- пагинация ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 18px 0 0; }
.page-info { color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col, .two-col.wide-right, .two-col.wide-left { grid-template-columns: 1fr; }
  .dict-grid { grid-template-columns: 1fr; }
  .lead-card { grid-template-columns: 1fr; }
  .lead-side { align-items: stretch; }
  .lead-actions, .lead-links { justify-content: flex-start; }
  .user-name { display: none; }
}

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding-top: 8px; padding-bottom: 8px; }
  .main-nav { order: 3; width: 100%; flex-basis: 100%; }
  .userbox { margin-left: auto; }
  .content { padding-top: 18px; }
  .chart { height: 150px; }
  .settings-row { align-items: stretch; }
  .settings-row .field.compact { flex: 1; }
  .filter-bar .btn { flex: 1; }
  .lead-card { padding: 14px; }
  .page-head { align-items: flex-start; }
}

/* ---------- вход ---------- */
.login-body {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 14px;
  background:
    radial-gradient(circle at 15% 15%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 45%),
    radial-gradient(circle at 85% 80%, color-mix(in srgb, #22c55e 14%, transparent), transparent 40%),
    var(--bg);
}
.login-card {
  width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; padding: clamp(22px, 5vw, 34px); box-shadow: 0 24px 70px rgba(15, 23, 42, .16);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .brand-mark { width: 46px; height: 46px; font-size: 24px; border-radius: 14px; }
.login-brand h1 { font-size: 24px; margin-bottom: 2px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 12.5px; }
.telegram-zone { margin-bottom: 4px; }
.telegram-zone p { margin: 8px 0 0; }
.login-hint { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.login-hint strong { font-size: 12.5px; }
.login-hint p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.btn-block + .muted { margin-top: 10px; }

/* ---------- завершение заявки ---------- */
:root {
  --done: #166534;
  --done-ink: #ffffff;
  --done-soft: #dcfce7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --done: #4ade80;
    --done-ink: #062b18;
    --done-soft: #14331f;
  }
}

.badge.done {
  background: var(--done);
  color: var(--done-ink);
  border-color: transparent;
}

/* «Выполнена» — заливка, а «В работе» остаётся обычной контурной кнопкой. */
.btn-done,
.action-done {
  background: var(--done);
  border-color: var(--done);
  color: var(--done-ink);
}

.btn-done:hover,
.action-done:hover {
  background: color-mix(in srgb, var(--done) 88%, #000);
  border-color: color-mix(in srgb, var(--done) 88%, #000);
  color: var(--done-ink);
}

/* ---------- модальное подтверждение ---------- */
.confirm-modal {
  width: min(430px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(15, 23, 42, .28);
}

.confirm-modal::backdrop {
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(3px);
}

.confirm-card { padding: clamp(18px, 4vw, 24px); }

.confirm-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 22px;
  font-weight: 800;
}

.confirm-modal[data-tone="success"] .confirm-icon {
  background: var(--done-soft);
  color: var(--done);
}

.confirm-modal h2 { margin-bottom: 7px; }
.confirm-modal p { margin: 0; }

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.confirm-actions .btn { min-width: 112px; }

@media (max-width: 480px) {
  .confirm-actions { flex-direction: column-reverse; }
  .confirm-actions .btn { width: 100%; }
}


