:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-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;
  --track: #cde2fb;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --none: #c3c2b7;
  --none-label: #0b0b0b;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --track: #184f95;
    --good-text: #0ca30c;
    --none: #52514e;
    --none-label: #f0efec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --track: #184f95;
  --good-text: #0ca30c;
  --none: #52514e;
  --none-label: #f0efec;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.hidden { display: none !important; }
h2 { font-size: 16px; margin: 0 0 4px; font-weight: 600; }
kbd { font: 11px ui-monospace, Consolas, monospace; border: 1px solid var(--border); border-radius: 4px;
  padding: 0 4px; margin: 0 1px; background: var(--surface-2); color: var(--text-secondary); }

button, select, input { font: inherit; color: var(--text-primary); }
select, input[type="search"], input[type="text"], input[type="datetime-local"] {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; min-width: 0; }
button { cursor: pointer; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-1); padding: 5px 10px; }
button:hover { background: var(--surface-2); }
.ghost { background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; color: var(--text-primary); }
.ghost:hover { background: var(--surface-2); text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 8px 16px; background: var(--surface-1); border-bottom: 1px solid var(--border); }
.brand { font-weight: 600; }
.tabs { display: flex; gap: 4px; }
.tab { border: none; background: transparent; padding: 6px 12px; border-radius: 6px; color: var(--text-secondary); }
.tab.active { background: var(--accent-wash); color: var(--text-primary); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }

.tabpane { padding: 12px 16px 40px; max-width: 1400px; margin: 0 auto; }

/* ---------- filters (one row above content) ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end; margin-bottom: 10px; }
.filters label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-secondary); }
.filters select { max-width: 220px; }
.filters .grow { flex: 1 1 220px; }
.filters .grow input { width: 100%; }

.listbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 4px 0 10px; }
.listbar-right { display: flex; gap: 12px; align-items: center; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(560px, 1fr)); gap: 10px; align-items: start; }
@media (max-width: 640px) { .cards { grid-template-columns: 1fr; } }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px; position: relative; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-wash); }
.card.done { opacity: 0.62; }
.card-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.card-title { font-size: 16px; font-weight: 600; line-height: 1.25; word-break: break-word; }
.card-sub { color: var(--text-secondary); font-size: 12px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; border-radius: 999px;
  padding: 1px 8px; border: 1px solid var(--border); white-space: nowrap; color: var(--text-secondary); }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pill.st-lead { border-color: var(--good); color: var(--good-text); }
.pill.st-refusal { border-color: var(--critical); color: var(--critical); }
.pill.st-callback { border-color: var(--warning); color: var(--text-primary); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-secondary); }
.badge.nosite { background: var(--accent-wash); color: var(--text-primary); font-weight: 600; }
.badge.broken { color: var(--critical); }

.phones { display: flex; flex-direction: column; gap: 4px; }
.phone-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.phone { font-size: 19px; font-weight: 600; letter-spacing: 0.2px; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.phone:hover { color: var(--accent); }
.phone-kind { font-size: 11px; color: var(--text-muted); }
.icon-btn { border: 1px solid var(--border); background: transparent; border-radius: 6px; padding: 1px 7px; font-size: 12px; color: var(--text-secondary); }
.tg-link { font-size: 12px; }
.links { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.links .lbl { color: var(--text-muted); margin-right: 4px; }
.site-state { font-size: 12px; color: var(--text-secondary); }
.site-state.bad { color: var(--critical); }
.related { font-size: 12px; color: var(--text-secondary); border-left: 2px solid var(--warning); padding-left: 8px; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border-top: 1px solid var(--border); padding-top: 8px; }
.act { font-weight: 600; padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-1); }
.act .k { font-weight: 400; color: var(--text-muted); font-size: 11px; margin-left: 4px; }
.act.lead:hover, .act.lead.on { background: var(--good); border-color: var(--good); color: #fff; }
.act.refusal:hover, .act.refusal.on { background: var(--critical); border-color: var(--critical); color: #fff; }
.act.callback:hover, .act.callback.on { background: var(--warning); border-color: var(--warning); color: #0b0b0b; }
.act.on .k, .act:hover .k { color: inherit; }
.note { flex: 1 1 180px; }
.cb-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: 1px 10px; background: transparent; font-size: 12px; }
.chip:hover { background: var(--surface-2); }
.src { font-size: 12px; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }
.more-wrap { text-align: center; margin: 16px; }
.phones .chip { align-self: flex-start; }
.empty { padding: 40px; text-align: center; color: var(--text-secondary); }

/* ---------- analytics ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.tile .lbl { font-size: 12px; color: var(--text-secondary); }
.tile .val { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); }
.card-block { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg-switch { display: inline-flex; flex-wrap: wrap; gap: 2px; background: var(--surface-2); border-radius: 8px; padding: 2px; }
.seg-switch button { border: none; background: transparent; padding: 4px 10px; border-radius: 6px; font-size: 12px; color: var(--text-secondary); }
.seg-switch button.on { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

/* tall segmented bar */
.segbar { display: flex; gap: 2px; height: 28px; margin: 10px 0 8px; }
.segbar .part { height: 28px; border-radius: 4px; display: flex; align-items: center; padding-left: 8px;
  font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap; overflow: visible; min-width: 0; }
.segbar .part.dark-label { color: var(--none-label); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend b { font-weight: 600; }

/* ranked horizontal bars */
.rank-chart { display: grid; grid-template-columns: minmax(160px, 260px) 1fr; gap: 0 12px; margin-top: 8px; }
.rank-label { font-size: 13px; padding: 4px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-primary); }
.rank-label .n { color: var(--text-muted); font-size: 11px; margin-left: 4px; }
.rank-track { position: relative; display: flex; align-items: center; min-height: 28px; border-left: 1px solid var(--axis); cursor: default; }
.rank-bar { height: 16px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 0; }
.rank-track:hover .rank-bar, .rank-track:focus .rank-bar { filter: brightness(1.12); }
.rank-val { font-size: 12px; margin-left: 6px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* tables */
.table-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; }
.table-wrap.tall { max-height: 720px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; white-space: normal; min-width: 200px; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; font-size: 12px;
  color: var(--text-secondary); cursor: pointer; user-select: none; z-index: 1; }
table.data th.sorted { color: var(--text-primary); }
table.data td { font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: var(--accent-wash); }
.meter { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; }
.meter .track { width: 64px; height: 8px; border-radius: 999px; background: var(--grid); overflow: hidden; display: inline-block; }
.meter .fill { height: 8px; border-radius: 999px; background: var(--series-1); display: block; }
.meter .pct { min-width: 38px; display: inline-block; }
.link-btn { border: none; background: none; color: var(--accent); padding: 0; cursor: pointer; text-align: left; font: inherit; }
.link-btn:hover { text-decoration: underline; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12); max-width: 320px; }
.tooltip .tv { font-size: 15px; font-weight: 600; }
.tooltip .tl { color: var(--text-secondary); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--text-primary);
  color: var(--surface-1); padding: 8px 14px; border-radius: 8px; font-size: 13px; }

/* ---------- Telegram ---------- */
.tab-badge { display: inline-block; margin-left: 4px; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 999px;
  background: var(--accent-wash); color: var(--text-primary); }
.tg-auth { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.tg-auth .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.tg-auth label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-secondary); }
.tg-auth input { min-width: 220px; }
.tg-me { font-size: 15px; }
.tg-me b { font-weight: 600; }
.tg-error { color: var(--critical); font-size: 13px; }
.tg-opts { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: flex-end; margin: 8px 0; }
.tg-opts label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-secondary); }
.tg-opts label.chk { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--text-primary); }
.tg-scope { margin: 6px 0 10px; }
.tg-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.act.tg-start { background: var(--accent); border-color: var(--accent); color: #fff; }
.act.tg-start:disabled, .act:disabled { opacity: 0.45; cursor: not-allowed; }
.tg-state { font-size: 13px; color: var(--text-secondary); }
.tg-state.wait { color: var(--text-primary); }
.progress { position: relative; height: 12px; border-radius: 999px; background: var(--track); overflow: hidden; margin: 6px 0 4px; }
.progress .fill { height: 12px; border-radius: 999px; background: var(--series-1); transition: width 0.4s ease; }
.progress.mini { height: 8px; }
.progress.mini .fill { height: 8px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-secondary); }
.progress-label b { color: var(--text-primary); font-weight: 600; }
.tg-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin: 12px 0; }
.tg-part { margin: 10px 0; font-size: 13px; }
.tg-part .muted { margin-left: 4px; }
.tg-log { font-size: 12px; max-height: 320px; overflow: auto; display: flex; flex-direction: column; gap: 3px; }
.tg-log .ts { color: var(--text-muted); font-variant-numeric: tabular-nums; margin-right: 8px; }

/* ---------- публичная версия: шапка на узком экране ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 6px 12px; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
}
