/* ==========================================================================
   СП 12 — мобильная адаптация (<= 768 px)
   Дерево объектов, верхнее меню, панель инструментов, таблицы.
   ========================================================================== */

html, body { max-width: 100%; overflow-x: clip; }

/* --------------------------- Дерево объектов ----------------------------- */
.sp12-tree__node--l1,
.tree-node {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  align-items: center;
  border-radius: 8px;
  transition: background-color .15s ease;
}
.sp12-tree__node--l1:hover,
.tree-node:hover { background-color: rgba(37, 99, 235, .07); }
.sp12-tree__label { cursor: pointer; }

/* Плавающая кнопка возврата к дереву */
.mobile-tree-fab { display: none; }

@media (max-width: 768px) {

  /* ---------- верхнее меню: клик, нижняя шторка ---------- */
  .fcx-menubar {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 2px;
    height: auto !important;
    min-height: 46px;
    padding: 4px 8px;
    scrollbar-width: none;
  }
  .fcx-menubar::-webkit-scrollbar { display: none; }
  .fcx-menu { flex: 0 0 auto; }
  .fcx-menu__btn {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 14px;
    border-radius: 8px;
    white-space: nowrap;
  }
  .fcx-menubar__right { display: none; }

  /* выпадающий список — фиксированная нижняя шторка, не уезжает за край */
  .fcx-menu.is-open .fcx-menu__list {
    display: block !important;
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    top: auto !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: 70vh;
    overflow-y: auto;
    border-radius: 16px;
    padding: 10px;
    box-shadow: 0 -10px 35px rgba(15, 23, 42, .28);
    z-index: 1200;
  }
  .fcx-menu.is-open .fcx-menu__item {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 8px 12px;
    font-size: 15px;
    white-space: normal;
    border-radius: 8px;
  }
  .fcx-menu.is-open .fcx-menu__item:hover,
  .fcx-menu.is-open .fcx-menu__item:active { background: var(--fcx-accent); color: #fff; }
  .fcx-menu.is-open .fcx-menu__sep { margin: 6px 2px; }

  /* затемнение под шторкой */
  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 1150;
    display: none;
  }
  .mobile-menu-backdrop:not([hidden]) { display: block; }

  /* ---------- панель инструментов: один скролл-ряд ---------- */
  .fcx-toolbar {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    min-height: 50px;
    padding: 5px 8px;
    scrollbar-width: none;
  }
  .fcx-toolbar::-webkit-scrollbar { display: none; }
  .fcx-tool { width: 40px; height: 40px; border-radius: 6px; }
  .fcx-tool svg { width: 20px; height: 20px; }
  .fcx-sep { height: 26px; margin: 0 3px; }
  .fcx-grip { display: none; }

  /* ---------- дерево объектов ---------- */
  .sp12-tree__node--l1,
  .tree-node {
    min-height: 46px;
    padding: 6px 8px;
    gap: 6px;
  }
  .sp12-tree__node--l1 .sp12-tree__add {
    width: 44px;
    height: 44px;
    min-width: 44px;
    font-size: 20px;
    line-height: 1;
  }
  .sp12-tree__toggle {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }
  .sp12-tree__label,
  .tree-node__label { font-size: 14.5px; }

  /* плавающая кнопка «Дерево объектов» */
  .mobile-tree-fab.is-visible {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    right: 14px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 1050;
    height: 48px;
    padding: 0 18px;
    background: #1e293b;
    color: #fff;
    border: 1px solid #3b82f6;
    border-radius: 999px;
    font: 600 14px/1 -apple-system, "Segoe UI", Roboto, sans-serif;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .28);
    cursor: pointer;
  }
  .mobile-tree-fab.is-visible:active { transform: scale(.96); background: #0f172a; }

  /* ---------- таблицы ---------- */
  .mobile-table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    margin-bottom: 14px;
    background: #fff;
  }
  .mobile-table-wrapper table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    min-width: 620px;
  }
  .mobile-table-wrapper th:first-child,
  .mobile-table-wrapper td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    max-width: 165px;
    white-space: normal;
    word-break: break-word;
    box-shadow: 2px 0 6px rgba(15, 23, 42, .08);
  }
  .mobile-table-wrapper thead th:first-child { background: #f1f5f9; z-index: 3; }
  .mobile-table-wrapper input,
  .mobile-table-wrapper select {
    font-size: 16px !important;
    min-height: 40px;
    min-width: 82px;
    padding: 6px 8px;
    border-radius: 6px;
  }
  .mobile-table-wrapper td,
  .mobile-table-wrapper th { padding: 8px 10px; font-size: 13.5px; }
}
