/* Unified mobile document scroll for the RichHome administrator.
 * Mobile header is an independent grid child. A 100dvh .content below it
 * makes the final rows unreachable when body/layout overflow is locked.
 * Keep vertical scrolling on the document; preserve horizontal table swipes.
 * Desktop/tablet widths above 900px continue to use the existing layout.
 */
@media (max-width: 900px) {
  body:has(#app > .layout) {
    height: auto !important;
    min-height: 100dvh;
    overflow-x: clip;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Menu drawer must still prevent background page scrolling. */
  body.mobile-menu-open:has(#app > .layout) {
    overflow: hidden !important;
  }

  #app > .layout {
    display: block !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    overflow: visible !important;
  }

  #app > .layout > aside {
    display: none !important;
  }

  #app > .layout > .content {
    display: block !important;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    overscroll-behavior: auto !important;
    /* Protect the bottom row/actions above Android gesture/navigation bars. */
    padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Keep the mobile app header sticky, not a second fixed page header. */
  #app > .layout > .content > .top {
    position: relative !important;
    top: auto !important;
  }

  /* Dashboard and order management previously locked the entire content area
     and delegated vertical scrolling to a fixed-height table. */
  #app > .layout > .content .dashboard-table-panel,
  #order-management-page > .table-panel {
    flex: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
  }

  #order-management-page {
    display: block !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  /* Quotation form and pricing screen should grow naturally on mobile. */
  #app > .layout > .content > .quotation-editor {
    flex: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  #work-type-management-page,
  #work-type-management-page .work-type-pane,
  #work-type-management-page .work-type-grid,
  #work-type-management-page .work-type-editor {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  /* Long tables continue to scroll sideways within their own panel. */
  .completion-review-page .table-panel,
  #technician-login-status-page .member-table-panel {
    max-height: none !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }
}
