:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #161a22;
  --ink-2: #474d5a;
  --muted: #727988;
  --line: #e2e5ea;
  --line-2: #eef0f3;
  --side: #1f2a44;
  --side-2: #2a3654;
  --side-ink: #c9d2e4;
  --side-ink-hi: #ffffff;
  --accent: #2456c9;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefb;
  --bar: #d6e2f8;
  --good: #1b7f4b;
  --good-soft: #e5f4ec;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #c0352b;
  --bad-soft: #fdeceb;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --heat-0: #eef3fc; --heat-1: #1e4fa8;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(22, 26, 34, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121418; --surface: #1a1d22; --surface-2: #1f2228; --ink: #eceef2; --ink-2: #c1c6d0; --muted: #8e95a3;
    --line: #2d3139; --line-2: #24272e; --side: #0f1524; --side-2: #1b2438; --side-ink: #aab5cc;
    --accent: #5b8cf0; --accent-ink: #0d1220; --accent-soft: #1d2a45; --bar: #243a63;
    --good: #4cc38a; --good-soft: #15291f; --warn: #e3b341; --warn-soft: #2d2410; --bad: #f07167; --bad-soft: #321a19;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --heat-0: #1c2433; --heat-1: #6d9cf2;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121418; --surface: #1a1d22; --surface-2: #1f2228; --ink: #eceef2; --ink-2: #c1c6d0; --muted: #8e95a3;
  --line: #2d3139; --line-2: #24272e; --side: #0f1524; --side-2: #1b2438; --side-ink: #aab5cc;
  --accent: #5b8cf0; --accent-ink: #0d1220; --accent-soft: #1d2a45; --bar: #243a63;
  --good: #4cc38a; --good-soft: #15291f; --warn: #e3b341; --warn-soft: #2d2410; --bad: #f07167; --bad-soft: #321a19;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --heat-0: #1c2433; --heat-1: #6d9cf2;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }
code, .code { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 10px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--side-ink-hi); font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.logo { width: 22px; height: 22px; fill: currentColor; }
.site-pick { display: block; padding: 4px 14px 12px; }
.site-pick select { width: 100%; background: var(--side-2); color: var(--side-ink-hi); border: 1px solid transparent; border-radius: 6px; padding: 7px 8px; }
.nav { padding: 2px 8px 10px; }
.nav-title { color: #8794b0; font-size: 12px; padding: 12px 10px 4px; }
.nav a, .nav summary { display: block; color: var(--side-ink); padding: 5px 10px; border-radius: 6px; font-size: 13.5px; cursor: pointer; }
.nav a:hover, .nav summary:hover { background: var(--side-2); color: var(--side-ink-hi); text-decoration: none; }
.nav a.active { background: var(--side-2); color: var(--side-ink-hi); box-shadow: inset 3px 0 0 #8fb4f0; }
.nav a.dim { opacity: .55; }
.nav details > div { padding-left: 10px; }
.nav summary { list-style: none; color: var(--side-ink-hi); font-weight: 600; font-size: 13px; }
.nav summary::-webkit-details-marker { display: none; }
.nav summary::before { content: "▸"; display: inline-block; width: 14px; color: #8794b0; transition: transform .15s; }
.nav details[open] > summary::before { transform: rotate(90deg); }
.nav-settings { border-top: 1px solid var(--side-2); margin-top: auto; }
.side-foot { padding: 12px 18px 16px; border-top: 1px solid var(--side-2); display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.link-btn { background: none; border: 0; padding: 0; color: #8fb4f0; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 16px; padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.top-title { flex: 1 1 260px; min-width: 0; }
.crumb { color: var(--muted); font-size: 12.5px; }
.top h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.015em; }
.period { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.presets { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.presets button { background: var(--surface); border: 0; border-right: 1px solid var(--line); padding: 6px 10px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.presets button:last-child { border-right: 0; }
.presets button:hover { background: var(--surface-2); }
.presets button.on { background: var(--accent); color: var(--accent-ink); }
.dates { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.dates input { border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; background: var(--surface); font-size: 13px; }
.cmp { font-size: 13px; color: var(--ink-2); gap: 6px; white-space: nowrap; }
.seg-btn.on { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.segbar { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; align-items: end; padding: 14px 28px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.segbar-actions { display: flex; gap: 8px; }
.segline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 9px 28px; background: var(--accent-soft); border-bottom: 1px solid var(--line); font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2px 4px 2px 10px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; padding: 2px 5px; border-radius: 10px; }
.chip button:hover { background: var(--line-2); color: var(--ink); }
.kpi-delta { font-size: 12.5px; margin-top: 3px; font-variant-numeric: tabular-nums; color: var(--muted); }
.kpi-delta .good, td .good { color: var(--good); }
.kpi-delta .bad, td .bad { color: var(--bad); }
.legend i.dashed { background: none !important; border-top: 2px dashed var(--s1); height: 0; width: 14px; border-radius: 0; opacity: .7; }
.view { padding: 22px 28px 60px; max-width: 1500px; width: 100%; }
.view:focus { outline: none; }

.banner { padding: 10px 28px; font-size: 13.5px; border-bottom: 1px solid var(--line); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--accent-soft); color: var(--ink); }

/* ---------- элементы ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 7px 13px; cursor: pointer; font-size: 13.5px; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: inherit; padding: 4px 8px; }
.only-mobile { display: none; }

input[type=text], input[type=search], input[type=password], input[type=url], input[type=number], input:not([type]), select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: var(--surface); width: 100%;
}
textarea { min-height: 120px; font-family: var(--mono); font-size: 12.5px; }
label { display: block; font-size: 13px; color: var(--ink-2); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--ink); }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.check input { width: auto; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; align-items: end; }
.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-top: 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 8px 10px; border-radius: 6px; margin: 0 0 12px; }
.notice { background: var(--good-soft); color: var(--good); padding: 8px 10px; border-radius: 6px; margin: 0 0 12px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.panel > h2, .panel-head { margin: 0; padding: 14px 18px 0; font-size: 15px; font-weight: 650; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding-bottom: 4px; }
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.panel-body { padding: 14px 18px 18px; }
.panel p:first-child { margin-top: 0; }
.note { background: var(--surface-2); border-left: 3px solid var(--line); padding: 9px 12px; color: var(--ink-2); font-size: 13px; border-radius: 0 6px 6px 0; margin: 0 0 16px; }
.empty { padding: 34px 18px; text-align: center; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }

/* ---------- отчёт ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.tabs { display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 5px 11px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.tabs button:hover { background: var(--surface-2); }
.tabs button.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.toolbar .spacer { flex: 1; }
.search { max-width: 240px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 18px; }
.kpi { background: var(--surface); padding: 13px 16px 14px; box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line); }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 25px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; line-height: 1.15; }
.kpi:first-child .kpi-value { color: var(--accent); }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; margin-bottom: 18px; }
.charts .panel { margin: 0; }
.charts .wide { grid-column: 1 / -1; }
.chart-wrap { padding: 8px 14px 12px; position: relative; }
.chart-wrap svg { display: block; width: 100%; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0 18px 4px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.axis text, .chart-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--line-2); }
.baseline { stroke: var(--line); }
.donut-center { fill: var(--ink); font-size: 20px; font-weight: 650; }
.donut-sub { fill: var(--muted); font-size: 11px; }
.crosshair { stroke: var(--muted); stroke-dasharray: 3 3; }
.hit { fill: transparent; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--surface); border-radius: 6px; padding: 7px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.18); max-width: 320px; }
.tooltip b { font-weight: 600; }
.tooltip .row { display: flex; align-items: center; gap: 7px; font-variant-numeric: tabular-nums; }
.tooltip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.donut { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 4px 4px 2px; }
.donut svg { width: 190px; flex: none; }
.donut-legend { flex: 1; min-width: 160px; display: grid; gap: 5px; font-size: 13px; }
.donut-legend .row { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }

.heat-tools { margin: 0; }
.heat-tools select { width: auto; max-width: 380px; }
.heat-wrap { position: relative; overflow-x: hidden; overflow-y: auto; max-height: 760px; border: 1px solid var(--line); border-radius: 6px;
  background: repeating-linear-gradient(0deg, var(--surface-2) 0 39px, var(--line-2) 39px 40px); }
.heat-sizer { position: relative; margin: 0 auto; overflow: hidden; background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.heat-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.heat-stage iframe { position: absolute; inset: 0; border: 0; pointer-events: none; background: #fff; }
.heat-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.live-hint { display: flex; align-items: center; gap: 8px; margin: -6px 0 14px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.rules { display: grid; gap: 10px; }
.rules .check { align-items: flex-start; }
.rules .check input { margin-top: 3px; }
.rule-num { width: 72px !important; display: inline-block; margin: 0 6px; padding: 3px 6px !important; }
.channel { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.share-app { min-height: 100vh; }
.share-top { display: flex; align-items: center; gap: 22px; padding: 14px 28px; background: var(--side); color: var(--side-ink); flex-wrap: wrap; }
.share-top .brand { color: #fff; }
.share-top h1 { margin: 0; font-size: 19px; color: #fff; font-weight: 650; }
.share-top .crumb { color: var(--side-ink); }
.share-app .view { margin: 0 auto; }
.share-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 0 16px 30px; }

/* таблица */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12.5px; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; cursor: pointer; user-select: none; }
table.data th.n, table.data td.n { text-align: right; }
table.data th .arr { color: var(--accent); margin-left: 3px; }
table.data td { padding: 7px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data td.dim { min-width: 150px; max-width: 520px; overflow-wrap: anywhere; }
table.data td.n { white-space: nowrap; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tfoot td { font-weight: 650; border-top: 1px solid var(--line); border-bottom: 0; background: var(--surface-2); }
td.bar-cell { position: relative; }
td.bar-cell .barfill { position: absolute; right: 0; top: 4px; bottom: 4px; background: var(--bar); border-radius: 3px; z-index: 0; max-width: 100%; }
td.bar-cell span { position: relative; z-index: 1; }
.muted { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.pill.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.table-foot { padding: 8px 18px 12px; color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* страницы настроек */
.cards { display: grid; gap: 14px; }
.site-card { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.site-card:last-child { border-bottom: 0; }
.site-card h3 { margin: 0; font-size: 15px; }
.site-meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 12px; flex-wrap: wrap; margin-top: 3px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; }
pre.snippet { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; margin: 8px 0; white-space: pre; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }
.progress { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }
.counts { font-size: 12.5px; color: var(--ink-2); }
.subtabs { margin-bottom: 14px; }

/* диалог, уведомления */
.dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink); width: min(520px, calc(100vw - 32px)); box-shadow: 0 16px 48px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(10, 14, 24, .45); }
.dialog form { padding: 20px 22px 18px; }
.dialog h2 { margin: 0 0 10px; font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 60; font-size: 13.5px; max-width: calc(100vw - 32px); }
.toast.error { background: var(--bad); color: #fff; }
.loading { color: var(--muted); padding: 30px 0; }
.skeleton { height: 220px; border-radius: var(--radius); background: linear-gradient(90deg, var(--line-2), var(--surface-2), var(--line-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* вход */
.login-page { background: var(--side); min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); }
.login-brand { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 20px; font-weight: 650; margin-bottom: 18px; justify-content: center; }
.login-brand .logo { width: 28px; height: 28px; fill: #8fb4f0; }
.login-form { background: var(--surface); border-radius: 12px; padding: 26px 26px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-form h1 { margin: 0 0 16px; font-size: 19px; }
.login-form label { margin-bottom: 12px; }
.login-form .btn { margin-top: 6px; }
.login-foot { text-align: center; color: #8794b0; font-size: 12.5px; margin-top: 14px; }

@media (max-width: 900px) {
  .charts { grid-template-columns: 1fr; }
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .only-mobile { display: inline-block; }
  .top { padding: 12px 16px; }
  .view { padding: 16px 16px 50px; }
  .banner { padding: 10px 16px; }
  .segbar, .segline { padding-left: 16px; padding-right: 16px; }
  .split { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
  .presets button { padding: 6px 7px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
