:root {
  color-scheme: light;
  --ink: #172027;
  --muted: #5f6b74;
  --line: #d8dee2;
  --panel: #f7f9fa;
  --field: #ffffff;
  --blue: #1f6feb;
  --cyan: #0093a3;
  --green: #0a7d45;
  --red: #c92f2f;
  --amber: #a05a00;
  --steel: #6b7883;
  --die: #48535c;
  --sheet: #e7b65f;
  --shadow: 0 14px 40px rgba(31, 42, 54, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eef2f4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="number"] {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--ink);
}

button {
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
select:hover,
input[type="number"]:hover {
  border-color: #a8b3ba;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(310px, 360px) 1fr;
  min-height: 100vh;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
  max-height: 100vh;
  padding: 22px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand-strip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--cyan);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: 1.72rem;
  letter-spacing: 0;
}

h2 {
  color: #27333b;
  font-size: 0.88rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 74px;
  padding: 7px 11px;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow);
}

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

.status-pill.warn {
  background: var(--amber);
}

.status-pill.hit {
  background: var(--red);
}

.step-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.step-tabs button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.step-tabs button:first-child {
  border-right: 1px solid var(--line);
}

.step-tabs button.active {
  background: #dbeafe;
  color: #174ea6;
}

.panel-page {
  display: none;
}

.panel-page.active {
  display: contents;
}

.control-section,
.results-section,
.reference-section {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  color: var(--ink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 0.85fr;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.segmented button {
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  font-size: 0.82rem;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: #dbeafe;
  color: #174ea6;
  font-weight: 800;
}

.tool-row,
.view-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-view-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.profile-view-control[hidden] {
  display: none;
}

.profile-view-control.disabled {
  opacity: 0.58;
}

.profile-view-control > span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.axis-slider {
  display: grid;
  grid-template-columns: auto 62px auto;
  align-items: center;
  gap: 8px;
  color: #33414b;
  font-size: 0.78rem;
  font-weight: 800;
}

.axis-slider input[type="range"] {
  width: 62px;
  margin: 0;
}

.primary-action {
  min-height: 40px;
  border-color: #174ea6;
  background: var(--blue);
  color: #ffffff;
  font-weight: 800;
}

.add-side-row {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  gap: 10px;
}

.add-side-row button {
  width: 52px;
  height: 52px;
  border-color: var(--blue);
  border-radius: 999px;
  color: var(--blue);
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}

.add-side-row button.active {
  background: var(--blue);
  color: #ffffff;
}

.add-side-row span {
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

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

.stage-grid button {
  min-height: 40px;
  font-weight: 800;
}

.stage-grid button.active {
  border-color: var(--blue);
  background: #dbeafe;
  color: #174ea6;
}

.sim-return-section {
  padding-bottom: 12px;
}

.back-build-btn {
  width: 100%;
  min-height: 42px;
  border-color: #174ea6;
  background: #eaf2ff;
  color: #174ea6;
  font-weight: 900;
}

.machine-align {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.machine-align h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.box-axis-builder {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.box-axis-builder h3 {
  margin: 0;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 900;
  text-transform: uppercase;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.result-grid div {
  min-height: 68px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.result-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.result-grid dd {
  margin: 7px 0 0;
  color: var(--ink);
  font-size: 1.03rem;
  font-weight: 800;
}

.result-grid dd small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.2;
}

.warnings-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.warnings-list li {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 7px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
  box-shadow: 0 8px 18px rgba(23, 32, 39, 0.08);
}

.warnings-list li > span:last-child {
  display: grid;
  gap: 2px;
}

.warnings-list li strong {
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.warning-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 0.72rem;
  font-weight: 900;
}

.warnings-list li.hit {
  border-color: #f0aaa7;
  border-left-color: var(--red);
  color: #7d1d1d;
  background: #fff1f1;
  box-shadow: 0 10px 24px rgba(201, 47, 47, 0.16);
}

.warnings-list li.warn {
  border-color: #edc886;
  border-left-color: var(--amber);
  color: #664000;
  background: #fff7e6;
  box-shadow: 0 10px 24px rgba(160, 90, 0, 0.13);
}

.warnings-list li.ok {
  border-color: #a7d9bd;
  border-left-color: var(--green);
  color: #14532d;
  background: #f0fff5;
}

.warnings-list li.hit .warning-icon {
  background: var(--red);
  color: #ffffff;
}

.warnings-list li.warn .warning-icon {
  background: var(--amber);
  color: #ffffff;
}

.warnings-list li.ok .warning-icon {
  background: var(--green);
  color: #ffffff;
}

.segment-list,
.sequence-list,
.box-axis-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.segment-list li,
.sequence-list li,
.box-axis-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  min-height: 54px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: default;
}

.sequence-list li {
  cursor: pointer;
}

.sequence-list li.active {
  border-color: var(--blue);
  box-shadow: inset 4px 0 0 var(--blue);
}

.sequence-list li.empty,
.box-axis-list li.empty {
  display: block;
  color: var(--muted);
  cursor: default;
}

.segment-list span,
.sequence-list span,
.box-axis-list span {
  font-weight: 800;
}

.segment-list strong,
.sequence-list strong,
.box-axis-list strong {
  color: var(--cyan);
}

.segment-list small,
.sequence-list small,
.box-axis-list small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.sequence-list .sequence-radius {
  grid-column: 1 / -1;
  justify-self: start;
  padding: 3px 8px;
  border: 1px solid #b8dde3;
  border-radius: 999px;
  background: #eefbfc;
  color: #006c78;
  font-size: 0.74rem;
  font-weight: 900;
}

.reference-section figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.reference-section img {
  display: block;
  width: 100%;
  height: auto;
}

.library-open-btn {
  min-height: 38px;
  font-weight: 800;
}

.library-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
}

.library-modal.open {
  display: block;
}

.library-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 39, 0.34);
}

.library-window {
  position: absolute;
  inset: 22px;
  display: grid;
  grid-template-columns: 180px minmax(420px, 1fr) 320px;
  min-height: 620px;
  overflow: hidden;
  border: 1px solid #aeb5bb;
  border-radius: 8px;
  background: #d1d3d9;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
}

.catalog-pane,
.tool-picker-pane,
.inventory-pane {
  min-height: 0;
  padding: 14px;
}

.catalog-pane {
  border-right: 1px solid #aeb5bb;
}

.catalog-pane h2,
.library-header h2,
.inventory-pane h2 {
  margin: 0 0 10px;
  color: #111820;
  font-size: 0.96rem;
  text-transform: none;
}

.catalog-pane select {
  min-height: 30px;
  margin-bottom: 14px;
  background: #eceef1;
}

.catalog-tree {
  display: grid;
  gap: 5px;
}

.catalog-tree strong {
  padding-left: 18px;
  color: #2a3036;
}

.catalog-filter,
.catalog-static {
  min-height: 24px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
}

.catalog-filter:not([data-category="all"]) {
  padding-left: 32px;
}

.catalog-filter.active,
.catalog-static.active {
  background: rgba(255, 255, 255, 0.72);
  font-weight: 800;
}

.catalog-tree span,
.library-note {
  margin: 0;
  color: #3c454d;
  font-size: 0.78rem;
}

.tool-picker-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  border-right: 1px solid #aeb5bb;
}

.library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 10px;
}

.library-header .check-row {
  color: #2f363d;
  font-weight: 500;
}

.tool-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  align-content: start;
  gap: 18px 16px;
  overflow: auto;
  padding: 8px 10px 18px 0;
}

.tool-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 178px;
  padding: 2px 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #303840;
}

.tool-card:hover,
.tool-card.selected {
  border-color: #7d878e;
  background: rgba(255, 255, 255, 0.42);
}

.tool-card svg {
  width: 72px;
  height: 112px;
}

.tool-card strong,
.tool-card small {
  max-width: 96px;
  text-align: center;
}

.tool-card strong {
  font-size: 0.78rem;
}

.tool-card small {
  color: #303840;
  font-size: 0.69rem;
  line-height: 1.15;
}

.tool-card-flags {
  height: 24px;
}

.tool-card-flags span {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 5px;
  background: #ffae6f;
  color: #1f2933;
  font-size: 0.68rem;
  font-weight: 800;
}

.inventory-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
}

.tool-detail {
  min-height: 0;
  overflow: auto;
}

.detail-top {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}

.detail-top svg {
  width: 110px;
  height: 150px;
}

.detail-top strong,
.detail-top span {
  display: block;
}

.detail-top strong {
  margin-bottom: 4px;
}

.detail-top span {
  margin-bottom: 8px;
  color: #303840;
  font-size: 0.82rem;
}

.detail-top dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  margin: 0;
  font-size: 0.76rem;
}

.detail-top dt {
  color: #303840;
}

.detail-top dd {
  margin: 0;
  font-weight: 800;
}

.inventory-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.inventory-list li {
  display: grid;
  grid-template-columns: 38px 98px 1fr;
  align-items: center;
  gap: 6px;
  color: #2d353c;
  font-size: 0.82rem;
}

.inventory-list i {
  display: block;
  height: 16px;
  border: 1px solid #858c92;
  background: #ffffff;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 100vh;
  background: #fdfefe;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.mode-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.mode-copy strong {
  font-size: 1rem;
}

.mode-copy span {
  color: var(--muted);
  font-size: 0.86rem;
}

.viewer-stage {
  position: relative;
  min-height: 580px;
  overflow: hidden;
}

#simCanvas,
#modelCanvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 580px;
  touch-action: none;
}

#simCanvas {
  background:
    linear-gradient(#f5f8fa 1px, transparent 1px),
    linear-gradient(90deg, #f5f8fa 1px, transparent 1px),
    #ffffff;
  background-size: 26px 26px;
}

#modelCanvas {
  display: none;
  background: #f9fbfc;
}

.viewer-stage.three-d #simCanvas {
  display: none;
}

.viewer-stage.three-d #modelCanvas {
  display: block;
}

.viewer-alert {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  width: min(560px, calc(100% - 32px));
  padding: 13px 16px;
  border: 1px solid #ef9a9a;
  border-left: 8px solid var(--red);
  border-radius: 8px;
  background: rgba(255, 245, 245, 0.94);
  color: #7d1d1d;
  font-size: 0.96rem;
  font-weight: 900;
  line-height: 1.3;
  box-shadow: 0 14px 36px rgba(127, 29, 29, 0.22);
  pointer-events: none;
}

.viewer-alert[hidden] {
  display: none;
}

.viewer-alert.hit {
  border-color: #ef9a9a;
  border-left-color: var(--red);
  background: rgba(255, 241, 241, 0.96);
  color: #7d1d1d;
}

.viewer-alert.warn {
  border-color: #edc886;
  border-left-color: var(--amber);
  background: rgba(255, 247, 230, 0.96);
  color: #664000;
  box-shadow: 0 14px 36px rgba(160, 90, 0, 0.18);
}

.machine-align-pad {
  position: absolute;
  right: 16px;
  top: 16px;
  z-index: 4;
  display: grid;
  gap: 8px;
  width: min(430px, calc(100% - 32px));
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 24px rgba(30, 41, 59, 0.12);
}

.machine-align-pad[hidden] {
  display: none;
}

.align-pad-header,
.align-row {
  display: grid;
  align-items: center;
  gap: 6px;
}

.align-pad-header {
  grid-template-columns: 1fr auto;
}

.align-pad-header strong {
  font-size: 0.84rem;
}

.align-pad-header button {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.align-row {
  grid-template-columns: 54px 42px 36px 58px 36px 42px;
}

.align-row span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.align-row button {
  min-height: 30px;
  padding: 4px 0;
  font-size: 0.78rem;
  font-weight: 900;
}

.align-row output {
  min-height: 30px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.viewer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 8px 18px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.viewer-mode-group {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.viewer-mode-group button {
  min-width: 96px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-weight: 800;
}

.viewer-mode-group button + button {
  border-left: 1px solid var(--line);
}

.viewer-mode-group button.active {
  background: #dbeafe;
  color: #174ea6;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .library-window {
    inset: 10px;
    grid-template-columns: 130px 1fr;
  }

  .inventory-pane {
    grid-column: 1 / -1;
    min-height: 260px;
    border-top: 1px solid #aeb5bb;
  }

  .side-panel {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    min-height: 680px;
  }
}

@media (max-width: 540px) {
  .side-panel {
    padding: 16px;
  }

  .library-window {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .catalog-pane,
  .tool-picker-pane,
  .inventory-pane {
    border-right: 0;
  }

  .canvas-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .view-actions {
    width: 100%;
  }

  .view-actions button {
    flex: 1;
  }
}
