/* Layout: one-screen instrument. Mobile = stage on top, tabbed panel below.
   Desktop = stage left, tabbed panel right. Palette: cool slate paper / controller-screen navy. */
:root {
  --bg: #E9EDF1;
  --panel: #FFFFFF;
  --panel-2: #F3F6F9;
  --fg: #13202B;
  --muted: #566878;
  --line: #D3DBE3;
  --accent: #0A6E91;
  --accent-soft: #D7ECF4;
  --accent-fg: #FFFFFF;
  --canvas: #FAFCFD;
  --grid: #E4EAEF;
  --grid-text: #6F8294;
  --axis: #8CA2B5;
  --rapid: #6F8294;
  --ghost: #7F93A8;
  --stock: #E3EAF0;
  --stock-line: #A3B5C5;
  --marker: #E4572E;
  --bad: #C23A3A;
  --bad-soft: #F9E1E1;
  --warn: #9A6200;
  --warn-soft: #FBEFD4;
  --good: #1F7A4D;
  --good-soft: #DCF1E5;
  --note: #566878;
  --note-soft: #E6ECF1;
  --t0: #1F6FD1; --t1: #0B9B8A; --t2: #7B4FD6; --t3: #C2338A;
  --t4: #3C9A2B; --t5: #A85F24; --t6: #1E9FC4; --t7: #B8860B;
  --font-ui: "Barlow", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Noto Sans Mono CJK TC", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1218; --panel: #131D27; --panel-2: #1A2631; --fg: #E4ECF3; --muted: #8DA0B2; --line: #263543;
    --accent: #4CC3E0; --accent-soft: #15384A; --accent-fg: #05212B;
    --canvas: #0A1117; --grid: #15202B; --grid-text: #6A7F93; --axis: #47607A;
    --rapid: #7C91A5; --ghost: #7C91A5; --stock: #17232E; --stock-line: #3A5064;
    --marker: #FF7A59; --bad: #FF7B7B; --bad-soft: #3A1D22; --warn: #F0B450; --warn-soft: #3A2C12;
    --good: #52CC90; --good-soft: #153525; --note: #8DA0B2; --note-soft: #1E2B37;
    --t0: #5B9DFF; --t1: #3DD6BF; --t2: #A98BFF; --t3: #FF6FB5; --t4: #7ED957; --t5: #E39A5A; --t6: #4CD0F0; --t7: #E3C04A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0B1218; --panel: #131D27; --panel-2: #1A2631; --fg: #E4ECF3; --muted: #8DA0B2; --line: #263543;
  --accent: #4CC3E0; --accent-soft: #15384A; --accent-fg: #05212B;
  --canvas: #0A1117; --grid: #15202B; --grid-text: #6A7F93; --axis: #47607A;
  --rapid: #7C91A5; --ghost: #7C91A5; --stock: #17232E; --stock-line: #3A5064;
  --marker: #FF7A59; --bad: #FF7B7B; --bad-soft: #3A1D22; --warn: #F0B450; --warn-soft: #3A2C12;
  --good: #52CC90; --good-soft: #153525; --note: #8DA0B2; --note-soft: #1E2B37;
  --t0: #5B9DFF; --t1: #3DD6BF; --t2: #A98BFF; --t3: #FF6FB5; --t4: #7ED957; --t5: #E39A5A; --t6: #4CD0F0; --t7: #E3C04A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--font-ui); font-size: 14px; line-height: 1.4;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  overflow-y: auto; -webkit-text-size-adjust: 100%;
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { height: 100%; min-height: 660px; display: grid; gap: 10px;
  grid-template-rows: auto minmax(0, 1.12fr) minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { flex: none; color: var(--accent); }
.brand h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.sel, .iconbtn, .txtbtn {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; height: 36px; color: var(--fg);
}
.sel { padding: 0 8px; max-width: 120px; }
.iconbtn { width: 36px; display: inline-grid; place-items: center; padding: 0; }
.iconbtn:hover, .txtbtn:hover, .sel:hover { border-color: var(--axis); }
.txtbtn { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; font-weight: 500; white-space: nowrap; }
.txtbtn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i .f { fill: currentColor; stroke: none; }

/* stage */
.stage { display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; }
.status { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); font-weight: 600; cursor: pointer; text-align: left; width: 100%; }
.status .dot { width: 10px; height: 10px; flex: none; }
.status.ok { background: var(--good-soft); color: var(--good); border-color: transparent; }
.status.ok .dot { border-radius: 50%; background: currentColor; }
.status.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status.warn .dot { background: currentColor; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.status.err { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.status.err .dot { background: currentColor; }
.status.empty { color: var(--muted); }
.status span.txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.halt { align-items: flex-start; padding: 8px 12px; }
.status.halt .dot { margin-top: 4px; }
.status.halt .txt { white-space: normal; overflow: visible; display: flex; flex-direction: column; gap: 2px; }
.status .txt .t { font-weight: 700; overflow-wrap: anywhere; }
.status .txt .t code { font-family: var(--font-mono); font-weight: 500; font-size: 12.5px; margin-left: 4px; }
.status .txt .r { font-weight: 500; color: var(--fg); }
.status .txt .h { font-weight: 400; font-size: 12.5px; color: var(--muted); }

.cwrap { position: relative; flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--canvas); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#cv.drag { cursor: grabbing; }
.hud { position: absolute; left: 8px; top: 8px; padding: 6px 9px; border-radius: 8px; background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line); font-family: var(--font-mono); font-size: 11.5px; line-height: 1.5; pointer-events: none; max-width: calc(100% - 64px); font-variant-numeric: tabular-nums; }
.hud b { font-weight: 600; color: var(--accent); }
.hud .dim { color: var(--muted); }
.hud .alarm { color: var(--bad); font-weight: 600; }
.zoom { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; }
.zoom .iconbtn { width: 34px; height: 34px; background: color-mix(in srgb, var(--panel) 88%, transparent); }
.legend { position: absolute; left: 8px; bottom: 24px; right: 8px; display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11.5px; color: var(--muted); pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 5px; background: color-mix(in srgb, var(--canvas) 82%, transparent); padding: 1px 6px; border-radius: 6px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top-width: 2.5px; border-top-style: solid; }
.legend i.dash { border-top-style: dashed; border-top-width: 2px; }
.legend i.dot { border-top-style: dotted; border-top-width: 3px; }
.drop { position: absolute; inset: 0; display: none; place-items: center; background: color-mix(in srgb, var(--accent) 18%, var(--canvas)); border: 2px dashed var(--accent); font-weight: 600; z-index: 3; }
body.dragging .drop { display: grid; }

.player { display: flex; flex-direction: column; gap: 6px; }
.scrub { width: 100%; height: 22px; margin: 0; accent-color: var(--accent); }
.ctrls { display: flex; align-items: center; gap: 6px; }
.ctrls .iconbtn { width: 40px; height: 40px; }
.ctrls .play { width: 52px; background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.ctrls .spacer { flex: 1; }
.ctrls .sel { height: 40px; max-width: 84px; font-family: var(--font-mono); }

/* side */
.side { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.tab { flex: 1; height: 40px; border: 0; background: transparent; color: var(--muted); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-bottom: 2px solid transparent; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); background: var(--panel); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 12px; display: inline-grid; place-items: center; background: var(--note-soft); color: var(--note); }
.badge.err { background: var(--bad); color: #fff; }
.badge.warn { background: var(--warn); color: #fff; }
:root[data-theme="dark"] .badge.warn, :root:not([data-theme="light"]) .badge.warn { color: #1A1204; }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.panel[hidden] { display: none !important; }
.ptool { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }
.ptool > * { flex: 1 1 0; min-width: 0; height: 36px; max-width: none; justify-content: center; }
.ptool .txtbtn { padding: 0 8px; }
.ptool .txtbtn span { overflow: hidden; text-overflow: ellipsis; }
.ed { --lh: 22px; flex: 1; min-height: 0; display: flex; position: relative; font-family: var(--font-mono); font-size: 13px; line-height: var(--lh); }
.gut { width: 54px; flex: none; overflow: hidden; background: var(--panel-2); border-right: 1px solid var(--line); user-select: none; }
#gutin { padding-top: 4px; will-change: transform; }
.g { height: var(--lh); display: grid; grid-template-columns: 1fr 14px; align-items: center; cursor: pointer; }
.g .n { text-align: right; padding-right: 4px; color: var(--muted); font-size: 11px; }
.g .mk { width: 8px; height: 8px; justify-self: center; }
.g.e .mk { background: var(--bad); }
.g.w .mk { background: var(--warn); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.g.i .mk { background: var(--note); border-radius: 50%; width: 6px; height: 6px; }
.g.on .n { color: var(--accent); font-weight: 700; }
.edmain { position: relative; flex: 1; min-width: 0; }
.hl { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
#hlin { padding-top: 4px; will-change: transform; }
.hl div { height: var(--lh); }
.hl .e { background: var(--bad-soft); }
.hl .w { background: var(--warn-soft); }
.hl .on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.hl .halt, .hl .halt.on { background: var(--bad-soft); box-shadow: inset 3px 0 0 var(--bad); }
#ta { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; outline: 0; resize: none; padding: 4px 12px 4px 8px; margin: 0;
  font: inherit; line-height: var(--lh); background: transparent; color: var(--fg); white-space: pre; overflow: auto; tab-size: 4; caret-color: var(--accent); -webkit-overflow-scrolling: touch; }
@media (pointer: coarse) { .ed { --lh: 24px; font-size: 16px; } .gut { width: 58px; } .g .n { font-size: 12px; } }
.toast { position: absolute; left: 10px; right: 10px; bottom: 44px; padding: 8px 12px; border-radius: 8px; background: var(--fg); color: var(--panel); font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 5; }
.side { position: relative; }
.wi { cursor: pointer; }
.wi .acts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.wi .act { height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-weight: 600; font-size: 13px; }
.wi .act.fix { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .wi .act.fix, :root:not([data-theme="light"]) .wi .act.fix { color: #06141F; }
.wi .act:hover { filter: brightness(.96); }
.sec { margin: 8px 2px 0; font-weight: 700; font-size: 13px; }
.secnote { margin: 0 2px; font-size: 12.5px; color: var(--muted); }
.wi.more { opacity: .92; border-style: dashed; }
.sep { height: 1px; background: var(--line); margin: 4px 0; }
dialog[open] { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
dialog .dlg-b { overflow: auto; min-height: 0; }
.hint { padding: 6px 12px; font-size: 12.5px; color: var(--muted); background: var(--panel-2); border-top: 1px solid var(--line); }

.list { flex: 1; min-height: 0; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.empty { color: var(--muted); padding: 20px 8px; text-align: center; }
.wi { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; text-align: left; width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.wi:hover { border-color: var(--axis); }
.pill { display: inline-block; font-size: 11.5px; font-weight: 700; letter-spacing: .03em; padding: 1px 8px; border-radius: 6px; align-self: start; white-space: nowrap; }
.pill.error { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--note-soft); color: var(--note); }
.pill.limit { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1px currentColor; }
.tag { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 6px; background: var(--bad); color: #fff; font-family: var(--font-ui); font-weight: 700; font-size: 11.5px; }
.wi.halt { border-color: var(--bad); box-shadow: inset 3px 0 0 var(--bad); }
.wi .where { font-family: var(--font-mono); font-size: 12px; color: var(--muted); align-self: center; }
.wi .msg { grid-column: 1 / -1; overflow-wrap: anywhere; }
.wi .src { grid-column: 1 / -1; font-family: var(--font-mono); font-size: 12px; padding: 4px 8px; background: var(--panel-2); border-radius: 6px; color: var(--muted); overflow-x: auto; white-space: pre; }

.info { flex: 1; min-height: 0; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 14px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel-2); min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-family: var(--font-mono); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border: 1px solid var(--line); border-radius: 999px; font-family: var(--font-mono); font-size: 12.5px; }
.chip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.info h3 { margin: 0 0 4px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.info p { margin: 0; font-family: var(--font-mono); font-size: 12px; line-height: 1.7; color: var(--fg); overflow-wrap: anywhere; }
.info .disc { font-family: var(--font-ui); font-size: 13px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; }

/* settings dialog */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--fg); padding: 0; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 12, 18, .55); }
.dlg-h { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; }
.dlg-b { padding: 14px 16px; display: grid; gap: 12px; }
.fld { display: grid; gap: 4px; }
.fld label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.fld .sel, .fld input { width: 100%; max-width: none; height: 38px; padding: 0 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg-b .note { font-size: 12.5px; color: var(--muted); margin: 0; }
.dlg-f { padding: 10px 16px 14px; display: flex; justify-content: flex-end; }

/* desktop */
@media (min-width: 900px) {
  .app { grid-template-columns: minmax(0, 1.55fr) minmax(360px, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
  .top { grid-column: 1 / -1; }
  .hud { font-size: 12.5px; }
}
@media (max-width: 420px) {
  .brand h1 { font-size: 16px; }
  .sel { max-width: 104px; }
  .txtbtn .lbl-long { display: none; }
  .legend { font-size: 10.5px; gap: 3px 6px; }
  .ctrls { gap: 4px; }
  .ctrls .iconbtn { width: 38px; }
  .ctrls .play { width: 48px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* ---- Plan tab */
#panel-plan { min-height: 0; }
.plan-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.plan-intro { margin: 0; font-size: 12.5px; color: var(--muted); }
.plan-prev { border: 1px solid var(--line); border-radius: 10px; background: var(--canvas); padding: 6px 8px 4px; }
#pl-svg { width: 100%; height: 118px; display: block; }
.pv-stock { fill: var(--stock); stroke: var(--stock-line); stroke-width: 1.2; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.pv-bore { fill: var(--canvas); stroke: var(--stock-line); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.pv-axis { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 8 3 2 3; vector-effect: non-scaling-stroke; }
.pv-part { fill: var(--accent-soft); stroke: none; }
.pv-fg { fill: var(--canvas); stroke: var(--accent); stroke-width: 1; vector-effect: non-scaling-stroke; }
.pv-cut { fill: var(--accent); fill-opacity: 0.18; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.pv-thread { fill: var(--accent); fill-opacity: 0.35; stroke: var(--accent); stroke-width: 0.8; stroke-dasharray: 1.5 1.5; vector-effect: non-scaling-stroke; }
.pv-line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.pv-centre { fill: none; stroke: var(--marker); stroke-width: 1.4; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.plan-lg { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--muted); padding: 2px 2px 0; }
.plan-lg span { display: inline-flex; align-items: center; gap: 5px; }
.plan-lg i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; }
.plan-lg .lg-stock { border-top-style: dashed; border-color: var(--stock-line); }
.plan-lg .lg-bore { border-top-style: dotted; border-color: var(--stock-line); }
.plan-lg .lg-part { border-color: var(--accent); border-top-width: 3px; }
.plan-lg .lg-centre { border-color: var(--marker); border-top-style: dashed; }
.vbox { border-radius: 10px; padding: 9px 12px; border: 1px solid transparent; }
.vbox.good { background: var(--good-soft); color: var(--fg); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.vbox.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.vbox.note { background: var(--note-soft); margin-top: 8px; }
.vbox .vh { font-weight: 700; font-size: 15px; }
.vbox.good .vh { color: var(--good); }
.vbox.bad .vh { color: var(--bad); }
.vbox .note { margin: 4px 0 6px; font-size: 12.5px; color: var(--muted); }
.rl { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 3px; font-size: 13px; }
.rl.ok { list-style: none; padding-left: 0; }
.rl.ok li::before { content: "✓"; color: var(--good); font-weight: 700; margin-right: 6px; }
.rl.note { margin-top: 0; font-size: 12.5px; color: var(--note); }
.rl b { font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; }
.pl-sec { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.pl-sec > summary { cursor: pointer; padding: 10px 12px; font-weight: 700; list-style: none; display: flex; align-items: center; gap: 8px; min-height: 40px; }
.pl-sec > summary::-webkit-details-marker { display: none; }
.pl-sec > summary::before { content: "▸"; color: var(--muted); transition: transform .12s; }
.pl-sec[open] > summary::before { transform: rotate(90deg); }
.pl-body { padding: 2px 12px 12px; display: grid; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pl-body .note, .pcb .note { margin: 0; font-size: 12.5px; color: var(--muted); }
.seg2 { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segb { height: 36px; border: 0; background: var(--panel-2); font-weight: 600; color: var(--muted); }
.segb.on { background: var(--accent); color: var(--accent-fg); }
.pcard { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.pcard.start { opacity: .85; }
.pch { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; min-height: 40px; }
.pch .sp, .plan-bar .sp { flex: 1; }
.pn { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; font-family: var(--font-mono); }
.pch .meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.mini { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 16px; line-height: 1; padding: 0; flex: none; }
.mini:disabled { opacity: .35; cursor: default; }
.pcb { padding: 0 10px 10px; display: grid; gap: 8px; }
.pcb .fld input, .pcb .fld .sel, .ptr input, .ptr .sel, .cgrow input, .cgrow .sel { width: 100%; max-width: none; height: 38px; padding: 0 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.cg[hidden] { display: none; }
.cg .lb { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.cgrow { display: grid; grid-template-columns: 1.3fr 1fr; gap: 8px; }
.addrow { display: flex; flex-wrap: wrap; gap: 8px; }
.ptab { display: grid; gap: 6px; overflow-x: auto; }
.ptr { display: grid; grid-template-columns: 24px minmax(58px, 1fr) minmax(58px, 1fr) minmax(86px, 1.3fr) minmax(46px, .8fr) minmax(70px, 1fr) minmax(46px, .8fr) 32px; gap: 4px; align-items: center; min-width: 500px; }
.ptr.ph { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.plan-disc { margin: 0; font-size: 12px; color: var(--muted); }
.plan-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.plan-bar .txtbtn { height: 38px; }
.plan-bar .txtbtn:disabled { opacity: .45; cursor: default; }
.vchip { font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--note-soft); color: var(--note); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.vchip.good { background: var(--good-soft); color: var(--good); }
.vchip.bad { background: var(--bad-soft); color: var(--bad); }
@media (max-width: 520px) { .plan-bar .txtbtn { padding: 0 9px; font-size: 13px; } .vchip { max-width: 34%; } }
.plan-scroll { overflow-x: hidden; }
.plan-scroll > *, .pl-body > *, .pcb > *, .pl-sec, .pcard, .row2 > *, .row3 > *, .cgrow > *, .fld { min-width: 0; }
.pl-body input, .pl-body select, .pcb input, .pcb select { min-width: 0; width: 100%; }
.pl-body, .pcb { grid-template-columns: minmax(0, 1fr); }
.plan-bar { flex-wrap: wrap; row-gap: 6px; }
.plan-bar .txtbtn { flex: 1 1 0; min-width: 0; justify-content: center; overflow: hidden; text-overflow: ellipsis; }
.plan-bar .txtbtn:last-of-type { flex: 1.4 1 0; }
.plan-bar .sp { display: none; }
.vchip { flex: 0 0 100%; max-width: none !important; text-align: center; }
@media (min-width: 900px) { .vchip { flex: 0 1 auto; max-width: 30% !important; } .plan-bar .txtbtn { flex: 0 0 auto; } .plan-bar .sp { display: block; } }

.trial-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 12.5px; font-weight: 600; }
.trial-banner span { flex: 1 1 200px; }
.trial-banner .txtbtn { height: 32px; text-decoration: none; }
select:disabled, input:disabled { opacity: .55; }

/* units: a suffix inside every number field of the Plan tab */
.inu { position: relative; min-width: 0; }
.inu input { padding-right: 46px !important; }
.inu .un { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 11.5px; font-weight: 600; color: var(--muted); pointer-events: none; white-space: nowrap; }
.plan-units { display: grid; grid-template-columns: auto minmax(0, 260px); align-items: center; gap: 10px; }
.plan-units .lb { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.ptr.ph small { font-weight: 500; opacity: .8; }

/* operation sheet (工序卡) */
.sheet-row { margin-top: 10px; display: flex; justify-content: flex-end; }
dialog.sheet-dlg { width: min(1180px, calc(100vw - 16px)); }
.sheet-b { gap: 10px; }
.sheet-head { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 10px; }
.shf { display: grid; gap: 2px; min-width: 0; }
.shf label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.shf span { font-size: 13.5px; overflow-wrap: anywhere; }
.shf input { height: 30px; padding: 0 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; min-width: 0; }
.sheet-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.sheet-t { border-collapse: collapse; width: 100%; min-width: 980px; font-size: 12.5px; }
.sheet-t th, .sheet-t td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 5px 6px; text-align: left; vertical-align: top; }
.sheet-t th { background: var(--panel-2); font-weight: 700; white-space: nowrap; font-size: 12px; }
.sheet-t td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sheet-t td.ed { padding: 2px; min-width: 120px; }
.sheet-t td.ed textarea { width: 100%; min-width: 110px; resize: vertical; font: inherit; padding: 3px 5px; border: 1px dashed var(--line); border-radius: 4px; background: var(--panel-2); color: var(--fg); }
.sheet-t tfoot td { font-weight: 700; background: var(--panel-2); }
.sheet-f { gap: 8px; align-items: center; }
.sheet-f .sp { flex: 1; }
#print-area { display: none; }
@media print {
  html.printing body > *:not(#print-area) { display: none !important; }
  html.printing #print-area { display: block; }
  html.printing, html.printing body { background: #fff !important; color: #000 !important; height: auto !important; min-height: 0 !important; overflow: visible !important; }
  .sheet-print { font-size: 10pt; color: #000; }
  .sheet-print h1 { font-size: 15pt; margin: 0 0 8px; }
  .sheet-print .sheet-head { grid-template-columns: repeat(5, 1fr); margin-bottom: 8px; }
  .sheet-print .shf label { color: #444; }
  .sheet-print .shf span { border-bottom: 1px solid #999; min-height: 1.3em; display: block; }
  .sheet-print .sheet-t { min-width: 0; font-size: 8.5pt; }
  .sheet-print .sheet-t th, .sheet-print .sheet-t td { border: 1px solid #555; color: #000; background: #fff; }
  .sheet-print .note { font-size: 8pt; color: #333; }
  @page { size: A4 landscape; margin: 10mm; }
}

/* footer, safety gate, e-mail sign-up (D-015) */
.foot { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 10px; padding: 2px 0 4px; font-size: 13px; color: var(--muted); }
.foot .txtbtn { height: 30px; font-size: 13px; }
.linkbtn { background: none; border: 0; padding: 4px 2px; color: var(--accent); text-decoration: underline; font-size: 13px; }
ul.legal { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; line-height: 1.5; }
.chk { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; font-weight: 600; cursor: pointer; }
.chk input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
#gate-go:disabled { opacity: .45; cursor: not-allowed; }
.em-f { gap: 8px; }
.em-msg { margin: 0; min-height: 1.2em; font-size: 13px; }
.em-msg.ok { color: var(--ok, #1d7a4a); } .em-msg.bad { color: var(--bad); }
#em-input { width: 100%; height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.info ul.legal { font-size: 13px; color: var(--muted); }

.chk-s { font-size: 13px; font-weight: 500; }
#em-policy { justify-self: start; padding: 0; }

/* cncvia: embedded in a site page - the site header already has the language switch */
body.lp-embed #lang { display: none; }
#em-send:disabled { opacity: .5; cursor: default; }
