/*
  Планшет (iPad, Android 8–13", обе ориентации) и вообще любой сенсорный экран шире телефона (от 741 px).
  Навигация — выезжающая панель ☰ (mobile.css, при касании до 1400 px); страницы остаются «настольными», но:
    • всё нажимаемое не меньше 44 px; поля ввода 16 px (iPad иначе приближает страницу при касании);
    • таблицы, графики и доска листаются пальцем внутри своей рамки, страница вбок не уезжает;
    • окна не выше экрана, внутри прокручиваются; поля и сетки перестраиваются под ширину;
    • перетаскивание пальцем (задержать ~0,35 с на карточке, операции, полосе задания) — скрипт touch_drag.js.
  Подключается последним (после mobile.css).
*/
@media (pointer: coarse) and (min-width: 741px) {
  html, body { max-width: 100%; -webkit-text-size-adjust: 100%; }
  .content { padding: 0 16px 36px; }
  .page-header { padding-top: 16px; }
  .block { padding: 16px; }
  .block-head { flex-wrap: wrap; gap: 8px 10px; }
  .block-title { min-width: 0; }

  /* Нажимаемое: не меньше 44 px */
  button, .btn, [role=button], .primary-btn, .secondary-btn, .danger-btn, .toolbar-btn, .mini, .sp-btn, .wt-btn, .nav-link, .nav-btn,
  .kb-tab, .adm-tab, .issue-btn, .m-switch-btn { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; font-size: 16px; }
  .hint-btn { width: 30px; height: 30px; min-height: 0; font-size: 13px; position: relative; }
  .hint-btn::after { content: ''; position: absolute; inset: -8px; }                 /* область касания шире значка */
  .modal-close, .task-modal-close, #task-modal-close { min-width: 44px; min-height: 44px; font-size: 26px; }
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea { font-size: 16px; min-height: 44px; }
  select[multiple], textarea { min-height: 0; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  label:has(> input[type=checkbox]), label:has(> input[type=radio]) { min-height: 36px; display: inline-flex; align-items: center; gap: 8px; }
  table td > a, table td > button { min-height: 36px; }
  table td > a { display: inline-flex; align-items: center; }
  .gs-box { min-height: 44px; }
  .master-tab, .adm-toc-i, .block-link { min-height: 40px; display: inline-flex; align-items: center; }
  .er-mini { min-height: 36px; padding: 4px 12px; font-size: 13px; }
  .col-hint-btn { position: relative; }
  .col-hint-btn::after { content: ''; position: absolute; inset: -6px -10px; }
  input.cp-done { width: 28px; height: 28px; }

  /* Таблицы и графики листаются внутри своей рамки */
  .table-wrap, .tt-wrap, .cp-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .gantt-timeline, .gantt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .board-row { overflow-x: auto; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
  .kanban-column { scroll-snap-align: start; }
  .column-body, .modal-content, .ca-dialog, .task-modal { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

  /* Окна: не выше экрана, внутри прокручиваются */
  .modal, .ca-modal, .task-modal-backdrop { padding: 12px !important; align-items: center; justify-content: center; }
  .modal-content, .ca-dialog, .task-modal { max-width: min(96vw, 900px); max-height: 94dvh; overflow-y: auto; overflow-x: hidden; }
  .modal-content.modal-content-wide, .modal-content-wide, .ca-dialog.rep-dialog, .ca-dialog.wide { max-width: min(96vw, 1040px); }
  .modal-header { position: sticky; top: -24px; z-index: 2; background: var(--c-surface); padding-top: 4px; }
  .modal-footer, .task-modal-foot, .ca-actions { flex-wrap: wrap; gap: 8px; }

  /* Сетки подстраиваются под ширину, а не вылезают за экран */
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px 6px; }
  .metrics-bar .metric-divider { display: none; }
  .toolbar, .page-actions { flex-wrap: wrap; gap: 8px; }
  [class*="legend"] { flex-wrap: wrap; }
  img, video, canvas, svg { max-width: 100%; }

  /* Перетаскивание пальцем: без выделения и системного меню */
  [draggable="true"], .gantt-bar, .gantt-row-label { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  [draggable="true"], .gantt-bar { touch-action: none; }      /* иначе браузер забирает жест под прокрутку; листать — за пустое место и заголовки */
  [draggable="true"] { -webkit-user-drag: none; }
  html.td-dragging, html.td-dragging * { -webkit-user-select: none; user-select: none; }
  .td-ghost { border-radius: 10px; }
}

/* Сенсорные экраны любого размера: у карточек и полос заданий нет выделения при долгом касании */
@media (pointer: coarse) {
  [draggable="true"], .gantt-bar { -webkit-touch-callout: none; }
}

/* Планшет вертикально (741–1000 px): сетки плиток в два столбца, панели переносятся */
@media (pointer: coarse) and (min-width: 741px) and (max-width: 1000px) {
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rep-pick, .kb-cols, .oc-grid, .viz-body { grid-template-columns: 1fr; }
  .adm-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kb-tabs, .tabs { flex-wrap: wrap; }
}

/* Помощник ИИ: на планшете компактная круглая кнопка, не закрывающая содержимое */
@media (pointer: coarse) and (min-width: 741px) {
  .aiw-fab { width: 76px !important; height: 76px !important; right: 16px !important; bottom: 16px !important; opacity: .94; }
  .aiw-fab-label { display: none !important; }
  .aiw-fab-icon { font-size: 32px !important; }
  .gs-key { display: none !important; }
}
