/* ==========================================================================
   ЗаЖим — единая дизайн-система
   Токены + сброс + компоненты. Раньше стили были размазаны по base.html
   (инлайн <style>) и по отдельным шаблонам (enter_phone/enter_profile/
   enter_pin/set_pin), каждый со своими цветами и радиусами — отсюда
   разнобой между экранами. Теперь один источник правды.
   ========================================================================== */

:root {
  /* Фирменный синий — уже используется в theme-color и иконках PWA */
  --primary: #2a4d69;
  --primary-dark: #1c3a52;
  --primary-light: #eaf1f6;

  /* Акцент для фокуса/ссылок/успеха при вводе */
  --accent: #3b82f6;
  --accent-light: rgba(59, 130, 246, .12);

  --success: #16a34a;
  --success-bg: #f0fdf4;
  --danger: #dc2626;
  --danger-bg: #fef2f2;

  --text: #1e293b;
  --text-muted: #64748b;
  --bg: #f7f9fb;
  --card-bg: #ffffff;
  --border: #e2e8f0;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 14px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 30px -10px rgba(15, 23, 42, .12);

  --field-h: 44px;
}

/* ---------- Сброс ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { height: auto; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  touch-action: manipulation;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4 { margin: 0 0 .6em; color: var(--text); line-height: 1.3; }

a { color: var(--accent); text-decoration: none; }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  flex: 1;
}

@media (max-width: 600px) {
  .container { padding: 16px 12px 32px; }
}

/* Обёртка для админ-панели: без узкого max-width мобильного приложения,
   чтобы на компьютере панель занимала весь экран, а сайдбар и таблицы
   не сжимались в мобильную колонку. На телефоне админка сама переключается
   в мобильный режим через свою вёрстку (admin-layout / .admin-sidebar). */
.admin-container {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

/* Экраны без общей навигации: вход, регистрация, PIN — центрируем карточку */
.center-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
  padding: 24px 16px;
  box-sizing: border-box;
  background: linear-gradient(135deg, #f4f7fa 0%, #eaf1f6 100%);
}

/* ---------- Логотип ---------- */
.logo-container { text-align: center; margin-bottom: 24px; }
.gym-logo {
  height: 56px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .1));
}

/* ---------- Карточка (авторизация/регистрация) ---------- */
.login-form, .reg-form {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  position: relative;
  overflow: hidden;
}

.reg-form { max-width: 480px; padding: 28px 24px; }

.login-form::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.reg-title, .login-form h2 {
  text-align: center;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 20px;
}

.instruction {
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
  line-height: 1.5;
  margin: 0 0 24px;
}

@media (max-width: 480px) {
  .login-form, .reg-form { padding: 24px 20px; }
  .gym-logo { height: 48px; }
}

/* ---------- Поля форм ---------- */
.field, .form-group { margin-bottom: 18px; }

.field label, .form-label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.input, .select, .form-control {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.input:focus, .select:focus, .form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* ---------- Кнопка ---------- */
.submit-btn {
  width: 100%;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
  box-shadow: 0 4px 14px -2px rgba(42, 77, 105, .35);
}

.submit-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.submit-btn:active:not(:disabled) { transform: translateY(0); }

.submit-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* ---------- Телефонный ввод (registration/enter_phone) ---------- */
.phone-wrapper {
  margin: 8px 0 4px;
  padding: 2px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.phone-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.phone-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.15rem;
  font-weight: 500;
  text-align: center;
  letter-spacing: .5px;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  font-family: inherit;
}

.phone-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: .8rem;
  margin: 10px 0 18px;
  min-height: 1.2em;
}

.phone-hint.success { color: var(--success); }
.phone-hint.error { color: var(--danger); }

/* ---------- Уведомления / ошибки полей ---------- */
.alert {
  padding: 14px 18px;
  margin: 0 0 18px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.alert-error, .alert.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-left: 3px solid var(--danger);
}

.alert-info, .alert.alert-info {
  background: var(--primary-light);
  color: var(--primary);
}

.picker-hint.err, .picker-hint.ok { text-align: center; font-size: .85rem; margin-top: 6px; }
.picker-hint.err { color: var(--danger); }
.picker-hint.ok { color: var(--success); }

/* ---------- PWA install banner ---------- */
.install-banner {
  display: none;
  margin-top: 16px;
  padding: 12px;
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

.install-banner.show { display: block; }
.install-banner-text { font-size: .9rem; color: var(--primary); margin-bottom: 4px; }

.install-btn {
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
}

.install-btn:hover { background: var(--primary-dark); }

/* ---------- Дата рождения — колёсико (registration/enter_profile) ---------- */
.picker-wrap {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
  margin: 8px 0;
}

.picker-wrap::before, .picker-wrap::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: var(--field-h);
  z-index: 3;
  pointer-events: none;
}

.picker-wrap::before { top: 0; background: linear-gradient(180deg, var(--bg), transparent); }
.picker-wrap::after { bottom: 0; background: linear-gradient(0deg, var(--bg), transparent); }

.picker-highlight {
  position: absolute;
  top: 50%; left: 0; right: 0;
  height: var(--field-h);
  transform: translateY(-50%);
  background: linear-gradient(180deg, var(--accent-light), rgba(59, 130, 246, .18) 50%, var(--accent-light));
  border-top: 1px solid rgba(59, 130, 246, .3);
  border-bottom: 1px solid rgba(59, 130, 246, .3);
  pointer-events: none;
  z-index: 1;
}

.picker-col {
  flex: 1;
  max-width: 90px;
  height: 132px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: relative;
  z-index: 2;
  text-align: center;
  scroll-padding: var(--field-h) 0;
  padding: var(--field-h) 0;
}

.picker-col::-webkit-scrollbar { display: none; }
.picker-spacer { height: var(--field-h); visibility: hidden; }

.picker-item {
  height: var(--field-h);
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  font-size: 17px;
  color: var(--text-muted);
  transition: all .15s;
  user-select: none;
  cursor: pointer;
}

.picker-col.scrolling .picker-item { opacity: .5; transform: scale(.95); }
.picker-item.selected { color: var(--text); font-weight: 700; font-size: 19px; transform: scale(1.05); opacity: 1; }

.picker-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
  margin: 8px 0 0;
  min-height: 1.2em;
  font-weight: 500;
}

.consent-box {
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius);
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.consent-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 15px;
  line-height: 1.5;
}

.consent-row input { margin-top: 4px; width: 20px; height: 20px; accent-color: var(--primary); }
.consent-row a { color: var(--accent); }

@media (max-width: 480px) {
  .picker-item { font-size: 16px !important; }
  .picker-item.selected { font-size: 18px !important; }
  .picker-highlight { height: 40px; }
  .picker-wrap { gap: 4px; }
}

/* ---------- PIN-код (auth/enter_pin, auth/set_pin) ---------- */
.pin-group {
  margin: 20px 0;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.pin-group-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-align: center;
}

.pin-container {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 20px 0;
}

.pin-digit {
  width: 48px;
  height: 60px;
  font-size: 26px;
  font-weight: 600;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  transition: all .15s ease;
  font-family: inherit;
}

.pin-digit::-webkit-outer-spin-button,
.pin-digit::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.pin-digit:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  outline: none;
  transform: translateY(-2px);
  z-index: 1;
}

.pin-digit.filled { border-color: var(--success); background: var(--success-bg); }
.pin-digit.error { border-color: var(--danger); animation: pin-shake .3s ease; }

@keyframes pin-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.pin-hint { text-align: center; color: var(--text-muted); font-size: .9rem; margin: 4px 0; }
.pin-error { text-align: center; color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: 4px 0; }

.pin-match-status { text-align: center; font-size: .9rem; min-height: 1.4em; margin: 8px 0 4px; font-weight: 500; }
.pin-match-status.match { color: var(--success); }
.pin-match-status.mismatch { color: var(--danger); }

.auth-link { text-align: center; margin-top: 24px; }
.auth-link a { text-decoration: none; font-weight: 600; }
.auth-link a:hover { text-decoration: underline; }

@media (max-width: 480px) {
  .pin-digit { width: 42px; height: 54px; font-size: 22px; }
  .pin-container { gap: 8px; }
  .pin-group { padding: 12px; }

  /* 🔧 Найдено рендером auth/set_pin.html на 390px: два блока PIN внутри
     .pin-group (у него свой padding) не оставляли 6 полям по 42px + отступам
     8px хватающего места — не хватало ~2px, и шестое поле переносилось на
     новую строку. У auth/enter_pin.html (без .pin-group) той же проблемы
     нет — там места больше. Сокращаем gap только внутри .pin-group, где
     тесно, не трогая обычный .pin-container. */
  .pin-group .pin-container { gap: 5px; }
}

/* ---------- Текстовые страницы (оферта, правила, политика) ---------- */
.container h1, .container h2, .container h3, .container h4 {
  margin-top: 1.6em;
  margin-bottom: .7em;
  font-weight: 700;
  color: var(--primary-dark);
}

.container h1 { font-size: 1.7rem; text-align: center; margin-top: .6em; }
.container h2 { font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.container p { margin: 1em 0; line-height: 1.6; }
.container ul, .container ol { margin: 1.1em 0 1.1em 1.6em; line-height: 1.6; }
.container li { margin-bottom: .5em; }
.container p a, .container li a { text-decoration: underline; }

/* ---------- Футер ---------- */
.site-footer {
  width: 100%;
  padding: 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.6;
}

.site-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }
.site-footer a:hover { text-decoration: underline; }
.site-footer p { margin: 4px 0; }

@media (max-width: 480px) {
  .site-footer { font-size: 12px; padding: 16px 12px; }
}

/* ==========================================================================
   Нижняя навигация (единый компонент)
   Раньше эта разметка и стили были продублированы в каждом шаблоне
   отдельно (профиль, абонемент, дневник, тренеры, информация) — с разным
   числом вкладок и мелкими расхождениями. Теперь один источник правды:
   стили здесь, разметка — в app/templates/_bottom_nav.html.
   ========================================================================== */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 68px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, .06);
  z-index: 1000;
  padding: 0 8px;
  box-sizing: border-box;
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  flex: 1;
  min-width: 0;
  height: 100%;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-muted);
  transition: all .2s ease;
  border-radius: 12px;
  padding: 6px 2px;
  position: relative;
}

.bottom-nav a span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.bottom-nav a:hover:not(.active) { color: var(--text); background-color: var(--bg); }

.bottom-nav a.active { color: var(--primary); background-color: var(--primary-light); }
.bottom-nav a.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 20px; height: 3px;
  background: var(--primary);
  border-radius: 2px;
}

.bottom-nav .nav-icon {
  font-size: 19px;
  margin-bottom: 3px;
  line-height: 1;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Место под контентом страниц, где есть нижняя навигация */
body.has-bottom-nav { padding-bottom: 78px; }

/* ==========================================================================
   notify.js — тосты и модальное подтверждение (замена alert()/confirm())
   ========================================================================== */
#notify-toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 380px);
  pointer-events: none;
}

.notify-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #2a3140;
  color: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  font-size: 14px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.notify-toast--show { opacity: 1; transform: translateY(0); }
.notify-toast--hide { opacity: 0; transform: translateY(-10px); }

.notify-toast--success { background: #1f7a4d; }
.notify-toast--error   { background: #a13939; }
.notify-toast--info    { background: #2a4d69; }

.notify-toast__msg { flex: 1; word-break: break-word; }

.notify-toast__close {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.notify-toast__close:hover { color: #fff; }

.notify-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.notify-confirm-overlay--show { opacity: 1; }

.notify-confirm-box {
  background: #fff;
  border-radius: 14px;
  padding: 22px 20px;
  width: min(90vw, 340px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  transform: scale(0.95);
  transition: transform 0.2s ease;
}
.notify-confirm-overlay--show .notify-confirm-box { transform: scale(1); }

.notify-confirm-msg {
  font-size: 15px;
  color: #222;
  margin-bottom: 18px;
  white-space: pre-line;
}

.notify-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.notify-confirm-btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}
.notify-confirm-btn--cancel { background: #eee; color: #333; }
.notify-confirm-btn--cancel:hover { background: #e0e0e0; }
.notify-confirm-btn--ok { background: #2a4d69; color: #fff; }
.notify-confirm-btn--ok:hover { background: #223f57; }
