/* WB Метрики — всё локально, без внешних CDN и шрифтов (сервис работает и без доступа к ним). */

:root {
  color-scheme: light;
  --paper: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #1b2130;
  --ink-2: #4a5263;
  --muted: #7a8292;
  --rule: #e2e5eb;
  --rule-strong: #c9ced8;
  --accent: #4b3bd1;
  --accent-ink: #ffffff;
  --accent-wash: #eceafd;
  --good: #006300;
  --warn-bg: #fff6e0;
  --warn-ink: #6b4a00;
  --bad-bg: #fdeceb;
  --bad-ink: #9b1c1c;
  --focus: 0 0 0 3px rgba(75, 59, 209, 0.35);

  /* данные: проверены валидатором палитры (светлая поверхность #ffffff) */
  --series-total: #2a78d6;   /* все заказы */
  --series-ads: #eb6834;     /* всё, что про рекламу */
  --series-search: #1baf7a;  /* портрет: поиск */
  --series-main: #eda100;    /* портрет: главная */
  --series-card: #e87ba4;    /* портрет: карточка товара */
  --series-other: #c3c8d2;   /* портрет: прочие точки входа */
  --grid: #e8eaef;
  --axis: #c9ced8;

  --radius: 10px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --paper: #0f1218;
    --surface: #171b23;
    --surface-2: #1d222c;
    --ink: #eef0f4;
    --ink-2: #b9bfcc;
    --muted: #8a92a3;
    --rule: #2a303b;
    --rule-strong: #3a4250;
    --accent: #8f84f0;
    --accent-ink: #11131a;
    --accent-wash: #262243;
    --good: #0ca30c;
    --warn-bg: #2e2612;
    --warn-ink: #f2cf7a;
    --bad-bg: #351b1b;
    --bad-ink: #f3a3a3;
    --series-total: #3987e5;
    --series-ads: #d95926;
    --series-search: #199e70;
    --series-main: #c98500;
    --series-card: #d55181;
    --series-other: #4a5160;
    --grid: #252a34;
    --axis: #3a4250;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0f1218;
  --surface: #171b23;
  --surface-2: #1d222c;
  --ink: #eef0f4;
  --ink-2: #b9bfcc;
  --muted: #8a92a3;
  --rule: #2a303b;
  --rule-strong: #3a4250;
  --accent: #8f84f0;
  --accent-ink: #11131a;
  --accent-wash: #262243;
  --good: #0ca30c;
  --warn-bg: #2e2612;
  --warn-ink: #f2cf7a;
  --bad-bg: #351b1b;
  --bad-ink: #f3a3a3;
  --series-total: #3987e5;
  --series-ads: #d95926;
  --series-search: #199e70;
  --series-main: #c98500;
  --series-card: #d55181;
  --series-other: #4a5160;
  --grid: #252a34;
  --axis: #3a4250;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 var(--font);
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ------------------------------------------------ шапка */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-weight: 650; font-size: 16px; }
.brand svg { flex: none; }
.topnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.topnav a, .topnav button {
  color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 8px; font: inherit; font-size: 14px;
  background: none; border: 0; cursor: pointer;
}
.topnav a:hover, .topnav button:hover { background: var(--surface-2); color: var(--ink); }
.topnav a[aria-current="page"] { color: var(--ink); background: var(--accent-wash); }
.topnav form { margin: 0; }
.topnav .short { display: none; }

.page { max-width: 1240px; margin: 0 auto; padding: 18px 20px 48px; }
.page-narrow { max-width: 640px; }

/* ------------------------------------------------ сообщения */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; border: 1px solid transparent; }
.flash.success { background: #e9f6ea; color: #14501a; border-color: #cde8cf; }
.flash.warning { background: var(--warn-bg); color: var(--warn-ink); border-color: #f0dfb0; }
.flash.error { background: var(--bad-bg); color: var(--bad-ink); border-color: #f2c9c6; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .flash.success { background: #16301a; color: #a7e3ad; border-color: #23462a; }
  :root:where(:not([data-theme="light"])) .flash.warning { border-color: #4a3d16; }
  :root:where(:not([data-theme="light"])) .flash.error { border-color: #5a2a2a; }
}

/* ------------------------------------------------ формы и кнопки */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule-strong); border-radius: 8px; padding: 9px 11px; min-height: 40px;
}
textarea { min-height: 96px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: 14px; font-weight: 550; line-height: 1;
  padding: 0 14px; min-height: 38px; border-radius: 8px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.danger { color: var(--bad-ink); }
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------ панели */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; }
.panel + .panel { margin-top: 14px; }
.panel-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h1, .panel-head h2 { margin-right: auto; }
.panel-head .src { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------ вход / регистрация */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .panel { width: 100%; max-width: 380px; padding: 24px; }
.auth h1 { margin-bottom: 4px; }
.auth .lead { color: var(--ink-2); margin-bottom: 18px; font-size: 14px; }

/* ------------------------------------------------ фильтры дашборда */
.filters {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
  padding: 10px 0 12px; margin-bottom: 6px; border-bottom: 1px solid var(--rule);
}
.filters .group { display: flex; flex-direction: column; gap: 5px; }
.filters .group > .cap { font-size: 12px; color: var(--muted); }
.filters .spacer { flex: 1 1 0; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button {
  font: inherit; font-size: 13px; padding: 0 11px; min-height: 38px; border: 0; background: none; color: var(--ink-2); cursor: pointer;
  white-space: nowrap;
}
.seg button + button { border-left: 1px solid var(--rule); }
.seg button[aria-pressed="true"] { background: var(--accent-wash); color: var(--ink); font-weight: 600; }
.dates { display: flex; align-items: center; gap: 6px; }
.dates input { width: 142px; min-height: 38px; padding: 6px 8px; }
.dates span { color: var(--muted); }

/* выбор артикулов */
.picker { position: relative; }
.picker > .btn { min-width: 200px; justify-content: space-between; }
.picker-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: min(440px, 92vw);
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(15, 18, 28, 0.16); padding: 12px;
}
.picker-panel[hidden] { display: none; }
.picker-list { list-style: none; margin: 10px 0; padding: 0; max-height: 320px; overflow: auto; border-top: 1px solid var(--rule); }
.picker-list li { border-bottom: 1px solid var(--rule); }
.picker-list label { display: grid; grid-template-columns: 20px 1fr; gap: 2px 10px; padding: 8px 4px; cursor: pointer; }
.picker-list label:hover { background: var(--surface-2); }
.picker-list input { grid-row: span 2; margin-top: 3px; accent-color: var(--accent); }
.picker-list .t { font-weight: 550; overflow-wrap: anywhere; }
.picker-list .s { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.picker-empty { padding: 14px 4px; color: var(--muted); font-size: 14px; }

/* ------------------------------------------------ статус загрузки */
.syncbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: 8px; margin: 10px 0 4px; font-size: 14px; background: var(--surface); border: 1px solid var(--rule); }
.syncbar[hidden] { display: none; }
.syncbar .msg { flex: 1 1 260px; color: var(--ink-2); }
.syncbar.error { background: var(--bad-bg); border-color: transparent; color: var(--bad-ink); }
.syncbar.error .msg { color: var(--bad-ink); }
.syncbar.warn { background: var(--warn-bg); border-color: transparent; }
.syncbar.warn .msg { color: var(--warn-ink); }
.track { flex: 1 1 140px; height: 6px; background: var(--rule); border-radius: 99px; overflow: hidden; min-width: 120px; }
.track > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }

/* ------------------------------------------------ сводка: три блока */
.summary { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; margin-top: 14px; }
.summary > .panel, .charts > .panel { margin: 0; }
.span-12 { grid-column: span 12; }
.span-7 { grid-column: span 7; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
@media (max-width: 900px) {
  .span-7, .span-5, .span-6 { grid-column: span 12; }
}
.refetching { opacity: 0.5; transition: opacity 0.2s; }

.big { font-size: 34px; font-weight: 650; line-height: 1.1; letter-spacing: -0.02em; }
.big small { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.label { font-size: 13px; color: var(--ink-2); }

/* цепочка рекламы: показы → клики → заказы */
.chain { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: stretch; gap: 0; }
.chain .node { padding: 4px 0; min-width: 0; }
.chain .node .v { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; overflow-wrap: anywhere; }
.chain .node .sub { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.chain .node .sub b { color: var(--ink); font-weight: 600; }
.chain .link { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 14px; color: var(--muted); font-size: 12px; text-align: center; }
.chain .link svg { display: block; margin: 4px 0; }
.chain .link .r { font-size: 14px; color: var(--ink); font-weight: 600; white-space: nowrap; }
.spendline { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--rule); }
.spendline .item .v { font-size: 20px; font-weight: 650; }
.spendline .item .k { font-size: 12px; color: var(--muted); }
@media (max-width: 620px) {
  .chain { grid-template-columns: 1fr; }
}

/* метр: доля РК */
.meter { height: 10px; border-radius: 99px; background: color-mix(in srgb, var(--series-total) 22%, var(--surface)); overflow: hidden; margin: 14px 0 8px; display: flex; }
.meter > i { display: block; height: 100%; background: var(--series-ads); }
.meter-legend { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.key { display: inline-flex; align-items: center; gap: 6px; }
.key::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--muted)); flex: none; }
.key.line::before { height: 2px; width: 14px; border-radius: 2px; }

/* структура показов: одна полоса из частей */
.stackbar { display: flex; height: 14px; gap: 2px; margin: 14px 0 10px; }
.stackbar > i { display: block; height: 100%; min-width: 2px; }
.stackbar > i:first-child { border-radius: 4px 0 0 4px; }
.stackbar > i:last-child { border-radius: 0 4px 4px 0; }
.stackbar > i:only-child { border-radius: 4px; }
.parts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 16px; }
.parts .p .v { font-size: 18px; font-weight: 650; }
.parts .p .k { font-size: 13px; color: var(--ink-2); }
.empty { color: var(--ink-2); font-size: 14px; max-width: 64ch; }
.empty p { margin-bottom: 12px; }

/* ------------------------------------------------ графики */
.charts { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; margin-top: 14px; }
.chart-box { position: relative; width: 100%; }
.chart-box svg { display: block; width: 100%; overflow: visible; }
.chart-box .nodata { color: var(--muted); font-size: 14px; padding: 40px 0; text-align: center; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 18, 28, 0.14); padding: 8px 10px; font-size: 13px;
}
.chart-tip[hidden] { display: none; }
.chart-tip .d { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.chart-tip .row { display: flex; align-items: center; gap: 8px; }
.chart-tip .row b { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 56px; }
.chart-tip .row i { width: 12px; height: 2px; border-radius: 2px; flex: none; }
.chart-tip .row span { color: var(--ink-2); }
.axis-text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.end-label { font-size: 12px; fill: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-box line.grid { stroke: var(--grid); stroke-width: 1; }
.chart-box line.baseline { stroke: var(--axis); stroke-width: 1; }
.chart-box line.crosshair { stroke: var(--rule-strong); stroke-width: 1; }
.chart-box path.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-box circle.ring { stroke: var(--surface); stroke-width: 2; }
.chart-box g.col { transition: opacity 0.12s; }
.chart-box g.col.dim { opacity: 0.45; }
.chart-box rect.hit { cursor: crosshair; outline: none; }
.chart-box rect.hit:focus-visible { stroke: var(--accent); stroke-width: 2; }

/* ------------------------------------------------ таблицы */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
table.data th { background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: 12px; white-space: normal; min-width: 84px; vertical-align: bottom; }
table.data thead tr.groups th { font-weight: 500; color: var(--muted); font-size: 11px; text-align: left; border-bottom: 1px solid var(--rule); padding-top: 7px; padding-bottom: 5px; }
table.data thead tr.groups th + th { border-left: 1px solid var(--rule); }
table.data th.gstart, table.data td.gstart { border-left: 1px solid var(--rule); }
table.data th:first-child, table.data td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 2; }
table.data th:first-child { background: var(--surface-2); z-index: 3; }
table.data tr.total td { font-weight: 650; background: var(--surface-2); }
table.data tr.total td:first-child { background: var(--surface-2); }
table.data td.text { text-align: left; white-space: normal; min-width: 180px; max-width: 280px; }
table.data td .sub { display: block; color: var(--muted); font-size: 12px; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover td { background: var(--surface-2); }
table.data .na { color: var(--muted); }

/* ------------------------------------------------ кабинеты */
.acc { display: grid; gap: 10px; }
.acc .row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.scope { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); }
.scope.ok::before { content: "✓"; color: var(--good); font-weight: 700; }
.scope.no::before { content: "✕"; color: var(--bad-ink); font-weight: 700; }
details.more summary { cursor: pointer; color: var(--ink-2); font-size: 14px; }
details.more[open] summary { margin-bottom: 10px; }
.steps { padding-left: 20px; margin: 8px 0 0; color: var(--ink-2); font-size: 14px; }
.steps li { margin-bottom: 6px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

@media (max-width: 620px) {
  .page { padding: 12px 16px 40px; }
  .topbar { padding: 8px 16px; gap: 4px 8px; }
  .topnav { margin-left: 0; width: 100%; flex-wrap: nowrap; overflow-x: auto; gap: 2px; }
  .topnav a, .topnav button { padding: 6px 8px; white-space: nowrap; }
  .topnav .long { display: none; }
  .topnav .short { display: inline; }
  .filters .group { flex: 1 1 100%; }
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1 1 auto; padding: 0 6px; }
  .filters .group:last-child { flex: 1 1 100%; }
  .filters .group:last-child .btn-row > * { flex: 1 1 0; }
  .filters .spacer { display: none; }
  .chain .node { display: grid; grid-template-columns: 1fr auto; align-items: end; column-gap: 12px; padding: 2px 0; }
  .chain .node .label { grid-column: 1 / -1; }
  .chain .node .sub { margin: 0 0 4px; text-align: right; }
  .chain .link { flex-direction: row; justify-content: flex-start; align-items: baseline; gap: 6px; padding: 4px 0 8px; }
  .chain .link svg { display: none; }
  .chain .link::before { content: "↓"; font-size: 15px; color: var(--muted); }
  .panel { padding: 14px; }
  .big { font-size: 28px; }
  .chain .node .v { font-size: 24px; }
  .dates input { width: 132px; }
  .picker > .btn { min-width: 0; width: 100%; }
  .filters .group.grow { flex: 1 1 100%; }
}
