/* MillPulse Global Mobile CSS — v1
   Single file fix for ALL pages. Edit here, deploy once, everything updates.
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
@import url('mp-theme.css?v=20260803');
@import url('app-ui.css?v=20260803');

/* ═══════════════════════════════════════════════════════════════
   GLOBAL SAFETY NETS (all viewports)
   Prevent media/embeds from forcing horizontal scroll. Applies
   everywhere so any page (incl. new ones) benefits automatically.
   ═══════════════════════════════════════════════════════════════ */
img, svg, video, canvas, iframe { max-width: 100%; }
img, video, canvas { height: auto; }

/* Flex/grid children must be allowed to shrink so wide tables scroll
   inside .table-wrap instead of forcing the page sideways. */
.app, .main, .main-content, .content, .card, .panel, .section-card {
  min-width: 0;
}
html, body {
  max-width: 100%;
}

/* Bottom nav removed from sub-pages — sidebar handles navigation.
   The main index.html tab switcher (mobile-bottom-nav) stays but hides when modal is open. */

/* Hide bottom nav when any modal overlay is open, so buttons aren't blocked */
body.modal-open .mobile-bottom-nav,
.modal-overlay.open ~ .mobile-bottom-nav,
.modal-overlay.open + .mobile-bottom-nav {
  display: none !important;
}

/* Also bump modal max-height to not be cut off by bottom nav */
@media (max-width: 640px) {
  .modal {
    max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top, 0px))) !important;
  }
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE — max-width 640px
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

  /* Show bottom nav */
  /* ── Layout: collapse all 2-col grids ─────────────────────── */
  .app,
  .page-shell,
  .da-shell,
  .shell,
  .app-layout,
  .ws-layout,
  .workspace-layout,
  .layout,
  .pitch-hero {
    display: block !important;
    grid-template-columns: 1fr !important;
  }

  /* Prevent any stray horizontal scroll on phones */
  body { overflow-x: hidden !important; }

  /* ── Hide ALL static sidebars (sidebar.js drawer handles mobile) */
  aside.sidebar,
  .sidebar,
  nav.sidebar,
  .ws-sidebar,
  .workspace-sidebar {
    display: none !important;
  }

  /* ── Main content: full width, breathable padding ─────────── */
  .main,
  .main-content,
  .main-wrap,
  .content,
  .page-content,
  .inner,
  .da-main,
  .ws-main,
  .ws-content,
  .workspace-content {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    padding: 0.85rem !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  /* ── Topbars: compact ─────────────────────────────────────── */
  .top, .topbar, header.top, .navbar, .mp-topnav {
    padding: 0.55rem 0.85rem !important;
    flex-wrap: wrap !important;
    gap: 0.4rem !important;
  }

  /* ── Typography ───────────────────────────────────────────── */
  h1, .page-title { font-size: 1rem !important; }
  h2 { font-size: 0.95rem !important; }
  h3 { font-size: 0.88rem !important; }

  /* ── Tables: scroll horizontally inside wrapper ───────────── */
  .table-wrap,
  .table-container,
  .ws-table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
    width: 100% !important;
  }
  /* Unwrapped tables: self-contained scroll box */
  table {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    font-size: 0.78rem !important;
  }
  /* Wrapped tables: keep real table layout; wrapper scrolls */
  .table-wrap > table,
  .table-container > table,
  .ws-table-wrap > table {
    display: table !important;
    width: max-content !important;
    min-width: 100% !important;
    max-width: none !important;
    overflow: visible !important;
  }
  th, td { padding: 0.4rem 0.6rem !important; white-space: nowrap !important; }

  /* ── Cards and grids: single column ──────────────────────────
     Broad net: any element whose class contains "grid"/"cols", any
     element with an inline grid-template-columns, plus the common
     bespoke grid/row class names used across module pages. This makes
     multi-column layouts collapse to one column automatically. */
  [class*="grid"],
  [class*="cols"],
  [style*="grid-template-columns"],
  .card-grid, .cards-container, .stats-grid,
  .kpi-grid, .report-type-grid, .form-grid, .form-grid-2, .form-grid-3,
  .form-row, .stat-cards, .stat-row, .metrics, .kpis,
  .handover-summary-grid, .two-col {
    grid-template-columns: 1fr !important;
    gap: 0.65rem !important;
  }
  .card, .kpi-card, .stat-card {
    padding: 0.85rem !important;
    border-radius: 12px !important;
  }

  /* ── Modals: slide up from bottom like native iOS ─────────── */
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
    z-index: 400 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  .modal {
    max-width: 100% !important;
    width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important; left: 0 !important; right: 0 !important; top: auto !important;
    max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top, 0px))) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 1.25rem 1rem !important;
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px)) !important;
    box-sizing: border-box !important;
    margin: 0 !important;
  }

  /* ── Forms: prevent iOS zoom, full width ─────────────────── */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="search"], input[type="date"],
  select, textarea {
    font-size: 16px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }
  .field, .form-group, .form-field { width: 100% !important; }

  /* ── Buttons: comfortable touch targets ───────────────────── */
  .btn, button.btn { min-height: 44px !important; font-size: 0.85rem !important; }

  /* Nav / tab / back links get real tap targets (>=44px) */
  .mp-topnav a, .back-link, .back-btn, .back,
  .tab, .hub-tab, .cat-pill, .nav-tab, .hub-tabs button {
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
  }

  /* Trim oversized desktop padding on common content containers */
  .container, .page, .page-inner, .wrap, .content-wrap, .section, .panel {
    padding-left: 0.9rem !important;
    padding-right: 0.9rem !important;
  }
  .modal-actions, .action-row, .btn-row {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
  }
  .modal-actions .btn { flex: 1 !important; justify-content: center !important; }

  /* ── User management specific ─────────────────────────────── */
  .search-wrap { flex-direction: column !important; align-items: stretch !important; }
  .search-input { min-width: 0 !important; width: 100% !important; }
  .mill-pills { flex-wrap: wrap !important; gap: 0.25rem !important; }
  .um-col-secondary { display: none !important; }
  .um-toolbar { align-items: stretch !important; }
  #filterRole { width: 100% !important; }

  /* Header stacks vertically so buttons are always visible */
  .top, header.top {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.65rem !important;
    padding: 0.75rem 0.85rem !important;
  }

  /* Avoid double-padding: pad header/content, not the whole .main shell */
  .app > .main {
    padding: 0 !important;
  }
  .app > .main > .content {
    padding: 0.85rem !important;
  }

  /* Button row: full width, buttons share space evenly */
  .um-actions,
  .top > div:last-child,
  header.top > div[style*="display:flex"],
  header.top > div[style*="display: flex"] {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 0.45rem !important;
    align-items: center !important;
  }

  /* Each button in the header row gets equal space */
  .um-actions .btn,
  header.top .btn {
    flex: 1 1 auto !important;
    min-width: 110px !important;
    justify-content: center !important;
    display: flex !important;
    align-items: center !important;
    font-size: 0.78rem !important;
    padding: 0 0.65rem !important;
  }

  /* Stats grid: 2 cols on phone instead of 4 */
  #statsRow {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── Workspace specific ───────────────────────────────────── */
  .ws-file-item, .file-card {
    padding: 0.65rem !important;
    font-size: 0.82rem !important;
  }

  /* ── Toast: above bottom nav ──────────────────────────────── */
  .toast {
    bottom: 70px !important;
    left: 0.75rem !important;
    right: 0.75rem !important;
    width: auto !important;
  }

  /* ── Hide desktop-only clutter ────────────────────────────── */
  .desktop-only,
  .lang-switcher,
  .lang-pills,
  #installAppBtn,
  #themeToggle { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════════
   TABLET — 641px to 1024px
   ═══════════════════════════════════════════════════════════════ */
@media (min-width: 641px) and (max-width: 1024px) {
  .app, .app-layout {
    grid-template-columns: 200px 1fr !important;
  }
  .card-grid, .cards-container, .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ── Sidebar: full-page drawer on mobile (prevents flash before JS) ── */
@media (max-width: 640px) {
  .mp-sidebar:not([data-sb-ready]) {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    transform: translateX(-100%) !important;
    pointer-events: none !important;
    overflow: hidden !important;
  }
}
