/* Распределение сделок/лидов — оформление как в bizandsoft (Bootstrap dark) */
:root {
  --bg: #212529;
  --panel: #2b3035;
  --panel-2: #343a40;
  --border: #495057;
  --border-soft: #3a4148;
  --text: #dee2e6;
  --muted: #adb5bd;
  --accent: #0d6efd;
  --accent-dark: #0b5ed7;
  --success: #198754;
  --success-soft: #198754;
  --warning: #ffc107;
  --danger: #dc3545;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: #6ea8fe; text-decoration: none; }
a:hover { color: #8bb9fe; text-decoration: underline; }
code, .mono { font-family: "SF Mono", Consolas, monospace; font-size: 12px; color: #e685b5; }
h1, h2, h3, h4 { margin: 0; font-weight: 500; }
ul { margin: 0; padding: 0; }

/* ------------------------------------------------------------- верхняя панель */
.topbar {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--panel-2);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); }
.brand:hover { text-decoration: none; color: #fff; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 4px;
  display: grid; place-items: center;
  background: transparent; color: #6ea8fe;
}
.brand-name { font-size: 15px; font-weight: 500; }
.topbar-actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------- каркас */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  width: 228px;
  flex: 0 0 228px;
  min-height: calc(100vh - 50px);
  border-right: 1px solid var(--panel-2);
  padding: 12px 8px;
  position: sticky;
  top: 50px;
  height: calc(100vh - 50px);
  overflow-y: auto;
}
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 4px;
  color: #ced4da; font-size: 12.5px;
}
.nav-item svg { width: 14px; height: 14px; color: #6ea8fe; flex: 0 0 14px; }
.nav-item:hover { background: #2b3035; text-decoration: none; color: #fff; }
.nav-item.is-active { background: #2b3035; color: #fff; }

.main { flex: 1; min-width: 0; }
.content { padding: 16px 24px 48px; display: flex; flex-direction: column; gap: 16px; }
.content > h1 { font-size: 30px; font-weight: 500; margin: 4px 0 6px; letter-spacing: -.01em; }

.sidebar-foot { display: none; }

/* ------------------------------------------------------------- панели */
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: transparent;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 15px; font-weight: 500; }
.panel-head-wrap { flex-wrap: wrap; }
.panel-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel-warning { border-color: #664d03; background: rgba(255, 193, 7, .06); }
.panel-danger { border-color: #842029; background: rgba(220, 53, 69, .06); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.metric-panel .metric { font-size: 30px; font-weight: 500; line-height: 1.15; }
.metric-panel.is-accent { border-color: #0d6efd; background: rgba(13, 110, 253, .12); }
.metric-caption { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  display: inline-flex; gap: 4px; align-items: center;
  border: 1px solid var(--border); border-radius: 4px;
  padding: 2px 8px; font-size: 12px; color: var(--muted);
}
.plain-list { list-style: none; display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.plain-list li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.plain-list .arrow { color: var(--muted); }

.alert { border-radius: var(--radius); padding: 12px 14px; font-size: 13px; border: 1px solid transparent; }
.alert-warning { background: rgba(255, 193, 7, .1); border-color: #664d03; color: #ffda6a; }
.alert-info { background: rgba(13, 110, 253, .12); border-color: #084298; color: #9ec5fe; }
.alert-danger { background: rgba(220, 53, 69, .12); border-color: #842029; color: #ea868f; }

.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------- кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 4px; border: 1px solid transparent;
  padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 400;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  background: transparent; color: var(--text); line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-secondary { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-secondary:hover { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: #6c757d; color: #ced4da; }
.btn-ghost:hover { background: #6c757d; color: #fff; }
.btn-danger-ghost { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger); color: #fff; }
.btn-success-ghost { background: transparent; border-color: var(--success); color: #75b798; }
.btn-success-ghost:hover { background: var(--success); color: #fff; }
.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: default; }

.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  font-size: 14px; line-height: 1; padding: 5px;
}
.icon-btn:hover { color: #fff; }
.link-btn {
  border: 0; background: transparent; padding: 0; cursor: pointer;
  color: #6ea8fe; font: inherit; font-size: 12px;
}
.link-btn:hover { text-decoration: underline; }

/* ------------------------------------------------------------- формы */
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); border-radius: 4px;
  padding: 6px 10px; font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: #86b7fe;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, .25);
}
.input::placeholder { color: #6c757d; }
.input-sm { width: auto; padding: 4px 8px; font-size: 12px; }
.input-xs { width: 74px; padding: 3px 6px; font-size: 12px; }
select[multiple].input { padding: 4px; min-height: 132px; }
select[multiple].input option { padding: 3px 6px; }
select[multiple].input option:checked {
  background: linear-gradient(0deg, #0d6efd, #0d6efd);
  color: #fff;
}
option, optgroup { background: var(--bg); color: var(--text); }
#load-dates .input { flex: 1 1 180px; width: auto; }

.form-row {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 8px 16px;
  align-items: start;
  margin-top: 14px;
}
.form-row > label {
  display: block; font-size: 14px; font-weight: 400; color: var(--muted);
  padding-top: 7px; margin: 0;
}
/* всё, что идёт после подписи, занимает правую колонку */
.form-row > :not(label) { grid-column: 2; }
.form-row > label:not(.switch-row)::after { content: ":"; }
.form-row > .switch-row { margin-top: 5px; align-items: center; }
.form-row > .switch-row input { margin-top: 0; }
.form-row-narrow { grid-template-columns: 230px minmax(0, 1fr); max-width: none; }
.form-row-narrow > .input, .form-row-narrow > select { max-width: 420px; }
.inline-fields { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-fields .form-row { flex: 1 1 320px; margin-top: 10px; }

.switch-row {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 13px; margin-top: 10px; cursor: pointer; color: var(--text);
}
.switch-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 30px; height: 16px; border-radius: 999px; background: var(--border);
  position: relative; cursor: pointer; flex: 0 0 auto; margin: 1px 0 0;
  transition: background .18s;
}
.switch-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: #fff; transition: transform .18s;
}
.switch-row input[type="checkbox"]:checked { background: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(14px); }
.sub-check { margin-left: 24px; }
.subblock { margin-left: 24px; padding-left: 14px; border-left: 1px solid var(--border); }

.fieldset {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px 16px; margin: 18px 0 0;
}
.fieldset legend { font-size: 15px; font-weight: 500; padding: 0 6px; color: var(--text); }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.form-sep { border-top: 1px solid var(--border); margin: 18px 0 2px; }
.btn-block { width: 100%; }

/* ------------------------------------------------------------- карточки настроек */
.setting-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; background: rgba(255, 255, 255, .02);
}
.setting-card h3 { font-size: 15px; font-weight: 500; margin-bottom: 8px; }
.state { font-size: 13px; font-weight: 500; margin: 0; }
.state-ok { color: #75b798; }
.state-warning { color: #ffda6a; }

/* ------------------------------------------------------------- члены группы */
.mass-fill {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: 4px;
  padding: 8px 10px; margin-bottom: 10px; font-size: 12.5px;
  background: rgba(255, 255, 255, .02);
}
.mass-fill select.input, .mass-fill input.input { width: auto; min-width: 120px; }
.members {
  max-height: 340px; overflow: auto;
  border: 1px solid var(--border); border-radius: 4px;
}
.dep + .dep { border-top: 1px solid var(--border); }
.dep-head {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); padding: 6px 10px; font-size: 12.5px; font-weight: 500;
  color: #e9ecef; position: sticky; top: 0; z-index: 1;
}
.dep-switch { flex: 0 0 auto; }
.dep-title {
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: 0; color: inherit; font: inherit;
  cursor: pointer; flex: 1; text-align: left; padding: 0; min-width: 0;
}
.dep-title .chev { color: var(--muted); width: 12px; transition: transform .15s; display: inline-block; }
.dep.is-open .dep-title .chev { transform: rotate(90deg); }
.dep-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep-count {
  font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 9px; padding: 0 6px; line-height: 15px; flex: 0 0 auto;
}
.dep-body { border-top: 1px solid var(--border-soft); }
#members-selected { color: #9ec5fe; font-weight: 500; }
.member {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 10px 5px 14px; border-top: 1px solid var(--border-soft);
}
.member-check-label { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; cursor: pointer; }
.member-check-label input {
  appearance: none; -webkit-appearance: none;
  width: 30px; height: 16px; border-radius: 999px; background: var(--border);
  position: relative; cursor: pointer; flex: 0 0 auto; margin: 0;
  transition: background .18s;
}
.member-check-label input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: #fff; transition: transform .18s;
}
.member-check-label input:checked { background: var(--accent); }
.member-check-label input:checked::after { transform: translateX(14px); }
.member-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.member-params { display: flex; gap: 4px; flex: 0 0 auto; }
.member-params .input { display: none; }
.member.is-checked .member-name { color: #fff; }
#group-form[data-mode="load_coef"] .p-weight { display: block; }
#group-form[data-mode="ratio"] .p-percent { display: block; }
#group-form[data-mode="queue_limit"] .p-limit { display: block; }
#group-form[data-mode="bonus"] .p-threshold,
#group-form[data-mode="bonus"] .p-bonus { display: block; }

/* ------------------------------------------------------------- фильтры */
.rules { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.rule {
  display: grid; grid-template-columns: minmax(0, 1.5fr) 140px minmax(0, 1fr) auto auto;
  gap: 8px; align-items: center;
}
.rule-or { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.rule-or input { accent-color: var(--accent); }

/* ------------------------------------------------------------- карточки групп */
.page-actions { display: flex; align-items: center; gap: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.group-card { display: flex; flex-direction: column; gap: 5px; padding: 14px 16px; }
.group-card.is-off { opacity: .55; }
.card-top { display: flex; align-items: center; justify-content: space-between; }
.counter {
  font-size: 11px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 10px; padding: 0 8px; line-height: 17px;
}
.card-title { font-size: 15px; font-weight: 500; margin-top: 4px; color: #fff; }
.card-mode { font-size: 13px; color: #e9ecef; }
.card-text { font-size: 12.5px; color: var(--muted); margin: 2px 0 10px; }
.card-foot { display: flex; gap: 8px; margin-top: auto; }

.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 34px; height: 18px; border-radius: 999px; background: var(--border);
  transition: background .18s; position: relative; display: block;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; transition: transform .18s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }

.empty-state {
  grid-column: 1 / -1; border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted);
}
.form-panel { scroll-margin-top: 60px; }
.form-body { margin-top: 4px; }
.form-panel .panel-head { border-bottom: 1px solid var(--border-soft); padding-bottom: 10px; margin-bottom: 6px; }

/* ------------------------------------------------------------- таблицы */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.table thead th {
  background: var(--panel-2); font-weight: 500; font-size: 12.5px; color: #e9ecef;
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.table tbody tr:nth-child(odd) { background: rgba(255, 255, 255, .02); }
.table tbody tr:hover { background: rgba(255, 255, 255, .04); }
.table tfoot td { background: var(--panel-2); font-weight: 500; }
.table .empty { color: var(--muted); text-align: center; padding: 24px; }

.badge {
  display: inline-block; border-radius: 4px; padding: 2px 7px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap; line-height: 1.5;
}
.badge-success { background: var(--success); color: #fff; }
.badge-warning { background: var(--warning); color: #000; }
.badge-danger { background: var(--danger); color: #fff; }
.badge-info { background: #0dcaf0; color: #000; }
.badge-secondary { background: #6c757d; color: #fff; }
.cell-note { color: var(--muted); font-size: 11.5px; margin-top: 3px; }

.log-toolbar { display: flex; align-items: center; gap: 12px; }
.icon-square {
  width: 34px; height: 34px; border: 1px solid var(--accent); border-radius: 4px;
  background: rgba(13, 110, 253, .18); color: #9ec5fe; display: grid; place-items: center;
  font-size: 14px;
}
.icon-square:hover { background: var(--accent); color: #fff; }
.pagination { display: flex; align-items: center; gap: 3px; }
.pagination a, .pagination .page-gap {
  min-width: 30px; height: 30px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px; color: #6ea8fe; font-size: 13px;
}
.pagination a:hover { background: rgba(13, 110, 253, .16); text-decoration: none; }
.pagination a.is-active { background: var(--accent); color: #fff; }
.pagination .page-gap { color: var(--muted); }
.log-help { margin-bottom: 14px; line-height: 1.55; }
.log-filters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 0 0 14px; }
.log-filters .input { width: auto; }
.log-filters .input-entity { min-width: 260px; }
.log-filters .input-number { min-width: 150px; }
.log-filters .input-result { min-width: 280px; }

.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form .input { width: auto; min-width: 150px; }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 12px; }

.pill {
  display: inline-block; min-width: 34px; text-align: center;
  background: var(--success); color: #fff; border-radius: 4px; padding: 1px 7px; font-weight: 500;
}
.dash { color: #6c757d; }

.stats-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stats-filters .input { width: auto; min-width: 140px; }
.stats-table .sticky-col { position: sticky; left: 0; background: var(--bg); z-index: 1; }
.stats-table tbody tr:nth-child(odd) .sticky-col { background: #24282c; }
.stats-table tfoot .sticky-col { background: var(--panel-2); }
.th-note { font-weight: 400; color: var(--muted); font-size: 11px; }

/* ------------------------------------------------------------- модалки/тосты */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.modal-card {
  position: relative; width: min(560px, 100%);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 16px 48px rgba(0, 0, 0, .5);
  animation: pop .16s ease-out;
}
.modal-card.is-narrow { width: min(420px, 100%); }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 0; }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 10px 16px 16px; font-size: 13.5px; color: #ced4da; }
.modal-body p { margin: 0 0 10px; }
.modal-body ul { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 16px 16px; }

.toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  min-width: 240px; max-width: 360px;
  background: var(--panel-2); color: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 13px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
  animation: toast-in .18s ease-out;
}
.toast.is-error { background: #842029; border-color: #a52834; }
.toast.is-success { background: #146c43; border-color: #198754; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------- адаптив */
@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; min-height: 0; position: static;
    border-right: 0; border-bottom: 1px solid var(--panel-2); padding: 8px;
  }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav-item { white-space: nowrap; }
  .content { padding: 12px 14px 32px; }
  .content > h1 { font-size: 24px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row, .form-row-narrow { grid-template-columns: 1fr; gap: 4px; }
  .form-row > label { padding-top: 0; }
  .rule { grid-template-columns: 1fr 1fr; }
}
