/**
 * Trivali Opigno — fit the Opigno SCORM player iframe to the viewport.
 *
 * Goal: the SCORM iframe should fit inside the viewport so the *page* does not
 * scroll — only the iframe scrolls internally — and the "Next" button below it
 * stays visible without scrolling.
 *
 * DOM (Opigno SCORM player):
 *   .opigno_activity__wrapper
 *     .opigno_activity
 *       .scorm-ui-player
 *         .scorm-ui-player-iframe-wrapper        <- height set by theme CSS
 *           iframe[src*="/opigno-scorm/player/sco/"]
 *
 * Why a viewport-relative height (not a fixed px):
 * Aristotle ships `min-height: calc(100vh - 80px)` on the iframe. The 80px only
 * accounts for the header, so once the nav bar, the Next button and the footer
 * are added, the page exceeds 100vh and the user has to scroll. We instead
 * reserve space for ALL of that surrounding chrome and let the iframe take
 * whatever viewport height is left — so it stays responsive on any screen
 * instead of a brittle fixed pixel value.
 *
 * Notes:
 * - The reserved amount is exposed as the --scorm-reserved-space custom
 *   property so it can be tuned without touching selectors.
 * - We MUST override `min-height` as well, otherwise Aristotle's larger
 *   min-height wins and the iframe stays too tall. `!important` is used so this
 *   beats the theme's compiled CSS (and any inline style).
 * - scorm-player.js (optional) refines this by measuring the real header /
 *   footer / Next-button heights at runtime; this CSS is the no-JS baseline.
 */

:root {
  /* admin toolbar + header + nav + Next button + footer + margins. Estimate —
     tune per site, or rely on scorm-player.js to measure it exactly. */
  --scorm-reserved-space: 360px;
  /* Never collapse the iframe below this; on very short viewports we allow the
     page to scroll instead of showing an unusable sliver. */
  --scorm-min-height: 200px;
}

.scorm-ui-player-iframe-wrapper,
.scorm-ui-player-iframe-wrapper iframe[src*="/opigno-scorm/player/sco/"] {
  height: calc(100vh - var(--scorm-reserved-space)) !important;
  max-height: calc(100vh - var(--scorm-reserved-space)) !important;
  min-height: var(--scorm-min-height) !important;
}

.scorm-ui-player-iframe-wrapper iframe[src*="/opigno-scorm/player/sco/"] {
  display: block;
  width: 100%;
  border: 0;
  /* Tall SCORM content scrolls inside the iframe, not the page. */
  overflow: auto;
}

/* Small screens: header/footer chrome is taller, so reserve more space. */
@media (max-width: 767.98px) {
  :root {
    --scorm-reserved-space: 380px;
  }
}

/**
 * Full-width mode (Opigno's expand button, or "Open in full width
 * automatically" on the activity): let the player use the whole viewport width
 * instead of the Bootstrap container max-width (1320px), keeping a small gutter.
 */
body.section-module.fullscreen .page-main > .container {
  max-width: 100% !important;
  padding-left: var(--scorm-fullwidth-gutter) !important;
  padding-right: var(--scorm-fullwidth-gutter) !important;
}

body.section-module.fullscreen .page-main > .container > .row {
  margin-left: 0;
  margin-right: 0;
}

/**
 * Edge-to-edge mode: in full-width mode the player iframe is laid over the whole
 * viewport (no margins, no white space). The iframe stays in the page, so the
 * SCORM API on the parent page — and therefore tracking — keeps working. The
 * expand/compress button and the Next/Finish actions float above the content.
 */
body.section-module.fullscreen .page-main > .container {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

body.section-module.fullscreen .opigno_activity__wrapper,
body.section-module.fullscreen .opigno_activity,
body.section-module.fullscreen .scorm-ui-player {
  margin: 0 !important;
  padding: 0 !important;
}

body.section-module.fullscreen .scorm-ui-player-iframe-wrapper,
body.section-module.fullscreen .opigno_activity__wrapper iframe[src*="/opigno_tincan_extracted/"] {
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: none !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  z-index: 1;
}

body.section-module.fullscreen .scorm-ui-player-iframe-wrapper iframe[src*="/opigno-scorm/player/sco/"] {
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  min-height: 0 !important;
}

/* Absolute (not fixed) inside .opigno_activity__wrapper, which is the
   positioned top-left of the page in full-width mode: it keeps working even if
   an ancestor creates a containing block, and sits above the fixed player. */
body.section-module.fullscreen .opigno_activity__wrapper > .module-title-wrapper {
  position: absolute !important;
  top: 10px;
  right: 10px;
  left: auto;
  width: auto;
  margin: 0;
  z-index: 2147483000;
  display: flex !important;
}

body.section-module.fullscreen .opigno_activity__wrapper > .module-title-wrapper .fullscreen-link {
  display: flex !important;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

body.section-module.fullscreen .opigno_activity__wrapper .form-actions {
  position: fixed;
  right: 10px;
  bottom: 10px;
  z-index: 1000;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

:root {
  --scorm-fullwidth-gutter: 20px;
}

@media (max-width: 767.98px) {
  :root {
    --scorm-fullwidth-gutter: 8px;
  }
}
