/* Courtbook — оболочка Telegram Mini App.
   Цвета приходят из themeParams (tma_shell.js) в CSS-переменные --tg-*;
   значения ниже — фолбэк для отладки в браузере. Ширина вёрстки 360–430px. */

:root {
  --tg-bg: #17212b;
  --tg-text: #ffffff;
  --tg-hint: #708499;
  --tg-secondary-bg: #232e3c;
  --tg-button: #5288c1;
  --tg-button-text: #ffffff;

  --radius: 16px;
  --radius-sm: 12px;
  --gap: 12px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --tg-bg: #ffffff;
    --tg-text: #0f0f0f;
    --tg-hint: #707579;
    --tg-secondary-bg: #f4f4f5;
    --tg-button: #3390ec;
    --tg-button-text: #ffffff;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: var(--tg-bg);
  color: var(--tg-text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding:
    calc(16px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Шапка ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 22px;
  line-height: 1;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 13px;
  color: var(--tg-hint);
}

/* ── Контент ────────────────────────────────────────────────────────────── */
.content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
}

.card h1 {
  margin: 0 0 8px;
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tg-hint);
}

.lead {
  margin: 0;
  font-size: 15px;
  color: var(--tg-text);
  opacity: 0.92;
}

.hint {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--tg-hint);
}

.hint code {
  font-size: 12px;
  padding: 1px 4px;
  border-radius: 5px;
  background: rgba(127, 127, 127, 0.18);
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 15px;
}

.steps li {
  position: relative;
  padding-left: 22px;
}

.steps li::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 9px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tg-button);
  opacity: 0.85;
}

.button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  margin-top: 16px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.button:active { opacity: 0.8; }

/* ── Статус окружения ───────────────────────────────────────────────────── */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0 4px;
  font-size: 12px;
  color: var(--tg-hint);
}

.dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--tg-hint);
}

html.tg-inside .dot { background: #31c48d; }

/* ── Шлюз «Откройте через Telegram» ─────────────────────────────────────── */
body.is-guest .app.is-locked { display: none; }

.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(24px + env(safe-area-inset-top))
    calc(20px + env(safe-area-inset-right))
    calc(32px + env(safe-area-inset-bottom))
    calc(20px + env(safe-area-inset-left));
}

.gate[hidden] { display: none; }

.gate-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.gate-card h1 {
  font-size: 22px;
  margin: 12px 0 10px;
}

.gate-mark {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 26px;
}

/* ── Навигация по разделам ──────────────────────────────────────────────── */
body.is-authed .app { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 4px;
  max-width: 520px;
  margin: 0 auto;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--tg-secondary-bg);
  border-top: 1px solid rgba(127, 127, 127, 0.18);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border-radius: 12px;
  color: var(--tg-hint);
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab svg { width: 22px; height: 22px; }

.tab.is-active {
  color: var(--tg-button);
  background: rgba(82, 136, 193, 0.14);
  font-weight: 600;
}

.tab:active { background: rgba(127, 127, 127, 0.16); }

/* ── Секции и события ───────────────────────────────────────────────────── */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}

.section-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tg-hint);
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.18);
  color: var(--tg-hint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.event-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--tg-secondary-bg);
}

.event-time {
  flex: 0 0 46px;
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.event-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.event-title {
  font-size: 15px;
  font-weight: 550;
}

.event-meta {
  font-size: 12px;
  color: var(--tg-hint);
}

.event-arrow {
  flex: 0 0 auto;
  color: var(--tg-hint);
  font-size: 20px;
  line-height: 1;
}

/* ── Профиль ────────────────────────────────────────────────────────────── */
.profile-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--tg-button);
  color: var(--tg-button-text);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-id {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.profile-name {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.profile-handle {
  font-size: 14px;
  color: var(--tg-hint);
  overflow-wrap: anywhere;
}

.club-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.club-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(127, 127, 127, 0.12);
}

.club-name {
  font-size: 15px;
  font-weight: 550;
  min-width: 0;
}

.role-chip {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(82, 136, 193, 0.18);
  color: var(--tg-button);
  font-size: 12px;
  font-weight: 600;
}

.logout-form { margin: 0; }

.button-ghost {
  background: transparent;
  border: 1px solid rgba(127, 127, 127, 0.35);
  color: var(--tg-text);
  cursor: pointer;
  font-family: inherit;
}

.button-ghost:active { opacity: 0.6; }

@media (prefers-color-scheme: light) {
  .role-chip { background: rgba(51, 144, 236, 0.12); }
}
