/* Оформление кабинета записи.
 *
 * Палитра, радиусы и тени взяты один в один из кабинета тренажера
 * RusByBartuli: синий #2f6bf6, фон #eef2fb, карточки 16px с мягкой тенью,
 * шапка - синий градиент со скругленным низом. Это не украшательство:
 * человек попадает сюда из того же бренда, и если цвет и форма меняются,
 * он читает это как «я не туда попал» - особенно родитель, который платит.
 *
 * Светлая тема - основная и совпадает с тренажером до пикселя. Темная
 * держит тот же синий и ту же геометрию: Telegram в ночном режиме белым
 * листом бьет по глазам, но менять при этом фирменный цвет незачем.
 */

:root {
  /* Боковой отступ контента. Ленты, которые прокручиваются вбок, выпускают
     себя на эту величину, чтобы доходить до краев экрана. */
  --gutter: 16px;
  color-scheme: light;

  --blue: #2f6bf6;
  --blue-d: #1f54d6;
  --blue-l: #eaf1ff;
  --blue-soft: #dfe9ff;
  --bg: #eef2fb;
  --card: #ffffff;
  --surface-soft: #f3f6fd;
  --text: #16223a;
  --hint: #7b88a3;
  --line: #e4eaf4;
  --ok: #159a4d;
  --ok-bg: #e6f7ee;
  --amber: #b9740f;
  --amber-bg: #fbeed6;
  --danger: #c0392f;
  --danger-bg: #fbe7e4;
  --on-blue: #ffffff;

  --hero: linear-gradient(135deg, #2f6bf6, #6a9bff);
  --shadow-card: 0 4px 16px rgba(36, 68, 140, .06);
  --shadow-hero: 0 8px 24px rgba(47, 107, 246, .25);
  --shadow-blue: 0 4px 14px rgba(47, 107, 246, .3);
  --shadow-sheet: 0 -18px 50px rgba(22, 34, 58, .22);

  --radius-card: 16px;
  --radius-lg: 20px;
  --radius-pill: 13px;

  /* Telegram отдает свои отступы отдельно от системных: в полноэкранном
     режиме под шапкой мессенджера env() еще ноль, а контент уже уехал.
     Берем то, что дает Telegram, и падаем на системные, если его нет. */
  --safe-top: calc(
    var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) +
    var(--tg-content-safe-area-inset-top, 0px)
  );
  --safe-bottom: calc(
    var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) +
    var(--tg-content-safe-area-inset-bottom, 0px)
  );

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --blue: #3f6fe0;
    --blue-d: #8fb2ff;
    --blue-l: #1b2643;
    --blue-soft: #23315a;
    --bg: #0f1526;
    --card: #171f33;
    --surface-soft: #1c2438;
    --text: #eaf0ff;
    --hint: #93a1bd;
    --line: #26304a;
    --ok: #52c98a;
    --ok-bg: #14301f;
    --amber: #e2ad5c;
    --amber-bg: #33260f;
    --danger: #f08a7f;
    --danger-bg: #3a1c19;
    --on-blue: #ffffff;
    --hero: linear-gradient(135deg, #2b5fd8, #4a7bea);
    --shadow-card: 0 4px 16px rgba(0, 0, 0, .32);
    --shadow-hero: 0 8px 24px rgba(0, 0, 0, .4);
    --shadow-blue: 0 4px 14px rgba(43, 95, 216, .45);
    --shadow-sheet: 0 -18px 50px rgba(0, 0, 0, .5);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

button,
input,
select,
textarea {
  font-family: var(--font);
  font-size: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 40%, transparent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
  margin: 0 auto;
  background: var(--bg);
}

/* --- Шапка: тот же синий градиент, что и в тренажере --------------------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(20px + var(--safe-top)) 20px 20px;
  border-radius: 0 0 26px 26px;
  background: var(--hero);
  color: #fff;
  box-shadow: var(--shadow-hero);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-weight: 700;
  letter-spacing: -.3px;
}

.brand-copy {
  min-width: 0;
}

.brand-copy strong,
.brand-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy strong {
  font-size: 17px;
  font-weight: 700;
}

.brand-copy span {
  margin-top: 2px;
  font-size: 13px;
  opacity: .92;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  cursor: pointer;
  font-size: 20px;
}

.icon-button:disabled {
  opacity: .6;
}

.screen-heading .icon-button {
  background: var(--blue-l);
  color: var(--blue-d);
}

.app-main {
  min-height: calc(100vh - 240px);
  padding: 18px var(--gutter) 104px;
}

/* --- Состояния загрузки и пустоты ---------------------------------------- */

.loading-screen,
.error-screen,
.empty-screen {
  min-height: 52vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 32px 18px;
  text-align: center;
}

.loading-screen p,
.error-screen p,
.empty-screen p {
  margin: 0;
  color: var(--hint);
}

.error-screen h1,
.empty-screen h2 {
  margin: 0;
  font-size: 20px;
}

.loading-mark {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 24px;
  background: var(--hero);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  box-shadow: var(--shadow-blue);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Заголовок экрана ---------------------------------------------------- */

.screen-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  margin: 0 2px 16px;
}

.screen-heading h1,
.screen-heading p {
  margin: 0;
}

.screen-heading h1 {
  font-size: clamp(23px, 6.4vw, 28px);
  line-height: 1.12;
  letter-spacing: -.5px;
}

.screen-heading p {
  margin-bottom: 4px;
  color: var(--hint);
  font-size: 13px;
}

/* --- Ближайшее занятие --------------------------------------------------- */

.next-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--hero);
  color: #fff;
  box-shadow: var(--shadow-hero);
}

.next-card strong,
.next-card span {
  display: block;
}

.next-card .eyebrow {
  margin-bottom: 4px;
  opacity: .85;
  font-size: 12px;
}

.next-card .next-time {
  text-align: right;
  white-space: nowrap;
}

.next-card .next-time strong {
  font-size: 16px;
}

.next-card .next-time span {
  opacity: .85;
  font-size: 12px;
}

/* Неподтвержденный запрос не должен выглядеть как подтвержденное занятие:
   синяя карточка читается как «все решено», а решено еще ничего. */
.next-card.requested,
.next-card.proposed {
  background: var(--amber-bg);
  color: var(--amber);
  box-shadow: var(--shadow-card);
  cursor: pointer;
}

/* --- Календарь ----------------------------------------------------------- */

.calendar-card {
  margin-top: 16px;
  padding: 16px 10px 12px;
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 6px 12px;
}

.calendar-header h2 {
  margin: 0;
  font-size: 17px;
}

.calendar-arrows {
  display: flex;
  gap: 6px;
}

.calendar-arrows button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: var(--blue-l);
  color: var(--blue-d);
  cursor: pointer;
  font-size: 20px;
}

.weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  text-align: center;
}

.weekdays span {
  display: grid;
  place-items: center;
  min-height: 28px;
  color: var(--hint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.calendar-day {
  position: relative;
  min-width: 0;
  min-height: 44px;
  margin: 2px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.calendar-day:disabled {
  cursor: default;
  color: color-mix(in srgb, var(--hint) 55%, transparent);
}

.calendar-day.outside {
  color: color-mix(in srgb, var(--hint) 45%, transparent);
}

.calendar-day.has-free::after,
.calendar-day.has-busy::after,
.calendar-day.has-request::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translateX(-50%);
  background: var(--ok);
}

.calendar-day.has-busy::after {
  background: var(--blue);
}

.calendar-day.has-request::after {
  background: var(--amber);
}

.calendar-day.selected {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-blue);
}

.calendar-day.selected::after {
  background: #fff;
}

.calendar-day.today:not(.selected) {
  box-shadow: inset 0 0 0 1.5px var(--blue);
  color: var(--blue-d);
  font-weight: 600;
}

.day-count {
  position: absolute;
  right: 3px;
  top: 3px;
  display: grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--blue-l);
  color: var(--blue-d);
  font-size: 9px;
  font-weight: 700;
}

.selected .day-count {
  background: rgba(255, 255, 255, .28);
  color: #fff;
}

/* --- Слоты времени ------------------------------------------------------- */

.slot-section {
  margin-top: 18px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 12px;
}

.section-header h2,
.section-header p {
  margin: 0;
}

.section-header h2 {
  font-size: 17px;
}

.section-header p {
  margin-top: 2px;
  color: var(--hint);
  font-size: 12.5px;
}

.timezone-badge,
.status-badge {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--ok-bg);
  color: var(--ok);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.pending {
  background: var(--amber-bg);
  color: var(--amber);
}

.status-badge.cancelled {
  background: var(--danger-bg);
  color: var(--danger);
}

.status-badge.neutral {
  background: var(--blue-l);
  color: var(--blue-d);
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.time-button {
  min-height: 46px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--card);
  color: var(--blue-d);
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}

.time-button.selected {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-blue);
}

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

.primary-button,
.secondary-button,
.danger-button {
  min-height: 48px;
  padding: 11px 16px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}

.primary-button {
  border: 0;
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-blue);
}

.primary-button:active {
  background: var(--blue-d);
}

.secondary-button {
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--blue-d);
}

.danger-button {
  border: 0;
  background: var(--danger-bg);
  color: var(--danger);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: .45;
  box-shadow: none;
  cursor: default;
}

.block-button {
  width: 100%;
  margin-top: 14px;
}

.inline-actions {
  display: grid;
  /* minmax(0, 1fr), а не голый 1fr - у 1fr-трека по умолчанию минимальный
     размер "auto" (по контенту), и поле с парой <input type="number"> +
     подписями единиц (часы работы -> "Занятие"/"Шаг сетки") раздувало
     шторку вбок на узком экране (У2, тот же баг, что и в «Часах работы»). */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 10px;
}

/* Одна кнопка занимает всю ширину. Раньше вторую половину держала пустая
   заглушка, и кнопка «Отменить» висела в правой половине карточки без
   пары - выглядело как недорисованный экран. */
.inline-actions.one {
  grid-template-columns: minmax(0, 1fr);
}

.compact-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  border-radius: 12px;
  font-size: 13.5px;
}

.selection-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-card);
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 13.5px;
}

.selection-banner button {
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.empty-inline {
  padding: 20px;
  border-radius: var(--radius-card);
  background: var(--card);
  color: var(--hint);
  box-shadow: var(--shadow-card);
  text-align: center;
}

/* --- Карточки ------------------------------------------------------------ */

.lesson-list,
.student-list,
.request-list,
.lead-list {
  display: grid;
  /* Без явной ширины колонки CSS Grid считает ее по самой широкой карточке
     (min-content) и растягивает под нее ВСЕ карточки - на 360px карточка с
     длинным именем или двумя бейджами раздувала весь список вбок (B4,
     ночь 5), хотя каждая карточка сама по себе спокойно переносит текст. */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.lesson-card,
.student-card,
.request-card,
.lead-card,
.agenda-item {
  padding: 15px;
  border-radius: var(--radius-card);
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.lesson-main,
.student-main,
.request-main {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

/* У домашки нет времени слева, поэтому колонок две. Без этого значок статуса
   попадал в растягивающуюся колонку и раздувался на пол-карточки. */
.lesson-main.no-time {
  grid-template-columns: minmax(0, 1fr) auto;
}

.time-box,
.avatar-box {
  display: grid;
  place-items: center;
  min-width: 58px;
  min-height: 48px;
  padding: 7px;
  border-radius: 14px;
  background: var(--blue-l);
  color: var(--blue-d);
  font-weight: 700;
}

.avatar-box {
  width: 48px;
  min-width: 48px;
  border-radius: 16px;
}

.lesson-main h3,
.lesson-main p,
.student-main h3,
.student-main p,
.request-main h3,
.request-main p {
  margin: 0;
}

.lesson-main h3,
.student-main h3,
.request-main h3 {
  font-size: 15.5px;
}

.lesson-main p,
.student-main p,
.request-main p {
  margin-top: 3px;
  color: var(--hint);
  font-size: 12.5px;
}

.lesson-note {
  margin: 10px 0 0;
  color: var(--hint);
  font-size: 12.5px;
}

/* --- Заявки -------------------------------------------------------------- */

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  /* Лента прокручивается, поэтому выпускаем ее до краев экрана и возвращаем
     отступ изнутри: иначе последняя кнопка обрезается ровно по краю колонки
     и читается как сломанная верстка, а не как «пролистай дальше». */
  margin-inline: calc(-1 * var(--gutter));
  padding-inline: var(--gutter);
  scroll-padding-inline: var(--gutter);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

/* Д6, минимум: без подсказки лента чипов выглядит так, будто в ней больше
   нечего смотреть - последний чип (например, «Написали боту» в списке
   учеников) молча пропадает за краем экрана. Класс переключает
   `markScrollableChipRows()` в app.js только тогда, когда прокрутка
   реально есть. */
.filter-row.has-more {
  box-shadow: inset -24px 0 16px -16px rgba(16, 26, 48, .3);
}

/* Чипы выбора шаблона сообщения (F1 п.8): их немного и заголовки бывают
   длиннее, чем в ленте фильтра - переносим на новую строку, а не
   прокручиваем и не обрезаем. `.inline-actions` (грид 1fr 1fr) для этого
   не подходил: голый `1fr` не сжимается уже нерезинового `.filter-chip`
   (white-space: nowrap) и раздувал шторку вбок - тот же баг, что чинили в
   «Часах работы» (У2). */
.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.filter-chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--card);
  color: var(--hint);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: .15s;
}

.filter-chip.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-blue);
}

.lead-card {
  cursor: pointer;
  text-align: left;
  width: 100%;
  border: 0;
  font: inherit;
  color: inherit;
  display: block;
}

.lead-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lead-head h3 {
  margin: 0;
  font-size: 15.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-meta {
  margin: 6px 0 0;
  color: var(--hint);
  font-size: 12.5px;
}

.lead-note {
  margin: 9px 0 0;
  padding: 9px 11px;
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12.5px;
}

.lead-source {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--hint);
  font-size: 11px;
}

/* --- Профиль ------------------------------------------------------------- */

.profile-card {
  padding: 24px 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.profile-head {
  display: grid;
  place-items: center;
  text-align: center;
}

.profile-avatar {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  overflow: hidden;
  border-radius: 26px;
  background: var(--hero);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  box-shadow: var(--shadow-blue);
}

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

.profile-head h1 {
  margin: 12px 0 2px;
  font-size: 22px;
}

.profile-head p {
  margin: 0;
  color: var(--hint);
  font-size: 13.5px;
}

.auth-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
  padding: 13px;
  border-radius: var(--radius-card);
  background: var(--ok-bg);
  color: var(--ok);
}

.auth-row strong,
.auth-row span {
  display: block;
}

.auth-row span {
  font-size: 12px;
  opacity: .9;
}

.form-grid {
  display: grid;
  /* Без явной колонки неявная auto-колонка растет до max-content самой
     широкой строки формы, а не до реально доступной ширины шторки - на
     обычных полях этого не видно (они узкие), но на строке с двумя
     <input type="time"> подряд раздувало всю форму вбок (У2, «Часы
     работы»). minmax(0, 1fr) - тот же прием, что и ниже в .hours-row/
     .hours-list: явный резиновый трек, а не подогнанный под контент. */
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.field {
  display: grid;
  /* Тот же прием, что в .form-grid/.hours-list/.inline-actions выше: явная
     резиновая колонка вместо неявной auto, чтобы не сжимаемое по контенту
     (например, .hm-row с двумя <input type="number">) не раздувало поле
     шире реально доступного места в узкой колонке (У2). */
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}

.field label {
  color: var(--hint);
  font-size: 12.5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

/* Занятие/шаг сетки часами и минутами (B2, ночь 5): два узких числовых поля
   рядом вместо одного на всю ширину. min-width:0 нужен, чтобы flex-элементы
   сжимались внутри узкой колонки .inline-actions и на экране 360px. */
.field .hm-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field .hm-row input {
  width: auto;
  min-width: 0;
  flex: 1 1 0;
  padding: 12px 6px;
  text-align: center;
}

.hm-unit {
  flex: 0 0 auto;
  color: var(--hint);
  font-size: 13px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue);
}

.field textarea {
  min-height: 84px;
  resize: vertical;
}

/* Чекбокс внутри `.field label` (D6, ночь 7 - QA новых экранов): без этого
   переопределения `.field input` растягивал его в пустую пилюлю на всю
   ширину высотой 48px, а подпись из того же `<label>` съезжала под нее на
   следующую строку - "Присылать сводку недели…"/"Показывать родителю
   деньги" читались как два оторванных друг от друга элемента. Флажок
   должен остаться обычным маленьким чекбоксом перед своим текстом. */
.field input[type="checkbox"] {
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  vertical-align: middle;
  margin: 0 6px 0 0;
}

/* --- Переключатели ------------------------------------------------------- */

.view-switch,
.mode-switch {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border-radius: var(--radius-card);
  background: var(--surface-soft);
}

.view-switch {
  grid-template-columns: repeat(3, 1fr);
}

.mode-switch {
  grid-template-columns: 1fr 1fr;
  margin: 12px 0;
}

.view-switch button,
.mode-switch button {
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--hint);
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
}

.view-switch button.active,
.mode-switch button.active {
  background: var(--card);
  color: var(--blue-d);
  box-shadow: var(--shadow-card);
}

.request-banner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 66px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--radius-card);
  background: var(--amber-bg);
  color: var(--amber);
  text-align: left;
  cursor: pointer;
}

.request-count {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--amber);
  color: var(--amber-bg);
  font-weight: 700;
}

.request-banner strong,
.request-banner > span:not(.request-count) {
  display: block;
}

.request-banner > span span {
  font-size: 12.5px;
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin: 0 0 16px;
}

.week-day {
  min-width: 0;
  min-height: 62px;
  padding: 6px 1px;
  border: 0;
  border-radius: 14px;
  background: var(--card);
  color: var(--hint);
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: .15s;
}

.week-day span,
.week-day strong {
  display: block;
}

.week-day span {
  font-size: 10px;
  text-transform: uppercase;
}

.week-day strong {
  margin-top: 4px;
  font-size: 16px;
  color: var(--text);
}

.week-day.active {
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-blue);
}

.week-day.active strong {
  color: #fff;
}

/* --- Лента дня ----------------------------------------------------------- */

.agenda {
  display: grid;
  gap: 8px;
  padding-left: 57px;
}

.agenda-item {
  position: relative;
  min-height: 64px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
}

.agenda-item::before {
  content: attr(data-time);
  position: absolute;
  right: calc(100% + 10px);
  top: 16px;
  color: var(--hint);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.agenda-item h3,
.agenda-item p {
  margin: 0;
}

.agenda-item h3 {
  font-size: 15px;
}

.agenda-item p {
  margin-top: 3px;
  color: var(--hint);
  font-size: 12.5px;
}

.agenda-free {
  position: relative;
  padding: 12px 14px 10px;
  border: 1.5px dashed color-mix(in srgb, var(--ok) 45%, transparent);
  border-radius: 16px;
  background: var(--ok-bg);
}

.agenda-free::before {
  content: attr(data-time);
  position: absolute;
  right: calc(100% + 10px);
  top: 14px;
  color: var(--hint);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.agenda-free-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.agenda-free-head strong {
  color: var(--ok);
  font-size: 14.5px;
}

.agenda-free-head span {
  color: var(--hint);
  font-size: 12px;
}

.free-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.free-chip {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent);
  border-radius: 11px;
  background: var(--card);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.free-chip:active {
  background: var(--ok-bg);
}

.agenda-free-hint {
  margin: 9px 0 0;
  color: var(--hint);
  font-size: 11.5px;
}

/* P1.4: закрытый сегмент ленты дня - тот же каркас, что и свободный, но
   приглушенный, а не зеленый, и без чипов. */
.agenda-closed {
  position: relative;
  padding: 12px 14px 10px;
  border: 1.5px dashed color-mix(in srgb, var(--danger) 40%, transparent);
  border-radius: 16px;
  background: var(--danger-bg);
}

.agenda-closed::before {
  content: attr(data-time);
  position: absolute;
  right: calc(100% + 10px);
  top: 14px;
  color: var(--hint);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.agenda-closed .agenda-free-head strong {
  color: var(--danger);
  font-size: 14.5px;
}

.agenda-closed .agenda-free-head span {
  color: var(--hint);
  font-size: 12px;
}

.agenda-closed .compact-button {
  margin-top: 9px;
}

.agenda-closed-note {
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 11.5px;
}

.agenda-item.requested {
  border-left: 4px solid var(--amber);
}

.agenda-item.booked {
  border-left: 4px solid var(--blue);
}

.agenda-item.proposed {
  border-left: 4px dashed var(--blue);
}

/* Деньги в карточке занятия (F2, К4): та же строка, что в карточке
   ученика, но прямо там, где занятие уже открыто. */
.slot-finance-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-soft);
  font-weight: 600;
  font-size: 13.5px;
}

.slot-finance-line.debt {
  background: var(--danger-bg);
  color: var(--danger);
}

/* --- Неделя целиком (F2, К1) -----------------------------------------------
   Одна разметка для узкого и широкого экрана. До 900px в колонке видны
   только строки занятий, обычным потоком (свободное и закрытое время - в
   подписи дня, не блоками, п.2). От 900px открывается позиционирование по
   CSS-переменным --start-min/--dur-min внутри общей сетки часов (п.3) -
   меняется только этот блок, разметка та же самая. */

.week-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 4px;
}

.week-col {
  border-radius: var(--radius-card);
  background: var(--card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.week-col.today {
  box-shadow: 0 0 0 2px var(--blue), var(--shadow-card);
}

.week-col.past {
  opacity: .6;
}

.week-col-head {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.week-col-weekday {
  display: block;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  text-transform: capitalize;
}

.week-col-caption {
  display: block;
  margin-top: 2px;
  color: var(--hint);
  font-size: 12.5px;
}

.week-col-body {
  display: grid;
  gap: 6px;
  padding: 0 10px 12px;
}

.week-block {
  display: block;
  min-width: 0;
  border: 0;
  border-radius: 12px;
  padding: 8px 10px;
  background: var(--surface-soft);
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}

.week-block strong,
.week-block span,
.week-block em {
  display: block;
}

.week-block strong {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
}

.week-block span {
  margin-top: 1px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.week-block em {
  margin-top: 1px;
  font-style: normal;
  font-size: 11.5px;
  color: var(--hint);
}

.week-block-lesson.requested {
  border-left: 3px solid var(--amber);
}

.week-block-lesson.booked {
  border-left: 3px solid var(--blue);
}

.week-block-lesson.proposed {
  border-left: 3px dashed var(--blue);
}

/* Свободное/закрытое время в неделе - блоками только на широком экране. */
.week-block-free,
.week-block-closed {
  display: none;
}

/* Шкала часов слева от недели - только на широком экране, на телефоне
   разметка та же, но список без абсолютного позиционирования (п.2). */
.week-hour-ruler {
  display: none;
}

/* Широкий экран (F2, п.3): семь колонок, время - позицией внутри колонки.
   Отдельный блок от широкой раскладки кабинета (ниже, F4) - здесь только
   календарь. */
@media (min-width: 900px) {
  .week-grid {
    grid-template-columns: 40px repeat(7, 1fr);
    align-items: start;
  }

  /* F8, важно: без подписей часов пустое место рядом со свободными блоками
     было ничем не подписано - час можно было узнать только по карточке
     занятия. Колонка выровнена по той же высоте и шкале минут, что и день
     (--week-start-min/--week-end-min), сдвиг верха на 36px - под шапку дня
     (.week-col-head), чтобы 00:00 подписи стояли вровень с телом колонки. */
  .week-hour-ruler {
    display: block;
    position: relative;
    top: 36px;
    height: calc((var(--week-end-min) - var(--week-start-min)) * 1px);
    min-height: 120px;
  }

  .week-hour-ruler span {
    position: absolute;
    right: 8px;
    left: 0;
    top: calc((var(--start-min) - var(--week-start-min)) * 1px);
    transform: translateY(-50%);
    font-size: 11px;
    color: var(--hint);
    text-align: right;
    white-space: nowrap;
  }

  .week-col-body {
    position: relative;
    height: calc((var(--week-end-min) - var(--week-start-min)) * 1px);
    min-height: 120px;
    padding: 0 4px 4px;
    overflow-y: auto;
  }

  .week-block {
    position: absolute;
    left: 4px;
    right: 4px;
    top: calc((var(--start-min) - var(--week-start-min)) * 1px);
    height: calc(var(--dur-min) * 1px);
    padding: 4px 8px;
    overflow: hidden;
  }

  .week-block-free,
  .week-block-closed {
    display: block;
  }

  /* Область свободного времени видна всегда (по ней сразу понятно, где
     есть окно), а вот сам "+" проступает только при наведении - иначе на
     каждой пустой минуте всей недели висел бы плюсик. */
  .week-block-free {
    border: 1.5px dashed color-mix(in srgb, var(--ok) 45%, transparent);
    background: var(--ok-bg);
    color: transparent;
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    transition: color .15s;
  }

  .week-block-free:hover,
  .week-block-free:focus-visible {
    color: var(--ok);
  }

  .week-block-closed {
    background: repeating-linear-gradient(
      45deg,
      color-mix(in srgb, var(--danger) 12%, transparent),
      color-mix(in srgb, var(--danger) 12%, transparent) 6px,
      transparent 6px,
      transparent 12px
    );
    pointer-events: none;
  }
}

/* --- Часы работы ----------------------------------------------------------- */

.hours-list {
  display: grid;
  /* Без явной колонки грид сам выбирает единственную неявную auto-колонку,
     а она растет до max-content своих строк (сумма двух не сжимаемых по
     природе <input type="time">), даже если у самого .hours-list есть
     только 354px реального места (У2). minmax(0, 1fr) - явный резиновый
     трек: он растягивается на реальную доступную ширину, а не на
     предпочитаемую ширину содержимого. */
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}

.hours-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: 13px;
  background: var(--surface-soft);
  /* Сама строка - тоже грид-элемент своего родителя (.hours-list); без
     min-width: 0 ее собственный min-content (два нерезиновых <input
     type="time">) раздувал бы ширину строки, даже если ее СОБСТВЕННЫЕ
     колонки внутри ниже готовы сжаться (У2). */
  min-width: 0;
}

.hours-row.off {
  opacity: .55;
}

.hours-toggle {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--blue-d);
  font-weight: 800;
  cursor: pointer;
}

.hours-toggle.on {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.hours-name {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hours-time {
  /* Ширина с запасом: на телефоне с 24-часовым форматом сюда встает «15:00»,
     а на 12-часовом - «03:00 PM», и оно не должно обрезаться. */
  width: 104px;
  min-height: 38px;
  padding: 6px 6px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  color: var(--text);
  font-size: 13.5px;
}

.hours-time:disabled {
  opacity: .5;
}

.fact .compact-button {
  /* Было 32px - меньше порога тап-таргета в 40px (B4, ночь 5): по кнопке
     "Подходит" в строке предложенного времени трудно попасть пальцем. */
  min-height: 40px;
  padding: 6px 12px;
  font-size: 12.5px;
}

/* Узкий экран: строка дня разворачивается в две. Сверху галочка и название,
   снизу два поля времени поровну. Прежняя версия загоняла поле «с» в колонку
   шириной 30 пикселей - на телефоне вместо времени была полоска, а поле «до»
   растягивалось на всю строку. Раскладку задаем явно, не полагаясь на
   автоматическое размещение: оно и было причиной. */
@media (max-width: 430px) {
  .hours-row {
    /* Было "1fr 1fr" - у голого fr трек минимально не уже, чем
       min-content своего <input type="time"> (тот же баг, что чинили
       для .app-header еще в ночь 5), и второе поле обрезалось краем
       экрана (У2). minmax(0, 1fr), как в базовой раскладке этой же
       строки выше - трек действительно сжимается до доступной ширины. */
    grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 8px;
    row-gap: 9px;
  }

  .hours-toggle {
    grid-column: 1 / 2;
    grid-row: 1;
  }

  .hours-name {
    grid-column: 2 / 4;
    grid-row: 1;
  }

  .hours-time {
    width: 100%;
    min-width: 0;
    grid-row: 2;
  }

  .hours-row .hours-time[data-role="start"] {
    grid-column: 2 / 3;
  }

  .hours-row .hours-time[data-role="end"] {
    grid-column: 3 / 4;
  }

  /* "Ближайшее занятие" (F8, важно): на телефонах уже 390px, до сих пор
     стек ломался только ниже 360px. Колонка даты (1fr) делит место с
     колонкой времени (auto, nowrap) - длинная дата "среда, 16 сентября"
     переносилась на три строки и выглядела как сломанная верстка (см.
     student_01_home.png). Одна колонка - дата и время друг под другом,
     обе читаются целиком. */
  .next-card {
    grid-template-columns: 1fr;
  }

  .next-card .next-time {
    text-align: left;
  }
}

.floating-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.floating-row .primary-button {
  display: flex;
  align-items: center;
  gap: 7px;
}

.stats-line {
  margin: 12px 2px 0;
  color: var(--hint);
  font-size: 12px;
  text-align: center;
}

/* P1.5: "Сегодня" - одна строка про следующее занятие и одна про свободное
   время, обе не карточки, а компактный текст между блоками. */
.next-lesson-line {
  margin: 2px 2px 0;
  color: var(--hint);
  font-size: 13px;
  text-align: left;
}

.free-today-line {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--blue);
  font-size: 12.5px;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}

/* --- Нижнее меню --------------------------------------------------------- */

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 560px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 8px 10px calc(9px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 95%, transparent);
  backdrop-filter: blur(20px);
}

.bottom-nav.four {
  grid-template-columns: repeat(4, 1fr);
}

.bottom-nav.three {
  grid-template-columns: repeat(3, 1fr);
}

.bottom-nav.five {
  grid-template-columns: repeat(5, 1fr);
}

.bottom-nav.five .nav-label {
  font-size: 10px;
}

/* Просроченная домашка. Красной заливки нет намеренно: это напоминание, а не
   выговор - ученик и так знает, что не успел. */
.lesson-card.overdue {
  border-left: 3px solid var(--amber);
}

.overdue-text {
  color: var(--amber);
  font-weight: 600;
}

.hint-text {
  color: var(--hint);
  font-size: 12.5px;
}

.nav-button {
  position: relative;
  min-height: 52px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--hint);
  cursor: pointer;
  transition: .15s;
}

.ui-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
}

.icon-button .ui-icon {
  width: 21px;
  height: 21px;
  flex: 0 0 21px;
}

.mark-icon {
  width: 32px;
  height: 32px;
}

.nav-button .nav-icon {
  width: 22px;
  height: 22px;
  color: var(--hint);
}

.nav-button.active .nav-icon {
  color: var(--blue);
}

.nav-button .nav-label {
  font-size: 11px;
}

.nav-button.active {
  background: var(--blue-l);
  color: var(--blue-d);
  font-weight: 600;
}

.nav-badge {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 6px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--amber);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

/* --- Нижний лист --------------------------------------------------------- */

.sheet-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(16, 26, 48, .5);
  animation: fade-in .18s ease-out;
}

.bottom-sheet {
  width: min(100%, 560px);
  max-height: min(88vh, 800px);
  overflow-y: auto;
  padding: 20px 18px calc(22px + var(--safe-bottom));
  border-radius: 24px 24px 0 0;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sheet);
  animation: sheet-in .22s ease-out;
}

.sheet-handle {
  width: 42px;
  height: 4px;
  margin: -8px auto 16px;
  border-radius: 999px;
  background: var(--line);
}

.bottom-sheet h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.bottom-sheet > p {
  margin: 0 0 14px;
  color: var(--hint);
  font-size: 13.5px;
}

.sheet-summary {
  margin: 14px 0;
  padding: 14px;
  border-radius: var(--radius-card);
  background: var(--blue-l);
}

.sheet-summary strong,
.sheet-summary span {
  display: block;
}

.sheet-summary strong {
  color: var(--blue-d);
}

.sheet-summary span {
  margin-top: 4px;
  color: var(--hint);
  font-size: 13px;
}

.fact-list {
  margin: 14px 0;
  border-radius: var(--radius-card);
  background: var(--surface-soft);
  overflow: hidden;
}

/* Код входа в кабинет в браузере без telegram.org (B3a) - крупно, чтобы
   ввести руками на другом устройстве без ошибок. */
.web-login-code {
  margin: 10px 0 2px;
  text-align: center;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 6px;
}

.fact {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

.fact:last-child {
  border-bottom: 0;
}

.fact span {
  /* C6 п.1/4: `flex-shrink: 0` не давал строке сжаться и перенестись, если
     весь текст (не только короткая метка) лежит в `<span>` без пары
     `<strong>` рядом (плейсхолдеры вида "Тем пока нет...", строка домашки
     с кнопкой) - на узкой карточке это раздувало `.fact` за ширину экрана. */
  flex: 0 1 auto;
  color: var(--hint);
  font-size: 12.5px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.fact strong {
  font-weight: 600;
  text-align: right;
  /* Длинное слово без пробелов (например, в комментарии заявки) иначе
     раздувает строку `.fact` за карточку - без flex/min-width строка не
     сжимается, а overflow-wrap без них не за что "цепляться". */
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.sheet-actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.sheet-actions.two {
  grid-template-columns: 1fr 1fr;
}

.sheet-actions > button {
  width: 100%;
}

.weekday-picker {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.weekday-picker button {
  min-width: 0;
  min-height: 42px;
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--hint);
  font-weight: 600;
  cursor: pointer;
}

.weekday-picker button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.success-icon {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: 0 auto 13px;
  border-radius: 21px;
  background: var(--ok-bg);
  color: var(--ok);
  font-size: 28px;
}

.centered {
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 150;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--card);
  box-shadow: 0 10px 30px rgba(16, 26, 48, .3);
  font-size: 13.5px;
  text-align: center;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(28px);
    opacity: .4;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

@media (min-width: 620px) {
  body {
    padding: 16px 0;
  }

  .app-shell {
    min-height: calc(100vh - 32px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(36, 68, 140, .16);
  }

  .app-header {
    border-radius: 0;
  }

  .bottom-nav {
    bottom: 16px;
    border-radius: 0 0 28px 28px;
  }
}

@media (max-width: 360px) {
  :root {
    --gutter: 12px;
  }

  .app-main {
    padding-inline: var(--gutter);
  }

  .slot-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .next-card {
    grid-template-columns: 1fr;
  }

  .next-card .next-time {
    text-align: left;
  }

  .lesson-main,
  .request-main {
    grid-template-columns: auto 1fr;
  }

  .lesson-main .status-badge,
  .request-main .status-badge {
    grid-column: 2;
    justify-self: start;
  }
}


/* --- Родная кнопка Telegram ---------------------------------------------- */

/* Когда доступна MainButton, свою дублирующую кнопку убираем: две одинаковые
   кнопки на экране - это вопрос «а какая настоящая». Разметку оставляем,
   потому что на старом клиенте родной кнопки может не быть вовсе. */
body.has-main-button [data-main] {
  display: none;
}

body.has-main-button .bottom-sheet {
  padding-bottom: 16px;
}

/* --- Подсказка о часовом поясе ------------------------------------------- */

.tz-hint {
  margin: 10px 2px 0;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--blue-l);
  color: var(--blue-d);
  font-size: 12.5px;
  line-height: 1.45;
}

/* --- Быстрый выбор ближайшего времени ------------------------------------ */

.quick-row {
  display: flex;
  gap: 8px;
  margin: 0 0 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick-row::-webkit-scrollbar {
  display: none;
}

.quick-chip {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 8px 14px;
  border: 1.5px solid var(--blue);
  border-radius: var(--radius-pill);
  background: var(--card);
  color: var(--blue-d);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.quick-chip strong {
  display: block;
  font-size: 14px;
}

.quick-chip span {
  display: block;
  color: var(--hint);
  font-size: 11px;
  font-weight: 500;
}

/* --- Домашка 1.12.0: выбор нескольких учеников --------------------------- */
.pick-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding: 2px;
}

.pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  cursor: pointer;
}

.pick-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--blue);
  flex: none;
}

.pick-row:has(input:checked) {
  border-color: var(--blue);
}

/* 1.12: поиск в списке учеников */
.search-field { margin: 0 0 10px; }
.search-field input { width: 100%; }
.student-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 0; }

/* Длинные статусы ("не приглашен", "доступ отозван") не сужают карточку на
   узком экране (B4, ночь 5) - переносятся внутри своей же таблетки вместо
   того, чтобы раздувать колонку бейджей шире доступного места. */
.student-badges .status-badge {
  white-space: normal;
  text-align: center;
  max-width: 96px;
}
.filter-row.searching .filter-chip.active { border-color: var(--line, #dfe6f3); background: var(--card); color: var(--hint); box-shadow: none; }

/* 1.13.0: карта тем и оценки */
.topic-counts { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.topic-count { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--card); color: var(--hint); }
.topic-row { align-items: center; gap: 10px; }
.topic-badge { flex: none; border: 0; font: inherit; font-size: 12px; font-weight: 700; padding: 6px 11px; border-radius: 999px; white-space: nowrap; cursor: default; }
button.topic-badge { cursor: pointer; }
.topic-repeat { background: #fdecd8; color: #9a4a00; }
.topic-learning { background: #e3ecff; color: #1f4fd1; }
.topic-planned { background: #eef1f6; color: #5b6475; }
.topic-mastered { background: #dff5e7; color: #1c7a43; }
.filter-row.wrap { flex-wrap: wrap; overflow: visible; }
.marks-chart { display: flex; align-items: flex-end; gap: 6px; height: 110px; padding: 12px 12px 8px; border-radius: var(--radius-card); background: var(--card); box-shadow: var(--shadow-card); }
.mark-bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.mark-bar span { width: 100%; max-width: 26px; border-radius: 6px 6px 3px 3px; background: var(--blue); opacity: .85; }
.mark-bar em { font-style: normal; font-size: 11px; font-weight: 700; color: var(--hint); }
.topic-title { color: var(--text, inherit); font-weight: 600; }

/* Финансы (1.15.0): полоска оплаты абонемента и таблица «Доходы» - без
   библиотек графиков, просто CSS-полоски, как марки в .mark-bar выше. */
.pkg-bar { height: 6px; border-radius: 999px; background: var(--line); margin: 4px 14px 10px; overflow: hidden; }
.pkg-bar-fill { height: 100%; border-radius: 999px; background: var(--blue); }
/* Деньги 2.0 (E2, ночь 8): полоса делений абонемента - одно занятие, одно
   деление, использованные закрашены (задание п.4 «Осталось 3 из 8»). */
.pkg-blocks { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 14px 10px; }
.pkg-block { width: 14px; height: 8px; border-radius: 3px; background: var(--line); }
.pkg-block.used { background: var(--blue); }
.ledger-row { display: flex; justify-content: space-between; gap: 8px; }
.ledger-row.reversed { opacity: .5; text-decoration: line-through; }
.income-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.income-table th, .income-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); }
.income-table thead th {
  color: var(--hint);
  font-weight: 600;
  font-size: 12px;
  /* Заголовки липкие (F3 п.6) - таблица за год длиннее одного экрана,
     подписи столбцов должны быть видны при прокрутке. */
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}
.income-table tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }

/* Явка по неделям (C2): 12 клеток высотой в долю явки за неделю - тот же
   принцип полоски, что и .pkg-bar, без библиотек графиков. */
.att-weeks { display: flex; align-items: flex-end; gap: 3px; height: 28px; margin: 6px 14px 10px; }
.att-week { flex: 1; min-width: 4px; border-radius: 2px; background: var(--blue); opacity: 0.85; }

/* Карточка ученика заново (F3 п.1): разделы-раскрышки поверх обычных
   `<details>` - по умолчанию одна колонка и порядок как в разметке; на
   широком экране колонки разводит только правило внутри
   `@media (min-width: 900px)` ниже. */
.student-sheet-grid { display: block; margin-top: 8px; }
.ss-col { display: block; }
.details-section {
  border-top: 1px solid var(--line);
  padding: 6px 0 4px;
}
.details-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 2px;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.details-section > summary::-webkit-details-marker { display: none; }
.details-section > summary::after {
  content: "▾";
  color: var(--hint);
  transition: transform .15s ease;
}
.details-section[open] > summary::after { transform: rotate(180deg); }

/* =========================================================================
   Широкая раскладка (E5, ночь 8). Кабинет в браузере на большом экране -
   тот же код, те же данные, те же маршруты, другая верстка. Ниже 900px
   ничего не меняется: все правила этого раздела - только внутри
   `@media (min-width: 900px)`, кроме `.logout-button` (новый элемент,
   которого раньше не было вовсе - по умолчанию скрыт, виден только тут).
   ========================================================================= */

.logout-button { display: none; }

@media (min-width: 900px) {

  body { padding: 0; font-size: 16px; }

  /* Кнопка входа по коду и «оболочка без вкладок» (роль еще не известна,
     `.bottom-nav` стоит `hidden`) занимают всю ширину без бокового меню -
     карточка входа по центру, а не растянутая форма. */
  .app-shell:has(.bottom-nav[hidden]) {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main";
  }

  .app-shell:has(.bottom-nav[hidden]) .app-main {
    display: grid;
    place-items: start center;
  }

  .error-screen {
    max-width: 460px;
    margin: 48px auto 0;
    padding: 40px 36px;
    border-radius: 24px;
    background: var(--card);
    box-shadow: 0 20px 60px rgba(36, 68, 140, .16);
  }

  /* Оболочка: боковое меню слева + шапка и контент справа, вместо колонки
     на весь монитор шириной с телефон. Селектор по id, а не по классу:
     в браузере без Telegram `tg-shim.js` дописывает в `<head>` свой
     `<style>.app-shell{max-width:480px}` (именно телефонная раскладка,
     которую этот блок и меняет) - он приходит позже нашего файла, и
     обычный класс той же специфичности проиграл бы ему по порядку. */
  #app-shell {
    width: min(100%, 1440px);
    max-width: none;
    min-height: 100vh;
    margin: 0 auto;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    display: grid;
    /* minmax(0, 1fr), не голый 1fr: F7 п.2 (проверка ровно на границе
       900px) поймала, что список учеников не влезал в узкую сторону
       широкой раскладки (на 1280px хватало места и с трека auto, на самой
       границе - нет) и раздувал весь #app-shell вбок, утаскивая шапку и
       кнопку "Выйти" за край экрана - тот же баг min-width:auto, что и в
       .inline-actions выше. */
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "nav header" "nav main";
    align-items: start;
  }

  .app-header {
    grid-area: header;
    border-radius: 0 0 20px 20px;
  }

  /* Раньше это был квадрат 42×42 с одним символом "⎋" - на широком экране
     выглядел обрезанным. Обычная кнопка с подписью, той же высоты, что и
     круглая "Обновить" рядом (F4 п.5). */
  .logout-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    height: 42px;
    padding: 0 18px;
    border: 0;
    border-radius: 14px;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    font: 600 14px -apple-system, system-ui, sans-serif;
    white-space: nowrap;
    cursor: pointer;
  }

  .logout-button:hover { background: rgba(255, 255, 255, .28); }

  /* Плавающая "← Назад" (tg-shim.js, обычный браузер без Telegram) на
     широком экране не нужна - "назад" здесь боковое меню слева, всегда
     видное. Сама кнопка - не часть .app-shell, добавляется в document.body
     напрямую, поэтому прячем по id, а не по вложенности (F4 п.5). */
  #tg-back-button { display: none !important; }

  .app-main {
    grid-area: main;
    min-height: auto;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 40px 56px;
  }

  /* Нижний таб-бар -> боковое меню: те же кнопки (иконка, подпись, бейдж),
     просто в столбик и во всю высоту экрана вместо строки внизу. */
  .bottom-nav {
    grid-area: nav;
    position: sticky;
    top: 0;
    left: auto;
    bottom: auto;
    transform: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    height: 100vh;
    gap: 4px;
    padding: 24px 14px;
    border-top: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    backdrop-filter: none;
  }

  .bottom-nav.four,
  .bottom-nav.three,
  .bottom-nav.five {
    grid-template-columns: none;
  }

  .nav-button {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    min-height: 46px;
    padding: 0 14px;
  }

  .nav-button:hover {
    background: var(--surface-soft);
  }

  .nav-button .nav-label {
    font-size: 14px;
  }

  .nav-badge {
    position: static;
    top: auto;
    left: auto;
    margin-left: auto;
  }

  /* Шторки (`openSheet`) - модальное окно по центру с затемнением, а не
     панель снизу. Карточка ученика (форма `#student-form` внутри) - особый
     случай: список остается виден и кликабелен слева, карточка стоит
     справа отдельной панелью, без перехода на отдельный экран. */
  .sheet-overlay {
    align-items: center;
    padding: 32px;
  }

  .bottom-sheet {
    width: min(92vw, 640px);
    max-height: min(86vh, 760px);
    border-radius: 22px;
    animation: fade-in .18s ease-out;
  }

  .sheet-overlay:has(#student-form) {
    justify-content: flex-end;
    align-items: stretch;
    background: transparent;
    padding: 24px;
    pointer-events: none;
  }

  .sheet-overlay:has(#student-form) .bottom-sheet {
    pointer-events: auto;
    width: min(46vw, 620px);
    max-height: none;
    height: 100%;
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(16, 26, 48, .28);
  }

  /* Карточка ученика занимает правую колонку, а не перекрывает список
     (F4 п.5): список сужается ровно на ширину шторки + отступ и прижимается
     к боковому меню, вместо центрирования на всю ширину `.app-main`. Формула
     повторяет ширину `.bottom-sheet` выше - `#student-form` есть в DOM,
     только пока шторка открыта (`closeSheet` чистит `innerHTML`). */
  body:has(#student-form) .app-main {
    max-width: min(1200px, calc(100vw - 240px - min(46vw, 620px) - 24px));
    margin: 0;
  }

  /* Имя ученика - одна строка с многоточием, а не перенос на 2-3 строки:
     при суженном списке длинное имя ("Константинопольская-Щербатова...")
     иначе распирало бы строку по высоте. `minmax(0, 1fr)` обязателен -
     обычный `1fr` не разрешает колонке сжаться меньше текста внутри
     (`overflow:hidden` на h3 без этого не сработает, см. ловушку с
     min-width:auto у grid-элемента). */
  .student-list .student-main h3 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body:has(#student-form) .student-list .student-main {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  /* Списки карточками -> таблица: те же строки, без отдельных теней и
     скруглений у каждой, числа выровнены вправо моноширинными цифрами. */
  .student-list,
  .request-list,
  .lesson-list {
    gap: 0;
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: var(--shadow-card);
  }

  .student-list .student-card,
  .request-list .request-card,
  .lesson-list .lesson-card {
    border-radius: 0;
    box-shadow: none;
    border-bottom: 1px solid var(--line);
    transition: background-color .12s;
  }

  .student-list .student-card:last-child,
  .request-list .request-card:last-child,
  .lesson-list .lesson-card:last-child {
    border-bottom: 0;
  }

  .student-card:hover,
  .request-card:hover,
  .lesson-card:hover,
  .agenda-item:hover {
    background: var(--surface-soft);
    cursor: pointer;
  }

  .fact:hover {
    background: var(--surface-soft);
  }

  .fact strong,
  .sheet-summary strong,
  .income-table td {
    font-variant-numeric: tabular-nums;
  }

  .income-table td:not(:first-child),
  .income-table th:not(:first-child) {
    text-align: right;
  }

  /* Видимая рамка фокуса - клавиатурная навигация по широкому экрану. */
  a:focus-visible,
  button:focus-visible,
  input:focus-visible,
  textarea:focus-visible,
  select:focus-visible,
  .nav-button:focus-visible,
  .student-card:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
  }

  /* Карточка ученика (F3 п.1, У3): сводка и "Занятия"/"Деньги" слева,
     остальные разделы справа - только раскладка, разметка и данные те же.
     Сама колонка - отдельный `@media` ниже (F7 п.2, порог 1050px, а не
     900px): карточка живет в шторке шириной `min(46vw, 620px)`, и ровно на
     границе 900px это 414px - тесно для двух колонок, текст переносился
     по одному-два слова в строке. */
}

@media (min-width: 1050px) {
  .student-sheet-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 32px;
    align-items: start;
  }
}
