:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #1a1a19;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6effb;
  --bar: #2a78d6;
  --bar-track: #ecebe7;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s-other: #8f8e86;
  --grid: #e8e7e3;
  --good: #1f7a3a;
  --bad: #b3261e;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  --radius: 10px;
  --ct-fo: #d3dfec; --ct-focus: #dfe8f2; --ct-region: #edf2f8; --ct-comp: #f6f8fb; --ct-total: #cfdbe9;
  --ct-d-head: #e6f2e1; --ct-d-cell: rgba(120, 180, 100, .08); --ct-form: #fffbe6;
  --good-bg: #e3f3e6; --bad-bg: #fdecea; --warn-bg: #fff3d6; --warn: #8a5a00;
  --alert-bg: #fdecea; --alert-fg: #8c1d18;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --accent-soft: #1d2b3d; --bar: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s-other: #8f8e86; --bar-track: #2a2a27; --grid: #2a2a27;
    --good: #5cc27a; --bad: #f08a80; --shadow: none;
    --ct-fo: #26323f; --ct-focus: #22303c; --ct-region: #1d2833; --ct-comp: #19222b; --ct-total: #2a3947;
    --ct-d-head: #22351f; --ct-d-cell: rgba(120, 180, 100, .07); --ct-form: #3a3520;
    --good-bg: #17301f; --bad-bg: #3a1a17; --warn-bg: #3a2e12; --warn: #e0b54d;
    --alert-bg: #3a1a17; --alert-fg: #f08a80;
  }
}
/* выбор темы вручную (переключатель в шапке; тот же ключ, что у админки Django) */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --accent-soft: #1d2b3d; --bar: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s-other: #8f8e86; --bar-track: #2a2a27; --grid: #2a2a27;
    --good: #5cc27a; --bad: #f08a80; --shadow: none;
    --ct-fo: #26323f; --ct-focus: #22303c; --ct-region: #1d2833; --ct-comp: #19222b; --ct-total: #2a3947;
    --ct-d-head: #22351f; --ct-d-cell: rgba(120, 180, 100, .07); --ct-form: #3a3520;
    --good-bg: #17301f; --bad-bg: #3a1a17; --warn-bg: #3a2e12; --warn: #e0b54d;
    --alert-bg: #3a1a17; --alert-fg: #f08a80;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 650; font-size: 16px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-sub { font-weight: 400; font-size: 13px; }
.brand-mark { width: 14px; height: 14px; border-radius: 4px; background: var(--accent); display: inline-block; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-right form { margin: 0; }
.user { color: var(--text-2); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.scope { position: relative; }
.scope summary { list-style: none; cursor: pointer; background: var(--accent-soft); color: var(--text);
  padding: 5px 10px; border-radius: 999px; font-size: 13px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scope summary::-webkit-details-marker { display: none; }
.scope-pop { position: absolute; right: 0; top: calc(100% + 6px); width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.scope-pop ul { margin: 6px 0 8px; padding-left: 18px; }
.scope-title { font-weight: 600; }

.page { padding: 16px 24px 32px; max-width: 1600px; margin: 0 auto; }
.foot-page { padding: 0 24px 24px; max-width: 1600px; margin: 0 auto; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn[aria-disabled="true"] { opacity: .6; pointer-events: none; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.spacer { flex: 1; }
.ms { position: relative; }
.ms-btn { height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; max-width: 260px; }
.ms-btn:hover { border-color: var(--text-2); }
.ms-label { color: var(--text-2); white-space: nowrap; }
.ms-val { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms.active .ms-btn { border-color: var(--accent); background: var(--accent-soft); }
.ms-pop { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; width: 320px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 8px; }
.ms-search { width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.ms-actions { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px; font-size: 12px; color: var(--muted); }
.ms-actions button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.ms-list { max-height: 320px; overflow: auto; }
.ms-item { display: flex; gap: 8px; align-items: flex-start; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.ms-item:hover { background: var(--surface-2); }
.ms-item input { margin-top: 2px; accent-color: var(--accent); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--text-2); font-size: 12px; }
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-unit { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 3px; }
.kpi-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 650; }
.card-head select, .card-head input { height: 30px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); padding: 0 8px; font: inherit; }
.grid > * { min-width: 0; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.side .card { margin-bottom: 16px; }
@media (max-width: 1100px) { .grid { grid-template-columns: 1fr; } }

/* ---------- table ---------- */
.table-card { padding-bottom: 8px; }
.table-wrap { max-height: 720px; overflow: auto; margin: 0 -16px; }
table.rank { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rank th, .rank td { padding: 7px 10px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
.rank th:first-child, .rank td:first-child { padding-left: 16px; }
.rank th:last-child, .rank td:last-child { padding-right: 16px; }
.rank th { position: sticky; top: 0; background: var(--surface); font-weight: 600; color: var(--text-2); font-size: 12px; z-index: 1; }
.rank th[data-sort] { cursor: pointer; user-select: none; }
.rank th[data-sort]:hover { color: var(--text); }
.rank th.sorted::after { content: " ↓"; }
.rank th.sorted.asc::after { content: " ↑"; }
.rank .num { text-align: right; }
.rank td.name { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.rank tbody tr { cursor: pointer; }
.rank tbody tr:hover { background: var(--surface-2); }
.share-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.share-bar { width: 44px; height: 6px; background: var(--bar-track); border-radius: 3px; overflow: hidden; }
.share-bar > i { display: block; height: 100%; background: var(--bar); border-radius: 0 3px 3px 0; }
.foot { padding-top: 8px; }

/* ---------- bar lists ---------- */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; cursor: pointer; padding: 2px 4px; margin: 0 -4px; border-radius: 6px; }
.bar-row:hover { background: var(--surface-2); }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.bar-val { color: var(--text-2); font-variant-numeric: tabular-nums; font-size: 12px; }
.bar-track { grid-column: 1 / -1; height: 8px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.bar-track > i { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; }

/* ---------- trend ---------- */
#trend svg { display: block; width: 100%; height: 220px; }
#trend .axis text { fill: var(--muted); font-size: 11px; }
#trend .gridline { stroke: var(--grid); stroke-width: 1; }
#trend .line { fill: none; stroke: var(--bar); stroke-width: 2; }
#trend .dot { fill: var(--bar); stroke: var(--surface); stroke-width: 2; }
#trend .dot.sel { r: 6; }
#trend .hit { fill: transparent; cursor: pointer; }
#trend .bar { fill: var(--bar); }
.trend-note { color: var(--muted); padding: 8px 0; }

.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--surface);
  padding: 6px 10px; border-radius: 6px; font-size: 12px; max-width: 320px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.loading { position: fixed; bottom: 16px; right: 16px; background: var(--text); color: var(--surface); padding: 6px 12px; border-radius: 6px; font-size: 12px; }
.empty-state { text-align: center; padding: 80px 20px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--text-2); font-size: 13px; }
.login-card input { height: 38px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; background: var(--bg); color: var(--text); font: inherit; }
.login-card .btn { height: 40px; justify-content: center; }
.alert { background: var(--alert-bg); color: var(--alert-fg); padding: 8px 10px; border-radius: 8px; }

@media (max-width: 700px) {
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .page { padding: 12px 16px 24px; }
  .brand-sub, .user { display: none; }
  .topbar-right { flex-wrap: wrap; gap: 10px; width: 100%; }
  .scope { flex: 1 1 100%; } .scope summary { max-width: 100%; }
  .scope-pop { width: calc(100vw - 32px); right: auto; left: 0; }
  .kpi-value { font-size: 22px; }
  .ms-pop { width: min(320px, calc(100vw - 32px)); }
}

/* ---------- всплывающие меню: выгрузка и показатели ---------- */
details.export, details.cols { position: relative; }
details.export > summary, details.cols > summary { list-style: none; }
details.export > summary::-webkit-details-marker, details.cols > summary::-webkit-details-marker { display: none; }
.export-pop, .cols-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px; }
.export-pop { width: 320px; }
.export-pop a { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.export-pop a:hover { background: var(--surface-2); }
.export-pop a span { color: var(--muted); font-size: 12px; }
.cols-pop { width: 260px; max-height: 460px; overflow: auto; }
.cols-presets { display: flex; gap: 6px; padding: 4px 4px 8px; border-bottom: 1px solid var(--grid); margin-bottom: 4px; }
.cols-presets button { flex: 1; height: 28px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); cursor: pointer; }
.cols-presets button:hover { border-color: var(--text-2); }
.card-head .spacer { flex: 1; }
.card-head .btn { height: 30px; }
.rank th { white-space: normal; min-width: 64px; vertical-align: bottom; }
.rank th:nth-child(2) { min-width: 160px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin: -4px 0 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
#trend .line.s { stroke-width: 2; }
#trend .dot.s { stroke: var(--surface); stroke-width: 2; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; }
.section-head h2 { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0; text-transform: uppercase; letter-spacing: .04em; }
details.tiles { position: relative; }
details.tiles > summary { list-style: none; height: 30px; }
details.tiles > summary::-webkit-details-marker { display: none; }
.cols-presets { flex-wrap: wrap; }
.grid.panels-hidden { grid-template-columns: minmax(0, 1fr); }
.grid.panels-hidden .side { display: none; }
.grid.panels-hidden .table-wrap { max-height: 1000px; }
.rank tfoot td { position: sticky; bottom: 0; background: var(--surface-2); font-weight: 650; border-top: 2px solid var(--border); white-space: nowrap; }
.rank tr.nofilter { cursor: default; }

.rebuild-banner { background: var(--accent-soft); color: var(--text); padding: 8px 24px; font-size: 13px; border-bottom: 1px solid var(--border); }
.rebuild-banner.error { background: var(--alert-bg); color: var(--alert-fg); }

/* сети по группам в фильтре */
.ms-item.ms-group { font-weight: 600; border-top: 1px solid var(--border); margin-top: 2px; padding-top: 6px; }
.ms-item.ms-group:first-child { border-top: 0; margin-top: 0; }
.ms-item.ms-child { padding-left: 22px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; cursor: pointer; }

/* навигация */
.nav { display: flex; gap: 4px; margin-left: 24px; margin-right: auto; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 14px; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.on { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* карточка магазина */
.store-search { position: relative; padding: 14px 16px; margin-bottom: 16px; }
.store-search input { width: 100%; font-size: 16px; padding: 10px 12px; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); box-sizing: border-box; }
.sres { position: absolute; left: 16px; right: 16px; top: 100%; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 60vh; overflow: auto; }
.sres-item { display: grid; gap: 2px; width: 100%; text-align: left; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); cursor: pointer; font: inherit; }
.sres-item:hover { background: var(--surface-2); }
.sres-addr { font-size: 13px; }
.small-empty { padding: 24px; }
.store-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin: 4px 0 14px; }
.store-head h2 { margin: 0 0 4px; font-size: 22px; }
.s-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); font-size: 12px; color: var(--muted); }
.store-ctrl { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.store-ctrl label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.store-ctrl select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.mbars { display: flex; gap: 6px; align-items: stretch; height: 170px; padding: 4px 0; overflow-x: auto; }
.mbar { flex: 1 0 54px; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: none; cursor: pointer; padding: 2px; border-radius: 6px; color: var(--text); font: inherit; }
.mbar:hover, .mbar.sel { background: var(--surface-2); }
.mbar-col { flex: 1; width: 60%; display: flex; align-items: flex-end; }
.mbar-col i { display: block; width: 100%; background: var(--bar); border-radius: 3px 3px 0 0; }
.mbar.sel .mbar-col i { background: var(--s2, var(--bar)); }
.mbar-v { font-size: 11px; color: var(--muted); white-space: nowrap; }
.mbar-l { font-size: 11px; color: var(--muted); white-space: nowrap; }
.store-table tr.prod { cursor: pointer; font-weight: 500; }
.store-table tr.prod.open { background: var(--surface-2); }
.store-table tr.prod.in-hold td:first-child { box-shadow: inset 3px 0 0 var(--s3, #c58b2b); }
.store-table tr.sku td { font-size: 12.5px; color: var(--muted); }
.store-table tr.sku td.name { padding-left: 30px; }
.store-table .caret { display: inline-block; width: 16px; color: var(--muted); }
.store-table td.name { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hold-mark { display: inline-block; width: 3px; height: 12px; background: var(--s3, #c58b2b); vertical-align: middle; margin-right: 2px; }
#s-filter { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); min-width: 240px; }

/* региональный отчёт */
.filters-inner { display: contents; }
.region-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 16px; margin-bottom: 14px; }
.region-head h2 { margin: 0 0 4px; font-size: 22px; }
.region-facts { display: flex; gap: 22px; flex-wrap: wrap; }
.fact b { font-size: 18px; font-variant-numeric: tabular-nums; }
.block { margin-bottom: 14px; }
.block .more { margin: 8px 12px 12px; }
.region-table tr.prod { cursor: pointer; }
.region-table tr.prod.open { background: var(--surface-2); }
.region-table tr.in-hold td:first-child { box-shadow: inset 3px 0 0 var(--s3); }
.region-table tr.in-hold { background: color-mix(in srgb, var(--s3) 6%, transparent); }
.region-table tr.nested td.name { padding-left: 26px; }
.region-table tr.hold-row { font-weight: 600; background: color-mix(in srgb, var(--s3) 12%, transparent); }
.region-table tr.sku td { font-size: 12.5px; color: var(--muted); }
.region-table tr.sku td.name { padding-left: 34px; }
.region-table td.name { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.region-table .hold-col { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.region-table .caret, .store-table .caret, .pot-table .caret { display: inline-block; width: 16px; color: var(--muted); }
.summary-card { padding-bottom: 14px; }
.summary-card p { margin: 6px 16px; }
.summary-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 16px 0; }
.warn { color: var(--warn); }
.chk select { padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.block .table-wrap { max-height: none; }
.region-table th, .region-table td { padding-left: 8px; padding-right: 8px; }
.region-table td.name { max-width: 300px; }
.chk select { width: auto; }

/* калькулятор потенциала */
.params-card { padding: 12px 16px; margin-bottom: 14px; }
.params { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-end; }
.params label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.params input, .params select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 15px; }
.params input[type=number] { width: 80px; }
.params-card p { margin: 10px 0 0; }
.pot-wrap { max-height: none; }
.pot-table tr.grp { cursor: pointer; }
.pot-table tr.grp.open { background: var(--surface-2); }
.pot-table tr.sku td { font-size: 12.5px; color: var(--muted); }
.pot-table tr.sku td.name { padding-left: 34px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pot-table th, .pot-table td { padding-left: 7px; padding-right: 7px; }
#p-search { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); min-width: 240px; }
.region-table tfoot tr.sel-tot td { font-weight: 600; color: var(--s3); }
.list-search { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 260px; font-size: 14px; }
.slist-wrap { max-height: 70vh; }
#slist tbody tr { cursor: pointer; }
#slist td.addr { max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13px; }
#s-back { margin: 0 0 10px; }
.chk select { flex: 0 0 auto; max-width: 260px; }
.top-input { width: 64px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }

/* Битрикс24: вкладка «Рынок клиента» */
.b24-page { padding-top: 12px; }
.b24-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; padding: 12px 16px; margin-bottom: 12px; }
.b24-head h2 { margin: 0 0 2px; font-size: 20px; }
.b24-link { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.b24-pick { padding: 0 16px 14px; margin-bottom: 12px; }
.b24-pick form { display: grid; gap: 10px; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2px 16px; }
.pick-search input { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); min-width: 280px; margin-bottom: 6px; }
.b24-pick .btn { justify-self: start; }
.b24-ctrl { display: flex; gap: 14px; align-items: center; margin: 0 0 10px; }
.b24-ctrl select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
tr.clickable { cursor: pointer; }
.grid2 > * { min-width: 0; }
.b24-page .table-wrap { overflow-x: auto; }
.b24-page .rank th, .b24-page .rank td { padding-left: 8px; padding-right: 8px; }

/* ---------- Коммерция ---------- */
.ctabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 14px; border-bottom: 1px solid var(--border); }
.ctabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.ctabs button:hover { color: var(--text); }
.ctabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.c-note { margin: -4px 0 12px; }
.c-ctrl { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 0 0 12px; }
.c-ctrl input[type=search], .pp-search input { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 280px; font: inherit; }
.c-ctrl select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.pp-search { position: relative; }
.pp-search .sres { left: 0; right: auto; min-width: 100%; }
.ctable td, .ctable th { white-space: nowrap; }
.ctable td.ev-cell { white-space: normal; min-width: 260px; }
.hbar { display: inline-block; width: 90px; height: 8px; background: var(--bar-track); border-radius: 4px; vertical-align: middle; margin-right: 8px; overflow: hidden; }
.hbar i { display: block; height: 100%; background: var(--bar); border-radius: 4px; }
.hbar-v { display: inline-block; min-width: 64px; text-align: right; }
.c-local { color: var(--accent); }
.c-up { color: var(--good); }
.c-down { color: var(--bad); }
.tag.st-client { background: var(--good-bg); color: var(--good); }
.tag.st-deal { background: var(--warn-bg); color: var(--warn); }
.tag.st-crm { background: var(--accent-soft); color: var(--accent); }
.tag.ev-good { background: var(--good-bg); color: var(--good); }
.tag.ev-bad { background: var(--bad-bg); color: var(--bad); }
.tag.ev-warn { background: var(--warn-bg); color: var(--warn); }
.tag.ev-info { background: var(--surface-2); color: var(--muted); }
:root { --c-us: #2a78d6; --c-unk: #c9c8c2; }
.split { display: flex; height: 28px; border-radius: 6px; overflow: hidden; margin: 6px 0 10px; background: var(--bar-track); }
.split i { display: block; height: 100%; }
.legend span i { width: 10px; height: 10px; border-radius: 2px; }
.funnel { display: grid; gap: 8px; padding: 6px 2px; }
.f-row { display: grid; grid-template-columns: minmax(120px, 30%) 1fr auto; gap: 10px; align-items: center; }
.f-bar { height: 18px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.f-bar i { display: block; height: 100%; background: var(--bar); }
.f-val { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 12px; }
.pp-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.pp-head h2 { margin: 0 0 4px; font-size: 22px; }
.pp-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pp-over { font-size: 12px; color: var(--text-2); }
.pp-over input { width: 90px; padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.ctable td.small, .ctable td.wrap { white-space: normal; }
.ctable td.wrap { min-width: 170px; }

.c-chains { min-width: 200px; }
.c-comment { max-width: 280px; }

.c-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 8px; }
.c-toolbar input[type=search] { flex: 1 1 260px; max-width: 420px; }
.btn-lite { border: 1px solid var(--border); background: transparent; border-radius: 6px; padding: 3px 10px; cursor: pointer; font: inherit; font-size: 13px; }
.ct-wrap { max-height: 75vh; overflow: auto; }
.ct-tree thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.ct-tree td { white-space: nowrap; }
.ct-tree td.c-comment { white-space: normal; min-width: 220px; }
.ct-tree tr.ct-l0 td { background: var(--ct-focus); font-weight: 600; }
.ct-tree tr.ct-l1 td { background: var(--ct-region); font-weight: 600; }
.ct-tree tr.ct-l2 td { background: var(--ct-comp); font-weight: 600; }
.ct-tree tr[data-lv]:not([data-lv="3"]) { cursor: pointer; }
.ct-tree tr.ct-total td { background: var(--ct-total); }
.ct-tree .caret { display: inline-block; width: 14px; color: var(--muted, #667); }

.spark { display: inline-flex; align-items: flex-end; gap: 2px; height: 22px; vertical-align: middle; }
.spark i { display: block; width: 6px; background: var(--c-us, #2f6fb0); border-radius: 1px; opacity: .8; }
.c-gap { color: var(--warn); }

/* справочник конкурентов: уровни дерева, данные сетей, режим правки */
.ct-tree tr.ct-k-fo td { background: var(--ct-fo); font-weight: 700; }
.ct-tree tr.ct-k-focus td { background: var(--ct-focus); font-weight: 600; }
.ct-tree tr.ct-k-region td { background: var(--ct-region); font-weight: 600; }
.ct-tree tr.ct-k-comp td { background: var(--ct-comp); font-weight: 600; }
.ct-tree tr[data-kind]:not([data-kind="client"]) { cursor: pointer; }
.ct-tree th.ct-d { background: var(--ct-d-head); }
.ct-tree td.ct-d { background-color: var(--ct-d-cell); }
.ct-basis { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 0 0 8px; line-height: 1.45; }
.ct-dlab { background: var(--ct-d-head); padding: 0 4px; border-radius: 3px; }
.ct-matched { font-weight: 400; }
.ct-in { width: 100%; min-width: 70px; font: inherit; font-size: 13px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: inherit; }
.ct-in.num { text-align: right; min-width: 80px; }
textarea.ct-in { min-width: 220px; resize: vertical; }
.ct-in.ct-bad { border-color: var(--bad); }
.ct-in.ct-nomatch { border-color: var(--warn); }
.ct-editing td.ct-name { min-width: 220px; }
.ct-act { white-space: nowrap; }
.btn-x { border: 0; background: transparent; cursor: pointer; color: var(--muted, #667); font-size: 14px; padding: 0 4px; }
.btn-x.sure { color: var(--bad); font-size: 12px; }
.ct-form td { background: var(--ct-form) !important; }
.ct-form-in { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ct-form-in input { min-width: 200px; }
.c-ok { color: var(--good); } .c-err { color: var(--bad); }

.ct-tree td.ct-name { max-width: 340px; white-space: normal; }
.ct-tree td.ct-months { white-space: normal; min-width: 120px; }
.ct-editing input.ct-in:not(.num) { min-width: 150px; }
.ct-editing td.ct-name input.ct-in { min-width: 240px; }

/* ---- Справка ---- */
.help { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 32px; max-width: 1180px; margin: 0 auto; padding: 20px 24px 64px; }
.help-toc { position: sticky; top: 64px; align-self: start; display: flex; flex-direction: column; gap: 2px; max-height: calc(100vh - 80px); overflow: auto; }
.help-toc a { color: var(--text-2); text-decoration: none; padding: 5px 10px; border-radius: 6px; font-size: 13px; }
.help-toc a.sub { padding-left: 22px; font-size: 12.5px; color: var(--muted); }
.help-toc a:hover { background: var(--surface-2); color: var(--text); }
.help-toc a.on { background: var(--accent-soft); color: var(--accent); }
.help-body { max-width: 820px; font-size: 15px; line-height: 1.55; }
.help-body h1 { font-size: 26px; margin: 4px 0 12px; }
.help-body h2 { font-size: 20px; margin: 36px 0 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.help-body h3 { font-size: 16px; margin: 22px 0 6px; }
.help-body h4 { font-size: 14.5px; margin: 16px 0 6px; }
.help-body section, .help-body h3, .help-body tr { scroll-margin-top: 64px; }
.help-body ol, .help-body ul { padding-left: 22px; margin: 6px 0 12px; }
.help-body li { margin: 3px 0; }
.help-t { border-collapse: collapse; width: 100%; margin: 8px 0 14px; font-size: 14px; }
.help-t th, .help-t td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.help-t th { background: var(--surface-2); font-weight: 600; }
.help-t tr:target td { background: var(--accent-soft); }
.help-note { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 6px; padding: 10px 14px; }
.help-green { background: var(--good-bg); color: var(--good); padding: 0 6px; border-radius: 4px; }
.help-faq dt { font-weight: 600; margin-top: 14px; }
.help-faq dd { margin: 4px 0 0; color: var(--text-2); }
.b24-help { white-space: nowrap; }
@media (max-width: 760px) {
  .help { grid-template-columns: 1fr; padding: 12px 16px 48px; gap: 12px; }
  .help-toc { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; }
  .help-toc a.sub { display: none; }
}

/* ---- Переключатель темы ---- */
.theme-btn { border: 1px solid var(--border); background: transparent; color: var(--text-2); border-radius: 999px;
  padding: 3px 10px; font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.theme-btn:hover { background: var(--surface-2); color: var(--text); }
.c-toolbar input[type=search], .c-toolbar input[type=text] { background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }
.c-toolbar input::placeholder { color: var(--muted); }

/* ---------- конкуренты: паспорт, задачи, статусы ---------- */
.kp-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kp-title h2 { margin: 0; font-size: 20px; }
.kp-req { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; color: var(--text-2); }
.kp-head .alert { margin-top: 8px; }
.tag.kst-watch { background: var(--surface-2); color: var(--text-2); }
.tag.kst-study { background: var(--accent-soft); color: var(--accent); }
.tag.kst-talks, .tag.kst-taking { background: var(--warn-bg); color: var(--warn); }
.tag.kst-taken { background: var(--good-bg); color: var(--good); }
.tag.kst-skip, .tag.kst-none, .tag.kst- { background: var(--surface-2); color: var(--muted); }
.kst-form, .kdlg-in { display: flex; flex-direction: column; gap: 10px; }
.kst-form label, .kdlg-in label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); flex: 1; min-width: 0; }
.kst-form input, .kst-form select, .kst-form textarea, .kdlg-in input, .kdlg-in select, .kdlg-in textarea {
  font: inherit; font-size: 13.5px; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; min-width: 0; }
.kst-form input:disabled, .kst-form select:disabled, .kst-form textarea:disabled { opacity: .8; }
.kdlg-row { display: flex; gap: 10px; flex-wrap: wrap; }
.kdlg-btns { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.kdlg { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text);
  padding: 18px 20px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.kdlg::backdrop { background: rgba(0,0,0,.35); }
.kdlg h3 { margin: 0; font-size: 16px; }
.ktasks .kt-done td { color: var(--muted); }
.ktasks .kt-late, .kt-late { color: var(--bad); font-weight: 600; }
.klog { margin-top: 10px; }
.klog ul { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.ks-row { cursor: pointer; }
.ks-row.open td { border-bottom-color: transparent; }
.ks-sub td { background: var(--surface-2); }
.ks-sub table { margin: 4px 0 8px; }
.ks-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.ks-chips button { border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 14px;
  padding: 3px 10px; font: inherit; font-size: 12.5px; cursor: pointer; }
.ks-chips button.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
@media (max-width: 900px) { .kdlg-row { flex-direction: column; } }
