/* Мини-приложение: вид. Цвета — только var(--tg-theme-*), запасное — вторым аргументом var(). Вид как в iOS-эталоне:
   группы карточками section_bg со скруглением 12 px на фоне secondary_bg; шрифт системный, 17 px основной, 15 px
   подсказки; нажимаемое ≥ 44 px, строка списка ≥ 56 px, поля по краям 16 px. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f0f0f4);
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #007aff);
  --btn: var(--tg-theme-button-color, #007aff);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --accent: var(--tg-theme-accent-text-color, var(--tg-theme-link-color, #007aff));
  --head: var(--tg-theme-section-header-text-color, var(--tg-theme-hint-color, #6d6d72));
  --bar: var(--tg-theme-bottom-bar-bg-color, var(--tg-theme-bg-color, #ffffff));
  --sep: var(--tg-theme-section-separator-color, color-mix(in srgb, var(--tg-theme-hint-color, #8e8e93) 35%, transparent));
  --soft: color-mix(in srgb, var(--tg-theme-hint-color, #8e8e93) 16%, transparent);
  --btn-soft: color-mix(in srgb, var(--tg-theme-button-color, #007aff) 14%, transparent);
  --shade: rgba(0, 0, 0, .4);   /* затемнение под листом в обеих темах (из цвета текста в тёмной было белым) */
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --tabbar-h: 56px;
  --mb-h: 0px;
  --radius: 12px;
  --gap: 16px;
}

body.has-mb { --mb-h: 50px; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Документ не прокручивается: его высота — окно приложения, прокручивается только #view. На iPhone прокрутку документа
   двигает и сам WKWebView (восстановление по истории после «Назад», инерция, клавиатура), и Telegram — от этого главная
   открывалась сдвинутой: пустое поле сверху, карточки внизу под панелью. Внутренний контейнер двигает только наш код. */
html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: var(--tg-viewport-stable-height, 100%);
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg2);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--btn); outline-offset: 2px; }
a { color: var(--link); }

.hint { color: var(--hint); font-size: 15px; }
.danger, .alert { color: var(--danger); }

/* ---- шапка ------------------------------------------------------------------------------- */
#top {
  position: relative;
  flex: none;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px var(--gap);
  background: var(--bg2);
}
#title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.back, .hdr-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--link);
  font-size: 17px;
  white-space: nowrap;
}
.back { margin-left: -4px; }
#hdr-action:empty { display: none; }

/* ---- содержимое -------------------------------------------------------------------------- */
#view {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 24px;
}
/* своя нижняя кнопка вне Telegram (#mainbtn, fixed) — под ней место, панель встаёт над ней */
body.has-mb { padding-bottom: calc(var(--mb-h) + var(--safe-bottom)); }
/* клавиатура открыта (фокус в поле на самом экране) — панель не висит над ней посреди экрана */
body.kb #tabbar { display: none; }
.route { padding-top: 4px; }

#loader {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  color: var(--hint);
  font-size: 17px;
  pointer-events: none;
}

.state { padding: 48px 24px 24px; text-align: center; }
.state-icon { font-size: 48px; line-height: 1; margin-bottom: 12px; }
.state-title { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.state-hint { margin: 0 0 20px; color: var(--hint); font-size: 15px; overflow-wrap: anywhere; }

/* ---- кнопки ------------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
}
.btn-primary { background: var(--btn); color: var(--btn-text); }
.btn-plain { background: var(--soft); color: var(--text); }
.btn-soft { background: var(--btn-soft); color: var(--link); }
.btn-danger { background: var(--danger); color: var(--btn-text); }
.btn-wide { display: flex; width: calc(100% - 2 * var(--gap)); margin: 0 var(--gap) var(--gap); }
.link-btn {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--link);
  font-size: 17px;
}

/* ---- группы и строки ---------------------------------------------------------------------- */
.group-title {
  margin: 20px calc(var(--gap) * 2) 8px;
  color: var(--head);
  font-size: 15px;
  font-weight: 400;
}
.group-title.alert { color: var(--danger); }
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 12px var(--gap) 4px calc(var(--gap) * 2);
}
.group-head .group-title { margin: 0; }
.group {
  margin: 0 var(--gap) var(--gap);
  background: var(--section);
  border-radius: var(--radius);
  overflow: hidden;
}
.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px var(--gap);
  background: var(--section);
  transition: opacity .15s;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: var(--gap);
  right: 0;
  border-top: 0.5px solid var(--sep);
}
.row.with-check { padding-left: 4px; }
.row.with-check + .row.with-check::before { left: 52px; }
button.row, a.row { width: 100%; border: 0; text-align: left; color: var(--text); text-decoration: none; font-size: 17px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; overflow-wrap: anywhere; }
.row-sub { color: var(--hint); font-size: 15px; overflow-wrap: anywhere; }
.row-meta { color: var(--hint); font-size: 15px; white-space: nowrap; }
.row-amount { font-weight: 600; white-space: nowrap; }
.row.alert .row-sub, .row .alert { color: var(--danger); }
.row.busy { opacity: .4; pointer-events: none; }
.row.done .row-title { color: var(--hint); text-decoration: line-through; }
.row-dots { flex: none; color: var(--hint); font-size: 20px; line-height: 1; letter-spacing: 1px; }
.row-chevron::after { content: "›"; color: var(--hint); font-size: 22px; line-height: 1; }
.row.selected { background: var(--btn-soft); }

.check {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
}
.check::before {
  content: "";
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid var(--hint);
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}
.check.on::before { content: "✓"; background: var(--btn); border-color: var(--btn); color: var(--btn-text); }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--btn-soft);
  color: var(--link);
  font-size: 15px;
  white-space: nowrap;
}

/* ---- ленты вкладок и фильтров: листаются вбок внутри себя ------------------------------------ */
.tabs, .chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 var(--gap) 12px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tab, .chip-btn {
  flex: none;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 22px;
  background: var(--section);
  color: var(--text);
  font-size: 15px;
  white-space: nowrap;
}
.tab.current, .chip-btn.current { background: var(--btn); color: var(--btn-text); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  margin: 0 var(--gap) 12px;
  padding: 2px;
  border-radius: 10px;
  background: var(--soft);
}
.segmented button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 15px;
}
.segmented button.current { background: var(--section); font-weight: 600; box-shadow: 0 0 0 0.5px var(--sep), 0 1px 3px rgba(0, 0, 0, .25); }

/* ---- счётчик, период, «ещё» ----------------------------------------------------------------- */
.counter { margin: 0 var(--gap) 12px; font-size: 15px; color: var(--hint); }
.counter b { color: var(--text); font-weight: 600; }
.progress { height: 6px; margin-top: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 3px; background: var(--btn); }

.period {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 var(--gap) 12px;
}
.period-label { flex: 1; text-align: center; font-weight: 600; }
.period button {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  background: var(--section);
  color: var(--link);
  font-size: 20px;
}
.period button:disabled { color: var(--hint); opacity: .5; }

.more { display: flex; justify-content: center; margin: 0 var(--gap) var(--gap); }
.cut-note { margin: 0 calc(var(--gap) * 2) var(--gap); color: var(--hint); font-size: 15px; }

/* ---- карточки (главная, разделы) ------------------------------------------------------------- */
.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 8px var(--gap);
  border: 0;
  background: var(--section);
  color: var(--text);
  text-align: left;
  font-size: 17px;
}
.card + .card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 68px;
  right: 0;
  border-top: 0.5px solid var(--sep);
}
.card-icon { flex: none; width: 40px; font-size: 28px; line-height: 1; text-align: center; }
.card-main { flex: 1; min-width: 0; }
.card-label { font-size: 17px; overflow-wrap: anywhere; }
.card-badge { color: var(--hint); font-size: 15px; overflow-wrap: anywhere; }
.card.alert .card-badge { color: var(--danger); }
/* значение переносится по словам и не шире 55 %: иначе длинное «2 открыто · 2 просрочено» сжимало подпись слева,
   и «Поручения» рвалось посреди слова */
.card-value { flex: 0 1 auto; max-width: 55%; font-weight: 600; text-align: right; overflow-wrap: break-word; }
.card.alert .card-value { color: var(--danger); }
.card::after { content: "›"; flex: none; color: var(--hint); font-size: 22px; line-height: 1; }
.card.static::after { content: none; }

/* ---- текст уровня А и HTML бота ------------------------------------------------------------- */
.tg-text {
  margin: 0 var(--gap) var(--gap);
  padding: 14px var(--gap);
  border-radius: var(--radius);
  background: var(--section);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tg-text pre, .tg-text code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 15px; }
.tg-text pre { margin: 6px 0; padding: 10px; border-radius: 8px; background: var(--soft); overflow-x: auto; white-space: pre; }
.tg-text code { padding: 0 3px; border-radius: 4px; background: var(--soft); }
.tg-text pre code { padding: 0; background: none; }
.tg-text blockquote { margin: 6px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--btn); }
.spoiler { border-radius: 4px; background: var(--hint); color: transparent; cursor: pointer; }
.spoiler.shown { background: none; color: inherit; }

.a-rows { display: flex; flex-direction: column; gap: 8px; margin: 0 var(--gap) var(--gap); }
.a-row { display: flex; gap: 8px; }
.a-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius);
  background: var(--section);
  color: var(--link);
  font-size: 15px;
  overflow-wrap: anywhere;
}

/* ---- таблицы: листаются вбок внутри себя ---------------------------------------------------- */
.table-wrap {
  margin: 0 var(--gap) var(--gap);
  border-radius: var(--radius);
  background: var(--section);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: 15px; }
.table-wrap th, .table-wrap td { padding: 10px 12px; text-align: right; white-space: nowrap; border-bottom: 0.5px solid var(--sep); }
.table-wrap th { color: var(--hint); font-weight: 600; background: var(--section); }
.table-wrap th:first-child, .table-wrap td:first-child { position: sticky; left: 0; z-index: 1; text-align: left; background: var(--section); }
.table-wrap thead th { position: sticky; top: 0; z-index: 2; }
.table-wrap thead th:first-child { z-index: 3; }
.table-wrap tfoot td { font-weight: 600; }

/* ---- поля ввода (≥ 16 px, иначе iOS увеличивает страницу) ----------------------------------- */
input, textarea, select { font-size: 17px; }
.search { margin: 0 var(--gap) 12px; }
.search input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--soft);
  color: var(--text);
}
.search input::placeholder { color: var(--hint); }

/* ---- слои: лист снизу, подтверждение -------------------------------------------------------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--shade);
  opacity: 0;
  transition: opacity .15s;
}
.backdrop.open { opacity: 1; }
.panel { width: 100%; max-height: calc(var(--tg-viewport-stable-height, 100vh) * .88); overflow-y: auto; overscroll-behavior: contain; }
.sheet-panel {
  padding: 8px 8px calc(8px + var(--safe-bottom) + var(--mb-h));
  border-radius: 14px 14px 0 0;
  background: var(--bg2);
}
.sheet-title { padding: 10px 16px 12px; color: var(--hint); font-size: 15px; text-align: center; overflow-wrap: anywhere; }
.sheet-list { border-radius: var(--radius); overflow: hidden; background: var(--section); }
.sheet-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
  border: 0;
  background: var(--section);
  color: var(--link);
  font-size: 17px;
}
.sheet-list .sheet-item + .sheet-item::before { content: ""; position: absolute; top: 0; left: 0; right: 0; border-top: 0.5px solid var(--sep); }
.sheet-item.danger { color: var(--danger); }
.sheet-cancel { margin-top: 8px; border-radius: var(--radius); font-weight: 600; }

.backdrop.confirm { align-items: center; padding: var(--gap); }
.confirm-panel {
  max-width: 360px;
  padding: 20px var(--gap) var(--gap);
  border-radius: 14px;
  background: var(--section);
}
.confirm-text { margin: 0 0 16px; font-size: 17px; text-align: center; overflow-wrap: anywhere; }
.confirm-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---- тост над нижней панелью ---------------------------------------------------------------- */
#toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tabbar-h) + var(--mb-h) + var(--safe-bottom) + 8px);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 8px 6px 16px;
  border-radius: var(--radius);
  background: #1c1c1e;          /* тёмный в обеих темах: в тёмной var(--text) давал белый тост, и «Отменить» не читалось */
  color: #ffffff;
  font-size: 15px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .15s, transform .15s;
}
#toast.open { opacity: 1; transform: none; }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-btn {
  flex: none;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: #64a8ff;
  font-size: 15px;
  font-weight: 600;
}

/* ---- нижняя панель «Главная · Задачи · Заметки · ➕» ------------------------------------------ */
/* в потоке страницы под #view, а не fixed: всегда у нижнего края видимой части (высота body — окно Telegram,
   --tg-viewport-stable-height), даже если окно WebView выше видимой части */
#tabbar {
  position: relative;
  flex: none;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bar);
  border-top: 0.5px solid var(--sep);
}
body.has-mb #tabbar { height: var(--tabbar-h); padding-bottom: 0; }
#tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--hint);
  font-size: 12px;
}
#tabbar .ico { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .75; }
#tabbar .ico.plus { display: grid; place-items: center; width: 30px; height: 22px; border-radius: 7px; background: var(--btn); color: var(--btn-text); font-size: 18px; filter: none; opacity: 1; }
#tabbar button.current { color: var(--link); }
#tabbar button.current .ico { filter: none; opacity: 1; }

/* ---- нижняя кнопка вне Telegram: полоса 50 px в самом низу -------------------------------------- */
#mainbtn {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding-bottom: var(--safe-bottom);
  background: var(--btn);
}
.mainbtn {
  display: block;
  width: 100%;
  height: 50px;
  border: 0;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 17px;
  font-weight: 600;
}
.mainbtn.busy { opacity: .6; }

/* ================================================================================================
   Оболочка (дорожка О): общий вид Б (generic.js), формы (forms.js), главная и версии (home.js).
   Существующие классы выше не меняются — ими пользуются парадные разделы.
   ================================================================================================ */

/* ---- строки списка общего вида ---------------------------------------------------------------- */
.row-tap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  font-size: 17px;
}
.row-body { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.row-main > span { display: block; }
.row-side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  max-width: 45%;
  text-align: right;
}
.row-side .row-meta { white-space: normal; overflow-wrap: anywhere; }
.row-side .row-amount { white-space: nowrap; }
.check-pad { flex: none; width: 44px; height: 44px; }
.row-more {
  flex: none;
  width: 44px;
  height: 44px;
  margin-right: -8px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: none;
  color: var(--hint);
  font-size: 22px;
  line-height: 1;
}
.row-act {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 22px;
  background: var(--btn-soft);
  color: var(--link);
  font-size: 15px;
  white-space: nowrap;
}
.row.selected .check::before { content: "✓"; background: var(--btn); border-color: var(--btn); color: var(--btn-text); }
.selecting .row-tap, .selecting .row-body { cursor: pointer; }
.selecting .row-chevron, .selecting .row-more { visibility: hidden; }

.screen-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 var(--gap) 12px; }
.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  margin: 0 var(--gap) 4px calc(var(--gap) * 2);
  color: var(--hint);
  font-size: 15px;
}
.block-empty { padding: 14px var(--gap); }
.block-empty p { margin: 0; }

/* тревога (alert) красит подпись, а не всю строку или карточку */
.row.alert .row-title, .row.alert .row-amount, .card.alert .card-label { color: var(--text); }

/* карточки блока cards: без значка — черта от края */
.cards-plain .card + .card::before { left: var(--gap); }
.card-main > span { display: block; }

/* текст блока text: простой текст, переносы строк сохраняются */
.text-item { padding: 12px var(--gap); }
.text-item + .text-item { border-top: 0.5px solid var(--sep); }
.text-title { margin: 0 0 4px; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.text-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.text-item.busy { opacity: .4; pointer-events: none; }
/* запись-переход (link блока): вся запись — кнопка с «›» */
.text-tap {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  font-size: 17px;
}
.text-tap-main { flex: 1; min-width: 0; }
/* действия записи — видимыми кнопками, рядами с переносом */
.text-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.text-actions .row-act { white-space: normal; text-align: center; }
.row-act.danger { color: var(--danger); background: color-mix(in srgb, var(--tg-theme-destructive-text-color, #ff3b30) 12%, transparent); }
.btn.busy, .row-act.busy { opacity: .6; }

/* таблица и сводная */
.table-wrap tr.tap { cursor: pointer; }
.table-wrap tbody th { color: var(--text); font-weight: 400; text-align: left; }

/* уровень А */
.a-btn.busy { opacity: .5; }
.a-ext { color: var(--hint); }

/* ---- формы: лист на весь экран и встроенная форма ---------------------------------------------- */
body.form-open { overflow: hidden; }
.form-sheet {
  position: fixed;
  inset: 0;
  z-index: 35;               /* над панелью (30), под нижней кнопкой (40), листами выбора (50) и тостом (60) */
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg2);
  padding-bottom: calc(var(--mb-h) + var(--safe-bottom) + 24px);
}
.form-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 4px var(--gap);
  background: var(--bg2);
}
.form-cancel { justify-self: start; margin-left: -4px; }
.form-title {
  max-width: 60vw;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.form-wrap { margin: 0; }
.form-fields { display: flex; flex-direction: column; gap: 14px; margin: 4px var(--gap) var(--gap); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { padding: 0 var(--gap); color: var(--head); font-size: 15px; }
.field-control {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  margin: 0;
  padding: 0 var(--gap);
  border: 0;
  border-radius: var(--radius);
  background: var(--section);
  color: var(--text);
  font-size: 17px;            /* ≥ 16 px: иначе iOS увеличивает страницу при фокусе */
  line-height: 1.35;
}
.field-control::placeholder { color: var(--hint); }
.field-textarea { min-height: 104px; padding: 12px var(--gap); resize: vertical; }
input.field-control[type="date"], input.field-control[type="time"], input.field-control[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  line-height: 48px;
  text-align: left;
}
.select-wrap { position: relative; }
.select-wrap select { -webkit-appearance: none; appearance: none; padding-right: 40px; }
.select-wrap::after {
  content: "›";
  position: absolute;
  top: 50%;
  right: 16px;
  color: var(--hint);
  font-size: 22px;
  line-height: 1;
  transform: translateY(-50%) rotate(90deg);
  pointer-events: none;
}
.field-new { margin-top: 2px; }
.field.invalid .field-control { box-shadow: inset 0 0 0 2px var(--danger); }
.field.invalid .toggle-row { box-shadow: inset 0 0 0 2px var(--danger); }
.field-error { padding: 0 var(--gap); color: var(--danger); font-size: 15px; }

/* переключатель как в iOS: вся строка нажимается (прозрачный input на всю строку, ≥ 44 px) */
.toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px var(--gap);
  border-radius: var(--radius);
  background: var(--section);
  cursor: pointer;
}
.toggle-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toggle-row input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--soft);
  transition: background .15s;
  pointer-events: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--btn-text);
  box-shadow: 0 1px 3px var(--shade);
  transition: transform .15s;
}
.toggle-row input:checked + .switch { background: var(--btn); }
.toggle-row input:checked + .switch::after { transform: translateX(20px); }
.toggle-row input:focus-visible + .switch { outline: 2px solid var(--btn); outline-offset: 2px; }

.form-block { margin-top: 4px; }
.form-block .form-fields { margin-bottom: 12px; }

/* ---- главная ------------------------------------------------------------------------------------ */
.home-date { margin: -4px var(--gap) 12px; color: var(--hint); font-size: 15px; }
.home-empty { padding: 16px var(--gap); }
.home-empty-title { margin: 0 0 4px; font-weight: 600; }
.home-empty-hint { margin: 0; color: var(--hint); font-size: 15px; }
.home-late .group-head { flex-wrap: wrap; }
.home-late .group-head .link-btn { flex: none; max-width: 100%; font-size: 15px; text-align: right; }
.versions .row-meta { flex: none; }
