/* =============================================================
   Induction Portal — Mobile Premium Layer
   -------------------------------------------------------------
   Additive, last-loaded CSS that lifts the training hub from
   "responsive" to "mobile-first premium" without rewriting the
   existing stylesheets. Safe to drop into any page that loads
   it after its own CSS.
   ============================================================= */

/* --- 1. Global hygiene ------------------------------------- */

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
/* overflow-x:hidden on html/body turns them into scroll containers, which
   silently KILLS every position:sticky sidebar/topbar on the page (the menu
   scrolls away with the content). Desktop layouts rely on sticky menus, so
   the horizontal-overflow guard now applies on mobile widths only — where
   the sticky sidebars are hidden anyway. */
@media (max-width: 820px) {
  html, body { overflow-x: hidden; }
}
body { -webkit-tap-highlight-color: transparent; text-rendering: optimizeLegibility; }

/* Larger default tap target everywhere (WCAG 2.5.5 24x24 minimum, we use 44x44) */
button, a.btn, .btn, .cta, .nav-list a, .nav-list .nav-trigger,
input[type="submit"], input[type="button"], [role="button"] {
  min-height: 44px;
  touch-action: manipulation;
}

/* Prevent iOS zoom on focus by enforcing 16px+ on all inputs */
input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="search"], input[type="number"],
select, textarea {
  font-size: max(16px, 1rem);
}

/* Strong visible focus ring for keyboard users only */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid #f5a623;
  outline-offset: 2px;
  border-radius: 6px;
}

/* Skip link (added to pages via inline HTML or JS) */
.skip-link {
  position: absolute; top: -100px; left: 12px; z-index: 9999;
  background: #0b3d91; color: #fff; padding: 12px 18px;
  border-radius: 0 0 10px 10px; font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 0; }

/* --- 2. Fluid typography overrides -------------------------- */

/* Smoother type scaling between breakpoints */
@media (max-width: 768px) {
  h1 { font-size: clamp(1.55rem, 6.5vw, 2.2rem); line-height: 1.18; }
  h2 { font-size: clamp(1.3rem, 5vw, 1.75rem); line-height: 1.22; }
  h3 { font-size: clamp(1.1rem, 4.2vw, 1.35rem); line-height: 1.3; }
  p, li { font-size: 1rem; line-height: 1.6; }
  .lead, .sub { font-size: 1rem; }
}

/* --- 3. Touch-friendly course catalogue --------------------- */

@media (max-width: 768px) {
  /* The catalogue's <main> has padding:22px 26px. To make filter pills scroll
     edge-to-edge, we bleed the row out of the padding with -26px margin and
     pad it back inwards. Then we add a right-edge fade gradient so users see
     there's more to scroll to.
     Note: padding-right is intentionally larger so the last pill is fully
     visible past the fade. */
  main {
    padding-left: 16px !important;
    padding-right: 16px !important;
    overflow-x: hidden;
  }

  .filterBar {
    overflow-x: auto !important;
    overflow-y: hidden;
    flex-wrap: nowrap !important;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    padding: 4px 32px 8px 16px;
    margin: 14px -16px 20px;
    scrollbar-width: none;
    position: relative;
    /* Right-edge fade hint so users know there is more */
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 24px), transparent 100%);
            mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 24px), transparent 100%);
  }
  .filterBar::-webkit-scrollbar { display: none; }
  .filterBar > button, .filterBar > .pill {
    flex-shrink: 0;
    scroll-snap-align: start;
    min-height: 40px;
    padding: 8px 14px;
    font-weight: 600;
    white-space: nowrap;
  }
  .filterBar > .search {
    flex-shrink: 0;
    width: 70vw;
    max-width: 320px;
    order: -1; /* search jumps to the start so it's reachable without scrolling all the way */
  }

  /* Course cards: single column on mobile, tighter spacing */
  .grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
  .card { border-radius: 14px; }
  .card .cover { height: 130px; }
  .card .body { padding: 14px; }
  .card .actions { gap: 10px; }
  .card .actions button { min-height: 44px; padding: 11px 12px; }
}

/* --- 3b. Training hub topbar mobile fix --------------------
   The catalogue.html and training/index.html topbar uses
   display:flex; justify-content:space-between with both brand and
   controls. On phones this squeezes the trial pill and brand text
   into multi-line vertical columns. Rebuild as a single tight row
   with smaller logo and abbreviated controls. */

@media (max-width: 640px) {
  .topbar {
    padding: 8px 12px !important;
    gap: 8px !important;
    min-height: 56px;
  }
  /* Catalogue topbar (logo + colored mark + INDUCTION PORTAL · TRAINING HUB text) */
  .topbar .brand {
    flex-shrink: 1;
    min-width: 0;
    gap: 6px !important;
    font-size: .82rem !important;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .topbar .brand .logo { width: 26px !important; height: 26px !important; flex-shrink: 0; }
  .topbar .brand > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 38vw; }

  /* Right-side controls: compact pills, no wrapping */
  .topbar .right {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
  }
  .topbar .right > * { flex-shrink: 0; }

  /* Trial pill: shorten copy and prevent wrap */
  .topbar .trialPill {
    padding: 7px 12px !important;
    font-size: .78rem !important;
    white-space: nowrap !important;
    min-height: 38px;
    line-height: 1.1 !important;
    border-radius: 99px !important;
  }
  /* Hide the "14-day" prefix on mobile to keep pill short */
  .topbar .trialPill .dot { display: none !important; }

  /* Business plans / upgrade button */
  .topbar .upgrade, .topbar a.linkBtn, .topbar a.primaryBtn {
    padding: 7px 11px !important;
    font-size: .76rem !important;
    white-space: nowrap !important;
    min-height: 38px;
    border-radius: 99px !important;
  }

  /* training/index.html topbar specifically (different markup, same intent) */
  .topbar a.backSite { display: none; }
  .topbar a.linkBtn { padding: 7px 10px !important; }
}

/* For very narrow phones (under 380px) cut copy even tighter */
@media (max-width: 380px) {
  .topbar .brand > span { max-width: 32vw; font-size: .76rem; }
  .topbar .trialPill, .topbar .upgrade, .topbar a.primaryBtn { padding: 6px 9px !important; font-size: .72rem !important; }
  /* Optionally hide secondary CTAs on tiny screens */
  .topbar .right > a.linkBtn[href*="login"] { display: none; }
}

/* JS hook: when the trial pill renders with full "Start 14-day free trial" copy,
   swap it to a shorter mobile-only label. The CSS replaces the visible text via
   a data attribute if present. */
@media (max-width: 640px) {
  .topbar .trialPill[data-mobile-label] {
    font-size: 0 !important;
  }
  .topbar .trialPill[data-mobile-label]::before {
    content: attr(data-mobile-label);
    font-size: .78rem;
  }
}

/* --- 4. Catalogue modal becomes a bottom sheet on mobile ---- */

@media (max-width: 768px) {
  .modalBg { align-items: flex-end; padding: 0; }
  .modalBg .modal {
    max-height: 92vh;
    border-radius: 18px 18px 0 0;
    animation: sheetUp .28s cubic-bezier(.2,.7,.2,1);
  }
  .modal .content { grid-template-columns: 1fr !important; gap: 14px; padding: 16px; }
  .modal header { padding: 12px 14px; }
  .modal header .close { width: 44px; height: 44px; font-size: 1.6rem; }
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* --- 5. Mobile sticky bottom CTA for marketing pages ------- */

.mobileStickyCta {
  position: fixed; left: 12px; right: 12px; bottom: 12px;
  z-index: 70;
  display: none;
  padding: 14px 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f5a623, #e89512);
  color: #1f2937;
  font-weight: 800;
  text-decoration: none;
  text-align: center;
  box-shadow: 0 16px 40px rgba(245,166,35,.45), 0 2px 6px rgba(0,0,0,.18);
  font-size: 1rem;
  min-height: 56px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s;
}
.mobileStickyCta:active { transform: translateY(1px); }
@media (max-width: 768px) {
  .mobileStickyCta { display: flex; }
  /* Add bottom padding to body so sticky doesn't cover content */
  body.hasMobileSticky { padding-bottom: 84px; }
}

/* Hide the floating-cta when mobile sticky is active to avoid stacking */
@media (max-width: 768px) {
  body.hasMobileSticky .float-cta { display: none !important; }
}

/* --- 6. Mobile bottom nav for the course player ------------ */

.mobileCourseNav {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 65;
  display: none;
  background: rgba(255,255,255,.96);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid #e5e7eb;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -6px 20px rgba(11,30,58,.10);
}
.mobileCourseNav button, .mobileCourseNav a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: 0;
  padding: 12px 8px;
  border-radius: 10px;
  font-weight: 700;
  font-size: .88rem;
  color: #0b3d91;
  cursor: pointer;
  min-height: 48px;
}
.mobileCourseNav .primary {
  background: linear-gradient(135deg, #0b3d91, #1d4ed8);
  color: #fff;
  box-shadow: 0 6px 16px rgba(11,61,145,.30);
}
.mobileCourseNav .primary:hover { filter: brightness(1.05); }
.mobileCourseNav .ghost:hover { background: #eef3fb; }
.mobileCourseNav .toc-open { font-size: 1.3rem; padding: 12px 14px; }

@media (max-width: 920px) {
  body.courseMode .mobileCourseNav { display: flex; }
  body.courseMode { padding-bottom: 80px; }
  /* Tighten the cinematic progress panel for narrow screens */
  body.courseMode .progPanel { padding: 6px 10px 6px 6px; gap: 8px; }
  body.courseMode .progPanel .dial { width: 56px; height: 56px; }
  body.courseMode .progPanel .info b { font-size: .78rem; }
  body.courseMode .progPanel .info { font-size: .72rem; }
}

/* --- 7. Better mobile TOC drawer ---------------------------- */

@media (max-width: 920px) {
  nav.toc {
    position: fixed !important;
    top: 0 !important; left: 0 !important; bottom: 0 !important;
    width: min(86vw, 360px) !important;
    height: 100vh !important;
    max-height: 100vh !important;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.2,.7,.2,1);
    z-index: 100;
    border-radius: 0 18px 18px 0 !important;
    overflow-y: auto !important;
    padding: 22px 16px !important;
    box-shadow: 12px 0 30px rgba(11,30,58,.18);
  }
  body.tocOpen nav.toc { transform: translateX(0); }
  body.tocOpen::after {
    content: "";
    position: fixed; inset: 0;
    background: rgba(7,23,46,.55);
    z-index: 99;
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    animation: fadeIn .2s ease-out;
  }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- 8. Lazy-image fade-in (when loading="lazy" + JS hint) -- */

img.lazy-fade { opacity: 0; transition: opacity .4s ease-out; }
img.lazy-fade.is-loaded { opacity: 1; }

/* --- 9. Reduced motion ------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* --- 10. High-contrast user preference --------------------- */

@media (prefers-contrast: more) {
  :root {
    --c-line: #94a3b8;
    --c-muted: #1f2937;
  }
  .btn--outline { border-width: 2.5px; }
  a { text-decoration: underline; text-underline-offset: 3px; }
}

/* --- 11. Cert print: extra precision for A4 portrait+landscape -- */

@media print {
  /* Belt-and-braces single-page constraints (the BS7858 page already has
     most of this; these rules are additive and safe across all course pages) */

  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 297mm !important;
    height: 210mm !important;
  }

  /* Force colour-accurate print everywhere */
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  /* Belt-and-braces page-break control on the cert */
  .cert, .cert-safe, .certFoot {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
  }
  .cert { page-break-before: avoid !important; }

  /* Hide everything that's never useful in print */
  .enrolGate, .previewBanner,
  .mobileStickyCta, .mobileCourseNav,
  .tour-spotlight, .tour-tooltip, .tour-launch,
  .float-cta, .modal-backdrop,
  #cursorFx, .docModalBg,
  .no-print {
    display: none !important;
  }

  /* For pages that hide the cert with .visually-hidden, force it back */
  .cert { display: block !important; visibility: visible !important; }

  /* Avoid widow/orphan in any printed paragraph inside the cert */
  .cert p, .cert li { orphans: 3; widows: 3; }

  /* Strip link underlines and external URL appendices from the cert area */
  .cert a, .cert a:visited { text-decoration: none !important; color: inherit !important; }
  .cert a[href]::after { content: "" !important; }
}

/* --- 12. Optional A4 PORTRAIT cert mode --------------------
   Toggle .cert.portrait if a user prefers a portrait certificate
   (e.g. for tall frames). Triggered via a button in the cert UI
   that adds the class. Print rules adapt accordingly. */

.cert.portrait { aspect-ratio: 1 / 1.4142; max-width: 210mm; }
@media print {
  body.printPortrait { width: 210mm !important; height: 297mm !important; }
  body.printPortrait { @page { size: A4 portrait; margin: 14mm 16mm; } }
  body.printPortrait .cert {
    min-height: calc(297mm - 28mm) !important;
    width: 100% !important;
  }
  body.printPortrait .cert .certFoot {
    grid-template-columns: 1fr !important;
    text-align: center !important;
    gap: 5mm !important;
  }
  body.printPortrait .cert .seal { width: 45mm !important; height: 45mm !important; margin: 0 auto !important; }
  body.printPortrait .cert .qrBox .qr { width: 32mm !important; height: 32mm !important; margin: 0 auto !important; }
}

/* --- 13. Sticky enrol CTA inside BS7858 page on mobile ----- */

@media (max-width: 768px) {
  body.previewMode {
    padding-bottom: 76px;
  }
  body.previewMode .previewBanner {
    position: fixed;
    bottom: 0; top: auto;
    left: 0; right: 0;
    border-top: 1px solid rgba(255,255,255,.18);
    box-shadow: 0 -6px 20px rgba(0,0,0,.25);
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    font-size: .9rem;
  }
}

/* --- 14. Safe-area-inset support for notched devices ------- */

.site-header { padding-top: env(safe-area-inset-top); }
@supports (padding: max(0px)) {
  .container { padding-left: max(var(--s-5, 24px), env(safe-area-inset-left)); padding-right: max(var(--s-5, 24px), env(safe-area-inset-right)); }
}

/* --- 15a. App chrome: bottom tab bar ------------------------
   Native-app-style navigation injected by mobile-premium.js on the
   main hub pages (Home / Courses / My learning / Business). Fully
   distributed: four equal tabs spanning edge to edge, safe-area
   aware, glass blur, active-state pill. Desktop never sees it. */

.ipAppNav {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 80;
  display: none;
  background: rgba(255,255,255,.97);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid #e5e7eb;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
  gap: 4px;
  box-shadow: 0 -8px 24px rgba(11,30,58,.10);
}
.ipAppNav a {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  padding: 7px 4px 6px;
  min-height: 52px;
  text-decoration: none;
  color: #64748b;
  font-size: .68rem; font-weight: 700; letter-spacing: .2px;
  border-radius: 12px;
  transition: background .15s, color .15s;
}
.ipAppNav a svg { width: 23px; height: 23px; display: block; }
.ipAppNav a.active { color: #0b3d91; background: #eef3fb; }
.ipAppNav a:active { background: #e2eafc; }

@media (max-width: 820px) {
  body.hasAppNav .ipAppNav { display: flex; }
  body.hasAppNav { padding-bottom: calc(78px + env(safe-area-inset-bottom)) !important; }
  /* If a sticky CTA is also present, lift it above the tab bar */
  body.hasAppNav .mobileStickyCta { bottom: calc(76px + env(safe-area-inset-bottom)); }
  body.hasAppNav .float-cta { bottom: calc(84px + env(safe-area-inset-bottom)) !important; }
  /* The tab bar has its own Basket item on phones, so the floating basket
     button is redundant there - and worse, it hovered over the dashboard
     tiles and swallowed their taps. Hide it whenever the tab bar is up. */
  body.hasAppNav .basketFab { display: none !important; }
  /* Basket count badge on the tab-bar item */
  .ipAppNav .ipNavBasket { position: relative; }
  .ipAppNav .ipNavBasket .navCount {
    position: absolute; top: 2px; right: 50%; margin-right: -22px;
    min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px;
    background: #f5a623; color: #1f2937; font-size: .66rem; font-weight: 800;
    display: inline-flex; align-items: center; justify-content: center;
    font-style: normal; line-height: 1;
  }
}

/* --- 15b. App chrome: glass header --------------------------
   The hub topbars are already sticky white; on mobile give them the
   translucent "app header" treatment. Scoped to hasAppNav pages so
   gradient headers (enrol) are untouched. */

@media (max-width: 820px) {
  body.hasAppNav .topbar {
    background: rgba(255,255,255,.92) !important;
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    box-shadow: 0 1px 0 rgba(229,231,235,.9), 0 6px 18px rgba(11,30,58,.05);
  }
}

/* --- 15c. Fully distributed, justified mobile layout --------
   Corporate "app view": action rows span edge to edge in equal
   columns, CTAs fill their container, and long body copy is
   justified with hyphenation like print collateral. */

@media (max-width: 820px) {
  /* Card action rows: text buttons share the row equally; the
     icon-only share button keeps a fixed square footprint. */
  .card .actions { display: flex !important; width: 100%; }
  .card .actions > button:not([data-action="share"]),
  .card .actions > a { flex: 1 1 0 !important; }
  .card .actions > [data-action="share"] { flex: 0 0 48px !important; }

  /* Full-width primary CTAs in forms, modals and hero blocks */
  .modal .content button.primary,
  .modal .content a.primary,
  form button.primary,
  .heroCtas > a, .heroCtas > button { width: 100%; }
  .heroCtas { display: flex; flex-direction: column; gap: 10px; }

  /* Justified corporate body copy (course reading + card blurbs).
     Headings, lists, buttons and short UI strings stay left-aligned —
     justification is only applied to sustained prose. */
  .card p.desc,
  #lessonArea p,
  .lesson p,
  .prose p,
  article p {
    text-align: justify;
    text-justify: inter-word;
    hyphens: auto; -webkit-hyphens: auto;
    overflow-wrap: break-word;
  }

  /* Evenly distributed footer links */
  footer, .siteFoot {
    text-align: center;
  }
  footer .links, .siteFoot .links {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px;
  }

  /* Consistent corporate radius + elevation rhythm on surfaces */
  .card, .panel, .perks, .modal { border-radius: 16px; }
  .card { box-shadow: 0 2px 6px rgba(11,30,58,.06), 0 12px 28px rgba(11,30,58,.07); }
}

/* --- 15. Print: hide every non-certificate element ---------- */

@media print {
  /* App chrome injected by mobile-premium.js. Without these, printing from a
     phone (print viewport <= 820px) pulls the bottom tab bar and skip link
     into the PDF - the tab icons render as huge SVGs, one per page. */
  .ipAppNav,
  .skip-link,
  .mobileStickyCta,
  .mobileCourseNav {
    display: none !important;
  }
  body.hasAppNav { padding-bottom: 0 !important; }
  /* The certificate prints alone on the page. We use visibility:hidden
     rather than display:none on .printPreviewStage so the cert inside
     can still be lifted onto the page via the visibility:visible cascade
     in certificate.html. (Earlier revs used display:none here, which
     also collapsed any cert nested inside the preview stage → blank print.) */
  .verifyUrlNote,
  .no-print,
  .nav-buttons,
  footer,
  header,
  .topbar,
  body > p {
    display: none !important;
  }
  /* Don't hide .printPreviewStage outright — neutralize its styling so
     the cert child still renders at the page origin. */
  .printPreviewStage {
    background: none !important;
    padding: 0 !important; margin: 0 !important;
    border-radius: 0 !important; box-shadow: none !important;
  }
  .printPreviewStage .page {
    width: auto !important; height: auto !important;
    padding: 0 !important; margin: 0 !important;
    background: none !important; box-shadow: none !important;
  }
  body::after, body::before { content: none !important; display: none !important; }
}
