/* The document is the page scroller. Keeping scroll ownership at the document
   lets wheel, trackpad, and touch input over any ordinary page surface work. */
html {
  height: auto;
  min-height: 100%;
  overflow-x: clip;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

body {
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  overflow-y: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* The legacy workspace theme fixes #tv-app to the viewport. Release that
   root too, so overflowing workspace content contributes to document height. */
body #tv-app {
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* Keep the page behind the mobile navigation stationary. The sidebar's own
   navigation list remains independently scrollable while it is open. */
html:has(body[data-navy-navigation-open]) {
  overflow: hidden;
}

body[data-navy-navigation-open] #tv-app > .app-shell.ps-app {
  overflow: hidden;
}

/* Let the shell grow with its content instead of trapping page scrolling in
   a viewport-sized nested container. */
body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] {
  position: relative;
  inset: auto;
  grid-template-rows: 64px max-content max-content;
  align-content: start;
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
  overflow: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* Keep navigation anchored to the viewport and outside document grid sizing. */
body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] > .ps-sidebar {
  position: fixed;
  inset: 0 auto auto 0;
}

body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] > .ps-header {
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Main content remains in normal document flow and expands to its content. */
body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] > main.ps-main {
  grid-column: 2;
  grid-row: 3;
  min-width: 0;
  min-height: max-content;
  height: auto;
  overflow: visible;
}

body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] > main.ps-main > .content-frame {
  height: auto;
  min-height: max-content;
  overflow: visible;
}

body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] > main.ps-main > .content-frame > .workspace {
  height: auto;
  min-height: max-content;
  overflow: visible;
  overscroll-behavior-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* Preserve native document and menu scrolling while hiding decorative tracks.
   Nested drawers/tables retain their own scroll behavior. */
html::-webkit-scrollbar,
body::-webkit-scrollbar,
#tv-app::-webkit-scrollbar,
.ps-app::-webkit-scrollbar,
.ps-app > .ps-main::-webkit-scrollbar,
.ps-app .workspace::-webkit-scrollbar,
.ps-app .ps-nav::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.ps-app,
.ps-app > .ps-main,
.ps-app .ps-nav {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* Sidebar regions must not consume the page's wheel/touch gesture when they
   have no remaining vertical movement. Keep the list scrollable, but let the
   gesture chain to the document at either boundary. */
.ps-app .ps-sidebar,
.ps-app .ps-nav {
  overscroll-behavior-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ps-app .ps-sidebar::-webkit-scrollbar,
.ps-app .ps-nav::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

@media (max-width: 900px) {
  body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 64px max-content max-content;
  }

  body #tv-app > .app-shell.ps-app[data-shell-design="stitch-navy-atelier-v1"] > main.ps-main {
    grid-column: 1;
    grid-row: 3;
  }
}

/* On narrow screens the collapsed desktop rail is an overlay, not a grid
   track. Remove its reserved width so the workspace uses the full viewport. */
@media (max-width: 900px) {
  /* Match the generated shell's full selector. The navigation becomes an
     overlay at this breakpoint, so neither saved sidebar state nor a stale
     desktop track may reserve width beside the workspace. */
  body #tv-app > .app-shell.ps-app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 64px auto minmax(0, 1fr);
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    overflow-x: clip;
  }
  body #tv-app > .app-shell.ps-app > .main.ps-main {
    grid-column: 1;
    grid-row: 3;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-inline: 0;
  }
  body #tv-app > .app-shell.ps-app > .main.ps-main > .content-frame {
    width: 100%;
    max-width: none;
    min-width: 0;
    margin-inline: 0;
  }
  body #tv-app > .app-shell.ps-app > .main.ps-main > .content-frame > .workspace,
  body #tv-app > .app-shell.ps-app > .main.ps-main > .content-frame > .workspace .workspace-body,
  body #tv-app > .app-shell.ps-app > .main.ps-main > .content-frame > .workspace .workspace-main,
  body #tv-app > .app-shell.ps-app > .main.ps-main > .content-frame > .workspace[data-active-route="home"] .tv-home-v1 {
    width: 100%;
    max-width: none;
    min-width: 0;
    margin-inline: 0;
  }
}
