/* =========================================================
   FORMULA ERP — ALL MODULES MOBILE CONTENT OPTIMIZATION
   Applies to module internals, not only the app shell.
========================================================= */
@media (max-width: 767.98px){
  /* Universal width safety */
  .page-content *, .modal-content *, .card *{max-width:100%;}
  .page-content .row, .modal-body .row{--bs-gutter-x:.65rem;--bs-gutter-y:.65rem;}
  .page-content .row>[class*="col-"], .modal-body .row>[class*="col-"]{min-width:0;}
  .page-content .table-responsive, .modal-body .table-responsive{width:100%;overflow-x:auto!important;}

  /* Module headers / toolbars */
  .fg-module-toolbar,.module-toolbar,.page-toolbar,.fg-page-toolbar{display:flex!important;flex-wrap:wrap!important;gap:8px!important;align-items:center!important;width:100%!important;}
  .fg-module-toolbar>*,.module-toolbar>*{min-width:0!important;}
  .fg-module-toolbar .search,.module-toolbar .search,.search-bar input{flex:1 1 180px!important;min-width:0!important;}
  .fg-module-toolbar .btn,.module-toolbar .btn{flex:0 0 auto!important;}

  /* Dashboard */
  .fg-dash,.dashboard,.dashboard-grid,.fg-dashboard-grid{width:100%!important;max-width:100%!important;}
  .fg-dash .row>[class*="col-"],.dashboard .row>[class*="col-"]{width:100%!important;flex:0 0 100%!important;max-width:100%!important;}
  .fg-stat-grid,.fg-kpi-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:8px!important;}
  .fg-chart-card,.fg-white-card,.fg-dash-card{min-width:0!important;overflow:hidden!important;}
  .fg-chart-card canvas,.fg-chart-card svg{max-height:260px!important;}

  /* Products / Warehouse / Stock */
  .products-table,.fg-products-table,.warehouse-table,.stock-table{min-width:760px!important;}
  .products-table td,.products-table th,.warehouse-table td,.warehouse-table th,.stock-table td,.stock-table th{font-size:11px!important;padding:8px 7px!important;}
  .products-table .actions,.warehouse-table .actions{white-space:nowrap!important;}
  .fg-product-grid,.fg-warehouse-grid,.fg-stock-grid,.product-form-grid{grid-template-columns:1fr!important;}
  .fg-product-form,.fg-warehouse-form,.fg-stock-form{width:100%!important;}

  /* Vendors / Users */
  .fg-vendor-info-grid,.fg-user-info-grid,.fg-vendor-edit-grid,.fg-user-edit-grid{grid-template-columns:1fr!important;}
  .fg-vendor-actions-head,.fg-user-actions-head{text-align:center!important;}
  .fg-vendor-actions-cell,.fg-user-actions-cell{justify-content:center!important;text-align:center!important;}
  .fg-vendor-actions,.fg-user-actions{justify-content:center!important;gap:5px!important;}
  .fg-vendor-action,.fg-user-action{width:40px!important;height:40px!important;min-width:40px!important;padding:0!important;}

  /* Orders / Invoices / Purchase Orders */
  .fg-order-form-grid,.fg-invoice-form-grid,.fg-po-form-grid,.fg-form-grid{grid-template-columns:1fr!important;gap:9px!important;}
  .fg-form-grid.two,.fg-form-grid.three,.fg-form-grid.four,.fg-form-grid.five{grid-template-columns:1fr!important;}
  .fg-form-grid>[class*="span-"],.fg-order-form-grid>[class*="span-"],.fg-invoice-form-grid>[class*="span-"]{grid-column:1/-1!important;}
  .fg-order-view-dialog,.fg-add-order-dialog,.fg-order-style-modal{width:100%!important;max-width:none!important;}
  .fg-order-modal-body,.fg-order-view-body{padding:10px!important;}
  .fg-order-modal-footer{gap:7px!important;}
  .fg-order-modal-footer .btn{flex:1 1 120px!important;}
  .fg-invoice-head-grid,.fg-invoice-grid{grid-template-columns:1fr!important;gap:9px!important;}
  .fg-invoice-summary-panel{grid-template-columns:1fr 1fr!important;gap:8px!important;}
  .fg-invoice-summary-panel>*{min-width:0!important;}
  .fg-invoice-table,.fg-inv-table,.purchase-orders-table{min-width:760px!important;}
  .fg-edit-item,.fg-invoice-item,.fg-order-item{width:100%!important;min-width:0!important;}
  .fg-item-fields{grid-template-columns:1fr!important;}
  .fg-item-fields>*{grid-column:1!important;min-width:0!important;}

  /* Reports */
  .report-shell,.r-shell,.reports-page{width:100%!important;max-width:100%!important;overflow:hidden!important;}
  .report-head,.r-head{display:flex!important;flex-wrap:wrap!important;gap:8px!important;}
  .report-filter-grid,.r-filter-grid{grid-template-columns:1fr!important;}
  .r-grid,.fg-stat-grid{grid-template-columns:1fr 1fr!important;}
  .r-layout{grid-template-columns:1fr!important;}
  .r-section{overflow:hidden!important;}
  .r-table{min-width:760px!important;}
  .r-table-wrap,.r-section .table-responsive{overflow-x:auto!important;-webkit-overflow-scrolling:touch!important;}
  .report-tabs,.r-tabs{display:flex!important;overflow-x:auto!important;flex-wrap:nowrap!important;white-space:nowrap!important;scrollbar-width:none!important;}
  .report-tabs::-webkit-scrollbar,.r-tabs::-webkit-scrollbar{display:none;}

  /* Email / Email accounts */
  .fg-email-account-grid,.fg-email-grid,.email-account-grid{grid-template-columns:1fr!important;}
  .fg-email-account-card,.fg-email-card,.fg-mail-card{width:100%!important;min-width:0!important;}
  .fg-email-card-actions,.fg-email-actions{display:flex!important;flex-wrap:wrap!important;gap:6px!important;}
  .fg-email-card-actions .btn,.fg-email-actions .btn{flex:1 1 120px!important;}
  .email-table{min-width:680px!important;}

  /* All custom section cards */
  .fg-form-section,.fg-form-card,.fg-section-card,.fg-ea-section,.fg-user-section,.fg-vendor-section,.fg-edit-section{width:100%!important;min-width:0!important;padding:11px!important;overflow:hidden!important;}
  .fg-form-section-head,.fg-edit-section-head{display:flex!important;flex-wrap:wrap!important;gap:6px!important;}
  .fg-form-section-head>*{min-width:0!important;}

  /* Action bars: no overflow, thumb-friendly */
  .fg-actions,.action-buttons,.table-actions,.fg-vendor-actions,.fg-user-actions,.fg-email-actions{max-width:100%!important;}
  .fg-actions .btn,.action-buttons .btn,.table-actions .btn{min-width:40px!important;min-height:40px!important;}

  /* View/detail pages */
  .detail-grid,.fg-detail-grid,.fg-info-grid,.view-grid{grid-template-columns:1fr!important;}
  .detail-grid>* ,.fg-detail-grid>*{min-width:0!important;}
  .detail-value,.fg-detail-value{overflow-wrap:anywhere!important;word-break:break-word!important;}

  /* Attachments / history */
  .attachment-list,.history-list,.audit-list{width:100%!important;overflow:hidden!important;}
  .attachment-list .btn,.history-list .btn{max-width:100%!important;white-space:normal!important;}

  /* Prevent long values from forcing the viewport wider */
  code,pre,.text-break,.sku,.invoice-number,.order-number,.vendor-code,.email-address{overflow-wrap:anywhere!important;word-break:break-word!important;}

  /* Sticky action footer inside long forms */
  .fg-sticky-actions,.form-sticky-actions{position:sticky!important;bottom:0!important;z-index:8!important;background:#fff!important;padding:9px 0 calc(9px + env(safe-area-inset-bottom,0px))!important;box-shadow:0 -5px 15px rgba(15,23,42,.06)!important;}
}

@media (max-width: 480px){
  .fg-stat-grid,.fg-kpi-grid,.r-grid,.fg-invoice-summary-panel{grid-template-columns:1fr!important;}
  .page-content .btn,.modal-body .btn{max-width:100%;}
  .fg-module-toolbar .btn,.module-toolbar .btn{width:100%!important;}
  .fg-actions .btn,.action-buttons .btn{flex:1 1 44px!important;}
  .fg-form-section,.fg-form-card,.fg-section-card,.fg-ea-section,.fg-user-section,.fg-vendor-section,.fg-edit-section{padding:9px!important;border-radius:11px!important;}
  .fg-form-section-head h5,.fg-edit-section-head h5{font-size:13px!important;}
}
