:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --funnel-1: #86b6ef;
  --funnel-2: #5598e7;
  --funnel-3: #2a78d6;
  --funnel-4: #1c5cab;
  --funnel-5: #104281;
  --good: #006300;
  --bad: #d03b3b;
  --warn: #fab219;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --funnel-1: #184f95;
    --funnel-2: #1c5cab;
    --funnel-3: #256abf;
    --funnel-4: #3987e5;
    --funnel-5: #6da7ec;
    --good: #0ca30c;
    --bad: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --funnel-1: #184f95;
  --funnel-2: #1c5cab;
  --funnel-3: #256abf;
  --funnel-4: #3987e5;
  --funnel-5: #6da7ec;
  --good: #0ca30c;
  --bad: #e66767;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* шапка */
.top {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 15px; color: var(--ink); white-space: nowrap; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.who { color: var(--muted); font-size: 12px; white-space: nowrap; }
.who a { margin-left: 8px; }

.page { max-width: 1480px; margin: 0 auto; padding: 20px 24px 48px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.head .sub { color: var(--muted); margin-top: 4px; }

/* период */
.period { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.period a, .period button {
  font: inherit; font-size: 13px; padding: 5px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.period a.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.period input[type=date] {
  font: inherit; font-size: 13px; padding: 4px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}

/* карточки и сетки */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; min-width: 0; }
.grid { display: grid; gap: 12px; margin-bottom: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) { .g2, .g3 { grid-template-columns: 1fr; } }

.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 600; margin: 4px 0 2px; white-space: nowrap; }
.tile .foot { font-size: 12px; color: var(--muted); }
.tile.hero .value { font-size: 28px; }
.d { font-weight: 600; white-space: nowrap; }
.d.good { color: var(--good); }
.d.bad { color: var(--bad); }
.d.flat { color: var(--muted); }

/* воронка */
.funnel { display: flex; flex-direction: column; gap: 10px; }
.fstep { display: grid; grid-template-columns: 170px 1fr 92px; gap: 12px; align-items: center; }
.fstep .name { color: var(--ink-2); }
.fstep .bar { height: 22px; background: var(--surface-2); border-radius: 0 4px 4px 0; position: relative; }
.fstep .bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; min-width: 2px; }
.fstep .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.fconv { margin-left: 182px; color: var(--muted); font-size: 12px; margin-top: -6px; }
.fconv b { color: var(--ink-2); }
@media (max-width: 600px) {
  .fstep { grid-template-columns: 110px 1fr 70px; }
  .fconv { margin-left: 122px; }
}

/* графики */
.chart { position: relative; height: 220px; }
.chart.tall { height: 280px; }

/* таблицы */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none; }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td { font-variant-numeric: tabular-nums; }
th:first-child, td:first-child, td.l, th.l { text-align: left; }
tbody tr:hover { background: var(--surface-2); }
td .pname { display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
td .pmeta { color: var(--muted); font-size: 12px; }
tr.total td { font-weight: 600; border-top: 1px solid var(--axis); }
.thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--surface-2); vertical-align: middle; margin-right: 8px; }
.cellp { display: flex; align-items: center; }

/* плашки */
.note { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid var(--border); background: var(--surface); }
.note.warn { border-left: 3px solid var(--warn); }
.note.err { border-left: 3px solid var(--bad); }
.note.ok { border-left: 3px solid var(--good); }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); }
.badge.ok { color: var(--good); }
.badge.error { color: var(--bad); }

/* формы */
form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
input[type=text], input[type=password], select, input[type=file] {
  font: inherit; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}
button.primary { font: inherit; font-weight: 600; padding: 8px 16px; border-radius: 6px; border: 0; background: var(--accent); color: #fff; cursor: pointer; }
button.link { font: inherit; border: 0; background: none; color: var(--bad); cursor: pointer; padding: 0; }

.login { max-width: 360px; margin: 12vh auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 600px) {
  .top, .page { padding-left: 16px; padding-right: 16px; }
  .top { gap: 8px 16px; }
  .brand { order: 1; }
  .who { order: 2; margin-left: auto; }
  .nav { order: 3; flex: 0 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .nav a { white-space: nowrap; }
  .tiles, .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px; }
  .tile .value, .tile.hero .value { font-size: 19px; }
  .who { font-size: 11px; }
}

/* переключатель день/неделя */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg a { border: 0 !important; border-radius: 0 !important; }
.seg a.on { background: var(--accent-wash); }

/* мини-графики в таблицах */
svg.spark { display: block; overflow: visible; }
svg.spark polyline { fill: none; stroke: var(--c); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
svg.spark circle { fill: var(--c); stroke: var(--surface); stroke-width: 1.5; }
td.sp { padding-top: 4px; padding-bottom: 4px; }
td .sub2 { display: block; font-size: 11px; }

/* выбор показателя */
.metrics { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.metrics .grp { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.metrics .grp b { font-size: 12px; color: var(--muted); font-weight: 500; width: 72px; }
.metrics a { font-size: 13px; padding: 4px 10px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); }
.metrics a.on { border-color: var(--accent); background: var(--accent-wash); color: var(--accent); font-weight: 600; }

/* матрица динамики */
table.dyn th, table.dyn td { padding: 6px 8px; font-size: 12px; }
table.dyn td.h { min-width: 52px; }
table.dyn td .pname { max-width: 200px; }
table.dyn th:first-child, table.dyn td:first-child { position: sticky; left: 0; z-index: 2; background: var(--surface); box-shadow: 1px 0 0 var(--grid); }
table.dyn thead th:first-child { z-index: 3; }
table.dyn th.sum, table.dyn td.sum { font-weight: 600; }
table.dyn th.chg, table.dyn td.chg { border-right: 1px solid var(--axis); }
.legend-heat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-heat i { display: inline-block; width: 64px; height: 10px; border-radius: 2px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 6%, transparent), color-mix(in srgb, var(--accent) 46%, transparent)); }

.skuswitch { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.skuswitch a { font-size: 12px; padding: 3px 9px; border-radius: 12px; border: 1px solid var(--border); color: var(--ink-2); background: var(--surface); }
.skuswitch a.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.g3c { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g3c { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .g3c { grid-template-columns: 1fr; } }

/* общий график с переключаемыми показателями */
.combo .chips { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.combo .chips .grp { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.combo .chips .grp b { font-size: 12px; color: var(--muted); font-weight: 500; width: 72px; }
.combo .chip { font: inherit; font-size: 12px; padding: 3px 10px 3px 8px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.combo .chip i { width: 10px; height: 10px; border-radius: 3px; border: 1px solid var(--axis); background: transparent; }
.combo .chip.on { color: var(--ink); border-color: var(--axis); font-weight: 600; }
.combo .chip:disabled { opacity: .45; cursor: not-allowed; }
.combo .chart { height: 360px; }
.combo .mode { font-size: 12px; color: var(--muted); margin-top: 8px; }
@media (max-width: 600px) { .combo .chart { height: 280px; } .combo .chips .grp b { width: 100%; } }

/* регионы */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); white-space: nowrap; margin-right: 10px; }
.st i { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; font-style: normal; font-size: 10px; font-weight: 700; color: #fff; }
.st-out i { background: var(--bad); } .st-out i::before { content: "✕"; }
.st-low i { background: var(--warn); color: #3b2a00; } .st-low i::before { content: "!"; }
.st-ok i { background: var(--good); } .st-ok i::before { content: "✓"; }
.st-idle i { background: var(--surface-2); border: 1px solid var(--axis); color: var(--muted); } .st-idle i::before { content: "·"; }
.lg { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; }
.lg i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
td.shares { min-width: 170px; }
.sbar { display: flex; align-items: center; gap: 6px; height: 9px; margin: 2px 0; }
.sbar i { display: block; height: 7px; border-radius: 0 4px 4px 0; min-width: 0; }
.sbar em { font-style: normal; font-size: 11px; color: var(--muted); }
table.matrix th.cl { white-space: normal; min-width: 64px; max-width: 96px; text-align: center; line-height: 1.2; vertical-align: bottom; }
table.matrix td.mc { text-align: center; min-width: 64px; border-left: 2px solid var(--surface); }
table.matrix td.mc b { display: block; font-size: 14px; }
table.matrix td.mc .sub2 { color: var(--ink-2); }
td.mc.m-out { background: color-mix(in srgb, var(--bad) 16%, transparent); }
td.mc.m-low { background: color-mix(in srgb, var(--warn) 22%, transparent); }
td.mc.m-ok { background: color-mix(in srgb, var(--good) 10%, transparent); }
td.mc.m-idle { background: var(--surface-2); }
.st.ic { margin: 0 3px 0 0; vertical-align: -2px; }
.st.ic i { width: 12px; height: 12px; font-size: 9px; }
.legend-st { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; }

/* пользователи */
.nav .count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.login .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.login .pair input { width: 100%; box-sizing: border-box; min-width: 0; }
form.act { display: inline-flex; gap: 6px; align-items: center; margin: 0 0 0 10px; }
td.acts { white-space: nowrap; }
button.sm { font-size: 13px; padding: 5px 12px; }
button.ghost { font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); cursor: pointer; }
button.link2 { font: inherit; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; }
input.sm { padding: 4px 8px; font-size: 13px; width: 140px; }
