/* Titan 4 Progressive 1:1 SN Workbench v3.0 — Native Responsive Flexbox + Split Blueprint Dock */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #eae2d3;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #24201c;
  font-variant-numeric: tabular-nums;
}

.mo { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace; }

/* ---------------- Top Workbench Header ---------------- */
.hdr {
  flex: 0 0 54px;
  height: 54px;
  background: #fcf9f3;
  border-bottom: 1px solid #d9cdba;
  box-shadow: 0 2px 10px rgba(75, 56, 32, 0.06);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
  z-index: 40;
}
.hdr-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-right: 10px;
  border-right: 1px solid #e4d9c6;
  flex-shrink: 0;
}
.hdr-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: block;
  box-shadow: 0 2px 6px rgba(25, 20, 16, 0.16);
}
.hdr-brand-txt {
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.hdr-brand-txt b {
  font-size: 16.5px;
  font-weight: 800;
  letter-spacing: -0.3px;
  line-height: 1.05;
  color: #1f1b18;
}
.hdr-brand-txt span {
  font-size: 8.2px;
  font-weight: 600;
  letter-spacing: 1.4px;
  color: #6b6052;
  margin-top: 2px;
}

.hdr-title { display: flex; flex-direction: column; flex-shrink: 0; margin-right: 2px; }
.hdr-title h1 { margin: 0; font-size: 14.5px; font-weight: 700; color: #1f1b18; white-space: nowrap; }
.hdr-title p { margin: 1px 0 0; font-size: 9.5px; color: #786d5f; white-space: nowrap; }

.icon-toggle {
  height: 30px;
  padding: 0 8px;
  border-radius: 5px;
  border: 1px solid #d8ccb8;
  background: #fffdf9;
  color: #3a332c;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
.icon-toggle:hover { background: #f4ece0; border-color: #bfa98b; }
.icon-toggle.active { background: #26221e; border-color: #26221e; color: #fff; }

.search-wrap {
  position: relative;
  flex: 1 1 260px;
  max-width: 340px;
  min-width: 170px;
  display: flex;
  align-items: center;
}
.search-wrap input {
  width: 100%;
  height: 32px;
  padding: 0 76px 0 28px;
  border-radius: 6px;
  border: 1.5px solid #d5c8b2;
  background: #fffdf9;
  font-size: 11.5px;
  color: #231f1b;
  outline: none;
  user-select: text;
}
.search-wrap input:focus { border-color: #e3562a; box-shadow: 0 0 0 3px rgba(227, 86, 42, 0.14); }
.search-icon { position: absolute; left: 8px; color: #8c7f6f; pointer-events: none; }
.search-actions {
  position: absolute;
  right: 4px;
  display: flex;
  align-items: center;
  gap: 3px;
}
.search-scope-btn, .search-clear {
  padding: 2px 5px;
  font-size: 9.5px;
  border-radius: 4px;
  border: 1px solid #dcd0bc;
  background: #f5efe4;
  color: #4c4339;
  cursor: pointer;
  font-weight: 600;
}
.search-scope-btn.scoped { background: #fdece5; border-color: #e3562a; color: #c84218; }

.hdr-select {
  height: 30px;
  max-width: 185px;
  padding: 0 6px;
  border-radius: 5px;
  border: 1px solid #d8ccb8;
  background: #fffdf9;
  color: #2c2722;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 1;
}

.hdr-ctrls {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  flex-shrink: 0;
}
.chip-btn {
  height: 30px;
  padding: 0 8.5px;
  border-radius: 5px;
  border: 1px solid #d8ccb8;
  background: #fffdf9;
  color: #352f29;
  font: 600 10.5px 'Inter', sans-serif;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.chip-btn:hover { border-color: #b8a88e; background: #f6efe4; }
.chip-btn.active { background: #e3562a; border-color: #d1491f; color: #fff; }
.chip-btn.accent { border-color: #e3562a; color: #c94117; background: #fff6f1; }
.chip-btn.accent.active { background: #e3562a; color: #fff; }
.chip-btn i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.cart-badge {
  padding: 0 5px;
  border-radius: 9px;
  background: #e3562a;
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
}
.chip-btn.active .cart-badge { background: #fff; color: #e3562a; }

.explode-box {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 7px 0 4px;
  height: 30px;
  border-radius: 5px;
  border: 1px solid #d8ccb8;
  background: #fffdf9;
  font-size: 10px;
  font-weight: 600;
}
.ex-scope-btn {
  height: 22px;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid #dcd0bc;
  background: #f5efe4;
  color: #3c342c;
  font-size: 9.8px;
  font-weight: 700;
  cursor: pointer;
}
.ex-scope-btn.local { background: #fff2eb; border-color: #e3562a; color: #c84218; }
.explode-box input[type="range"] { width: 68px; accent-color: #e3562a; cursor: pointer; }

/* ---------------- Main Workspace (Left | Center Stage + Split Blueprint | Right) ---------------- */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* Left Collapsible Subsystem Sidebar */
.left-sidebar {
  flex: 0 0 258px;
  width: 258px;
  background: #faf6ee;
  border-right: 1px solid #dcd0bc;
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
  transition: margin-left 0.18s ease;
}
.left-sidebar.collapsed { margin-left: -258px; }

.sec-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 11px 7px;
  border-bottom: 1px solid #e7decb;
  background: #f5efe3;
  flex-shrink: 0;
}
.sec-hd b {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 0.6px;
  color: #24201c;
}
.sec-hd b::before { content: ""; display: block; width: 3px; height: 12px; background: #e3562a; border-radius: 1px; }
.sec-hd span { font-size: 9.8px; color: #7e7161; }

.sub-list {
  flex: 1;
  padding: 6px 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.sub-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6.5px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: rgba(240, 233, 220, 0.55);
  cursor: pointer;
  gap: 6px;
}
.sub-item:hover { background: #efe6d5; border-color: #d4c5ae; }
.sub-item.active { background: #fff5ef; border-color: #e3562a; box-shadow: inset 3px 0 0 #e3562a; }
.sub-code { font-size: 9.5px; font-weight: 700; color: #e3562a; width: 24px; flex-shrink: 0; }
.sub-meta { flex: 1; min-width: 0; }
.sub-meta div { font-size: 12px; font-weight: 600; color: #221e1a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-meta small { display: block; font-size: 9.2px; color: #7c7061; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-cnt { font-size: 9.5px; padding: 1.5px 6px; border-radius: 10px; background: #e6dccb; color: #554b40; font-weight: 600; }
.sub-item.active .sub-cnt { background: #e3562a; color: #fff; }

.left-foot {
  padding: 7px 10px;
  border-top: 1px solid #e7decb;
  background: #f4ede1;
  font-size: 10px;
  color: #6a5f51;
  line-height: 1.45;
}

/* Center Area: 3D Viewport + Optional Docked Blueprint Split View */
.center-area {
  flex: 1;
  min-width: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

.viewport-pane {
  flex: 1 1 55%;
  min-width: 260px;
  position: relative;
  overflow: hidden;
  background: #ede6d9;
}

#gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#gl.dragging { cursor: grabbing; }
#gl.panning { cursor: move; }
#gl.hover-part { cursor: pointer; }

/* 3D Leader Callouts inside viewport-pane */
.leaders-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
}
.callout-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 9;
}
.callout-tag {
  position: absolute;
  transform: translateY(-50%);
  padding: 4px 8px;
  border-radius: 5px;
  background: rgba(253, 250, 245, 0.94);
  border: 1px solid #d5c7b0;
  box-shadow: 0 2px 8px rgba(60, 44, 24, 0.11);
  pointer-events: auto;
  cursor: pointer;
  white-space: nowrap;
}
.callout-tag:hover { border-color: #e3562a; }
.callout-tag.active { border: 1.5px solid #e3562a; background: #fff4ee; z-index: 14; }
.callout-tag .ct-top { display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 700; }
.callout-tag .ct-dot { width: 6px; height: 6px; border-radius: 50%; background: #e3562a; }
.callout-tag .ct-pn { color: #c94117; }
.callout-tag .ct-it { color: #786c5e; font-size: 9px; }
.callout-tag .ct-zh { font-size: 9.8px; color: #302b26; margin-top: 1px; }

/* Viewport Floating Overlays */
.prog-pill {
  position: absolute;
  left: 12px;
  top: 10px;
  height: 26px;
  padding: 0 11px;
  border-radius: 13px;
  background: rgba(252, 249, 243, 0.92);
  border: 1px solid #dfd4c1;
  box-shadow: 0 2px 8px rgba(80, 60, 35, 0.08);
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  color: #3e372f;
  z-index: 16;
}
.prog-dot { width: 7px; height: 7px; border-radius: 50%; background: #268e58; }
.prog-dot.busy { background: #e3562a; animation: pulseDot 0.9s infinite alternate; }
@keyframes pulseDot { from { opacity: 0.3; } to { opacity: 1; } }
.prog-bar { width: 52px; height: 4px; background: #e6dccb; border-radius: 2px; overflow: hidden; }
.prog-bar > div { height: 100%; background: #e3562a; transition: width 0.15s; }

.vp-quickbar {
  position: absolute;
  right: 12px;
  top: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 16;
}
.vp-btn {
  height: 27px;
  padding: 0 9px;
  border-radius: 5px;
  border: 1px solid #d5c7b1;
  background: rgba(252, 249, 243, 0.94);
  color: #332d27;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(60, 44, 24, 0.08);
}
.vp-btn:hover { background: #fff; border-color: #e3562a; color: #c84218; }

.peel-banner {
  position: absolute;
  left: 50%;
  top: 42px;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 14px;
  background: rgba(38, 34, 30, 0.9);
  color: #fff;
  font-size: 10.5px;
  display: none;
  align-items: center;
  gap: 8px;
  z-index: 18;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}
.peel-banner.show { display: flex; }
.peel-banner button {
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: #e3562a;
  color: #fff;
  font-size: 9.8px;
  font-weight: 600;
  cursor: pointer;
}
.peel-banner button.ghost { background: transparent; }

/* Collapsible 7-DOF Floating Drawer */
.dof-drawer {
  position: absolute;
  left: 12px;
  bottom: 42px;
  width: 266px;
  background: rgba(252, 249, 243, 0.95);
  border: 1px solid #dacdb8;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(65, 48, 28, 0.12);
  z-index: 18;
  overflow: hidden;
}
.dof-drawer-hd {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 10.8px;
  font-weight: 700;
  color: #2a2520;
  background: rgba(244, 237, 225, 0.75);
}
.dof-drawer-hd:hover { background: #efe6d6; }
.dof-drawer-body {
  display: none;
  border-top: 1px solid #e7decb;
}
.dof-drawer.open .dof-drawer-body { display: block; }
.pose-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px 8px 4px; }
.pose-btn {
  padding: 3.5px 2px; font-size: 9.5px; font-weight: 600; border: 1px solid #dcd0bc;
  border-radius: 4px; background: #fffdf9; color: #463e35; cursor: pointer;
}
.pose-btn.active, .pose-btn:hover { border-color: #e3562a; color: #e3562a; background: #fff6f2; }
.dof-rows { padding: 3px 9px 6px; display: flex; flex-direction: column; gap: 4px; }
.dof-row { display: grid; grid-template-columns: 60px 1fr 52px; align-items: center; gap: 5px; font-size: 10px; }
.dof-row label { font-weight: 600; color: #4a4238; }
.dof-row input[type="range"] { width: 100%; height: 4px; accent-color: #e3562a; cursor: pointer; }
.dof-val { text-align: right; font-weight: 600; }
.kin-strip {
  padding: 5px 9px; border-top: 1px solid #ebe2d2;
  background: rgba(242, 235, 222, 0.55); display: flex; justify-content: space-between; font-size: 9.5px; color: #5e5347;
}

.vp-hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 8px;
  height: 26px;
  padding: 0 11px;
  border-radius: 6px;
  background: rgba(252, 249, 243, 0.90);
  border: 1px solid #dfd4c1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: #655a4d;
  z-index: 15;
  pointer-events: none;
}

.hover-tip {
  position: absolute;
  padding: 5px 9px;
  border-radius: 5px;
  background: rgba(30, 26, 22, 0.94);
  color: #fff;
  font-size: 11px;
  pointer-events: none;
  z-index: 35;
  white-space: nowrap;
  transform: translate(14px, -20px);
  display: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
}
.hover-tip b { color: #ff8a61; margin-right: 6px; }

/* 3D Right-Click Context Menu */
.ctx-menu {
  position: absolute;
  min-width: 196px;
  background: #fcf9f3;
  border: 1px solid #cbbba2;
  border-radius: 7px;
  box-shadow: 0 10px 28px rgba(30, 22, 14, 0.24);
  padding: 4px;
  z-index: 60;
  display: none;
  flex-direction: column;
}
.ctx-menu.open { display: flex; }
.ctx-hd {
  padding: 5px 8px;
  font-size: 10px;
  font-weight: 700;
  color: #7c6f60;
  border-bottom: 1px solid #e8dfd0;
  margin-bottom: 2px;
}
.ctx-item {
  padding: 6px 9px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: #28231e;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ctx-item:hover { background: #fdece5; color: #c94117; }
.ctx-item small { font-size: 9.5px; color: #8c7f6f; }

/* ---------------- Split-Screen Interactive Blueprint Dock ---------------- */
.bp-dock {
  flex: 0 0 47%;
  width: 47%;
  min-width: 300px;
  background: #f5efe4;
  border-left: 2px solid #d2c3ac;
  display: none;
  flex-direction: column;
  position: relative;
  z-index: 22;
}
.bp-dock.open { display: flex; }
.bp-dock.maximized {
  position: absolute;
  inset: 0;
  width: 100% !important;
  flex: 1 1 100% !important;
  z-index: 45;
}
.bp-dock-hd {
  padding: 7px 10px;
  background: #efe7d8;
  border-bottom: 1px solid #d9cbb5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}
.bp-dock-title {
  font-size: 11.5px;
  font-weight: 700;
  color: #221e1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.bp-pages-bar {
  padding: 5px 10px;
  background: #f8f4ec;
  border-bottom: 1px solid #e5dac7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}
.bp-page-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.bp-tools { display: flex; gap: 4px; align-items: center; }
.bp-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #ded6c7;
  cursor: grab;
}
.bp-stage.panning { cursor: grabbing; }
.bp-stage img {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  background: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.20);
  border-radius: 3px;
  user-select: none;
  -webkit-user-drag: none;
  max-width: none;
}
.bp-foot-hint {
  position: absolute;
  left: 10px;
  bottom: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(32, 28, 24, 0.78);
  color: #fff;
  font-size: 9.8px;
  pointer-events: none;
}

/* ---------------- Right Collapsible SN Card + Virtualized BOM Sidebar ---------------- */
.right-sidebar {
  flex: 0 0 412px;
  width: 412px;
  background: #faf6ee;
  border-left: 1px solid #dcd0bc;
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 20;
  transition: margin-right 0.18s ease;
}
.right-sidebar.collapsed { margin-right: -412px; }

.sn-card {
  flex: 0 0 auto;
  margin: 8px 8px 6px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid #e3562a;
  background: linear-gradient(180deg, #fffaf5 0%, #fcf7ef 100%);
  box-shadow: 0 3px 10px rgba(120, 60, 25, 0.07);
}
.sn-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.sn-label { font-size: 9px; font-weight: 700; letter-spacing: 1px; color: #e3562a; }
#app.immersive-3d .hdr { display: none; }

/* Edge Collapse Handles & Immersive Mini SN HUD */
.edge-handle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 26;
  padding: 12px 4px;
  background: rgba(252, 249, 243, 0.92);
  border: 1px solid #d5c6b0;
  color: #4a4035;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(60, 44, 24, 0.10);
  writing-mode: vertical-rl;
  letter-spacing: 2px;
}
.edge-handle:hover { background: #e3562a; border-color: #e3562a; color: #fff; }
.edge-handle.left { left: 0; border-left: none; border-radius: 0 6px 6px 0; }
.edge-handle.right { right: 0; border-right: none; border-radius: 6px 0 0 6px; }

.vp-btn.active { background: #e3562a; border-color: #d1491f; color: #fff; }

.mini-sn-hud {
  position: absolute;
  right: 14px;
  bottom: 42px;
  max-width: 390px;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1.5px solid #e3562a;
  background: rgba(255, 250, 244, 0.96);
  box-shadow: 0 6px 20px rgba(50, 35, 18, 0.16);
  display: none;
  align-items: center;
  gap: 8px;
  z-index: 24;
}
.mini-sn-hud.show { display: flex; }
.mini-sn-hud .m-pn { font-size: 16px; font-weight: 700; color: #1b1714; white-space: nowrap; user-select: text; }
.mini-sn-hud .m-zh { font-size: 11.5px; font-weight: 600; color: #3a322b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }

.sn-pn-row { display: flex; align-items: center; gap: 4px; margin-top: 3px; flex-wrap: nowrap; }
.sn-pn { font-size: 19px; font-weight: 700; color: #1b1714; user-select: text; margin-right: 2px; white-space: nowrap; }

.act-btn {
  height: 23px;
  padding: 0 6.5px;
  border-radius: 4px;
  border: 1px solid #d5c6b0;
  background: #fffdf9;
  color: #2f2923;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}
.act-btn.primary { background: #e3562a; border-color: #e3562a; color: #fff; }
.act-btn.primary.copied { background: #268e58; border-color: #268e58; }
.act-btn.cart-add { border-color: #268e58; color: #1c7344; background: #f2fbf5; }
.act-btn:hover { filter: brightness(0.96); }

.sn-balloon {
  padding: 3px 7px;
  border-radius: 4px;
  background: #26221e;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.sn-name-zh { margin-top: 5px; font-size: 13px; font-weight: 700; color: #221e1a; }
.sn-desc-en { margin-top: 1px; font-size: 9.8px; color: #6e6255; user-select: text; }

.sn-grid {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #e1d5c2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
  font-size: 10px;
}
.sn-kv span { color: #827565; margin-right: 4px; }
.sn-kv b { color: #25211d; user-select: text; }

/* Same-P/N Cross-Assembly Distribution Bar */
.sn-xref-bar {
  margin-top: 6px;
  padding: 5px 7px;
  border-radius: 5px;
  background: #f5efe4;
  border: 1px solid #e5dac7;
  font-size: 9.8px;
  color: #4d4338;
}
.xref-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  max-height: 48px;
  overflow-y: auto;
}
.xref-chip {
  padding: 1.5px 6px;
  border-radius: 4px;
  border: 1px solid #d5c6b0;
  background: #fffdf9;
  font-size: 9.2px;
  font-weight: 600;
  color: #3d352d;
  cursor: pointer;
}
.xref-chip:hover { border-color: #e3562a; color: #c94117; }
.xref-chip.current { background: #e3562a; border-color: #e3562a; color: #fff; }

.sn-platform-bar {
  margin-top: 5px;
  padding: 4.5px 7px;
  border-radius: 4px;
  background: #efe7da;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 9.8px;
  color: #4a4035;
}

/* Virtualized 1,386-Item BOM Panel */
.bom-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #dcd0bc;
}
.search-banner {
  display: none;
  padding: 4px 10px;
  background: #fff3eb;
  border-bottom: 1px solid #f2d2be;
  font-size: 10px;
  color: #b53d15;
  align-items: center;
  justify-content: space-between;
}
.search-banner.show { display: flex; }

.cat-tabs {
  display: flex;
  gap: 4px;
  padding: 5px 8px;
  border-bottom: 1px solid #e7decb;
  flex-wrap: wrap;
  background: #faf6ee;
}
.cat-tab {
  padding: 2.5px 6.5px;
  border-radius: 4px;
  border: 1px solid #dcd0bc;
  background: #fffdf9;
  font-size: 9.8px;
  font-weight: 600;
  color: #5b5145;
  cursor: pointer;
}
.cat-tab.active { background: #26221e; border-color: #26221e; color: #fff; }

.bom-head {
  display: grid;
  grid-template-columns: 42px 88px 1fr 56px;
  padding: 5px 10px;
  font-size: 9.2px;
  font-weight: 700;
  color: #827564;
  background: #f3ece0;
  border-bottom: 1px solid #e4d9c6;
  flex-shrink: 0;
}

.bom-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  position: relative;
  background: #fcf9f3;
}
.bom-phantom { width: 1px; pointer-events: none; }
.bom-slice {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: 0 4px;
}
.bom-row {
  height: 46px;
  display: grid;
  grid-template-columns: 42px 88px 1fr 56px;
  align-items: center;
  padding: 0 6px;
  border-radius: 5px;
  cursor: pointer;
  border-bottom: 1px solid rgba(226, 216, 200, 0.45);
}
.bom-row:hover { background: #f3ebdd; }
.bom-row.active { background: #fdece5; outline: 1.5px solid #e3562a; z-index: 2; }
.b-item { font-size: 9.5px; font-weight: 600; color: #6f6457; }
.b-pn { font-size: 11px; font-weight: 700; color: #d2461b; }
.b-name { min-width: 0; padding-right: 4px; }
.b-name div { font-size: 11px; font-weight: 600; color: #24201c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-name small { display: block; font-size: 9px; color: #7c7061; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-right { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.b-qty { font-size: 10px; font-weight: 600; color: #4f463c; }
.b-cart-btn {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid #d2c4ae;
  background: #fff;
  color: #3c342c;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  opacity: 0.55;
}
.bom-row:hover .b-cart-btn, .b-cart-btn.in-cart { opacity: 1; }
.b-cart-btn.in-cart { background: #268e58; border-color: #268e58; color: #fff; font-size: 10px; }
.stock-tag { display: inline-block; padding: 0 4px; border-radius: 3px; background: #def4e6; color: #196b3d; font-size: 8.8px; margin-left: 4px; }

/* ---------------- Modals: Platform SN Editor & Spare Requisition Cart ---------------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(28, 24, 20, 0.50);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
  backdrop-filter: blur(2px);
}
.modal-mask.open { display: flex; }
.modal-box {
  background: #fcf9f3;
  border: 1px solid #d5c6b0;
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.26);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 88vh;
}
.modal-hd {
  padding: 11px 16px;
  background: #f3ece0;
  border-bottom: 1px solid #e2d6c3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-hd b { font-size: 13.5px; color: #221e1a; }

.mgr-modal { width: 520px; max-width: 94vw; }
.mgr-body { padding: 15px 18px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.mgr-field { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; }
.mgr-field label { font-weight: 600; color: #463e35; }
.mgr-field input, .mgr-field textarea, .mgr-field select {
  padding: 7px 9px; border-radius: 5px; border: 1px solid #d4c6b0; background: #fff; font-size: 12px; user-select: text;
}
.mgr-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mgr-ft { padding: 10px 18px; background: #f3ece0; border-top: 1px solid #e2d6c3; display: flex; justify-content: flex-end; gap: 8px; }

/* Requisition Cart Modal */
.cart-modal { width: 680px; max-width: 94vw; }
.cart-list {
  flex: 1;
  min-height: 180px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cart-empty {
  padding: 36px 20px;
  text-align: center;
  color: #827565;
  font-size: 12.5px;
}
.cart-item {
  display: grid;
  grid-template-columns: 96px 1fr 112px 28px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #e3d7c3;
  background: #fffdf9;
}
.cart-pn { font-size: 12px; font-weight: 700; color: #d2461b; cursor: pointer; }
.cart-meta div { font-size: 12px; font-weight: 600; color: #221e1a; }
.cart-meta small { font-size: 10px; color: #75695a; }
.cart-stepper {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
.cart-stepper button {
  width: 24px; height: 24px; border-radius: 4px; border: 1px solid #d4c6b0; background: #f6efe4; cursor: pointer; font-weight: 700;
}
.cart-stepper span { min-width: 28px; text-align: center; font-size: 12px; font-weight: 700; }
.cart-del { border: none; background: transparent; color: #9c8e7d; font-size: 14px; cursor: pointer; }
.cart-del:hover { color: #c93b2b; }


/* ============================================================================
   Mobile H5 & Portrait Tablet Responsive Mode (@media max-width: 960px)
   ============================================================================ */
.m-only-btn, .m-sub-bar, .m-ex-drawer, .m-sheet-bar, .m-assy-select { display: none; }

@media (max-width: 960px) {
  #app {
    height: 100vh;
    height: 100dvh;
  }

  /* Compact 1-row Mobile Header (zero overlap on 360px~430px phones) */
  .hdr {
    flex: 0 0 46px;
    height: 46px;
    padding: 0 6px;
    gap: 5px;
  }
  .hdr-brand { padding-right: 4px; border-right: none; gap: 6px; }
  .hdr-logo { width: 30px; height: 30px; border-radius: 7px; }
  .hdr-brand-txt { display: none; }
  .hdr-title, #btn-toggle-left, #btn-toggle-right, #assy-select,
  #hdr-explode-box, #btn-jaw-swap, #btn-xray, #btn-isolate,
  #btn-callouts, #btn-tray, #btn-new-part, .desk-lbl {
    display: none !important;
  }
  .hdr-ctrls { gap: 4px; margin-left: 0; }
  .m-only-btn { display: inline-flex; padding: 0 7px; font-size: 10.5px; }
  #btn-split-bp, #btn-cart-open { padding: 0 7px; font-size: 10.5px; }

  .search-wrap {
    flex: 1 1 auto;
    max-width: none;
    min-width: 96px;
  }
  .search-wrap input {
    height: 30px;
    font-size: 12px;
    padding: 0 54px 0 24px;
  }
  .search-scope-btn { padding: 2px 4px; font-size: 9px; }

  /* Horizontal Swipeable 10-Subsystem Strip */
  .m-sub-bar {
    display: block;
    flex: 0 0 36px;
    height: 36px;
    background: #f6f0e4;
    border-bottom: 1px solid #ddd1bd;
    z-index: 35;
  }
  .m-sub-scroll {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .m-sub-scroll::-webkit-scrollbar { display: none; }
  .m-sub-pill {
    flex: 0 0 auto;
    height: 26px;
    padding: 0 9px;
    border-radius: 13px;
    border: 1px solid #d6c8b2;
    background: #fffdf9;
    color: #3a332b;
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
  }
  .m-sub-pill span { color: #e3562a; font-size: 9.5px; font-weight: 700; }
  .m-sub-pill.active { background: #e3562a; border-color: #e3562a; color: #fff; }
  .m-sub-pill.active span { color: #fff; }

  /* Floating Mobile Explode + X-Ray + Jaw Bar */
  .m-ex-drawer.open {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #fcf8f0;
    border-bottom: 1px solid #dcd0bc;
    z-index: 34;
    font-size: 11px;
  }
  .m-ex-drawer input[type="range"] { flex: 1; accent-color: #e3562a; }

  /* Hide Desktop Left Sidebar & Desktop Edge Handles on H5 */
  .left-sidebar, .edge-handle, .vp-hint, .mini-sn-hud {
    display: none !important;
  }

  .workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
  }

  .center-area {
    flex: 1;
    width: 100%;
    flex-direction: column;
  }

  /* Compact H5 Viewport Overlays */
  .prog-pill {
    left: 8px;
    top: 8px;
    height: 22px;
    padding: 0 8px;
    font-size: 9.2px;
    max-width: 56vw;
  }
  #prog-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .prog-bar { display: none; }

  .vp-quickbar {
    right: 8px;
    top: 8px;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
  }
  .vp-btn {
    height: 28px;
    padding: 0 8px;
    font-size: 10.5px;
  }
  #btn-vp-full3d { display: none; }

  /* Tuck 7-DOF Posture Drawer cleanly at bottom-left of visible 3D pane */
  .dof-drawer {
    left: 8px;
    bottom: 8px;
    width: 224px;
  }
  .peel-banner {
    top: 36px;
    width: max-content;
    max-width: 92vw;
    font-size: 10px;
  }

  /* Vertical Top/Bottom Split for Interactive Blueprint on Mobile H5! */
  .bp-dock {
    width: 100% !important;
    min-width: 0;
    flex: 0 0 56%;
    border-left: none;
    border-top: 2px solid #cbbba3;
    z-index: 42;
  }
  #app.bp-open .right-sidebar { display: none !important; }
  .bp-foot-hint { font-size: 9px; right: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* 3-Snap Flex-Docked Mobile Bottom Sheet (3D viewport automatically centers in remaining upper space!) */
  .right-sidebar {
    position: relative;
    width: 100% !important;
    margin-right: 0 !important;
    border-left: none;
    border-top: 1.5px solid #d4c4ac;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -5px 20px rgba(35, 25, 14, 0.14);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 38;
    transition: height 0.2s cubic-bezier(0.22, 1, 0.36, 1), flex-basis 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .right-sidebar.sheet-peek { flex: 0 0 130px !important; height: 130px; }
  .right-sidebar.sheet-half { flex: 0 0 48dvh !important; height: 48dvh; }
  .right-sidebar.sheet-full { flex: 0 0 76dvh !important; height: 76dvh; }

  .m-sheet-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px 10px 4px;
    background: #f5efe3;
    border-radius: 14px 14px 0 0;
    border-bottom: 1px solid #e6dcc9;
    touch-action: none;
    flex-shrink: 0;
  }
  .m-grab-pill {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: #c5b69e;
    margin-bottom: 5px;
  }
  .m-sheet-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }
  .m-st-btn {
    height: 23px;
    border-radius: 5px;
    border: 1px solid #d8ccb8;
    background: #fffdf9;
    color: #4a4035;
    font-size: 10.5px;
    font-weight: 700;
    cursor: pointer;
  }
  .m-st-btn.active { background: #26221e; border-color: #26221e; color: #fff; }

  /* In Peek state, show compact SN header without overflow */
  .right-sidebar.sheet-peek .sn-card {
    margin: 5px 8px;
    padding: 7px 10px;
  }
  .right-sidebar.sheet-peek .sn-desc-en,
  .right-sidebar.sheet-peek .sn-grid,
  .right-sidebar.sheet-peek .sn-xref-bar,
  .right-sidebar.sheet-peek .sn-platform-bar,
  .right-sidebar.sheet-peek .bom-panel {
    display: none;
  }

  .m-assy-select {
    display: inline-block;
    height: 22px;
    max-width: 145px;
    font-size: 10px;
    border-radius: 4px;
    border: 1px solid #d5c7b0;
    background: #fff;
  }

  /* Touch-friendly Modals on Mobile */
  .mgr-row2 { grid-template-columns: 1fr; }
  .cart-item { grid-template-columns: 82px 1fr 88px 24px; padding: 7px 8px; }
}

/* ============================================================================
   Compact Laptop / Desktop Responsive Header (961px ~ 1620px: MacBook 13"/14"/15")
   Ensures zero right-edge button clipping & zero overlay collision!
   ============================================================================ */
@media (min-width: 961px) and (max-width: 1620px) {
  .hdr { gap: 5px; padding: 0 8px; }
  .hdr-title { display: none; }
  .hdr-brand { padding-right: 7px; gap: 7px; }
  .hdr-brand-txt b { font-size: 15px; }
  .hdr-brand-txt span { font-size: 7.5px; letter-spacing: 1px; }
  .search-wrap { flex: 1 1 170px; min-width: 140px; max-width: 250px; }
  .hdr-select { max-width: 152px; font-size: 10px; }
  .hdr-ctrls { gap: 4px; }
  .chip-btn, .icon-toggle { padding: 0 6.5px; font-size: 10px; gap: 4px; }
  .explode-box { padding: 0 5px 0 3px; gap: 4px; }
  .explode-box input[type="range"] { width: 54px; }
  .left-sidebar { flex: 0 0 236px; width: 236px; }
  .left-sidebar.collapsed { margin-left: -236px; }
  .right-sidebar { flex: 0 0 386px; width: 386px; }
  .right-sidebar.collapsed { margin-right: -386px; }
  .prog-pill { max-width: calc(100% - 355px); overflow: hidden; }
  #prog-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
