/* Мини-приложение записи (Telegram / MAX / браузер).
   Цвета берём из темы Telegram (--tg-theme-*), в браузере и MAX — свои запасные
   (светлые и тёмные, по prefers-color-scheme или data-scheme на <html>).
   В CSS ссылки на файлы только относительные: nginx переписывает префикс /train
   лишь в HTML. */

:root {
  --fb-bg: #f1f3f7;
  --fb-surface: #ffffff;
  --fb-text: #10141c;
  --fb-hint: #7a8291;
  --fb-accent: #2563eb;
  --fb-accent-text: #ffffff;
  --fb-link: #2563eb;
  --fb-danger: #e5484d;

  --ok: #12965a;     --ok-bg: rgba(18, 150, 90, .11);
  --warn: #b26a00;   --warn-bg: rgba(245, 158, 11, .15);
  --full: #d93036;   --full-bg: rgba(229, 72, 77, .11);
  --mute-bg: rgba(120, 128, 145, .12);
  --track: rgba(120, 128, 145, .18);
  --sep: rgba(16, 20, 28, .07);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 14px rgba(16, 24, 40, .05);
  --accent-bg: rgba(37, 99, 235, .1);

  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-surface)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --danger: var(--tg-theme-destructive-text-color, var(--fb-danger));

  --r-card: 18px;
  --r-btn: 13px;
  color-scheme: light;
}

@supports (color: color-mix(in srgb, red 10%, transparent)) {
  :root { --accent-bg: color-mix(in srgb, var(--accent) 12%, transparent); }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --fb-bg: #0e1116; --fb-surface: #1a1f27; --fb-text: #eef1f6; --fb-hint: #8b93a3;
    --fb-accent: #4c8dff; --fb-link: #6ea2ff; --fb-danger: #ff6369;
    --ok: #3ccf8a; --ok-bg: rgba(60, 207, 138, .14);
    --warn: #f6b23e; --warn-bg: rgba(246, 178, 62, .15);
    --full: #ff6b6f; --full-bg: rgba(255, 107, 111, .14);
    --mute-bg: rgba(160, 168, 185, .14); --track: rgba(160, 168, 185, .2);
    --sep: rgba(255, 255, 255, .07);
    --shadow: 0 1px 2px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-scheme="dark"] {
  --fb-bg: #0e1116; --fb-surface: #1a1f27; --fb-text: #eef1f6; --fb-hint: #8b93a3;
  --fb-accent: #4c8dff; --fb-link: #6ea2ff; --fb-danger: #ff6369;
  --ok: #3ccf8a; --ok-bg: rgba(60, 207, 138, .14);
  --warn: #f6b23e; --warn-bg: rgba(246, 178, 62, .15);
  --full: #ff6b6f; --full-bg: rgba(255, 107, 111, .14);
  --mute-bg: rgba(160, 168, 185, .14); --track: rgba(160, 168, 185, .2);
  --sep: rgba(255, 255, 255, .07);
  --shadow: 0 1px 2px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* --- основа ------------------------------------------------------------------ */

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link); text-decoration: underline; }
.hint { color: var(--hint); }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.ic-sm { width: 15px; height: 15px; vertical-align: -2px; }
form { margin: 0; }

.app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(28px + env(safe-area-inset-bottom)); }

/* --- кнопки ------------------------------------------------------------------- */

.btn-x {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 18px; border-radius: var(--r-btn);
  border: 0; font: inherit; font-weight: 600; font-size: 15px; line-height: 1.2;
  cursor: pointer; text-decoration: none; user-select: none;
  transition: transform .12s ease, filter .12s ease, opacity .12s ease, background-color .12s ease;
}
.btn-x:hover { text-decoration: none; }
.btn-x:active { transform: scale(.97); }
.btn-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-x.block { width: 100%; }
.btn-x.big { min-height: 52px; font-size: 16px; }
.btn-primary-x { background: var(--accent); color: var(--accent-text); }
.btn-primary-x:hover { color: var(--accent-text); filter: brightness(1.05); }
.btn-soft { background: var(--accent-bg); color: var(--accent); }
.btn-soft:hover { color: var(--accent); }
.btn-ghost { background: var(--mute-bg); color: var(--text); }
.btn-ghost:hover { color: var(--text); }
.btn-danger-soft { background: var(--full-bg); color: var(--danger); }
.btn-danger-soft:hover { color: var(--danger); }
.btn-x.is-busy { opacity: .6; pointer-events: none; }
.btn-x.is-busy::after {
  content: ""; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--hint); cursor: pointer;
}
.icon-btn:hover, .icon-btn:active { background: var(--mute-bg); color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- шапка -------------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  margin: 0 -16px; padding: 10px 16px 0;
  background: var(--bg);
  transition: box-shadow .2s ease;
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) and (color: color-mix(in srgb, red 10%, transparent)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 84%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
  }
}
.topbar.is-stuck { box-shadow: 0 1px 0 var(--sep); }
.me { display: flex; align-items: center; gap: 12px; min-height: 52px; }
.me-ava {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2bb673, #1f6feb); color: #fff;
  font-weight: 700; font-size: 18px; letter-spacing: -.02em;
}
.me-body { min-width: 0; flex: 1; }
.me-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; line-height: 1.2;
           white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
  border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: var(--mute-bg); color: var(--sub);
}
.tag.accent { background: var(--accent-bg); color: var(--accent); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.full { background: var(--full-bg); color: var(--full); }

/* лента дат */
.dates {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 8px -16px 0; padding: 2px 16px 10px; scroll-snap-type: x proximity;
}
.dates::-webkit-scrollbar { display: none; }
.date {
  flex: none; width: 50px; height: 60px; border-radius: 15px; scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--surface); color: var(--text); position: relative;
  box-shadow: var(--shadow); transition: background-color .15s ease, color .15s ease;
}
.date:hover { text-decoration: none; color: var(--text); }
.date-wd { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); }
.date-n { font-size: 19px; font-weight: 700; line-height: 1.1; }
.date.has-mine::after {
  content: ""; position: absolute; bottom: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--ok);
}
.date.is-active { background: var(--accent); color: var(--accent-text); }
.date.is-active .date-wd { color: var(--accent-text); opacity: .8; }
.date.is-active.has-mine::after { background: var(--accent-text); }

/* --- блоки -------------------------------------------------------------------- */

.section-t {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin: 22px 4px 10px; font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--hint);
}
.card-x {
  background: var(--surface); border-radius: var(--r-card); padding: 14px 16px;
  box-shadow: var(--shadow); margin-bottom: 10px;
}

/* абонементы */
.pass { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.pass-ic {
  width: 42px; height: 42px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-bg); color: var(--accent);
}
.pass.is-frozen .pass-ic { background: rgba(56, 189, 248, .15); color: #0ea5e9; }
.pass-body { flex: 1; min-width: 0; }
.pass-t { font-weight: 600; }
.pass-sub { font-size: 13px; color: var(--hint); margin-top: 1px; }
.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.pass .btn-x { min-height: 44px; padding: 8px 14px; font-size: 14px; }
.pass form { flex: none; }
.pass .pass-act { flex-basis: 100%; padding-left: 54px; margin-top: -2px; }
.pass-sub b { color: var(--text); }
.section-t form { margin: -12px 0; }
.section-link { text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; }

/* группы */
.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin: 16px -16px 0; padding: 2px 16px 4px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; min-height: 38px; padding: 0 15px;
  border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); white-space: nowrap;
}
.chip:hover { text-decoration: none; color: var(--text); }
.chip.is-on { background: var(--text); color: var(--bg); }

/* день */
.day { scroll-margin-top: 150px; }
.day-h { display: flex; align-items: baseline; gap: 8px; margin: 24px 4px 10px; }
.day-wd { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.day-date { color: var(--hint); font-size: 15px; }
.day-rel { margin-left: auto; }

/* карточка тренировки */
.tc {
  position: relative; background: var(--surface); border-radius: var(--r-card);
  padding: 14px 14px 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.tc::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px;
  border-radius: 0 4px 4px 0; background: transparent;
}
.tc.is-mine::before { background: var(--ok); }
.tc.is-wait::before { background: var(--warn); }
.tc-top { display: flex; gap: 12px; align-items: flex-start; }
.tc-time { flex: none; min-width: 56px; }
.tc-time b { display: block; font-size: 20px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15;
             font-variant-numeric: tabular-nums; }
.tc-time span { font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; }
.tc-main { flex: 1; min-width: 0; padding-top: 1px; }
.tc-title { font-weight: 600; font-size: 16px; line-height: 1.25; display: flex;
            align-items: center; gap: 6px; flex-wrap: wrap; }
.tc-meta { margin-top: 3px; font-size: 13.5px; color: var(--hint); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.tc-meta span { display: inline-flex; align-items: center; gap: 4px; }
.tc-top .icon-btn { margin: -8px -8px 0 0; }
.lvl {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px;
  padding: 0 6px; border-radius: 7px; font-size: 12.5px; font-weight: 700;
  background: var(--accent-bg); color: var(--accent);
}

.seats { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.seats-viz { flex: 1; min-width: 0; }
.dots { display: flex; gap: 3px; }
.dots i { flex: 1; height: 7px; border-radius: 4px; background: var(--track); max-width: 22px; }
.dots i.on { background: var(--accent); }
.tc.is-mine .dots i.on { background: var(--ok); }
.tc.is-full .dots i.on, .tc.is-wait .dots i.on { background: var(--full); }
.tc.is-locked .dots i.on { background: var(--hint); }
.tc .meter { margin-top: 0; height: 7px; }
.tc.is-mine .meter > i { background: var(--ok); }
.tc.is-full .meter > i, .tc.is-wait .meter > i { background: var(--full); }
.tc.is-locked .meter > i { background: var(--hint); }
.seats-n { flex: none; font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; }
.seats-n b { color: var(--text); font-weight: 700; }
.need { margin-top: 6px; font-size: 13px; color: var(--sub); display: flex; gap: 6px; align-items: center; }

.tc-act { margin-top: 12px; display: flex; gap: 10px; align-items: center; }
.tc-act > form { flex: 1; }
.tc-act > form.shrink { flex: none; }
.state {
  flex: 1; display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 14px;
  border-radius: var(--r-btn); font-weight: 600; font-size: 14.5px;
}
.state.ok { background: var(--ok-bg); color: var(--ok); }
.state.warn { background: var(--warn-bg); color: var(--warn); }
.state.full { background: var(--full-bg); color: var(--full); }
.state.mute { background: var(--mute-bg); color: var(--sub); }
.tc.is-locked .tc-top, .tc.is-locked .seats { opacity: .62; }

/* пустое состояние */
.empty { text-align: center; padding: 26px 20px 24px; }
.empty img { width: 150px; height: 150px; object-fit: contain; margin-bottom: 6px; }
.empty-t { font-weight: 600; font-size: 16px; }
.empty-s { color: var(--hint); font-size: 14px; margin-top: 4px; }

/* подвал */
/* --- бот в других мессенджерах ------------------------------------------------- */

.msgr { margin-top: 28px; display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px; }
.msgr-t { color: var(--hint); font-size: 13px; width: 100%; text-align: center; }
.msgr-b {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px 6px 6px;
  border-radius: 999px; background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  text-decoration: none; box-shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 0 0 1px var(--line, rgba(0, 0, 0, .08));
}
.msgr-b i {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-style: normal; font-weight: 800; font-size: 13px; letter-spacing: -.02em;
}
.msgr-b i svg { width: 18px; height: 18px; fill: #fff; margin-left: -2px; }
.msgr-b.is-telegram i { background: #2aabee; }
.msgr-b.is-max i { background: linear-gradient(135deg, #3d7bff, #8a3dff); }
.msgr-b.is-vk i { background: #0077ff; }
.msgr-b.is-here { display: none; }
.foot { margin-top: 12px; display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 18px; font-size: 13px; }
.foot a, .foot-btn { color: var(--hint); padding: 8px 2px; }
.foot-btn { background: none; border: 0; font: inherit; }

/* --- вход ---------------------------------------------------------------------- */

.login { padding-top: 28px; }
.hero { text-align: center; margin-bottom: 20px; }
.hero-ava {
  width: 96px; height: 96px; border-radius: 28px; object-fit: cover;
  box-shadow: 0 10px 30px rgba(31, 111, 235, .25), 0 0 0 4px var(--surface);
}
.hero h1 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 18px 0 6px; }
.hero p { color: var(--hint); margin: 0 auto; max-width: 22rem; }

.steps { display: flex; align-items: center; gap: 8px; margin: 0 4px 14px; font-size: 13.5px; font-weight: 600; }
.step { display: flex; align-items: center; gap: 7px; color: var(--hint); }
.step i {
  width: 24px; height: 24px; border-radius: 50%; font-style: normal; font-size: 12.5px;
  display: inline-flex; align-items: center; justify-content: center; background: var(--mute-bg);
}
.step.is-on { color: var(--text); }
.step.is-on i { background: var(--accent); color: var(--accent-text); }
.step.is-done i { background: var(--ok-bg); color: var(--ok); }
.step-line { flex: 1; height: 2px; border-radius: 1px; background: var(--track); max-width: 60px; }

.field-l { display: block; font-size: 13.5px; font-weight: 600; color: var(--sub); margin: 2px 2px 8px; }
.field {
  display: block; width: 100%; min-height: 52px; padding: 12px 14px; border-radius: 14px;
  border: 1.5px solid var(--sep); background: var(--bg); color: var(--text);
  font: inherit; font-size: 18px; outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.field::placeholder { color: var(--hint); opacity: .7; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-bg); }
.field.code { text-align: center; letter-spacing: .4em; font-size: 24px; font-weight: 700;
              font-variant-numeric: tabular-nums; padding-left: calc(14px + .4em); }
.form-note { font-size: 13px; color: var(--hint); margin-top: 10px; text-align: center; }
.link-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; }
.link-btn {
  border: 0; background: none; color: var(--link); font: inherit; font-size: 14px; font-weight: 500;
  padding: 10px 2px; min-height: 44px; cursor: pointer;
}

.note {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px;
  margin-bottom: 12px; font-size: 14px; font-weight: 500;
}
.note .ic { margin-top: 1px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.ok { background: var(--ok-bg); color: var(--ok); }

.wait { text-align: center; padding: 28px 18px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%; margin: 0 auto 14px;
  border: 3px solid var(--track); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.need-bot img { width: 140px; height: 140px; object-fit: contain; display: block; margin: 0 auto 6px; }
.need-bot p { margin: 0 0 14px; text-align: center; }

.bots { display: flex; flex-direction: column; gap: 8px; }
.bots-t { font-size: 14px; color: var(--hint); margin-bottom: 10px; }
.ch-dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; opacity: .9; }

/* --- ответы бота --------------------------------------------------------------- */

.backbar { position: sticky; top: 0; z-index: 30; margin: 0 -16px; padding: 8px 8px 8px; background: var(--bg); }
.back {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 12px 0 6px;
  border-radius: 12px; font-weight: 600; color: var(--link);
}
.back:hover { text-decoration: none; background: var(--mute-bg); }
.screen-card { padding: 18px 16px 16px; }
.screen-text { white-space: pre-wrap; word-wrap: break-word; font-size: 15.5px; line-height: 1.5; margin: 0; font-family: inherit; }
.screen-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.screen-row { display: flex; gap: 8px; }
.screen-row > form, .screen-row > a { flex: 1 1 0; min-width: 0; }
.screen-row .btn-x { width: 100%; white-space: normal; text-align: center; }

@media (max-width: 360px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .topbar, .backbar { margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
  .dates, .chips { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
  .tc-time { min-width: 50px; }
  .tc-time b { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation-duration: .01s !important; }
}
