/* ==========================================================================
   mobile-base.css — мобильная адаптация справочника веществ (base.html)
   Версия 2026-11-14a. Правила действуют только на узких экранах
   (≤ 992 px), десктоп не затрагивается. Все цвета — через токены темы,
   поэтому тёмная тема работает автоматически.
   ========================================================================== */

/* --- 1. Запрет горизонтального микроскролла -------------------------------- */
@media (max-width: 992px) {
  html, body { overflow-x: hidden; }

  .bs-wrap,
  .bs-grid,
  .bs-col,
  .bs-mix,
  .bs-mix__col { max-width: 100%; }

  /* страница не должна заканчиваться под плавающей кнопкой «Замечание» */
  body { padding-bottom: 76px; }

  /* пока открыта шторка фильтров — фон не скроллится */
  body.bs-sheet-lock { overflow: hidden; }
}

/* --- 2. Вкладки «Фильтры / Вещества / Конструктор» ------------------------- */
@media (max-width: 992px) {
  .mobile-base-tabs {
    position: sticky;
    top: var(--site-header-h, 68px);
    z-index: 900;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 12px;
    padding: 8px 10px;
    background: var(--tz-f1f4f8-panel);
    border-bottom: 1px solid var(--tz-dde3ea-border);
    border-radius: 0;
  }

  .mobile-base-tabs button {
    flex: none;
    min-width: 0;
    min-height: 44px;
    padding: 8px 4px;
    font: 600 13px/1.2 var(--mono, monospace);
    font-family: inherit;
    letter-spacing: .01em;
    border-radius: 10px;
    border: 1.5px solid var(--tz-dde3ea-border);
    background: var(--tz-fbfcfe-card);
    color: var(--tz-45505e-text);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-base-tabs button[aria-selected="true"] {
    background: var(--accent, #1f5fa9);
    border-color: var(--accent, #1f5fa9);
    color: #fff;
  }

  .mobile-base-tabs button:focus-visible {
    outline: 2px solid var(--accent-strong, #1f5fa9);
    outline-offset: 2px;
  }
}

/* --- 3. Нижняя шторка с фильтрами ------------------------------------------ */
@media (max-width: 992px) {
  .bs-sheet-scrim {
    position: fixed;
    inset: 0;
    z-index: 9990;
    background: rgba(10, 16, 26, .5);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }

  .bs-sheet-scrim[hidden] { display: none; }

  .bs-toolbar#search {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9991;
    display: block;
    margin: 0;
    padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
    max-height: 88vh;
    max-height: 88dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: var(--tz-ffffff-card);
    border: 1px solid var(--tz-dde3ea-border);
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 34px rgba(12, 20, 30, .28);
    transform: translateY(102%);
    transition: transform .26s cubic-bezier(.22, .61, .36, 1);
    visibility: hidden;
  }

  .bs-toolbar#search.is-open {
    transform: translateY(0);
    visibility: visible;
  }

  .bs-sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tz-edf0f4-border);
  }

  .bs-sheet__title {
    font: 700 15px/1.25 inherit;
    color: var(--d-ink, var(--tz-1b2430-text));
  }

  .bs-sheet__close {
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid var(--tz-cfd6df-border);
    background: var(--tz-f3f6fa-card);
    color: var(--tz-45505e-text);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
  }

  .bs-sheet__foot { margin-top: 14px; }

  .bs-sheet__apply {
    width: 100%;
    min-height: 46px;
    font-size: 15px;
  }

  /* поля внутри шторки — во всю ширину, крупный шрифт (без автозума iOS) */
  .bs-toolbar#search .bs-field,
  .bs-toolbar#search .bs-field--wide {
    flex: 1 1 100%;
    min-width: 0;
    margin-bottom: 12px;
  }

  .bs-toolbar#search .bs-in,
  .bs-toolbar#search .bs-sel {
    font-size: 16px;
    min-height: 46px;
    padding: 9px 10px;
  }

  .bs-toolbar#search .bs-label { font-size: .8rem; }

  /* экспорт — раскрывающийся блок внутри шторки, без вылезания за экран */
  .bs-toolbar#search .bs-export { width: 100%; }

  .bs-toolbar#search .bs-export__btn {
    width: 100%;
    min-height: 46px;
    font-size: 15px;
  }

  .bs-toolbar#search .bs-export__menu {
    position: static;
    min-width: 0;
    width: 100%;
    margin-top: 8px;
    border-radius: 12px;
  }

  .bs-toolbar#search .bs-export__item {
    min-height: 46px;
    display: flex;
    align-items: center;
    font-size: 14px;
  }
}

/* --- 4. Список веществ ------------------------------------------------------ */
@media (max-width: 992px) {
  .bs-col--list { max-height: none; }

  .bs-list {
    max-height: 58vh;
    min-height: 180px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .bs-item {
    min-height: 46px;
    padding: 8px 12px;
  }

  .bs-item__name { font-size: .9rem; }

  .bs-item__meta { font-size: .76rem; }
}

/* --- 5. Состояния панелей (вкладки управляют классами .bs-grid) ------------- */
@media (max-width: 992px) {
  .bs-grid.mbt-filters .bs-col { display: none !important; }

  .bs-grid.mbt-list .bs-col--list { display: flex !important; }

  /* карточка свойств показывается под списком, когда выбрано вещество */
  .bs-grid.mbt-list .bs-col--props:not([hidden]) { display: block !important; }

  .bs-grid.mbt-detail .bs-col--list { display: none !important; }
  .bs-grid.mbt-detail .bs-col--props { display: block !important; }

  .bs-grid.mbt-mix .bs-col--list { display: none !important; }
  .bs-grid.mbt-mix .bs-col--props { display: block !important; }

  .bs-grid.mbt-list,
  .bs-grid.mbt-detail,
  .bs-grid.mbt-mix,
  .bs-grid.mbt-filters { grid-template-columns: 1fr; }

  .bs-col--props { padding: 12px; }
}

/* --- 6. Кнопка «назад к списку» в карточке свойств -------------------------- */
@media (max-width: 992px) {
  .bs-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    margin: 0 0 8px;
    padding: 8px 12px;
    border: 1px solid var(--tz-cfd6df-border);
    border-radius: 10px;
    background: var(--tz-f3f6fa-card);
    color: var(--tz-1f5fa9-ink-blue);
    font: 600 14px/1.2 inherit;
    cursor: pointer;
  }

  .bs-back[hidden] { display: none; }

  .bs-props__head { flex-direction: column; align-items: stretch; gap: 8px; }
}

/* --- 7. Липкая панель действий ---------------------------------------------- */
@media (max-width: 992px) {
  .bs-actions {
    position: sticky;
    bottom: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0 10px 62px; /* слева место под плавающую кнопку «Замечание» */
    background: var(--tz-fbfcfe-card);
    border-top: 1px solid var(--tz-dde3ea-border);
    box-shadow: 0 -6px 18px rgba(12, 20, 30, .10);
  }

  .bs-actions .bs-btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    font-size: 13px;
    padding: 8px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* меню «Ещё» — всплывающая панель над липкой панелью */
  .bs-more {
    display: none;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 40;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border-radius: 14px;
    background: var(--tz-ffffff-card);
    border: 1px solid var(--tz-dde3ea-border);
    box-shadow: 0 12px 32px rgba(12, 20, 30, .24);
  }

  .bs-more.is-open { display: flex; }

  .bs-more .bs-btn {
    width: 100%;
    min-height: 46px;
    justify-content: flex-start;
    text-align: left;
    font-size: 14px;
  }
}

/* на десктопе «Ещё» не существует: кнопки раскладываются инлайн */
@media (min-width: 993px) {
  .bs-more { display: contents; }
  .bs-btn--more { display: none; }
}

/* --- 8. Таблицы: горизонтальный скролл + липкая первая колонка ------------- */
@media (max-width: 992px) {
  .bs-tblscroll {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    border: 1px solid var(--tz-edf0f4-border);
    border-radius: 10px;
  }

  .bs-tblscroll .bs-mix__tbl,
  .bs-tblscroll .bs-mix__live-tbl { min-width: 340px; }

  .bs-mix__tbl,
  .bs-mix__live-tbl {
    white-space: nowrap;
    word-break: keep-all;
  }

  .bs-mix__tbl th,
  .bs-mix__tbl td,
  .bs-mix__live-tbl th,
  .bs-mix__live-tbl td { white-space: nowrap; }

  .bs-mix__tbl th:first-child,
  .bs-mix__tbl td:first-child,
  .bs-mix__live-tbl th:first-child,
  .bs-mix__live-tbl td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--tz-ffffff-card);
  }

  .bs-mix__tbl th:first-child,
  .bs-mix__live-tbl th:first-child { background: var(--tz-f1f4f8-panel); }

  .bs-mix__tbl input,
  .bs-mix__tbl select {
    font-size: 16px;
    min-height: 44px;
  }

  .bs-mix__tbl .num { width: 92px; }

  .bs-mix__del {
    min-width: 44px;
    min-height: 44px;
  }
}

/* --- 9. Конструктор смеси --------------------------------------------------- */
@media (max-width: 992px) {
  .bs-mix {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .bs-mix__pick .bs-in {
    font-size: 16px;
    min-height: 46px;
  }

  .bs-mix__move {
    min-width: 44px;
    min-height: 46px;
  }

  .bs-mix__src { max-height: 190px; overflow-y: auto; }

  .bs-mix__src-item { min-height: 46px; }

  .bs-mix__live-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bs-mix__live-t .bs-in {
    font-size: 16px;
    width: 96px;
    min-height: 44px;
  }
}

/* --- 10. Поля формы: 16 px, крупные зоны нажатия ---------------------------- */
@media (max-width: 992px) {
  .bs-col--props input,
  .bs-col--props select,
  .bs-col--props textarea,
  .bs-mix input,
  .bs-mix select,
  .bs-mix textarea {
    font-size: 16px !important;
    min-height: 44px;
  }

  .bs-btn {
    min-height: 44px;
  }

  .bs-btn--sp12 { min-height: 46px; }

  .btn-tooltip {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Подсказка «[?]» на мобильном — поп-авер над кнопкой. Координаты
     (--tip-x/--tip-y) считает JS при открытии, поэтому пузырь не вылезает
     за экран и не перекрывает поля под собой. */
  .btn-tooltip::after {
    position: fixed;
    width: min(260px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    z-index: 9995;
    overflow-wrap: anywhere;
  }
}

/* На тач-устройствах подсказка открывается по клику (класс .is-open),
   а не по наведению: :hover на тач-экранах залипает, а :focus держит
   подсказку открытой и она перекрывает поля. */
@media (max-width: 992px) and (hover: none) {
  .btn-tooltip:hover::after,
  .btn-tooltip:focus::after { opacity: 0; visibility: hidden; }
  .btn-tooltip.is-open::after { opacity: 1; visibility: visible; }
}

/* --- 10б. Радиокнопки → сегментированный контрол ---------------------------- */
@media (max-width: 992px) {
  .bs-radios {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    width: 100%;
  }

  /* Радиокнопка и подпись — в обычном потоке (grid), без absolute:
     раньше radio стоял абсолютно по left:8px, а текст был центрирован,
     и на узком экране подпись наезжала на переключатель. */
  .bs-radios label {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 9px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1.5px solid var(--tz-cfd6df-border);
    border-radius: 12px;
    background: var(--tz-ffffff-card);
    font-size: .86rem;
    line-height: 1.25;
    text-align: left;
  }

  .bs-radios input[type="radio"] {
    position: static;
    transform: none;
    width: 18px;
    height: 18px;
    min-height: 0;
    margin: 0;
    flex: none;
    justify-self: start;
    accent-color: var(--accent-strong, var(--tz-1f5fa9-ink-blue));
  }

  .bs-radios input:checked + span {
    color: var(--tz-1f5fa9-ink-blue);
    font-weight: 600;
  }

  .bs-radios label:has(input:checked) {
    border-color: var(--accent, #1f5fa9);
    background: var(--tz-eef4fd-card);
  }

  .bs-radios input:focus-visible + span {
    outline: 2px solid var(--accent-strong, #1f5fa9);
    outline-offset: 2px;
  }

  .bs-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    font-size: .86rem;
  }

  .bs-check input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-height: 0;
    margin: 0;
    accent-color: var(--accent-strong, var(--tz-1f5fa9-ink-blue));
  }
}

/* --- 11. Плавающая кнопка «Замечание» — круглая, не перекрывает действия ---- */
@media (max-width: 992px) {
  .cmtw__fab {
    left: 10px;
    bottom: 12px;
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }

  .cmtw__fab-txt { display: none; }
}

/* --- 11б. Длинные методические тексты — спойлер (на мобильном свёрнуты) ------ */
.bs-fold { margin: 0 0 12px; }

.bs-fold__sum {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--tz-d8dde5-border);
  border-radius: 12px;
  background: var(--tz-f5f8fa-card);
  color: var(--tz-1d2935-text);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.bs-fold__sum::-webkit-details-marker { display: none; }

.bs-fold__sum::after {
  content: "▾";
  margin-left: auto;
  font-size: .95rem;
  transition: transform .2s ease;
}

.bs-fold[open] > .bs-fold__sum::after { transform: rotate(180deg); }
.bs-fold[open] > .bs-fold__sum { margin-bottom: 10px; }

.bs-fold__sum:focus-visible {
  outline: 2px solid var(--accent-strong, #1f5fa9);
  outline-offset: 2px;
}

.bs-fold > .lead,
.bs-fold > .mdb__note { margin-top: 0; }

/* на десктопе текст раскрыт, «шапка» спойлера не нужна */
@media (min-width: 1024px) {
  .bs-fold__sum { display: none; }
  .bs-fold { margin-bottom: 12px; }
}

/* --- 12. Зоны нажатия в шапке и вкладках разделов ≥ 44 px --------------------
   Общие файлы (style.css, theme.css, sp12.css) не трогаем — правила
   действуют только на этой странице. */
.site-header .brand__mark,
.site-header .theme-toggle { width: 44px; height: 44px; }
.site-header .brand__name {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
footer.site-footer-unified a.footer-brand__lk,
footer.site-footer-unified a.footer-brand__remark { min-height: 44px; }

@media (max-width: 992px) {
  .sp12tabs__btn { min-height: 44px; }
  /* единый подвал: ссылки — не меньше 44 px (в design.css правило
     завязано на .site-footer, а подвал называется .site-footer-unified) */
  .site-footer-unified a { display: inline-flex; align-items: center; min-height: 44px; }
}

/* --- 13. Тёмная тема: только токены, без жёстких цветов --------------------- */@media (max-width: 992px) {
  html.dark-theme .bs-sheet-scrim { background: rgba(4, 8, 14, .62); }

  html.dark-theme .bs-toolbar#search,
  html.dark-theme .bs-more {
    background: var(--tz-ffffff-card);
    border-color: var(--tz-dde3ea-border);
  }

  html.dark-theme .bs-actions { background: var(--tz-fbfcfe-card); }

  html.dark-theme .mobile-base-tabs { background: var(--tz-f1f4f8-panel); }

  html.dark-theme .bs-sheet__close,
  html.dark-theme .bs-back { background: var(--tz-f3f6fa-card); color: var(--tz-7fb2e8-ink-blue); }

  html.dark-theme .bs-mix__tbl th:first-child,
  html.dark-theme .bs-mix__live-tbl th:first-child { background: var(--tz-f1f4f8-panel); }
}


/* prbase-hint-row-20261121 — кнопка «?» на мобильном 44×44 стояла absolute
   в подписи высотой 18px и свисала на поле ввода, перехватывая тапы.
   Даём строке подписи min-height, чтобы кнопка помещалась внутри неё. */
@media (max-width: 820px) {
  .bs-row > label:has(.btn-tooltip) {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding-right: 48px;
  }
  .bs-row > label .btn-tooltip {
    top: 50%;
    transform: translateY(-50%);
  }
}
