/* Аналитика — полноэкранный overlay поверх layout (этап «Аналитика»).
   Токены Notion из base.css, цвета не хардкодим. */

.analytics-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* safe-area: страница на весь экран, учитываем вырезы */
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.analytics-view[hidden] {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── Шапка ── */
.an-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.an-title {
  flex: 1;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.an-close {
  color: var(--text-secondary);
}

.an-account-select {
  max-width: 180px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* ── Тело (скролл) ── */
.an-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

/* ── Карточка ── */
.an-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.an-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.an-card__head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ── Сегментный контрол ── */
.an-seg {
  display: inline-flex;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.an-seg__btn {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.an-seg__btn.is-active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 15, 15, 0.08);
}

/* ── Блок «Новые чаты за период» ── */
.an-nc__cap {
  margin: -4px 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.an-nc__tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.an-nc__tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  text-align: left;
}

.an-nc__tile.is-active {
  border-color: var(--accent-blue);
  background: var(--bg-secondary);
}

.an-nc__num {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.an-nc__per {
  font-size: 12px;
  color: var(--text-secondary);
}

.an-nc__list {
  display: flex;
  flex-direction: column;
  margin-top: 12px;
}

.an-nc__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.an-nc__row:last-child {
  border-bottom: none;
}

.an-nc__count {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

/* ── Блок A: скорость ответа ── */
.an-rt__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.an-rt__median {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
  margin: 2px 0 6px;
}

.an-rt__sub {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.an-rt__sub b {
  color: var(--text);
  font-weight: 600;
}

.an-rt__waiting {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
  background: #fef3c7;
}

.an-rt__waiting b {
  font-weight: 700;
}

.an-rt__chart {
  position: relative;
  height: 80px;
  margin-top: 14px;
}

.an-rt__hint {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.an-rt__empty {
  margin: 8px 0;
}

/* ── Блок B: heatmap ── */
.an-hm__cap {
  margin: -4px 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.an-hm__scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Сетка: 1 колонка под подпись дня + 24 колонки часов. */
.an-hm__grid {
  display: grid;
  grid-template-columns: 28px repeat(24, 1fr);
  gap: 2px;
  min-width: 520px;
}

.an-hm__corner {
  grid-column: 1;
}

.an-hm__hours {
  grid-column: 2 / span 24;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
}

.an-hm__hour {
  font-size: 9px;
  color: var(--text-muted);
  text-align: left;
}

.an-hm__day {
  grid-column: 1;
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
}

.an-hm__row {
  grid-column: 2 / span 24;
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  gap: 2px;
}

.an-hm__cell {
  aspect-ratio: 1 / 1;
  border-radius: 2px;
  min-height: 14px;
}

/* ── Блок C: топ-10 ── */
.an-top__list {
  display: flex;
  flex-direction: column;
}

.an-top__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.an-top__row:last-child {
  border-bottom: none;
}

.an-top__thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.an-top__thumb--empty {
  background: var(--bg-secondary);
}

.an-top__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.an-top__title {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.an-top__count {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

/* Бейдж аккаунта — переиспользуем цветовые токены (account_id % 6). */
.an-badge {
  align-self: flex-start;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 10px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.an-badge[data-account-color="0"] { background: var(--badge-color-0-bg); color: var(--badge-color-0-text); }
.an-badge[data-account-color="1"] { background: var(--badge-color-1-bg); color: var(--badge-color-1-text); }
.an-badge[data-account-color="2"] { background: var(--badge-color-2-bg); color: var(--badge-color-2-text); }
.an-badge[data-account-color="3"] { background: var(--badge-color-3-bg); color: var(--badge-color-3-text); }
.an-badge[data-account-color="4"] { background: var(--badge-color-4-bg); color: var(--badge-color-4-text); }
.an-badge[data-account-color="5"] { background: var(--badge-color-5-bg); color: var(--badge-color-5-text); }

/* ── Состояния ── */
.an-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px 16px;
  color: var(--text-secondary);
  text-align: center;
}

.an-state__msg {
  margin: 0;
  color: var(--text);
}

.an-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: an-spin 0.8s linear infinite;
}

@keyframes an-spin {
  to { transform: rotate(360deg); }
}

.an-empty {
  padding: 16px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.an-btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-blue);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

.an-btn:hover {
  background: var(--accent-hover);
}

/* ── Блок D: поток сообщений по дням (стэк ночь/день/вечер) ── */
.an-mv__cap {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.an-mv__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

.an-mv__legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.an-mv__dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.an-mv__chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.an-mv__col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.an-mv__stack {
  width: 100%;
  height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.an-mv__seg {
  width: 100%;
}

.an-mv__seg--night {
  background: #6366f1;
}

.an-mv__seg--day {
  background: #2383e2;
}

.an-mv__seg--evening {
  background: #f59e0b;
}

.an-mv__xlabel {
  font-size: 10px;
  color: var(--text-muted);
}

/* ── Мобила (≤768px) ── */
@media (max-width: 768px) {
  .an-rt__median {
    font-size: 34px;
  }
  /* 24 столбца не ломают верстку: сетка скроллится по горизонтали (.an-hm__scroll). */
  .an-hm__grid {
    min-width: 560px;
  }
  .an-account-select {
    max-width: 140px;
  }
}
