/*
 * HENDAR UALL-O — native document scrolling recovery.
 *
 * Mobile Safari is unreliable when both html/body are locked and an inner
 * 100dvh application node owns every normal page.  Normal application views
 * therefore use the browser document as their single scroll owner on touch
 * and narrow screens.  Purpose-built surfaces (project chat and modals) keep
 * their own bounded scrollers.
 */

@media (max-width: 980px), (hover: none) and (pointer: coarse) {
  html[data-auth-surface="app"],
  html[data-auth-surface="app"] body,
  body.hendar-authenticated {
    width: 100% !important;
    height: auto !important;
    min-height: 100% !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-x: none !important;
    overscroll-behavior-y: auto !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
  }

  html[data-auth-surface="app"] .app-shell:not(.hidden),
  body.hendar-authenticated .app-shell:not(.hidden) {
    width: 100% !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    overflow: visible !important;
  }

  html[data-auth-surface="app"] .main-content,
  body.hendar-authenticated .main-content {
    width: 100% !important;
    height: auto !important;
    min-height: 100dvh !important;
    max-height: none !important;
    overflow: visible !important;
    overscroll-behavior: auto !important;
    touch-action: pan-y !important;
  }

  html[data-auth-surface="app"] .main-content > .view:not(.hidden),
  body.hendar-authenticated .main-content > .view:not(.hidden) {
    height: auto !important;
    min-height: calc(100dvh - 64px) !important;
    max-height: none !important;
    overflow: visible !important;
    padding-bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px)) !important;
    touch-action: pan-y !important;
  }

  /* Long dialogs remain reachable without re-locking the underlying page. */
  .modal-backdrop:not(.hidden) {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .modal-backdrop:not(.hidden) > .modal:not(.hidden) {
    max-height: calc(100dvh - 24px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Full project chat is a bounded application surface.  Only its message
   * list (and roster) scroll so the header and composer stay usable. */
  html[data-auth-surface="app"] #projectWorkspaceView.project-chat-active,
  body.hendar-authenticated #projectWorkspaceView.project-chat-active {
    height: calc(100dvh - 64px) !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 64px) !important;
    padding-bottom: 0 !important;
    overflow: hidden !important;
    touch-action: manipulation !important;
  }

  #projectWorkspaceView.project-chat-active .project-chat-messages,
  #projectWorkspaceView.project-chat-active .project-chat-roster-rows,
  .hendar-chat-widget-v084 .hcw-messages {
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

@supports selector(body:has(*)) {
  @media (max-width: 980px), (hover: none) and (pointer: coarse) {
    html[data-auth-surface="app"]:has(#projectWorkspaceView.project-chat-active),
    html[data-auth-surface="app"]:has(#projectWorkspaceView.project-chat-active) body,
    body.hendar-authenticated:has(#projectWorkspaceView.project-chat-active) {
      height: 100dvh !important;
      min-height: 0 !important;
      max-height: 100dvh !important;
      overflow: hidden !important;
    }

    body.hendar-authenticated:has(#projectWorkspaceView.project-chat-active) .app-shell:not(.hidden),
    body.hendar-authenticated:has(#projectWorkspaceView.project-chat-active) .main-content {
      height: 100dvh !important;
      min-height: 0 !important;
      max-height: 100dvh !important;
      overflow: hidden !important;
    }
  }
}
