/* Учёт баеров — панель. Стиль «data terminal»: карточки темнее фона, цифры в моноширинном,
   выбор отмечается одной линией в 1px, цвет только у состояния и у плохих цифр.
   Сетка сводки на 1440: рейка 55 + поля 32 + (колонка 1fr + 24 + правая колонка 384) + поля 32. */
:root {
  --ground: #171719; --surface: #131217; --raised: #212023; --border: #222224; --rule: #1b1a1f; --control: #3a3a3e;
  --text: #ffffff; --muted: #8a8c92; --accent: #4a8ad6;
  --positive: #44a282; --negative: #e5566f; --warning: #d9a441;
  --chart-1: #4a8ad6; --chart-muted: #3a3a3e; --grid: #2b2b2b; --axis-ink: #8a8c92; --ink: #ffffff; --chart-span: .12;
  --radius-card: 6px; --radius-control: 999px;
  --row: 42px; --rail: 55px; --gap: 24px; --pad: 32px; --control-height: 34px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body { margin: 0; background: var(--ground); color: var(--text); font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, dl, dd { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, .kpi b, td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.unit { color: var(--muted); font-size: .85em; margin-left: 1px; }
.dash, .muted { color: var(--muted); }
.neg { color: var(--negative); }
.pos { color: var(--positive); }

/* каркас */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 0 12px; border-right: 1px solid var(--border); }
.rail a, .rail button { position: relative; display: grid; place-items: center; width: var(--rail); height: 42px; color: var(--muted); background: none; border: 0; padding: 0; }
.rail a:hover, .rail button:hover { color: var(--text); }
.rail span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.rail .brand { color: var(--accent); height: 44px; margin-bottom: 14px; }
.rail a[aria-current="page"] { color: var(--text); }
.rail a[aria-current="page"]::after { content: ""; position: absolute; right: -1px; top: 11px; bottom: 11px; width: 1px; background: var(--accent); }
.rail-end { margin-top: auto; }
.canvas { min-width: 0; padding: 28px var(--pad) 64px; }

/* заголовок экрана */
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--gap); margin-bottom: 20px; }
h1 { font-size: 26px; line-height: 1.15; font-weight: 600; letter-spacing: -0.01em; }
.finding { margin-top: 6px; font-size: 15px; color: var(--muted); max-width: 70ch; }
.finding b { color: var(--text); font-weight: 500; }
.title-side { display: flex; align-items: center; gap: 12px; flex: none; }
.stamp { font-size: 12px; color: var(--muted); white-space: nowrap; }
.primary, .ghost { height: var(--control-height); padding: 0 16px; border-radius: var(--radius-control); font-weight: 500; white-space: nowrap; }
.primary { background: #ffffff; color: #000000; border: 0; }
.primary:hover { background: #dcdcde; }
.ghost { background: none; border: 1px solid var(--control); }
.ghost:hover { border-color: var(--muted); }

/* вкладки: выбор — линия в 1px шириной с подпись */
.scope { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--gap); border-bottom: 1px solid var(--border); margin-bottom: var(--gap); }
.tabs { display: flex; gap: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { position: relative; flex: none; height: 36px; padding: 0; background: none; border: 0; color: var(--muted); white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--accent); }
.tabs .n { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: 4px; }
.filters { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); margin-bottom: 16px; flex-wrap: wrap; }
.filters .right { display: flex; align-items: center; gap: 20px; }
input[type="search"] { height: var(--control-height); width: 320px; max-width: 100%; padding: 0 14px; border-radius: var(--radius-control); border: 1px solid var(--control); background: transparent; }
input[type="search"]::placeholder { color: var(--muted); }

.period { display: flex; align-items: flex-end; gap: 22px; }
.days { display: flex; align-items: center; gap: 6px; height: 36px; color: var(--muted); white-space: nowrap; position: relative; }
.days.on { color: var(--text); }
.days.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--accent); }
.days input { width: 58px; height: 26px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--control); background: transparent; font-family: var(--mono); text-align: right; }
.presets { margin-bottom: 14px; }
th.rank, td.rank { width: 64px; }

/* панели */
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 384px; gap: var(--gap); align-items: start; }
.col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); min-width: 0; }
.panel > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 16px 20px 4px; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
.side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
.side > div { min-width: 0; }
.side h2 { margin-bottom: 8px; }
.note { padding: 14px 20px 18px; color: var(--muted); }

/* цифры дня и воронка: одна лента, проценты между шагами считаются из цифр на экране */
.kpis { display: flex; align-items: stretch; }
.kpi { flex: 1 1 0; min-width: 0; padding: 16px 20px 15px; border-left: 1px solid var(--rule); }
.kpi:first-child { border-left: 0; }
.kpi > span { display: block; color: var(--muted); white-space: nowrap; }
.kpi:first-child { flex: 1.7 1 0; }
.kpi b { display: block; margin: 5px 0 3px; font-size: 22px; line-height: 1.2; font-weight: 400; white-space: nowrap; }
.kpi b.lead { font-size: 28px; line-height: 1; margin: 4px 0 5px; }
.kpi small { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; }
.link { flex: none; width: 76px; display: grid; align-content: center; justify-items: center; gap: 5px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.link i { display: block; width: 100%; height: 1px; background: var(--control); }
.link em { font-style: normal; font-family: var(--font); font-size: 11px; }
.link.neg { color: var(--negative); }
.link.neg i { background: var(--negative); }
.link.pos { color: var(--positive); }
.link.pos i { background: var(--positive); }
.chart { padding: 6px 20px 14px; height: 196px; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { height: 38px; padding: 0 12px; text-align: left; font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }
th.num { text-align: right; font-family: var(--font); }
th button { background: none; border: 0; padding: 0; color: inherit; }
th button:hover, th[aria-sort] button { color: var(--text); }
th[aria-sort="descending"] button::after { content: " ↓"; }
th[aria-sort="ascending"] button::after { content: " ↑"; }
td { height: var(--row); padding: 0 12px; border-top: 1px solid var(--rule); white-space: nowrap; }
td.num { text-align: right; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
tr.row, tr.go { cursor: pointer; }
tr.row:hover td, tr.go:hover td { background: #19181d; }
tr.row[aria-expanded="true"] td { background: var(--raised); border-top-color: var(--raised); }
tr.group td { height: 44px; padding-top: 10px; vertical-align: middle; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
tr.group b, .group-title b { font-weight: 600; color: var(--warning); }
.owner { font-style: normal; font-weight: 600; color: #171719; background: var(--warning); border-radius: 4px; padding: 1px 7px; margin-right: 8px; }
tr.group .num { color: var(--muted); }
.name { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 520px; }
.name > span { overflow: hidden; text-overflow: ellipsis; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.dot.bad { background: var(--negative); }
.dot.good { background: var(--positive); }
.dot.few { border: 1px solid var(--muted); }
.chip { flex: none; font-style: normal; font-size: 11px; line-height: 18px; padding: 0 7px; border-radius: 4px; background: var(--raised); color: #bdbdc0; white-space: nowrap; }
.chip.warn { background: #2a2416; color: var(--warning); }
.chip.bad { background: #2c1a20; color: var(--negative); }

/* раскрытая кампания */
tr.detail td { height: auto; padding: 0; white-space: normal; background: var(--raised); border-top: 0; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 32px; padding: 6px 20px 22px 38px; }
.detail-grid h3 { margin-bottom: 10px; color: var(--muted); font-weight: 400; font-size: 12px; }
.detail-grid dl + h3 { margin-top: 18px; }
.steps { display: flex; align-items: center; margin-bottom: 12px; }
.steps div { flex: none; }
.steps div span { display: block; font-size: 12px; color: var(--muted); }
.steps div b { font-family: var(--mono); font-size: 18px; font-weight: 400; }
.steps .link { width: auto; flex: 1 1 0; min-width: 44px; padding: 0 8px; }
.verdict { margin-bottom: 12px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 5px 16px; }
.facts dt { color: var(--muted); }
.facts dd { font-family: var(--mono); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facts dd.text { font-family: var(--font); }
table.mini th, table.mini td { height: 28px; padding: 0 0 0 12px; border-top: 0; background: none; }
table.mini th:first-child, table.mini td:first-child { padding-left: 0; }
table.mini th:last-child, table.mini td:last-child { padding-right: 0; }
table.mini tr.today td { color: var(--text); }
table.mini td { color: #c9c9cc; }
.share { display: block; height: 2px; margin-top: 3px; background: var(--control); }
.share i { display: block; height: 2px; background: var(--muted); }
tr.top .share i { background: var(--text); }

/* карточки кампаний */
.group-title { margin: 22px 0 10px; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 16px; }
.group-title:first-child { margin-top: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card { padding: 16px 18px; }
.card > header { display: flex; align-items: flex-start; justify-content: flex-start; gap: 10px; margin-bottom: 12px; padding: 0; }
.card header .dot { margin-top: 6px; }
.card h3 { font-size: 14px; font-weight: 500; line-height: 1.35; overflow-wrap: anywhere; }
.figs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.figs dt { font-size: 12px; color: var(--muted); }
.figs dd { font-family: var(--mono); font-size: 17px; white-space: nowrap; }
.card .line { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card .line b { font-family: var(--mono); font-weight: 400; color: #c9c9cc; }

/* списки справа */
.list .item { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 9px 16px; border-top: 1px solid var(--rule); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.list .item:first-child { border-top: 0; }
button.item:hover { background: #19181d; }
.list .who { flex: 1 1 auto; min-width: 0; }
.list .who b { display: block; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .who small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .val { flex: none; text-align: right; font-family: var(--mono); white-space: nowrap; }
.list .val small { display: block; font-size: 12px; color: var(--muted); }
.list .more { display: block; width: calc(100% - 32px); margin: 6px 16px 14px; height: 30px; border-radius: var(--radius-control); border: 1px solid var(--control); background: none; }
.list .more:hover { border-color: var(--muted); }
.empty { margin: 12px 16px; padding: 10px 12px; border: 1px dashed var(--control); border-radius: var(--radius-card); color: var(--muted); }
.skeleton { height: 22px; width: 60%; background: var(--raised); border-radius: 4px; }
.error { margin-bottom: 16px; padding: 10px 14px; border: 1px solid #4a2630; border-radius: var(--radius-card); background: #2c1a20; color: #f0a9b6; display: flex; justify-content: space-between; align-items: center; gap: 16px; }

/* вход */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login { width: 100%; max-width: 360px; }
.login-brand { display: flex; align-items: center; gap: 12px; color: var(--accent); }
.login-brand h1 { color: var(--text); font-size: 26px; }
.login-lead { margin: 14px 0 28px; font-size: 15px; color: var(--muted); }
.login-form { display: grid; gap: 8px; }
.login-form label { color: var(--muted); }
.login-form input { height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--control); background: var(--surface); font-size: 15px; }
.login-form .primary { height: 40px; margin-top: 12px; font-size: 14px; }
.login-error { color: #f0a9b6; }

/* планшет: правая колонка уходит под основную */
@media (max-width: 1100px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .side > div { min-width: 0; }
  .kpis { flex-wrap: wrap; }
  .kpi { flex: 1 1 30%; border-top: 1px solid var(--rule); }
  .link { display: none; }
  .detail-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding-left: 20px; }
}
/* телефон: рейка становится нижней панелью с подписями, таблица кампаний — карточками */
@media (max-width: 700px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; z-index: 5; top: auto; bottom: 0; left: 0; right: 0; height: 58px; flex-direction: row; justify-content: space-around; padding: 0; gap: 0; border-right: 0; border-top: 1px solid var(--border); background: var(--ground); }
  .rail .brand { display: none; }
  .rail a, .rail button { width: 72px; height: 58px; align-content: center; gap: 3px; }
  .rail span { position: static; width: auto; height: auto; clip-path: none; font-size: 11px; }
  .rail a[aria-current="page"]::after { right: 14px; left: 14px; top: 0; bottom: auto; width: auto; height: 1px; }
  .rail-end { margin: 0; }
  .canvas { padding: 20px 16px 88px; }
  .title-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .title-side { justify-content: space-between; }
  h1 { font-size: 22px; }
  .finding { font-size: 14px; }
  .scope { flex-direction: column; align-items: stretch; gap: 0; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .kpi { flex: 1 1 45%; padding: 14px 16px; }
  .kpi:nth-child(odd) { border-left: 0; }
  .kpi b.lead { font-size: 26px; }
  .filters .right { width: 100%; justify-content: space-between; }
  input[type="search"] { width: 100%; }
  .hide-s { display: none; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  th, td { padding: 0 8px; }
  th:first-child, td:first-child { padding-left: 14px; }
  th:last-child, td:last-child { padding-right: 14px; }
  .name { max-width: 190px; }
  .chart { height: 180px; padding: 6px 12px 12px; }
}
@media (prefers-reduced-motion: no-preference) {
  .rail a, .tabs button, .ghost, .primary, tr.row td { transition: color .12s, background-color .12s, border-color .12s; }
}

/* Таблица кампаний: при прокрутке заголовки колонок прилипают к верху, под ними — шапка текущей группы.
   Работает на широком экране, где таблица помещается целиком и ей не нужна своя горизонтальная прокрутка. */
@media (min-width: 1101px) {
  .table-wrap.sticky { overflow: visible; }
  .table-wrap.sticky thead th { position: sticky; top: 0; z-index: 3; background: var(--surface); box-shadow: 0 1px 0 var(--border); }
  .table-wrap.sticky thead th:first-child { border-top-left-radius: var(--radius-card); }
  .table-wrap.sticky thead th:last-child { border-top-right-radius: var(--radius-card); }
  .table-wrap.sticky tr.group td { position: sticky; top: 38px; z-index: 2; background: var(--surface); box-shadow: 0 1px 0 var(--border); }
}

/* отбор по состоянию и по норме стоят слева в одном ряду */
.filters .left { display: flex; align-items: center; gap: 30px; flex-wrap: wrap; }
