:root {
  --brand: #2f6fed;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --danger: #d92d20;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --navbar: 58px;
  --income: #0a7a3d;
}

/* Любой авторский display перекрывает стиль браузера для hidden — и уже перекрыл
   его у слоя кнопок (.actions с display: flex). Одно правило на всё приложение. */
[hidden] { display: none !important; }

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Только на корне. На <body> эта же пара убивала прокрутку: overflow-x делает body
   собственным (нечего прокручивать) контейнером прокрутки, а overscroll-behavior
   запрещает передать прокрутку выше — колесо и палец не двигали ничего, хотя
   window.scrollTo работал. Корень отдаёт overflow области просмотра, и она едет. */
html {
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* Замок PIN'а — на корне: прокручивается область просмотра, и её overflow
   берётся у <html>. core.js помечает классом и body — на вид это ничего не
   меняет, замок даёт одна эта строка. */
html.locked { overflow: hidden; }

#screens {
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--navbar) + var(--safe-bottom) + 24px);
  min-height: 100vh;
}

.screen { display: none; transition: transform .18s ease; }
.screen.active { display: block; }
.screen.bounce-left { transform: translateX(-14px); }
.screen.bounce-right { transform: translateX(14px); }

.screen-head h1 { font-size: 24px; margin: 4px 0 16px; }

.placeholder {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.muted { color: var(--muted); }
.error { color: var(--danger); }

#navbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  backdrop-filter: blur(10px);
  z-index: 20;
}

#navbar .tab {
  flex: 1;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  padding: 7px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#navbar .tab svg { width: 24px; height: 24px; fill: currentColor; }
#navbar .tab.active { color: var(--brand); }

#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  opacity: 0;
  transition: opacity .2s ease;
  z-index: 30;
}
#sheet-backdrop.open { opacity: 1; }

#sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 20px);
  transform: translateY(100%);
  transition: transform .22s ease;
  z-index: 31;
}
#sheet.open { transform: translateY(0); }

#sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 4px auto 8px;
}

#sheet header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
#sheet header h2 { font-size: 17px; margin: 0; }
#sheet-cancel {
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  padding: 6px 0;
}
#sheet-body { padding-top: 12px; }

#toast {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(var(--navbar) + var(--safe-bottom) + 16px);
  background: #16181d;
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
  opacity: 0;
  transition: opacity .2s ease;
  z-index: 40;
}
#toast.show { opacity: .96; }

#pin {
  position: fixed;
  inset: 0;
  background: var(--bg);
  padding: calc(var(--safe-top) + 12vh) 24px calc(var(--safe-bottom) + 24px);
  z-index: 50;
}

#pin h1 { font-size: 28px; margin: 0 0 8px; }
#pin form { display: flex; flex-direction: column; gap: 12px; }

#pin input {
  font-size: 22px;
  letter-spacing: 6px;
  text-align: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

#pin button {
  font: inherit;
  font-size: 17px;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
}

#install-hint { margin-top: 28px; color: var(--muted); }
#install-hint summary { color: var(--brand); }
#install-hint ol { padding-left: 20px; line-height: 1.6; }

/* 02 — главный экран «Сегодня» и формы дохода/расхода */

.today-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav h1 { font-size: 22px; margin: 0; min-width: 140px; text-align: center; }
.month-arrow {
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  font-size: 26px;
  line-height: 1;
  padding: 4px 10px;
}

.link-btn { border: 0; background: none; color: var(--brand); font: inherit; padding: 6px 0; }
.small { font-size: 13px; }

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fdecea;
  color: var(--danger);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.banner .link-btn { color: var(--danger); font-weight: 600; white-space: nowrap; }
.banner .small { display: block; margin-top: 2px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.totals { display: flex; gap: 8px; margin-bottom: 14px; }
.totals .total {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 8px;
  text-align: center;
}
.totals .total span { display: block; color: var(--muted); font-size: 12px; }
.totals .total b { font-size: 17px; white-space: nowrap; }
.totals .total b.minus { color: var(--danger); }

.section-title { font-size: 15px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }

.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.feed-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.feed-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.feed-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; white-space: nowrap; }
.feed-side b.income { color: #0a7a3d; }
.feed-side b.expense { color: var(--danger); }
.feed-side .link-btn { font-size: 13px; }
.feed-empty { text-align: center; }

.actions {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--navbar) + var(--safe-bottom) + 10px);
  display: flex;
  gap: 10px;
  z-index: 10;
}
.actions .big {
  flex: 1;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  padding: 16px 8px;
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .16);
}
.actions .big.income { background: #0a7a3d; }
.actions .big.expense { background: var(--danger); }

#screen-today .feed { padding-bottom: 76px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form .field { display: flex; flex-direction: column; gap: 6px; }
.form .field > span { color: var(--muted); font-size: 13px; }
.form input, .form select {
  font: inherit;
  font-size: 17px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  width: 100%;
}
.form .field-error { color: var(--danger); font-size: 13px; margin: 0; }
.form .submit {
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  padding: 15px;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  margin-top: 4px;
}
.form .submit:disabled { opacity: .6; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* 05 */
#screen-report .chips { margin-bottom: 12px; }
#report-range { margin: 0 0 12px; }

.report-dates { margin-bottom: 14px; }
.report-dates .field { flex-direction: row; align-items: center; gap: 10px; }
.report-dates .field > span { width: 18px; }
.report-dates .submit { margin-top: 0; }

.split {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.split:first-child { padding-top: 0; }
.split:last-child { padding-bottom: 0; border-bottom: 0; }
.split .name { overflow-wrap: anywhere; }
.split b { white-space: nowrap; }
.split b.minus { color: var(--danger); }
.debts-total span { color: var(--muted); }

/* 04 — ученики, карточка, баннер оболочки */

.app-banner {
  position: fixed;
  left: 12px; right: 12px;
  top: calc(var(--safe-top) + 8px);
  z-index: 40;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}

.students-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
#students-search {
  flex: 1;
  font: inherit;
  font-size: 17px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.students { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.student { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.student-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.student-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Одни и те же классы для слов («предоплата 4 000 ₽») и для числа со знаком
   («+4 000 ₽») — цвет и начертание цифр одинаковы в списке, слоте и карточке. */
.debt { color: var(--danger); font-size: 14px; }
.prepaid { color: var(--income); font-size: 14px; }
.debt, .prepaid { font-variant-numeric: tabular-nums; white-space: nowrap; }

.student-card { display: flex; flex-direction: column; gap: 10px; }
.card-state { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card-state .card-name { font-size: 20px; margin-right: auto; }
.card-state span { color: var(--muted); font-size: 14px; }
.card-body { display: flex; flex-direction: column; gap: 10px; }
.card-body .field { display: flex; flex-direction: column; gap: 4px; }
.card-body .field > span { color: var(--muted); font-size: 13px; }
.card-body input, .card-body textarea {
  font: inherit;
  font-size: 17px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  width: 100%;
  resize: none;
}
.card-body .link-btn { align-self: flex-start; }

.card-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 0 2px;
  background: var(--card);
}
.card-actions .big {
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
}
.card-actions .big.income { background: var(--brand); border-color: var(--brand); color: #fff; }
.card-actions .big.debt-btn { color: var(--danger); border-color: var(--danger); }
.card-actions .big:disabled { opacity: .6; }
.card-amount {
  font: inherit;
  font-size: 17px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 100%;
}

.entry-card { display: flex; flex-direction: column; gap: 6px; }
.entry-card .entry-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.entry-card a.link-btn { align-self: flex-start; text-decoration: none; }

/* 06 */
.schedule-today { display: flex; flex-direction: column; gap: 8px; }
.slots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.slot {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.slot-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 52px; }
.slot-name { flex: 1; }
.slot-state { text-align: right; white-space: nowrap; }
.slot.unknown .slot-name { color: var(--muted); }

/* Day strip: seven equal columns. At 320 px that leaves 36 px per button, so the row
   never wraps and the page never scrolls sideways. Not .chip: that style is shared by
   the forms and «Отчёт», and its rhythm is a line where this one is a column. */
.days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}
.day {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 2px;
  border: 0;
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
}
.day-name { font-size: 12px; line-height: 14px; color: var(--muted); }
.day-num { font-size: 21px; line-height: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
/* The dot always keeps its place: hidden would drop it out of flow and buttons without a
   schedule would end up shorter. visibility hides it here — an exception to the rule. */
.day-dot {
  width: 5px;
  height: 5px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--brand);
  visibility: hidden;
}
.day-dot.on { visibility: visible; }
.day.active { background: var(--brand); color: #fff; }
.day.active .day-name { color: #fff; }
.day.active .day-dot { background: #fff; }
#schedule-add { margin-top: 12px; }

/* 08 */
.confirm { display: flex; flex-direction: column; gap: 10px; }
.confirm p { margin: 0 0 4px; font-size: 17px; }
.confirm .big {
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
}
.confirm .big.danger { border-color: var(--danger); color: var(--danger); }

/* 04 */
.pick { display: flex; align-items: center; gap: 8px; }
.pick .grow, .pick > input { flex: 1; min-width: 0; }
.pick .grow > select { width: 100%; }
.plus {
  flex: none;
  width: 46px;
  height: 46px;
  font: inherit;
  font-size: 26px;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--brand);
}
.state-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.check { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.check input { width: 22px; height: 22px; flex: none; }
.settle-row { display: flex; flex-wrap: wrap; gap: 10px; }
.settle-row .submit { flex: 1; margin-top: 0; }
.settle-row .submit.ghost {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
}
.settle-row .hint { flex-basis: 100%; margin: 0; color: var(--danger); font-size: 14px; }
.mini { display: flex; flex-direction: column; gap: 12px; }
.card-name.dup { color: var(--danger); }
.card-actions .big.danger { border-color: var(--danger); color: var(--danger); }
.entry-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 2px 0 4px;
}
.entry-numbers span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--muted);
  font-size: 13px;
}
.entry-numbers b { color: var(--text); font-size: 16px; white-space: nowrap; }
.entry-card .big {
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  padding: 14px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
}
.entry-card .big.danger { border-color: var(--danger); color: var(--danger); }

/* 05 */
.screen-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.screen-head h1 { margin-bottom: 12px; }
.slot.done { opacity: .55; }
.slot-name.dup { color: var(--danger); }
.slot-state {
  white-space: normal;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: baseline;
  gap: 2px 8px;
}
.slot-state > span { white-space: nowrap; }
/* Состояние слота «Сегодня» рисует общая SF.forms.stateHtml, и своих классов
   размера у неё нет: размер и начертание задаёт контейнер, как в списке учеников. */
.schedule-today .slot-state { font-size: 14px; }
.schedule-today .slot-state > span, .schedule-today .slot-state > b { font-weight: 400; }
.slot-check { color: #0a7a3d; font-weight: 700; }
.student-state {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: baseline;
  gap: 2px 8px;
  font-size: 14px;
  color: var(--muted);
  text-align: right;
}
.student-state > span, .student-state > b { white-space: nowrap; font-weight: 400; }
.student.dup .student-main b { color: var(--danger); }
.student.unknown .student-main b { color: var(--muted); }

/* 01 — общие куски для форм и расписания (используют таски 02 и 03) */

/* Поле с крестиком: обёртка вокруг <input>, кнопка «×» внутри справа.
   Видимость — только классом `filled` на обёртке; ставит и снимает его
   SF.forms.wireClears(root) из forms.js — вне его разметка будет без поведения. */
.clearable { position: relative; display: block; }
/* Обёртка часто стоит прямым потомком .field, где span — это подпись поля. */
.form .field > .clearable { color: inherit; font-size: inherit; }
.clearable > input { width: 100%; padding-right: 44px; }
.clearable > .clear {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 20px;
  line-height: 1;
  padding: 0;
}
.clearable.filled > .clear { display: flex; }

/* Кнопка «добавить слот»: карточка на всю ширину списка, высотой со слот. */
.slot-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: 17px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--brand);
}
.slot-add::before { content: "+"; font-size: 22px; line-height: 1; }
