/* Отчёт по рекламе — оформление.
   Палитра и спецификации марок взяты из проверенного набора data-viz:
   светлая и тёмная темы подобраны отдельно, а не выведены автоматом. */

.viz-root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, .10);
  --series-1: #2a78d6;   /* расход */
  --series-2: #eb6834;   /* цена заявки */
  --series-3: #1baf7a;   /* заявки */
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 8px 24px rgba(11, 11, 11, .04);
  --radius: 14px;
  --gap: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, .10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-text: #0ca30c;
    --shadow: none;
  }
}

:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, .10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good-text: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--plane, #f9f9f7);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.viz-root {
  background: var(--plane);
  color: var(--text-primary);
  min-height: 100vh;
  padding: 20px clamp(12px, 2.2vw, 32px) 56px;
  max-width: 1760px;
  margin: 0 auto;
  font-size: 15px;
  line-height: 1.45;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
p { margin: 0; }

/* ── Шапка ─────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 14px; flex-wrap: wrap;
}
.topbar-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.topbar h1::before {
  content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--series-1); margin-right: 9px; vertical-align: middle;
}
.sub { color: var(--text-secondary); font-size: 13px; }
.topbar-side { display: flex; gap: 8px; align-items: center; }

/* ── Фильтры ───────────────────────────────────────────── */
/* Липкая полоса: на длинной странице период всегда под рукой
   и всегда видно, к какому отрезку относятся цифры. */
.filterbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--plane);
  padding: 8px 0 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.filters { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.filters-right {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-left: auto;
}

.btn, .chip, .select, .input {
  font: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
  transition: background .12s, border-color .12s;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover, .chip:hover, .select:hover { border-color: var(--axis); }
.chip.active {
  background: var(--series-1); border-color: var(--series-1);
  color: #fff; font-weight: 600;
}
.btn.ghost { background: transparent; }
.input { cursor: text; padding: 5px 8px; }
.daterange { display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--text-muted); }

.periodline { font-size: 12.5px; color: var(--text-muted); margin-top: 8px; }

.accounts {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px;
}
.accounts .lbl { font-size: 12px; color: var(--text-muted); margin-right: 2px; }

/* Остатки на счетах — первое, на что смотрят утром, поэтому отдельной
   полосой над отчётом, а не строкой в подвале. */
.balances {
  display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0 var(--gap);
}
.bal {
  display: flex; align-items: baseline; gap: 8px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid var(--good); border-radius: 10px;
  padding: 8px 13px; box-shadow: var(--shadow);
}
.bal.low { border-left-color: var(--warning); }
.bal.empty { border-left-color: var(--critical); }
.bal.err { border-left-color: var(--axis); }
.bal .who { font-size: 12px; color: var(--text-secondary); }
.bal .amt { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bal .days { font-size: 11.5px; color: var(--text-muted); }

/* ── Карточки ──────────────────────────────────────────── */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
main > section { margin-bottom: var(--gap); }
.card-head { margin-bottom: 14px; }
.card-sub { color: var(--text-secondary); font-size: 12.5px; margin-top: 3px; max-width: 78ch; }
.section-head { margin: 26px 2px 12px; }

.hero-row {
  display: grid; grid-template-columns: minmax(200px, 250px) 1fr;
  gap: var(--gap); align-items: stretch;
}
.hero { display: flex; flex-direction: column; justify-content: center; }
.hero-value {
  font-size: 40px; font-weight: 600; letter-spacing: -.02em;
  line-height: 1.05; margin: 4px 0 6px; white-space: nowrap;
}
.label { font-size: 12.5px; color: var(--text-secondary); }
.hint { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }

.tiles {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  grid-auto-rows: 1fr;
}
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile-value {
  font-size: 23px; font-weight: 600; letter-spacing: -.015em; line-height: 1.15;
}
.tile .label { font-size: 12px; }
.tile.accent { border-color: color-mix(in srgb, var(--series-1) 40%, var(--border)); }

.delta { font-size: 12.5px; font-weight: 600; margin-top: 2px; }
.delta .pct { white-space: nowrap; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical); }
.delta.flat { color: var(--text-muted); font-weight: 500; }
.delta .note {
  color: var(--text-muted); font-weight: 400; font-size: 11.5px; margin-left: 5px;
}

/* ── Две колонки: график + выводы ──────────────────────── */
.split { display: grid; gap: var(--gap); grid-template-columns: 1fr; }
@media (min-width: 1240px) {
  .split { grid-template-columns: minmax(0, 1.85fr) minmax(300px, 1fr); }
  .split > .card { min-width: 0; }
  #insightsCard .insights { grid-template-columns: 1fr; }
  #insightsCard { max-height: none; }
}

.insights { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.ins {
  border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 10px; padding: 11px 13px; background: var(--plane);
}
.ins h3 { font-size: 13.5px; display: flex; align-items: baseline; gap: 7px; }
.ins p { font-size: 12.5px; color: var(--text-secondary); margin-top: 4px; }
.ins .ico { font-size: 12px; line-height: 1; flex: none; }
.ins.good { border-left-color: var(--good); }
.ins.warn { border-left-color: var(--warning); }
.ins.bad  { border-left-color: var(--critical); }
.ins.info { border-left-color: var(--axis); }

/* ── Графики ───────────────────────────────────────────── */
.panels { display: flex; flex-direction: column; gap: 4px; }
.panel { position: relative; }
.panel-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 2px; padding-left: 2px;
}
.panel-title { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.panel-key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.panel-total { font-size: 12px; color: var(--text-muted); }
.chart-wrap { width: 100%; overflow-x: auto; }
svg { display: block; max-width: 100%; }
svg text { font-family: inherit; }

.tooltip {
  position: fixed; z-index: 90; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; font-size: 12.5px;
  box-shadow: 0 4px 20px rgba(11, 11, 11, .16); min-width: 150px;
}
.tooltip .tt-date { font-size: 11.5px; color: var(--text-muted); margin-bottom: 5px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; margin-top: 3px; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-val { font-weight: 600; margin-left: auto; }
.tooltip .tt-name { color: var(--text-secondary); font-size: 12px; }

/* ── Срезы ─────────────────────────────────────────────── */
/* align-items:start — иначе сетка тянет все карточки до высоты самой длинной,
   и рядом с «Полом и возрастом» остальные превращаются в пустые простыни. */
.seg-grid {
  display: grid; gap: var(--gap); align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  margin-bottom: var(--gap);
}
.seg-stack { display: grid; gap: var(--gap); align-items: start; }
@media (min-width: 1240px) {
  .seg-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .seg-stack > .seg-wide { grid-column: span 2; }
}
.seg-card { min-width: 0; }
.seg-card h3 { font-size: 14px; margin-bottom: 2px; }
.seg-note { font-size: 11.5px; color: var(--text-muted); margin-bottom: 10px; }
.seg-bars { display: flex; flex-direction: column; gap: 9px; }
.seg-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: baseline; }
.seg-name { font-size: 12.5px; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.seg-val { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.seg-track {
  grid-column: 1 / -1; height: 8px; border-radius: 4px;
  background: color-mix(in srgb, var(--axis) 32%, transparent); overflow: hidden;
}
/* display:block обязателен: у инлайнового элемента ширина и высота
   в процентах не работают, и полоса просто не появляется. */
.seg-fill { display: block; height: 100%; border-radius: 4px; background: var(--series-1); }
.seg-fill.dead { background: var(--critical); }
.seg-fill.other { background: var(--axis); }
.seg-meta { grid-column: 1 / -1; font-size: 11.5px; color: var(--text-muted);
  font-variant-numeric: tabular-nums; }

/* ── Таблицы ───────────────────────────────────────────── */
.table-scroll { overflow-x: auto; margin-top: 12px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 620px; }
table.grid th, table.grid td {
  padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
table.grid th {
  font-weight: 600; font-size: 11.5px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .03em; border-bottom-color: var(--axis);
}
table.grid th:first-child, table.grid td:first-child {
  text-align: left; white-space: normal; min-width: 190px;
}
table.grid td { font-variant-numeric: tabular-nums; }
table.grid tbody tr:hover { background: var(--plane); }
table.grid tfoot td { font-weight: 600; border-top: 1px solid var(--axis); border-bottom: none; }
.cname { display: flex; align-items: center; gap: 8px; }
.cdot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.muted { color: var(--text-muted); }
.warnrow td { background: color-mix(in srgb, var(--critical) 7%, transparent); }

details summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸"; color: var(--text-muted); transition: transform .15s; }
details[open] summary::before { transform: rotate(90deg); }

/* ── Группы ────────────────────────────────────────────── */
.chats-list { display: grid; gap: 8px; margin: 12px 0; }
.chat-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  background: var(--plane);
}
.chat-row .nm { font-weight: 600; font-size: 13.5px; }
.chat-row .meta { font-size: 12px; color: var(--text-muted); }
.chat-row .acts { margin-left: auto; display: flex; gap: 6px; }
.chat-row.off { opacity: .55; }
.chat-form {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px;
}
.chat-form .input { min-width: 150px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px;
  color: var(--text-secondary); }

.state { padding: 48px 16px; text-align: center; color: var(--text-secondary); font-size: 14px; }
.foot { margin-top: 20px; color: var(--text-muted); font-size: 12px; display: grid; gap: 6px; }

/* ── Узкий экран ───────────────────────────────────────── */
@media (max-width: 860px) {
  .viz-root { padding: 14px 12px 40px; font-size: 14px; }
  .hero-row { grid-template-columns: 1fr; }
  .hero-value { font-size: 34px; }
  .filters-right { margin-left: 0; width: 100%; }
  .filterbar { position: static; }
  h1 { font-size: 19px; }
  .seg-grid { grid-template-columns: 1fr; }
}

@media print {
  .filterbar, .topbar-side, .tooltip, #printBtn { display: none !important; }
  .viz-root { padding: 0; max-width: none; }
  .card, .seg-card { break-inside: avoid; box-shadow: none; }
  .split { grid-template-columns: 1fr; }
  details { display: none; }
}
