/* ============================================================
   Статистика (admin/stats*.js): шапка с периодом, главные метрики с дельтой,
   график по дням, топ персонажей, монетизация, себестоимость, рефералы. Префикс .ast-
   Телефон — одна колонка, от 720px — сетка 4 плиток, от 1024px — топ и панели рядом
   ============================================================ */
.ast { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 1240px; min-width: 0; margin: 12px auto 0; }

/* ---------- Шапка ---------- */
.ast-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 12px; }
.ast-head__text { min-width: 0; }
.ast-head__period { font-size: 16px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; white-space: nowrap; }
.ast-head__sub { margin-top: 2px; font-size: 12px; color: var(--muted); }
.ast-head__tools { display: flex; align-items: center; gap: 6px; }
.ast-head__refresh .icon { width: 20px; height: 20px; }
/* Период — общий компонент .seg (components.css); здесь только равные по ширине пункты */
.ast-period { display: grid; grid-template-columns: 1fr 1fr; }
.ast-period__item { white-space: nowrap; }

/* ---------- Главные метрики ---------- */
.ast-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ast-hero {
  position: relative;
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px 16px 0;
  overflow: hidden;
  border-radius: var(--r-lg);
  background: var(--grad-soft), var(--card);
  border: 1px solid rgba(255, 45, 120, 0.3);
}
.ast-hero__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; }
/* Сумма и её долларовый эквивалент — одной строкой по базовой линии; не влезает — доллары ниже */
.ast-hero__main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; margin-top: 4px; }
.ast-hero__value { display: flex; align-items: baseline; font-size: 40px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ast-hero__unit { margin-left: 6px; font-size: 26px; }
.ast-hero__sub { font-size: 14px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.ast-hero__prev { margin-top: 4px; font-size: 11px; color: var(--muted-2); }
.ast-hero__spark { flex: 0 0 auto; height: 48px; margin: 10px 0 0 -16px; color: var(--pink); }
/* Нижняя полоса: оплат · платили · средний чек — во всю ширину карточки */
.ast-hero__facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 12px -16px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(11, 10, 20, 0.22);
}
.ast-hero__spark + .ast-hero__facts { margin-top: 0; }
.ast-hero__fact { min-width: 0; padding: 9px 10px 11px 16px; }
.ast-hero__fact + .ast-hero__fact { border-left: 1px solid rgba(255, 255, 255, 0.08); }
.ast-hero__fact-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.ast-hero__fact-label { margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 600; color: var(--muted); }

.ast-tile {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 122px;
  padding: 12px 12px 0;
  overflow: hidden;
  border-radius: var(--r);
  background: var(--card);
  border: 1px solid var(--line);
}
.ast-tile__label { font-size: 12px; font-weight: 600; color: var(--muted); }
.ast-tile__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 6px; margin-top: 4px; }
.ast-tile__value { min-width: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; overflow-wrap: anywhere; }
.ast-tile__sub { margin-top: 3px; padding-bottom: 8px; font-size: 11px; line-height: 1.35; color: var(--muted-2); }
.ast-tile__spark { height: 30px; margin: auto 0 0 -12px; }
.ast-tile--bad .ast-tile__value { color: var(--red); }
.ast-tile--bad .ast-tile__spark { color: var(--red); }

/* Дельта к прошлому периоду: стрелка + цвет (рост хорош) */
.ast-delta {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.4;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  animation: fade-in var(--t) var(--ease) both;
}
.ast-delta.is-up { color: var(--green); background: rgba(45, 212, 160, 0.12); }
.ast-delta.is-down { color: var(--red); background: rgba(255, 77, 94, 0.12); }
.ast-delta.is-flat { color: var(--muted); background: rgba(255, 255, 255, 0.06); }

/* Спарклайн: SVG растянут по ширине, точка — последний день */
.ast-spark { position: relative; display: block; color: var(--violet); }
.ast-spark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.ast-spark__line { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ast-spark__area { fill: currentColor; opacity: 0.14; }
.ast-spark__dot {
  position: absolute;
  right: 0;
  width: 7px;
  height: 7px;
  margin: -3.5px -3.5px 0 0;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px var(--card);
}
.ast-hero .ast-spark__dot { box-shadow: 0 0 0 3px rgba(255, 45, 120, 0.25); }

/* ---------- Панели ---------- */
.ast-panel { min-width: 0; padding: 16px; border-radius: var(--r-lg); background: var(--card); border: 1px solid var(--line); }
.ast-panel__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 10px; margin-bottom: 12px; }
.ast-panel__title { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: -0.01em; }
.ast-panel__aside { font-size: 11px; color: var(--muted-2); }
.ast-panel__sub { margin: 14px 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.ast-empty { padding: 16px 0 6px; font-size: 13px; color: var(--muted); text-align: center; }

/* Чипы выбора метрики — две строки (13 чипов в одну — 1 200 px прокрутки), лишнее листается вбок */
.ast-metrics {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, auto);
  justify-content: start;
  gap: 6px;
  overflow-x: auto;
  margin: 0 -16px 4px;
  padding: 2px 16px 10px; /* запас снизу под свечение активного чипа */
  scrollbar-width: none;
}
.ast-metrics::-webkit-scrollbar { display: none; }
.ast-metrics .chip { min-height: 40px; padding: 0 14px; white-space: nowrap; }

/* ---------- График ---------- */
.ast-chart__readout { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; min-height: 42px; }
.ast-chart__when { display: flex; flex-direction: column; gap: 1px; min-width: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.ast-chart__note { font-size: 11px; font-weight: 500; color: var(--muted-2); }
.ast-chart__value { flex: 0 0 auto; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ast-chart__frame { position: relative; margin-top: 12px; padding-left: 38px; }
/* Весь график — одна цель касания: день выбирается ведением пальца (ближайший столбик, stats-chart.js).
   pan-y — вертикальная прокрутка страницы пальцем по графику по-прежнему работает */
.ast-chart__plot {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 168px;
  cursor: pointer;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
.ast-chart__plot:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: 6px; }
.ast-chart__plot.is-dense { gap: 2px; }
.ast-chart__grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px dashed var(--line); pointer-events: none; }
.ast-chart__grid.is-zero { border-top: 1px solid var(--line-2); }
.ast-chart__tick {
  position: absolute;
  right: calc(100% + 8px);
  top: -7px;
  font-size: 10px;
  line-height: 14px;
  color: var(--muted-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ast-chart__empty {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--muted-2);
  pointer-events: none;
}
.ast-chart__avg { position: absolute; left: 0; right: 0; z-index: 3; height: 0; border-top: 1.5px dashed rgba(255, 45, 120, 0.6); pointer-events: none; }
.ast-chart__col {
  position: relative;
  z-index: 2;
  flex: 1 1 0;
  min-width: 0;
  padding: 0;
  border-radius: 6px 6px 0 0;
  background: transparent;
  pointer-events: none;
  transition: background var(--t-fast);
}
.ast-chart__col.is-active { background: rgba(255, 255, 255, 0.05); }
.ast-chart__bar {
  position: absolute;
  left: 14%;
  right: 14%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, var(--violet), rgba(139, 92, 246, 0.6));
  transition: background var(--t-fast);
}
.ast-chart__plot.is-dense .ast-chart__bar { left: 0; right: 0; border-radius: 2px 2px 0 0; }
.ast-chart__bar.is-neg { border-radius: 0 0 4px 4px; background: var(--red); }
.ast-chart__bar.is-zero { background: var(--line-2); }
.ast-chart__col.is-today .ast-chart__bar:not(.is-zero):not(.is-neg) {
  background: repeating-linear-gradient(135deg, rgba(139, 92, 246, 0.75) 0 4px, rgba(139, 92, 246, 0.4) 4px 8px);
}
.ast-chart__col.is-active .ast-chart__bar:not(.is-zero) { background: var(--grad-diag); }
/* Подписи дней — каждая сама по себе под своим столбиком (stats-chart.js axis), крайние прижаты к краям */
.ast-chart__axis { position: relative; height: 14px; margin-top: 6px; }
.ast-chart__day {
  position: absolute;
  top: 0;
  font-size: 10px;
  line-height: 14px;
  color: var(--muted-2);
  white-space: nowrap;
}

/* ---------- Топ персонажей ----------
   Переключатель метрики — общий компонент .seg; на узком экране пункты не влезают — строка листается
   с затуханием края (edge-fade.js) */
.ast-seg {
  gap: 2px;
  margin-bottom: 6px;
  overflow-x: auto;
  background: var(--bg-2);
  scrollbar-width: none;
}
.ast-seg::-webkit-scrollbar { display: none; }
.ast-seg__item { flex: 1 0 auto; padding: 0 10px; font-size: 13px; white-space: nowrap; }

.ast-top { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.ast-top__row {
  display: grid;
  grid-template-columns: 18px 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  animation: rise-in 260ms var(--ease) both;
}
.ast-top__row:first-child { border-top: 0; }
.ast-top__pos { font-size: 13px; font-weight: 800; color: var(--muted-2); text-align: center; font-variant-numeric: tabular-nums; }
.ast-top__row.is-podium .ast-top__pos { color: var(--pink); }
.ast-top__ava.avatar { width: 40px; height: 40px; font-size: 15px; }
.ast-top__row.is-podium .ast-top__ava.avatar { box-shadow: 0 0 0 2px var(--card), 0 0 0 3px rgba(255, 45, 120, 0.55); }
.ast-top__body { min-width: 0; }
.ast-top__name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ast-top__title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 700; }
.ast-top__tag { flex: 0 0 auto; padding: 0 6px; border-radius: 999px; font-size: 10px; font-weight: 700; line-height: 16px; color: var(--muted); border: 1px solid var(--line-2); }
.ast-top__hearts { flex: 0 0 auto; font-size: 11px; font-weight: 800; color: var(--pink); white-space: nowrap; animation: fade-in var(--t) var(--ease) both; }
.ast-top__track { display: block; height: 4px; margin-top: 6px; overflow: hidden; border-radius: 2px; background: var(--line); }
.ast-top__bar { display: block; height: 100%; border-radius: 2px; background: var(--grad); }
.ast-top__others { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--muted-2); }
.ast-top__value { min-width: 48px; font-size: 15px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ast-top__value small { display: block; font-size: 10px; font-weight: 600; color: var(--muted-2); }

/* ---------- Монетизация, себестоимость, рефералы ---------- */
.ast-minis { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
/* Телефон: две колонки, нечётная последняя цифра — во всю ширину (без «дырки» справа) */
@media (max-width: 719px) {
  .ast-minis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ast-minis > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}
.ast-minis--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 4px; }
.ast-mini { min-width: 0; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); }
.ast-mini__value { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.ast-mini__label { margin-top: 1px; font-size: 11px; font-weight: 600; color: var(--muted); }
.ast-mini__hint { margin-top: 2px; font-size: 10px; line-height: 1.3; color: var(--muted-2); }

.ast-margin { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 12px; }
.ast-margin__label { font-size: 13px; font-weight: 600; color: var(--muted); }
.ast-margin__value { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.ast-margin__rate { font-size: 13px; font-weight: 700; color: var(--muted); }
.ast-bars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.ast-bars__row { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 12px; }
.ast-bars__label { color: var(--muted); }
.ast-bars__track { display: flex; gap: 2px; height: 10px; overflow: hidden; border-radius: 5px; background: var(--line); }
.ast-bars__fill { flex: 0 0 auto; height: 100%; border-radius: 5px; }
.ast-bars__fill--rev { background: var(--violet); }
.ast-bars__fill--erofy { background: var(--pink); }
.ast-bars__fill--llm { background: var(--amber); }
.ast-bars__value { min-width: 64px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.ast-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding-left: 68px; font-size: 11px; color: var(--muted); }
.ast-legend__item { display: inline-flex; align-items: center; gap: 6px; }
.ast-legend__item::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.ast-legend__item--erofy::before { background: var(--pink); }
.ast-legend__item--llm::before { background: var(--amber); }

.ast-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.ast-line__label { min-width: 0; font-size: 13px; }
.ast-line__hint { margin-top: 2px; font-size: 11px; color: var(--muted-2); }
.ast-line__value { flex: 0 0 auto; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.ast-good { color: var(--green); }
.ast-bad { color: var(--red); }
.ast-note { margin: 8px 0 0; font-size: 11px; line-height: 1.45; color: var(--muted-2); }
.ast-foot { padding: 2px 0 8px; font-size: 11px; color: var(--muted-2); text-align: center; }

.ast-refs { display: flex; flex-direction: column; gap: 10px; }
.ast-ref { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.ast-ref__ava.avatar { width: 32px; height: 32px; font-size: 13px; }
.ast-ref__body { min-width: 0; }
.ast-ref__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; }
.ast-ref__bar { display: block; height: 4px; margin-top: 5px; border-radius: 2px; background: var(--violet); }
.ast-ref__count { font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }

.ast-cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.ast-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

/* ---------- Скелетон загрузки ---------- */
.ast-sk { border: 0; }
.ast-sk--title { width: 150px; height: 36px; border-radius: 10px; } /* = период + «обновлено» */
.ast-sk--switch { width: 220px; height: calc(var(--tap) + 8px); border-radius: 999px; } /* = период .seg + «Обновить» */
.ast-sk--chart { height: 300px; border-radius: var(--r-lg); }

/* ---------- Планшет и шире ---------- */
@media (min-width: 720px) {
  .ast-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  /* Карточка на две строки плиток: график растягивается, полоса цифр прижата к низу */
  .ast-hero { grid-column: span 2; grid-row: span 2; padding: 18px 20px 0; }
  .ast-hero__value { font-size: 52px; }
  .ast-hero__spark { flex: 1 1 56px; height: auto; min-height: 56px; max-height: 120px; margin-left: -20px; }
  .ast-hero__facts { margin: auto -20px 0; }
  /* Без графика (продаж не было) сумма стоит посередине между подписью и полосой цифр */
  .ast-hero__main { margin-top: auto; }
  .ast-hero__spark + .ast-hero__facts { margin-top: 0; }
  .ast-hero__fact { padding: 12px 12px 14px 20px; }
  .ast-hero__fact-value { font-size: 18px; }
  .ast-chart__plot { height: 210px; }
  .ast-side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .ast-side > :first-child { grid-column: 1 / -1; }
}

@media (min-width: 1024px) {
  .ast { gap: 16px; }
  .ast-cols { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; gap: 16px; }
  .ast-side { display: flex; align-items: stretch; }
  .ast-chart__plot { height: 240px; }
  .ast-tile__value { font-size: 24px; }
}
