/* Mobile / PWA layout — phones (<= 768px). Loaded after the other stylesheets so it overrides. */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }

  /* ---- shell: sidebar becomes an app-style bottom nav ---- */
  .main-wrapper { flex-direction: column; }
  .main-left {
    width: 100% !important; position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    height: auto; min-height: 0; z-index: 1000; background: #fff;
    border-top: 1px solid var(--uhc-line, #e1e5ee); box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
    padding: 0; margin: 0;
  }
  .main-left-group { padding: 0; }
  .main-left-group > h2 { display: none; }
  .nav-bar-list { display: flex !important; flex-direction: row; justify-content: space-around; align-items: stretch; gap: 0; padding: 4px 2px; margin: 0; }
  .nav-bar-list > li { flex: 1; }
  .nav-bar-list > li[style*="display: none"], .nav-bar-list > li[style*="display:none"] { display: none !important; }
  .nav-bar-list .nav-link { flex-direction: column; gap: 2px; padding: 7px 2px; font-size: 10px; line-height: 1.1; text-align: center; justify-content: center; align-items: center; border-radius: 8px; }
  .nav-bar-list .nav-link svg { width: 20px; height: 20px; }
  .nav-link-content { font-size: 10px; }

  .main-right { width: 100%; padding-bottom: 78px; }
  .main-right-cover { padding: 10px 0 !important; }
  .container, .container-fluid { padding-left: 10px; padding-right: 10px; }

  /* ---- header ---- */
  header .container-fluid { padding: 0 10px; }
  header .navbar { flex-wrap: wrap; gap: 8px; min-height: auto; }
  .nav-brand img { max-height: 30px; }
  .custom-header-cta { gap: 6px; }
  .custom-header-cta .btn { font-size: 12px; padding: 6px 10px; }

  /* ---- dashboard grids stack ---- */
  .dash-kpis { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .dash-3col, .dash-2col { grid-template-columns: 1fr !important; }
  .my-perf-grid { grid-template-columns: 1fr !important; }
  .bd-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .kpi-card { padding: 12px 14px; }
  .dash-panel { padding: 12px 14px; }

  /* ---- toolbars wrap ---- */
  #dash-toolbar-host { width: 100%; }
  #dash-toolbar-host .dash-toolbar, .dash-toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .dash-presets { justify-content: center; flex-wrap: wrap; }
  .dash-range { justify-content: center; flex-wrap: wrap; }
  .dash-freshness { justify-content: center; }
  .main-heading { display: block !important; }

  /* ---- wide tables scroll instead of squishing ---- */
  .dash-panel > div[style*="overflow"], .cmp-scroll, .leave-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .dash-team-table, .cmp-table, .res-table { min-width: 560px; }
  .dash-teams, #dash-teams { overflow-x: auto; }

  /* ---- monthly calendars fit small screens ---- */
  .cal-bar { flex-wrap: wrap; gap: 8px; }
  .cal-who, .cal-who-label { max-width: 100%; }
  .cal-legend { width: 100%; margin-left: 0; order: 3; }
  .cal-grid { gap: 3px; }
  .cal-cell { min-height: 58px; padding: 4px; }
  .cal-dow { font-size: 9px; }
  .cal-date { font-size: 11px; }
  .cal-status, .cal-clock, .cal-chip, .cal-off { font-size: 9px; padding: 1px 4px; }
  .mc-row { font-size: 9px; }

  /* ---- compliance page ---- */
  .cmp-stats { grid-template-columns: repeat(2, 1fr) !important; }
  .cmp-controls, .cmp-email-bar, .cmp-email-actions { flex-direction: column; align-items: stretch; }
  .cmp-field input { width: 100%; }
  .cmp-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .cmp-email-preview { padding: 10px; }

  /* ---- drill-down modal goes full-screen ---- */
  .detail-overlay { padding: 0; align-items: stretch; }
  .detail-card { width: 100% !important; max-width: 100% !important; height: 100dvh; max-height: 100dvh; border-radius: 0; display: flex; flex-direction: column; }
  .detail-head { flex: 0 0 auto; }
  /* body fills remaining height and scrolls (fixes "page won't scroll" in the popup) */
  .detail-body { flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .detail-metrics { grid-template-columns: repeat(2, 1fr); }

  /* keep the install button above the bottom nav */
  #pwa-install-btn { bottom: 90px !important; }

  /* footer (admin) */
  footer .row, .footer-row { flex-direction: column; }
}

/* very small phones */
@media (max-width: 380px) {
  .dash-kpis, .bd-grid, .cmp-stats { grid-template-columns: 1fr !important; }
  .nav-link-content { display: none; }
  .nav-bar-list .nav-link { padding: 9px 2px; }
}
