/**
 * Mobile scroll + layout: one document scroller, native finger scroll.
 * overflow-x: clip/hidden on html AND body creates two scrollports — iOS/Android freeze.
 * Horizontal bleed is stopped with max-width, not nested overflow traps.
 */

html {
  scroll-behavior: smooth;
}

@media (hover: none) and (pointer: coarse) {
  html {
    scroll-behavior: auto;
  }
}

@media (max-width: 960px) {
  html {
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-x: none;
    -webkit-overflow-scrolling: touch;
  }

  body {
    height: auto !important;
    max-height: none !important;
    min-height: 100%;
    overflow: visible !important;
    overscroll-behavior-x: none;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
  }

  body.panel-body,
  body.site-body,
  body.auth-body,
  body.site-body-home,
  .panel-body,
  .panel-main,
  .panel-body > .panel-main,
  .page,
  .qc-wrap,
  .pfc-page,
  .dashboard-page,
  .questions-page,
  .expert-review-page,
  .curated-exam-page,
  .special-hub-page,
  .panel-body .page,
  .panel-body .questions-page,
  .panel-body .form-card,
  .panel-body .card,
  .panel-body .panel-main > .page {
    overflow: visible !important;
    max-height: none !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .table-scroll,
  .page table.table,
  .panel-body .table-scroll {
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    max-width: 100%;
    touch-action: pan-x pan-y;
  }

  .grid-2,
  .grid-3,
  .pfc-grid,
  .pfc-grid.is-curated,
  .pfc-row2,
  .bq-grid-2,
  .bq-grid-3,
  .qc-filter-grid,
  .trial-shell {
    grid-template-columns: 1fr !important;
  }

  input, select, textarea {
    max-width: 100%;
  }

  .bq-modal-overlay.open,
  .modal-overlay.open {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .bq-modal-body,
  .bq-modal {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

/* Locks: menu / modals / exam take — html is the only scroller we freeze */
html:has(body.admin-menu-open),
html:has(body.ai-crop-open),
html:has(body.prep-modal-open),
html:has(body.modal-open),
html:has(.bq-modal-overlay.open),
html:has(.modal-overlay.open) {
  overflow: hidden !important;
}

body.admin-menu-open,
body.ai-crop-open,
body.prep-modal-open,
body.modal-open {
  overflow: hidden !important;
}

/* Timed exam: keep the in-question scroller, not the document */
html:has(body.exam-body .exam-shell),
body:has(.exam-shell) {
  overflow: hidden !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
}
