/* Визуальный отчёт (report.js). Все правила — под классом .hqr, чтобы ничего не утекло на страницу дашборда
   и её стили не сломали отчёт. Размеры рассчитаны на телефон (около 390 px); на широком экране отчёт
   сам становится крупнее по ширине своего контейнера, а не окна. */

/* ───────────── Цвета ─────────────
   Фон и текст берём из темы Telegram, если она есть; иначе — по системной теме.
   Акценты (зелёный — лучше, красный — хуже, цвета рядов) свои для светлого и тёмного фона:
   report.js смотрит на реальный фон и ставит data-scheme. */
.hqr {
  --hqr-bg: var(--tg-theme-bg-color, #ffffff);
  --hqr-text: var(--tg-theme-text-color, #111827);
  --hqr-muted: var(--tg-theme-hint-color, #6b7280);
  --hqr-soft: var(--tg-theme-secondary-bg-color, #f1f2f4);
  --hqr-line: rgba(128, 128, 128, 0.3);
  --hqr-rail: rgba(128, 128, 128, 0.16);
  --hqr-before: #9ca3af;
  --hqr-good: #15803d;
  --hqr-good-fill: #16a34a;
  --hqr-bad: #dc2626;
  --hqr-bad-fill: #ef4444;
  --hqr-s1: #2a78d6;
  --hqr-s2: #1baf7a;
  --hqr-s3: #eb6834;
}
@media (prefers-color-scheme: dark) {
  .hqr:not([data-scheme="light"]) {
    --hqr-bg: var(--tg-theme-bg-color, #17181a);
    --hqr-text: var(--tg-theme-text-color, #f3f4f6);
    --hqr-muted: var(--tg-theme-hint-color, #9ca3af);
    --hqr-soft: var(--tg-theme-secondary-bg-color, #26282c);
    --hqr-before: #7d8490;
    --hqr-good: #4ade80;
    --hqr-good-fill: #22c55e;
    --hqr-bad: #f87171;
    --hqr-bad-fill: #ef4444;
    --hqr-s1: #3987e5;
    --hqr-s2: #199e70;
    --hqr-s3: #d95926;
  }
}
.hqr[data-scheme="dark"] {
  --hqr-bg: var(--tg-theme-bg-color, #17181a);
  --hqr-text: var(--tg-theme-text-color, #f3f4f6);
  --hqr-muted: var(--tg-theme-hint-color, #9ca3af);
  --hqr-soft: var(--tg-theme-secondary-bg-color, #26282c);
  --hqr-before: #7d8490;
  --hqr-good: #4ade80;
  --hqr-good-fill: #22c55e;
  --hqr-bad: #f87171;
  --hqr-bad-fill: #ef4444;
  --hqr-s1: #3987e5;
  --hqr-s2: #199e70;
  --hqr-s3: #d95926;
}

/* ───────────── Основа ───────────── */
.hqr {
  position: relative;
  container: hqr / inline-size;
  box-sizing: border-box;
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  background: var(--hqr-bg);
  color: var(--hqr-text);
  font: 400 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  text-align: left;
  -webkit-text-size-adjust: 100%;
}
.hqr *, .hqr *::before, .hqr *::after { box-sizing: border-box; }
.hqr [hidden] { display: none !important; }
.hqr h2, .hqr h3, .hqr p { margin: 0; }
.hqr button {
  margin: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit;
  appearance: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.hqr :focus-visible { outline: 2px solid var(--hqr-s1); outline-offset: 2px; }

.hqr-header { margin-bottom: 18px; }
.hqr-title { font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.hqr-subtitle { margin-top: 4px; color: var(--hqr-muted); font-size: 14px; overflow-wrap: anywhere; }

.hqr-blocks { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.hqr-heading { font-size: 17px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.hqr-note { margin-top: 3px; color: var(--hqr-muted); font-size: 13px; overflow-wrap: anywhere; }
.hqr-heading + .hqr-card, .hqr-note + .hqr-card,
.hqr-heading + .hqr-kpis, .hqr-note + .hqr-kpis,
.hqr-heading + .hqr-tabs, .hqr-note + .hqr-tabs { margin-top: 10px; }

.hqr-card { padding: 14px; border: 1px solid var(--hqr-line); border-radius: 14px; background: var(--hqr-bg); }
.hqr-text { display: grid; gap: 8px; overflow-wrap: anywhere; }
.hqr-error { padding: 12px 14px; border: 1px solid var(--hqr-bad); border-radius: 14px; color: var(--hqr-bad); overflow-wrap: anywhere; }

.hqr-tone-good { color: var(--hqr-good); }
.hqr-tone-bad { color: var(--hqr-bad); }
.hqr-tone-neutral { color: var(--hqr-muted); }

/* ───────────── Карточки с цифрами ───────────── */
.hqr-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hqr-kpis-1 { grid-template-columns: minmax(0, 1fr); }
.hqr-kpis-3 > :last-child, .hqr-kpis > .hqr-kpi-s { grid-column: 1 / -1; }
.hqr-kpi { display: flex; flex-direction: column; min-width: 0; }
.hqr-kpi-label, .hqr-kpi-note { color: var(--hqr-muted); font-size: 13px; line-height: 1.3; overflow-wrap: anywhere; }
.hqr-kpi-value {
  margin: 4px 0 2px; font-size: 32px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hqr-kpi-value.hqr-tone-neutral { color: var(--hqr-text); }
.hqr-kpi-m .hqr-kpi-value { font-size: 25px; }
.hqr-kpi-s .hqr-kpi-value { font-size: 28px; }
.hqr-kpi-note { margin-top: auto; }
/* Подпись, цифра и пояснение стоят на общих линиях у всех карточек ряда, даже если подпись где-то в две строки. */
@supports (grid-template-rows: subgrid) {
  .hqr-kpi { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 0; }
  .hqr-kpi-note { margin-top: 0; }
}

/* ───────────── Столбцы ───────────── */
.hqr-chart { --hqr-plot-h: 200px; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; padding-top: 16px; }
.hqr-axis, .hqr-plot-box { position: relative; height: var(--hqr-plot-h); }
.hqr-below-zero .hqr-axis, .hqr-below-zero .hqr-plot-box { margin-bottom: 14px; }
.hqr-axis { color: var(--hqr-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.hqr-axis span { position: absolute; right: 0; transform: translateY(-50%); line-height: 1; white-space: nowrap; }
.hqr-plot { position: absolute; inset: 0; display: block; overflow: visible; }
.hqr-grid, .hqr-zero { stroke: var(--hqr-rail); stroke-width: 1; shape-rendering: crispEdges; }
.hqr-zero { stroke: var(--hqr-line); }

.hqr .hqr-bar { cursor: default; outline: none; } /* фокус показывает рамка столбца ниже: обводку у SVG браузеры рисуют по-разному */
.hqr-hit { fill: transparent; pointer-events: all; }
.hqr-anchor { fill: none; pointer-events: none; }
.hqr-bar[data-active] .hqr-hit, .hqr-bar:focus-visible .hqr-hit { fill: var(--hqr-rail); }
.hqr-bar:focus-visible .hqr-hit { stroke: var(--hqr-s1); stroke-width: 2; }
.hqr-s1 { fill: var(--hqr-s1); background: var(--hqr-s1); }
.hqr-s2 { fill: var(--hqr-s2); background: var(--hqr-s2); }
.hqr-s3 { fill: var(--hqr-s3); background: var(--hqr-s3); }
.hqr-bar-shape { transform-box: fill-box; transform-origin: 50% 100%; }
.hqr-bar-shape.hqr-down { transform-origin: 50% 0; }

.hqr-bar-labels { position: absolute; inset: 0; pointer-events: none; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hqr-bar-labels span {
  position: absolute; transform: translateX(-50%); padding: 3px 0; line-height: 1; white-space: nowrap;
  text-shadow: 0 0 2px var(--hqr-bg), 0 0 2px var(--hqr-bg), 0 0 3px var(--hqr-bg);
}
.hqr-no-labels .hqr-bar-labels { visibility: hidden; }

.hqr-cats { grid-column: 2; display: grid; grid-template-columns: repeat(var(--hqr-n), minmax(0, 1fr)); margin-top: 6px; }
.hqr-cats span {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden;
  padding: 0 2px; font-size: 12px; line-height: 1.25; text-align: center; overflow-wrap: anywhere; hyphens: auto;
}

/* Шесть и больше категорий на узком экране: подписи боком, снизу вверх, иначе слова рвутся по слогам. */
.hqr-cats-dense span {
  display: block; justify-self: center; max-height: 104px; padding: 2px 0; line-height: 1.2;
  writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; text-overflow: ellipsis; text-align: end;
}

.hqr-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 6px; margin-top: 10px; }
.hqr .hqr-legend-item { display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 4px 10px; border-radius: 999px; font-size: 13px; text-align: left; }
.hqr button.hqr-legend-item:hover { background: var(--hqr-rail); }
.hqr-legend-item[aria-pressed="false"] { color: var(--hqr-muted); text-decoration: line-through; }
.hqr-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
.hqr-legend-item[aria-pressed="false"] .hqr-dot { background: none; box-shadow: inset 0 0 0 2px var(--hqr-muted); }
.hqr-unit { margin-top: 6px; color: var(--hqr-muted); font-size: 12px; overflow-wrap: anywhere; }

/* ───────────── Полосы: «до / после» и выполнение ───────────── */
.hqr-cmp { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; column-gap: 10px; align-items: center; }
.hqr-cmp-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 16px; }
.hqr-cmp-head:first-child { margin-top: 0; }
.hqr-cmp-label { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.hqr-delta { flex: none; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hqr-delta.hqr-tone-plain { color: var(--hqr-text); }
.hqr-cmp-key { color: var(--hqr-muted); font-size: 13px; white-space: nowrap; }
.hqr-cmp-value { font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hqr-cmp-unit { grid-column: 1 / -1; color: var(--hqr-muted); font-size: 13px; overflow-wrap: anywhere; }

.hqr-track { display: block; padding: 7px 0; border-radius: 6px; cursor: default; }
.hqr-rail { display: block; height: 8px; border-radius: 999px; background: var(--hqr-rail); }
.hqr-track:hover .hqr-rail, .hqr-track[data-active] .hqr-rail { box-shadow: 0 0 0 3px var(--hqr-rail); }
.hqr-fill { display: block; min-width: 8px; height: 100%; border-radius: 999px; transform-origin: 0 50%; }
.hqr-fill-before { background: var(--hqr-before); }
.hqr-fill-good { background: var(--hqr-good-fill); }
.hqr-fill-bad { background: var(--hqr-bad-fill); }
.hqr-fill-neutral { background: var(--hqr-muted); }
.hqr-fill-accent { background: var(--hqr-s1); }
.hqr-progress-item + .hqr-progress-item { margin-top: 16px; }
.hqr-progress .hqr-track { padding: 6px 0 5px; }
.hqr-progress .hqr-rail { height: 10px; }

/* ───────────── Таблица ───────────── */
.hqr-table { padding-top: 4px; padding-bottom: 4px; }
.hqr-table-scroll { overflow-x: auto; }
.hqr table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 1.35; }
/* Текстовый столбец не сжимается уже нескольких слов: широкая таблица прокручивается внутри карточки. */
.hqr th, .hqr td { min-width: 6.5em; padding: 10px 12px 10px 0; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.hqr th:first-child:not(.hqr-num), .hqr td:first-child:not(.hqr-num) { min-width: 9em; }
.hqr th:last-child, .hqr td:last-child { padding-right: 0; }
.hqr th { color: var(--hqr-muted); font-size: 12px; font-weight: 600; vertical-align: bottom; border-bottom: 1px solid var(--hqr-line); }
.hqr tbody tr + tr td { border-top: 1px solid var(--hqr-rail); }
.hqr .hqr-num { min-width: 0; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hqr-table .hqr-copy { margin-bottom: 10px; }

/* ───────────── Вкладки ───────────── */
.hqr-seg { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--hqr-line); border-radius: 999px; overflow-x: auto; scrollbar-width: none; }
.hqr-seg::-webkit-scrollbar { display: none; }
.hqr .hqr-tab { flex: 1 0 auto; min-height: 34px; padding: 6px 14px; border-radius: 999px; color: var(--hqr-muted); font-size: 14px; white-space: nowrap; }
.hqr .hqr-tab[aria-selected="true"] { background: var(--hqr-soft); box-shadow: inset 0 0 0 1px var(--hqr-rail); color: var(--hqr-text); font-weight: 600; }
.hqr-panel { margin-top: 14px; }

/* ───────────── Кнопка копирования и подсказка ───────────── */
.hqr .hqr-copy {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 40px; margin-top: 14px;
  padding: 8px 14px; border: 1px solid var(--hqr-line); border-radius: 999px; color: var(--hqr-muted); font-size: 14px;
}
.hqr .hqr-copy:hover { background: var(--hqr-rail); }
.hqr-copy-icon { flex: none; fill: none; stroke: currentColor; stroke-width: 1.4; }
.hqr-clip { position: absolute; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.hqr-tip {
  position: absolute; z-index: 5; display: grid; max-width: min(260px, calc(100% - 8px)); padding: 6px 10px;
  border-radius: 8px; background: var(--hqr-text); color: var(--hqr-bg); font-size: 12.5px; line-height: 1.3; pointer-events: none;
}
.hqr-tip-title { opacity: 0.75; }
.hqr-tip-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ───────────── Появление ─────────────
   Столбцы и полосы один раз вырастают от оси. Кто просил систему убрать анимацию — не получает её. */
@keyframes hqr-rise { from { transform: scaleY(0); } }
@keyframes hqr-grow { from { transform: scaleX(0); } }
.hqr-enter .hqr-bar-shape { animation: hqr-rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.hqr-enter .hqr-fill { animation: hqr-grow 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@media (prefers-reduced-motion: reduce) {
  .hqr *, .hqr *::before, .hqr *::after { animation: none !important; transition: none !important; }
}

/* ───────────── Широкий контейнер (компьютер, планшет) ───────────── */
@container hqr (min-width: 600px) {
  .hqr-header { margin-bottom: 24px; }
  .hqr-title { font-size: 28px; }
  .hqr-subtitle { font-size: 15px; }
  .hqr-blocks { gap: 28px; }
  .hqr-heading { font-size: 20px; }
  .hqr-note { font-size: 14px; }
  .hqr-text { font-size: 16px; }
  .hqr-card { padding: 20px; border-radius: 16px; }
  .hqr-kpis { gap: 12px; }
  .hqr-kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hqr-kpis-3 > :last-child { grid-column: auto; }
  .hqr-kpis-3 > .hqr-kpi-s { grid-column: 1 / -1; }
  .hqr-kpi-label, .hqr-kpi-note { font-size: 14px; }
  .hqr-kpi-value { font-size: 44px; }
  .hqr-kpi-m .hqr-kpi-value { font-size: 36px; }
  .hqr-kpi-s .hqr-kpi-value { font-size: 40px; }
  .hqr-chart { --hqr-plot-h: 280px; column-gap: 10px; }
  .hqr-axis { font-size: 12px; }
  .hqr-bar-labels { font-size: 12px; }
  .hqr-cats span, .hqr-unit { font-size: 13px; }
  .hqr-cats-dense span {
    display: -webkit-box; justify-self: stretch; max-height: none; padding: 0 2px; line-height: 1.25;
    writing-mode: horizontal-tb; transform: none; white-space: normal; text-align: center;
  }
  .hqr .hqr-legend-item { font-size: 14px; }
  .hqr-cmp { column-gap: 14px; }
  .hqr-cmp-head { margin-top: 20px; }
  .hqr-cmp-label, .hqr-delta { font-size: 16px; }
  .hqr-cmp-key, .hqr-cmp-unit { font-size: 14px; }
  .hqr-cmp-value { font-size: 15px; }
  .hqr-rail { height: 10px; }
  .hqr-fill { min-width: 10px; }
  .hqr-table { padding-top: 6px; padding-bottom: 6px; }
  .hqr table { font-size: 15px; }
  .hqr th { font-size: 13px; }
}
