/* Приказчик — кабинет биддера. Токены цвета — из справочника палитры (светлая и тёмная темы — свои ступени). */
:root {
  color-scheme: light;
  --page: #f5f5f3; --surface: #fcfcfb; --surface-2: #f0efec; --line: #e1e0d9; --line-strong: #c3c2b7;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --accent: #2a78d6; --accent-ink: #ffffff; --accent-soft: #e6f0fc;
  --good: #0ca30c; --good-ink: #006300; --warn: #fab219; --warn-ink: #8a5a00; --bad: #d03b3b; --bad-ink: #b02a2a;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --ring: rgba(11, 11, 11, .10); --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 4px 16px rgba(11, 11, 11, .04);
  --tg-bg: #dfe7d6; --tg-bubble: #ffffff; --tg-name: #2a78d6; --tg-btn: #2a78d6;
  --r: 12px; --r-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --line: #2c2c2a; --line-strong: #383835;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --accent: #3987e5; --accent-soft: #16263a;
    --good-ink: #0ca30c; --warn-ink: #fab219; --bad-ink: #e66767;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --ring: rgba(255, 255, 255, .10); --shadow: none;
    --tg-bg: #0f1a24; --tg-bubble: #1e2c3a; --tg-name: #6ab3f3; --tg-btn: #6ab3f3;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --line: #2c2c2a; --line-strong: #383835;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --accent: #3987e5; --accent-soft: #16263a;
  --good-ink: #0ca30c; --warn-ink: #fab219; --bad-ink: #e66767;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --ring: rgba(255, 255, 255, .10); --shadow: none;
  --tg-bg: #0f1a24; --tg-bubble: #1e2c3a; --tg-name: #6ab3f3; --tg-btn: #6ab3f3;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; color: var(--ink-2); }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 13px; }

/* ---- каркас ---- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 650; font-size: 16px; color: var(--ink); }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 16px; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-sm); color: var(--ink-2); font-weight: 500; }
.side a.nav:hover { background: var(--surface-2); text-decoration: none; }
.side a.nav.on { background: var(--accent-soft); color: var(--accent); }
.side a.nav svg { width: 18px; height: 18px; flex: none; }
.side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; }
.side .foot form { margin: 6px 0 0; }
.main { padding: 24px 28px 64px; min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.tabbar { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 16px 16px 96px; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
            padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 6px; min-width: 56px; }
  .tabbar a.on { color: var(--accent); }
  .tabbar svg { width: 22px; height: 22px; }
  h1 { font-size: 20px; }
}

/* ---- карточки и плитки ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { font-size: 12.5px; color: var(--muted); }
.kpi .v { font-size: 26px; font-weight: 650; line-height: 1.2; margin-top: 4px; letter-spacing: -.01em; }
.kpi .s { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g2 { grid-template-columns: 1fr; } .kpi .v { font-size: 22px; } }

/* ---- полоса ошибок ---- */
.alert { border-radius: var(--r); padding: 12px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; font-size: 14px; border: 1px solid; }
.alert.bad { background: color-mix(in srgb, var(--bad) 8%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.alert.warn { background: color-mix(in srgb, var(--warn) 12%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.alert b { display: block; }

/* ---- переключатели окна ---- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a { padding: 6px 12px; border-radius: 8px; color: var(--ink-2); font-size: 13.5px; font-weight: 500; }
.seg a:hover { text-decoration: none; color: var(--ink); }
.seg a.on { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
select, input[type=email], input[type=text], input[type=number] {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 8px 12px; }
select { padding-right: 28px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

/* ---- кнопки ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; border-radius: 10px; padding: 10px 16px;
       border: 1px solid transparent; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line-strong); font-weight: 500; }
.btn.wide { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; text-decoration: underline; }

/* ---- таблицы ---- */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.t th { position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
        padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
.t th.n, .t td.n { text-align: right; }
.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: var(--surface-2); }
.t tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; }
.t .lbl { font-weight: 600; color: var(--ink); }
.t .sorted::after { content: " ↓"; } .t .sorted.asc::after { content: " ↑"; }
.cellbar { display: inline-block; height: 6px; border-radius: 3px; background: var(--series-1); vertical-align: middle; margin-left: 6px; opacity: .85; }

/* ---- метки статуса: цвет + значок + слово ---- */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 500; padding: 2px 8px 2px 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.st::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.st.active { color: var(--good-ink); } .st.active::before { background: var(--good); }
.st.limit { color: var(--warn-ink); } .st.limit::before { background: var(--warn); }
.st.bad { color: var(--bad-ink); } .st.bad::before { background: var(--bad); }
.st.review::before { background: var(--accent); }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); margin-left: 4px; }

/* ---- графики (SVG рисует app.js) ---- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .bar.s2 { fill: var(--series-2); }
.chart .bar.s3 { fill: var(--series-3); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hl { filter: brightness(1.12); }
.chart .base { stroke: var(--line-strong); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); border-radius: 8px; padding: 6px 9px; font-size: 12px;
       white-space: nowrap; transform: translate(-50%, calc(-100% - 8px)); opacity: 0; transition: opacity .08s; z-index: 5; font-variant-numeric: tabular-nums; }
.tip.on { opacity: 1; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---- воронка ---- */
.fun { display: grid; gap: 8px; }
.fun .row { display: grid; grid-template-columns: minmax(150px, 260px) 1fr 70px 70px; align-items: center; gap: 12px; font-size: 13.5px; }
.fun .track { height: 22px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.fun .fill { height: 100%; border-radius: 6px; background: var(--series-1); min-width: 2px; }
.fun .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.fun .p { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12.5px; }
@media (max-width: 700px) { .fun .row { grid-template-columns: 1fr 52px 56px; } .fun .track { grid-column: 1 / -1; order: 5; } }

/* ---- превью объявления, как в Telegram ---- */
.previews { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.pv { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.pv .chat { background: var(--tg-bg); padding: 18px 14px; flex: 1;
            background-image: radial-gradient(circle at 20% 20%, rgba(255,255,255,.18) 0 2px, transparent 3px), radial-gradient(circle at 70% 60%, rgba(255,255,255,.12) 0 2px, transparent 3px);
            background-size: 38px 38px, 52px 52px; }
.bubble { background: var(--tg-bubble); border-radius: 14px 14px 14px 4px; padding: 9px 12px 8px; max-width: 100%; box-shadow: 0 1px 1px rgba(0,0,0,.08); color: var(--ink); }
.bubble .who { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13.5px; font-weight: 600; color: var(--tg-name); margin-bottom: 2px; }
.bubble .who span { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.bubble .txt { font-size: 14px; line-height: 1.38; white-space: pre-wrap; word-wrap: break-word; }
.bubble img { display: block; width: calc(100% + 24px); margin: 6px -12px 6px; max-height: 220px; object-fit: cover; }
.bubble .tgbtn { margin: 8px -4px 0; border-top: 1px solid var(--line); padding-top: 8px; text-align: center; font-size: 13px; font-weight: 600;
                 color: var(--tg-btn); text-transform: uppercase; letter-spacing: .02em; }
.pv .botbar { background: var(--tg-bubble); border-radius: 10px; padding: 9px 12px; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.pv .botbar .who { color: var(--muted); font-size: 11.5px; margin-bottom: 2px; }
.pv .search { background: var(--tg-bubble); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; }
.pv .ava { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.pv .meta { padding: 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.pv .meta .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.pv .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 12px; color: var(--muted); }
.pv .stats b { display: block; color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---- вход ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .box { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth .brand { padding: 0 0 22px; }
.auth h1 { font-size: 21px; margin-bottom: 6px; }
.auth p { color: var(--ink-2); margin: 0 0 20px; font-size: 14.5px; }
.auth label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.auth input { width: 100%; padding: 12px 14px; font-size: 16px; margin-bottom: 14px; }
.auth input.code { letter-spacing: .4em; font-size: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.err { color: var(--bad-ink); font-size: 14px; margin: -4px 0 14px; }
.ok { color: var(--good-ink); font-size: 14px; margin: 0 0 14px; }

.list { margin: 0; padding: 0; list-style: none; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; align-items: baseline; font-size: 13.5px; }
.list li:last-child { border-bottom: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 18px 0; text-align: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
code { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
pre { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 12px; border-radius: 10px; overflow-x: auto; }
.chart .axis text.peak { fill: var(--ink-2); font-weight: 600; }
