:root {
  --system-footer-height: 46px;
}

/* No viewport-height floor: the document is exactly visible content + footer.
   Also suppress elastic vertical overscroll where the browser supports it. */
body.system-footer-page {
  min-height: 0 !important;
  overscroll-behavior-y: none;
}

body.system-footer-page > footer.system-footer {
  display: flex !important;
  visibility: visible !important;
  position: static !important;
  inset: auto !important;
  align-items: center;
  justify-content: center;
  width: 100% !important;
  min-height: var(--system-footer-height) !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 10px 16px max(10px, env(safe-area-inset-bottom)) !important;
  overflow: visible !important;
  transform: none !important;
  border: 0 !important;
  border-top: 1px solid #002b4c !important;
  background: #c0ebff !important;
  color: #002b4c !important;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Arial, sans-serif;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  flex: 0 0 auto;
  z-index: auto !important;
}

body.system-footer-page > footer.system-footer *,
body.system-footer-page > footer.system-footer p,
body.system-footer-page > footer.system-footer span {
  margin: 0 !important;
  color: #002b4c !important;
  -webkit-text-fill-color: #002b4c !important;
}

body.system-footer-page > .system-footer-spacer {
  display: none !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  flex: 0 0 0;
  pointer-events: none;
}

body.system-footer-page .sidebar,
body.system-footer-page .psidebar {
  padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
}

/* Keep validation errors and success notifications inside the viewport. */
body.system-footer-page > .toast {
  z-index: 7001 !important;
  bottom: calc(14px + env(safe-area-inset-bottom)) !important;
  max-width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 28px - env(safe-area-inset-bottom));
  overflow-wrap: anywhere;
}

/* Short login screens fill the viewport; long screens grow naturally. */
body.system-footer-page:has(#authGate) > footer.system-footer {
  position: static !important;
  inset: auto !important;
  margin: 0 !important;
}

body.system-footer-page:has(#authGate) #authGate {
  min-height: calc(100vh - var(--system-footer-height)) !important;
  min-height: calc(100dvh - var(--system-footer-height)) !important;
}

/* Let visible content determine the page height. A viewport-height floor here
   kept a blank remainder on short mobile routes and became especially obvious
   after rotating a phone. */
body.system-footer-page > .screen.active {
  height: auto !important;
  min-height: 0 !important;
}

body.system-footer-page > #s-login.screen.active,
body.system-footer-page > #s-login.screen.active > .auth,
body.student-dashboard-active #s-app.screen.active .pbody {
  height: auto !important;
  min-height: 0 !important;
}

@media (max-width: 480px) {
  body.system-footer-page > footer.system-footer {
    padding-right: 12px !important;
    padding-left: 12px !important;
    font-size: 11px;
  }
}

@media print {
  body.system-footer-page > footer.system-footer,
  body.system-footer-page > .system-footer-spacer {
    display: none !important;
  }
}

/* =====================================================
   FINAL FOOTER FLOW FIX
===================================================== */

body.system-footer-page {
  height: auto !important;
  min-height: 0 !important;
  overflow-y: visible !important;
}

body.system-footer-page > :is(
  .app,
  .screen.active,
  #s-app.screen.active,
  #s-login.screen.active
) {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
}

body.system-footer-page > footer.system-footer {
  position: static !important;
  inset: auto !important;
  height: auto !important;
  min-height: 0 !important;
  margin: 0 !important;
  transform: none !important;
}

body.system-footer-page > :is(
  .system-footer-spacer,
  .footer-spacer,
  .footer-gap
) {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}
