/* ===========================================================================
   /services/manufacturing/ (ja, vi, en) -- 製品構成: one row per module (text + screen
   picture) and the product screens drawn in HTML/CSS. Every screen is drawn by
   NAL with sample data and carries a caption that says so. Status fills reuse
   the contrast-checked pairs of sales-ui.css (text on fill >= 4.5:1).
   =========================================================================== */

:root {
  --mfs-stage: linear-gradient(145deg, #D9E5F1 0%, #E4EBF3 60%, #EDF1F5 100%);
  --mfs-chrome: #102A43;     /* product top bar, like every Solutions mock */
  --mfs-chrome-tx: #C6D3E0;  /* text on the top bar 9.62:1 */
  --mfs-floor: #F4F7FA;      /* background behind the panels */
  --mfs-hair: #E2E8EE;
  --mfs-track: #E8EDF2;
  --mfs-run: #237A52;   --mfs-run-tx: #FFFFFF;
  --mfs-set: #E08A1E;   --mfs-set-tx: #3D2C00;
  --mfs-stop: #C2542A;  --mfs-stop-tx: #FFFFFF;
}

/* ---- module rows: stacked on phones, text + screen side by side from 1024px -- */
.mf-mods { display: grid; gap: clamp(48px, 6vw, 88px); }
.mf-mod { display: grid; gap: 24px; align-items: center; }
.mf-mod__txt { display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 1024px) {
  .mf-mod { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 56px; }
  .mf-mod:nth-child(even) { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
  .mf-mod:nth-child(even) .mf-mod__txt { order: 2; }
}

/* ---- stage + window --------------------------------------------------------- */
.mfs-fig { margin: 0; }
.mfs-stage { container-type: inline-size; padding: clamp(12px, 2.4vw, 28px); border-radius: 14px; background: var(--mfs-stage); pointer-events: none; user-select: none; -webkit-user-select: none; }
.mfs-win { overflow: hidden; border-radius: 8px; background: var(--white); box-shadow: 0 10px 30px rgba(16, 42, 67, 0.12); font-family: 'Noto Sans JP', sans-serif; font-size: 13px; line-height: 1.6; color: var(--ink); word-break: auto-phrase; }
.mfs-win p, .mfs-win ul, .mfs-win ol, .mfs-win dl, .mfs-win dd { margin: 0; }
.mfs-win ul, .mfs-win ol { padding: 0; list-style: none; }
.mfs-top { display: flex; align-items: center; gap: 12px; height: 34px; padding: 0 12px; background: var(--mfs-chrome); color: var(--mfs-chrome-tx); white-space: nowrap; }
.mfs-brand { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; color: var(--white); }
.mfs-brand::before { content: ""; width: 14px; height: 14px; border-radius: 4px; background: var(--blue); box-shadow: inset 0 0 0 3px var(--blue-pale); }
.mfs-crumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.mfs-time { margin-left: auto; font-variant-numeric: tabular-nums; }
.mfs-body { display: grid; gap: 10px; padding: 12px; background: var(--mfs-floor); }
.mfs-panel { min-width: 0; padding: 12px 14px; border: 1px solid var(--mfs-hair); border-radius: 6px; background: var(--white); }
.mfs-win .mfs-h { margin-bottom: 10px; font-weight: 700; color: var(--navy); }

/* ---- MES: OEE gauge + its three factors ------------------------------------ */
.mfs-oee { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 0 14px; }
.mfs-oee .mfs-h { grid-column: 1 / -1; }
.mfs-gauge { position: relative; width: 88px; aspect-ratio: 1; }
.mfs-gauge svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.mfs-gauge__v { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.mfs-kpi { display: grid; gap: 4px; }
.mfs-kpi div { display: flex; justify-content: space-between; gap: 8px; padding-bottom: 4px; border-bottom: 1px solid var(--mfs-hair); }
.mfs-kpi dt { color: var(--muted); }
.mfs-kpi dd { font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }

/* ---- MES: line status (one grid, rows share columns) ------------------------ */
/* Narrow: the badge column never drops below its longest word and the count
   (auto) folds after the slash when short of room, so a long label cannot run
   over the count. A panel of 350px+ adds the bar (query further down). */
.mfs-lines ul { display: grid; grid-template-columns: max-content minmax(min-content, 1fr) auto; align-items: center; gap: 8px 10px; }
.mfs-lines li { display: contents; }
.mfs-name { font-weight: 700; color: var(--navy); white-space: nowrap; }
.mfs-st { justify-self: start; padding: 0 7px; border-radius: 3px; font-weight: 700; line-height: 20px; white-space: nowrap; }
.mfs-lines .mfs-st { white-space: normal; overflow-wrap: normal; }
.mfs-lines .mfs-num { text-align: right; white-space: normal; overflow-wrap: normal; }
.mfs-st--run { background: var(--mfs-run); color: var(--mfs-run-tx); }
.mfs-st--set { background: var(--mfs-set); color: var(--mfs-set-tx); }
.mfs-st--stop { background: var(--mfs-stop); color: var(--mfs-stop-tx); }
.mfs-st--wait { background: var(--mfs-track); color: var(--navy); }
.mfs-num { justify-self: end; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mfs-bar { display: none; height: 8px; border-radius: 4px; background: var(--mfs-track); overflow: hidden; }
.mfs-bar i { display: block; height: 100%; border-radius: inherit; }
.mfs-bar--run i { background: var(--mfs-run); }
.mfs-bar--set i { background: var(--mfs-set); }
.mfs-bar--stop i { background: var(--mfs-stop); }
.mfs-note { grid-column: 1 / -1; margin-top: -4px; font-weight: 700; color: var(--mfs-stop); }

/* ---- MES: downtime by reason, longest first --------------------------------- */
.mfs-stops ul { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; align-items: center; gap: 7px 10px; }
.mfs-stops li { display: contents; }
.mfs-stops .mfs-bar { display: block; height: 12px; border-radius: 2px; }
.mfs-stops .mfs-bar i { background: var(--blue); }
.mfs-stops li:first-child .mfs-bar i { background: var(--navy); }
.mfs-val { justify-self: end; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- shared: item code above its name, panel sub line ------------------------ */
.mfs-item { display: flex; min-width: 0; flex-direction: column; line-height: 1.45; overflow-wrap: normal; }
.mfs-code { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mfs-item b { font-weight: 700; color: var(--navy); }
.mfs-win .mfs-sub { margin: -6px 0 10px; color: var(--muted); }

/* ---- ERP: material stock against safety stock, MRP suggestion --------------- */
.mfs-stock ul { display: grid; grid-template-columns: minmax(0, 1fr) max-content max-content; align-items: center; gap: 9px 12px; }
.mfs-stock li { display: contents; }
.mfs-stock .mfs-num { text-align: right; }
.mfs-th { align-self: end; padding-bottom: 6px; border-bottom: 1px solid var(--mfs-hair); font-size: 12px; color: var(--muted); white-space: nowrap; }
.mfs-th:nth-child(2) { text-align: right; }
.mfs-hint { margin-top: 12px; padding: 8px 10px; border-left: 3px solid var(--blue); border-radius: 0 4px 4px 0; background: #EEF5FB; font-weight: 700; color: var(--navy); }

/* ---- ERP: unit cost from the BOM (stacked bar + table) ----------------------- */
.mfs-stack { display: flex; gap: 2px; height: 14px; margin-bottom: 12px; border-radius: 3px; overflow: hidden; }
.mfs-stack i { display: block; height: 100%; }
.mfs-c1 { background: var(--navy); }
.mfs-c2 { background: var(--blue); }
.mfs-c3 { background: #5FA3DB; }
.mfs-c4 { background: var(--blue-pale); }
.mfs-cost ul { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content max-content; align-items: center; gap: 6px 10px; }
.mfs-cost li { display: contents; }
.mfs-sw { width: 10px; height: 10px; border-radius: 2px; }
.mfs-pct { justify-self: end; min-width: 3em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.mfs-total { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--mfs-hair); font-weight: 700; color: var(--navy); }
.mfs-total b { font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---- Quality: pass rate by inspection stage --------------------------------- */
.mfs-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 1px; }
/* subgrid keeps the values on one row even when a stage name wraps to two lines */
.mfs-tile { display: grid; grid-row: span 4; grid-template-rows: subgrid; min-width: 0; padding: 0 10px; border-left: 1px solid var(--mfs-hair); line-height: 1.4; }
.mfs-tile:first-child { padding-left: 0; border-left: 0; }
.mfs-tile__k { font-weight: 700; color: var(--navy); }
.mfs-tile span:nth-child(2) { font-size: 12px; color: var(--muted); }
.mfs-tile__v { margin-top: 4px; font-size: 20px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.mfs-tile__t { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mfs-tile--miss .mfs-tile__v, .mfs-tile--miss .mfs-tile__t { color: var(--mfs-stop); }

/* ---- Quality: defect Pareto. Bars = count over the total, line + dots = cumulative share. Columns have no gap so each dot sits on its bar centre. */
.mfs-plot { position: relative; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: 120px; border-bottom: 1px solid var(--mfs-hair); }
.mfs-pbar { display: flex; align-items: flex-end; justify-content: center; height: 100%; }
.mfs-pbar i { display: block; width: 56%; max-width: 40px; border-radius: 2px 2px 0 0; background: var(--blue); }
.mfs-pbar:first-child i { background: var(--navy); }
.mfs-pline { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.mfs-pdot { position: absolute; width: 9px; height: 9px; border: 2px solid var(--white); border-radius: 50%; background: var(--mfs-stop); transform: translate(-50%, 50%); }
.mfs-p80 { position: absolute; right: 0; bottom: 80%; left: 0; border-top: 1px dashed #B5C3D1; font-size: 11px; line-height: 1; text-align: right; color: var(--muted); }
.mfs-plab { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding-top: 6px; }
.mfs-plab span { padding: 0 2px; font-size: 12px; line-height: 1.35; text-align: center; color: var(--ink); overflow-wrap: anywhere; }
.mfs-plab b { display: block; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.mfs-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.mfs-lg { display: inline-flex; align-items: center; gap: 6px; }
.mfs-lg::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--blue); }
.mfs-lg--line::before { width: 14px; height: 2px; border-radius: 1px; background: var(--mfs-stop); }

/* ---- Quality: corrective actions (8D) and 4M changes ------------------------ */
/* fit-content(45%): a long status ("Awaiting approval") wraps on a phone instead
   of squeezing the item title to a sliver. */
.mfs-acts ul { display: grid; grid-template-columns: minmax(0, 1fr) fit-content(45%); align-items: center; gap: 10px 12px; }
.mfs-acts li { display: contents; }
.mfs-acts .mfs-st { white-space: normal; overflow-wrap: normal; }

/* ---- AI assistant: question, answer with numbered sources, access scope ------ */
.mfs-chat { display: grid; gap: 10px; }
.mfs-q { justify-self: end; max-width: 86%; padding: 8px 12px; border-radius: 12px 12px 2px 12px; background: var(--navy); color: var(--white); }
.mfs-a { max-width: 94%; padding: 10px 12px; border: 1px solid var(--mfs-hair); border-radius: 12px 12px 12px 2px; background: var(--white); }
.mfs-win .mfs-a__who { margin-bottom: 4px; font-size: 12px; font-weight: 700; color: var(--blue); }
.mfs-ref { margin-left: 1px; padding: 0 4px; border-radius: 3px; background: #E3F0FB; font-size: 10px; font-weight: 700; color: var(--navy); vertical-align: 0.5em; line-height: 1; }
.mfs-src { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--mfs-hair); }
.mfs-win .mfs-src p { margin-bottom: 4px; font-size: 12px; font-weight: 700; color: var(--muted); }
.mfs-src ol { display: grid; gap: 4px; }
.mfs-src li { display: flex; align-items: baseline; gap: 6px; font-size: 12px; line-height: 1.5; color: var(--blue); }
.mfs-src li b { flex: none; min-width: 16px; border-radius: 3px; background: #E3F0FB; font-size: 10px; line-height: 16px; text-align: center; color: var(--navy); }
.mfs-scope { display: flex; align-items: flex-start; gap: 6px; font-size: 12px; color: var(--mfs-run); }
.mfs-scope svg { flex: none; width: 14px; height: 14px; margin-top: 2px; }
.mfs-input { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 6px 6px 14px; border: 1px solid var(--mfs-hair); border-radius: 20px; background: var(--white); color: var(--muted); }
.mfs-send { display: grid; flex: none; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--blue); color: var(--white); }
.mfs-send svg { width: 14px; height: 14px; }

/* ---- wider windows: MES bars and two columns, ERP and Quality side by side -- */
/* MES lines and ERP stock query their own panel width (not the stage), because
   the 600px two-column layout makes the panels narrow again. */
.mfs-lines { container: mfs-lines / inline-size; }
.mfs-stock { container: mfs-stock / inline-size; }
@container mfs-lines (min-width: 350px) {
  .mfs-lines ul { grid-template-columns: max-content max-content minmax(48px, 1fr) max-content; }
  .mfs-lines .mfs-st, .mfs-lines .mfs-num { white-space: nowrap; }
  .mfs-lines .mfs-bar { display: block; }
}
/* Narrow ERP stock (phones): two columns. The item spans two rows; the count
   folds after the slash ("1,850 /" + "1,200 kg", no-break spaces from the
   generator) with the status badge under it, so the item name keeps its room.
   overflow-wrap: normal keeps min-content at the longest word, not one letter. */
@container mfs-stock (max-width: 339.98px) {
  .mfs-stock ul { grid-template-columns: minmax(0, 1fr) min-content; row-gap: 6px; }
  .mfs-stock .mfs-item { grid-row: span 2; }
  .mfs-stock .mfs-num, .mfs-stock .mfs-th:nth-child(2) { white-space: normal; overflow-wrap: normal; }
  .mfs-stock .mfs-num { align-self: end; }
  .mfs-stock .mfs-st { align-self: start; justify-self: end; }
  .mfs-stock .mfs-th:nth-child(3) { display: none; }
}
@container (min-width: 600px) {
  .mfs-win--mes .mfs-body { grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.4fr); }
  .mfs-oee { grid-template-columns: 1fr; justify-items: center; gap: 10px; }
  .mfs-oee .mfs-h, .mfs-kpi { justify-self: stretch; }
  .mfs-gauge { width: 108px; }
  .mfs-stops { grid-column: 1 / -1; }
  .mfs-win--erp .mfs-body { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
  .mfs-win--qc .mfs-body { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .mfs-rate { grid-column: 1 / -1; }
}
@container (max-width: 359.98px) { .mfs-crumb { display: none; } }

/* ---- required caption under every product screen ---------------------------- */
.mfs-cap { margin: 14px 0 0; font-family: 'Noto Sans JP', sans-serif; font-size: 13px; line-height: 1.9; color: var(--muted); }
