:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --panel-2: #eef2f0;
  --ink: #1f2528;
  --muted: #657175;
  --line: #d7ddda;
  --line-strong: #b9c3bf;
  --teal: #0f8a8a;
  --teal-2: #d7f0ed;
  --amber: #bd7b16;
  --amber-2: #fff1d9;
  --red: #b4473f;
  --green: #2f8a4a;
  --steel: #35454b;
  --shadow: 0 16px 40px rgba(35, 44, 47, 0.14);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

body.dark {
  color-scheme: dark;
  --bg: #171b1d;
  --panel: #20272a;
  --panel-2: #252d31;
  --ink: #edf0ee;
  --muted: #a9b5b5;
  --line: #374247;
  --line-strong: #4d5b61;
  --teal: #39b8b4;
  --teal-2: #153a3b;
  --amber: #e0a444;
  --amber-2: #3a2c18;
  --red: #e06b62;
  --green: #63b878;
  --steel: #111719;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 58px 1fr;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--steel), #0f8a8a);
  color: #fff;
  font-weight: 800;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  line-height: 20px;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}

.top-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 112px;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.ok {
  background: var(--green);
}

.status-dot.warning {
  background: var(--amber);
}

.status-dot.error {
  background: var(--red);
}

.command-strip {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-button,
.tool-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.icon-button svg,
.tool-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.language-button {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.icon-button:hover,
.tool-button:hover,
.tool-button.active {
  border-color: var(--teal);
  color: var(--teal);
  background: var(--teal-2);
}

.tool-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  border-color: var(--line);
  color: var(--muted);
  background: var(--panel-2);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 330px minmax(420px, 1fr) 330px;
  gap: 0;
}

.workspace.document-mode {
  grid-template-columns: 330px minmax(420px, 1fr);
}

.workspace.document-mode .right-pane {
  display: none;
}

.left-pane,
.right-pane {
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.right-pane {
  border-right: 0;
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.setup-band,
.inspector-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.section-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.setup-grid div,
.metric,
.quality-item {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.setup-grid span,
.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 15px;
}

.setup-grid b,
.metric b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  line-height: 18px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.segment {
  min-width: 0;
  height: 34px;
  padding: 0 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  font-size: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.segment::after {
  content: attr(data-short-label);
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 32px;
}

.segment.active {
  color: var(--teal);
  background: var(--teal-2);
  border-color: var(--teal);
}

.list-panel {
  min-height: 0;
  display: none;
  flex: 1;
  flex-direction: column;
}

.list-panel.active {
  display: flex;
}

.panel-head {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  border-bottom: 1px solid var(--line);
}

.scroll-list {
  min-height: 0;
  overflow-y: auto;
  padding: 10px;
}

.operation-row,
.tool-row,
.model-row,
.note-row {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 6px;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
}

.operation-row.active,
.tool-row.active,
.model-row-wrap.active .model-row {
  border-color: var(--teal);
  box-shadow: inset 3px 0 0 var(--teal);
  background: var(--teal-2);
}

.tree-root {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 12px;
}

.tree-toggle {
  color: var(--teal);
  font-weight: 900;
}

.model-row-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 6px;
  margin-bottom: 8px;
}

.model-row {
  margin-bottom: 0;
  grid-template-columns: 14px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
}

.model-row-wrap.hidden-body .model-row {
  opacity: 0.48;
}

.model-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(31, 37, 40, 0.28);
}

.model-node-text {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.model-node-text b,
.model-node-text small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-node-text b {
  font-size: 12px;
  color: var(--ink);
}

.model-node-text small {
  font-size: 10px;
  color: var(--muted);
}

.model-eye {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--teal);
  display: grid;
  place-items: center;
  gap: 1px;
  font-weight: 900;
  cursor: pointer;
}

.model-eye-dot {
  font-size: 14px;
  line-height: 14px;
}

.model-eye-label {
  max-width: 66px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  line-height: 12px;
}

.model-row-wrap.hidden-body .model-eye {
  color: var(--muted);
  background: var(--panel-2);
}

.model-eye:hover {
  border-color: var(--teal);
  background: var(--teal-2);
}

.empty-node {
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.op-line,
.tool-line {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.op-title,
.tool-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.op-meta,
.tool-meta,
.note-row {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  min-width: 42px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.badge.ok {
  background: rgba(47, 138, 74, 0.14);
  color: var(--green);
}

.badge.warning {
  background: var(--amber-2);
  color: var(--amber);
}

.badge.error {
  background: rgba(180, 71, 63, 0.14);
  color: var(--red);
}

.stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 70px;
  background: #fff;
  overflow: hidden;
}

.workspace.document-mode .stage {
  background: var(--panel);
}

.workspace.document-mode .viewport-frame {
  display: none;
}

.document-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.document-stage[hidden] {
  display: none;
}

.document-stage-header {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.document-stage-header span,
.document-stage-header small {
  display: block;
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.document-stage-header span {
  font-size: 11px;
  line-height: 14px;
  font-weight: 850;
  text-transform: uppercase;
}

.document-stage-header b {
  display: block;
  min-width: 0;
  margin-top: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 17px;
  line-height: 22px;
}

.document-stage-header small {
  margin-top: 1px;
  font-size: 12px;
  line-height: 16px;
}

.document-stage-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.document-stage-frame[hidden] {
  display: none;
}

.pdf-pages {
  min-width: 0;
  min-height: 0;
  padding: 12px;
  overflow: auto;
  background: #e7ece9;
  -webkit-overflow-scrolling: touch;
}

.pdf-pages[hidden] {
  display: none;
}

.pdf-page-shell {
  width: 100%;
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 6px;
}

.pdf-page-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(35, 44, 47, 0.12);
}

.pdf-page-shell figcaption,
.pdf-status {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.pdf-status {
  min-height: 240px;
  display: grid;
  place-items: center;
}

body.dark .stage {
  background: #fff;
}

.viewport-frame {
  min-width: 0;
  min-height: 0;
  position: relative;
  background: #fff;
  overflow: hidden;
}

.viewport {
  position: absolute;
  inset: 0;
}

.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viewport-fallback {
  height: 100%;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.viewport-fallback b {
  color: var(--ink);
  font-size: 18px;
}

.viewport-fallback span {
  max-width: 520px;
  line-height: 1.5;
}

.scene-toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  z-index: 4;
}

.scene-readout {
  position: absolute;
  left: 12px;
  bottom: 12px;
  min-width: 240px;
  max-width: min(520px, calc(100% - 24px));
  padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  color: #fff;
  background: rgba(30, 38, 40, 0.74);
  box-shadow: var(--shadow);
}

.scene-readout span {
  display: block;
  color: #bed8d5;
  font-size: 12px;
  font-weight: 800;
}

.scene-readout b {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.view-cube {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  width: 114px;
  height: 114px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.view-cube-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.scene-panel {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  width: min(360px, calc(100% - 24px));
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: rgba(30, 38, 40, 0.82);
  color: #fff;
  box-shadow: var(--shadow);
}

.scene-panel[hidden] {
  display: none;
}

.scene-panel-title {
  font-size: 12px;
  font-weight: 850;
  color: #bed8d5;
  text-transform: uppercase;
}

.toolpath-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.toolpath-panel-head .scene-panel-title {
  flex: 0 0 auto;
}

.toolpath-active-tool {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  line-height: 15px;
  white-space: nowrap;
  overflow: visible;
}

.toolpath-active-tool-inline {
  display: none;
}

.toolpath-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: #dfeceb;
  font-size: 11px;
  font-weight: 850;
}

.toolpath-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
}

.toolpath-legend .toolpath-active-tool-inline {
  display: none;
}

.toolpath-legend i {
  width: 18px;
  height: 0;
  border-top: 3px solid currentColor;
}

.toolpath-legend .legend-g0 {
  color: #0057d9;
  border-top-style: dashed;
}

.toolpath-legend .legend-g1 {
  color: #009b57;
}

.toolpath-legend b,
.toolpath-legend em {
  font-style: normal;
}

.toolpath-legend em {
  color: #bed8d5;
  font-size: 10px;
}

.compact-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-button {
  height: 32px;
  min-width: 44px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.11);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.mini-button.active,
.mini-button:hover {
  border-color: rgba(20, 184, 166, 0.95);
  background: rgba(20, 184, 166, 0.24);
}

.range-row {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) 72px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 800;
}

.range-row input {
  width: 100%;
  accent-color: var(--teal);
  min-height: 28px;
  touch-action: none;
}

.range-row b,
.measure-readout,
.measure-dimensions {
  font-size: 12px;
  color: #e9f3f1;
}

.measure-readout {
  min-height: 18px;
  font-weight: 850;
}

.measure-dimensions {
  color: #bed8d5;
  line-height: 1.35;
}

.timeline {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  padding: 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 34px 34px minmax(0, 1fr) 34px 34px;
  align-items: center;
  gap: 6px;
}

.timeline-track {
  height: 42px;
  display: grid;
  gap: 4px;
  grid-auto-flow: column;
  grid-auto-columns: clamp(42px, 5vw, 62px);
  justify-content: start;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.timeline-track::-webkit-scrollbar {
  display: none;
}

.timeline-nav {
  width: 34px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--panel-2);
  cursor: pointer;
  touch-action: manipulation;
}

.timeline-nav svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.timeline-nav:hover:not(:disabled),
.timeline-nav:focus-visible {
  border-color: var(--teal);
  color: var(--teal);
  outline: none;
}

.timeline-operation-nav {
  background: rgba(20, 184, 166, 0.11);
}

.timeline-nav:disabled {
  cursor: default;
  opacity: 0.34;
}

.timeline-item {
  min-width: 0;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  cursor: pointer;
  position: relative;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  scroll-snap-align: start;
}

.timeline-item.ok {
  background: rgba(47, 138, 74, 0.18);
}

.timeline-item.warning {
  background: var(--amber-2);
}

.timeline-item.hidden-body {
  color: var(--muted);
  background: repeating-linear-gradient(
    135deg,
    var(--panel-2),
    var(--panel-2) 5px,
    rgba(101, 113, 117, 0.16) 5px,
    rgba(101, 113, 117, 0.16) 10px
  );
  opacity: 0.7;
}

.timeline-item.tool-timeline-item {
  font-size: 10px;
}

.timeline-item.active {
  color: var(--teal);
  border-color: var(--teal);
  box-shadow: inset 0 -4px 0 var(--teal);
}

.summary-block {
  display: grid;
  gap: 8px;
}

.summary-title {
  font-size: 20px;
  font-weight: 850;
  line-height: 26px;
}

.summary-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.machine-status {
  display: grid;
  gap: 10px;
  padding: 11px;
  border: 1px solid rgba(26, 42, 45, 0.28);
  border-radius: 8px;
  color: #ecf7f4;
  background: #172226;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.machine-status-compact {
  display: none;
  gap: 7px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #ecf7f4;
  background: rgba(12, 22, 25, 0.76);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.compact-machine-head {
  display: grid;
  grid-template-columns: 46px repeat(3, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
}

.compact-machine-head > b,
.compact-axis,
.compact-machine-command-row span {
  min-width: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
}

.compact-machine-head > b {
  display: grid;
  place-items: center;
  color: #061414;
  background: #79f1d3;
  font-size: 16px;
  font-weight: 950;
}

.compact-axis {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  padding: 5px;
}

.compact-axis em {
  display: grid;
  place-items: center;
  height: 22px;
  border-radius: 5px;
  color: #fff;
  font-style: normal;
  font-size: 11px;
  font-weight: 950;
}

.compact-axis.x em { background: #db3d35; }
.compact-axis.y em { background: #238c4b; }
.compact-axis.z em { background: #246bdb; }

.compact-axis strong {
  overflow: hidden;
  color: #dffdf6;
  font-size: 13px;
  font-weight: 950;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.compact-machine-command-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.compact-machine-command-row span {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 7px;
  color: #a7bbb7;
  font-size: 11px;
  font-weight: 900;
}

.compact-machine-command-row b {
  min-width: 0;
  overflow: hidden;
  color: #fff;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.machine-readout-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #9fb7b2;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.machine-readout-head b {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-width: 54px;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 6px;
  color: #061414;
  background: #79f1d3;
  font-size: 16px;
  letter-spacing: 0;
}

.machine-readout-head em {
  font-style: normal;
  font-size: 12px;
}

.axis-readout {
  display: grid;
  gap: 6px;
}

.axis-cell {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.axis-cell span {
  display: grid;
  place-items: center;
  height: 26px;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 950;
}

.axis-cell.x span { background: #db3d35; }
.axis-cell.y span { background: #238c4b; }
.axis-cell.z span { background: #246bdb; }

.axis-cell b {
  min-width: 0;
  padding: 6px 8px;
  border-radius: 6px;
  color: #dffdf6;
  background: rgba(255, 255, 255, 0.08);
  font-size: 18px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.machine-command-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.machine-command {
  min-width: 0;
  padding: 7px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
}

.machine-command:last-child {
  grid-column: 1 / -1;
}

.machine-command span {
  display: block;
  color: #a7bbb7;
  font-size: 10px;
  font-weight: 800;
}

.machine-command b {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-card {
  display: grid;
  gap: 10px;
}

.right-pane.tool-inspector-mode .tool-section {
  padding-top: 10px;
}

.tool-inspector-card {
  gap: 0;
}

.image-stack {
  display: grid;
  gap: 10px;
}

.viewer-image-card {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
}

.viewer-image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #f4f5f2;
}

body.dark .viewer-image-card img {
  background: #171b1d;
}

.viewer-image-card figcaption {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  border-top: 1px solid var(--line);
}

.setup-preview-card img {
  aspect-ratio: 16 / 7;
}

.tool-visual {
  height: 92px;
  display: grid;
  place-items: center;
  position: relative;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: linear-gradient(90deg, var(--panel-2), rgba(15, 138, 138, 0.12));
  overflow: hidden;
  contain: paint;
}

.tool-visual svg {
  width: 230px;
  height: 72px;
}

.tool-visual.real-tool-image {
  height: clamp(260px, 32vh, 420px);
  padding: 10px;
  background: #fbfcfa;
}

.tool-inspector-card .tool-hero {
  height: clamp(260px, 38vh, 430px);
}

.tool-inspector-card .tool-hero.real-tool-image {
  height: clamp(380px, 58vh, 720px);
  max-height: calc(100vh - 176px);
  padding: 10px;
  overflow: hidden;
}

body.dark .tool-visual.real-tool-image {
  background: #f4f5f2;
}

.tool-card-image {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

.tool-card-image-frame {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.document-row {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 12px;
  text-align: left;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.document-row.active {
  border-color: var(--teal);
  background: var(--teal-2);
  box-shadow: inset 4px 0 0 var(--teal);
}

.document-row b,
.document-row span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.document-row b {
  font-size: 13px;
  line-height: 18px;
}

.document-row span {
  color: var(--muted);
  font-size: 12px;
}

.document-viewer-card {
  gap: 10px;
}

.pdf-frame {
  width: 100%;
  min-height: min(72vh, 760px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.pdf-open-link {
  display: inline-grid;
  place-items: center;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  color: #fff;
  background: var(--teal);
  font-weight: 850;
  text-decoration: none;
}

.document-empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-2);
}

.tool-data {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quality-list {
  display: grid;
  gap: 8px;
}

.tool-operation-list {
  gap: 8px;
}

.tool-operation-item {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
}

.tool-operation-item.active {
  border-color: var(--teal);
  background: var(--teal-2);
  box-shadow: inset 3px 0 0 var(--teal);
}

.tool-operation-item b,
.tool-operation-item span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tool-operation-item b {
  font-size: 13px;
  line-height: 18px;
}

.tool-operation-item span {
  color: var(--muted);
  font-size: 12px;
}

.quality-item {
  display: grid;
  grid-template-columns: 12px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.quality-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
}

.quality-dot.warning {
  background: var(--amber);
}

.quality-dot.error {
  background: var(--red);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(120%);
  min-width: 220px;
  max-width: min(480px, calc(100vw - 28px));
  padding: 11px 14px;
  border-radius: 8px;
  background: var(--steel);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 20;
  text-align: center;
  font-weight: 700;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.package-loading {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(246, 248, 246, 0.58);
  backdrop-filter: blur(7px);
}

.package-loading[hidden] {
  display: none;
}

.package-loading-card {
  width: min(380px, calc(100vw - 36px));
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.package-loading-title {
  font-size: 16px;
  font-weight: 900;
}

.package-loading-detail {
  min-height: 18px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.package-loading-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(12, 139, 139, 0.16);
}

.package-loading-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 160ms ease;
}

.package-loading-percent {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: right;
}

.dark .package-loading {
  background: rgba(12, 18, 20, 0.62);
}

.dark .package-loading-card {
  background: rgba(30, 39, 42, 0.95);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 300px minmax(360px, 1fr);
  }

  .workspace.document-mode {
    grid-template-columns: 300px minmax(360px, 1fr);
  }

  .right-pane {
    display: none;
  }
}

@media (max-width: 820px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: auto;
    grid-template-rows: auto 1fr;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .top-status {
    display: none;
  }

  .brand-subtitle {
    max-width: 54vw;
  }

  .workspace {
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .workspace.document-mode {
    display: flex;
  }

  .stage {
    order: 1;
    min-height: 540px;
    grid-template-rows: 470px 70px;
  }

  .left-pane {
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--line);
    min-height: 560px;
  }

  .right-pane {
    order: 3;
    display: flex;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .right-pane .machine-section {
    display: none;
  }

  .machine-status-compact {
    display: grid;
  }

  .metric-grid,
  .tool-data {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace.document-mode .right-pane {
    display: none;
  }

  .right-pane.tool-inspector-mode .tool-section {
    order: -1;
  }

  .right-pane.tool-inspector-mode .detail-section,
  .right-pane.tool-inspector-mode #detailSection {
    order: 0;
  }

  .right-pane.tool-inspector-mode .quality-section,
  .right-pane.tool-inspector-mode #qualitySection {
    order: 1;
  }

  .workspace.document-mode .document-stage {
    min-height: 540px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 8px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .brand-title {
    font-size: 15px;
  }

  .command-strip {
    gap: 4px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .segmented-control {
    gap: 5px;
    padding: 10px;
  }

  .segment {
    height: 32px;
    padding: 0 4px;
  }

  .segment::after {
    line-height: 32px;
  }

  .stage {
    min-height: 0;
    grid-template-rows: auto 74px;
  }

  .workspace.document-mode .stage {
    grid-template-rows: minmax(520px, 76vh) 74px;
  }

  .document-stage-header {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 8px 10px;
  }

  .document-stage-frame {
    width: calc(100% - 14px);
    height: calc(100% - 8px);
    margin: 0 7px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .viewport-frame {
    display: grid;
    grid-template-rows: clamp(455px, 64vh, 560px) auto;
    overflow: visible;
  }

  .viewport {
    position: relative;
    inset: auto;
    min-height: 0;
    height: 100%;
  }

  .scene-readout {
    display: none;
  }

  .scene-panel.toolpath-panel {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    width: auto;
    margin: 0 8px 8px;
    gap: 6px;
    padding: 8px;
    background: rgba(30, 38, 40, 0.72);
    backdrop-filter: blur(8px);
  }

  .machine-status-compact {
    gap: 5px;
    padding: 7px;
  }

  .toolpath-legend {
    gap: 5px;
    flex-wrap: nowrap;
    font-size: 10px;
  }

  .toolpath-legend span {
    min-height: 20px;
    padding: 2px 6px;
  }

  .toolpath-panel-head {
    display: none;
  }

  .toolpath-legend .toolpath-active-tool-inline {
    display: inline-flex;
    flex: 1 1 auto;
    min-width: 92px;
    max-width: none;
    justify-content: center;
    padding: 2px 6px;
    color: #fff;
  }

  .compact-machine-head {
    grid-template-columns: 42px repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .compact-axis {
    grid-template-columns: 20px minmax(0, 1fr);
    padding: 4px;
  }

  .compact-axis strong {
    font-size: 12px;
  }

  .compact-machine-command-row {
    gap: 5px;
  }

  .compact-machine-command-row span {
    padding: 5px 6px;
    font-size: 10px;
  }

  .scene-panel.toolpath-panel[hidden] {
    display: none;
  }

  .toolpath-panel .scene-panel-title,
  .toolpath-panel .toolpath-panel-head,
  .toolpath-panel .playback-readout {
    display: none;
  }

  .toolpath-panel .compact-row {
    display: grid;
    grid-template-columns: minmax(54px, 1fr) minmax(54px, 1fr) minmax(42px, 0.72fr) minmax(42px, 0.72fr);
    gap: 6px;
  }

  .toolpath-panel .mini-button {
    height: 30px;
    min-width: 0;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 12px;
  }

  .toolpath-panel .playback-position-row {
    grid-template-columns: 54px minmax(0, 1fr) 86px;
    gap: 6px;
    font-size: 11px;
  }

  .toolpath-panel .playback-speed-row {
    grid-template-columns: 54px minmax(0, 1fr) 72px;
    gap: 6px;
    font-size: 11px;
  }

  .toolpath-panel .playback-speed-row b {
    font-size: 11px;
    line-height: 13px;
  }

  .toolpath-panel .playback-position-row b {
    font-size: 11px;
    line-height: 13px;
  }

  .timeline {
    padding: 10px 14px 12px;
    grid-template-columns: 32px 32px minmax(0, 1fr) 32px 32px;
    gap: 5px;
  }

  .timeline-track {
    height: 52px;
    grid-auto-columns: 58px;
  }

  .timeline-nav {
    width: 32px;
    height: 52px;
  }

  .setup-grid,
  .metric-grid,
  .tool-data {
    grid-template-columns: 1fr;
  }

  .tool-visual.real-tool-image {
    height: min(44vh, 330px);
    min-height: 240px;
    padding: 8px;
  }

  .tool-inspector-card .tool-hero.real-tool-image {
    height: min(46vh, 360px);
    min-height: 0;
    padding: 6px;
    overflow: hidden;
  }

  .pdf-frame {
    min-height: 68vh;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: auto;
    grid-template-rows: auto 1fr;
  }

  .topbar {
    grid-template-columns: minmax(220px, 1fr) auto;
    padding: 6px 10px;
  }

  .top-status {
    display: none;
  }

  .workspace {
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .right-pane .machine-section {
    display: none;
  }

  .stage {
    order: 1;
    min-height: 0;
    grid-template-rows: auto 54px;
  }

  .workspace.document-mode .stage {
    grid-template-rows: minmax(260px, calc(100vh - 104px)) 54px;
  }

  .document-stage-header {
    padding: 7px 10px;
  }

  .document-stage-frame {
    width: calc(100% - 14px);
    height: calc(100% - 8px);
    margin: 0 7px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .viewport-frame {
    display: grid;
    grid-template-rows: minmax(180px, calc(100vh - 180px)) auto;
    overflow: visible;
  }

  .viewport {
    position: relative;
    inset: auto;
    min-height: 180px;
    height: 100%;
  }

  .scene-toolbar {
    top: 8px;
    left: 10px;
  }

  .scene-toolbar .tool-button {
    width: 34px;
    height: 34px;
  }

  .scene-readout {
    display: none;
  }

  .machine-status-compact {
    display: grid;
  }

  .toolpath-legend {
    display: none;
  }

  .scene-panel.toolpath-panel {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    width: auto;
    margin: 0 10px 8px;
    padding: 6px;
    display: grid;
    grid-template-columns: minmax(190px, 1fr) minmax(212px, 0.85fr) minmax(180px, 1fr) minmax(145px, 0.75fr);
    align-items: center;
    gap: 8px;
    background: rgba(30, 38, 40, 0.74);
    backdrop-filter: blur(8px);
  }

  .compact-machine-head {
    grid-template-columns: 42px repeat(3, minmax(0, 1fr));
  }

  .compact-machine-command-row span {
    padding: 5px 6px;
    font-size: 10px;
  }

  .scene-panel.toolpath-panel[hidden] {
    display: none;
  }

  .toolpath-panel .scene-panel-title,
  .toolpath-panel .toolpath-panel-head,
  .toolpath-panel .playback-readout {
    display: none;
  }

  .toolpath-panel .compact-row {
    display: grid;
    grid-template-columns: minmax(64px, 1fr) minmax(54px, 0.85fr) 46px 46px;
    gap: 6px;
  }

  .toolpath-panel .mini-button {
    height: 30px;
    min-width: 0;
    padding: 0 8px;
    font-size: 12px;
  }

  .toolpath-panel .playback-position-row {
    grid-template-columns: 60px minmax(0, 1fr) 92px;
    gap: 6px;
    font-size: 11px;
  }

  .toolpath-panel .playback-speed-row {
    grid-template-columns: 34px minmax(0, 1fr) 70px;
    gap: 6px;
    font-size: 11px;
  }

  .toolpath-panel .playback-position-row b,
  .toolpath-panel .playback-speed-row b {
    font-size: 11px;
    line-height: 13px;
  }

  .tool-inspector-card .tool-hero.real-tool-image {
    height: clamp(280px, 66vh, 460px);
    min-height: 0;
    padding: 8px;
    overflow: hidden;
  }

  .pdf-frame {
    min-height: 78vh;
  }

  .timeline {
    padding: 8px 12px;
    grid-template-columns: 30px 30px minmax(0, 1fr) 30px 30px;
    gap: 4px;
  }

  .timeline-track {
    height: 38px;
    grid-auto-columns: 44px;
  }

  .timeline-nav {
    width: 30px;
    height: 38px;
  }

  .timeline-nav svg {
    width: 16px;
    height: 16px;
  }

  .left-pane {
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--line);
    min-height: 420px;
  }

  .right-pane {
    order: 3;
    display: none;
  }
}
