:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #1d2733;
  --ink-2: #3b4757;
  --muted: #6b7685;
  --faint: #9aa3af;
  --line: #e4e7ec;
  --line-2: #eef0f3;
  --asphalt: #2b3644;
  --accent: #2563c9;
  --accent-soft: #e8effa;
  --won: #2563c9;
  --qual: #8fb0e3;
  --work: #cbd9ee;
  --junk: #c9cfd8;
  --bad: #b5473a;
  --good: #23704f;
  --radius: 10px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.45 'IBM Plex Sans', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num { font-variant-numeric: tabular-nums; }

/* Каркас: меню слева */
.layout { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--asphalt); color: #fff; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px 14px; }
.brand { font-weight: 600; letter-spacing: .01em; padding: 0 10px 18px; line-height: 1.3; }
.brand span { display: block; color: #9fb3cc; font-weight: 400; font-size: 12.5px; margin-top: 2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-i { display: flex; align-items: center; gap: 10px; background: none; border: 0; color: #c3ccd8; padding: 8px 10px; border-radius: 7px; cursor: pointer; text-align: left; }
.nav-i:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-i.on { background: rgba(111,155,224,.18); color: #fff; }
.nav-i .ic { width: 16px; height: 16px; flex: none; display: inline-flex; }
.nav-i svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.side-f { margin-top: auto; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; color: #9fb3cc; font-size: 12px; padding: 0 10px; }
.icon-btn { background: rgba(255,255,255,.08); border: 0; color: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 12.5px; }
.icon-btn:hover { background: rgba(255,255,255,.16); }
.body { min-width: 0; }
.who { color: #9fb3cc; font-size: 12px; }
.who a { color: #c3d3ea; }
.gate .btn { display: inline-block; text-decoration: none; padding: 10px 18px; }
.page-h { padding: 18px 24px 0; background: var(--surface); }
.page-h h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.005em; }
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-f { margin-top: 10px; flex-direction: row; align-items: center; }
}

/* Фильтры */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--surface); border: 0; padding: 6px 11px; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--line-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.dates { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
input[type=date], select, input[type=text], input[type=password], input[type=number] { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: var(--surface); }
select { padding-right: 26px; max-width: 220px; }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); cursor: pointer; user-select: none; }
.reset { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 4px; }
.reset:hover { color: var(--ink); }

main { padding: 20px 24px 48px; max-width: 1440px; margin: 0 auto; }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.g-2 { grid-template-columns: 1.6fr 1fr; }
.g-2e { grid-template-columns: 1fr 1fr; }
@media (max-width: 1000px) { .g-2, .g-2e { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-gap { margin-top: 16px; }

/* KPI */
.kpi { padding: 16px 18px; }
.kpi .lbl { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 26px; font-weight: 600; margin-top: 6px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 4px; }
.kpi .meta { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.delta { font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Графики */
.chart { width: 100%; display: block; }
.chart text { font: 11px 'IBM Plex Sans', sans-serif; fill: var(--faint); }
.chart .grid-l { stroke: var(--line-2); }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.tip { position: fixed; pointer-events: none; background: var(--asphalt); color: #fff; padding: 8px 10px; border-radius: 7px; font-size: 12.5px; z-index: 20; line-height: 1.5; box-shadow: 0 6px 20px rgba(20,30,45,.18); }
.tip b { font-weight: 600; }

/* Полосы */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 190px) 1fr 52px; align-items: center; gap: 12px; }
.bar-row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.bar-track { height: 10px; background: var(--line-2); border-radius: 3px; overflow: hidden; display: flex; }
.bar-fill { height: 100%; background: var(--accent); }
.bar-row .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.bar-row.f .bar-fill { background: #b9c2cf; }
.bar-row.s .bar-fill { background: var(--qual); }
.bar-row.c .bar-fill { background: var(--accent); }
.bar-row.p .bar-fill { background: #7e9fd4; }

/* Таблицы */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: default; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink); }
th.r, td.r { text-align: right; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
td.r { font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8f9fb; }
tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; }
.mini { display: inline-flex; height: 6px; width: 90px; border-radius: 2px; overflow: hidden; background: var(--line-2); vertical-align: middle; }
.mini i { display: block; height: 100%; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill.won { background: var(--accent-soft); color: var(--accent); }
.pill.junk { background: #f4eceb; color: var(--bad); }
.pill.ad { background: #eef1f6; color: var(--asphalt); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { color: var(--muted); padding: 28px 0; text-align: center; }

/* Тепловая карта */
.heat { display: grid; grid-template-columns: 26px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 10.5px; color: var(--faint); }
.heat div { aspect-ratio: 1.6; border-radius: 2px; }
.heat .h { text-align: center; aspect-ratio: auto; }
.heat .d { aspect-ratio: auto; line-height: 1.6; }

/* Настройки */
.form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 500; }
.btn:hover { background: #1f56b0; }
.btn.ghost { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--line-2); }
.btn:disabled { opacity: .55; cursor: default; }
pre.code { background: #f7f8fa; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: 12px/1.5 var(--mono); max-height: 260px; overflow: auto; white-space: pre; }
.note { background: #f7f8fa; border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 0 8px 8px 0; color: var(--ink-2); font-size: 13px; }
.status-ok { color: var(--good); }
.status-err { color: var(--bad); }

.gate { max-width: 460px; margin: 18vh auto; text-align: center; color: var(--ink-2); }
.gate h2 { font-weight: 600; margin-bottom: 8px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.search { min-width: 240px; }
