:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeeb;
  --line: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #1f8a4c;
  --good-bg: #e3f3e9;
  --warn: #b26b00;
  --warn-bg: #fbf0dc;
  --bad: #c9302c;
  --bad-bg: #fbe5e4;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8d8c85;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #4cc27c;
    --good-bg: #16301f;
    --warn: #e2a33a;
    --warn-bg: #33270f;
    --bad: #f07470;
    --bad-bg: #3a1a19;
  }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8d8c85;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #4cc27c;
    --good-bg: #16301f;
    --warn: #e2a33a;
    --warn-bg: #33270f;
    --bad: #f07470;
    --bad-bg: #3a1a19;
  }
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1180px; margin: 0 auto; padding-block: 0 48px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* шапка и навигация — горизонтальная лента на телефоне */
header.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1180px; margin: 0 auto; padding-block: 10px 0; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.brand { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 17px; }
.brand .out { font-weight: 400; font-size: 13px; color: var(--muted); }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 0 0; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  white-space: nowrap; padding: 8px 12px 10px; color: var(--text-2); border-bottom: 2px solid transparent;
  font-weight: 500;
}
nav.tabs a.on { color: var(--text); border-color: var(--accent); }
nav.tabs a:hover { text-decoration: none; color: var(--text); }

h1 { font-size: 22px; margin: 22px 0 14px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--text-2); font-size: 13px; }
.muted { color: var(--muted); }

.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.kpi .label { color: var(--text-2); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.section { margin-top: 18px; }

.chart-box { position: relative; height: 240px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* таблицы прокручиваются внутри карточки, а не всей страницей */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.good { color: var(--good); background: var(--good-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.idle { color: var(--text-2); background: var(--surface-2); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--text-2); font-size: 13px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip:hover { text-decoration: none; }

form.inline { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
button, .btn {
  font: inherit; font-weight: 600; border: none; border-radius: 10px; padding: 9px 14px; cursor: pointer;
  background: var(--accent); color: #fff; display: inline-block;
}
button.ghost, .btn.ghost { background: var(--surface-2); color: var(--text); }
button.danger { background: var(--bad-bg); color: var(--bad); }
.btn:hover { text-decoration: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.space { justify-content: space-between; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--good-bg); color: var(--good); margin-bottom: 12px; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.events { list-style: none; padding: 0; margin: 0; }
.events li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.events li:last-child { border-bottom: none; }
.events .ts { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 92px; padding-top: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; margin-top: 7px; }
.dot.ok { background: var(--good); } .dot.info { background: var(--muted); }
.dot.warn { background: var(--warn); } .dot.error { background: var(--bad); }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.big-profit.pos { color: var(--good); } .big-profit.neg { color: var(--bad); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
.login { max-width: 360px; margin: 14vh auto; }
.login input { width: 100%; margin: 12px 0; }
.login button { width: 100%; }
fieldset { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 14px; background: var(--surface); }
legend { font-weight: 600; padding: 0 6px; }
.setting { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: none; }
.setting input[type=number], .setting input[type=text] { width: 120px; }
.locked { opacity: .55; }
@media (max-width: 560px) {
  .kpi .value { font-size: 22px; }
  .setting { flex-direction: column; align-items: stretch; }
  .setting input[type=number], .setting input[type=text] { width: 100%; }
}

/* группы клиентов и рассылка */
.seg-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.seg-card { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--text); cursor: pointer; position: relative; }
.seg-card:hover { text-decoration: none; border-color: var(--accent); }
.seg-card.on, .radio-card:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.seg-card .seg-n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.seg-card .seg-t { font-size: 12px; color: var(--text-2); }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.stack-f { display: flex; flex-direction: column; min-width: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-row .chip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chip-row .chip:has(input:checked) { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip-row .chip input { display: none; }
.fmt-bar { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.fmt-bar button { padding: 6px 12px; }
.fmt-bar .sub { margin-left: auto; font-variant-numeric: tabular-nums; }
.preview-box { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.tg-chat { display: flex; flex-direction: column; gap: 4px; max-width: 360px; }
.tg-bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.tg-kb { display: grid; gap: 4px; }
.tg-kb span { text-align: center; padding: 8px; border-radius: 10px; background: var(--surface-2); color: var(--accent); font-weight: 600; font-size: 13px; }

/* история рассылок и сворачиваемые блоки */
.bc-list { display: flex; flex-direction: column; }
.bc-row { display: flex; flex-direction: column; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.bc-row:last-child { border-bottom: none; }
.bc-text { color: var(--text-2); font-size: 14px; }
.bc-bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bc-bar i { display: block; height: 100%; background: var(--good); }
.bc-row form { align-self: flex-start; }
details.fold summary { cursor: pointer; font-weight: 600; padding: 8px 0; }

button.armed { background: var(--bad); color: #fff; }
