/* GritHQ Alpha4.90 — PWA navigation/sheet stability audit lock
   Scope: installed iOS PWA only. Native iOS/Worker is intentionally untouched.
   This file is loaded LAST and only normalizes shell mechanics around navigation
   and dialogs. It does not redesign any page content. */
@media (max-width:959px) {
  html.ios-standalone,
  html.ios-standalone body {
    width:100%!important;
    height:100%!important;
    min-height:100%!important;
    max-height:100%!important;
    overflow:hidden!important;
  }

  html.ios-standalone body:not(.workout-mode) .app-shell {
    position:fixed!important;
    inset:0!important;
    width:100%!important;
    height:100dvh!important;
    min-height:0!important;
    max-height:100dvh!important;
    overflow:hidden!important;
  }

  html.ios-standalone body:not(.workout-mode) .app-stage {
    position:absolute!important;
    inset:0!important;
    display:grid!important;
    grid-template-columns:minmax(0,1fr)!important;
    grid-template-rows:auto minmax(0,1fr) auto!important;
    width:100%!important;
    height:100%!important;
    min-width:0!important;
    min-height:0!important;
    overflow:hidden!important;
  }

  /* One scroll owner for Home, Train, Progress, Profile and all secondary pages. */
  html.ios-standalone body:not(.workout-mode) #mainContent.main-content {
    grid-row:2!important;
    position:relative!important;
    width:100%!important;
    height:100%!important;
    min-width:0!important;
    min-height:0!important;
    max-height:none!important;
    margin:0!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    -webkit-overflow-scrolling:touch!important;
    overscroll-behavior-y:auto!important;
    touch-action:pan-y!important;
    scroll-padding-bottom:20px!important;
  }

  html.ios-standalone body:not(.workout-mode) #view-home.active,
  html.ios-standalone body:not(.workout-mode) #view-routines.active,
  html.ios-standalone body:not(.workout-mode) #view-history.active,
  html.ios-standalone body:not(.workout-mode) #view-profile.active,
  html.ios-standalone body:not(.workout-mode) #view-health.active,
  html.ios-standalone body:not(.workout-mode) #view-nutrition.active,
  html.ios-standalone body:not(.workout-mode) #view-settings.active {
    width:100%!important;
    min-width:0!important;
    height:auto!important;
    max-height:none!important;
    overflow:visible!important;
    contain:none!important;
    transform:none!important;
    will-change:auto!important;
    box-sizing:border-box!important;
  }

  /* Preserve the approved short-page drag/return feel on Home and Profile. */
  html.ios-standalone body.home-mode:not(.workout-mode) #view-home.active,
  html.ios-standalone body:not(.workout-mode) #view-profile.active {
    min-height:calc(100% + 52px)!important;
  }

  /* Secondary destinations use the same stable viewport without changing dock geometry. */
  html.ios-standalone body:not(.workout-mode) #view-health.active,
  html.ios-standalone body:not(.workout-mode) #view-nutrition.active,
  html.ios-standalone body:not(.workout-mode) #view-settings.active {
    min-height:100%!important;
  }

  /* Exact Alpha4.89 approved dock geometry, frozen on every PWA surface. */
  html.ios-standalone body:not(.workout-mode) #bottomNav.bottom-nav {
    grid-row:3!important;
    position:relative!important;
    inset:auto!important;
    left:auto!important;
    right:auto!important;
    top:auto!important;
    bottom:auto!important;
    transform:none!important;
    width:auto!important;
    height:58px!important;
    min-height:58px!important;
    max-height:58px!important;
    margin:6px max(10px,env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(10px,env(safe-area-inset-left))!important;
    padding:4px!important;
    display:grid!important;
    grid-template-columns:repeat(4,minmax(0,1fr))!important;
    gap:0!important;
    align-self:end!important;
    box-sizing:border-box!important;
    overflow:hidden!important;
  }

  html.ios-standalone body:not(.workout-mode) #bottomNav .nav-btn,
  html.ios-standalone body:not(.workout-mode) #bottomNav .nav-btn.active {
    width:100%!important;
    min-width:0!important;
    max-width:none!important;
    height:50px!important;
    min-height:50px!important;
    max-height:50px!important;
    margin:0!important;
    padding:3px 2px!important;
    display:grid!important;
    grid-template-rows:23px auto!important;
    grid-template-columns:1fr!important;
    place-items:center!important;
    align-content:center!important;
    row-gap:2px!important;
    text-align:center!important;
    box-sizing:border-box!important;
  }

  html.ios-standalone body:not(.workout-mode) #bottomNav .nav-btn svg,
  html.ios-standalone body:not(.workout-mode) #bottomNav .nav-btn.active svg {
    display:block!important;
    width:20px!important;
    height:20px!important;
    min-width:20px!important;
    min-height:20px!important;
    margin:0 auto!important;
  }

  html.ios-standalone body:not(.workout-mode) #bottomNav .nav-btn small,
  html.ios-standalone body:not(.workout-mode) #bottomNav .nav-btn.active small {
    display:block!important;
    width:100%!important;
    margin:0!important;
    padding:0!important;
    font-size:10px!important;
    line-height:1!important;
    text-align:center!important;
  }

  /* Dialogs remain top-layer overlays. The app shell behind them must not be
     repositioned when a review/settings sheet opens. */
  html.ios-standalone body:not(.workout-mode):has(dialog[open]) .app-shell,
  html.ios-standalone body:not(.workout-mode):has(dialog[open]) .app-stage {
    inset:0!important;
    height:100dvh!important;
    max-height:100dvh!important;
  }
}
