/* R21 — stability, de-duplication, and print pagination QA */

/* Keep the visual Kaizen orbit as the primary presentation. The underlying
   seven-step sequence remains in the DOM as source content but is not repeated. */
#kaizenModel .qi-redundant-sequence,
#kaizenModel .qi-kaizen-sequence {
  display:none !important;
}

/* The detailed three-stage matrix repeats the preceding stage summary. Keep it
   available only in Review mode; default presentation stays concise. */
#processEvolution .qi-detail-comparison.reviewOnly {
  margin-top:12px;
}

/* Safe automatic stakeholder motion: emphasis only, never programmatic scroll. */
.figma-live-v3 .qi-stakeholder-network>.grid3>.card {
  transition:transform .55s cubic-bezier(.2,.75,.25,1),box-shadow .55s ease,border-color .55s ease;
}
.figma-live-v3 .qi-stakeholder-network>.grid3>.card.qi-live-active {
  transform:translateY(-5px) scale(1.012);
  border-color:#6fa88d;
  box-shadow:0 15px 30px rgba(15,79,57,.12);
}

/* Stable mobile navigation fallback. */
.qi-back-to-top {
  position:fixed;
  inset-inline-end:16px;
  bottom:max(18px,env(safe-area-inset-bottom));
  z-index:95;
  min-width:46px;
  height:46px;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  padding:0 13px;
  border:1px solid rgba(255,255,255,.32);
  border-radius:999px;
  background:#0a5039;
  color:#fff;
  box-shadow:0 10px 24px rgba(5,54,38,.22);
  font:800 12px/1 Arial,"Segoe UI",Tahoma,sans-serif;
  opacity:0;
  visibility:hidden;
  transform:translateY(8px);
  transition:opacity .2s ease,transform .2s ease,visibility .2s ease;
}
.qi-back-to-top.is-visible {opacity:1;visibility:visible;transform:none}
.qi-back-to-top>span:first-child {font-size:19px;line-height:1}
.qi-back-label {display:none}
@media (min-width:760px){.qi-back-label{display:inline}}

/* Reduce scroll-chaining risk from horizontally scrollable cards on phones. */
@media (max-width:760px) {
  .figma-live-v3 .qi-stakeholder-network>.grid3,
  .figma-live-v3 .flow,
  .figma-live-v3 .pathMap,
  .figma-live-v3 .wasteGrid {
    overscroll-behavior-inline:contain;
    scroll-behavior:auto;
  }
}

@media print {
  @page { size:A4 portrait; margin:9mm 9mm 10mm }

  .qi-back-to-top {display:none !important}
  .figma-live-v3 .qi-stakeholder-network>.grid3>.card.qi-live-active {transform:none !important;box-shadow:none !important}

  /* Print in deliberate modules. This prevents section headings or major
     visuals from being stranded at the bottom of the previous page. */
  #processEvolution,
  #s16,
  #implementationRoadmap,
  #kaizenModel {
    break-before:page !important;
    page-break-before:always !important;
  }

  /* Section 05A: the summary is the presentation artifact. The detailed
     comparison is Review-only and therefore excluded from print. */
  #processEvolution .qi-detail-comparison {display:none !important}
  #processEvolution .dataTable {
    table-layout:fixed !important;
    font-size:6.7pt !important;
    line-height:1.22 !important;
  }
  #processEvolution .dataTable th,
  #processEvolution .dataTable td {
    padding:1.35mm !important;
    overflow-wrap:anywhere !important;
    word-break:normal !important;
  }
  #processEvolution .dataTable tr {
    break-inside:avoid !important;
    page-break-inside:avoid !important;
  }

  /* Root-cause analysis: keep the Ishikawa visual itself complete and compact.
     The 5 Whys may continue on the following page, but the fishbone must not. */
  #s16 .qi-fishbone-scroll {
    overflow:visible !important;
    width:100% !important;
  }
  #s16 .qi-fishbone-visual,
  #s16 .causeBoard {
    display:grid !important;
    grid-template-columns:minmax(0,1fr) 43mm !important;
    gap:4mm !important;
    width:100% !important;
    min-width:0 !important;
    padding:3mm !important;
    margin:0 !important;
    border:1px solid #789989 !important;
    border-radius:3mm !important;
    break-inside:avoid !important;
    page-break-inside:avoid !important;
    overflow:hidden !important;
  }
  #s16 .causeGrid {
    display:grid !important;
    grid-template-columns:repeat(3,minmax(0,1fr)) !important;
    gap:2.4mm !important;
    min-width:0 !important;
    align-content:center !important;
  }
  #s16 .causeCard {
    min-height:26mm !important;
    padding:2mm !important;
    border-top-width:1.2mm !important;
    box-shadow:none !important;
    break-inside:avoid !important;
    page-break-inside:avoid !important;
  }
  #s16 .causeCard h3 {font-size:7.5pt !important;line-height:1.2 !important;margin-bottom:1mm !important}
  #s16 .causeCard p {font-size:6.7pt !important;line-height:1.27 !important;margin:0 !important}
  #s16 .effectHead,
  html[dir="rtl"] #s16 .effectHead {
    min-height:59mm !important;
    height:auto !important;
    padding:4mm 3mm !important;
    border-radius:50% 3mm 3mm 50% !important;
    display:grid !important;
    place-content:center !important;
    text-align:center !important;
    background:#0b553d !important;
    color:#fff !important;
    break-inside:avoid !important;
    page-break-inside:avoid !important;
  }
  html[dir="rtl"] #s16 .effectHead {border-radius:3mm 50% 50% 3mm !important}
  #s16 .effectHead h3 {font-size:8.4pt !important;line-height:1.2 !important}
  #s16 .effectHead p,#s16 .effectHead small {font-size:6.5pt !important;line-height:1.25 !important}
  #s16 .qi-fishbone-svg {display:block !important}

  /* Implementation roadmap: keep the seven-stage map together and allow the
     priority lanes to paginate only between lanes. */
  #implementationRoadmap>.card {break-inside:auto !important;page-break-inside:auto !important}
  #implementationRoadmap .kaizenFlow {
    display:grid !important;
    grid-template-columns:repeat(4,minmax(0,1fr)) !important;
    gap:2mm !important;
    break-inside:avoid !important;
    page-break-inside:avoid !important;
    margin-bottom:3mm !important;
  }
  #implementationRoadmap .kaizenStep {
    min-height:17mm !important;
    padding:2mm !important;
    font-size:7.2pt !important;
  }
  #implementationRoadmap .priorityRoadmap {display:block !important}
  #implementationRoadmap .roadmapLane {
    break-inside:avoid !important;
    page-break-inside:avoid !important;
    margin-bottom:3mm !important;
    padding:3mm !important;
  }

  /* Kaizen: remove the duplicate rectangular sequence and keep the orbit as the
     single visual explanation. Start the module on a clean page. */
  #kaizenModel .qi-kaizen-sequence,
  #kaizenModel .qi-redundant-sequence {display:none !important}
  #kaizenModel>.card {break-inside:auto !important;page-break-inside:auto !important}
  #kaizenModel .methodDistinction,
  #kaizenModel .qi-kaizen-orbit {
    break-inside:avoid !important;
    page-break-inside:avoid !important;
  }
  #kaizenModel .methodDistinction {
    display:grid !important;
    grid-template-columns:repeat(2,minmax(0,1fr)) !important;
    gap:2mm !important;
    margin-bottom:2mm !important;
  }
  #kaizenModel .methodDistinction>div {
    min-height:0 !important;
    padding:2mm !important;
    font-size:7pt !important;
    line-height:1.25 !important;
  }
  #kaizenModel .qi-kaizen-orbit {
    width:82mm !important;
    height:82mm !important;
    max-width:82mm !important;
    margin:1mm auto 3mm !important;
  }
  #kaizenModel .qi-kaizen-node {font-size:6.4pt !important}
  #kaizenModel .qi-kaizen-core b {font-size:13pt !important}

  /* General pagination hardening for the modules shown in the screenshots. */
  .sectionHead,
  .methodIntro,
  .controlAssurance,
  .qi-data-boundary,
  .roadmapLane,
  .whyStep,
  .pdsaCard,
  .qi-trend-card {
    break-inside:avoid !important;
    page-break-inside:avoid !important;
  }

  .figma-live-v3 .card,
  .figma-live-v3 .pathCard,
  .figma-live-v3 .wasteCard,
  .figma-live-v3 .pdsaCard {
    box-shadow:none !important;
  }
}
