/* Order story: HTML replicas of DEX pages. Base styles are each screen's final state; .is-run replays the build-up. */
.ms-story { min-width: 0; color: var(--ink); border: 1px solid var(--line); background: #fff; }
.ms-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding: 28px 32px 24px; border-bottom: 1px solid var(--line); }
.ms-heading .section-label { font-size: 11px; margin-bottom: 8px; }
.ms-heading h3 { margin: 0 0 8px; font-size: clamp(21px, 2.3vw, 28px); line-height: 1.35; }
.ms-heading p { margin: 0; color: var(--mute); font-size: 13px; line-height: 1.8; }
.ms-stage { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); align-items: stretch; }

/* App window */
.ms-window { position: relative; min-width: 0; padding: 22px; background: linear-gradient(160deg, #e9f1f9, #f4f8fc); display: flex; align-items: center; }
.ms-progress-top { position: absolute; inset: 0 0 auto; height: 4px; background: rgba(5, 99, 193, .14); overflow: hidden; }
.ms-progress-top i { position: absolute; inset: 0; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, var(--blue), #22a05a); animation: ms-chapter-time var(--ms-chapter, 3600ms) linear forwards; animation-play-state: paused; }
.is-running .ms-progress-top i { animation-play-state: running; }
.ms-screens { position: relative; width: 100%; aspect-ratio: 16 / 10.4; container-type: inline-size; border: 1px solid #cfdbe8; box-shadow: 0 16px 36px rgba(20, 50, 79, .14); background: #f3f5f8; overflow: hidden; }
.ms-screen { position: absolute; inset: 0; display: none; }
.ms-screen.is-active { display: block; animation: ms-screen-in .35s ease; }
.ms-app { height: 100%; display: flex; flex-direction: column; font-size: 1.68cqw; line-height: 1.45; color: #1f2d3d; font-variant-numeric: tabular-nums; }
.ms-app em { font-style: normal; }
.ms-appbar { flex: none; display: flex; align-items: center; gap: .9em; height: 2.7em; padding: 0 1em; background: #fff; border-bottom: 1px solid #e3e8ef; }
.ms-logo { padding: .2em .45em; background: #2775c7; color: #fff; font-weight: 700; font-size: .9em; letter-spacing: .04em; border-radius: 3px; }
.ms-crumb { color: #6b7b8c; white-space: nowrap; }
.ms-crumb em { padding: 0 .3em; color: #b5c0cc; }
.ms-crumb b { color: #1f2d3d; }
.ms-appbody { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: .75em; padding: 1em 1.1em; overflow: hidden; }
.ms-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1em; }
.ms-toolbar strong { font-size: 1.15em; }
.ms-toolbar span { display: flex; gap: .45em; }
.ms-toolbar b { padding: .25em .7em; border: 1px solid #d5dde7; background: #fff; color: #44566a; font-weight: 500; border-radius: 3px; white-space: nowrap; }
.ms-toolbar b.is-primary { background: #2775c7; border-color: #2775c7; color: #fff; }
.ms-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5em 1.8em; padding: .6em .85em; background: #fff; border: 1px solid #e3e8ef; }
.ms-head > span { display: flex; flex-direction: column; gap: .1em; font-weight: 600; white-space: nowrap; }
.ms-head small { color: #7b8a9a; font-size: .85em; font-weight: 400; }
.ms-subtitle { font-weight: 600; }
.ms-subtitle small { margin-left: .6em; color: #7b8a9a; font-weight: 400; }
.ms-foot { color: #6b7b8c; font-size: .9em; }
.ms-detail { display: flex; flex-direction: column; gap: .5em; padding: .7em .85em; background: #fff; border: 1px solid #e3e8ef; border-top: 2px solid #2775c7; }
.ms-detail .ms-head { padding: 0; border: 0; }
.ms-detail .ms-grid { border-color: #eef1f5; }

.ms-grid { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e3e8ef; }
.ms-grid th, .ms-grid td { padding: .5em .65em; text-align: left; white-space: nowrap; }
.ms-grid th { background: #f7f9fb; color: #5b6b7d; font-weight: 600; border-bottom: 1px solid #e3e8ef; }
.ms-grid td { border-top: 1px solid #eef1f5; }
.ms-grid tr.is-focus td { background: #eaf3fe; }
.ms-grid tr.is-focus td:first-child { box-shadow: inset .22em 0 #2775c7; font-weight: 600; color: #1d63b8; }

.ms-chip { display: inline-block; padding: .12em .55em; border-radius: 3px; font-size: .9em; font-weight: 600; white-space: nowrap; }
.ms-gray { background: #eef1f5; color: #5b6b7d; }
.ms-blue { background: #e3eefc; color: #1d63b8; }
.ms-green { background: #e3f4e8; color: #1e7b3a; }
.ms-amber { background: #fdf0d9; color: #a5650a; }
.ms-chip.big { font-size: 1.2em; padding: .25em .9em; }
.ms-swap { display: inline-grid; vertical-align: middle; }
.ms-swap > span { grid-area: 1 / 1; }
.ms-from { opacity: 0; }
.ms-bar { display: block; height: .55em; background: #e5eaf0; border-radius: 1em; overflow: hidden; }
.ms-bar i { display: block; height: 100%; width: var(--w); background: #2775c7; border-radius: inherit; }

/* Receiving / picking */
.ms-progress { display: flex; align-items: center; gap: .8em; padding: .55em .85em; background: #fff; border: 1px solid #e3e8ef; }
.ms-progress small { color: #6b7b8c; white-space: nowrap; }
.ms-progress .ms-bar { flex: 1; }
.ms-progress b { min-width: 3em; text-align: right; }

/* Scheduling gantt */
.ms-result { display: flex; align-items: center; gap: .8em; padding: .5em .85em; background: #fff; border: 1px solid #e3e8ef; color: #44566a; }
.ms-result b { color: #1f2d3d; }
.ms-result span { margin-left: auto; display: flex; gap: .4em; }
.ms-gantt { background: #fff; border: 1px solid #e3e8ef; padding: .3em .85em .6em; }
.ms-axis, .ms-lane { display: grid; grid-template-columns: 6.8em 1fr; align-items: center; }
.ms-axis div { display: grid; grid-template-columns: repeat(4, 1fr); color: #7b8a9a; font-size: .85em; }
.ms-axis em { padding: .3em 0 .3em .4em; border-left: 1px solid #e3e8ef; }
.ms-lane > span { color: #44566a; font-weight: 600; white-space: nowrap; }
.ms-lane > div { position: relative; height: 2.5em; border-top: 1px dashed #e3e8ef; background: repeating-linear-gradient(90deg, #e3e8ef 0 1px, transparent 1px 25%); }
.ms-gbar { position: absolute; top: .5em; bottom: .5em; width: var(--w); background: #cfd8e3; border-radius: 3px; overflow: hidden; }
.ms-gbar.is-focus { background: #2775c7; }
.ms-gbar b { display: block; font-style: normal; padding: 0 .45em; color: #fff; font-size: .82em; line-height: 1.5em; white-space: nowrap; font-weight: 600; }
.ms-legend { display: flex; gap: 1.6em; color: #6b7b8c; font-size: .88em; }
.ms-legend i { display: inline-block; width: 1.4em; height: .7em; margin-right: .4em; background: #cfd8e3; border-radius: 2px; vertical-align: middle; }
.ms-legend i.is-focus { background: #2775c7; }

/* SMT command monitor (dark, as in the real board) */
.ms-dark { background: #061022; color: #d4e2f3; }
.ms-dark .ms-appbar { background: #0a1830; border-color: #1a2f50; }
.ms-dark .ms-crumb, .ms-dark .ms-crumb b { color: #9fb6d1; }
.ms-dark .ms-logo { background: #1aa4c0; }
.ms-boardhead { display: flex; justify-content: center; align-items: center; gap: 1em; }
.ms-boardhead strong { font-size: 1.3em; letter-spacing: .12em; color: #e8f4ff; }
.ms-live { color: #4ade80; font-size: .88em; }
.ms-live::before { content: ''; display: inline-block; width: .55em; height: .55em; margin-right: .35em; border-radius: 50%; background: currentColor; box-shadow: 0 0 .5em currentColor; }
.ms-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6em; }
.ms-kpi { padding: .55em .8em; background: #0b1c36; border: 1px solid #1b3356; }
.ms-kpi small { display: block; color: #85a3c6; font-size: .85em; }
.ms-kpi b { font-size: 1.75em; line-height: 1.25; color: #eaf3ff; }
.ms-panels { display: grid; grid-template-columns: 1fr 1fr; gap: .6em; min-height: 0; }
.ms-panels section { min-width: 0; padding: .5em .6em; background: #0a1830; border: 1px solid #1a2f50; }
.ms-panels h5 { margin: 0 0 .45em; color: #49d6e6; font-size: .95em; }
.ms-dark .ms-grid { background: transparent; border: 0; table-layout: fixed; }
.ms-dark .ms-grid th, .ms-dark .ms-grid td { overflow: hidden; text-overflow: ellipsis; padding: .42em .5em; }
.ms-panels section:first-child .ms-grid th:nth-child(1) { width: 3em; }
.ms-panels section:first-child .ms-grid th:nth-child(3) { width: 4.6em; }
.ms-panels section:first-child .ms-grid th:nth-child(4) { width: 4.9em; }
.ms-panels section:nth-child(2) .ms-grid th:nth-child(2) { width: 4.9em; }
.ms-panels section:nth-child(2) .ms-grid th:nth-child(3) { width: 3.6em; }
.ms-dark .ms-grid th { background: #0f2442; color: #8fb0d3; border-color: #1a2f50; }
.ms-dark .ms-grid td { border-color: #142a49; }
.ms-dark .ms-grid tr.is-focus td { background: rgba(73, 214, 230, .1); }
.ms-dark .ms-grid tr.is-focus td:first-child { box-shadow: inset .22em 0 #49d6e6; color: #8eeaf4; }
.ms-panels section:nth-child(2) .ms-grid th:first-child { width: 6em; }
.ms-panels section:nth-child(2) .ms-grid td:last-child { display: flex; align-items: center; gap: .5em; }
.ms-panels section:nth-child(2) .ms-grid td:last-child .ms-bar { flex: 1; min-width: 2em; }
.ms-feed { list-style: none; margin: 0; padding: 0; }
.ms-feed li { display: flex; gap: .8em; padding: .3em 0; border-top: 1px solid #142a49; white-space: nowrap; }
.ms-feed li:first-child { border-top: 0; }
.ms-feed em { color: #6f8db0; }
.ms-feed span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ms-feed b { color: #6fe3f0; font-weight: 500; }
.ms-dark .ms-bar { background: #15294a; }
.ms-bar.ms-cyan i { background: #49d6e6; }
.ms-chip.ms-cyan, .ms-dark .ms-chip.ms-cyan { background: rgba(73, 214, 230, .14); color: #6fe3f0; }
.ms-dark .ms-chip.ms-amber { background: rgba(245, 158, 11, .15); color: #fbbf4d; }
.ms-dark .ms-chip.ms-gray { background: #15294a; color: #8fa6c2; }
.ms-dark b.ms-cyan { color: #6fe3f0; }
.ms-dark b.ms-green { color: #4ade80; background: none; }

/* DIP */
.ms-pcs { display: flex; align-items: center; gap: .6em; }
.ms-pcs .ms-bar { width: 6.5em; flex: none; }

/* Test results */
.ms-split { flex: 1; min-height: 0; display: grid; grid-template-columns: 34% 1fr; gap: .8em; }
.ms-split aside, .ms-split section { min-width: 0; display: flex; flex-direction: column; gap: .55em; }
.ms-split aside { padding: .7em; background: #fff; border: 1px solid #e3e8ef; }
.ms-search { padding: .35em .6em; border: 1px solid #d5dde7; border-radius: 3px; color: #9aa7b5; white-space: nowrap; overflow: hidden; }
.ms-station { align-self: flex-start; padding: .2em .6em; background: #e3eefc; color: #1d63b8; font-weight: 600; border-radius: 3px; white-space: nowrap; }
.ms-snlist { list-style: none; margin: 0; padding: 0; }
.ms-snlist li { display: flex; justify-content: space-between; align-items: center; gap: .5em; padding: .42em .4em; border-top: 1px solid #eef1f5; font-family: ui-monospace, Consolas, monospace; font-size: .92em; }
.ms-snlist li span { overflow: hidden; text-overflow: ellipsis; }
.ms-snlist li.is-focus { background: #eaf3fe; box-shadow: inset .22em 0 #2775c7; }
.ms-sn { display: flex; align-items: center; justify-content: space-between; gap: 1em; padding: .5em .85em; background: #fff; border: 1px solid #e3e8ef; }
.ms-sn b { font-family: ui-monospace, Consolas, monospace; font-size: 1.12em; }

/* Packing and inbound */
.ms-boxes { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6em; }
.ms-box { display: grid; gap: .3em; justify-items: start; padding: .6em .7em; background: #fff; border: 1px solid #e3e8ef; }
.ms-box em { color: #44566a; }
.ms-scans { list-style: none; margin: 0; padding: .3em .7em; background: #fff; border: 1px solid #e3e8ef; }
.ms-scans li { display: flex; align-items: center; gap: .9em; padding: .32em 0; border-top: 1px solid #eef1f5; }
.ms-scans li:first-child { border-top: 0; }
.ms-scans li > span { color: #7b8a9a; }
.ms-scans b { font-family: ui-monospace, Consolas, monospace; font-weight: 500; }
.ms-scans .ms-chip { margin-left: auto; }
.ms-inbound { display: flex; align-items: center; gap: 1.2em; padding: .6em .85em; background: #edf8f1; border: 1px solid #c4e6cf; }
.ms-inbound .ms-chip { margin-left: auto; }

/* Shipment and trace */
.ms-journey { padding: .6em .85em .7em; background: #fff; border: 1px solid #e3e8ef; }
.ms-journey small { color: #6b7b8c; }
.ms-journey ol { position: relative; display: flex; justify-content: space-between; margin: .5em 0 0; padding: 0 1em; list-style: none; }
.ms-journey ol::before { content: ''; position: absolute; left: 2.5em; right: 2.5em; top: 1em; height: 2px; background: #bfe3cb; }
.ms-journey li { position: relative; display: flex; flex-direction: column; align-items: center; gap: .3em; font-weight: 600; }
.ms-journey li small { font-weight: 400; color: #7b8a9a; }
.ms-journey li i { display: grid; place-items: center; width: 2em; height: 2em; border-radius: 50%; background: #22a05a; color: #fff; font-style: normal; font-size: .95em; }

/* Narrative */
.ms-narrative { padding: 30px 28px 24px; min-height: 330px; display: flex; flex-direction: column; }
.ms-chapter { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; color: var(--blue); font-size: 11px; font-weight: 600; line-height: 1.6; }
.ms-count { white-space: nowrap; border-bottom: 2px solid var(--blue); padding-bottom: 5px; font-variant-numeric: tabular-nums; }
.ms-scene-title { font-size: 25px; line-height: 1.3; margin: 0 0 14px; }
.ms-scene-body { font-size: 14px; line-height: 1.9; color: var(--mute); margin: 0; }
.ms-handoff { margin-top: auto; border-top: 1px solid var(--line); padding-top: 15px; }
.ms-handoff > span { display: block; color: var(--mute); font-size: 11px; margin-bottom: 6px; }
.ms-handoff strong { font-size: 13px; color: var(--blue); line-height: 1.6; }
.ms-story button:focus-visible, .ms-story summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

/* Stepper, modelled on the DEX production-stage strip */
.ms-steps { position: relative; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); border-top: 1px solid var(--line); scrollbar-width: none; }
.ms-steps::-webkit-scrollbar { display: none; }
.ms-steps button { position: relative; appearance: none; font: inherit; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; padding: 16px 4px 18px; border: 0; background: #fff; color: var(--mute); cursor: pointer; }
.ms-steps button::before { content: ''; position: absolute; top: 28px; left: -50%; right: 50%; height: 2px; background: #dce6f0; }
.ms-steps button:first-child::before { display: none; }
.ms-dot { position: relative; z-index: 1; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid #c9d6e3; background: #fff; font-size: 11px; font-weight: 600; color: #7a8da1; }
.ms-steps strong { font-size: 12px; font-weight: 600; line-height: 1.5; color: var(--ink); white-space: nowrap; }
.ms-steps small { font-size: 10px; line-height: 1.4; }
.ms-steps button.is-past::before, .ms-steps button.is-active::before { background: #22a05a; }
.ms-steps button.is-past .ms-dot { background: #22a05a; border-color: #22a05a; color: #fff; }
.ms-steps button.is-past small { color: #1e7b3a; }
.ms-steps button.is-active { background: #f2f7fd; }
.ms-steps button.is-active .ms-dot { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 0 0 4px rgba(5, 99, 193, .16); }
.ms-steps button.is-active strong, .ms-steps button.is-active small { color: var(--blue); }
.ms-steps button:hover:not(.is-active) { background: #f7fafd; }
.ms-steps i { position: absolute; inset: auto 0 0; height: 3px; transform-origin: left; transform: scaleX(0); background: var(--blue); }
.ms-steps .is-active i { animation: ms-chapter-time var(--ms-chapter, 3600ms) linear forwards; animation-play-state: paused; }
.is-running .ms-steps .is-active i { animation-play-state: running; }

.ms-evidence { border-top: 1px solid var(--line); font-size: 12px; color: var(--blue); }
.ms-evidence summary { cursor: pointer; padding: 16px 24px; }
.ms-evidence figure { margin: 0; padding: 0 24px 20px; }
.ms-evidence img { display: block; width: 100%; height: auto; border: 1px solid var(--line); }
.ms-evidence figcaption { color: var(--mute); font-size: 11px; padding-top: 8px; }

/* Build-up, replayed each time a chapter starts playing */
.is-run .ms-app { animation: ms-screen-in .22s ease both; }
.is-run .ms-row { animation: ms-row .28s ease calc(var(--r0, .12s) + var(--i, 0) * .14s) both; }
.is-run .ms-from { animation: ms-out .18s ease var(--d) both; }
.is-run .ms-to { animation: ms-in .22s ease var(--d) both; }
.is-run .ms-bar i, .is-run .ms-gbar { animation: ms-fill var(--t, .45s) cubic-bezier(.3, .6, .3, 1) var(--d) both; }
.is-run .ms-pop { animation: ms-pop .3s cubic-bezier(.3, 1.4, .5, 1) var(--d) both; }
.is-run .ms-live::before { animation: ms-blink .9s ease-in-out infinite alternate; }
.is-run .ms-chip.ms-cyan, .is-run .ms-chip.ms-blue { animation: ms-chip-pulse 1.4s ease-in-out infinite alternate; }
@keyframes ms-chip-pulse { to { filter: brightness(1.12); box-shadow: 0 0 0 .15em rgba(5, 99, 193, .18); } }
@keyframes ms-row { from { opacity: 0; transform: translateY(.6em); } }
@keyframes ms-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes ms-in { from { opacity: 0; transform: scale(.85); } }
@keyframes ms-fill { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }
@keyframes ms-screen-in { from { opacity: 0; } }
@keyframes ms-pop { from { opacity: 0; transform: scale(.6); } }
@keyframes ms-blink { to { opacity: .35; } }
@keyframes ms-chapter-time { to { transform: scaleX(1); } }

@media (max-width: 900px) {
  .ms-stage { grid-template-columns: 1fr; }
  .ms-window { padding: 16px; }
  .ms-narrative { min-height: 0; padding: 22px 24px; }
  .ms-handoff { margin-top: 18px; }
  .ms-steps { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(92px, 1fr); overflow-x: auto; scroll-snap-type: x proximity; }
  .ms-steps button { scroll-snap-align: center; }
}
@media (max-width: 560px) {
  .ms-heading { padding: 20px; flex-direction: column; gap: 10px; }
  .ms-heading h3 { font-size: 21px; }
  .ms-window { padding: 10px; }
  .ms-screens { aspect-ratio: 4 / 3.9; }
  .ms-app { font-size: 2.5cqw; }
  .ms-opt, .ms-split aside { display: none; }
  .ms-split { grid-template-columns: 1fr; }
  .ms-head { gap: .4em 1.2em; }
  .ms-kpis { grid-template-columns: repeat(2, 1fr); }
  .ms-panels { grid-template-columns: 1fr; }
  .ms-panels section + section { display: none; }
  .ms-boxes { grid-template-columns: repeat(2, 1fr); }
  .ms-axis, .ms-lane { grid-template-columns: 6.2em 1fr; }
  .ms-pcs .ms-bar { width: 5em; }
  .ms-narrative { padding: 20px; }
  .ms-scene-title { font-size: 22px; }
  .ms-steps { grid-auto-columns: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  .ms-story *:not(.ms-progress-top i, .ms-steps i), .ms-story *::before, .ms-story *::after { animation: none !important; transition: none !important; }
}
