/* Overlay and modal guards: bottom bars, floating buttons, support FAB, lightbox, score table. */

/* Marketing bottom bar and Zalo pill belong to the public unauthenticated home only */
body:not(.unauthenticated) #gauth-mobile-bottom-bar,
body:not(.unauthenticated) #btn-floating-zalo,
html.portal-mode #gauth-mobile-bottom-bar,
body.portal-mode #gauth-mobile-bottom-bar,
html.parent-mode #gauth-mobile-bottom-bar,
body.parent-mode #gauth-mobile-bottom-bar,
html.utility-mode #gauth-mobile-bottom-bar,
body.utility-mode #gauth-mobile-bottom-bar,
html.studio-mode #gauth-mobile-bottom-bar,
body.studio-mode #gauth-mobile-bottom-bar,
html.pdf-to-word-mode #gauth-mobile-bottom-bar,
body.pdf-to-word-mode #gauth-mobile-bottom-bar,
html.geometry-board-mode #gauth-mobile-bottom-bar,
body.geometry-board-mode #gauth-mobile-bottom-bar,
html.exam-composer-mode #gauth-mobile-bottom-bar,
body.exam-composer-mode #gauth-mobile-bottom-bar,
html.math-visual-mode #gauth-mobile-bottom-bar,
body.math-visual-mode #gauth-mobile-bottom-bar,
html.math-ocr-mode #gauth-mobile-bottom-bar,
body.math-ocr-mode #gauth-mobile-bottom-bar,
html.portal-mode #btn-floating-zalo,
body.portal-mode #btn-floating-zalo,
html.parent-mode #btn-floating-zalo,
body.parent-mode #btn-floating-zalo,
html.utility-mode #btn-floating-zalo,
body.utility-mode #btn-floating-zalo,
html.studio-mode #btn-floating-zalo,
body.studio-mode #btn-floating-zalo,
html.pdf-to-word-mode #btn-floating-zalo,
body.pdf-to-word-mode #btn-floating-zalo,
html.geometry-board-mode #btn-floating-zalo,
body.geometry-board-mode #btn-floating-zalo,
html.exam-composer-mode #btn-floating-zalo,
body.exam-composer-mode #btn-floating-zalo,
html.math-visual-mode #btn-floating-zalo,
body.math-visual-mode #btn-floating-zalo,
html.math-ocr-mode #btn-floating-zalo,
body.math-ocr-mode #btn-floating-zalo,
body.speedgrader-active #btn-floating-zalo {
  display: none !important;
}

/* Support button never covers an open modal */
body:has(.modal-backdrop.active) #ag-support-fab,
body:has(.modal-backdrop[style*="display: flex"]) #ag-support-fab,
body:has(.modal-backdrop[style*="display: block"]) #ag-support-fab {
  display: none !important;
}

/* Support button clears the authenticated bottom dock */
@media (max-width: 768px) {
  body:has(nav.mobile-bottom-dock) #ag-support-fab {
    bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* Image lightbox: close button stays inside the viewport and the shell stays transparent */
#modal-image-lightbox .modal-content.image-lightbox-content {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  overflow: visible !important;
}
#modal-image-lightbox #btn-close-lightbox {
  top: 8px !important;
  right: 8px !important;
  min-height: 44px !important;
  z-index: 20 !important;
}

/* Score breakdown table scrolls horizontally on narrow screens */
#modal-score-breakdown .table-responsive {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}
#modal-score-breakdown .table-responsive table {
  min-width: 460px;
}

/* Prevent double-padding on 3-tier modals on mobile (<= 768px) */
@media (max-width: 768px) {
  .modal-backdrop .modal-content:has(.dlg-h, .dlg-b, .dlg-f, .modal-header, .modal-body, .modal-footer) {
    padding: 0 !important;
  }

  .teacher-floating-dock {
    height: auto !important;
    min-height: 52px;
    max-width: 96vw !important;
    flex-wrap: wrap !important;
    padding: 6px 10px !important;
    gap: 6px !important;
  }
}

/* Allow long Math OCR action labels to wrap on narrow phones */
@media (max-width: 480px) {
  .ocr-combined-shortcut-btn,
  .ocr-primary-action-btn {
    white-space: normal !important;
    text-align: center !important;
    line-height: 1.3 !important;
  }
}

/* Allow vertical page scrolling over unzoomed Math Visual SVG stage */
#math-visual-studio-view .math-visual-svg-viewport {
  touch-action: pan-y;
}

/* Inline KaTeX horizontal scroll safety on narrow screens */
.ocr-q-feedback,
.ocr-q-correction,
.ocr-q-criteria,
.gs-hint-card,
.rubric-box {
  overflow-wrap: break-word;
}

.gs-step-card,
#practice-twin-statement {
  overflow-x: auto;
  max-width: 100%;
}

/* Lock background page scroll while modal stack has active dialogs */
body.modal-scroll-locked,
html.modal-scroll-locked {
  overflow: hidden !important;
  overscroll-behavior: contain;
}

/* Ensure Toasts always appear above highest confirm/scanner modals */
#toast-container,
.toast-container {
  z-index: 110000 !important;
}
