/* ============================================================================
   Fitness Studio Mini App — дизайн-система
   Поверхности наследуются от темы Telegram, акценты — свои.
   ========================================================================== */
:root {
  /* --- поверхности (из темы Telegram, с запасными значениями) --- */
  --bg:        var(--tg-theme-secondary-bg-color, #F2F3F7);
  --surface:   var(--tg-theme-bg-color, #FFFFFF);
  --surface-2: color-mix(in srgb, var(--surface) 94%, #000 6%);
  --text:      var(--tg-theme-text-color, #0B0B10);
  --text-dim:  var(--tg-theme-hint-color, #7A7D8C);
  --link:      var(--tg-theme-link-color, #2F6FED);
  --border:    color-mix(in srgb, var(--text) 12%, transparent);
  --border-soft: color-mix(in srgb, var(--text) 7%, transparent);

  /* --- бренд и семантика --- */
  --brand:      #6E56F8;
  --brand-2:    #9B7BFF;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, transparent);
  --on-brand:   #FFFFFF;
  --ok:         #12B76A;
  --ok-soft:    color-mix(in srgb, var(--ok) 14%, transparent);
  --warn:       #F79009;
  --warn-soft:  color-mix(in srgb, var(--warn) 16%, transparent);
  --danger:     #F04438;
  --danger-soft:color-mix(in srgb, var(--danger) 13%, transparent);

  /* --- радиусы, тени, отступы --- */
  --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-xl: 26px; --r-full: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px;
  --shadow-1: 0 1px 2px rgba(16,18,32,.06), 0 1px 3px rgba(16,18,32,.04);
  --shadow-2: 0 4px 16px rgba(16,18,32,.08), 0 1px 3px rgba(16,18,32,.05);
  --shadow-brand: 0 8px 24px color-mix(in srgb, var(--brand) 28%, transparent);

  /* --- движение --- */
  --ease: cubic-bezier(.22,.61,.36,1);
  --fast: 140ms; --base: 220ms;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        var(--tg-theme-secondary-bg-color, #0E0F14);
    --surface:   var(--tg-theme-bg-color, #16181F);
    --surface-2: color-mix(in srgb, var(--surface) 88%, #FFF 12%);
    --text:      var(--tg-theme-text-color, #F4F5F8);
    --text-dim:  var(--tg-theme-hint-color, #9BA0B0);
    --border:    color-mix(in srgb, #FFF 14%, transparent);
    --border-soft: color-mix(in srgb, #FFF 8%, transparent);
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 6px 20px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
#app {
  padding: var(--sp-4) var(--sp-4) calc(104px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
}
.hidden { display: none !important; }

/* ------------------------------------------------------------- типографика */
h1 { font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 2px; }
h2 { font-size: 12.5px; font-weight: 650; color: var(--text-dim); margin: var(--sp-5) 0 var(--sp-2);
     text-transform: uppercase; letter-spacing: .05em; }
.muted { color: var(--text-dim); font-size: 14px; }
.center { text-align: center; }
.num { font-weight: 700; letter-spacing: -.02em; }

/* ------------------------------------------------------------------ шапка */
.appbar { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.appbar .grow { flex: 1; min-width: 0; }
.appbar h1 { margin: 0; font-size: 22px; }
.appbar .sub { font-size: 13px; color: var(--text-dim); }

/* ------------------------------------------------------------------ иконки */
.ico { width: 20px; height: 20px; flex: 0 0 auto; stroke-width: 1.75; }
.ico-lg { width: 24px; height: 24px; }
.ico-xl { width: 30px; height: 30px; }
.ico-box {
  width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); flex: 0 0 auto;
}
.ico-box.ok { background: var(--ok-soft); color: var(--ok); }
.ico-box.warn { background: var(--warn-soft); color: var(--warn); }
.ico-box.danger { background: var(--danger-soft); color: var(--danger); }
.ico-box.dim { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text-dim); }

/* ----------------------------------------------------------------- карточки */
.card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--r-lg); padding: var(--sp-4);
  box-shadow: var(--shadow-1); margin-bottom: var(--sp-3);
}
.card.tight { padding: var(--sp-3); }
.card .title { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
       padding: 9px 0; border-bottom: 1px solid var(--border-soft); }
.row:last-child { border-bottom: none; }
.row .k { color: var(--text-dim); font-size: 14px; }
.row .v { font-weight: 600; text-align: right; font-size: 15px; }

/* ------------------------------------------------- герой-карточка абонемента */
.hero {
  position: relative; overflow: hidden; color: #fff;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
  border: none; box-shadow: var(--shadow-brand);
  border-radius: var(--r-xl); padding: var(--sp-5);
}
.hero::after {
  content: ''; position: absolute; right: -50px; top: -70px; width: 200px; height: 200px;
  border-radius: 50%; background: rgba(255,255,255,.13);
}
.hero .h-top { display: flex; align-items: flex-start; gap: var(--sp-3); position: relative; z-index: 1; }
.hero .h-name { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.hero .h-sched { font-size: 13.5px; opacity: .82; margin-top: 1px; }
.hero .h-foot { display: flex; align-items: center; gap: var(--sp-4); margin-top: var(--sp-4);
                position: relative; z-index: 1; }
.hero .h-metric { font-size: 12.5px; opacity: .82; }
.hero .h-metric b { display: block; font-size: 17px; font-weight: 700; opacity: 1; }
.hero.flat { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1);
             border: 1px solid var(--border-soft); }
.hero.flat::after { display: none; }

/* кольцо прогресса */
.ring { position: relative; width: 62px; height: 62px; flex: 0 0 auto; }
.ring svg { transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: flex; align-items: center;
             justify-content: center; gap: 1px; white-space: nowrap;
             font-size: 17px; font-weight: 700; letter-spacing: -.03em; }
.ring .val small { font-size: 10.5px; font-weight: 500; opacity: .78; }

/* ------------------------------------------------------------------ кнопки */
.btn {
  appearance: none; border: none; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 46px; padding: 0 var(--sp-4); width: 100%;
  border-radius: var(--r-md); font-size: 15.5px; font-weight: 600; letter-spacing: -.01em;
  background: var(--brand); color: var(--on-brand);
  transition: transform var(--fast) var(--ease), opacity var(--fast), background var(--fast);
}
.btn:active { transform: scale(.978); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn + .btn { margin-top: var(--sp-2); }
.btn.sec { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.soft-danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { min-height: 36px; width: auto; padding: 0 14px; font-size: 14px; border-radius: var(--r-sm); }
.btn.icon { width: 40px; min-height: 40px; padding: 0; border-radius: var(--r-md); }
.btn-row { display: flex; gap: var(--sp-2); }
.btn-row .btn { margin-top: 0; }

/* -------------------------------------------------------------------- строки */
.tile {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--r-md); padding: 11px var(--sp-3); margin-bottom: var(--sp-2);
  box-shadow: var(--shadow-1);
  transition: transform var(--fast) var(--ease), background var(--fast);
}
.tile[data-action]:active { transform: scale(.99); background: var(--surface-2); }
.tile .grow { flex: 1; min-width: 0; }
.tile .t1 { font-weight: 600; font-size: 15.5px; letter-spacing: -.01em;
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t2 { font-size: 13px; color: var(--text-dim); margin-top: 1px;
            white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .chev { color: var(--text-dim); opacity: .5; }

/* -------------------------------------------------------------------- бейджи */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  border-radius: var(--r-full); font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text-dim);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.solid { background: var(--brand); color: var(--on-brand); }
.badge .ico { width: 14px; height: 14px; }

/* ------------------------------------------------------------- статистика */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); margin-bottom: var(--sp-3); }
.stat {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-2); text-align: center; box-shadow: var(--shadow-1);
  transition: transform var(--fast) var(--ease);
}
.stat[data-action]:active { transform: scale(.97); }
.stat .n { font-size: 24px; font-weight: 700; letter-spacing: -.03em; }
.stat .l { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; line-height: 1.25; }

/* ----------------------------------------------------------------- фильтры */
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 0 var(--sp-3);
         scrollbar-width: none; margin: 0 calc(-1 * var(--sp-4)); padding-left: var(--sp-4);
         padding-right: var(--sp-4); }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--border-soft); cursor: pointer;
  background: var(--surface); color: var(--text); font-family: inherit;
  font-size: 13.5px; font-weight: 550; padding: 8px 14px; border-radius: var(--r-full);
  min-height: 36px; transition: all var(--fast) var(--ease);
}
.chip.on { background: var(--text); color: var(--surface); border-color: var(--text); }

/* -------------------------------------------------------------------- формы */
.field { margin-bottom: var(--sp-3); }
.field label { display: block; font-size: 13px; font-weight: 550; color: var(--text-dim);
               margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px var(--sp-3); min-height: 48px;
  transition: border-color var(--fast), box-shadow var(--fast);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.hint { font-size: 12.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.4; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
          padding: 10px 0; }
.switch input { width: auto; min-height: auto; }
.weekdays { display: flex; gap: 6px; }
.weekdays .wd {
  flex: 1; text-align: center; padding: 11px 0; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--text) 7%, transparent); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: all var(--fast) var(--ease); min-height: 44px;
  display: grid; place-items: center;
}
.weekdays .wd.on { background: var(--brand); color: var(--on-brand); }

/* ------------------------------------------------------------------- нижнее меню */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: flex;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border-soft);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.nav button {
  flex: 1; background: none; border: none; cursor: pointer; font-family: inherit;
  color: var(--text-dim); font-size: 10.5px; font-weight: 550;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px; border-radius: var(--r-md); min-height: 50px;
  transition: color var(--fast), background var(--fast);
}
.nav button.on { color: var(--brand); background: var(--brand-soft); }
.nav button:active { transform: scale(.96); }

/* ---------------------------------------------------------------- состояния */
.empty { text-align: center; padding: var(--sp-8) var(--sp-4); }
.empty .ico-box { width: 56px; height: 56px; margin: 0 auto var(--sp-3); border-radius: var(--r-lg); }
.empty .ico-box .ico { width: 28px; height: 28px; }
.empty h3 { font-size: 17px; font-weight: 650; margin: 0 0 6px; }
.empty p { color: var(--text-dim); font-size: 14px; margin: 0 auto; max-width: 300px; line-height: 1.5; }
.empty .btn { margin-top: var(--sp-4); width: auto; padding: 0 var(--sp-5); display: inline-flex; }

/* скелетоны */
.sk { background: linear-gradient(90deg,
        color-mix(in srgb, var(--text) 7%, transparent) 25%,
        color-mix(in srgb, var(--text) 12%, transparent) 37%,
        color-mix(in srgb, var(--text) 7%, transparent) 63%);
      background-size: 400% 100%; animation: shine 1.4s ease infinite;
      border-radius: var(--r-md); }
@keyframes shine { 0% { background-position: 100% 50% } 100% { background-position: 0 50% } }
.sk-card { height: 116px; margin-bottom: var(--sp-3); border-radius: var(--r-lg); }
.sk-tile { height: 62px; margin-bottom: var(--sp-2); }
.sk-line { height: 13px; margin-bottom: 9px; }

/* тост */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px); opacity: 0;
  background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--surface);
  padding: 11px 18px; border-radius: var(--r-full); font-size: 14px; font-weight: 550;
  z-index: 200; max-width: 88%; text-align: center; box-shadow: var(--shadow-2);
  animation: toastIn var(--base) var(--ease) forwards;
}
@keyframes toastIn { to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* появление контента */
.fade { animation: fade var(--base) var(--ease) both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.stagger > * { animation: fade var(--base) var(--ease) both; }
.stagger > *:nth-child(1) { animation-delay: 20ms } .stagger > *:nth-child(2) { animation-delay: 45ms }
.stagger > *:nth-child(3) { animation-delay: 70ms } .stagger > *:nth-child(4) { animation-delay: 95ms }
.stagger > *:nth-child(5) { animation-delay: 120ms } .stagger > *:nth-child(n+6) { animation-delay: 145ms }

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

/* бета-плашка */
.beta-bar {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--warn-soft); color: var(--warn); font-size: 12.5px; font-weight: 600;
  padding: 7px var(--sp-3); border-radius: var(--r-full); margin-bottom: var(--sp-3);
}
