:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #64748b;
  --brand: #1f4e78;
  --brand-2: #2f6ba0;
  --line: #e2e8f0;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--brand); }

/* ---------- вход ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f2c46, #1f4e78);
  padding: 16px;
}
.login-card {
  background: #fff; padding: 32px; border-radius: 14px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { margin: 0; color: var(--brand); font-size: 26px; }
.login-card .sub { margin: 4px 0 20px; color: var(--muted); }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.login-card input {
  width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 15px;
}
.login-card input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(31,78,120,.12); }
.error { color: var(--bad); margin-top: 12px; min-height: 18px; font-size: 13px; }

/* ---------- обёртка приложения ---------- */
.app header {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 10px 18px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; color: var(--brand); }
.tag { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 6px; }
nav { display: flex; gap: 4px; flex: 1; }
nav button {
  border: none; background: none; padding: 8px 12px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 500;
}
nav button.active { background: #eaf1f8; color: var(--brand); }
.userbox { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.userbox .who { font-weight: 600; color: var(--ink); }

main { padding: 18px; max-width: 1280px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* ---------- общие элементы ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: #f6f8fa; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-danger { color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { border: none; background: none; color: var(--muted); }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 8px; font-size: 12px; }
input, select, textarea {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit;
}
select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 34px;
}
input[type="checkbox"] { width: 18px; height: 18px; padding: 0; border: 0; accent-color: var(--brand); cursor: pointer; }
.chk { text-align: center; }
th.chk, td.chk { width: 120px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.search { min-width: 220px; }

/* ---------- карточки и сетки ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card .num { font-size: 28px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 13px; }
.card.good .num { color: var(--ok); }
.card.warn .num { color: var(--warn); }
.card.bad .num { color: var(--bad); }
.card.brand .num { color: var(--brand); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; color: var(--brand); }
.panel h3 { margin: 16px 0 8px; font-size: 14px; color: var(--ink); }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; position: sticky; top: 0; background: #fff; }
tbody tr:hover { background: #f8fafc; }
td.num { text-align: right; }
th.num { text-align: right; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn { margin-left: 4px; }

/* ---------- бейджи статусов и типов ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-новый { background: #eef2f7; color: #475569; }
.st-прозвон { background: #dbeafe; color: #1d4ed8; }
.st-думает { background: #ffedd5; color: #9a3412; }
.st-одобрен { background: #fef9c3; color: #854d0e; }
.st-оформлен { background: #dcfce7; color: #15803d; }
.st-слился { background: #fee2e2; color: #b91c1c; }
.st-отказ { background: #e5e7eb; color: #374151; }
.st-пауза { background: #ede9fe; color: #6d28d9; }
.type-офлайн { background: #e0f2fe; color: #0369a1; }
.type-онлайн { background: #fce7f3; color: #be185d; }
.type-прочее { background: #e5e7eb; color: #374151; }

/* ---------- модалка ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100;
}
.modal-card {
  background: #fff; border-radius: 12px; width: 100%; max-width: 600px;
  max-height: 90vh; overflow: auto; padding: 20px;
}
.modal-card h2 { margin: 0 0 14px; font-size: 18px; color: var(--brand); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; margin-top: 4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 12px; }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- мобильная версия ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .app header { padding: 8px 12px; gap: 8px; }
  /* на телефоне — только «Кандидаты» и «Фонд», без названия и блока «Админ / Выйти» */
  nav button:not([data-tab="leads"]):not([data-tab="fund"]) { display: none; }
  .userbox { display: none; }
  #tab-leads .toolbar a[href="/api/export.csv"] { display: none; }
  #tab-leads .toolbar select[data-f="channel"] { display: none; }
  .brand { display: none; }
  .tag { display: none; }
  nav {
    order: 3; width: 100%;
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  nav button { white-space: nowrap; padding: 8px 10px; font-size: 13px; }
  .userbox .who { display: none; }
  main { padding: 12px; }

  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { padding: 12px; }
  .card .num { font-size: 22px; }
  .panel { padding: 12px; margin-bottom: 12px; }
  .panel h2 { font-size: 15px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .grow { display: none; }
  .search { min-width: 0; width: 100%; }
  .toolbar .btn, .toolbar .search { width: 100%; }

  input, select, textarea { font-size: 16px; }

  .table-wrap { overflow: visible; }
  table, thead, tbody { display: block; width: 100%; }
  thead { display: none; }
  tr {
    display: flex; flex-direction: column;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    margin-bottom: 10px; padding: 10px 12px;
  }
  td {
    display: flex; gap: 8px; align-items: baseline;
    border: none; padding: 4px 0; text-align: left;
  }
  td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 12px; min-width: 92px; flex-shrink: 0;
  }
  td.cell-title {
    order: -1; font-size: 16px; font-weight: 700;
    border-bottom: 1px solid var(--line);
    padding-bottom: 6px; margin-bottom: 4px;
  }
  td.cell-title::before { display: none; }
  td.actions { justify-content: flex-end; flex-wrap: wrap; padding-top: 8px; }
  td.actions::before { display: none; }
  td.num { text-align: left; }
  td.chk { width: auto; text-align: left; justify-content: space-between; align-items: center; }
  td.chk::before { min-width: 0; flex: 1; text-align: left; }
  td.chk input[type="checkbox"] { flex-shrink: 0; }
  input[type="checkbox"] { width: 22px; height: 22px; }

  .modal { padding: 8px; }
  .modal-card { max-width: 100%; max-height: 92vh; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }
}
