/* Мобильный интерфейс.

   Те же краски и та же тема, что и в полной версии (переменные из app.css) —
   меняется не оформление, а размер: под палец, а не под курсор. Отсюда
   правила, которых нет в настольном экране:

   * ничего не появляется по наведению — на телефоне наводить нечем;
   * поля ввода не мельче 16 px, иначе Safari при фокусе увеличивает страницу;
   * действия живут внизу, где до них дотягивается большой палец;
   * нижняя полоса и панели отступают от вырезов экрана (safe-area).

   Полный редактор в это время просто скрыт: разметка у них общая. */

html[data-ui="mobile"] {
  height: 100%;
}

/* Полный редактор держит страницу нерастяжимой; мобильный экран этим же и
   пользуется, но высоту берёт динамическую — иначе нижняя полоса уезжает
   под адресную строку браузера, которая то появляется, то прячется. */
html[data-ui="mobile"] body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

html[data-ui="mobile"] > body > header.bar,
html[data-ui="mobile"] > body > main,
html[data-ui="mobile"] > body > footer.status { display: none; }

#mobile { display: none; }

html[data-ui="mobile"] #mobile {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0; position: relative;   /* якорь для сообщения внизу */
  background: var(--bg);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

/* ------------------------------------------------------------- заголовок */

.m-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px calc(env(safe-area-inset-left) + 16px);
  background: var(--panel); border-bottom: 1px solid var(--line);
}

.m-title { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 1px; }
.m-title-main {
  font-size: 16px; font-weight: 600; letter-spacing: -.1px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.m-title-sub {
  font-size: 12.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Кнопка со значком: 44 px — размер, в который уверенно попадает палец. */
.m-icon {
  flex: 0 0 auto; width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 10px; background: none;
  color: var(--ink-2); cursor: pointer;
}
.m-icon:active { background: var(--pressed); }

/* ----------------------------------------------------------- список разъёмов */

.m-list {
  flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 12px;
  padding: 12px calc(env(safe-area-inset-right) + 12px) 12px calc(env(safe-area-inset-left) + 12px);
  display: flex; flex-direction: column; gap: 8px;
}

.m-card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 10px 12px 14px; min-height: 64px;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-lg);
  font: inherit; color: var(--ink); text-align: left; cursor: pointer;
}
.m-card:active, .m-card.is-held { background: var(--sunken); }
/* Долгое нажатие — жест приложения; выделять при этом текст карточки
   телефону незачем, его меню выделения перекрыло бы наше. */
.m-card { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.m-card-ref {
  flex: 0 0 auto; min-width: 44px; padding: 4px 8px;
  font: 600 15px var(--mono); color: var(--accent-ink);
  background: var(--accent-soft); border-radius: var(--r); text-align: center;
}
.m-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.m-card-type {
  font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.m-card-meta { font-size: 12.5px; color: var(--muted); }
.m-card-go { flex: 0 0 auto; color: var(--faint); display: inline-flex; }

.m-total { padding: 6px 4px 0; font-size: 12.5px; color: var(--muted); text-align: center; }

.m-empty { padding: 32px 20px; text-align: center; color: var(--muted); }
.m-empty b { display: block; font-size: 16px; color: var(--ink); margin-bottom: 6px; }
.m-empty p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; }

/* ------------------------------------------------------------ нижняя полоса */

.m-foot {
  display: flex; gap: 8px;
  padding: 10px 12px;
  padding: 10px calc(env(safe-area-inset-right) + 12px)
           calc(env(safe-area-inset-bottom) + 10px) calc(env(safe-area-inset-left) + 12px);
  background: var(--panel); border-top: 1px solid var(--line);
}
/* Кнопкам разрешено сжиматься: без min-width:0 они держат ширину подписи со
   значком, и на узком экране (320 px) нижняя полоса выпирает за край. */
.m-foot .m-btn { flex: 1 1 0; min-width: 0; padding: 0 8px; }
.m-foot .m-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Совсем узкий экран: подпись важнее значка, значок и уходит. */
@media (max-width: 360px) {
  .m-foot { gap: 6px; }
  .m-foot .m-btn { padding: 0 6px; gap: 5px; font-size: 14px; }
  .m-foot .m-btn .ic { display: none; }
}

.m-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  background: var(--raised); color: var(--ink);
  font: inherit; font-size: 15px; cursor: pointer;
}
.m-btn:active { background: var(--sunken); }
.m-btn[disabled] { opacity: .4; cursor: default; }
.m-btn.primary { background: var(--primary-bg); border-color: var(--primary-bg); color: var(--primary-fg); }
.m-btn.wide { width: 100%; }
.m-btn .ic { flex: 0 0 auto; }

.m-row { display: flex; gap: 8px; }
.m-row .m-btn:first-child { flex: 1; }

/* Сообщение над нижней полосой: сказать и уйти, ничего не загораживая.
   Лежит выше панелей: сообщать есть о чём и из них тоже. */
.m-note {
  position: absolute; left: 12px; right: 12px; bottom: 78px;
  bottom: calc(env(safe-area-inset-bottom) + 78px);
  z-index: 80; padding: 10px 14px; border-radius: var(--r-lg);
  background: var(--primary-bg); color: var(--primary-fg);
  font-size: 13.5px; line-height: 1.4; box-shadow: var(--shadow);
}
.m-note[hidden] { display: none; }

/* ------------------------------------------------------------------ панели */

.m-sheet-back {
  position: fixed; inset: 0; z-index: 70; background: var(--scrim);
  display: flex; align-items: flex-end;
}
.m-sheet {
  display: flex; flex-direction: column;
  width: 100%; max-height: 92%; min-height: 0;
  background: var(--raised); border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow);
}
.m-sheet.full { height: 92%; }

.m-sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--line-soft);
}
.m-sheet-head h2 { margin: 0; flex: 1; font-size: 16px; font-weight: 600; }

.m-sheet-body {
  flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
}
.m-sheet-foot {
  padding: 10px 16px 12px;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--line-soft); background: var(--raised);
}

/* -------------------------------------------------------------- поля ввода */

/* 16 px — не оформление, а условие: при меньшем кегле Safari увеличивает
   страницу, как только палец попадает в поле, и экран уезжает. */
.m-input {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--field); color: var(--ink);
  font: inherit; font-size: 16px;
}
.m-input:focus { border-color: var(--accent); outline: none; }
.m-input::placeholder { color: var(--faint); }
.m-input.mono, .m-input.ref { font-family: var(--mono); }
.m-input.ref { flex: 0 0 88px; font-weight: 600; text-align: center; }
.m-input.area { min-height: 200px; resize: vertical; line-height: 1.5; }
select.m-input { appearance: none; -webkit-appearance: none; }

.m-form { display: flex; flex-direction: column; gap: 12px; }
.m-field { display: flex; flex-direction: column; gap: 6px; }
.m-field[hidden] { display: none; }
.m-field-label { font-size: 13px; color: var(--muted); }
.m-field-hint { font-size: 12px; color: var(--faint); line-height: 1.45; }
.m-hint { margin: 0 0 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.m-group {
  padding: 10px 0 0; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint);
}
.m-build { margin: 16px 0 0; font-size: 11.5px; color: var(--faint); text-align: center; }

/* Тумблер: вся строка — это и есть подпись, попасть в неё легко. */
.m-switch {
  display: flex; align-items: center; gap: 12px; min-height: 48px;
  padding: 6px 0; cursor: pointer;
}
.m-switch-text { flex: 1; }
.m-switch input { position: absolute; opacity: 0; pointer-events: none; }
.m-switch-track {
  flex: 0 0 auto; width: 46px; height: 28px; border-radius: 14px;
  background: var(--track); position: relative; transition: background .12s;
}
.m-switch-track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--knob); transition: transform .12s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.m-switch input:checked + .m-switch-track { background: var(--accent); }
.m-switch input:checked + .m-switch-track::after { transform: translateX(18px); }
.m-switch input:focus-visible + .m-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Равнозначные варианты в строку; тесные — переносятся, а не сжимаются в точку. */
.m-choice { display: flex; flex-wrap: wrap; gap: 6px; }
.m-choice-btn {
  flex: 1 1 auto; min-width: 84px; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--raised); color: var(--ink-2);
  font: inherit; font-size: 14px; cursor: pointer;
}
.m-choice-btn.is-on {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
}

.m-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.m-chip {
  min-width: 56px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--raised); color: var(--ink-2);
  font: 600 15px var(--mono); cursor: pointer;
}
.m-chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }

/* ------------------------------------------------------------- справочник */

.m-pick-wrap { display: flex; flex-direction: column; gap: 8px; margin: -12px -16px; }
.m-pick-search {
  position: sticky; top: -12px; z-index: 2;
  padding: 12px 16px 8px; background: var(--raised); border-bottom: 1px solid var(--line-soft);
}
.m-pick { display: flex; flex-direction: column; }
.m-pick-group {
  display: flex; flex-direction: column; gap: 2px;
  padding: 14px 16px 6px; background: var(--raised);
}
.m-pick-group span { font-size: 13px; font-weight: 600; color: var(--ink); }
.m-pick-group small { font-size: 11.5px; color: var(--faint); line-height: 1.4; }
.m-pick-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 52px; padding: 8px 16px;
  border: none; border-top: 1px solid var(--line-soft); background: none;
  font: inherit; color: var(--ink); text-align: left; cursor: pointer;
}
.m-pick-item:active { background: var(--sunken); }
.m-pick-type { flex: 1; min-width: 0; font-family: var(--mono); font-size: 14px; overflow-wrap: break-word; }
.m-pick-pins { flex: 0 0 auto; font-size: 12.5px; color: var(--muted); }

/* --------------------------------------------------------------- контакты */

.m-pin-head { display: flex; gap: 8px; margin-bottom: 12px; }
.m-pins { display: flex; flex-direction: column; gap: 4px; }

/* Строка контакта: номер слева меткой, наименование во всю оставшуюся
   ширину, ручка справа. Номер здесь не правится — он принадлежит разъёму,
   и поле ввода под него только отнимало бы место у наименования. */
.m-pin {
  display: flex; align-items: center; gap: 8px;
  border-radius: var(--r); padding: 1px 0;
}
.m-pin .m-input { flex: 1; min-width: 0; }
.m-pin-num {
  flex: 0 0 34px; text-align: right;
  font: 600 14px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums;
}
.m-pin-to {
  flex: 0 0 auto; max-width: 76px; font: 11.5px var(--mono); color: var(--faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.m-pin-to:empty { display: none; }

/* Ручка: за неё берут строку пальцем. touch-action снят, иначе жест
   уходит прокрутке списка и строка не трогается с места. */
.m-grip {
  flex: 0 0 auto; width: 40px; height: 44px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--faint); cursor: grab;
  touch-action: none; -webkit-user-select: none; user-select: none;
}
.m-grip:active { color: var(--ink-2); cursor: grabbing; }
.m-pin.is-dragging { opacity: .45; }
.m-pin.is-target { box-shadow: inset 0 2px 0 var(--accent); }

/* ------------------------------------------------------------- список дел */

.m-items { display: flex; flex-direction: column; gap: 2px; }
.m-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%;
  min-height: 52px; padding: 10px 12px;
  border: none; border-radius: var(--r); background: none;
  font: inherit; color: var(--ink); text-align: left; cursor: pointer;
}
.m-item:active { background: var(--sunken); }
.m-item-label { font-size: 15px; }
.m-item-hint { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.m-item.danger .m-item-label { color: var(--danger); }

.m-msg { font-size: 13.5px; padding: 10px 12px; border-radius: var(--r); line-height: 1.45; }
.m-msg.error { background: var(--err-soft); color: var(--danger); }
.m-msg.warn { background: var(--warn-soft); color: var(--warn); }

/* --------------------------------------------------------------- результат */

/* Лист занимает всё, что осталось от панели: у повёрнутого телефона высоты
   мало, и чертёж во всю ширину пришлось бы листать, чтобы увидеть целиком. */
.m-sheet[data-sheet="result"] .m-sheet-body { display: flex; flex-direction: column; }
.m-result { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.m-result-head { display: flex; flex-wrap: wrap; gap: 6px; flex: 0 0 auto; }
.m-tag {
  padding: 5px 10px; border-radius: 999px; background: var(--sunken);
  font-size: 12.5px; color: var(--ink-2); border: 1px solid var(--line-soft);
}
.m-tag.ok { color: var(--ok); }
.m-tag.warn { background: var(--warn-soft); border-color: var(--warn-soft); color: var(--warn); cursor: pointer; }

/* Лист показывается целиком: на телефоне его читают, а не правят.
   Подробности смотрят увеличением страницы — как любую картинку. */
.m-view {
  display: block; padding: 8px; border-radius: var(--r);
  background: var(--stage); box-shadow: var(--sheet-shadow);
  /* по содержимому, но не выше панели: лишней пустоты вокруг листа нет,
     а у повёрнутого телефона лист ужимается до того, что помещается */
  flex: 0 1 auto; min-height: 0;
}
/* Запасной путь для браузера без теневого дерева: там лист лежит прямо в
   странице (см. sheetResult), и вписывать его приходится отсюда. */
.m-view > svg { display: block; width: 100%; height: auto; max-height: 100%; }

/* Лист, уходящий в печать, лежит в самой странице (см. export.js): на экране
   его не видно, а @media print прячет на это время всё остальное. */
.cs-print { display: none; }

@media (prefers-reduced-motion: reduce) {
  .m-switch-track, .m-switch-track::after { transition: none; }
}
