/* ==========================================================================
   Cynex Stats — дизайн-система веб-панели.
   Mobile first: базовые стили — телефон, затем 640px (планшет) и 960px (десктоп).
   ========================================================================== */

@font-face {
  font-family: 'Inter';
  src: url('fonts/Inter-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Inter';
  src: url('fonts/Inter-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Нейтральные (слейт) */
  --page: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --line: #e5e9f0;
  --line-strong: #d3dae5;
  --ink-900: #0f172a;
  --ink-800: #1e293b;
  --ink-700: #334155;
  --ink-500: #64748b;
  --ink-400: #94a3b8;

  /* Бренд (индиго) */
  --brand-50: #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;

  /* Данные: голос (бирюза), участники (графит) */
  --teal-500: #14b8a6;
  --teal-600: #0d9488;
  --teal-50: #f0fdfa;

  /* Семантика */
  --good-fg: #047857;
  --good-bg: #ecfdf5;
  --bad-fg: #b42318;
  --bad-bg: #fef3f2;
  --flat-fg: #475467;
  --flat-bg: #f2f4f7;
  --warn-fg: #b54708;
  --warn-bg: #fffaeb;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;

  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.05);
  --shadow-md: 0 1px 3px rgb(16 24 40 / 0.06), 0 10px 28px -14px rgb(16 24 40 / 0.14);

  --gutter: 16px;
  --font-sans:
    'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
}

@media (min-width: 640px) {
  :root {
    --gutter: 24px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  background: var(--page);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  width: 100%;
  overflow-x: hidden;
  background: var(--page);
  color: var(--ink-700);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: 'cv11', 'ss01';
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  color: var(--ink-900);
  background: var(--brand-200);
}

:where(a, button, select):focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

a {
  color: var(--brand-600);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--brand-700);
}

button,
select {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--ink-900);
  letter-spacing: -0.015em;
}

p {
  margin: 0;
}

main,
header,
footer,
#app-view,
#login-view,
#content {
  min-width: 0;
  max-width: 100%;
}

main {
  flex: 1 0 auto;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--ink-500);
}

.small {
  font-size: 13px;
}

.wrap {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------- Шапка ---------- */

.hero {
  position: relative;
  isolation: isolate;
  padding-top: 20px;
}

/* Мягкий градиентный фон вместо растрового баннера: легче и чётче на любом экране. */
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 120% at 12% 0%, rgb(99 102 241 / 0.22), transparent 70%),
    radial-gradient(50% 120% at 88% 0%, rgb(20 184 166 / 0.16), transparent 70%),
    linear-gradient(180deg, #e9edff 0%, var(--page) 100%);
}

.hero-banner {
  display: none;
}

.hero-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px 14px;
  padding-bottom: 8px;
}

.logo {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow:
    0 0 0 3px var(--surface),
    var(--shadow-md);
}

.brand-block {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  overflow: hidden;
  color: var(--ink-900);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand {
  overflow: hidden;
  color: var(--ink-500);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spacer {
  display: none;
}

.header-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.auth-area {
  display: contents;
}

.user-identity {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-right: auto;
  color: var(--ink-700);
  font-size: 14px;
  font-weight: 500;
}

.user-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--brand-100);
  color: var(--brand-700);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}

.user-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-800);
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.locale-switch {
  display: inline-flex;
  flex: none;
  align-items: center;
  height: 36px;
  padding: 3px;
  background: var(--surface-3);
  border-radius: 10px;
}

.locale-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-width: 40px;
  padding: 0 10px;
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  transition:
    color 0.15s ease,
    background-color 0.15s ease,
    box-shadow 0.15s ease;
}

.locale-option:hover {
  color: var(--ink-900);
}

.locale-option.active,
.locale-option.active:hover {
  color: var(--ink-900);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.small-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  color: var(--ink-700);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  cursor: pointer;
  appearance: none;
  transition:
    color 0.15s ease,
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.small-button:hover {
  color: var(--ink-900);
  background: var(--surface-2);
  border-color: var(--ink-400);
}

.link-button {
  color: var(--brand-600);
  font-weight: 500;
  text-decoration: none;
}

/* ---------- Вход ---------- */

#login-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: 40px auto 0;
  max-width: 420px;
  padding: 36px 24px 28px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
}

.login-mark {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: var(--shadow-md);
}

#login-view h1 {
  font-size: 24px;
  font-weight: 600;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  padding: 0 22px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  background: var(--brand-600);
  border-radius: 12px;
  box-shadow:
    0 1px 2px rgb(79 70 229 / 0.3),
    0 8px 20px -10px rgb(79 70 229 / 0.6);
  text-decoration: none;
  transition:
    background-color 0.15s ease,
    transform 0.15s ease;
}

.button:hover {
  color: #fff;
  background: var(--brand-700);
}

.button:active {
  transform: translateY(1px);
}

/* ---------- Выбор сервера и вкладки ---------- */

.controls {
  margin-top: 8px;
}

.guild-picker {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.guild-select {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 46px;
  padding: 0 40px 0 14px;
  color: var(--ink-900);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.guild-picker.open .guild-select {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgb(99 102 241 / 0.16);
}

.guild-badge {
  display: grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  color: var(--brand-700);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  background: var(--brand-100);
  border-radius: 7px;
  object-fit: cover;
}

.guild-select-value {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guild-select-arrow {
  position: absolute;
  top: 50%;
  right: 16px;
  width: 12px;
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E")
    no-repeat center / contain;
  transform: translateY(-50%);
  transition: transform 0.15s ease;
}

.guild-picker.open .guild-select-arrow {
  transform: translateY(-50%) rotate(180deg);
}

.guild-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  z-index: 20;
  max-height: 272px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
}

.guild-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--ink-700);
  font-size: 14px;
  font-weight: 500;
  border-radius: 9px;
  cursor: pointer;
}

.guild-option-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guild-option:hover,
.guild-option.active {
  color: var(--ink-900);
  background: var(--surface-3);
}

.guild-option[aria-selected='true'] {
  color: var(--brand-700);
  font-weight: 600;
  background: var(--brand-50);
}

.guild-option[aria-selected='true']::after {
  content: '';
  flex: none;
  width: 14px;
  height: 14px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%234f46e5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 7.5l3.2 3.2L12 3.5'/%3E%3C/svg%3E")
    no-repeat center / contain;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 4px;
  margin: 16px calc(var(--gutter) * -1) 0;
  padding: 0 var(--gutter);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  background: var(--page);
  border-bottom: 1px solid var(--line);
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  flex: none;
  padding: 14px 10px 13px;
  color: var(--ink-500);
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: 0;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.tab:hover {
  color: var(--ink-900);
}

.tab[aria-selected='true'],
.tab.active {
  color: var(--ink-900);
}

.tab.active::after {
  content: '';
  position: absolute;
  right: 10px;
  bottom: -1px;
  left: 10px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand-600);
}

/* Подсказка «есть ещё вкладки»: мягкое затухание у края, пока есть что прокрутить. */
.tabs.is-scrollable:not(.is-at-end) {
  -webkit-mask-image: linear-gradient(90deg, #000 84%, transparent);
  mask-image: linear-gradient(90deg, #000 84%, transparent);
}

.tabs.is-scrollable:not(.is-at-start):not(.is-at-end) {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 84%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 84%, transparent);
}

#app-view {
  padding-bottom: 8px;
}

#content {
  padding-top: 20px;
}

/* ---------- Заголовки разделов ---------- */

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin: 28px 0 12px;
}

.section-head h2 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-head h2::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-500);
}

.section-head .muted {
  font-size: 13px;
}

/* ---------- Карточки ---------- */

.card,
.card-surface,
.chart-card,
.health-panel,
.heatmap-card,
.members-panel,
.list,
.legal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.cards > :last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 16px;
}

.label {
  color: var(--ink-500);
  font-size: 13px;
  font-weight: 500;
}

.value {
  margin-top: 6px;
  color: var(--ink-900);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-500);
}

.card-foot .muted {
  font-size: 12px;
}

/* Спарклайн в KPI: минимальная высота, без осей. */
.spark {
  position: relative;
  height: 44px;
  margin-top: 12px;
}

.spark canvas {
  width: 100% !important;
  height: 100% !important;
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.delta.good {
  color: var(--good-fg);
  background: var(--good-bg);
}

.delta.bad {
  color: var(--bad-fg);
  background: var(--bad-bg);
}

.delta.flat {
  color: var(--flat-fg);
  background: var(--flat-bg);
}

/* ---------- Здоровье сервера ---------- */

.health-panel {
  display: grid;
  gap: 20px;
  padding: 20px;
}

.health-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.gauge {
  position: relative;
  width: 148px;
  height: 148px;
}

.gauge-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.gauge-track {
  stroke: var(--surface-3);
}

.gauge-ring {
  stroke: var(--brand-600);
  transition: stroke-dasharray 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.gauge-ring.great {
  stroke: var(--good-fg);
}

.gauge-ring.good {
  stroke: var(--brand-600);
}

.gauge-ring.ok {
  stroke: #d97706;
}

.gauge-ring.weak {
  stroke: var(--bad-fg);
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gauge-score {
  color: var(--ink-900);
  font-size: 40px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.gauge-of {
  margin-top: 4px;
  font-size: 12px;
}

.grade {
  display: inline-flex;
  height: 26px;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--brand-50);
  color: var(--brand-700);
}

.grade.great {
  color: var(--good-fg);
  background: var(--good-bg);
}

.grade.ok {
  color: var(--warn-fg);
  background: var(--warn-bg);
}

.grade.weak {
  color: var(--bad-fg);
  background: var(--bad-bg);
}

.health-right {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  min-width: 0;
}

/* ---------- Полоски ---------- */

.bar-list {
  display: grid;
  gap: 16px;
  width: 100%;
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* Внутри блока здоровья полоски уже на карточке — без вложенной рамки. */
.health-panel .bar-list {
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 8px 12px;
  min-width: 0;
}

.bar-row > .bar-label {
  grid-column: 1;
  grid-row: 1;
}

.bar-row > .bar-value {
  grid-column: 2;
  grid-row: 1;
}

.bar-row > .track {
  grid-column: 1 / -1;
  grid-row: 2;
}

.bar-row > .delta {
  grid-column: 1 / -1;
  grid-row: 3;
  justify-self: start;
}

.bar-label {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-800);
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-value {
  color: var(--ink-900);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.track {
  height: 8px;
  overflow: hidden;
  background: var(--surface-3);
  border-radius: 999px;
}

.fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-500), var(--brand-600));
  transition: width 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.fill.accent {
  background: linear-gradient(90deg, var(--brand-400), var(--brand-600));
}

.fill.teal {
  background: linear-gradient(90deg, var(--teal-500), var(--teal-600));
}

.fill.gray {
  background: linear-gradient(90deg, #cbd5e1, #94a3b8);
}

/* ---------- Графики ---------- */

.chart-box {
  min-width: 0;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  margin-top: 12px;
  padding: 16px;
}

.chart-head {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chart-heading {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.chart-title {
  color: var(--ink-900);
  font-size: 16px;
  font-weight: 600;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  color: var(--ink-500);
  font-size: 13px;
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.chart-legend-bar {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--brand-600);
}

.chart-legend-line {
  width: 16px;
  height: 3px;
  border-radius: 2px;
  background: #475569;
}

.chart-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  margin: 0;
}

.chart-stat {
  min-width: 0;
}

.chart-stat dt {
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 500;
}

.chart-stat dd {
  margin: 2px 0 0;
  color: var(--ink-900);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.chart-stat-note {
  display: block;
  margin-top: 2px;
  color: var(--ink-500);
  font-size: 12px;
}

.chart-canvas {
  position: relative;
  height: 220px;
  min-width: 0;
}

.chart-canvas-main {
  height: 240px;
}

.chart-canvas canvas,
.chart-box > canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.members-panel {
  padding: 14px 14px 10px;
  box-shadow: none;
  background: var(--surface-2);
}

.members-title {
  margin-bottom: 4px;
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.members-panel .chart-canvas {
  height: 96px;
}

.chart-hint {
  padding: 10px 12px;
  color: var(--ink-500);
  font-size: 13px;
  background: var(--surface-2);
  border-radius: var(--r-md);
}

/* ---------- Тепловая карта ---------- */

.heatmap-card {
  padding: 16px;
}

.heatmap-scroll {
  margin: 0;
}

.heatmap {
  display: grid;
  grid-template-columns: 30px repeat(24, minmax(0, 1fr));
  gap: 3px;
  align-items: center;
}

.hm-hour {
  color: var(--ink-400);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.hm-day {
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 500;
}

.hm-cell {
  display: block;
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--surface-3);
}

.hm-cell.l0 {
  background: var(--surface-3);
}

.hm-cell.l1 {
  background: var(--brand-100);
}

.hm-cell.l2 {
  background: var(--brand-200);
}

.hm-cell.l3 {
  background: var(--brand-400);
}

.hm-cell.l4 {
  background: var(--brand-600);
}

.hm-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 12px;
  color: var(--ink-500);
  font-size: 12px;
}

.hm-legend .hm-cell {
  width: 14px;
  height: 14px;
  aspect-ratio: auto;
}

/* ---------- Таблица (когорты) ---------- */

.table-wrap {
  overflow-x: auto;
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  scrollbar-width: thin;
}

table {
  width: 100%;
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 11px 8px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

th:first-child,
td:first-child {
  padding-left: 14px;
}

th:last-child,
td:last-child {
  padding-right: 14px;
}

th {
  color: var(--ink-500);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--surface-2);
}

th:nth-child(n + 3) {
  text-align: center;
}

tr:last-child td {
  border-bottom: 0;
}

td:first-child {
  color: var(--ink-900);
  font-weight: 600;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: inherit;
}

td:first-child {
  background: var(--surface);
}

th:first-child {
  background: var(--surface-2);
}

/* Значение когорты — плитка на всю ячейку; белая рамка даёт зазор между плитками. */
td.cell-heat {
  padding: 6px 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-700);
  background: var(--surface-3);
  border: 3px solid var(--surface);
  border-radius: var(--r-sm);
}

td.cell-heat.h0 {
  color: var(--ink-400);
  background: transparent;
}

td.cell-heat.h1 {
  color: var(--brand-700);
  background: var(--brand-50);
}

td.cell-heat.h2 {
  color: var(--brand-700);
  background: var(--brand-100);
}

td.cell-heat.h3 {
  color: #fff;
  background: var(--brand-400);
}

td.cell-heat.h4 {
  color: #fff;
  background: var(--brand-600);
}

@media (max-width: 639px) {
  .table-wrap th,
  .table-wrap td {
    padding-right: 4px;
    padding-left: 4px;
  }

  .table-wrap th:first-child,
  .table-wrap td:first-child {
    padding-left: 10px;
  }

  .table-wrap th:last-child,
  .table-wrap td:last-child {
    padding-right: 10px;
  }

  .table-wrap th {
    font-size: 11px;
    line-height: 1.25;
    white-space: normal;
  }
}

/* ---------- Списки ---------- */

.list {
  margin: 12px 0 0;
  padding: 4px 0;
  list-style: none;
}

.list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-800);
  font-weight: 500;
}

.list li:last-child {
  border-bottom: 0;
}

.list.ranked {
  counter-reset: rank;
}

.list.ranked li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  grid-template-areas:
    'rank name'
    'rank stats';
  align-items: center;
  gap: 4px 12px;
  counter-increment: rank;
}

.list.ranked li::before {
  content: counter(rank);
  display: grid;
  grid-area: rank;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--ink-700);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.list.ranked li:nth-child(1)::before {
  background: #fef3c7;
  color: #92400e;
}

.list.ranked li:nth-child(2)::before {
  background: #e2e8f0;
  color: #334155;
}

.list.ranked li:nth-child(3)::before {
  background: #ffedd5;
  color: #9a3412;
}

.rank-name {
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-900);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-stats {
  display: flex;
  grid-area: stats;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 6px;
}

.rank-stats span {
  padding: 3px 9px;
  color: var(--ink-700);
  font-size: 13px;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rank-stats span.is-active {
  color: var(--brand-700);
  font-weight: 600;
  background: var(--brand-50);
  border-color: var(--brand-200);
}

.segmented {
  display: inline-flex;
  max-width: 100%;
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  overflow-x: auto;
  background: var(--surface-3);
  border-radius: 12px;
  scrollbar-width: none;
}

/* Два переключателя (период и сортировка) в одну строку; на узком экране переносятся. */
.segmented-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.segmented-row .segmented {
  margin-top: 0;
}

/* Переключатель не должен прилипать к карточкам KPI/пустому состоянию. */
.segmented + .cards,
.segmented + .empty,
.segmented-row + .empty,
.segmented-row + .cards {
  margin-top: 12px;
}

.seg {
  flex: none;
  height: 34px;
  padding: 0 14px;
  color: var(--ink-500);
  font-size: 13px;
  font-weight: 500;
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    color 0.15s ease,
    background-color 0.15s ease;
}

.seg:hover {
  color: var(--ink-900);
}

.seg.active {
  color: var(--ink-900);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ---------- Пустые состояния и загрузка ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 36px 20px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  color: var(--ink-500);
  font-size: 14px;
}

.empty strong {
  color: var(--ink-800);
  font-size: 15px;
  font-weight: 600;
}

.empty.ok {
  border-style: solid;
  border-color: #a7f3d0;
  background: var(--good-bg);
}

.empty.ok strong {
  color: var(--good-fg);
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 0%, #f8fafc 50%, var(--surface-3) 100%);
  background-size: 200% 100%;
  border-radius: var(--r-lg);
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-wrap {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.card-sk {
  height: 104px;
}

.block-sk {
  height: 240px;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* ---------- Ошибки и подвал ---------- */

.error {
  margin: 16px 0 0;
  padding: 12px 16px;
  color: var(--bad-fg);
  font-size: 14px;
  background: var(--bad-bg);
  border: 1px solid #fecdca;
  border-radius: var(--r-md);
}

footer.wrap {
  margin-top: 40px;
  padding-top: 24px;
  padding-bottom: 32px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  color: var(--ink-500);
  font-size: 13px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  max-width: 100%;
  gap: 4px 8px;
}

.footer-links a {
  white-space: nowrap;
}

@media (max-width: 639px) {
  .footer-links {
    gap: 6px 14px;
  }

  .footer-links [aria-hidden='true'] {
    display: none;
  }
}

/* ---------- Юридические страницы ---------- */

.legal {
  max-width: 760px;
  margin: 24px auto 0;
  padding: 28px 22px;
}

.legal h1 {
  font-size: 26px;
}

.legal-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.legal-updated {
  color: var(--ink-500);
  font-size: 13px;
}

.legal-back {
  margin: 0;
}

.legal-page {
  padding-bottom: 24px;
}

/* ---------- Адаптация ---------- */

@media (min-width: 640px) {
  .brand-name {
    font-size: 20px;
  }

  .logo {
    width: 60px;
    height: 60px;
  }

  .header-actions {
    width: auto;
    margin-left: auto;
  }

  .user-identity {
    margin-right: 0;
  }

  .cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
  }

  .cards:has(> :nth-child(3):last-child) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .cards > :last-child:nth-child(odd) {
    grid-column: auto;
  }

  .card {
    padding: 20px;
  }

  .value {
    font-size: 30px;
  }

  .chart-card {
    padding: 22px;
  }

  .chart-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .chart-stats {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    min-width: 260px;
  }

  .chart-canvas {
    height: 260px;
  }

  .chart-canvas-main {
    height: 280px;
  }

  .heatmap-card {
    padding: 20px;
  }

  .heatmap {
    grid-template-columns: 40px repeat(24, minmax(0, 1fr));
    gap: 4px;
  }

  .hm-cell {
    border-radius: 5px;
  }
}

@media (min-width: 960px) {
  .health-panel {
    grid-template-columns: 220px minmax(0, 1fr);
    align-items: center;
    gap: 40px;
    padding: 28px 32px;
  }

  .health-left {
    gap: 14px;
  }

  .gauge {
    width: 168px;
    height: 168px;
  }

  .bar-list {
    gap: 20px;
    padding: 22px 24px;
  }

  .bar-row {
    grid-template-columns: 180px minmax(0, 1fr) 90px;
    grid-template-rows: auto;
    gap: 14px;
  }

  .bar-row > .bar-label {
    grid-column: 1;
    grid-row: 1;
  }

  .bar-row > .track {
    grid-column: 2;
    grid-row: 1;
  }

  .bar-row > .bar-value {
    grid-column: 3;
    grid-row: 1;
    text-align: right;
  }

  .bar-row > .delta {
    grid-column: 2 / -1;
    grid-row: 2;
  }

  .bar-row.has-extra {
    grid-template-rows: auto auto;
  }

  .tabs {
    margin-left: 0;
    margin-right: 0;
    padding: 0;
    border-radius: 0;
  }

  .tab {
    padding: 14px 14px 13px;
  }

  .tab.active::after {
    right: 14px;
    left: 14px;
  }

  .guild-picker {
    max-width: 380px;
  }

  .list.ranked li {
    grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas: 'rank name stats';
    gap: 12px;
  }

  .rank-stats {
    justify-content: flex-end;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
