/* Mobile / PWA layer.
 *
 * The desktop CSS lives in styles.css; this file only adds responsive
 * behaviour for screens ≤ 900px (tablets and phones). The pattern:
 *   - Hide the sidebar by default on mobile, slide it in via .sidebar-open
 *   - Show the hamburger button (hidden on desktop)
 *   - Stack two-column grids vertically
 *   - Make tables horizontally scrollable instead of squishing
 *   - Larger tap targets, denser typography
 */

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid rgba(0,0,0,0.15);
  color: inherit;
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  margin-right: 10px;
}
.mobile-menu-btn:active { transform: scale(0.95); }

.top-bar-left { display: flex; align-items: center; gap: 6px; }

@media (max-width: 900px) {
  /* ---- Layout ---- */
  body { font-size: 14px; }
  .app { grid-template-columns: 1fr !important; }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 50;
    box-shadow: 2px 0 12px rgba(0,0,0,0.25);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 49;
  }
  .mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; }

  /* ---- Top bar ---- */
  .top-bar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .top-bar h1 { font-size: 17px; margin: 0; }
  .hospital-name-top { font-size: 11px; }
  .top-bar-right { width: 100%; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
  .global-search { flex: 1; min-width: 180px; }
  .global-search input { width: 100%; }
  #actingAsSelect { max-width: 160px; }
  #clock { display: none; }

  /* ---- Content ---- */
  .page-content { padding: 12px; }
  .card { padding: 12px; }
  .grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; gap: 10px !important; }
  .stat .num { font-size: 24px; }

  /* Tables → horizontal scroll instead of squishing */
  .card > table, .card table { display: block; overflow-x: auto; max-width: 100%; }
  table { font-size: 13px; }
  th, td { padding: 6px 8px !important; white-space: nowrap; }

  /* Forms — full width inputs */
  input, select, textarea { width: 100% !important; box-sizing: border-box; font-size: 16px; /* prevents iOS zoom */ }
  .form-row, .form-row-3 { grid-template-columns: 1fr !important; }

  /* Modals → full-screen on phones */
  .modal { width: 95vw !important; max-width: 95vw !important; max-height: 90vh; overflow-y: auto; }

  /* User menu — keep visible but compact */
  .user-pill #userMenuName { display: none; }
  .dept-badge { font-size: 10px; padding: 2px 6px; }

  /* Buttons — comfortable tap target */
  .btn-primary, .btn-secondary, .btn-danger, .btn-ghost { min-height: 38px; padding: 8px 14px; }
  .btn-sm { min-height: 30px; padding: 4px 10px; font-size: 12px; }
}

@media (max-width: 480px) {
  /* Phones — squeeze further */
  .top-bar h1 { font-size: 15px; }
  .stat .num { font-size: 20px; }
  .stat .lbl { font-size: 11px; }
  th, td { font-size: 12px; }
  /* Hide the global-search results dropdown stretching off-screen */
  .global-results { max-height: 60vh; overflow-y: auto; }
}

/* Connection-status banner shown when service worker reports offline */
.offline-banner {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  display: none;
}
body.is-offline .offline-banner { display: block; }
