/* ==========================================================================
   TDG - Mobile Controls Guard
   Keep editable text >= 16px on touch/mobile so iOS/Android does not zoom on focus.
   Loaded LAST in the cascade, never shrink with transform or disable pinch zoom.
   ========================================================================== */

@media screen and (hover: none) and (pointer: coarse) {
  /* Wide document tables can make mobile innerWidth exceed clientWidth.
     Bootstrap mistakes that horizontal overflow for a scrollbar and pads the
     body by hundreds of pixels. Keep the page stable behind the shared modal. */
  html body.modal-open:has(#shared-modal.show) {
    padding-right: 0 !important;
  }
}

@media screen and (max-width: 1024px), screen and (hover: none) {
  html body input:not([type=hidden]):not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=button]):not([type=submit]):not([type=reset]),
  html body textarea,
  html body select,
  html body [contenteditable=true],
  html body .ts-control,
  html body .ts-control input,
  html body .topbar-search input,
  html body .sidebar-search input,
  html body .dt-input,
  html body .app-compact-control {
    font-size: 16px !important;
    line-height: 1.35;
  }

  html body .form-control,
  html body .form-select,
  html body .app-filter-grid .form-control,
  html body .app-filter-grid .form-select,
  html body .app-filter-grid .ts-control,
  html body .app-table-popup .form-control {
    min-height: 38px;
    height: 38px;
  }

  /* 08/11/2026: hàng bộ lọc cao đều 38px. Ô chọn Tom Select (hl-controls.css: html[data-ui-skin] … .ts-control 32px) và nút
     Lọc/Hủy (filters.css 32px) cụ thể hơn quy tắc trên nên trước đây thấp hơn ô ngày/ô tìm 38px → hàng lọc bị lệch. */
  html[data-ui-skin] body .app-filter-grid .ts-wrapper.hl-ts .ts-control,
  html body .app-filter-grid .filter-actions .btn {
    min-height: 38px;
    height: 38px;
  }

  html body .app-detail-page .app-compact-control:is(.form-control, .form-select) {
    height: 38px;
    min-height: 38px;
  }

  html body .app-workflow-modal .app-compact-control:is(.form-control, .form-select),
  html body .ts-wrapper.hl-ts .ts-control,
  html body .hl-daterange {
    height: 38px;
    min-height: 38px;
  }

  html body .app-detail-page textarea.app-compact-control.form-control,
  html body .app-workflow-modal textarea.app-compact-control.form-control {
    height: auto;
    min-height: 72px;
  }

html body .topbar :is(.sidebar-toggle, #theme-toggle, .navbar-profile),
  html body .sidebar-mobile-close,
  html body .page-actions > .btn,
  html body .filter-actions .btn,
  html body .app-table-toolbar .btn,
  html body .app-line-bulk-actions .btn,
  html body .app-table-empty-clear,
  html body [data-result-pagination] .btn,
  html body .dt-paging .dt-paging-button {
    min-height: 44px;
    height: auto;
  }
  html body .topbar :is(.sidebar-toggle, #theme-toggle, .navbar-profile),
  html body .sidebar-mobile-close,
  html body .dt-paging .dt-paging-button {
    min-width: 44px;
  }
  html body .app-table-popup label {
    min-height: 44px;
  }
  html body .filter-toggle-btn {
    min-height: 38px;
    min-width: 38px;
    height: 38px;
  }
  html body .warehouse-sidebar :is(.nav-link, .menu-summary) {
    min-height: 44px;
  }
}

/* 05/11/2026: hàng nút đầu trang trên điện thoại — nút giữ đủ chữ và xuống dòng khi chật (trước đây flex:1 cơ sở 0 nén cả hàng làm chữ đè nhau). */
@media (max-width: 767px) {
  html body .page-actions > :is(.btn, .dropdown) { flex: 1 1 auto; white-space: nowrap; }
}

/* 09/11/2026: token kích thước trên màn chạm/hẹp — mọi thành phần dùng --app-control-h(-sm) đạt tối thiểu 38px. */
@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
  html[data-ui-skin] { --app-control-h: 38px; --app-control-h-sm: 38px; }
  html[data-ui-skin="hl"] [data-attachment-card] .app-attachment-bottom :is(.form-select, .form-control, .ts-wrapper.hl-ts .ts-control) { height: 38px; min-height: 38px !important; font-size: 16px !important; }
}
