/* =============================================================================
   HRx Dashboard — phone / small-tablet layout (loaded after app.css + theme)
   - Sidebar becomes an off-canvas drawer opened from a hamburger in the topbar
   - Content goes single-column, tables scroll sideways, modals go full screen
   - Honors iPhone safe areas (notch / home indicator)
   ============================================================================= */

.mnav-btn, .mnav-backdrop { display: none; }

@media (max-width: 820px) {
  html, body { overflow-x: clip; }
  body { font-size: 15px; -webkit-text-size-adjust: 100%; }

  /* ── Drawer ─────────────────────────────────────────────────────────── */
  .sidebar {
    width: min(84vw, 300px) !important; min-width: 0 !important;
    transform: translateX(-102%); transition: transform .24s cubic-bezier(.2,.8,.2,1);
    z-index: 960; box-shadow: none;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  body.mnav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .sidebar .sidebar-item, .sidebar .sidebar-action-btn { min-height: 44px; }
  .mnav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 955; background: rgba(8,15,30,.5);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.mnav-open .mnav-backdrop { opacity: 1; pointer-events: auto; }
  body.mnav-open { overflow: hidden; }

  .main-wrap { margin-left: 0 !important; width: 100%; min-width: 0; }

  /* ── Topbar ─────────────────────────────────────────────────────────── */
  .topbar {
    height: auto; min-height: 52px; padding: env(safe-area-inset-top) 12px 0 6px;
    gap: 8px;
  }
  .topbar-left { min-width: 0; flex: 1; gap: 6px; }
  .topbar-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-right { flex-shrink: 0; }
  .mnav-btn {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 44px; height: 44px; border: 0; background: transparent; color: var(--text);
    border-radius: 10px; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .mnav-btn:active { background: rgba(127,127,127,.15); }
  .mnav-btn svg { width: 22px; height: 22px; }
  #topAddHotelBtn { display: none !important; }

  /* ── Content ────────────────────────────────────────────────────────── */
  .main { padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); min-width: 0; }
  .main .page { min-width: 0; }
  .main .page * { min-width: 0; }
  .main img, .main canvas, .main svg { max-width: 100%; }
  .chart-wrap { max-width: 100%; }

  .kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 10px; margin-bottom: 14px; }
  .kpi-card { padding: 12px; border-radius: 12px; }
  .kpi-value { font-size: 24px; }
  .kpi-label { font-size: 10px; }
  .kpi-sub { font-size: 11px; }

  .row-2, .row-3, .row-2-3, .form-grid { grid-template-columns: 1fr !important; }
  .rm-grid { grid-template-columns: 1fr 1fr !important; }
  .card { padding: 14px; border-radius: 12px; }

  /* Inline-styled multi-column grids collapse on phones */
  .main [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .main .kpi-grid[style*="grid-template-columns"] { grid-template-columns: 1fr 1fr !important; }
  /* Inline flex toolbars wrap instead of overflowing */
  .main [style*="display:flex"], .main [style*="display: flex"] { flex-wrap: wrap; }
  .table-controls, .modal-footer { flex-wrap: wrap; gap: 8px; }

  /* Tables scroll sideways inside their card */
  .main table, .modal table {
    display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .main td, .main th { white-space: nowrap; }

  /* Buttons + inputs: thumb-sized, and 16px so iOS doesn't zoom on focus */
  .header-btn { padding: 8px 14px; min-height: 36px; }
  input, select, textarea { font-size: 16px !important; }

  /* ── Modals become full-screen sheets ───────────────────────────────── */
  .modal-overlay { align-items: stretch; backdrop-filter: none; }
  .modal {
    width: 100vw !important; max-width: 100vw !important; height: 100%; max-height: 100dvh !important;
    border-radius: 0; border: 0;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  }
  .modal-footer { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--surface);
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); margin-bottom: calc(-16px - env(safe-area-inset-bottom)); }

  /* Command palette / view-as banners */
  #viewAsBanner { padding-top: env(safe-area-inset-top); }

  /* CYRA launcher clears the iPhone home indicator */
  #cyraFab { bottom: calc(18px + env(safe-area-inset-bottom)) !important; right: 16px !important; }
}

@media (max-width: 380px) {
  .kpi-value { font-size: 21px; }
  .main { padding-left: 10px; padding-right: 10px; }
}
