/* CRM Tools - панель управления */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f1f0ec;
  --text: #1f1d1a;
  --muted: #6d6a64;
  --line: #e4e1da;
  --accent: #1f6f43;
  --accent-soft: #e3f1e8;
  --accent-text: #ffffff;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --info-soft: #e8eefc;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 18, 14, .05), 0 4px 16px rgba(20, 18, 14, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1e1d1a;
    --surface-2: #26241f;
    --text: #ecebe7;
    --muted: #a29f97;
    --line: #35332d;
    --accent: #4fb57d;
    --accent-soft: #1c3326;
    --accent-text: #0f1a13;
    --warn: #e2a54a;
    --warn-soft: #33281a;
    --danger: #f0776c;
    --danger-soft: #3a1f1c;
    --info-soft: #1d2535;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------- Шапка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-text); font-size: 12px; font-weight: 700; letter-spacing: .02em;
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar .logout { color: var(--muted); text-decoration: none; white-space: nowrap; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.switches { display: flex; flex-wrap: wrap; gap: 10px 28px; align-items: center; }
.switches .sw-label { display: flex; align-items: center; gap: 10px; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.center, th.center { text-align: center; }
.agent-name { font-weight: 600; }
.agent-sub { color: var(--muted); font-size: 12px; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-right: 6px; vertical-align: middle; }
.dot.on { background: #2fb35d; box-shadow: 0 0 0 3px rgba(47, 179, 93, .18); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.new { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.soon { background: var(--info-soft); color: var(--muted); }

/* ---------- Переключатель ---------- */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.toggle .track {
  position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .15s;
}
.toggle .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:disabled { cursor: not-allowed; }
.toggle input:disabled + .track { opacity: .45; }
.toggle.busy .track { opacity: .6; }

/* ---------- Формы и кнопки ---------- */
label { display: block; margin-bottom: 14px; font-weight: 500; }
label small { display: block; font-weight: 400; color: var(--muted); margin-top: 2px; }
input:not([type]), input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text);
  font: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.inline-input { margin: 0; padding: 6px 9px; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { display: flex; width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; }
.check .toggle { margin-top: 1px; }

.alert { padding: 10px 14px; border-radius: 9px; margin-bottom: 14px; background: var(--info-soft); }
.alert.ok { background: var(--accent-soft); color: var(--accent); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.error { background: var(--danger-soft); color: var(--danger); }

.add-row { display: grid; grid-template-columns: 2fr 2fr auto auto; gap: 10px; align-items: end; padding: 16px 20px; border-top: 1px solid var(--line); background: var(--surface-2); }
.add-row label { margin: 0; }

.copy-box { display: flex; gap: 8px; align-items: stretch; }
.copy-box input { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
pre.code {
  margin: 0; padding: 14px 16px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line);
  max-height: 320px; overflow: auto; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre;
}
ol.steps { padding-left: 20px; margin: 0; }
ol.steps li { margin-bottom: 10px; }
.kbd { display: inline-block; padding: 1px 7px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); font-size: 12px; font-family: inherit; white-space: nowrap; }

/* ---------- Вход / установка ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.auth-card.wide { max-width: 480px; }
.auth-card .brand { margin-bottom: 18px; }
.checks { list-style: none; padding: 0; margin: 0 0 16px; }
.checks li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.checks li.ok { color: var(--accent); }
.checks li.bad { color: var(--danger); }
.checks small { display: block; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- Телефон ---------- */
@media (max-width: 760px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .brand .brand-text { display: none; }
  .wrap { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .add-row { grid-template-columns: 1fr; }

  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  table.responsive td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; }
  table.responsive td.first { display: block; text-align: left; }
  table.responsive td.first::before { content: none; }
}
