/* AI Project Universe V6.15
   Final mobile document-height repair and AI Architect drawer scrolling. */

/* Student Performance: natural document height, no recursive blank tail. */
@media (max-width: 820px) {
  html[data-scroll-theme="student-performance"],
  html[data-scroll-theme="student-performance"] body,
  html[data-scroll-theme="student-performance"] .sp-app,
  html[data-scroll-theme="student-performance"] .sp-main,
  html[data-scroll-theme="student-performance"] .sp-view.is-active {
    min-height: 0 !important;
    min-block-size: 0 !important;
    height: auto !important;
    block-size: auto !important;
    max-height: none !important;
    max-block-size: none !important;
  }

  html[data-scroll-theme="student-performance"] .sp-app,
  html[data-scroll-theme="student-performance"] .sp-main {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
    overflow: visible !important;
  }

  html[data-scroll-theme="student-performance"] .sp-footer {
    margin: 18px 0 0 !important;
    padding: 18px 0 max(12px, env(safe-area-inset-bottom)) !important;
  }

  html[data-scroll-theme="student-performance"] .sp-scroll-end {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  html[data-scroll-theme="student-performance"] .sp-toast {
    position: fixed !important;
    left: 50% !important;
    right: auto !important;
    bottom: max(18px, env(safe-area-inset-bottom)) !important;
  }
}

/* AI Architect: the drawer owns the mobile scroll. The page beneath stays put. */
@media (max-width: 767px) {
  html[data-scroll-theme="ai-architect"] .ai-architect-drawer {
    position: fixed !important;
    inset: 60px auto 0 0 !important;
    width: min(88vw, 350px) !important;
    min-width: 0 !important;
    max-width: 350px !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    flex-direction: column !important;
    align-items: stretch !important;
    overflow: hidden !important;
    overscroll-behavior: contain !important;
    touch-action: pan-y !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer.hidden {
    display: none !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer.flex:not(.hidden),
  html[data-scroll-theme="ai-architect"] .ai-architect-drawer.is-open {
    display: flex !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer > .ai-drawer-heading,
  html[data-scroll-theme="ai-architect"] .ai-architect-drawer > header {
    flex: 0 0 auto !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer > div:not(.ai-drawer-heading),
  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav {
    min-height: 0 !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 7px !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 12px 12px max(28px, env(safe-area-inset-bottom)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-gutter: stable !important;
    touch-action: pan-y !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav > a {
    flex: 0 0 auto !important;
    width: 100% !important;
    min-height: 50px !important;
  }

  html[data-scroll-theme="ai-architect"] .ai-architect-drawer nav > a.apu-v69-contact-link {
    position: static !important;
    inset: auto !important;
    margin: 8px 0 4px !important;
  }

  html.ai-architect-nav-open,
  html.ai-architect-nav-open body {
    overflow: hidden !important;
    overscroll-behavior: none !important;
  }
}
