:root {
  --bg: #f6f7f9; --panel: #fff; --line: #e4e7ec; --line2: #eef0f3;
  --text: #1d2433; --muted: #6b7385; --accent: #3b5bdb; --accent-bg: #edf1ff;
  --ok: #2f9e44; --err: #e03131; --warn: #f08c00;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 Inter, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: #c9ced8; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .6; cursor: wait; }
button.link { border: 0; background: none; color: var(--accent); padding: 6px 8px; }
button.danger, .link.danger { color: var(--err); }
button.icon { border: 0; background: none; font-size: 16px; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-bg); border-color: var(--accent); }

.loading { padding: 80px; text-align: center; color: var(--muted); }

/* шапка */
header.top { position: sticky; top: 0; z-index: 5; display: flex; gap: 20px; align-items: center; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.2px; }
.brand span { color: var(--accent); }
.brand.big { font-size: 26px; text-align: center; margin-bottom: 8px; }
header nav { display: flex; gap: 4px; flex: 1; }
header nav button, .seg button { border: 0; background: none; color: var(--muted); font-weight: 500; }
header nav button.on { background: var(--accent-bg); color: var(--accent); }
.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; }
.seg button { padding: 4px 12px; border-radius: 6px; }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

main { padding: 18px 24px 60px; }
.hint { color: var(--muted); margin: 0 0 14px; }

/* панель инструментов и фильтры */
.toolbar { display: flex; gap: 10px; margin-bottom: 10px; }
.search { flex: 1; padding: 9px 12px; font-size: 15px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters select { padding: 5px 8px; color: var(--muted); }
.filters select.on { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

.stats { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; min-width: 130px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat b { font-size: 17px; }

/* таблицы */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 250px); }
table { border-collapse: collapse; width: 100%; }
th { position: sticky; top: 0; background: #fafbfc; text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
table.clients th { cursor: pointer; }
th.sorted { color: var(--accent); }
td { padding: 7px 10px; border-bottom: 1px solid var(--line2); white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
table.clients tbody tr { cursor: pointer; }
table.clients tbody tr:hover { background: #f7f9ff; }
.r { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.more { display: block; margin: 12px auto; }
table.summary td.brokers { white-space: normal; max-width: none; }
.chip { display: inline-block; background: var(--bg); border-radius: 5px; padding: 2px 7px; margin: 2px 4px 2px 0; font-size: 12px; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; background: var(--bg); color: var(--muted); }
.pill.es { background: #fff4e6; color: #d9480f; }
.pill.cis { background: #e7f5ff; color: #1971c2; }
.pill.st-выплачен { background: #ebfbee; color: var(--ok); }
.pill.st-квалифицирован { background: #e7f5ff; color: #1971c2; }
.pill.st-обработка { background: #fff9db; color: #e67700; }
.pill.st-неполучили { background: #fff5f5; color: var(--err); }
.pill.tg-in { background: #ebfbee; color: var(--ok); }

/* карточка */
.overlay { position: fixed; inset: 0; background: rgba(20,25,40,.28); z-index: 20; display: flex; justify-content: flex-end; }
.drawer { width: min(860px, 100%); height: 100%; overflow: auto; background: var(--panel); box-shadow: -8px 0 30px rgba(0,0,0,.12); padding: 0 24px 24px; }
.drawer.narrow { width: min(560px, 100%); }
.drawer header { position: sticky; top: 0; background: var(--panel); display: flex; justify-content: space-between; align-items: center; padding: 16px 0 10px; z-index: 2; }
.drawer h2 { margin: 0; font-size: 19px; }
.meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 12px 0 0; padding: 12px 0 0; }
legend { font-weight: 600; font-size: 13px; padding-right: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 14px; }
.drawer.narrow .grid { grid-template-columns: 1fr 1fr; }
.grid label { display: flex; flex-direction: column; gap: 3px; }
.grid label span { font-size: 12px; color: var(--muted); }
.grid label.wide { grid-column: 1 / -1; }
.grid label.check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 8px; }
.grid label.check input { width: 18px; height: 18px; }
.card-actions { position: sticky; bottom: -24px; background: var(--panel); display: flex; gap: 8px; padding: 14px 0; margin-top: 16px; border-top: 1px solid var(--line); }
.card-actions .danger { margin-left: auto; }
.warn { background: #fff4e6; border: 1px solid #ffd8a8; color: #a14a00; padding: 10px 12px; border-radius: 6px; margin-top: 10px; }

/* сетка CPA */
.grid-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; max-width: 640px; }
.grid-block h3 { margin: 0 0 8px; font-size: 15px; }
.grid-block small { color: var(--muted); font-weight: 400; }
.grid-block input { width: 110px; }
.grid-block td { overflow: visible; }

/* вход */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login { display: flex; flex-direction: column; gap: 10px; width: 320px; background: var(--panel); padding: 28px; border-radius: 12px; border: 1px solid var(--line); }
.login input { padding: 10px 12px; }
.login-note { color: var(--err); font-size: 13px; min-height: 18px; text-align: center; }

/* уведомления */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .4s, transform .4s; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }
.toast.live { background: #fff; color: var(--text); border-left: 4px solid var(--ok); font-weight: 600; }
.toast.hide { opacity: 0; transform: translateY(8px); }

@media (max-width: 800px) {
  header.top { flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  main { padding: 12px; }
  .drawer.narrow .grid { grid-template-columns: 1fr; }
}
