/* Складно: мобильная версия (09.10.2026). Подключается ПОСЛЕ основного CSS; правит только экраны уже 860px. */
@media (max-width: 860px) {
  html, body { -webkit-text-size-adjust: 100%; }
  .app-main { height: 100vh; height: 100dvh; }
  /* снизу место под плавающую панель выбора склада */
  .app-content { padding: 14px 14px 92px; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }

  /* поля 16px - iOS не приближает страницу при фокусе; нажимаемое не ниже 44px */
  input, select, textarea { font-size: 16px !important; }
  input:not([type=checkbox]):not([type=radio]), select { min-height: 44px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; padding: 9px 16px; font-size: .8rem; }
  select { max-width: 100%; }

  /* заголовок экрана: название сверху, кнопки сеткой под ним */
  .panel-head { flex-direction: column; align-items: stretch !important; gap: 12px; margin-bottom: 14px; }
  .panel-head h2 { font-size: 1.25rem; }
  .panel-head > div + div { display: flex; flex-wrap: wrap; gap: 8px !important; }
  .panel-head > div + div > .btn { flex: 1 1 calc(50% - 8px); }
  .panel-head > div + .btn { width: 100%; }

  /* поиск во всю ширину */
  .table-toolbar { margin-bottom: 10px; }
  .table-toolbar input { max-width: none !important; flex: 1 1 100% !important; }
  /* разделы склада - одна лента, листается пальцем вбок */
  .table-toolbar + div[style*="flex-wrap"] {
    flex-wrap: nowrap !important; overflow-x: auto; margin: 0 -14px 12px !important; padding: 0 14px 4px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .table-toolbar + div[style*="flex-wrap"]::-webkit-scrollbar { display: none; }
  .table-toolbar + div[style*="flex-wrap"] > .btn { flex: none; white-space: nowrap; }

  /* таблицы - карточки: заголовка нет, строка = плитка */
  table.wh { display: block; overflow: visible; white-space: normal; }
  table.wh thead { display: none; }
  table.wh tbody { display: block; }
  table.wh tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
  table.wh tr:last-child { border-bottom: none; }
  table.wh td { display: block; padding: 0; border: 0; }
  table.wh td:first-child { flex: 1 1 100%; }
  table.wh tr.cat-row { display: block; padding: 0; margin: 10px -4px 0; border: 0; position: sticky; top: -1px; z-index: 2; }
  table.wh tr.cat-row td { padding: 10px 14px !important; border-radius: 10px; }

  /* «Склад и остатки» (6 колонок): название и статус, ниже остаток, склад и ячейка, внизу шкала */
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) tr:not(.cat-row) {
    display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) td:nth-child(1) { grid-column: 1; grid-row: 1; min-width: 0; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) td:nth-child(6) { grid-column: 2; grid-row: 1; justify-self: end; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) td:nth-child(3) { grid-column: 1; grid-row: 2; font-size: 1.05rem; font-weight: 600; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) td:nth-child(4) { grid-column: 2; grid-row: 2; justify-self: end; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) td:nth-child(2) { grid-column: 1 / -1; grid-row: 3; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) td:nth-child(5) { grid-column: 1 / -1; grid-row: 4; }
  /* пока правится остаток, форма занимает всю ширину карточки */
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) tr:has(td:nth-child(3) > form) td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; font-size: 1rem; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) tr:has(td:nth-child(3) > form) td:nth-child(3) > form { flex-wrap: wrap; gap: 8px !important; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) tr:has(td:nth-child(3) > form) td:nth-child(3) > form input { width: 110px !important; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) tr:has(td:nth-child(3) > form) td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; justify-self: start; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) tr:has(td:nth-child(3) > form) td:nth-child(2) { grid-row: 4; }
  table.wh:has(thead th:nth-child(6)):not(:has(thead th:nth-child(7))) tr:has(td:nth-child(3) > form) td:nth-child(5) { grid-row: 5; }
  table.wh td .stock-bar-wrap { width: 100%; height: 5px; }
  /* карандаш «исправить остаток» - нажимаемый палец */
  table.wh td .btn.btn-ghost.btn-sm[title="Исправить остаток"] { min-width: 44px; min-height: 36px; margin-left: 6px !important; padding: 4px 10px !important; }
  /* ячейка склада: поле с видимой рамкой */
  table.wh td input[placeholder="—"] { width: 84px !important; min-height: 38px !important; padding: 6px 8px !important; border-color: var(--line) !important; background: var(--surface-2) !important; font-size: 16px !important; }

  /* «Команда» (4 колонки): имя, почта; роль и статус рядом */
  table.wh:has(thead th:nth-child(4)):not(:has(thead th:nth-child(5))) td.wh-sub:nth-child(2) { flex: 1 1 100%; overflow-wrap: anywhere; }
  /* пересчёт инвентаризации (4 колонки): название, под ним учёт, поле «факт» и разница в одну строку */
  table.wh:has(thead th:nth-child(4)):not(:has(thead th:nth-child(5))) td.tabular:nth-child(2) { flex: 1 1 auto; }
  table.wh:has(thead th:nth-child(4)):not(:has(thead th:nth-child(5))) td.tabular:nth-child(2)::before { content: "По учёту "; color: var(--text-faint); font-size: .72rem; }
  table.wh:has(thead th:nth-child(4)):not(:has(thead th:nth-child(5))) td.tabular:nth-child(2) ~ td:nth-child(3) { display: flex; align-items: center; gap: 8px; }
  table.wh:has(thead th:nth-child(4)):not(:has(thead th:nth-child(5))) td.tabular:nth-child(2) ~ td:nth-child(3)::before { content: "Факт"; color: var(--text-faint); font-size: .72rem; }
  table.wh:has(thead th:nth-child(4)):not(:has(thead th:nth-child(5))) td.tabular:nth-child(2) ~ td:nth-child(3) input { width: 104px !important; font-size: 16px !important; padding: 6px 10px !important; }
  table.wh:has(thead th:nth-child(4)):not(:has(thead th:nth-child(5))) td.tabular:nth-child(2) ~ td:nth-child(4) { min-width: 56px; text-align: right; }
  /* «Прогноз» (7 колонок): плитка, показатели в две колонки */
  table.wh:has(thead th:nth-child(7)) td:not(:first-child) { flex: 1 1 calc(50% - 12px); font-size: .82rem; }

  /* заказы поставщикам */
  .order-row { padding: 14px; }
  .order-row { grid-template-columns: 1fr !important; }
  /* строка инвентаризации: название на всю ширину, прогресс и статус в ряд, кнопка внизу */
  .order-row[style*="auto auto auto"] { grid-template-columns: 1fr auto !important; }
  .order-row[style*="auto auto auto"] > :first-child, .order-row[style*="auto auto auto"] > .btn { grid-column: 1 / -1; }
  .order-row select { max-width: none !important; width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }
  .order-row > div:last-child { flex-wrap: wrap; }
  .order-row > div:last-child > .btn { flex: 1 1 auto; }
  .stepper { flex-wrap: wrap; row-gap: 6px; }

  /* канбан заявок: пустая колонка не занимает экран */
  .kanban-col { min-height: 0; }
  button.approve, button.reject { min-height: 42px; font-size: .85rem; }

  /* окна: снизу листом на всю ширину, кнопки во всю ширину */
  .modal-backdrop { align-items: flex-end; }
  .modal {
    width: 100vw !important; max-width: 100vw; max-height: 92vh; max-height: 92dvh; border-radius: 18px 18px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); border-bottom: 0;
  }
  .modal h3 { font-size: 1.1rem; }
  .modal-actions { position: sticky; bottom: -20px; background: var(--surface); padding: 12px 0 0; margin-top: 12px; }
  .modal-actions .btn { flex: 1 1 0; }
  .line-item-row { grid-template-columns: 1fr 1fr auto !important; align-items: end; }
  .line-item-row > :first-child { grid-column: 1 / -1; }
  .line-item-row .line-item-remove { min-width: 44px; }
  .add-line-btn { min-height: 44px; }

  /* плавающий выбор склада: узкая полоса внизу, без кнопки удаления */
  #cabinetSwitcherBar {
    left: 0 !important; right: 0 !important; bottom: 0 !important; border-radius: 14px 14px 0 0 !important;
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom)) !important; box-shadow: 0 -4px 16px rgba(0, 0, 0, .35) !important;
  }
  #cabinetSwitcherBar select { flex: 1 1 auto; max-width: none !important; min-width: 0; font-size: 16px !important; min-height: 40px; }
  #cabinetSwitcherDelete { display: none !important; }
  /* пока открыто окно, панель склада не перекрывает его кнопки */
  body:has(.modal-backdrop) #cabinetSwitcherBar { display: none !important; }
}
