/*
 * Вид — как сгруппированные списки iOS (раздел 8 справочника): цвета только из темы Telegram (--tg-theme-*),
 * своих оттенков нет, тёмная тема приходит сама. Запасные значения — светлая и тёмная системная палитра iOS,
 * чтобы страница выглядела так же в обычном браузере при локальной проверке.
 * Статусам карты «светофора» нет: «на контроле» — не плохая оценка. Цвет есть только у роста.
 */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #007aff);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --header: var(--tg-theme-section-header-text-color, #6d6d72);
  --separator: var(--tg-theme-section-separator-color, rgba(60, 60, 67, .29));
  --destructive: var(--tg-theme-destructive-text-color, #ff3b30);
  --button: var(--tg-theme-button-color, #007aff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --growth: #34c759;
  --fill: rgba(120, 120, 128, .12);
  --radius: 12px;
  --gutter: 16px;
  --top: var(--tg-content-safe-area-inset-top, 0px);
  --bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #000000);
    --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1c1c1e));
    --text: var(--tg-theme-text-color, #ffffff);
    --hint: var(--tg-theme-hint-color, #8d8d93);
    --header: var(--tg-theme-section-header-text-color, #8d8d93);
    --separator: var(--tg-theme-section-separator-color, rgba(84, 84, 88, .65));
    --link: var(--tg-theme-link-color, #0a84ff);
    --destructive: var(--tg-theme-destructive-text-color, #ff453a);
    --button: var(--tg-theme-button-color, #0a84ff);
    --growth: #30d158;
    --fill: rgba(120, 120, 128, .24);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.29 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--top) + 8px) var(--gutter) calc(var(--bottom) + 32px);
  min-height: var(--tg-viewport-stable-height, 100vh);
}

body.has-fallback main { padding-bottom: calc(var(--bottom) + 96px); }

/* ── заголовки ── */
.large-title {
  margin: 12px 0 2px;
  font-size: 34px;
  line-height: 41px;
  font-weight: 700;
  letter-spacing: .01em;
}
.title {
  margin: 12px 0 20px;
  font-size: 28px;
  line-height: 34px;
  font-weight: 700;
}
.lede { margin: 0 0 20px; color: var(--hint); font-size: 15px; }
.title + .lede { margin-top: -16px; }

/* выбор ребёнка — сегменты iOS */
.segments {
  display: flex;
  gap: 2px;
  margin: 8px 0 20px;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}
.segments button {
  flex: 1;
  min-height: 32px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
}
.segments button[aria-pressed="true"] { background: var(--section); box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 3px 1px rgba(0, 0, 0, .04); font-weight: 600; }

/* ── сгруппированные секции ── */
.section { margin: 0 0 32px; }
.section-header {
  margin: 0 var(--gutter) 6px;
  color: var(--header);
  font-size: 13px;
  line-height: 18px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.section-footer {
  margin: 6px var(--gutter) 0;
  color: var(--hint);
  font-size: 13px;
  line-height: 18px;
}
.section-footer.error { color: var(--destructive); }

.group {
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--section);
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 11px var(--gutter);
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--gutter);
  right: 0;
  height: .5px;
  background: var(--separator);
}
button.row, a.row { cursor: pointer; }
button.row:active, a.row:active { background: var(--fill); }
.row:disabled { opacity: .4; }

.row-body { flex: 1; min-width: 0; }
.row-title { overflow-wrap: anywhere; }
.row-subtitle { margin-top: 2px; color: var(--subtitle); font-size: 15px; line-height: 20px; }
.row-value { flex: none; color: var(--hint); }
.row-value.good { color: var(--growth); }
.row.action { color: var(--link); }
.row.destructive { color: var(--destructive); justify-content: center; }
.row.quote .row-title { font-style: italic; }

.chevron {
  flex: none;
  width: 8px;
  height: 13px;
  color: var(--hint);
  opacity: .6;
}

.icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 29px;
  height: 29px;
  border-radius: 7px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}
.icon.growth { background: var(--growth); }
.icon.plain { background: var(--fill); color: var(--hint); }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--fill);
  color: var(--subtitle);
  font-size: 13px;
  line-height: 18px;
}
.badge.training { color: var(--accent); }

/* ── сводка недели: числа крупно, как в «Здоровье» ── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); padding: 14px 0 12px; }
.stat { padding: 0 var(--gutter); }
.stat + .stat { border-left: .5px solid var(--separator); }
.stat-value { font-size: 28px; line-height: 34px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-unit { margin-left: 2px; font-size: 15px; line-height: 1; font-weight: 500; color: var(--hint); }
.stat-label { color: var(--hint); font-size: 13px; line-height: 18px; }

/* ── карточка места ── */
.place-head { margin: 8px 0 24px; }
.place-kicker { color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .02em; }
.place-text { margin: 4px 0 8px; font-size: 22px; line-height: 28px; font-weight: 600; overflow-wrap: anywhere; }
.place-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--subtitle); font-size: 15px; }

/* ── формы ── */
textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  padding: 11px var(--gutter);
  border: 0;
  border-radius: var(--radius);
  background: var(--section);
  color: var(--text);
  font: inherit;
  resize: none;
  outline: none;
}
textarea::placeholder { color: var(--hint); }
.counter { float: right; font-variant-numeric: tabular-nums; }

/* ── пустые и служебные состояния ── */
.empty { padding: 72px 24px; text-align: center; color: var(--hint); }
.empty h2 { margin: 0 0 8px; color: var(--text); font-size: 20px; font-weight: 600; }
.empty p { margin: 0; font-size: 15px; line-height: 20px; }

.skeleton { pointer-events: none; }
.skeleton .bar { height: 14px; margin: 4px 0; border-radius: 4px; background: var(--fill); animation: pulse 1.4s ease-in-out infinite; }
.skeleton .bar.short { width: 40%; }
@keyframes pulse { 50% { opacity: .45; } }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom) + 24px);
  z-index: 10;
  padding: 10px 18px;
  border-radius: 20px;
  background: rgba(30, 30, 30, .88);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  transform: translateX(-50%);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  animation: toast-in .25s ease-out;
}
body.has-fallback #toast { bottom: calc(var(--bottom) + 88px); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

#fallback-button {
  position: fixed;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(var(--bottom) + 16px);
  max-width: 608px;
  min-height: 50px;
  margin: 0 auto;
  border: 0;
  border-radius: var(--radius);
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-weight: 600;
}
#fallback-button:disabled { opacity: .5; }

.screen { animation: screen-in .22s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateX(12px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
