/* =========================================================
   Mobile.css — Compassion Industries ERP
   Phone-first layout. Activates below 820px viewport width.
   - Sidebar lives as a left drawer (toggled by ☰ in topbar)
   - Locked viewport: content scrolls inside .main only
   - Single-column grids, scrollable tables inside cards
   - Modals as bottom sheets, safe-area aware
   ========================================================= */

@media (max-width: 820px) {

  /* ---------- Lock the page so nothing rubber-bands ---------- */
  html, body {
    overflow: hidden;
    overscroll-behavior: none;
    width: 100%;
    height: 100%;
    position: fixed;
  }

  /* ---------- App grid: full width, sidebar overlays ---------- */
  .app {
    grid-template-columns: 1fr;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* ---------- Sidebar drawer (existing toggleDrawer JS controls .open) ---------- */
  .sidebar {
    width: 280px;
    max-width: 84vw;
    padding-top: max(18px, env(safe-area-inset-top));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  /* ---------- Main content scrolls inside its own area ---------- */
  .main {
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: calc(env(safe-area-inset-top) + 16px) 16px 28px 16px;
    box-sizing: border-box;
  }

  /* ---------- Topbar: app-style header bar ---------- */
  .topbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
  }
  .menu-btn {
    width: 44px !important;
    height: 44px !important;
    font-size: 22px !important;
    border-radius: 10px !important;
    flex-shrink: 0;
  }
  .topbar > div:first-of-type {
    flex: 1;
    min-width: 0;
  }
  .topbar h1 {
    font-size: 19px;
    margin: 0;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar .meta {
    font-size: 11.5px;
    line-height: 1.35;
    white-space: normal;
    word-break: break-word;
  }
  /* Hide export/import buttons on Gate Receipts page */
  body[data-current-view="gate"] [data-hide-on-gate] { display: none !important; }
  .topbar .actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }
  .topbar .actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }
  .topbar .btn,
  .topbar .userPill,
  #syncDot {
    font-size: 10.5px;
    padding: 6px 8px;
    white-space: nowrap;
  }
  /* Trim the email pill on phones */
  .userPill .em {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: bottom;
  }

  /* ---------- Cards & layouts (single column) ---------- */
  .row { gap: 10px; }
  .card { padding: 14px; border-radius: 10px; }
  .card h3 { font-size: 13px; }
  .grid2, .grid3 { grid-template-columns: 1fr; gap: 10px; }
  .form-grid,
  .form-grid.three,
  .form-grid.four { grid-template-columns: 1fr; gap: 10px; }
  .kpi { min-width: 0; }
  .kpi .v { font-size: 22px; }

  /* ---------- Inputs comfortable on touch ---------- */
  input, select, textarea, .btn {
    font-size: 14px;
    min-height: 38px;
  }
  textarea { min-height: 70px; }
  label { font-size: 11.5px; }

  /* ---------- Tables: horizontal scroll inside their card ---------- */
  table { font-size: 12.5px; }
  th, td { padding: 7px 6px; }
  .card table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* ---------- Toolbar inside cards (title + button) ---------- */
  .toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .toolbar .left { width: 100%; }
  .search { max-width: 100%; }

  /* ---------- Modals: bottom-sheet style ---------- */
  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    padding: 18px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  .modal-bg {
    padding: 0;
    align-items: flex-end;
  }
  .modal h2 { font-size: 17px; }

  /* ---------- Auth screen ---------- */
  #authBox {
    padding: 24px 22px;
    border-radius: 16px;
    width: 100%;
    max-width: 92%;
  }
  #authLogoWrap { min-height: 64px; }
  #authLogoWrap img {
    max-width: 200px;
    max-height: 64px;
  }

  /* ---------- Gate alert banner ---------- */
  #gateAlertBanner {
    font-size: 12px;
    padding: 9px 12px;
    padding-top: max(9px, env(safe-area-inset-top));
  }
  #gateAlertBanner button {
    padding: 5px 10px !important;
    font-size: 11px !important;
  }

  /* ---------- Gate receipt cards: photo on top, details below ---------- */
  .gate-card-img {
    width: 100% !important;
    max-width: 360px;
    margin: 0 auto;
  }

  /* ---------- Verify-line cards inside modals ---------- */
  .modal .form-grid.four,
  .modal .form-grid.three { grid-template-columns: 1fr; }

  /* ---------- Touch-comfortable nav buttons in drawer ---------- */
  .nav button {
    padding: 12px 12px;
    font-size: 14px;
  }

}

/* ---------- Tiny phones ---------- */
@media (max-width: 380px) {
  .main { padding: 12px 12px 20px 12px; }
  .topbar h1 { font-size: 16px; }
  .card { padding: 12px; }
  .kpi .v { font-size: 20px; }
}
