/* =========================================================
   Трекер — дизайн-система. Тёмная, спокойная, без неона.
   ========================================================= */
:root {
  --bg: #0f131a;
  --bg-side: #0b0e14;
  --bg-card: #161b24;
  --bg-hover: #1c222d;
  --border: #242b37;
  --text: #e6e9ef;
  --text-2: #98a2b3;
  --text-3: #667085;
  --accent: #5b8def;      /* синий — клики, действия */
  --accent-2: #3ec78a;    /* зелёный — деньги, ок */
  --warn: #f2b23c;
  --danger: #ef5b6b;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  background: var(--bg); color: var(--text); min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 15px; }
p { margin: 0 0 8px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.green { color: var(--accent-2); } .red { color: var(--danger); } .amber { color: var(--warn); }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- Каркас: сайдбар + контент ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0,1fr); min-height: 100vh; }
.side {
  background: var(--bg-side); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 16px; letter-spacing: .04em; }
.brand .mark {
  width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 800;
}
.brand .tag { margin-left: auto; font-size: 10px; color: var(--text-3); font-weight: 500; letter-spacing: .08em; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; transition: .15s;
}
.nav a:hover { background: var(--bg-hover); color: var(--text); }
.nav a.active { background: rgba(91,141,239,.14); color: #fff; }
.nav a .ic { width: 18px; text-align: center; opacity: .9; }
.side .foot { margin-top: auto; padding: 8px; font-size: 12px; color: var(--text-3); }
.side .user { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-top: 1px solid var(--border); margin-top: 8px; }
.side .user .av { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-hover); display: grid; place-items: center; font-weight: 600; color: var(--text-2); }
.side .user .nm { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .user .rl { font-size: 11px; color: var(--text-3); }
.main { padding: 26px 32px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

/* ---------- Карточки, KPI ---------- */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .l { font-size: 12px; color: var(--text-2); }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; }
.grid2 .card + .card { margin-top: 0; }

/* ---------- Кнопки, поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-hover); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #33405a; background: #222a38; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.success { background: var(--accent-2); border-color: var(--accent-2); color: #0a1f16; }
.btn.danger { background: transparent; border-color: rgba(239,91,107,.5); color: var(--danger); }
.btn.danger:hover { background: rgba(239,91,107,.12); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: transparent; border: 0; color: var(--text-2); font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field .hint { font-size: 12px; color: var(--text-3); }
input, select, textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; outline: none; transition: .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,141,239,.18); }
textarea { min-height: 80px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.copy-box { display: flex; gap: 8px; align-items: center; }
.copy-box input { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.seg { display: inline-flex; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--text-2); padding: 6px 12px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; }
.seg button.active { background: var(--bg-hover); color: #fff; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--text-3); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:hover { background: rgba(255,255,255,.02); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.empty { text-align: center; color: var(--text-3); padding: 28px; }
td .wallet { display: block; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td .sub { display: block; font-size: 12px; color: var(--text-3); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--bg-hover); color: var(--text-2); }
.badge.active, .badge.approved, .badge.paid { background: rgba(62,199,138,.15); color: var(--accent-2); }
.badge.pending, .badge.requested, .badge.hold, .badge.moderation { background: rgba(242,178,60,.15); color: var(--warn); }
.badge.paused { background: rgba(152,162,179,.15); color: var(--text-2); }
.badge.blocked, .badge.rejected, .badge.cancelled { background: rgba(239,91,107,.15); color: var(--danger); }
.goal { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; }
.goal.g1 { background: rgba(91,141,239,.14); color: var(--accent); }
.goal.g2 { background: rgba(62,199,138,.14); color: var(--accent-2); }
.view-as { background: rgba(242,178,60,.12); border-bottom: 1px solid rgba(242,178,60,.35); color: var(--text); padding: 10px 32px; display: flex; gap: 12px; align-items: center; font-size: 13px; }
.view-as b { color: var(--warn); }
.geo { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg-hover); margin-right: 3px; color: var(--text-2); }

/* ---------- Офферы ---------- */
.offers { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.offer { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.offer .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.offer .name { font-weight: 600; font-size: 15px; }
.offer .adv { font-size: 12px; color: var(--text-3); }
.offer .pay { font-size: 20px; font-weight: 700; color: var(--accent-2); white-space: nowrap; }
.offer .pay small { font-size: 11px; color: var(--text-3); font-weight: 500; display: block; text-align: right; }
.offer .desc { color: var(--text-2); font-size: 13px; }
.offer .foot { margin-top: auto; display: flex; gap: 8px; align-items: center; justify-content: space-between; }

.thumb { width: 44px; height: 30px; object-fit: cover; border-radius: 6px; background: var(--bg-hover); flex: none; }
.thumb.ph { display: grid; place-items: center; color: var(--text-3); }
.img-prev { width: 96px; height: 60px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); flex: none; }
.link-btn { color: var(--accent); cursor: pointer; }
.offer .img { width: calc(100% + 36px); margin: -16px -18px 4px; height: 130px; object-fit: cover; border-radius: var(--radius) var(--radius) 0 0; background: var(--bg-hover); }
.offer .img.ph { display: grid; place-items: center; font-size: 28px; color: var(--text-3); }

/* ---------- График ---------- */
.chart-box { position: relative; }
.chart-svg { width: 100%; height: 200px; display: block; }
.chart-svg .grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-svg .axis { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart-tip { position: absolute; top: 4px; background: #0b0e14; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; pointer-events: none; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.chart-tip b { font-size: 13px; } .chart-tip span { color: var(--text-3); }

/* ---------- Модалки, тосты ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 20px; backdrop-filter: blur(3px); }
.modal { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 480px; box-shadow: var(--shadow); max-height: 92vh; display: flex; flex-direction: column; }
.modal.wide { max-width: 680px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
body.modal-open { overflow: hidden; }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1c222d; border: 1px solid var(--border); border-left: 3px solid var(--accent-2); padding: 10px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transform: translateY(8px); transition: .25s; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: none; }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* ---------- Страница входа ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.auth-card .brand { justify-content: center; padding-bottom: 20px; }
.auth-card h1 { font-size: 18px; text-align: center; margin-bottom: 18px; }
.auth-card .switch { text-align: center; margin-top: 14px; font-size: 13px; color: var(--text-2); }
.demo-note { margin-top: 16px; padding: 10px 12px; border-radius: 8px; background: rgba(242,178,60,.1); border: 1px solid rgba(242,178,60,.3); font-size: 12.5px; color: var(--text-2); }
.demo-note b { color: var(--warn); }
.err-msg { color: var(--danger); font-size: 12.5px; min-height: 16px; margin-bottom: 8px; }

/* ---------- Мобильные ---------- */
.topbar, .bottomnav { display: none; }
@media (max-width: 900px) {
  .shell { display: block; }
  .side { display: none; }
  /* верхняя шапка */
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--bg-side); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .topbar .brand { padding: 0; font-size: 15px; }
  /* нижняя панель вкладок */
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--bg-side); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 7px; font-size: 11px; color: var(--text-3); font-weight: 500; }
  .bottomnav a .ic { font-size: 18px; line-height: 1; }
  .bottomnav a.active { color: var(--accent); }
  .main { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }
  .view-as { padding: 8px 12px; font-size: 12px; flex-wrap: wrap; }
  h1 { font-size: 20px; }
  .page-head { margin-bottom: 14px; }
  .page-head .btn { width: 100%; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
  .kpi { padding: 12px 12px; } .kpi .v { font-size: 19px; }
  .card { padding: 14px 14px; } .card + .card { margin-top: 12px; }
  .grid2 { grid-template-columns: 1fr; gap: 12px; }
  .grid2 .card + .card { margin-top: 0; }
  .fields2 { grid-template-columns: 1fr; }
  .offers { grid-template-columns: 1fr; }
  .chart-svg { height: 160px; }
  /* сегменты — горизонтальная прокрутка одной строкой */
  .seg { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: none; padding: 7px 11px; }
  .card-head .row { width: 100%; }
  /* модалки — шторка снизу */
  .modal-wrap { place-items: end center; padding: 0; }
  .modal, .modal.wide { max-width: 100%; border-radius: 16px 16px 0 0; max-height: 94vh; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  .btn, input, select, textarea { min-height: 42px; }   /* пальцем удобнее */
  .btn.sm { min-height: 36px; }
  .icon-btn { min-height: 0; }
  .copy-box { flex-direction: column; align-items: stretch; }
  .copy-box .btn { width: 100%; }
}
/* ---------- Таблицы → карточки на узких экранах ---------- */
@media (max-width: 640px) {
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 6px 12px; background: var(--bg); }
  tbody tr:last-child { margin-bottom: 0; }
  tbody tr:hover { background: var(--bg); }
  td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); text-align: right; }
  td:last-child { border-bottom: 0; }
  td::before { content: attr(data-l); color: var(--text-3); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex: none; }
  td.num, td.right { text-align: right; }
  td.actions { justify-content: flex-end; flex-wrap: wrap; gap: 6px; padding-top: 10px; }
  td.actions::before { display: none; }
  td.empty { justify-content: center; text-align: center; }
  td.empty::before { display: none; }
  td .sub { display: block; margin-left: 0; text-align: right; }
  td .wallet { max-width: 55vw; }
  td:first-child { font-weight: 500; }
  td.actions .btn { flex: 1 1 auto; }
  /* справочные таблицы без шапки (макросы постбека) остаются обычными */
  table.plain, table.plain tbody, table.plain tr { display: table; width: 100%; border: 0; padding: 0; margin: 0; background: transparent; }
  table.plain tr { display: table-row; }
  table.plain td { display: table-cell; text-align: left; border-bottom: 1px solid var(--border); padding: 8px 6px; }
  table.plain td::before { display: none; }
}
