/* ═════════════════════════════════════════════════════════════════════
   WBIS MOBILE FIX — wbis_mobile.css
   One additive stylesheet included by EVERY page across all modules.
   Zero functional changes: pure responsive safety-net rules so every
   page is usable on phones/tablets (≤768px, plus small-phone 480px).

   Design targets:
   • No horizontal page scrolling
   • Tables scroll inside their cards instead of breaking layout
   • Grids collapse to single columns
   • Inputs keep 16px font (prevents iOS auto-zoom on focus)
   • Bigger tap targets (44px minimum)
   • Modals / sidebars / toolbars adapt to small screens
   ═════════════════════════════════════════════════════════════════════ */

html, body { max-width: 100%; overflow-x: hidden; }
img, video, canvas, iframe, svg { max-width: 100%; }

/* 1. TABLES: wrap in scroll containers instead of blowing out layout */
table { min-width: 0; }
@media (max-width: 820px) {
  .tablecard, .table-wrap, .table-responsive, .card > table, .panel > table,
  .section-card table, .gm-table, .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 640px; }            /* keep rows readable, scroll sideways */
  .tablecard table, .table-wrap table { min-width: 560px; }
  th, td { padding: 9px 10px !important; font-size: 12.5px !important; white-space: nowrap; }
  td.wrap, td.wrap-text { white-space: normal !important; }
}

/* 2. GRIDS collapse on small screens */
@media (max-width: 768px) {
  .stats-grid, .kpis, .stat-cards, .cards-grid,
  .gm-tiles, .scheme, .toolbar, .tabs, .act-grid,
  .quick-actions, .kpi-row, .summary-cards { grid-template-columns: 1fr 1fr !important; display: grid; }
  .kpis, .stats-grid { gap: 8px !important; }
  .wla-panel { padding: 14px !important; margin: 12px 0 !important; }
  .wla-panel #chips, .wla-panel > div[style*="auto-fill"] { grid-template-columns: 1fr 1fr !important; }
  [style*="grid-template-columns: 1fr 1fr"], [style*="grid-template-columns:repeat(2"] { grid-template-columns: 1fr !important; }
}

@media (max-width: 520px) {
  .stats-grid, .kpis, .gm-tiles, .cards-grid, .quick-actions { grid-template-columns: 1fr 1fr !important; }
  [class*="grid"] { }
  .sidebar, .sidenav, .side-nav { position: fixed !important; z-index: 200; transform: translateX(-100%); transition: transform .25s ease; width: 250px !important; max-width: 82vw !important; }
  .sidebar.open, .sidenav.open, .side-nav.open, body.nav-open .sidebar { transform: translateX(0); }
  .main-content, .main, .content, #contentArea { margin-left: 0 !important; width: 100% !important; padding: 12px !important; }
}

/* 3. FORM CONTROLS: 16px stops iOS zoom; comfortable tap targets */
@media (max-width: 820px) {
  input, select, textarea { font-size: 16px !important; }
  input:not([type="checkbox"]):not([type="radio"]), select, button, .btn, a.btn { min-height: 42px; }
  .btn, button { padding: 10px 14px !important; }
  .btn.sm, button.sm { min-height: 36px; padding: 7px 10px !important; }
  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar input[type=text], .toolbar select { flex: 1 1 100% !important; min-width: 0 !important; width: 100%; }
}

/* 4. TOP BARS / HEADERS wrap and shrink */
@media (max-width: 768px) {
  header, .topbar, .res-header, .hdr-right, .topbar-right, .top-right { flex-wrap: wrap !important; }
  .topbar, header { padding: 10px 12px !important; gap: 10px; }
  .topbar-title h1, h1 { font-size: 17px !important; }
  .topbar-title small, .brand .sub { font-size: 10.5px !important; }
  .topbar-logo, .brand .logo { width: 40px !important; height: 40px !important; }
  .brand h1 { font-size: 15px !important; }
  .chip, .hdr-chip { font-size: 11px !important; padding: 6px 10px !important; }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; padding-bottom: 4px; }
  .tab { flex: 0 0 auto; padding: 9px 14px !important; font-size: 12px !important; }
}

/* 5. MODALS fit small screens */
@media (max-width: 640px) {
  .modal, .m-modal, .modal-dialog, .modal-content { width: 94vw !important; max-width: 94vw !important; margin: 10px auto !important; max-height: 86vh; overflow-y: auto; }
  .modal-body, .modal { padding: 16px !important; }
  .frow input, .frow select, .frow textarea { font-size: 16px !important; }
  .mfoot { flex-wrap: wrap; }
  .mfoot .btn { flex: 1 1 100%; }
}

/* 6. BULK BAR / STICKY ELEMENTS stay reachable on phones */
@media (max-width: 768px) {
  .bulkbar { flex-wrap: wrap; justify-content: center; left: 3vw !important; right: 3vw !important; width: 94vw !important; transform: none !important; bottom: 10px !important; gap: 6px !important; padding: 10px !important; }
  .bulkbar .btn { flex: 1 1 45%; font-size: 11.5px; }
  .toasts { left: 10px; right: 10px; top: 10px; }
  .toast { max-width: 100% !important; font-size: 12.5px; }
}

/* 7. SCANNER page specifics */
@media (max-width: 768px) {
  .scanner-viewport { aspect-ratio: 3/4; }
  .class-chip { min-width: 45% !important; }
  .toolbar-left, .toolbar-right { flex-wrap: wrap; gap: 6px; }
  .container { padding: 10px !important; }
}

/* 8. DASHBOARD specific: overview grids + hero cards stack */
@media (max-width: 768px) {
  .welcome-banner { padding: 14px !important; }
  .stat-card { padding: 12px !important; }
  .stat-info h4, .stat-value { font-size: 18px !important; }
  [style*="grid-template-columns: 1fr 1fr 1fr"], [style*="repeat(3"], [style*="repeat(4"], [style*="repeat(5"] { grid-template-columns: 1fr 1fr !important; }
  section, .card { margin-bottom: 12px; }
  .gm-tiles .gm-tile { padding: 12px !important; }
}

/* 9. Small phones (≤380px) — single column everywhere */
@media (max-width: 380px) {
  .stats-grid, .kpis, .gm-tiles, .class-chip { grid-template-columns: 1fr !important; min-width: 0 !important; }
  .class-chip { min-width: 100% !important; }
  h1 { font-size: 15px !important; }
}
