:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #fbfbfe;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);

  --brand: #8b1538;

  --good: #16a34a;
  --warn: #f59e0b;
  --bad: #ef4444;
  --ring-bg: rgba(15, 23, 42, 0.08);
  --gauge-track: #cbd5e1;
  --gauge-na: #94a3b8;

  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Apple Color Emoji",
    "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 700px at 20% 0%, #ffffff 0%, var(--bg) 55%, var(--bg) 100%);
  font-variant-numeric: tabular-nums;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.95em;
}

.app {
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  padding: 18px;
  box-sizing: border-box;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: var(--shadow);
}

.topbar__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.topbar__link {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.topbar__link:hover {
  color: var(--text);
  background: rgba(139, 21, 56, 0.06);
}

.topbar__link--current {
  color: var(--brand);
  background: rgba(139, 21, 56, 0.1);
  border-color: rgba(139, 21, 56, 0.18);
}

.brand__title {
  font-weight: 800;
  letter-spacing: 0.04em;
}

.brand__subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 12px;
  align-items: end;
}

.control {
  display: grid;
  gap: 6px;
}

.control__label {
  font-size: 12px;
  color: var(--muted);
}

.control__input {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  height: 40px;
  padding: 0 12px;
  font-weight: 600;
}

.control__input:focus {
  outline: 2px solid rgba(139, 21, 56, 0.22);
  outline-offset: 2px;
}

.button {
  height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(139, 21, 56, 0.25);
  border-radius: 12px;
  background: rgba(139, 21, 56, 0.08);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.button:hover {
  background: rgba(139, 21, 56, 0.12);
}

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

.content {
  margin-top: 16px;
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: 100%;
}

.board-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.board {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.board__head,
.row {
  display: grid;
  width: 100%;
  box-sizing: border-box;
  align-items: center;
  gap: clamp(8px, 1.2vw, 14px);
  padding: 14px clamp(12px, 2vw, 24px);
}

/* Панель: менеджер + 4 метрики + оплата */
.board--metrics .board__head,
.board--metrics .row {
  min-width: 720px;
  grid-template-columns:
    minmax(9.5rem, 1.35fr)
    repeat(4, minmax(5.25rem, 1fr))
    minmax(6.75rem, 1fr);
}

/* Воронка: менеджер + 8 этапов + оплата (этапы с 1fr — иначе малые доли fr оставляют пустоту справа) */
.board--funnel .board__head,
.board--funnel .row {
  min-width: 860px;
  grid-template-columns:
    minmax(9.5rem, 1.2fr)
    repeat(8, minmax(3.25rem, 1fr))
    minmax(6.75rem, 1.15fr);
}

.board__head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(180deg, var(--panel), #f4f6ff);
  border-bottom: 1px solid var(--border);
}

.board__head .col {
  text-align: center;
}

.board__head .col--name {
  text-align: left;
}

.col__title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: rgba(15, 23, 42, 0.82);
}

.col__hint {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.col__title--funnel {
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.01em;
  text-transform: none;
  font-weight: 800;
}

.col__hint--funnel {
  font-size: 10px;
  margin-top: 2px;
  line-height: 1.15;
}

.funnelCell {
  display: grid;
  justify-items: center;
  justify-self: stretch;
  align-content: center;
  gap: 2px;
  min-width: 0;
  padding: 4px 2px;
  text-align: center;
}

.funnelCell__value {
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
}

.funnelCell__conv {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.1;
}

.funnelCell__conv--na {
  color: var(--gauge-na);
  font-weight: 600;
}

/* Конверсия к норме: &lt;70% нормы — красный; 70–89,99% — жёлтый; ≥90% — зелёный */
.funnelCell__conv--bad {
  color: var(--bad);
}

.funnelCell__conv--warn {
  color: var(--warn);
}

.funnelCell__conv--good {
  color: var(--good);
}

.board__body {
  display: grid;
}

.row {
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.row:hover {
  background: rgba(15, 23, 42, 0.015);
}

.row:last-child {
  border-bottom: 0;
}

.name {
  display: grid;
  gap: 2px;
}

.name__main {
  font-weight: 800;
  line-height: 1.05;
}

.name__sub {
  font-size: 12px;
  color: var(--muted);
}

.metric {
  display: grid;
  justify-items: center;
  justify-self: stretch;
  width: 100%;
  min-width: 0;
  gap: 8px;
}

.row > .name {
  justify-self: start;
}

.row > .payment {
  justify-self: stretch;
  width: 100%;
  min-width: 0;
}

.circle {
  width: 84px;
  height: 84px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ring-bg);
  background: rgba(255, 255, 255, 0.35);
}

.circle__value {
  font-weight: 900;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.circle__label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.payment {
  text-align: right;
  padding-right: 8px;
}

.payment__value {
  font-weight: 900;
  font-size: 22px;
  letter-spacing: -0.02em;
  display: inline-block;
  max-width: 100%;
  white-space: nowrap;
}

.payment__label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: none;
}

.gaugeBlock {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: 100%;
  max-width: min(124px, 100%);
}

.gaugeBlock__dial {
  width: 100px;
  height: 44px;
  display: block;
}

.gaugeBlock__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 4px 8px;
  line-height: 1.15;
  text-align: center;
}

.gaugeBlock__value {
  font-weight: 800;
  font-size: 1.375rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.gaugeBlock__unit {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

/* Время ответа: полоса «занято от предела» (не спидометр) */
.timeMetric {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.timeMetric__bar {
  position: relative;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--gauge-track);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.07);
}

.timeMetric__fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: inherit;
  min-width: 0;
  max-width: 100%;
}

.timeMetric__footer {
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
}

.timeMetric__value {
  display: block;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.timeMetric__over,
.timeMetric__under {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.timeMetric__over {
  color: var(--bad);
}

.timeMetric__under {
  color: var(--good);
}

.timeMetric--na .timeMetric__value {
  color: var(--gauge-na);
  font-weight: 700;
  font-size: 1.15rem;
}

.timeMetric--na .timeMetric__bar {
  opacity: 0.88;
}

.timeMetric--overflow .timeMetric__bar {
  box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.55);
}

@media (max-width: 1100px) {
  .board--metrics .board__head,
  .board--metrics .row {
    grid-template-columns:
      minmax(8.5rem, 1.2fr)
      repeat(4, minmax(4.75rem, 0.95fr))
      minmax(6rem, 0.85fr);
    gap: 8px;
    padding: 12px 10px;
  }

  .board--funnel .board__head,
  .board--funnel .row {
    grid-template-columns:
      minmax(8rem, 1.15fr)
      repeat(8, minmax(3rem, 1fr))
      minmax(5.75rem, 1.05fr);
    gap: 8px;
    padding: 12px 10px;
  }

  .funnelCell__value {
    font-size: 0.9rem;
  }

  .payment__value {
    font-size: 20px;
  }
}

@media (max-width: 920px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .controls {
    justify-content: space-between;
  }

  .board__head {
    display: none;
  }

  /*
   * Сброс desktop min-width и сетки строк (860px / 720px и 10/6 колонок).
   * Иначе .row остаётся с grid-template-columns от .board--funnel/.board--metrics
   * (специфичность выше, чем у голого .row { 1fr }) — единственный .rowCard
   * садится в первую дорожку (~10–12% ширины), мини-воронка сжимается в «полоску».
   */
  .board.board--funnel .row,
  .board.board--metrics .row {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    grid-template-columns: 1fr;
  }

  .board__body {
    display: grid;
    width: 100%;
    min-width: 0;
    justify-items: stretch;
  }

  .row {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 16px;
    min-width: 0;
  }

  .rowCard {
    display: grid;
    gap: 12px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    justify-items: stretch;
  }

  /* Карточка менеджера на всю ширину строки таблицы */
  .board .row > .rowCard {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    justify-self: stretch;
  }

  .rowCard__top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }

  .rowCard__payment {
    text-align: right;
  }

  /* Панель: 4 метрики — на узком экране 2×2, с ~540px — один ряд из 4 */
  .rowCard__grid--metrics4 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .rowCard__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  /* Компактнее датчики на мобильной панели (раньше круги 84px разъезжались в огромных ячейках 2×2) */
  .board--metrics .row .circle {
    width: 72px;
    height: 72px;
  }

  .board--metrics .row .circle__value {
    font-size: 18px;
  }

  .board--metrics .row .circle__label {
    font-size: 10px;
    margin-top: 4px;
    line-height: 1.2;
    max-width: 11rem;
  }

  .board--metrics .row .gaugeBlock {
    max-width: min(104px, 100%);
  }

  .board--metrics .row .gaugeBlock__dial {
    width: 96px;
    height: 42px;
  }

  .board--metrics .row .gaugeBlock__value {
    font-size: 1.125rem;
  }

  .board--metrics .row .gaugeBlock__unit {
    font-size: 0.7rem;
  }

  .board--metrics .row .timeMetric {
    gap: 6px;
    width: 100%;
    max-width: 7.5rem;
    justify-self: center;
  }

  .board--metrics .row .timeMetric__bar {
    height: 8px;
  }

  .board--metrics .row .timeMetric__value {
    font-size: 1.05rem;
  }

  .board--metrics .row .timeMetric__over,
  .board--metrics .row .timeMetric__under {
    font-size: 0.65rem;
  }

  .payment__label {
    display: none;
  }

  .rowCard__funnel {
    display: block;
    margin-top: 4px;
    padding-top: 12px;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .rowCard__funnelHead {
    font-size: 12px;
    font-weight: 800;
    color: rgba(15, 23, 42, 0.82);
    margin-bottom: 10px;
  }

  .rowCard__funnelHint {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
  }

  /*
   * Явное число колонок (не auto-fill): иначе в части браузеров сетка сжимается
   * по max-content и остаётся одна «полоска» слева.
   */
  .funnelMiniGrid {
    display: grid;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
  }

  .funnelMini {
    display: grid;
    gap: 4px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.5);
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .funnelMini__label {
    font-size: 11px;
    font-weight: 700;
    color: rgba(15, 23, 42, 0.75);
    line-height: 1.2;
  }

  .funnelMini__nums {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 6px 10px;
    width: 100%;
  }

  .funnelMini__value {
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
  }

  .funnelMini__conv {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
  }

  .funnelMini__conv--na {
    color: var(--gauge-na);
    font-weight: 600;
  }

  .funnelMini__conv--bad {
    color: var(--bad);
  }

  .funnelMini__conv--warn {
    color: var(--warn);
  }

  .funnelMini__conv--good {
    color: var(--good);
  }

  .funnelMini__norm {
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1.2;
    margin-bottom: 2px;
  }
}

@media (min-width: 480px) and (max-width: 920px) {
  .funnelMiniGrid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 640px) and (max-width: 920px) {
  .funnelMiniGrid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Панель: на ширине до 920px четыре метрики в один ряд */
@media (min-width: 540px) and (max-width: 920px) {
  .board--metrics .rowCard__grid--metrics4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .board--metrics .row .circle__label {
    max-width: none;
  }

  .board--metrics .row .gaugeBlock {
    max-width: 100%;
  }

  .board--metrics .row .timeMetric {
    max-width: 100%;
  }
}

@media (max-width: 440px) {
  .app {
    padding: 12px;
  }

  .control__input,
  .button {
    height: 44px;
  }

  .rowCard__grid,
  .rowCard__grid--metrics4 {
    grid-template-columns: 1fr;
  }

  .rowCard__grid--tiny {
    grid-template-columns: 1fr;
  }
}

/* Совсем узкий телефон — одна колонка карточек воронки на всю ширину */
@media (max-width: 380px) {
  .funnelMiniGrid {
    grid-template-columns: minmax(0, 1fr);
  }
}
