/* editor/mobile.css
 *
 * Телефонная раскладка студии. Включается классом m-on на body — его
 * ставит mobile.js, и только на узком экране в студии записи.
 *
 * ПРАВИЛО ОДНО: ЗА РАЗ ВИДНО ОДНО ДЕЙСТВИЕ. Всё, что на большом экране
 * лежит рядом, здесь разложено по шагам. Экран предпросмотра прилипает к
 * верху — на телефоне это единственная связь между «что я меняю» и «что
 * из этого выйдет», и терять её при прокрутке нельзя.
 *
 * ПАЛЬЦЕМ, А НЕ КУРСОРОМ. Ни одна цель не меньше 48 точек, поля — 16px
 * (меньше — и Safari сам увеличит страницу при фокусе, сдвинув всё), а
 * то, что раньше открывалось наведением, открывается нажатием.
 */

body.m-on .canvas,
body.m-on .tabs {
  display: none;
}

body.m-on {
  height: 100dvh;
  overflow: hidden;
}

body.m-on .top {
  padding: 8px 12px;
  gap: 8px;
}
body.m-on .top .guide {
  font-size: 13px;
}

/* ── Меню шапки ───────────────────────────────────────────────────
 *
 * Ссылки шапки на узком экране стоят в одну строку и налезают друг на
 * друга. За кнопкой они помещаются все, и каждая — крупная цель.
 */
.m-burger { display: none; }

body.m-on .m-burger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-inline-start: auto;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.m-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.m-menu[hidden] { display: none; }
.m-menu .m-menu-item {
  display: block;
  min-height: 48px;
  padding: 13px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
}
.m-menu .m-menu-item:active { background: var(--panel-2); }

/* В шапке этих ссылок больше нет — они переехали в меню. */
body.m-on .top .guide { display: none; }
body.m-on .m-menu .guide { display: block; }

/* ── Каркас мастера ───────────────────────────────────────────────── */

.m-app {
  display: none;
  flex-direction: column;
  /* Высота экрана минус шапка: dvh, а не vh, — на телефоне адресная
     строка съезжает, и vh на ней врёт на высоту этой самой строки. */
  height: calc(100dvh - 52px);
}
body.m-on .m-app {
  display: flex;
}

.m-steps {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.m-steps button {
  flex: 1;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.m-steps button b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}
.m-steps button.current {
  color: var(--text);
  border-color: var(--accent);
  background: var(--panel-2);
}
.m-steps button.current b {
  background: var(--accent);
  color: #fff;
}
/* Пройденный шаг — галочка вместо номера: путь виден целиком. */
.m-steps button.done b {
  background: transparent;
  color: var(--accent);
}
.m-steps button.done b::after {
  content: "✓";
}
.m-steps button.done b {
  font-size: 0;
}
.m-steps button.done b::after {
  font-size: 13px;
}

.m-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 16px;
}

.m-page {
  display: none;
  flex-direction: column;
  gap: 14px;
}
.m-page.is-on {
  display: flex;
}

/* Нижняя панель: два действия и ничего больше. */
.m-bar {
  display: flex;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.m-bar button {
  min-height: 50px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.m-bar .m-back {
  flex: 0 0 40%;
}
.m-bar .m-back:disabled {
  opacity: 0.4;
}
.m-bar .m-next {
  flex: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Экран предпросмотра: прилипает к верху ───────────────────────── */

body.m-on .screen.m-sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: -12px -12px 0;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
body.m-on .screen-field {
  height: clamp(150px, 26vh, 240px);
}
body.m-on .screen-bottom {
  flex-wrap: wrap;
  gap: 6px;
}

/* Кнопка листа структур. Стоит В КАЖДОЙ карточке сцены: сцен бывает
   пять, и какая из них сейчас текущая, на телефоне не видно — рамка
   выделения уходит за край ленты кадров. */
.m-pick {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-bottom: 10px;
  border-radius: 14px;
  border: 1px dashed var(--accent);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.m-pick:active { background: var(--panel-2); }

/* Текущая сцена — та, куда уедет выбранное. Отмечаем явно: сплошной
   рамкой и цветом кнопки. */
body.m-on .shot.m-current {
  border-color: var(--accent) !important;
}
body.m-on .shot.m-current .m-pick {
  border-style: solid;
  background: var(--panel-2);
}

/* Подтверждение выбора. Лист структур занимает экран целиком, карточка
   сцены под ним не видна — без этой строки нажатие на структуру выглядит
   как «ничего не произошло», и её нажимают ещё раз. */
.m-toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 80;
  max-width: min(92vw, 460px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease-out, transform 0.2s ease-out;
  pointer-events: none;
}
.m-toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce) {
  .m-toast { transition: none; }
}

/* ── Содержимое шагов ─────────────────────────────────────────────── */

body.m-on .m-page > section,
body.m-on .m-page > .topic-head {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

body.m-on .m-page h2 {
  font-size: 15px;
  margin: 0 0 8px;
}

body.m-on input,
body.m-on select,
body.m-on textarea {
  min-height: 48px;
  font-size: 16px; /* меньше — и Safari увеличит страницу при фокусе */
}
body.m-on .button {
  min-height: 50px;
  border-radius: 12px;
  font-size: 15px;
}
body.m-on .button.small {
  min-height: 42px;
}

body.m-on .topics {
  max-height: none;
}
body.m-on .topics li {
  min-height: 56px;
  padding: 12px;
  border-radius: 12px;
}

body.m-on #title {
  font-size: 18px;
  min-height: 54px;
}

/* Сцена — карточка, поля в столбик. На большом экране они стоят в ряд,
   и в ряду на телефоне каждое поле шириной в палец. */
body.m-on .shots {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
body.m-on .shot {
  border-radius: 14px;
  padding: 12px;
}
body.m-on .shot .line {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
body.m-on .shot .line label {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  font-size: 13px;
}
body.m-on .shot .line select,
body.m-on .shot .line input {
  width: 100%;
}
body.m-on .shot .line .button {
  width: 100%;
  margin-left: 0;
}
body.m-on .shot textarea {
  min-height: 110px;
}

/* Лента кадров: горизонтальная прокрутка с прилипанием — как в галерее
   телефона, а не как список ссылок. */
body.m-on .strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 4px;
}
body.m-on .tile {
  flex: 0 0 auto;
  min-width: 104px;
  scroll-snap-align: start;
}

/* Настройки сборки: два поля в ряд там, где они короткие. */
body.m-on .choice {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
body.m-on .choice label {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
body.m-on .render-buttons .button {
  width: 100%;
}

/* ── Лист структур ────────────────────────────────────────────────── */

.m-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}
.m-sheet.is-open {
  display: block;
}
.m-sheet-back {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.m-sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border-top: 1px solid var(--border);
  animation: m-rise 0.18s ease-out;
}
@keyframes m-rise {
  from {
    transform: translateY(12%);
    opacity: 0.6;
  }
}
@media (prefers-reduced-motion: reduce) {
  .m-sheet-card {
    animation: none;
  }
}
.m-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.m-grip {
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.m-sheet-close {
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.m-sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
}
.m-sheet-body .tree {
  min-height: 200px;
}
.m-sheet-body .sheet {
  min-height: 56px;
}
/* Пока лист открыт, страница под ним не ездит: иначе закрытие
   возвращает человека не туда, где он был. */
body.m-locked .m-body {
  overflow: hidden;
}

/* ── Выбор моделей на телефоне: во весь экран ──────────────────────────
 *
 * Лист занимает экран целиком: выбор модели — отдельное дело, и дереву
 * в две трети экрана пальцу было тесно. Сверху — поиск, ниже — плитки. */
body.m-on .m-sheet-card {
  top: 0;
  max-height: none;
  border-radius: 0;
  border-top: 0;
}
body.m-on .m-grip { display: none; }
.m-sheet-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-sheet-close { min-height: 44px; min-width: 96px; }

.m-pk-top {
  position: sticky;
  top: -12px;
  z-index: 2;
  display: flex;
  gap: 8px;
  margin: -12px -14px 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.m-pk-find {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}
.m-pk-back {
  min-height: 48px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}
.m-pk-h {
  margin: 14px 2px 8px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.m-pk-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
/* «Недавние» — одной полосой с прокруткой вбок. */
.m-pk-grid.m-pk-row {
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 40%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 4px;
}
.m-pk-row .m-pk-card { scroll-snap-align: start; }
.m-pk-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-height: 150px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  text-align: start;
  cursor: pointer;
}
.m-pk-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 10px;
  background: var(--bg);
}
.m-pk-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.m-pk-meta { font-size: 12px; color: var(--muted); }
.m-pk-card:active { transform: scale(0.98); }
/* Уже в сцене — рамкой и галочкой: видно, что касание сработало. */
.m-pk-card.is-in { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.m-pk-card.is-in .m-pk-meta { color: var(--accent); font-weight: 600; }
.m-pk-organ .m-pk-name { font-size: 15px; }
.m-pk-all {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-height: 64px;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px dashed var(--accent);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-align: start;
}
.m-pk-all b { font-size: 15px; }
.m-pk-all span { font-size: 12px; color: var(--muted); }

/* Подтверждение с «Отменить»: кнопка должна нажиматься. */
.m-toast.m-toast-undo {
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
  z-index: 90;
}
.m-toast.m-toast-undo[hidden] { display: none; }
.m-toast-undo button {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
}

/* ── Экран сцены: 16:9 во всю ширину ──────────────────────────────── */
body.m-on .screen-field {
  height: auto;
  aspect-ratio: 16 / 9;
}
/* Рисуют пальцем: пока выбран инструмент, экран не прокручивает страницу. */
body.m-on .screen-field.placing { touch-action: none; }

/* ── Отметки на кадре: одна кнопка, инструменты — листом снизу ─────── */
.m-mark-toggle {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
}
body.m-on #mark-tools { display: none; }
body.m-on #mark-tools.m-open {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.4);
}
body.m-on #mark-tools.m-open > span { grid-column: 1 / -1; }
body.m-on #mark-tools.m-open .button { min-height: 48px; width: 100%; }

/* ── Карточка сцены: компактно ────────────────────────────────────── */
body.m-on .shot .line.shot-head {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
body.m-on .shot-head .number { flex: 1; order: 0; font-size: 16px; }
body.m-on .shot-head .m-more { order: 1; }
body.m-on .shot-head > label:not(.level-chip) {
  order: 2;
  flex: 1 1 100%;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
body.m-on .shot-head > label:not(.level-chip) input { width: 72px; text-align: center; }
body.m-on .shot-head > label:not(.level-chip) button { min-width: 44px; min-height: 44px; }
/* Пациент / студент — две кнопки-переключателя рядом, а не флажки в столбик. */
body.m-on .shot .line.shot-head label.level-chip {
  order: 3;
  position: relative;
  flex: 1 1 40%;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 14px;
  font-weight: 600;
}
body.m-on .shot-head label.level-chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
body.m-on .shot .line.shot-head label.level-chip:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
/* «⋯» — редкие действия: удалить сцену. */
.m-more { position: relative; }
.m-more > summary {
  list-style: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 22px;
  cursor: pointer;
}
.m-more > summary::-webkit-details-marker { display: none; }
.m-more[open] > .button {
  position: absolute;
  inset-inline-end: 0;
  top: 50px;
  z-index: 8;
  width: max-content !important;
  min-height: 44px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
/* Камера — свёрнутый раздел. */
.m-cam > summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-weight: 600;
  cursor: pointer;
}
.m-cam[open] > summary { margin-bottom: 8px; }
/* Части сцены — переносятся, крупнее под палец. */
body.m-on .shot .shown { display: flex; flex-wrap: wrap; gap: 6px; }
body.m-on .shot .shown .icon { min-height: 40px; }
/* Свёрнутые сцены — строкой под палец. */
body.m-on .shot.folded .fold-head {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 14px;
}

/* На телефоне «+» между плитками — под палец: наведения нет, и
   приглушённую узкую кнопку не видно и в неё не попасть. */
body.m-on .tile-gap {
  width: 30px;
  height: 56px;
  opacity: 0.8;
  border-color: var(--border);
}
