/* =====================================================================
   Тренажёрка ПСБ Спорт — токены и общие компоненты.
   Источник вида: дизайн/Components.dc.html, Employee.dc.html, Admin.dc.html.

   Публичные классы (экраны используют только их и свои):

   Кнопки        .btn + вариант + размер
     варианты    .btn-accent        оранжевая, текст #000F3C (основное действие)
                 .btn-soft          лаванда #ECE6FF, текст #001F74 (второстепенная)
                 .btn-danger        красная, белый текст
                 .btn-danger-outline белая, рамка и текст #B3122E
                 .btn-ghost-light   полупрозрачная белая на синем
                 .btn-white         белая на цветном (экран результата)
                 .btn-text          текстовая синяя («Добавить запись по коду»)
                 .btn-text-danger   текстовая красная («Закрыть день»)
                 .btn-link-danger   красная подчёркнутая («Отменить запись»)
     размеры     .btn-sm 44 · .btn-md 52 · .btn-lg 56 · .btn-xl 64; .btn-block — на всю ширину
     disabled    у залитых вариантов серая #E5E9F1 / #4A557A (как «Выбери время»)
   Иконка-кнопка .icon-btn 44×44 круглая; .icon-btn-square (радиус 12),
                 .icon-btn-ghost-light (на синем), .icon-btn-soft (#F8F6FF)
   Пилюля        .chip [.chip-sm | .chip-xs] + .chip-success | .chip-muted |
                 .chip-danger | .chip-brand | .chip-accent
   Карточка      .card-soft (#F8F6FF, радиус 20, поля 16)
   Переключатель .segmented > button (активная — aria-pressed="true",
                 aria-selected="true" или .is-on); .segmented-strong — активная синяя
   Перерыв       .break-line (линия — текст — линия)
   Нижняя панель .bottom-bar (белая с тенью, safe-area снизу)
   Шторка        .sheet-backdrop > .sheet: .sheet-handle, .sheet-icon(.sheet-icon-danger|
                 .sheet-icon-brand), .sheet-title, .sheet-sub, .sheet-text, .sheet-actions
                 (собирает Gym.sheet; на ≥1024 px — модальное окно 440 px по центру)
   Сообщение     .toast-region > .toast (собирает Gym.toast); отступ снизу —
                 переменная --toast-bottom (по умолчанию 24px), экран с нижней
                 панелью ставит её на <html>, например 100px
   Поле кода     .code-cells(.is-lg) > .code-input + .code-cell(.is-filled|.is-active) +
                 .code-sep (собирает Gym.codeInput)
   Заглушки      .skeleton (плашка #F1F2F6) > .skeleton-bar (полоса #E5E9F1)
   Служебные     .visually-hidden, .scroll-area (без видимого скроллбара),
                 .on-dark (белое кольцо фокуса внутри синего/цветного блока),
                 .web-only / .tg-only (в Telegram на <html> стоит .is-tg)

   Иконки <psb-icon color="currentColor"> берут цвет текста родителя.
   ===================================================================== */

@font-face {
  font-family: 'PSB Lavr';
  src: url('../fonts/PSBLavr-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'PSB Lavr';
  src: url('../fonts/PSBLavr-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'PSB Lavr';
  src: url('../fonts/PSBLavr-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* бренд */
  --c-navy: #001F74;          /* шапки, выбранное, верх билета */
  --c-navy-hover: #0A2C8C;
  --c-ink: #000F3C;           /* текст на светлом */
  --c-ink-deep: #000E3B;      /* фон всплывающего сообщения */
  --c-accent: #FF6734;        /* основная кнопка, «мало мест», «Сейчас» */
  --c-accent-bg: #FFF1EB;     /* слот «мало мест» */
  --c-accent-ink: #A8360C;    /* текст «осталось 2 места» */
  --c-violet: #9F84FF;        /* конец градиента билета */
  --c-white: #FFFFFF;

  /* подложки и линии */
  --c-mist: #F8F6FF;          /* карточки, слоты, переключатели */
  --c-lavender: #ECE6FF;      /* второстепенная кнопка, круг иконки */
  --c-silver: #E5E9F1;        /* линии, пустая ячейка кода, неактивная кнопка */
  --c-cloud: #EEF0F5;         /* серая пилюля, рамка прошедшего слота */
  --c-fog: #F1F2F6;           /* «нет мест», закрытый слот, заглушки */
  --c-dash: #D6CFF2;          /* пунктир билета */

  /* текст */
  --c-text-2: #4A557A;        /* вторичный */
  --c-text-3: #5F6782;        /* приглушённый на сером */
  --c-steel: #80879D;         /* подписи, дефис кода */
  --c-steel-300: #A6B1CD;     /* время прошедшего слота */

  /* служебные */
  --c-green: #0B7A3E;
  --c-green-bg: #E3F3E9;
  --c-red: #B3122E;
  --c-red-bg: #FDECEE;

  --c-overlay: rgba(0, 14, 59, 0.5);
  --c-ghost-light: rgba(255, 255, 255, 0.14);
  --c-focus: #001F74;
  --grad-ticket: linear-gradient(170deg, #001F74 0%, #001F74 55%, #9F84FF 150%);

  /* радиусы */
  --r-6: 6px;
  --r-10: 10px;
  --r-12: 12px;
  --r-14: 14px;
  --r-16: 16px;
  --r-20: 20px;
  --r-24: 24px;
  --r-pill: 999px;

  /* тени */
  --sh-bar: 0 -6px 20px rgba(0, 14, 59, 0.08);     /* нижняя панель */
  --sh-card: 0 12px 32px rgba(0, 14, 59, 0.14);    /* билет */
  --sh-sheet: 0 -12px 32px rgba(0, 14, 59, 0.14);  /* шторка */
  --sh-toast: 0 12px 32px rgba(0, 14, 59, 0.22);   /* сообщение */
  --sh-modal: 0 28px 64px rgba(0, 14, 59, 0.22);   /* шторка на десктопе */

  --font: 'PSB Lavr', 'Helvetica Neue', Arial, sans-serif;
  --toast-bottom: 24px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--c-ink);
  background: var(--c-white);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

a { color: var(--c-navy); }
a:hover { color: var(--c-navy-hover); }

:focus-visible {
  outline: 3px solid var(--c-focus);
  outline-offset: 2px;
}
.on-dark { --c-focus: #FFFFFF; }

html.sheet-open, html.sheet-open body { overflow: hidden; }

.is-tg .web-only { display: none !important; }
html:not(.is-tg) .tg-only { display: none !important; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--r-16);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  user-select: none;
  -webkit-user-select: none;
  transition: filter 0.15s, background-color 0.15s;
}
.btn:disabled, .btn[aria-disabled="true"] { cursor: default; }
@media (hover: hover) {
  .btn:not(:disabled):hover, .icon-btn:not(:disabled):hover { filter: brightness(0.95); }
}
.btn:not(:disabled):active, .icon-btn:not(:disabled):active { filter: brightness(0.9); }

.btn-accent { background: var(--c-accent); color: var(--c-ink); }
.btn-soft { background: var(--c-lavender); color: var(--c-navy); }
.btn-danger { background: var(--c-red); color: #FFFFFF; }
.btn-danger-outline {
  background: #FFFFFF;
  color: var(--c-red);
  box-shadow: inset 0 0 0 2px var(--c-red);  /* рамка без сдвига размеров */
}
.btn-ghost-light { background: var(--c-ghost-light); color: #FFFFFF; --c-focus: #FFFFFF; }
.btn-white { background: #FFFFFF; color: var(--c-ink); --c-focus: #FFFFFF; }
.btn-text, .btn-text-danger, .btn-link-danger {
  background: none;
  padding: 0 8px;
  min-height: 48px;
}
.btn-text { color: var(--c-navy); }
.btn-text-danger { color: var(--c-red); font-size: 15px; }
.btn-link-danger {
  color: var(--c-red);
  min-height: 44px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* неактивная — как «Выбери время» в макете */
.btn:disabled {
  background: var(--c-silver);
  color: var(--c-text-2);
  box-shadow: none;
}
.btn-text:disabled, .btn-text-danger:disabled, .btn-link-danger:disabled {
  background: none;
  color: var(--c-steel);
}

.btn-sm { min-height: 44px; padding: 0 14px; border-radius: var(--r-14); font-size: 15px; }
.btn-md { min-height: 52px; padding: 0 22px; border-radius: var(--r-16); font-size: 16px; }
.btn-lg { min-height: 56px; padding: 0 28px; border-radius: var(--r-16); font-size: 17px; }
.btn-xl { min-height: 64px; padding: 0 28px; border-radius: var(--r-16); font-size: 19px; gap: 10px; }
.btn-block { display: flex; width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.icon-btn-square { border-radius: var(--r-12); }
.icon-btn-ghost-light { background: var(--c-ghost-light); color: #FFFFFF; --c-focus: #FFFFFF; }
.icon-btn-soft { background: var(--c-mist); color: var(--c-navy); }

/* ---------- пилюли статуса ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--r-pill);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}
.chip-sm { gap: 5px; padding: 3px 9px 3px 6px; font-size: 13px; }   /* «Ты записан» */
.chip-xs { gap: 4px; padding: 2px 8px; font-size: 12px; }            /* «Сейчас», «Закрыт» */
.chip-xs > psb-icon:first-child { margin-left: -3px; }
.chip-success { background: var(--c-green-bg); color: var(--c-green); } /* Активна */
.chip-muted { background: var(--c-cloud); color: var(--c-text-2); }    /* Пройдена, Не пришёл */
.chip-danger { background: var(--c-red); color: #FFFFFF; }             /* Слот закрыт залом */
.chip-brand { background: var(--c-navy); color: #FFFFFF; }             /* Ты записан */
.chip-accent { background: var(--c-accent); color: var(--c-ink); }     /* Сейчас */

/* ---------- карточки, переключатель, разделитель ---------- */

.card-soft {
  background: var(--c-mist);
  border-radius: var(--r-20);
  padding: 16px;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-16);
  background: var(--c-mist);
}
.segmented > button {
  min-height: 44px;
  padding: 4px;
  border: 0;
  border-radius: var(--r-12);
  background: transparent;
  color: var(--c-text-2);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.15;
  cursor: pointer;
}
.segmented > [aria-pressed="true"],
.segmented > [aria-selected="true"],
.segmented > .is-on { background: #FFFFFF; color: var(--c-navy); }

/* админка: дни и правила — активная залита синим */
.segmented-strong { border-radius: var(--r-14); }
.segmented-strong > button { border-radius: var(--r-10); font-size: 15px; color: var(--c-ink); }
.segmented-strong > [aria-pressed="true"],
.segmented-strong > [aria-selected="true"],
.segmented-strong > .is-on { background: var(--c-navy); color: #FFFFFF; }

.break-line {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  color: var(--c-text-2);
  font-size: 14px;
  white-space: nowrap;
}
.break-line::before, .break-line::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--c-silver);
}

.bottom-bar {
  flex: none;
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  background: #FFFFFF;
  box-shadow: var(--sh-bar);
}

/* ---------- всплывающее сообщение ---------- */

.toast-region {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--toast-bottom) + env(safe-area-inset-bottom, 0px));
  max-width: 440px;
  margin: 0 auto;
  z-index: 200;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--r-16);
  background: var(--c-ink-deep);
  color: #FFFFFF;
  font-size: 15px;
  line-height: 1.35;
  box-shadow: var(--sh-toast);
  animation: gym-toast-in 0.22s var(--ease-out);
}
.toast.is-leaving { animation: gym-fade-out 0.18s ease-in forwards; }

/* ---------- шторка ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--c-overlay);
  animation: gym-fade-in 0.2s ease-out;
}
.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 600px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  border-radius: var(--r-24) var(--r-24) 0 0;
  background: #FFFFFF;
  color: var(--c-ink);
  box-shadow: var(--sh-sheet);
  animation: gym-sheet-in 0.26s var(--ease-out);
}
.sheet:focus { outline: none; }
.sheet-handle {
  flex: none;
  align-self: center;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--c-silver);
}
.sheet-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--c-lavender);
  color: var(--c-navy);
}
.sheet-icon-brand { background: var(--c-lavender); color: var(--c-navy); }
.sheet-icon-danger { background: var(--c-red-bg); color: var(--c-red); }
.sheet-title { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; }
.sheet-sub { margin: -6px 0 0; font-size: 15px; line-height: 1.4; color: var(--c-text-2); }
.sheet-text { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.3; text-wrap: pretty; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; }
.sheet-note { margin: 0; font-size: 16px; line-height: 1.4; }
/* две кнопки в ряд: второстепенная слева, основная справа */
.sheet-actions.is-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 4px; }
.sheet-actions.is-row > .btn { min-height: 52px; font-size: 16px; }
.sheet-actions.is-row > .btn-soft { order: -1; }

@media (min-width: 1024px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet {
    width: 440px;
    max-height: 100%;
    padding: 24px;
    border-radius: var(--r-24);
    box-shadow: var(--sh-modal);
    animation-name: gym-modal-in;
  }
  .sheet-handle { display: none; }
}

/* ---------- поле кода: 7 ячеек поверх скрытого input ---------- */

.code-cells {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 6px;
  cursor: text;
}
.code-cells.is-lg { justify-content: space-between; }
.code-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;            /* без автозума на iOS */
  color: transparent;
  caret-color: transparent;
  background: transparent;
  cursor: text;
}
.code-cell {
  display: grid;
  place-items: center;
  flex: 0 1 44px;             /* на 320–375 px ячейки ужимаются, а не вылезают за край */
  min-width: 0;
  height: 56px;
  border: 2px solid var(--c-silver);
  border-radius: var(--r-12);
  background: #FFFFFF;
  color: var(--c-ink);
  font-size: 24px;
  font-weight: 700;
  pointer-events: none;
}
.code-cell.is-filled, .code-cell.is-active { border-color: var(--c-navy); }
.code-sep {
  display: grid;
  place-items: center;
  flex: none;
  width: 20px;
  height: 56px;
  color: var(--c-steel);
  font-size: 24px;
  font-weight: 700;
  pointer-events: none;
}
.code-cells.is-lg .code-cell { flex-basis: 48px; height: 68px; font-size: 30px; }
.code-cells.is-lg .code-sep { width: 22px; height: 68px; font-size: 30px; }
/* фокус: подсветка ячейки, куда пойдёт следующий символ */
.code-cells:focus-within .code-cell.is-active,
.code-cells.is-full:focus-within .code-cell:last-of-type {
  box-shadow: 0 0 0 3px rgba(0, 31, 116, 0.22);
}

/* ---------- заглушки загрузки ---------- */

.skeleton {
  border-radius: var(--r-16);
  background: var(--c-fog);
  animation: gym-pulse 1.1s ease-in-out infinite alternate;
}
.skeleton-bar {
  display: block;
  height: 12px;
  border-radius: var(--r-6);
  background: var(--c-silver);
}

/* ---------- служебные ---------- */

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.scroll-area {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll-area::-webkit-scrollbar { display: none; }

/* ---------- анимации ---------- */

@keyframes gym-fade-in { from { opacity: 0; } }
@keyframes gym-fade-out { to { opacity: 0; } }
@keyframes gym-sheet-in { from { transform: translateY(100%); } }
@keyframes gym-modal-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
@keyframes gym-toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes gym-pulse { to { opacity: 0.55; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
