/* Цвета — из темы Telegram (--tg-theme-*). Запасные значения — для открытия в обычном браузере. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-2: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #16161a);
  --hint: var(--tg-theme-hint-color, #8a8a93);
  --link: var(--tg-theme-link-color, #2d7fd3);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --button: var(--tg-theme-button-color, #2d7fd3);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --heading: var(--tg-theme-section-header-text-color, var(--accent));
  --danger: var(--tg-theme-destructive-text-color, #d93b3b);

  --display: "Unbounded", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius-outer: 18px;
  --pad: 16px;
  --radius-inner: 10px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17171b;
    --bg-2: #0f0f12;
    --text: #f2f2f5;
    --hint: #8d8d97;
    --link: #6ab2f2;
    --button: #3d8fe0;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg-2);
  color: var(--text);
  font: 16px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  padding: 0 0 calc(24px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin-inline: auto;
  overflow-wrap: anywhere;
}

h1, h2 { text-wrap: balance; margin: 0; }
p { margin: 0; text-wrap: pretty; }

.masthead { padding: 20px var(--pad) 8px; }
.fest {
  font: 700 22px/1.1 var(--display);
  letter-spacing: -0.01em;
}
.hello { color: var(--hint); margin-top: 6px; }
.hello:empty { display: none; }

main { display: grid; gap: 12px; padding: 8px 12px 0; }

.state { color: var(--hint); padding: 32px var(--pad); text-align: center; }

.section, .state-card, .balance {
  background: var(--section);
  border-radius: var(--radius-outer);
  padding: var(--pad);
  display: grid;
  gap: 10px;
}
.section-plain { background: transparent; padding-block: 4px; }
.section h2, .state-card h2 {
  font: 600 15px/1.3 var(--body);
  color: var(--heading);
}
.hint { color: var(--hint); font-size: 14px; }

/* Баланс — главная и единственная крупная деталь экрана. */
.balance { padding-block: 22px 18px; }
.balance-caption { color: var(--hint); font-size: 14px; }
.balance-value {
  font: 700 clamp(44px, 15vw, 64px)/1 var(--display);
  letter-spacing: -0.03em;
  color: var(--text);
}
.balance-split { display: flex; gap: 24px; margin: 4px 0 0; }
.balance-split div { display: grid; gap: 2px; }
.balance-split dt { color: var(--hint); font-size: 13px; }
.balance-split dd { margin: 0; font: 500 17px/1.2 var(--display); }

.ref-link {
  background: var(--bg-2);
  border-radius: var(--radius-inner); /* внешний 18 ≈ 10 + отступ блока */
  padding: 10px 12px;
  font-size: 15px;
  user-select: all;
}

.row-actions, .form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.button {
  appearance: none;
  border: 0;
  border-radius: var(--radius-inner);
  background: var(--button);
  color: var(--button-text);
  font: 600 15px/1 var(--body);
  min-height: 44px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  transition-property: scale, opacity;
  transition-duration: 160ms;
  transition-timing-function: var(--ease);
}
.button:active { scale: 0.96; }
.button:disabled { opacity: 0.55; cursor: default; }
.button-quiet {
  background: var(--bg-2);
  color: var(--link);
}
.row-actions .button { flex: 1 1 140px; }

.link-button {
  appearance: none;
  background: none;
  border: 0;
  color: var(--link);
  font: inherit;
  min-height: 44px;
  padding: 0 4px;
  cursor: pointer;
}

:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* Команда: три ступени — уровень 1, 2, 3. */
.team { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.team details {
  background: var(--bg-2);
  border-radius: var(--radius-inner);
}
.team summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 12px;
  cursor: pointer;
}
.team summary::-webkit-details-marker { display: none; }
.team .step {
  font: 700 13px/1 var(--display);
  width: 28px; height: 28px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--button);
  color: var(--button-text);
  flex: none;
}
.team li:nth-child(2) .step { opacity: 0.75; }
.team li:nth-child(3) .step { opacity: 0.5; }
.team .level-name { flex: 1; }
.team .level-count { font: 500 17px/1 var(--display); }
.team .chevron {
  color: var(--hint);
  transition: rotate 200ms var(--ease);
}
.team details[open] .chevron { rotate: 90deg; }
.team .members { list-style: none; margin: 0; padding: 0 12px 10px 52px; display: grid; gap: 8px; }
.team .members li { display: grid; }
.team .members small, .team .members .muted { color: var(--hint); font-size: 13px; }

.ops { list-style: none; margin: 0; padding: 0; display: grid; }
.ops li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--hint) 20%, transparent);
}
.ops li:last-child { box-shadow: none; }
.ops .what { display: grid; gap: 2px; min-width: 0; }
.ops .what small { color: var(--hint); font-size: 13px; }
.ops .amount { font: 500 16px/1.3 var(--display); white-space: nowrap; }
.ops .plus { color: var(--accent); }
.empty { color: var(--hint); font-size: 15px; }

/* Анкета */
.form { gap: 14px; }
.field { display: grid; gap: 6px; }
.field span { font-size: 14px; color: var(--hint); }
.field input, .field textarea, .field select, .search input, .refund-form input {
  font: 16px/1.3 var(--body); /* 16px — чтобы iOS не увеличивал страницу при фокусе */
  color: var(--text);
  background: var(--bg-2);
  border: 0;
  border-radius: var(--radius-inner);
  padding: 12px;
  min-height: 46px;
  box-shadow: inset 0 0 0 1px transparent;
  transition: box-shadow 160ms var(--ease);
}
.field textarea { resize: vertical; min-height: 120px; }
.field input:focus, .field textarea:focus, .field select:focus, .search input:focus, .refund-form input:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--link);
}
.field [aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--danger); }
.consent { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; cursor: pointer; }
/* Свой чекбокс: родной в тёмной теме Telegram оставался ярко-белым. */
.consent input {
  appearance: none;
  width: 22px; height: 22px;
  margin: 1px 0 0;
  flex: none;
  border-radius: 6px;
  background: var(--bg-2);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--hint) 70%, transparent);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition-property: background-color, box-shadow;
  transition-duration: 160ms;
  transition-timing-function: var(--ease);
}
.consent input::before {
  content: "";
  width: 12px; height: 12px;
  background: var(--button-text);
  clip-path: polygon(14% 44%, 0 58%, 40% 96%, 100% 22%, 86% 8%, 38% 68%);
  scale: 0.25;
  opacity: 0;
  transition-property: scale, opacity;
  transition-duration: 160ms;
  transition-timing-function: var(--ease);
}
.consent input:checked { background: var(--button); box-shadow: none; }
.consent input:checked::before { scale: 1; opacity: 1; }
.consent input[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--danger); }
.error { color: var(--danger); font-size: 13px; }
.error:empty { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  translate: -50% 8px;
  opacity: 0;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  pointer-events: none;
  transition-property: opacity, translate;
  transition-duration: 200ms;
  transition-timing-function: var(--ease);
}
.toast.shown { opacity: 1; translate: -50% 0; }

/* --- Админка ------------------------------------------------------------ */

/* Переключатель «Кабинет / Админка»: внешний радиус 13 = 10 + отступ 3. */
.tabs {
  display: flex;
  margin-top: 14px;
  padding: 3px;
  border-radius: 13px;
  background: var(--section);
}
.tab {
  appearance: none;
  flex: 1;
  border: 0;
  border-radius: var(--radius-inner);
  background: transparent;
  color: var(--hint);
  font: 600 15px/1 var(--body);
  min-height: 40px;
  cursor: pointer;
  transition-property: background-color, color;
  transition-duration: 160ms;
  transition-timing-function: var(--ease);
}
.tab[aria-pressed="true"] { background: var(--button); color: var(--button-text); }

#admin, .panel { display: grid; gap: 12px; }
#admin > .back { justify-self: start; }

.search { display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; }

.people { list-style: none; margin: 0; padding: 0; display: grid; }
.person {
  appearance: none;
  width: 100%;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px 0;
  cursor: pointer;
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--hint) 20%, transparent);
}
.people li:last-child .person { box-shadow: none; }
.person .what { display: grid; gap: 2px; min-width: 0; }
.person small, .people .muted { color: var(--hint); font-size: 13px; }
.person .amount { font: 500 16px/1.3 var(--display); white-space: nowrap; }

.facts { margin: 0; display: grid; gap: 10px; }
.facts div { display: grid; grid-template-columns: minmax(0, 9.5em) minmax(0, 1fr); gap: 12px; }
.facts dt { color: var(--hint); font-size: 14px; }
.facts dd { margin: 0; }
.facts .muted { color: var(--hint); }
@media (max-width: 360px) {
  .facts div { grid-template-columns: 1fr; gap: 2px; }
}

.ops .struck { text-decoration: line-through; color: var(--hint); }
.ops li.sale { flex-wrap: wrap; }
.refund { flex-basis: 100%; }
.refund > .link-button { padding-inline: 0; }
.refund-form { display: grid; gap: 8px; padding-top: 4px; }
.button-danger { background: var(--danger); color: #fff; }

.form h3, .report h3 { margin: 0; font: 600 15px/1.3 var(--body); }

/* Предпросмотр начислений — до подтверждения продажи. */
.preview {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-inner);
  background: var(--bg-2);
}
.split { list-style: none; margin: 0; padding: 0; display: grid; }
.split li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--hint) 20%, transparent);
}
.split li:last-child { box-shadow: none; }
.split .what { display: grid; gap: 2px; min-width: 0; }
.split small { color: var(--hint); font-size: 13px; }
.split .amount { font: 500 17px/1.2 var(--display); white-space: nowrap; }
.split .plus { color: var(--accent); }
.split .total { font-weight: 600; }

.segmented {
  display: flex;
  margin: 0;
  padding: 3px;
  border: 0;
  border-radius: 13px;
  background: var(--bg-2);
}
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: var(--radius-inner);
  color: var(--hint);
  font-weight: 600;
  cursor: pointer;
  transition-property: background-color, color;
  transition-duration: 160ms;
  transition-timing-function: var(--ease);
}
.segmented input:checked + span { background: var(--button); color: var(--button-text); }
.segmented input:focus-visible + span { outline: 2px solid var(--link); outline-offset: 2px; }

.report { display: grid; gap: 10px; padding-top: 6px; }
.missing { margin: 0; padding-left: 20px; display: grid; gap: 4px; color: var(--danger); }

/* --- Комкойны за активность ------------------------------------------------ */

/* Из бота кабинет открывается на этом блоке — оставляем воздух над ним. */
#activities { scroll-margin-top: 12px; }
.subhead { margin: 6px 0 0; font: 600 15px/1.3 var(--body); }

/* Виды активности: награда — главное число строки, как баланс на экране. */
.kinds { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.kinds li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-inner);
  background: var(--bg-2);
}
.kinds .what { display: grid; gap: 2px; min-width: 0; }
.kinds .what span { font-weight: 600; }
.kinds small { color: var(--hint); font-size: 13px; }
.kinds .reward {
  font: 700 22px/1 var(--display);
  letter-spacing: -0.02em;
  color: var(--accent);
  white-space: nowrap;
}
.kinds .empty { background: none; padding: 0; }

.claim-form {
  padding: 12px;
  border-radius: var(--radius-inner);
  background: var(--bg-2);
}
/* Поля внутри серой формы — на цвете карточки, иначе сливаются с фоном. */
.claim-form .field input, .claim-form .field select { background: var(--section); }

/* Статус заявки — цветом текста, без плашек. */
.status-pending { color: var(--hint); }
.status-approved { color: var(--accent); }
.status-rejected { color: var(--danger); }
.ops .status { font: 500 14px/1.3 var(--body); white-space: nowrap; }
.ops .reason { flex-basis: 100%; color: var(--danger); font-size: 13px; margin-top: -4px; }
.claims-mine li { flex-wrap: wrap; }

/* Очередь заявок у администратора. */
.claims { list-style: none; margin: 0; padding: 0; display: grid; }
.claim {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--hint) 20%, transparent);
}
.claim:last-child { box-shadow: none; }
.claim .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.claim .head .what { display: grid; gap: 2px; min-width: 0; }
.claim small { color: var(--hint); font-size: 13px; }
.claim .amount { font: 500 16px/1.3 var(--display); white-space: nowrap; color: var(--accent); }
/* Ссылка — только текстом: её не встраиваем и не делаем кликабельной разметкой. */
.claim-url {
  background: var(--bg-2);
  border-radius: var(--radius-inner);
  padding: 10px 12px;
  font-size: 14px;
  user-select: all;
}
.claim .note { font-size: 14px; }
.claim .form-actions .button { flex: 1 1 120px; }
.claim .refund-form { padding-top: 0; }

/* Одно появление при загрузке: блоки кабинета выходят по очереди. */
#home > * { animation: rise 360ms var(--ease) both; }
#home > *:nth-child(2) { animation-delay: 60ms; }
#home > *:nth-child(3) { animation-delay: 120ms; }
#home > *:nth-child(4) { animation-delay: 180ms; }
#home > *:nth-child(n+5) { animation-delay: 240ms; }
@keyframes rise { from { opacity: 0; translate: 0 8px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0ms !important; }
}

/* Тихая кнопка вне карточки стоит прямо на фоне страницы — даём ей фон карточки. */
.panel > .row-actions .button-quiet { background: var(--section); }

/* Таймпад: состояние сверки рядом с кнопкой «Сверить сейчас». */
.sync-state { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sync-state .hint { margin: 0; flex: 1 1 180px; text-wrap: pretty; }
.sync-state .error { margin: 0; }
/* Возвраты, задержанные предохранителем сверки: предупреждение и подтверждение. */
.refunds-held { display: grid; gap: 8px; margin-top: 12px; }
.refunds-held > .error { margin: 0; font-size: 14px; text-wrap: pretty; }
.refunds-held .hint { margin: 0; text-wrap: pretty; }
.claim .amount.plain { color: inherit; }
.claim .note.warn { color: var(--danger); }
.claim .people { margin-top: 4px; }
.claim .note.muted { color: var(--hint); }

/* Роли (ADR-0013): переключатель с пояснением, что он даёт; строка — не меньше 44px под палец. */
#adm-role .consent { min-height: 44px; align-items: center; }
#adm-role .consent span { display: grid; gap: 2px; }
.role-note { color: var(--hint); font-size: 13px; text-wrap: pretty; }
.consent input:disabled, .consent input:disabled + span { opacity: 0.55; cursor: default; }

/* --- Билет за комкойны (срез 8) ---------------------------------------------- */

#ticket { scroll-margin-top: 12px; }
.ticket-form { gap: 12px; }

/* Пять процентов в ряд: на узком телефоне — чуть плотнее. */
.percents span { min-height: 40px; font-size: 15px; }
.segmented input:disabled + span { opacity: 0.35; cursor: default; }
@media (max-width: 360px) {
  .percents span { font-size: 14px; }
}

/* Выданный код — главное на экране: крупно, моноширинно, выделяется целиком. */
.promo {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-inner);
  background: var(--bg-2);
}
.promo-caption { color: var(--hint); font-size: 14px; }
.promo-code {
  font: 600 24px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  color: var(--accent);
  user-select: all;
  -webkit-user-select: all;
  overflow-wrap: anywhere;
}

/* Наборы в админке: не кнопка — без нажатия, числа свободных справа. */
.code-set { cursor: default; }
.code-set .warn { color: var(--danger); }
