.lathe-cam-page {
  --cam-preview-bg: #10141c;
  --cam-grid: rgba(139, 149, 168, 0.13);
  --cam-grid-strong: rgba(139, 149, 168, 0.25);
  --cam-stock: rgba(91, 141, 239, 0.13);
  --cam-stock-edge: rgba(91, 141, 239, 0.55);
  --cam-rough: #f0ad55;
  --cam-rapid: #7f8ba0;
  --cam-finish: #a0c814;
  --cam-tool: #f3f5f7;
  display: grid;
  min-width: 0;
  gap: 14px;
}

/* Site-owner bulk tool management. */
.lathe-cam-tool-library-sidebar {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.lathe-cam-tool-library-sidebar-heading {
  flex-wrap: wrap;
}

.lathe-cam-tool-library-sidebar-heading > span {
  flex: 1 1 100%;
}

.lathe-cam-tool-library-sidebar-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.lathe-cam-tool-library-sidebar-actions .button {
  min-width: 0;
  justify-content: center;
}

.lathe-cam-tool-bulk-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-raised) 82%, transparent);
}

.lathe-cam-tool-bulk-toolbar[hidden],
.lathe-cam-tool-library-sidebar-actions .button[hidden] {
  display: none !important;
}

.lathe-cam-tool-bulk-toolbar .button {
  min-width: 0;
  min-height: 34px;
  padding-inline: 8px;
  justify-content: center;
}

#latheCamToolBulkDeleteButton {
  grid-column: 1 / -1;
}

.lathe-cam-tool-library-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  gap: 0;
}

.lathe-cam-tool-library-row .lathe-cam-tool-library-item {
  grid-column: 1;
  width: 100%;
}

.lathe-cam-tool-library-selector {
  min-width: 0;
  min-height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.lathe-cam-tool-library-list.is-bulk-mode .lathe-cam-tool-library-row {
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 6px;
}

.lathe-cam-tool-library-list.is-bulk-mode .lathe-cam-tool-library-selector {
  grid-column: 1;
  display: flex;
}

.lathe-cam-tool-library-list.is-bulk-mode .lathe-cam-tool-library-item {
  grid-column: 2;
}

.lathe-cam-tool-library-selector input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.lathe-cam-tool-library-selector span {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
}

.lathe-cam-tool-library-selector input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
}

.lathe-cam-tool-library-selector input:checked + span::after {
  width: 8px;
  height: 4px;
  content: "";
  border-left: 2px solid var(--surface);
  border-bottom: 2px solid var(--surface);
  transform: translateY(-1px) rotate(-45deg);
}

.lathe-cam-tool-library-selector input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lathe-cam-tool-library-row.is-selected .lathe-cam-tool-library-item {
  border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.lathe-cam-page[hidden] {
  display: none;
}

.lathe-cam-toolbar {
  min-width: 0;
}

.lathe-cam-notice {
  min-height: 42px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 13px;
  border: 1px solid rgba(245, 158, 11, 0.28);
  border-radius: 7px;
  color: #f4c06f;
  background: rgba(245, 158, 11, 0.08);
  font-size: 12px;
  line-height: 1.6;
}

.lathe-cam-notice[hidden] {
  display: none;
}

.lathe-cam-notice.is-error {
  border-color: rgba(239, 68, 68, 0.30);
  color: #ff9298;
  background: rgba(239, 68, 68, 0.08);
}

.lathe-cam-notice.is-success {
  border-color: rgba(16, 185, 129, 0.28);
  color: #77d8ab;
  background: rgba(16, 185, 129, 0.08);
}

.lathe-cam-notice svg,
.lathe-cam-safety svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  margin-top: 1px;
}

.lathe-cam-workspace {
  min-width: 0;
  min-height: 590px;
  height: calc(100vh - 255px);
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(490px, 1fr) minmax(310px, 370px);
  gap: 12px;
}

.lathe-cam-settings,
.lathe-cam-preview,
.lathe-cam-output {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: 8px;
}

.lathe-cam-settings,
.lathe-cam-output {
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.lathe-cam-pane-heading {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.lathe-cam-pane-heading > div:first-child {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.lathe-cam-pane-heading strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-pane-heading small {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-state {
  min-height: 25px;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border: 1px solid rgba(16, 185, 129, 0.24);
  border-radius: 6px;
  color: #77d8ab;
  background: rgba(16, 185, 129, 0.07);
  font-size: 10px;
}

.lathe-cam-state i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.lathe-cam-state b {
  font-weight: 750;
}

.lathe-cam-state.is-invalid {
  border-color: rgba(239, 68, 68, 0.26);
  color: #ff8d94;
  background: rgba(239, 68, 68, 0.08);
}

.lathe-cam-settings-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 2px 5px 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.lathe-cam-dxf-guide {
  padding: 2px 0 12px;
  border-bottom: 1px solid var(--line);
}

.lathe-cam-dxf-guide summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px;
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
  list-style: none;
}

.lathe-cam-dxf-guide summary::-webkit-details-marker {
  display: none;
}

.lathe-cam-dxf-guide summary svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: var(--accent);
}

.lathe-cam-dxf-guide summary::after {
  margin-left: auto;
  color: var(--muted);
  content: ">";
  font: 700 14px/1 Consolas, "Cascadia Mono", monospace;
  transform: rotate(90deg);
  transition: transform 140ms ease;
}

.lathe-cam-dxf-guide[open] summary::after {
  transform: rotate(-90deg);
}

.lathe-cam-dxf-guide ul {
  display: grid;
  gap: 5px;
  margin: 2px 0 0;
  padding: 0 8px 2px 27px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.lathe-cam-dxf-guide li::marker {
  color: var(--accent);
}

.lathe-cam-fieldset {
  min-width: 0;
  margin: 0;
  padding: 15px 0 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.lathe-cam-fieldset:last-child {
  border-bottom: 0;
}

.lathe-cam-fieldset legend {
  width: 100%;
  margin: 0 0 10px;
  padding: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.3;
}

.lathe-cam-scope-heading {
  position: sticky;
  top: -2px;
  z-index: 5;
  min-width: 0;
  min-height: 49px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 -2px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
}

.lathe-cam-scope-heading.is-operation {
  margin-top: 2px;
}

.lathe-cam-scope-icon {
  width: 28px;
  height: 28px;
  display: grid;
  flex: 0 0 28px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: 6px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-soft));
}

.lathe-cam-scope-icon svg {
  width: 14px;
  height: 14px;
}

.lathe-cam-scope-heading > span:last-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.lathe-cam-scope-heading strong {
  color: var(--ink);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.lathe-cam-scope-heading small {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.3;
}

.lathe-cam-operation-context {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: 43px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 13px 0 0;
  padding: 10px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 31%, var(--line));
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 7%, var(--surface-soft));
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--ink) 5%, transparent);
}

.lathe-cam-operation-context::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: var(--accent);
  content: "";
}

.lathe-cam-operation-context[data-tool-type="external-groove"],
.lathe-cam-operation-context[data-tool-type="internal-groove"] {
  border-color: color-mix(in srgb, #d9903d 35%, var(--line));
  background: color-mix(in srgb, #d9903d 7%, var(--surface-soft));
}

.lathe-cam-operation-context[data-tool-type="external-groove"]::before,
.lathe-cam-operation-context[data-tool-type="internal-groove"]::before {
  background: #d9903d;
}

.lathe-cam-operation-context-index {
  width: 43px;
  height: 43px;
  display: grid;
  place-content: center;
  gap: 1px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  background: var(--input-bg);
  text-align: center;
}

.lathe-cam-operation-context-index small {
  font-size: 8px;
  font-weight: 750;
  line-height: 1;
}

.lathe-cam-operation-context-index b {
  color: var(--ink);
  font: 800 15px/1.15 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-operation-context-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.lathe-cam-operation-context-copy > small {
  color: var(--accent);
  font-size: 9px;
  font-weight: 750;
  line-height: 1.2;
}

.lathe-cam-operation-context-copy > strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-operation-context-copy > span {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-operation-scope {
  align-self: start;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: color-mix(in srgb, var(--input-bg) 75%, transparent);
  font-size: 8px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.lathe-cam-operation-codes {
  grid-column: 2 / -1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.lathe-cam-operation-codes small {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 8px;
  font-weight: 750;
}

.lathe-cam-operation-codes b {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font: 700 9px/1.35 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-operation-target-fieldset {
  padding-top: 13px;
}

.lathe-cam-process-groups {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.lathe-cam-process-group {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--surface-soft) 74%, transparent);
}

.lathe-cam-process-group-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.lathe-cam-process-group-heading > svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  color: var(--accent);
}

.lathe-cam-process-group.is-roughing .lathe-cam-process-group-heading > svg {
  color: var(--cam-rough);
}

.lathe-cam-process-group.is-finishing .lathe-cam-process-group-heading > svg {
  color: var(--cam-finish);
}

.lathe-cam-process-group-heading > span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.lathe-cam-process-group-heading strong {
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.25;
}

.lathe-cam-process-group-heading small {
  color: var(--muted);
  font-size: 8px;
  line-height: 1.35;
}

.lathe-cam-field[hidden] {
  display: none;
}

.lathe-cam-operation-fieldset {
  position: relative;
}

.lathe-cam-operation-fieldset > legend {
  width: 100%;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lathe-cam-operation-add {
  position: static;
  flex: 0 0 28px;
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  height: 28px;
  padding: 0;
}

.lathe-cam-operation-list {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.lathe-cam-range-panel {
  min-width: 0;
  display: grid;
  gap: 7px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.lathe-cam-range-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.3;
}

.lathe-cam-range-mode {
  width: 100%;
}

.lathe-cam-range-controls {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(104px, 0.72fr);
  align-items: end;
  gap: 7px;
}

.lathe-cam-range-controls[hidden] {
  display: none;
}

.lathe-cam-range-actions {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

#appView .lathe-cam-page .lathe-cam-range-actions .button {
  min-width: 0;
  min-height: 34px;
  padding-inline: 7px;
}

.lathe-cam-range-overlap {
  min-width: 0;
}

.lathe-cam-range-status {
  min-width: 0;
  min-height: 27px;
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-soft) 72%, transparent);
  font: 9px/1.45 Consolas, "Cascadia Mono", monospace;
  overflow-wrap: anywhere;
}

.lathe-cam-operation-item {
  position: relative;
  min-width: 0;
  min-height: 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface-soft) 82%, transparent);
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.lathe-cam-operation-item::before {
  position: absolute;
  inset: 7px auto 7px 0;
  width: 2px;
  border-radius: 0 2px 2px 0;
  background: transparent;
  content: "";
}

.lathe-cam-operation-item.is-active {
  border-color: color-mix(in srgb, var(--accent) 46%, var(--line));
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-soft));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 5%, transparent);
}

.lathe-cam-operation-item.is-active::before {
  background: var(--accent);
}

.lathe-cam-operation-item.is-invalid {
  border-color: rgba(239, 68, 68, 0.38);
  background: rgba(239, 68, 68, 0.06);
}

.lathe-cam-operation-item.is-invalid::before {
  background: #ef4444;
}

.lathe-cam-operation-main {
  min-width: 0;
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.lathe-cam-operation-item.is-disabled .lathe-cam-operation-main {
  opacity: 0.54;
}

.lathe-cam-operation-index {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--muted);
  background: var(--input-bg);
  font: 700 9px/1 Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.lathe-cam-operation-item.is-active .lathe-cam-operation-index {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, var(--input-bg));
}

.lathe-cam-operation-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.lathe-cam-operation-name,
.lathe-cam-operation-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-operation-name {
  color: var(--ink);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.3;
}

.lathe-cam-operation-detail {
  color: var(--muted);
  font: 9px/1.3 Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.lathe-cam-operation-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 2px;
}

.lathe-cam-operation-enable,
.lathe-cam-operation-move,
.lathe-cam-operation-delete {
  width: 26px;
  min-width: 26px;
  min-height: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
}

.lathe-cam-operation-enable {
  position: relative;
  cursor: pointer;
}

.lathe-cam-operation-enable input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.lathe-cam-operation-enable i {
  width: 12px;
  height: 12px;
  display: block;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--input-bg);
}

.lathe-cam-operation-enable input:checked + i {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 2px var(--input-bg);
}

.lathe-cam-operation-enable:focus-within {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.lathe-cam-operation-enable:hover,
.lathe-cam-operation-move:hover {
  border-color: var(--line);
  color: var(--ink);
  background: var(--input-bg);
}

.lathe-cam-operation-enable.is-active,
.lathe-cam-operation-enable[aria-pressed="true"] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.lathe-cam-operation-delete:hover {
  border-color: rgba(239, 68, 68, 0.28);
  color: #ff8d94;
  background: rgba(239, 68, 68, 0.08);
}

.lathe-cam-operation-actions svg {
  width: 13px;
  height: 13px;
}

.lathe-cam-origin-calibration {
  min-width: 0;
  display: grid;
  gap: 6px;
  margin-top: 2px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface-soft) 82%, transparent);
}

.lathe-cam-origin-actions {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.lathe-cam-origin-actions .button {
  min-width: 0;
  min-height: 30px;
  height: 30px;
  flex: 1 1 78px;
  gap: 5px;
  padding: 0 7px;
  font-size: 9px;
  line-height: 1.2;
  white-space: normal;
}

.lathe-cam-origin-actions .button svg {
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
}

.lathe-cam-origin-status {
  min-width: 0;
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  overflow-wrap: anywhere;
  border-radius: 5px;
  color: var(--muted);
  background: color-mix(in srgb, var(--input-bg) 76%, transparent);
  font: 9px/1.45 Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.lathe-cam-origin-status::before {
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px color-mix(in srgb, var(--accent) 55%, transparent);
  content: "";
}

.lathe-cam-field-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 8px;
}

.lathe-cam-field {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 6px;
}

.lathe-cam-field-wide {
  grid-column: 1 / -1;
}

.lathe-cam-stock-profile-controls {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.lathe-cam-stock-profile-controls[hidden] {
  display: none;
}

.lathe-cam-stock-profile-controls .button {
  min-height: 36px;
  padding-inline: 10px;
  white-space: nowrap;
}

.lathe-cam-field.is-disabled {
  opacity: 0.48;
}

.lathe-cam-contour-mode {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--input-bg);
}

.lathe-cam-contour-mode label {
  position: relative;
  min-width: 0;
  cursor: pointer;
}

.lathe-cam-contour-mode input[type="radio"] {
  position: absolute;
  min-width: 0;
  min-height: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  background: transparent;
  opacity: 0;
  pointer-events: none;
}

.lathe-cam-contour-mode label > span {
  min-width: 0;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.lathe-cam-contour-mode input:checked + span {
  border-color: color-mix(in srgb, var(--accent) 28%, var(--line));
  color: var(--ink);
  background: var(--surface-soft);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16), inset 0 1px 0 color-mix(in srgb, var(--ink) 7%, transparent);
}

.lathe-cam-contour-mode input:focus-visible + span {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.lathe-cam-field > span,
.lathe-cam-switch > span > b {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-field input,
.lathe-cam-field select,
.lathe-cam-simulation select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink);
  background: var(--input-bg);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  outline: none;
}

.lathe-cam-field input:focus,
.lathe-cam-field select:focus,
.lathe-cam-simulation select:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: var(--input-focus-bg);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 9%, transparent);
}

.lathe-cam-field .code-input {
  min-height: 34px;
  font-size: 12px;
  font-weight: 700;
}

.lathe-cam-tool-assignment {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 7px;
}

#appView .lathe-cam-page .lathe-cam-tool-assignment .button {
  min-width: 92px;
  min-height: 34px;
  height: 34px;
  padding-inline: 9px;
  font-size: 10px;
}

.lathe-cam-active-tool-meta {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: color-mix(in srgb, var(--input-bg) 76%, transparent);
  font: 9px/1.45 Consolas, "Cascadia Mono", monospace;
  overflow-wrap: anywhere;
}

.lathe-cam-active-tool-meta::before {
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 7px color-mix(in srgb, var(--accent) 52%, transparent);
  content: "";
}

.lathe-cam-thread-tool-hint {
  display: block;
  margin: -2px 0 2px;
  padding: 7px 10px;
  border-left: 3px solid var(--accent, #2f7cf6);
  color: var(--muted, #64748b);
  background: color-mix(in srgb, var(--accent, #2f7cf6) 7%, transparent);
  line-height: 1.45;
}

.lathe-cam-thread-tool-hint.is-active {
  border-left-color: var(--success, #168a62);
  color: var(--text, #1f2937);
  background: color-mix(in srgb, var(--success, #168a62) 9%, transparent);
}

@supports not (background: color-mix(in srgb, white 10%, transparent)) {
  .lathe-cam-thread-tool-hint { background: rgba(47, 124, 246, 0.07); }
  .lathe-cam-thread-tool-hint.is-active { background: rgba(22, 138, 98, 0.09); }
}

.lathe-cam-tool-library-dialog {
  width: min(1120px, calc(100vw - 32px));
  max-width: 1120px;
  height: min(900px, calc(100vh - 32px));
  max-height: 900px;
  display: grid;
  /* Keep the editable tool form visible instead of letting the gang
     dimensions consume the entire dialog. The upper section scrolls on its
     own when its full set of dimensions does not fit. */
  grid-template-rows: auto minmax(240px, 1fr) minmax(360px, 1.35fr);
  overflow: hidden;
}

.lathe-cam-gang-config {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-soft) 76%, transparent);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.lathe-cam-gang-config-heading {
  grid-column: 1 / -1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.lathe-cam-gang-config-heading > div {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.lathe-cam-gang-config-heading > div:first-child {
  display: grid;
  gap: 3px;
}

.lathe-cam-gang-config-heading strong {
  color: var(--ink);
  font-size: 13px;
}

.lathe-cam-gang-config-heading small {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.lathe-cam-gang-state {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border: 1px solid rgba(224, 173, 91, 0.34);
  color: var(--warning);
  background: rgba(224, 173, 91, 0.07);
  font-size: 9px;
  white-space: nowrap;
}

.lathe-cam-gang-state.is-complete {
  border-color: rgba(85, 170, 120, 0.4);
  color: #78c998;
  background: rgba(85, 170, 120, 0.08);
}

#latheCamGangLayoutCanvas {
  width: 100%;
  height: clamp(160px, 22vh, 230px);
  display: block;
  border: 1px solid var(--line-strong);
  background: var(--input-bg);
}

.lathe-cam-gang-config-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-content: start;
  gap: 9px 10px;
}

.lathe-cam-gang-primary-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(250px, 1.7fr) repeat(3, minmax(130px, 1fr));
  align-items: end;
  gap: 10px;
}

.lathe-cam-gang-primary-grid .lathe-cam-confirm-field {
  grid-column: 1 / -1;
}

.lathe-cam-gang-assembly-field small {
  min-height: 14px;
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.35;
}

.lathe-cam-gang-field-hint {
  min-height: 14px;
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.35;
}

.lathe-cam-gang-advanced {
  min-width: 0;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--input-bg) 72%, transparent);
}

.lathe-cam-gang-advanced summary {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.lathe-cam-gang-advanced summary::marker {
  color: var(--accent);
}

.lathe-cam-gang-advanced summary small {
  color: var(--muted);
  font-size: 8px;
  font-weight: 500;
}

.lathe-cam-gang-advanced[open] summary {
  border-bottom: 1px solid var(--line);
}

.lathe-cam-gang-advanced .lathe-cam-gang-config-grid {
  padding: 11px;
}

.lathe-cam-gang-config-grid .field span,
.lathe-cam-gang-primary-grid .field span {
  font-size: 9px;
}

.lathe-cam-confirm-field {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  grid-column: 1 / -1;
  padding: 8px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: color-mix(in srgb, var(--input-bg) 84%, transparent);
  font-size: 9px;
  line-height: 1.45;
}

.lathe-cam-confirm-field input {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  margin: 0;
}

.lathe-cam-gang-layout-summary {
  grid-column: 1 / -1;
  min-height: 20px;
  color: var(--muted);
  font: 9px/1.5 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-tool-library-layout {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
}

.lathe-cam-tool-library-sidebar {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-soft) 86%, transparent);
}

.lathe-cam-tool-library-sidebar-heading {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.lathe-cam-tool-library-sidebar-heading > span {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.lathe-cam-tool-library-sidebar-heading .button {
  min-height: 34px;
  padding-inline: 10px;
}

.lathe-cam-tool-library-list {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 7px;
  overflow-y: auto;
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.lathe-cam-tool-library-item {
  min-width: 0;
  min-height: 64px;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: inherit;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.lathe-cam-tool-library-item:hover {
  border-color: var(--line-strong);
  background: var(--surface-raised);
}

.lathe-cam-tool-library-item.is-active {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--line));
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  box-shadow: inset 3px 0 0 var(--accent);
}

.lathe-cam-tool-library-visual {
  min-width: 0;
  display: grid;
  grid-template-rows: 40px auto;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--input-bg);
}

.lathe-cam-tool-library-visual canvas {
  width: 100%;
  height: 40px;
  display: block;
}

.lathe-cam-tool-library-code {
  display: block;
  padding: 3px 4px 4px;
  border-top: 1px solid var(--line);
  color: var(--accent);
  text-align: center;
  font: 750 11px/1 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-tool-library-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.lathe-cam-tool-library-copy strong,
.lathe-cam-tool-library-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-tool-library-copy strong {
  color: var(--ink);
  font-size: 11px;
}

.lathe-cam-tool-library-copy span {
  color: var(--muted);
  font-size: 9px;
}

.lathe-cam-tool-form {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 20px 0;
}

.lathe-cam-tool-form-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.lathe-cam-tool-form-heading > div {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.lathe-cam-tool-form-heading > div > span {
  padding: 6px 8px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: 5px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font: 750 11px/1 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-tool-form-heading strong {
  color: var(--ink);
  font-size: 15px;
}

.lathe-cam-tool-form-heading small {
  max-width: 260px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
  text-align: right;
}

.lathe-cam-tool-form-error {
  margin: -4px 0 14px;
  padding: 9px 11px;
  border: 1px solid rgba(239, 68, 68, 0.30);
  border-radius: 6px;
  color: #ff9298;
  background: rgba(239, 68, 68, 0.08);
  font-size: 11px;
  line-height: 1.5;
}

.lathe-cam-tool-form-error[hidden] {
  display: none;
}

.lathe-cam-insert-catalog {
  min-width: 0;
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--input-bg) 84%, transparent);
}

.lathe-cam-insert-catalog-heading {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(180px, 0.85fr) minmax(260px, 1.15fr);
  align-items: center;
  gap: 12px;
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-soft) 70%, transparent);
}

.lathe-cam-insert-catalog-heading > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.lathe-cam-insert-catalog-heading strong {
  color: var(--ink);
  font-size: 11px;
  line-height: 1.35;
}

.lathe-cam-insert-catalog-heading small {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-insert-catalog-search {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
}

.lathe-cam-insert-catalog-search svg {
  position: absolute;
  left: 10px;
  z-index: 1;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
}

.lathe-cam-insert-catalog-search input {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 7px 10px 7px 32px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: 0;
  color: var(--ink);
  background: var(--input-bg);
  font: 600 10px/1.3 Consolas, "Cascadia Mono", monospace;
  letter-spacing: 0;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
  -webkit-appearance: none;
  appearance: none;
}

.lathe-cam-insert-catalog-search input::placeholder {
  color: var(--faint);
  font-family: inherit;
  font-weight: 500;
  opacity: 1;
}

.lathe-cam-insert-catalog-search:focus-within svg {
  color: var(--accent);
}

.lathe-cam-insert-catalog-search input:focus,
.lathe-cam-insert-catalog-search input:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 62%, var(--line));
  background: var(--input-focus-bg);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.lathe-cam-insert-catalog-results {
  min-width: 0;
  min-height: 92px;
  max-height: 226px;
  display: grid;
  align-content: start;
  gap: 3px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 6px;
  outline: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.lathe-cam-insert-catalog-results:focus-visible {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 56%, transparent);
}

.lathe-cam-insert-catalog-result {
  min-width: 0;
  min-height: 52px;
  display: grid;
  grid-template-columns: minmax(145px, 0.8fr) minmax(255px, 1.55fr) minmax(145px, 0.85fr);
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 5px;
  outline: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.lathe-cam-insert-catalog-result:hover {
  border-color: var(--line);
  background: var(--surface-raised);
}

.lathe-cam-insert-catalog-result:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 64%, var(--line));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.lathe-cam-insert-catalog-result[aria-selected="true"],
.lathe-cam-insert-catalog-result.is-active {
  border-color: color-mix(in srgb, var(--accent) 48%, var(--line));
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
  box-shadow: inset 3px 0 0 var(--accent);
}

.lathe-cam-insert-catalog-identity,
.lathe-cam-insert-catalog-fit {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.lathe-cam-insert-catalog-identity strong {
  overflow-wrap: anywhere;
  color: var(--accent);
  font: 750 11px/1.25 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-insert-catalog-identity small,
.lathe-cam-insert-catalog-fit small {
  overflow: hidden;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-insert-catalog-specs {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font: 9px/1.35 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-insert-catalog-specs > span {
  white-space: nowrap;
}

.lathe-cam-insert-catalog-specs b {
  margin-right: 3px;
  color: var(--faint);
  font-weight: 650;
}

.lathe-cam-insert-catalog-fit {
  justify-items: end;
  text-align: right;
}

.lathe-cam-insert-catalog-status {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 74%, transparent);
  font-size: 8px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.lathe-cam-insert-catalog-status::before {
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.lathe-cam-insert-catalog-result.is-compatible .lathe-cam-insert-catalog-status {
  border-color: color-mix(in srgb, var(--success) 38%, var(--line));
  color: var(--success);
  background: color-mix(in srgb, var(--success) 9%, transparent);
}

.lathe-cam-insert-catalog-result.is-incompatible .lathe-cam-insert-catalog-status {
  border-color: color-mix(in srgb, var(--danger) 38%, var(--line));
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 9%, transparent);
}

.lathe-cam-insert-catalog-result.is-unconfirmed .lathe-cam-insert-catalog-status {
  border-color: color-mix(in srgb, var(--warning) 34%, var(--line));
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 8%, transparent);
}

.lathe-cam-insert-catalog-empty {
  min-height: 80px;
  display: grid;
  place-content: center;
  gap: 3px;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.lathe-cam-insert-catalog-empty strong {
  color: var(--ink);
  font-size: 10px;
  line-height: 1.4;
}

.lathe-cam-insert-catalog-empty span {
  max-width: 420px;
  font-size: 9px;
  line-height: 1.5;
}

.lathe-cam-tool-preview {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 152px;
  align-items: stretch;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--input-bg) 84%, transparent);
}

.lathe-cam-tool-preview canvas {
  width: 100%;
  height: 132px;
  display: block;
  border-right: 1px solid var(--line);
}

.lathe-cam-tool-preview > div {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 14px;
}

.lathe-cam-tool-preview span,
.lathe-cam-tool-preview small {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.4;
}

.lathe-cam-tool-preview strong {
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
}

.lathe-cam-tool-form-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 12px;
}

.lathe-cam-tool-form-wide {
  grid-column: 1 / -1;
}

.lathe-cam-tool-database-match {
  display: block;
  min-height: 14px;
  margin-top: 5px;
  color: var(--accent);
  font-size: 9px;
  line-height: 1.45;
}

.lathe-cam-tool-collision-state {
  min-height: 34px;
  display: flex;
  align-items: center;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.lathe-cam-tool-collision-state.is-complete {
  border-color: rgba(85, 170, 120, 0.38);
  color: #78c998;
  background: rgba(85, 170, 120, 0.08);
}

.lathe-cam-tool-collision-state.is-incomplete {
  border-color: rgba(224, 173, 91, 0.38);
  color: var(--warning);
  background: rgba(224, 173, 91, 0.08);
}

.lathe-cam-tool-angle-field {
  grid-column: span 2;
}

.lathe-cam-tool-angle-input {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.lathe-cam-tool-angle-input output {
  min-width: 92px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 6px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--input-bg));
  font: 600 10px/1.2 Consolas, "Cascadia Mono", monospace;
  white-space: nowrap;
}

.lathe-cam-tool-angle-input output.is-warning {
  border-color: rgba(224, 173, 91, 0.38);
  color: var(--warning);
  background: rgba(224, 173, 91, 0.08);
}

.lathe-cam-tool-angle-input output.is-danger {
  border-color: rgba(239, 68, 68, 0.4);
  color: #ff9298;
  background: rgba(239, 68, 68, 0.08);
}

.lathe-cam-tool-angle-field > small {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.lathe-cam-tool-form-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(224, 173, 91, 0.24);
  border-radius: 6px;
  color: var(--warning);
  background: rgba(224, 173, 91, 0.07);
  font-size: 10px;
  line-height: 1.55;
}

.lathe-cam-tool-form-note svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  margin-top: 1px;
}

.lathe-cam-tool-form-actions {
  position: sticky;
  bottom: 0;
  margin: auto -20px 0;
}

@media (max-width: 920px) {
  .lathe-cam-insert-catalog-heading {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .lathe-cam-insert-catalog-heading small {
    white-space: normal;
  }

  .lathe-cam-insert-catalog-result {
    min-height: 60px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 10px;
  }

  .lathe-cam-insert-catalog-specs {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .lathe-cam-insert-catalog-fit {
    max-width: 180px;
  }
}

html[data-theme="light"] .lathe-cam-tool-library-sidebar {
  background: #f0f4f1;
}

html[data-theme="light"] .lathe-cam-tool-library-item {
  background: #fafcfa;
}

html[data-theme="light"] .lathe-cam-tool-form-error {
  color: #b4232d;
}

@media (max-width: 760px) {
  .lathe-cam-tool-library-dialog {
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
    max-height: none;
    grid-template-rows: auto minmax(180px, 38vh) minmax(260px, 1fr);
  }

  .lathe-cam-tool-library-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 34vh) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    max-height: 44vh;
    grid-template-columns: 1fr;
    overflow-y: auto;
    padding: 12px;
  }

  .lathe-cam-gang-config-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .lathe-cam-gang-config-heading > div:last-child {
    width: 100%;
    justify-content: space-between;
  }

  #latheCamGangLayoutCanvas {
    height: 150px;
  }

  .lathe-cam-gang-config-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lathe-cam-gang-primary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lathe-cam-gang-assembly-field {
    grid-column: 1 / -1;
  }

  .lathe-cam-tool-library-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .lathe-cam-tool-form {
    padding: 16px 14px 0;
  }

  .lathe-cam-tool-form-grid {
    grid-template-columns: 1fr;
  }

  .lathe-cam-tool-form-wide {
    grid-column: auto;
  }

  .lathe-cam-tool-angle-field {
    grid-column: auto;
  }

  .lathe-cam-insert-catalog-heading {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .lathe-cam-insert-catalog-heading small {
    white-space: normal;
  }

  .lathe-cam-insert-catalog-search input {
    min-height: 44px;
  }

  .lathe-cam-insert-catalog-results {
    max-height: 252px;
  }

  .lathe-cam-insert-catalog-result {
    min-height: 64px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 10px;
    padding: 8px 9px;
  }

  .lathe-cam-insert-catalog-specs {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .lathe-cam-insert-catalog-fit {
    max-width: 142px;
  }

  .lathe-cam-tool-preview {
    grid-template-columns: 1fr;
  }

  .lathe-cam-tool-preview canvas {
    height: 116px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .lathe-cam-tool-preview > div {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 4px 10px;
    padding: 10px 12px;
  }

  .lathe-cam-tool-preview > div small {
    grid-column: 2;
  }

  .lathe-cam-tool-form-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .lathe-cam-tool-form-heading small {
    max-width: none;
    text-align: left;
  }

  .lathe-cam-tool-form-actions {
    margin-inline: -14px;
  }
}

.lathe-cam-input-unit {
  position: relative;
  min-width: 0;
}

.lathe-cam-input-unit input {
  padding-right: 38px;
}

.lathe-cam-input-unit em {
  position: absolute;
  top: 50%;
  right: 8px;
  overflow: hidden;
  max-width: 34px;
  color: var(--muted);
  font-size: 9px;
  font-style: normal;
  line-height: 1;
  text-overflow: ellipsis;
  transform: translateY(-50%);
  pointer-events: none;
  white-space: nowrap;
}

.lathe-cam-switch {
  position: relative;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  cursor: pointer;
}

.lathe-cam-switch > span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.lathe-cam-switch > span > small {
  color: var(--muted);
  font: 9px/1.2 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-switch input {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 0;
  min-height: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.lathe-cam-switch > i {
  position: relative;
  width: 34px;
  height: 19px;
  flex: 0 0 34px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--input-bg);
  transition: border-color 140ms ease, background 140ms ease;
}

.lathe-cam-switch > i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
  content: "";
  transition: transform 140ms ease, background 140ms ease;
}

.lathe-cam-switch input:checked + i {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 20%, var(--input-bg));
}

.lathe-cam-switch input:checked + i::after {
  background: var(--accent);
  transform: translateX(15px);
}

.lathe-cam-switch input:focus-visible + i {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.lathe-cam-preview {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 14px;
}

.lathe-cam-preview-heading {
  align-items: flex-start;
}

.lathe-cam-view-controls {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
}

.lathe-cam-view-button {
  min-width: 35px;
  height: 27px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--muted);
  background: transparent;
  font: 700 10px/1 Consolas, "Cascadia Mono", monospace;
  cursor: pointer;
}

.lathe-cam-view-button:hover,
.lathe-cam-view-button.is-active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.lathe-cam-view-controls .icon-button {
  width: 27px;
  min-height: 27px;
  height: 27px;
  border-color: transparent;
}

.lathe-cam-metrics {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.lathe-cam-metrics > span {
  min-width: 42px;
  display: grid;
  gap: 1px;
  text-align: right;
}

.lathe-cam-metrics b {
  color: var(--ink);
  font: 700 12px/1.2 Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.lathe-cam-metrics small {
  color: var(--muted);
  font-size: 9px;
  white-space: nowrap;
}

.lathe-cam-canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 400px;
  overflow: hidden;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--cam-preview-bg);
  cursor: grab;
  touch-action: none;
}

.lathe-cam-canvas-wrap.is-panning {
  cursor: grabbing;
}

.lathe-cam-canvas-wrap.is-contour-pick:not(.is-panning) {
  cursor: crosshair;
}

.lathe-cam-canvas-wrap.is-dragover {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 12%, transparent);
}

.lathe-cam-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.lathe-cam-canvas-wrap canvas[hidden] {
  display: none;
}

#latheCam3dCanvas {
  cursor: grab;
  touch-action: none;
}

#latheCam3dCanvas.is-dragging {
  cursor: grabbing;
}

.lathe-cam-3d-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  background: var(--cam-preview-bg);
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}

.lathe-cam-3d-fallback[hidden] {
  display: none;
}

.lathe-cam-deburr-panel {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--line));
  border-radius: 5px;
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}

.lathe-cam-deburr-toggle {
  min-height: 30px;
}

.lathe-cam-deburr-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
  gap: 8px;
}

.lathe-cam-deburr-controls > * {
  min-width: 0;
}

.lathe-cam-deburr-controls .button {
  grid-column: 1 / -1;
  min-height: 34px;
  min-width: 0;
  white-space: nowrap;
}

.lathe-cam-deburr-status {
  min-height: 16px;
  color: var(--muted);
  font-size: 10px;
}

.lathe-cam-deburr-status.is-selected {
  color: var(--accent);
}

.lathe-cam-drop-hint {
  position: absolute;
  inset: 16px;
  display: none;
  place-items: center;
  align-content: center;
  gap: 9px;
  border: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 6px;
  color: var(--accent);
  background: rgba(12, 14, 18, 0.88);
  pointer-events: none;
}

.lathe-cam-drop-hint svg {
  width: 24px;
  height: 24px;
}

.lathe-cam-drop-hint strong {
  font-size: 12px;
}

.lathe-cam-canvas-wrap.is-dragover .lathe-cam-drop-hint {
  display: grid;
}

.lathe-cam-legend {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px 12px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 5px;
  color: #aab2c0;
  background: rgba(12, 14, 18, 0.78);
  font-size: 9px;
  pointer-events: none;
}

.lathe-cam-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.lathe-cam-legend span::before {
  width: 11px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  content: "";
}

.lathe-cam-legend .is-stock { color: #73a3f8; }
.lathe-cam-legend .is-rough { color: var(--cam-rough); }
.lathe-cam-legend .is-finish { color: var(--cam-finish); }

.lathe-cam-mirror-controls {
  position: absolute;
  z-index: 3;
  top: 10px;
  left: 42px;
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  background: rgba(12, 14, 18, 0.78);
  pointer-events: auto;
  touch-action: manipulation;
}

.lathe-cam-mirror-controls .icon-button {
  width: 28px;
  min-height: 28px;
  height: 28px;
  border-color: transparent;
  background: transparent;
}

.lathe-cam-mirror-controls .icon-button.is-active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-soft));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 8%, transparent);
}

.lathe-cam-simulation {
  min-width: 0;
  min-height: 38px;
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr) auto 52px;
  align-items: center;
  gap: 10px;
}

.lathe-cam-sim-buttons {
  display: flex;
  gap: 5px;
}

.lathe-cam-sim-buttons .icon-button {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
}

.lathe-cam-sim-buttons .lathe-cam-play {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
  color: var(--accent);
}

.lathe-cam-timeline {
  width: 100%;
  min-width: 0;
  accent-color: var(--accent);
}

.lathe-cam-simulation output {
  min-width: 84px;
  color: var(--muted);
  font: 10px/1 Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.lathe-cam-simulation select {
  height: 30px;
  padding: 0 5px;
  font-size: 10px;
}

.lathe-cam-code-standard {
  flex: 0 0 auto;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font: 9px/1.2 Consolas, "Cascadia Mono", monospace;
}

.lathe-cam-gcode {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  margin: 12px 0;
  overflow: auto;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--code-text);
  background: var(--code-bg);
  font: 11px/1.65 Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
  outline: none;
  scrollbar-width: thin;
  tab-size: 2;
  white-space: pre;
}

.lathe-cam-gcode:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 52%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 9%, transparent);
}

.lathe-cam-gcode.is-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-family: inherit;
  text-align: center;
  white-space: normal;
}

.lathe-cam-output-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.lathe-cam-output-actions .button {
  min-width: 0;
  min-height: 36px;
  padding: 0 10px;
  font-size: 10px;
}

.lathe-cam-output-actions .button:last-child {
  grid-column: 1 / -1;
}

.lathe-cam-output-actions .button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-output-actions .button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.lathe-cam-safety {
  min-height: 32px;
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin: 10px 0 0;
  color: #e9b55e;
  font-size: 9px;
  line-height: 1.5;
}

html[data-theme="light"] .lathe-cam-page {
  --cam-preview-bg: #eef2f3;
  --cam-grid: rgba(61, 79, 91, 0.12);
  --cam-grid-strong: rgba(61, 79, 91, 0.25);
  --cam-stock: rgba(61, 111, 197, 0.10);
  --cam-stock-edge: rgba(61, 111, 197, 0.52);
  --cam-rough: #b86a17;
  --cam-rapid: #77838c;
  --cam-finish: #718d0e;
  --cam-tool: #25343d;
}

html[data-theme="light"] .lathe-cam-notice {
  color: #8a5608;
  background: rgba(245, 158, 11, 0.08);
}

html[data-theme="light"] .lathe-cam-notice.is-error {
  color: #b4232d;
}

html[data-theme="light"] .lathe-cam-notice.is-success {
  color: #18734f;
}

html[data-theme="light"] .lathe-cam-state {
  color: #18734f;
}

html[data-theme="light"] .lathe-cam-state.is-invalid {
  color: #b4232d;
}

html[data-theme="light"] .lathe-cam-scope-heading {
  background: color-mix(in srgb, var(--surface) 96%, transparent);
}

html[data-theme="light"] .lathe-cam-operation-context {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.62);
}

html[data-theme="light"] .lathe-cam-process-group {
  background: color-mix(in srgb, var(--surface-soft) 86%, transparent);
}

html[data-theme="light"] .lathe-cam-drop-hint {
  background: rgba(247, 249, 249, 0.92);
}

html[data-theme="light"] .lathe-cam-legend {
  border-color: rgba(34, 52, 63, 0.12);
  color: #566773;
  background: rgba(247, 249, 249, 0.86);
}

html[data-theme="light"] .lathe-cam-mirror-controls {
  border-color: rgba(34, 52, 63, 0.12);
  background: rgba(247, 249, 249, 0.86);
}

html[data-theme="light"] .lathe-cam-safety {
  color: #8a5608;
}

@media (max-width: 1450px) {
  .lathe-cam-workspace {
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  }

  .lathe-cam-settings,
  .lathe-cam-preview {
    height: calc(100vh - 255px);
    min-height: 590px;
  }

  .lathe-cam-output {
    min-height: 390px;
    grid-column: 1 / -1;
  }

  .lathe-cam-gcode {
    max-height: 320px;
  }

  .lathe-cam-output-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lathe-cam-output-actions .button:last-child {
    grid-column: auto;
  }
}

@media (max-width: 980px) {
  .lathe-cam-workspace {
    grid-template-columns: 1fr;
  }

  .lathe-cam-settings,
  .lathe-cam-preview {
    height: auto;
    min-height: 0;
  }

  .lathe-cam-settings-scroll {
    max-height: none;
    overflow: visible;
  }

  .lathe-cam-settings {
    overflow: visible;
  }

  .lathe-cam-preview {
    min-height: 560px;
  }

  .lathe-cam-canvas-wrap {
    min-height: 440px;
  }

  .lathe-cam-output {
    min-height: 440px;
    grid-column: auto;
  }
}

@media (max-width: 680px) {
  #appView .lathe-cam-page button,
  #appView .lathe-cam-page input:not([type="file"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  #appView .lathe-cam-page select,
  .lathe-cam-dxf-guide summary {
    min-height: 44px;
  }

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

  .lathe-cam-toolbar .toolbar-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lathe-cam-toolbar .button {
    min-width: 0;
  }

  .lathe-cam-field-grid {
    grid-template-columns: 1fr;
  }

  .lathe-cam-operation-context {
    grid-template-columns: 43px minmax(0, 1fr);
  }

  .lathe-cam-operation-scope {
    display: none;
  }

  .lathe-cam-field-wide {
    grid-column: auto;
  }

  #appView .lathe-cam-page .lathe-cam-operation-add {
    min-height: 30px;
    height: 30px;
  }

  .lathe-cam-operation-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .lathe-cam-range-controls {
    grid-template-columns: 1fr;
  }

  #appView .lathe-cam-page .lathe-cam-operation-enable,
  #appView .lathe-cam-page .lathe-cam-operation-move,
  #appView .lathe-cam-page .lathe-cam-operation-delete {
    min-height: 30px;
    height: 30px;
  }

  #appView .lathe-cam-page .lathe-cam-origin-actions .button {
    min-height: 36px;
    height: auto;
  }

  .lathe-cam-dxf-guide ul {
    font-size: 11px;
    line-height: 1.65;
  }

  .lathe-cam-preview-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .lathe-cam-metrics {
    justify-content: space-between;
  }

  .lathe-cam-view-controls {
    margin-left: 0;
    align-self: flex-start;
  }

  .lathe-cam-deburr-controls {
    grid-template-columns: 1fr;
  }

  .lathe-cam-deburr-controls .button {
    grid-column: auto;
  }

  .lathe-cam-metrics > span {
    text-align: left;
  }

  .lathe-cam-preview {
    min-height: 510px;
  }

  .lathe-cam-canvas-wrap {
    min-height: 370px;
  }

  .lathe-cam-legend {
    right: 7px;
    left: 7px;
    justify-content: center;
  }

  .lathe-cam-simulation {
    grid-template-columns: auto minmax(70px, 1fr) 48px;
  }

  .lathe-cam-simulation output {
    display: none;
  }

  .lathe-cam-output-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lathe-cam-output-actions .button:last-child {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lathe-cam-dxf-guide summary::after,
  .lathe-cam-contour-mode label > span,
  .lathe-cam-operation-item,
  .lathe-cam-insert-catalog-search input,
  .lathe-cam-insert-catalog-result,
  .lathe-cam-switch > i,
  .lathe-cam-switch > i::after {
    transition: none;
  }
}


.lathe-cam-model-catalog {
  flex: 0 0 auto;
  min-height: 160px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-heading {
  grid-template-columns: minmax(220px, 0.8fr) minmax(320px, 1.2fr);
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-heading strong {
  font-size: 12px;
}

.lathe-cam-model-pair-status {
  min-width: 0;
  min-height: 48px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 7%, transparent);
}

.lathe-cam-model-pair-status::before {
  width: 7px;
  height: 7px;
  grid-column: 1;
  grid-row: 1;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 13%, transparent);
  content: "";
}

.lathe-cam-model-pair-status.is-compatible {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 8%, transparent);
}

.lathe-cam-model-pair-status.is-incompatible {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

.lathe-cam-model-pair-label {
  display: none;
}

.lathe-cam-model-pair-copy {
  min-width: 0;
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.lathe-cam-model-pair-copy strong {
  flex: 0 0 auto;
  color: currentColor;
  font-size: 10px;
  line-height: 1.35;
}

.lathe-cam-model-pair-copy small {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font: 600 9px/1.4 Consolas, "Cascadia Mono", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lathe-cam-model-catalog-modes {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 7px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-soft) 48%, transparent);
}

.lathe-cam-model-catalog-modes button {
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 5px;
  outline: 0;
  color: var(--muted);
  background: transparent;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  cursor: pointer;
}

.lathe-cam-model-catalog-modes button:hover {
  color: var(--ink);
  background: var(--surface-raised);
}

.lathe-cam-model-catalog-modes button.is-active {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--line));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
}

.lathe-cam-model-catalog-modes button:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 68%, var(--line));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* Catalog clicks are staged until the operator confirms them.  Keep the
   pending card distinct from the currently applied model and reserve the
   right side of the mode bar for the single commit action. */
.lathe-cam-model-catalog-modes .lathe-cam-model-catalog-confirm {
  min-height: 30px;
  margin-left: auto;
  border-color: color-mix(in srgb, var(--accent) 58%, var(--line));
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  white-space: nowrap;
}

.lathe-cam-model-catalog-modes .lathe-cam-model-catalog-confirm:hover:not(:disabled) {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.lathe-cam-model-catalog-modes .lathe-cam-model-catalog-confirm:disabled {
  opacity: .55;
  cursor: default;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-result.is-pending {
  border-color: color-mix(in srgb, var(--accent) 82%, var(--line)) !important;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-result.is-pending
  .lathe-cam-insert-catalog-status {
  color: var(--accent);
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
  min-height: 116px;
  max-height: 286px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
  grid-template-columns: minmax(190px, 0.9fr) minmax(270px, 1.45fr) minmax(180px, 0.9fr);
}

/* Owner-managed CAD bindings sit in the same tool form as the model query.
   Keep the panel dense enough for desktop use without hiding the permission
   state or the actual imported formats. */
.lathe-cam-cad-manager {
  margin: 14px 0 16px;
  padding: 14px;
  border: 1px solid rgba(123, 151, 165, .34);
  border-radius: 8px;
  background: rgba(16, 25, 31, .72);
}
.lathe-cam-cad-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.lathe-cam-cad-heading strong {
  display: block;
  color: #eef4f7;
  font-size: 13px;
  letter-spacing: 0;
}
.lathe-cam-cad-heading small,
.lathe-cam-cad-note {
  display: block;
  margin: 4px 0 0;
  color: #91a3ad;
  font-size: 11px;
  line-height: 1.45;
}
.lathe-cam-cad-heading .lathe-cam-cad-guidance {
  color: #b9c9cf;
}
.lathe-cam-cad-role {
  flex: 0 0 auto;
  padding: 4px 7px;
  border: 1px solid rgba(235, 192, 87, .4);
  border-radius: 4px;
  color: #e8c86b;
  font-size: 11px;
  white-space: nowrap;
}
.lathe-cam-cad-role.is-owner {
  border-color: rgba(111, 220, 150, .45);
  color: #7fe19b;
}
.lathe-cam-cad-role.is-readonly {
  color: #e8c86b;
}
.lathe-cam-cad-fields {
  display: grid;
  grid-template-columns: 1fr 1.35fr .65fr .65fr;
  gap: 9px;
  margin-top: 12px;
}
.lathe-cam-cad-fields label {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.lathe-cam-cad-fields label > span {
  color: #aebcc4;
  font-size: 11px;
}
.lathe-cam-cad-fields input,
.lathe-cam-cad-fields select {
  width: 100%;
  min-height: 32px;
  box-sizing: border-box;
}
.lathe-cam-cad-file {
  grid-column: span 2;
}
.lathe-cam-cad-file input[type="file"] {
  padding: 5px 6px;
  color: #b9c6cc;
  font-size: 11px;
}
.lathe-cam-cad-edit-context {
  margin: 10px 0;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, #aeea53 52%, var(--line));
  border-radius: 6px;
  background: color-mix(in srgb, #aeea53 8%, transparent);
  color: var(--text, #e9f0f3);
  font-size: 12px;
  line-height: 1.55;
}
.lathe-cam-cad-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 11px;
}
.lathe-cam-cad-actions .button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 11px;
}
.lathe-cam-cad-actions .lathe-cam-cad-new-model {
  border-color: rgba(126, 221, 155, .42);
  color: #9ce8b0;
  background: rgba(47, 102, 68, .18);
}
.lathe-cam-cad-actions .lathe-cam-cad-new-model:hover {
  border-color: rgba(126, 221, 155, .72);
  background: rgba(47, 102, 68, .3);
}
.lathe-cam-cad-actions .lathe-cam-cad-new-model:disabled {
  border-color: rgba(128, 157, 168, .24);
  color: #7d8e96;
  background: rgba(25, 36, 42, .5);
}
.lathe-cam-cad-actions .lathe-cam-cad-example-button {
  margin-left: auto;
  border-color: rgba(137, 184, 204, .42);
  color: #c0d5de;
}
.lathe-cam-cad-actions .lathe-cam-cad-example-button:hover {
  border-color: rgba(174, 234, 83, .58);
  color: #edf5f7;
}
.lathe-cam-cad-example-backdrop {
  z-index: 1260;
  background: rgba(4, 8, 10, .72);
}
.lathe-cam-cad-example-dialog {
  width: min(920px, calc(100vw - 32px));
  max-height: min(820px, calc(100dvh - 32px));
  overflow: auto;
}
.lathe-cam-cad-example-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 14px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-soft));
}
.lathe-cam-cad-example-notice strong {
  color: var(--accent);
  font-size: 12px;
}
.lathe-cam-cad-example-notice span {
  color: var(--muted);
  font-size: 11px;
}
.lathe-cam-cad-example-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px 16px 10px;
}
.lathe-cam-cad-example-panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid rgba(128, 157, 168, .3);
  border-radius: 6px;
  background: #10191f;
}
.lathe-cam-cad-example-panel header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-bottom: 1px solid rgba(128, 157, 168, .24);
}
.lathe-cam-cad-example-panel header strong { color: #edf4f6; font-size: 12px; }
.lathe-cam-cad-example-panel header span { color: #91a4ad; font-size: 10px; }
.lathe-cam-cad-example-panel svg {
  display: block;
  width: 100%;
  height: 220px;
  aspect-ratio: 21 / 11;
  background: #0d151a;
}
.lathe-cam-cad-example-panel svg text {
  fill: #b7c7ce;
  font: 10px sans-serif;
  letter-spacing: 0;
}
.lathe-cam-cad-example-panel p {
  min-height: 34px;
  margin: 0;
  padding: 8px 11px 9px;
  color: #9eb0b8;
  font-size: 10px;
  line-height: 1.5;
}
.lathe-cam-cad-example-panel .cad-example-grid {
  fill: none;
  stroke: rgba(141, 165, 175, .28);
  stroke-width: 1;
}
.lathe-cam-cad-example-panel .cad-example-outline {
  fill: rgba(174, 234, 83, .12);
  stroke: #aeea53;
  stroke-width: 2;
}
.lathe-cam-cad-example-panel .cad-example-axis {
  fill: none;
  stroke: #74b7d1;
  stroke-width: 1.5;
}
.lathe-cam-cad-example-panel .cad-example-origin { fill: #f0c963; stroke: #10191f; stroke-width: 2; }
.lathe-cam-cad-example-panel .cad-example-fixture { fill: #31434c; stroke: #66818d; }
.lathe-cam-cad-example-panel .cad-example-fixture-top { fill: #425a65; stroke: #7894a0; }
.lathe-cam-cad-example-panel .cad-example-holder { fill: #406446; stroke: #78b27f; }
.lathe-cam-cad-example-panel .cad-example-holder-top { fill: #557c5a; stroke: #90c496; }
.lathe-cam-cad-example-panel .cad-example-insert { fill: #c8a94e; stroke: #f0d47d; }
.lathe-cam-cad-example-rules {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 16px 14px;
}
.lathe-cam-cad-example-rules strong,
.lathe-cam-cad-example-rules span {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border: 1px solid rgba(128, 157, 168, .28);
  border-radius: 4px;
  color: #adbec5;
  background: rgba(20, 31, 37, .72);
  font-size: 10px;
}
.lathe-cam-cad-example-rules strong {
  border-color: rgba(174, 234, 83, .38);
  color: #caef8d;
}
.lathe-cam-cad-example-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
}
.lathe-cam-cad-example-actions .button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 11px;
}
@media (max-width: 700px) {
  .lathe-cam-cad-actions .lathe-cam-cad-example-button { margin-left: 0; }
  .lathe-cam-cad-example-grid { grid-template-columns: 1fr; padding-inline: 10px; }
  .lathe-cam-cad-example-dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .lathe-cam-cad-example-actions { justify-content: stretch; padding-inline: 10px; }
  .lathe-cam-cad-example-actions .button { flex: 1 1 180px; }
  .lathe-cam-cad-example-panel svg { height: 176px; }
}
.lathe-cam-cad-status {
  min-height: 18px;
  margin-top: 9px;
  color: #b8c8cf;
  font-size: 11px;
  line-height: 1.45;
}
.lathe-cam-cad-status.is-ready { color: #84dfa1; }
.lathe-cam-cad-status.is-error { color: #ff9a9f; }
.lathe-cam-cad-status.is-readonly { color: #d8bd71; }
.lathe-cam-cad-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 6px;
  max-height: 120px;
  overflow: auto;
  margin-top: 8px;
}
.lathe-cam-cad-list-item {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid rgba(116, 145, 158, .28);
  border-radius: 5px;
  background: rgba(28, 40, 47, .68);
  color: #d9e3e7;
  text-align: left;
  cursor: pointer;
}
.lathe-cam-cad-list-item:hover { border-color: rgba(126, 221, 155, .6); }
.lathe-cam-cad-list-item strong {
  overflow: hidden;
  color: #e8eef0;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lathe-cam-cad-list-item small {
  overflow: hidden;
  color: #92a4ad;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 760px) {
  .lathe-cam-cad-fields { grid-template-columns: 1fr 1fr; }
  .lathe-cam-cad-file { grid-column: span 1; }
}

.lathe-cam-assembly-edit-controls {
  position: absolute;
  z-index: 8;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.lathe-cam-assembly-edit-controls .button {
  min-height: 30px;
  padding: 5px 9px;
  border-color: color-mix(in srgb, var(--line) 82%, #aeea53);
  background: color-mix(in srgb, var(--surface, #11191e) 92%, transparent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .24);
  backdrop-filter: blur(8px);
  font-size: 10px;
}

.lathe-cam-assembly-edit-controls svg {
  width: 14px;
  height: 14px;
}

.lathe-cam-tool-library-dialog .is-edit-target {
  outline: 2px solid #aeea53;
  outline-offset: 3px;
  background: color-mix(in srgb, #aeea53 8%, transparent);
}

.lathe-cam-tool-library-dialog .lathe-cam-cad-file.is-edit-target {
  outline: 2px solid #aeea53;
  outline-offset: 2px;
  border-radius: 5px;
  background: color-mix(in srgb, #aeea53 7%, transparent);
}

.lathe-cam-process-group.is-cycle-options,
.lathe-cam-process-group.is-drilling,
.lathe-cam-process-group.is-threading {
  min-width: 0;
}

@media (max-width: 760px) {
  .lathe-cam-assembly-edit-controls {
    top: 8px;
    right: 8px;
    flex-direction: column;
    align-items: stretch;
  }

  .lathe-cam-assembly-edit-controls .button {
    min-height: 28px;
    padding: 4px 7px;
    font-size: 9px;
  }
}

/* -------------------------------------------------------------------------
   Tool settings layout pass
   The host stylesheet reserves two large fractional rows for the gang
   summary and editor.  On taller screens that makes the preview canvas grow
   needlessly and leaves a second scrollbar inside the gang section.  Keep
   the summary compact and give the editor the only primary scroll surface.
   ------------------------------------------------------------------------- */
.lathe-cam-tool-library-dialog {
  width: min(1220px, calc(100vw - 28px));
  max-width: 1220px;
  height: min(920px, calc(100vh - 28px));
  max-height: 920px;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.lathe-cam-gang-config {
  max-height: none;
  overflow: visible;
  gap: 7px;
  padding: 10px 16px 8px;
}

.lathe-cam-gang-config-heading {
  gap: 10px;
}

.lathe-cam-gang-config-heading strong {
  font-size: 12px;
}

.lathe-cam-gang-config-heading small {
  font-size: 8px;
}

#latheCamGangLayoutCanvas {
  height: clamp(122px, 15vh, 168px);
}

.lathe-cam-gang-primary-grid {
  grid-template-columns: minmax(220px, 1.8fr) repeat(3, minmax(110px, 1fr));
  gap: 7px 8px;
}

.lathe-cam-gang-primary-grid .field {
  gap: 4px;
}

.lathe-cam-gang-primary-grid .field input,
.lathe-cam-gang-primary-grid .field select {
  min-height: 32px;
}

.lathe-cam-gang-primary-grid .lathe-cam-confirm-field {
  padding: 6px 8px;
}

.lathe-cam-gang-layout-summary {
  min-height: 16px;
  font-size: 8px;
}

.lathe-cam-tool-library-layout {
  grid-template-columns: minmax(228px, 270px) minmax(0, 1fr);
}

.lathe-cam-tool-library-sidebar-heading {
  min-height: 52px;
  padding: 9px 11px;
}

.lathe-cam-tool-library-sidebar-heading .button {
  min-height: 31px;
  padding-inline: 9px;
}

.lathe-cam-tool-library-list {
  gap: 5px;
  padding: 8px;
}

.lathe-cam-tool-library-item {
  min-height: 56px;
  grid-template-columns: 66px minmax(0, 1fr);
  gap: 8px;
  padding: 7px 8px;
}

.lathe-cam-tool-library-visual {
  grid-template-rows: 34px auto;
}

.lathe-cam-tool-library-visual canvas {
  height: 34px;
}

.lathe-cam-tool-library-code {
  padding: 3px 3px 3px;
  font-size: 10px;
}

.lathe-cam-tool-form {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 0;
}

.lathe-cam-tool-form-heading {
  gap: 10px;
  margin-bottom: 10px;
}

.lathe-cam-tool-form-heading strong {
  font-size: 14px;
}

.lathe-cam-tool-form-heading small {
  max-width: 220px;
  font-size: 9px;
}

.lathe-cam-insert-catalog {
  margin-bottom: 10px;
}

.lathe-cam-insert-catalog-heading {
  gap: 9px;
  padding: 8px 9px;
}

.lathe-cam-insert-catalog-results,
.lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
  min-height: 60px;
  max-height: 166px;
  padding: 5px;
}

.lathe-cam-insert-catalog-result,
.lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
  min-height: 46px;
  gap: 7px;
  padding: 6px 7px;
}

.lathe-cam-tool-preview {
  grid-template-columns: minmax(0, 1fr) 132px;
  margin-bottom: 10px;
}

.lathe-cam-tool-preview canvas {
  height: 96px;
}

.lathe-cam-tool-preview > div {
  gap: 5px;
  padding: 10px;
}

.lathe-cam-tool-form-grid {
  gap: 9px 10px;
}

.lathe-cam-tool-form-grid .field {
  gap: 4px;
}

.lathe-cam-tool-form-note {
  margin-top: 10px;
  padding: 8px 10px;
}

.lathe-cam-tool-form-actions {
  margin-inline: -16px;
}

.lathe-cam-cad-manager {
  margin: 8px 0 10px;
  padding: 10px;
}

.lathe-cam-cad-heading {
  gap: 8px;
}

.lathe-cam-cad-heading strong {
  font-size: 12px;
}

.lathe-cam-cad-heading small,
.lathe-cam-cad-note {
  font-size: 10px;
}

.lathe-cam-cad-fields {
  grid-template-columns: minmax(140px, 1.1fr) minmax(200px, 1.5fr) minmax(74px, .55fr) minmax(74px, .55fr);
  gap: 7px;
  margin-top: 8px;
}

.lathe-cam-cad-list {
  max-height: 82px;
  gap: 5px;
  margin-top: 6px;
}

.lathe-cam-cad-list-item {
  padding: 6px 7px;
}

.lathe-cam-toolpath-capability {
  margin: 9px 0 11px;
  padding: 9px 10px;
}

.lathe-cam-toolpath-checks {
  gap: 4px 6px;
  margin-top: 7px;
}

.lathe-cam-toolpath-check {
  padding: 5px 6px;
}

@media (max-width: 920px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    overflow: visible;
  }

  .lathe-cam-gang-primary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lathe-cam-gang-assembly-field {
    grid-column: 1 / -1;
  }
}

/* Model cards now carry a compact visual reference and explicit adaptation
   requirements.  The thumbnail is a supplied reference image when present,
   otherwise a deterministic outline preview from the CAD/parameter geometry. */
.lathe-cam-model-catalog .lathe-cam-insert-catalog-identity {
  grid-template-columns: 86px minmax(0, 1fr);
  align-items: center;
  column-gap: 9px;
}

.lathe-cam-model-catalog .lathe-cam-model-catalog-reference {
  width: 86px;
  height: 54px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(143, 166, 177, .38);
  border-radius: 4px;
  background: #111a20;
  grid-column: 1;
  grid-row: 1 / span 2;
}

.lathe-cam-model-catalog-reference canvas,
.lathe-cam-model-catalog-reference img {
  width: 86px;
  height: 54px;
  display: block;
  object-fit: contain;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-identity-line,
.lathe-cam-model-catalog .lathe-cam-insert-catalog-identity > small {
  grid-column: 2;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-adaptation {
  display: -webkit-box;
  max-width: 100%;
  margin-top: 4px;
  overflow: hidden;
  color: #c4d2d8;
  font-size: 9px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

@media (max-width: 920px) {
  .lathe-cam-model-catalog .lathe-cam-insert-catalog-identity {
    grid-template-columns: 74px minmax(0, 1fr);
  }

  .lathe-cam-model-catalog .lathe-cam-model-catalog-reference,
  .lathe-cam-model-catalog-reference canvas,
  .lathe-cam-model-catalog-reference img {
    width: 74px;
    height: 48px;
  }
}

@media (max-width: 760px) {
  .lathe-cam-model-catalog .lathe-cam-insert-catalog-identity {
    grid-template-columns: 68px minmax(0, 1fr);
    column-gap: 7px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-catalog-reference,
  .lathe-cam-model-catalog-reference canvas,
  .lathe-cam-model-catalog-reference img {
    width: 68px;
    height: 44px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-adaptation {
    font-size: 8px;
  }
}

@media (max-width: 760px) {
  .lathe-cam-tool-library-dialog {
    width: calc(100vw - 12px);
    height: calc(100dvh - 12px);
    max-height: none;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    max-height: 40vh;
    overflow-y: auto;
    padding: 9px 10px 7px;
  }

  #latheCamGangLayoutCanvas {
    height: 122px;
  }

  .lathe-cam-tool-library-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(154px, 28vh) minmax(0, 1fr);
  }

  .lathe-cam-tool-form {
    padding: 12px 11px 0;
  }

  .lathe-cam-tool-form-actions {
    margin-inline: -11px;
  }

  .lathe-cam-cad-fields {
    grid-template-columns: 1fr 1fr;
  }
}

/* Live toolpath feasibility report. Keep the dimensional checklist compact so
   it stays visible beside the tool editor on desktop and mobile. */
.lathe-cam-toolpath-capability {
  margin: 12px 0 14px;
  padding: 12px 13px;
  border: 1px solid rgba(123, 151, 165, .34);
  border-radius: 8px;
  background: rgba(16, 25, 31, .72);
}
.lathe-cam-toolpath-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.lathe-cam-toolpath-heading strong {
  display: block;
  color: #eef4f7;
  font-size: 13px;
}
.lathe-cam-toolpath-heading small,
.lathe-cam-toolpath-summary {
  display: block;
  margin: 4px 0 0;
  color: #91a3ad;
  font-size: 11px;
  line-height: 1.45;
}
.lathe-cam-toolpath-overall {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid rgba(235, 192, 87, .45);
  border-radius: 4px;
  color: #e8c86b;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}
.lathe-cam-toolpath-capability.is-pass {
  border-color: rgba(111, 220, 150, .45);
}
.lathe-cam-toolpath-capability.is-pass .lathe-cam-toolpath-overall {
  border-color: rgba(111, 220, 150, .55);
  color: #84dfa1;
}
.lathe-cam-toolpath-capability.is-fail {
  border-color: rgba(245, 112, 116, .5);
}
.lathe-cam-toolpath-capability.is-fail .lathe-cam-toolpath-overall {
  border-color: rgba(245, 112, 116, .6);
  color: #ff9a9f;
}
.lathe-cam-toolpath-checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 7px;
  margin-top: 9px;
}
.lathe-cam-toolpath-check {
  min-width: 0;
  display: grid;
  grid-template-columns: 7px minmax(0, auto) 1fr auto;
  align-items: baseline;
  gap: 6px;
  padding: 6px 7px;
  border: 1px solid rgba(116, 145, 158, .25);
  border-radius: 5px;
  background: rgba(28, 40, 47, .62);
}
.lathe-cam-toolpath-check-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d8bd71;
  box-shadow: 0 0 0 3px rgba(216, 189, 113, .12);
}
.lathe-cam-toolpath-check strong {
  color: #d9e3e7;
  font-size: 10px;
  line-height: 1.35;
  white-space: nowrap;
}
.lathe-cam-toolpath-check small {
  min-width: 0;
  overflow: hidden;
  color: #92a4ad;
  font-size: 10px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lathe-cam-toolpath-check em {
  color: #d8bd71;
  font-size: 9px;
  font-style: normal;
  font-weight: 750;
  letter-spacing: .03em;
}
.lathe-cam-toolpath-check.is-pass .lathe-cam-toolpath-check-dot {
  background: #84dfa1;
  box-shadow: 0 0 0 3px rgba(132, 223, 161, .12);
}
.lathe-cam-toolpath-check.is-pass em { color: #84dfa1; }
.lathe-cam-toolpath-check.is-fail .lathe-cam-toolpath-check-dot {
  background: #ff737c;
  box-shadow: 0 0 0 3px rgba(255, 115, 124, .12);
}
.lathe-cam-toolpath-check.is-fail em { color: #ff9a9f; }
@media (max-width: 760px) {
  .lathe-cam-toolpath-checks { grid-template-columns: 1fr; }
  .lathe-cam-toolpath-check { grid-template-columns: 7px minmax(0, auto) 1fr; }
  .lathe-cam-toolpath-check em { grid-column: 2 / -1; }
}

/* Three-part assembly inspection is intentionally a separate workspace from
   the machining preview. It keeps the insert, holder and gang fixture in one
   physical coordinate system while leaving the owner-only CAD editor intact. */
.lathe-cam-assembly-launcher {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
.lathe-cam-cad-heading > .lathe-cam-assembly-launcher {
  flex: 0 0 auto;
  margin-top: 0;
  margin-left: auto;
}
.lathe-cam-tool-form-heading > .lathe-cam-assembly-launcher {
  flex: 0 0 auto;
  margin-top: 0;
  margin-left: auto;
}
.lathe-cam-assembly-launcher .button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 11px;
}
#latheCamCadManager ~ .lathe-cam-tool-preview > .lathe-cam-assembly-launcher {
  display: none;
}
.lathe-cam-assembly-backdrop {
  z-index: 1200;
  background: rgba(4, 8, 10, .68);
}
.lathe-cam-assembly-dialog {
  width: min(1080px, calc(100vw - 36px));
  max-height: min(860px, calc(100vh - 36px));
  overflow: auto;
}
.lathe-cam-assembly-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.lathe-cam-assembly-fields label {
  display: grid;
  gap: 5px;
  min-width: 0;
}
.lathe-cam-assembly-fields label > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.lathe-cam-assembly-fields select {
  width: 100%;
  min-height: 34px;
  box-sizing: border-box;
}
.lathe-cam-assembly-workspace {
  position: relative;
  min-height: 430px;
  background: #0e151a;
}
.lathe-cam-assembly-workspace canvas {
  display: block;
  width: 100%;
  height: min(56vh, 560px);
  min-height: 360px;
  touch-action: none;
  cursor: grab;
}
.lathe-cam-assembly-workspace canvas.is-dragging { cursor: grabbing; }
.lathe-cam-assembly-status {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 14px;
  padding: 9px 11px;
  border: 1px solid rgba(134, 162, 174, .34);
  border-radius: 5px;
  color: #c1d0d6;
  background: rgba(10, 17, 21, .86);
  font-size: 10px;
  line-height: 1.35;
  pointer-events: none;
}
.lathe-cam-assembly-status strong { color: #e9f1f4; font-size: 11px; }
.lathe-cam-assembly-status span { color: #9fb1b9; }
.lathe-cam-assembly-status.is-ready { border-color: rgba(111, 220, 150, .48); }
.lathe-cam-assembly-status.is-ready strong { color: #7fe19b; }
.lathe-cam-assembly-status.is-warning { border-color: rgba(232, 200, 107, .54); }
.lathe-cam-assembly-status.is-warning strong { color: #e8c86b; }
.lathe-cam-assembly-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
}
.lathe-cam-assembly-actions .button {
  min-height: 32px;
  padding: 0 11px;
  font-size: 11px;
}
@media (max-width: 760px) {
  .lathe-cam-assembly-fields { grid-template-columns: 1fr; }
  .lathe-cam-assembly-dialog { width: calc(100vw - 20px); }
  .lathe-cam-assembly-workspace canvas { min-height: 300px; height: 56vh; }
  .lathe-cam-assembly-actions { flex-wrap: wrap; }
}

.lathe-cam-insert-catalog-identity-line {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.lathe-cam-insert-catalog-kind {
  min-width: 34px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-raised) 82%, transparent);
  font-size: 8px;
  font-weight: 750;
  line-height: 1;
}

.lathe-cam-insert-catalog-result[data-catalog-kind="holder"] .lathe-cam-insert-catalog-kind {
  color: var(--ink);
  background: color-mix(in srgb, var(--line-strong) 20%, transparent);
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-model {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 920px) {
  .lathe-cam-model-catalog .lathe-cam-insert-catalog-heading {
    grid-template-columns: 1fr;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-specs {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (max-width: 760px) {
  .lathe-cam-model-pair-copy {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .lathe-cam-model-pair-copy small {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .lathe-cam-model-catalog-modes {
    overflow-x: auto;
  }

  .lathe-cam-model-catalog-modes button {
    min-height: 44px;
    flex: 0 0 auto;
    padding-inline: 12px;
  }

  .lathe-cam-model-catalog-modes .lathe-cam-model-catalog-confirm {
    margin-left: 0;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
    max-height: 300px;
  }
}

/* Tool-library density pass: keep one predictable scroll region and reserve
   the first viewport for the selected tool rather than the entire catalog. */
.lathe-cam-tool-library-dialog {
  width: min(1240px, calc(100vw - 28px));
  height: min(900px, calc(100dvh - 28px));
  max-height: calc(100dvh - 28px);
  grid-template-rows: auto minmax(190px, 230px) minmax(0, 1fr);
  overflow: hidden !important;
}
.lathe-cam-gang-config {
  grid-template-rows: auto 130px auto auto;
  gap: 7px;
  padding: 10px 16px 9px;
  overflow: hidden;
}
#latheCamGangLayoutCanvas {
  height: 130px;
}
.lathe-cam-gang-config-heading { gap: 10px; }
.lathe-cam-gang-config-heading strong { font-size: 12px; }
.lathe-cam-gang-config-heading small { font-size: 8px; }
.lathe-cam-gang-primary-grid,
.lathe-cam-gang-config-grid { gap: 7px 8px; }
.lathe-cam-gang-primary-grid .field small,
.lathe-cam-gang-assembly-field small,
.lathe-cam-gang-field-hint { display: none; }
.lathe-cam-gang-layout-summary { min-height: 16px; font-size: 8px; }
.lathe-cam-tool-library-layout {
  min-height: 0;
  overflow: hidden;
}
.lathe-cam-tool-library-sidebar {
  min-height: 0;
  overflow: hidden;
}
.lathe-cam-tool-library-sidebar-heading {
  min-height: 48px;
  padding: 8px 12px;
}
.lathe-cam-tool-library-list { padding: 8px; gap: 5px; }
.lathe-cam-tool-library-item { min-height: 56px; padding: 6px 8px; }
.lathe-cam-tool-form {
  min-height: 0;
  padding: 14px 16px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.lathe-cam-tool-form-heading { margin-bottom: 10px; }
.lathe-cam-tool-form-heading strong { font-size: 14px; }
.lathe-cam-insert-catalog { margin-bottom: 10px; }
.lathe-cam-insert-catalog-heading { padding: 8px 10px; }
.lathe-cam-insert-catalog-results {
  min-height: 62px;
  max-height: 148px;
  padding: 5px;
}
.lathe-cam-insert-catalog-result {
  min-height: 44px;
  padding: 5px 7px;
}
.lathe-cam-model-catalog {
  min-height: 0;
  max-height: 190px;
  overflow: hidden;
}
.lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
  min-height: 58px;
  max-height: 112px;
}
.lathe-cam-cad-manager {
  margin: 8px 0 10px;
  padding: 10px;
}
.lathe-cam-cad-manager.is-collapsed > :not(.lathe-cam-cad-heading) {
  display: none;
}
.lathe-cam-cad-heading { flex-wrap: wrap; }
.lathe-cam-cad-heading > div:first-child { min-width: 180px; }
.lathe-cam-cad-toggle {
  flex: 0 0 auto;
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid rgba(128, 157, 168, .34);
  border-radius: 4px;
  color: #b6c6cc;
  background: rgba(25, 36, 42, .82);
  font-size: 10px;
  cursor: pointer;
}
.lathe-cam-cad-toggle:hover {
  border-color: rgba(126, 221, 155, .6);
  color: #e4edf0;
}
.lathe-cam-cad-note { display: none; }
.lathe-cam-cad-fields { margin-top: 8px; gap: 7px; }
.lathe-cam-cad-actions { margin-top: 8px; gap: 6px; }
.lathe-cam-cad-list { max-height: 82px; }
.lathe-cam-tool-preview { margin-bottom: 10px; }
.lathe-cam-tool-preview canvas { height: 98px; }
.lathe-cam-tool-preview > div { padding: 10px; gap: 5px; }
.lathe-cam-tool-form-grid { gap: 10px 10px; }
.lathe-cam-tool-form-note { margin-top: 10px; padding: 8px 10px; }
.lathe-cam-tool-form-actions { margin-inline: -16px; }

@media (max-width: 760px) {
  .lathe-cam-tool-library-dialog {
    width: calc(100vw - 12px);
    height: calc(100dvh - 12px);
    max-height: none;
    grid-template-rows: auto minmax(164px, 34vh) minmax(0, 1fr);
  }
  .lathe-cam-gang-config {
    max-height: none;
    grid-template-rows: auto 108px auto auto;
    padding: 8px 10px;
  }
  #latheCamGangLayoutCanvas { height: 108px; }
  .lathe-cam-tool-form { padding-inline: 12px; }
  .lathe-cam-tool-form-actions { margin-inline: -12px; }
  .lathe-cam-insert-catalog-results { max-height: 132px; }
}

/* Low-frequency CAD maintenance is a collapsible secondary section.  The
   summary remains visible in read-only mode so permissions are never hidden. */
.lathe-cam-tool-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--input-bg) 72%, transparent);
}

.lathe-cam-cad-details {
  margin: 8px 0 10px;
  overflow: hidden;
}

.lathe-cam-cad-details > summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.lathe-cam-cad-details > summary::-webkit-details-marker { display: none; }

.lathe-cam-cad-details > summary::before {
  width: 0;
  height: 0;
  margin-right: 1px;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid var(--muted);
  content: "";
  transition: transform 140ms ease;
}

.lathe-cam-cad-details[open] > summary::before {
  transform: rotate(90deg);
}

.lathe-cam-cad-details > summary .lathe-cam-tool-section-title {
  min-width: 0;
  flex: 1 1 auto;
}

.lathe-cam-cad-details > summary small {
  flex: 0 0 auto;
  padding: 3px 6px;
  border: 1px solid rgba(235, 192, 87, .4);
  border-radius: 4px;
  color: #e8c86b;
  font-size: 9px;
  font-weight: 650;
  white-space: nowrap;
}

.lathe-cam-cad-details > summary small.is-owner {
  border-color: rgba(111, 220, 150, .45);
  color: #7fe19b;
}

.lathe-cam-cad-details > summary small.is-readonly {
  color: #e8c86b;
}
.lathe-cam-cad-assembly-button {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid rgba(126, 221, 155, .45);
  border-radius: 4px;
  color: #9ce8b0;
  background: rgba(47, 102, 68, .2);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}
.lathe-cam-cad-details > summary .lathe-cam-cad-assembly-button { display: none; }
.lathe-cam-cad-assembly-button:hover {
  border-color: rgba(126, 221, 155, .8);
  background: rgba(47, 102, 68, .34);
}

.lathe-cam-cad-details[open] > summary {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-soft) 58%, transparent);
}

.lathe-cam-cad-details #latheCamCadManager {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.lathe-cam-cad-details #latheCamCadManager .lathe-cam-cad-heading {
  display: none;
}

.lathe-cam-cad-details #latheCamCadManager .lathe-cam-cad-note {
  margin-top: 0;
}

.lathe-cam-cad-details > summary:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 68%, transparent);
  outline-offset: -2px;
}

@media (max-width: 760px) {
  .lathe-cam-cad-details > summary {
    min-height: 42px;
    padding-inline: 9px;
  }
}

/* The compact preview still needs one complete row for the primary gang
   dimensions.  Give it a stable track so labels and inputs are not clipped
   at the boundary with the tool editor. */
@media (min-width: 761px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto minmax(278px, 296px) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-rows: auto 112px auto auto;
    overflow: hidden;
  }

  #latheCamGangLayoutCanvas {
    height: 112px;
  }
}

/* The dialog is fixed to the viewport; prevent the host page from adding a
   second full-page scrollbar while it is open. */
body:has(#latheCamToolLibraryDialog.is-open),
html:has(#latheCamToolLibraryDialog.is-open) {
  overflow: hidden !important;
}

@media (max-width: 760px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto minmax(440px, 52vh) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-rows: auto 108px auto auto;
    max-height: 52vh;
    overflow-y: auto;
  }

  #latheCamGangLayoutCanvas {
    height: 108px;
  }
}

/* Model catalog readability pass.  The catalog is the operator's lookup
   surface, so it gets a real viewport instead of the old 112px density cap.
   Results remain inside the form's scroll flow and never cover the geometry
   fields or sticky actions. */
.lathe-cam-model-catalog {
  min-height: 360px;
  max-height: none;
  overflow: visible;
  margin-bottom: 14px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-heading {
  min-height: 66px;
  grid-template-columns: minmax(240px, .85fr) minmax(360px, 1.15fr);
  gap: 14px;
  padding: 12px 14px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-heading strong {
  font-size: 13px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-heading small {
  font-size: 10px;
  white-space: normal;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-search input {
  min-height: 42px;
  font-size: 11px;
}

.lathe-cam-model-catalog .lathe-cam-model-pair-status {
  min-height: 58px;
  padding: 11px 13px;
}

.lathe-cam-model-catalog .lathe-cam-model-pair-copy {
  align-items: flex-start;
  flex-direction: column;
  gap: 3px;
}

.lathe-cam-model-catalog .lathe-cam-model-pair-copy strong {
  font-size: 11px;
}

.lathe-cam-model-catalog .lathe-cam-model-pair-copy small {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  font-size: 10px;
}

.lathe-cam-model-catalog .lathe-cam-model-catalog-modes {
  min-height: 44px;
  padding: 6px 9px;
}

.lathe-cam-model-catalog .lathe-cam-model-catalog-modes button {
  min-height: 32px;
  padding-inline: 12px;
  font-size: 10px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
  min-height: 244px;
  max-height: 344px;
  gap: 6px;
  padding: 8px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
  min-height: 82px;
  grid-template-columns: minmax(200px, .9fr) minmax(320px, 1.45fr) minmax(210px, .95fr);
  align-items: start;
  gap: 10px 13px;
  padding: 10px 11px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-identity,
.lathe-cam-model-catalog .lathe-cam-insert-catalog-fit {
  align-self: start;
  gap: 5px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-identity strong {
  font-size: 12px;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-identity small,
.lathe-cam-model-catalog .lathe-cam-insert-catalog-fit small {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  font-size: 10px;
  line-height: 1.45;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-specs {
  align-self: start;
  gap: 7px 14px;
  font-size: 10px;
  line-height: 1.5;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-specs > span {
  white-space: normal;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-fit {
  justify-items: start;
  text-align: left;
}

.lathe-cam-model-catalog .lathe-cam-insert-catalog-status {
  min-height: 27px;
  padding: 5px 9px;
  font-size: 10px;
}

@media (max-width: 1120px) and (min-width: 761px) {
  .lathe-cam-model-catalog {
    min-height: 340px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-heading {
    grid-template-columns: minmax(200px, .9fr) minmax(260px, 1.1fr);
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 96px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-specs {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

@media (max-width: 760px) {
  .lathe-cam-model-catalog {
    min-height: 0;
    max-height: min(440px, 58vh);
    overflow: hidden;
    margin-bottom: 11px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-heading {
    min-height: 0;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 11px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-search input {
    min-height: 44px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-pair-status {
    min-height: 62px;
    padding: 10px 11px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-catalog-modes {
    min-height: 46px;
    overflow-x: auto;
    padding: 6px 8px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-catalog-modes button {
    flex: 0 0 auto;
    min-height: 34px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
    min-height: 220px;
    max-height: 300px;
    padding: 7px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
    min-height: 104px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px 9px;
    padding: 9px 10px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-specs {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-fit {
    justify-items: end;
    text-align: right;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-fit small {
    max-width: 180px;
  }
}

/* Operator layout: keep the gang preview and its dimensions side by side so
   the model catalogue gets the majority of the lower viewport.  The previous
   stacked rows consumed almost 300px before the lookup panel even started. */
@media (min-width: 1000px) {
  .lathe-cam-tool-library-dialog {
    width: min(1420px, calc(100vw - 24px));
    max-width: 1420px;
    height: min(960px, calc(100dvh - 20px));
    max-height: calc(100dvh - 20px);
    grid-template-rows: auto minmax(208px, 228px) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-columns: minmax(0, 1.45fr) minmax(360px, .85fr);
    grid-template-rows: auto minmax(112px, 1fr) auto;
    gap: 7px 12px;
    padding: 9px 16px 8px;
    overflow: hidden;
  }

  .lathe-cam-gang-config-heading {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  #latheCamGangLayoutCanvas {
    grid-column: 1;
    grid-row: 2;
    height: 112px;
    align-self: stretch;
  }

  .lathe-cam-gang-primary-grid {
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: minmax(150px, 1.55fr) repeat(3, minmax(62px, 1fr));
    align-content: start;
    gap: 6px;
  }

  .lathe-cam-gang-primary-grid .lathe-cam-confirm-field {
    grid-column: 1 / -1;
    min-height: 27px;
    padding: 5px 7px;
    align-items: center;
  }

  .lathe-cam-gang-advanced {
    grid-column: 1;
    grid-row: 3;
  }

  .lathe-cam-gang-layout-summary {
    grid-column: 2;
    grid-row: 3;
    align-self: center;
  }

  /* The model query is the frequent workflow. Put it before the low-frequency
     CAD maintenance block so the first editor viewport contains real results. */
  .lathe-cam-tool-form-heading { order: 1; }
  .lathe-cam-tool-form-error { order: 2; }
  .lathe-cam-model-catalog { order: 3; }
  .lathe-cam-cad-manager { order: 4; }
  .lathe-cam-cad-details { order: 4; }
  .lathe-cam-tool-preview { order: 5; }
  .lathe-cam-tool-form-grid { order: 6; }
  .lathe-cam-tool-collision-state { order: 7; }
  .lathe-cam-toolpath-capability { order: 8; }
  .lathe-cam-tool-form-note { order: 9; }
  .lathe-cam-tool-form-actions { order: 10; }

  .lathe-cam-model-catalog {
    flex: 0 0 auto;
    min-height: 350px;
  }
}

@media (min-width: 761px) and (max-width: 999px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto minmax(230px, 250px) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-rows: auto 94px auto auto;
  }

  #latheCamGangLayoutCanvas { height: 94px; }
  .lathe-cam-tool-form-heading { order: 1; }
  .lathe-cam-tool-form-error { order: 2; }
  .lathe-cam-model-catalog { order: 3; }
  .lathe-cam-cad-manager { order: 4; }
  .lathe-cam-cad-details { order: 4; }
  .lathe-cam-tool-preview { order: 5; }
  .lathe-cam-tool-form-grid { order: 6; }
  .lathe-cam-tool-collision-state { order: 7; }
  .lathe-cam-toolpath-capability { order: 8; }
  .lathe-cam-tool-form-note { order: 9; }
  .lathe-cam-tool-form-actions { order: 10; }
}

@media (max-width: 760px) {
  .lathe-cam-tool-form-heading { order: 1; }
  .lathe-cam-tool-form-error { order: 2; }
  .lathe-cam-model-catalog { order: 3; }
  .lathe-cam-cad-manager { order: 4; }
  .lathe-cam-cad-details { order: 4; }
  .lathe-cam-tool-preview { order: 5; }
  .lathe-cam-tool-form-grid { order: 6; }
  .lathe-cam-tool-collision-state { order: 7; }
  .lathe-cam-toolpath-capability { order: 8; }
  .lathe-cam-tool-form-note { order: 9; }
  .lathe-cam-tool-form-actions { order: 10; }
}


/* Final guardrail for the expanded catalogue: reserve its complete header
   stack and give only the result list an internal scrollbar.  This prevents
   cards from flowing over CAD controls or the dimensional editor. */
@media (min-width: 761px) {
  .lathe-cam-model-catalog {
    flex: 0 0 420px;
    height: 420px;
    min-height: 420px;
    max-height: 420px;
    overflow: hidden;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
    height: 246px;
    min-height: 246px;
    max-height: 246px;
    overflow-y: auto;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
    min-height: 110px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-fit small {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .lathe-cam-cad-manager {
    position: relative;
    z-index: 0;
    flex: 0 0 auto;
  }
}

@media (max-width: 760px) {
  .lathe-cam-model-catalog {
    max-height: min(430px, 58vh);
    overflow: hidden;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
    max-height: 286px;
    overflow-y: auto;
  }
}

/* In the embedded QA page the usable height can be only a few hundred
   pixels.  Reclaim the stacked gang controls at that breakpoint so the first
   catalogue result remains on-screen instead of being hidden below the fold. */
@media (min-width: 1000px) and (max-height: 720px) {
  .lathe-cam-tool-library-dialog {
    height: calc(100dvh - 12px);
    max-height: none;
    grid-template-rows: auto minmax(88px, 98px) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 5px 10px;
    padding: 7px 12px 6px;
  }

  .lathe-cam-gang-config-heading small,
  .lathe-cam-gang-state,
  .lathe-cam-gang-primary-grid .field small,
  .lathe-cam-gang-field-hint {
    display: none;
  }

  #latheCamGangLayoutCanvas { display: none; }

  .lathe-cam-gang-primary-grid {
    grid-column: 1;
    grid-row: 2;
    grid-template-columns: minmax(220px, 1.7fr) repeat(3, minmax(78px, 1fr)) minmax(150px, 1.15fr);
    gap: 4px;
  }

  .lathe-cam-gang-primary-grid .field input,
  .lathe-cam-gang-primary-grid .field select {
    min-height: 28px;
  }

  .lathe-cam-gang-primary-grid .lathe-cam-confirm-field {
    grid-column: auto;
    min-height: 26px;
    padding: 3px 5px;
    font-size: 8px;
  }

  .lathe-cam-gang-advanced,
  .lathe-cam-gang-layout-summary { display: none; }

  .lathe-cam-gang-config-heading { grid-column: 1; grid-row: 1; }

  .lathe-cam-tool-form {
    padding-top: 8px;
  }

  .lathe-cam-tool-form-heading {
    margin-bottom: 6px;
  }

  .lathe-cam-model-catalog {
    flex-basis: 340px;
    height: 340px;
    min-height: 340px;
    max-height: 340px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-heading {
    min-height: 42px;
    padding-block: 5px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-pair-status {
    min-height: 28px;
    padding-block: 3px 4px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-pair-copy {
    flex-direction: row;
    align-items: center;
    gap: 7px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-pair-copy strong,
  .lathe-cam-model-catalog .lathe-cam-model-pair-copy small {
    font-size: 8px;
    line-height: 1.2;
  }

  .lathe-cam-model-catalog .lathe-cam-model-catalog-modes {
    min-height: 26px;
    padding-block: 2px;
  }

  .lathe-cam-model-catalog .lathe-cam-model-catalog-modes button {
    min-height: 21px;
    padding-inline: 8px;
    font-size: 8px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-results {
    height: 214px;
    min-height: 214px;
    max-height: 214px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-result {
    min-height: 82px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-fit small {
    -webkit-line-clamp: 1;
  }

  .lathe-cam-tool-form-actions {
    padding: 8px 12px 9px;
    gap: 6px;
    margin-inline: -12px;
  }
}

/* Keep the accessible search name available to assistive technology without
   letting it become a second visible label beside the input. */
.lathe-cam-insert-catalog-search > .sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* The physical gang plate is the operator's primary spatial reference.  Give
   it enough vertical room to read the real 200 mm station direction while
   keeping the catalogue below independently scrollable.  The short-window
   rule above intentionally remains compact and hides the canvas when there is
   not enough vertical space for a useful drawing. */
@media (min-width: 1000px) and (min-height: 721px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto minmax(340px, 360px) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-rows: auto minmax(230px, 1fr) auto;
    padding: 12px 16px 10px;
  }

  #latheCamGangLayoutCanvas {
    height: 230px;
  }
}

/* Keep the same two-column relationship on a medium desktop window.  The
   former single-column fallback put the primary fields below a short canvas,
   where the editor row could cover them before they were usable. */
@media (min-width: 761px) and (max-width: 999px) and (min-height: 721px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto minmax(290px, 310px) minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-columns: minmax(0, 1.35fr) minmax(330px, .95fr);
    grid-template-rows: auto minmax(180px, 1fr) auto;
    gap: 7px 10px;
    padding: 10px 12px 8px;
    overflow: hidden;
  }

  .lathe-cam-gang-config-heading {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  #latheCamGangLayoutCanvas {
    grid-column: 1;
    grid-row: 2;
    height: 180px;
    align-self: stretch;
  }

  .lathe-cam-gang-primary-grid {
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: minmax(140px, 1.35fr) repeat(3, minmax(54px, 1fr));
    align-content: start;
    gap: 6px;
  }

  .lathe-cam-gang-primary-grid .lathe-cam-confirm-field {
    grid-column: 1 / -1;
    min-height: 27px;
    padding: 5px 7px;
    align-items: center;
  }

  .lathe-cam-gang-advanced {
    grid-column: 1;
    grid-row: 3;
  }

  .lathe-cam-gang-layout-summary {
    grid-column: 2;
    grid-row: 3;
    align-self: center;
  }
}

/* -------------------------------------------------------------------------
   Tool settings workspace
   The physical gang setup and station navigation form the left workspace;
   model lookup and the editable tool definition use the wider right side.
   Both columns scroll independently so measured dimensions can fully expand.
   ------------------------------------------------------------------------- */
.lathe-cam-tool-library-left {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-soft, #141d22) 94%, #0b1216);
  box-sizing: border-box;
  contain: inline-size;
}

.lathe-cam-tool-library-left > *,
.lathe-cam-tool-library-left .lathe-cam-gang-primary-grid,
.lathe-cam-tool-library-left .lathe-cam-gang-advanced,
.lathe-cam-tool-library-left .lathe-cam-gang-config-grid {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

@media (min-width: 1180px) {
  .lathe-cam-tool-library-dialog {
    width: min(1760px, calc(100vw - 20px));
    max-width: 1760px;
    height: min(1080px, calc(100dvh - 16px));
    max-height: calc(100dvh - 16px);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .lathe-cam-tool-library-layout {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(450px, 500px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }

  .lathe-cam-tool-library-left {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  .lathe-cam-gang-config {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 190px auto auto auto;
    gap: 10px;
    padding: 13px 14px 14px;
    overflow: visible;
    border-bottom: 1px solid var(--line);
    box-sizing: border-box;
  }

  .lathe-cam-gang-config-heading,
  #latheCamGangLayoutCanvas,
  .lathe-cam-gang-primary-grid,
  .lathe-cam-gang-advanced,
  .lathe-cam-gang-layout-summary {
    grid-column: 1;
  }

  .lathe-cam-gang-config-heading { grid-row: 1; }
  #latheCamGangLayoutCanvas {
    grid-row: 2;
    display: block;
    height: 190px;
  }

  .lathe-cam-gang-primary-grid {
    grid-row: 3;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 8px;
  }

  .lathe-cam-gang-primary-grid .lathe-cam-gang-assembly-field,
  .lathe-cam-gang-primary-grid .lathe-cam-confirm-field {
    grid-column: 1 / -1;
  }

  .lathe-cam-gang-primary-grid .field small,
  .lathe-cam-gang-assembly-field small,
  .lathe-cam-gang-field-hint {
    display: block;
  }

  .lathe-cam-gang-advanced {
    grid-row: 4;
    display: block !important;
    overflow: visible;
  }

  .lathe-cam-gang-advanced .lathe-cam-gang-config-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    padding: 12px;
  }

  .lathe-cam-gang-layout-summary {
    grid-row: 5;
    display: block !important;
    min-height: 26px;
    padding: 6px 8px;
    font-size: 9px;
    line-height: 1.45;
  }

  .lathe-cam-tool-library-sidebar {
    flex: 1 0 280px;
    min-height: 280px;
    display: grid;
    grid-template-rows: auto minmax(220px, 1fr);
    overflow: visible;
    border-right: 0;
  }

  .lathe-cam-tool-library-list {
    min-height: 220px;
    overflow-y: visible;
  }

  .lathe-cam-tool-form {
    min-width: 0;
    min-height: 0;
    padding: 16px 18px 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
  }

  .lathe-cam-tool-form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 11px 12px;
  }

  .lathe-cam-tool-form-wide,
  .lathe-cam-tool-angle-field {
    grid-column: 1 / -1;
  }

  .lathe-cam-tool-preview {
    grid-template-columns: minmax(0, 1fr) 180px;
  }

  .lathe-cam-tool-preview canvas {
    height: 132px;
  }

  .lathe-cam-model-catalog .lathe-cam-insert-catalog-heading {
    grid-template-columns: minmax(250px, .8fr) minmax(360px, 1.2fr);
  }

  .lathe-cam-tool-form-actions {
    margin-inline: -18px;
    padding-inline: 18px;
  }
}

@media (min-width: 761px) and (max-width: 1179px) {
  .lathe-cam-tool-library-dialog {
    width: calc(100vw - 18px);
    max-width: none;
    height: calc(100dvh - 16px);
    max-height: none;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .lathe-cam-tool-library-layout {
    grid-template-columns: minmax(350px, 42%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .lathe-cam-tool-library-left {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .lathe-cam-gang-config {
    max-height: none;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 150px auto auto auto;
    padding: 10px 12px 12px;
    overflow: visible;
    border-bottom: 1px solid var(--line);
  }

  .lathe-cam-gang-config-heading,
  #latheCamGangLayoutCanvas,
  .lathe-cam-gang-primary-grid,
  .lathe-cam-gang-advanced,
  .lathe-cam-gang-layout-summary {
    grid-column: 1;
  }

  .lathe-cam-gang-config-heading { grid-row: 1; }
  #latheCamGangLayoutCanvas {
    grid-row: 2;
    display: block;
    height: 150px;
  }
  .lathe-cam-gang-primary-grid { grid-row: 3; }
  .lathe-cam-gang-advanced { grid-row: 4; }
  .lathe-cam-gang-layout-summary { grid-row: 5; }

  .lathe-cam-gang-primary-grid,
  .lathe-cam-gang-advanced .lathe-cam-gang-config-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lathe-cam-gang-primary-grid .lathe-cam-gang-assembly-field,
  .lathe-cam-gang-primary-grid .lathe-cam-confirm-field {
    grid-column: 1 / -1;
  }

  .lathe-cam-gang-advanced,
  .lathe-cam-gang-layout-summary {
    display: block !important;
  }

  .lathe-cam-tool-library-sidebar {
    min-height: 260px;
    border-right: 0;
  }

  .lathe-cam-tool-form {
    min-height: 0;
    overflow-y: auto;
  }
}

/* A short but wide desktop window still benefits from the physical layout
   preview.  Keep the row explicit so the hidden-canvas rule from the compact
   preset cannot leave an empty 150px track above the editor. */
@media (min-width: 1000px) and (max-height: 720px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .lathe-cam-gang-config {
    grid-template-rows: auto 150px auto auto auto;
  }

  #latheCamGangLayoutCanvas {
    display: block;
    height: 150px;
  }
}

@media (max-width: 760px) {
  .lathe-cam-tool-library-dialog {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .lathe-cam-tool-library-layout {
    display: block;
    overflow-y: auto;
  }

  .lathe-cam-tool-library-left {
    overflow: visible;
    border-right: 0;
  }

  .lathe-cam-gang-config {
    max-height: none;
    overflow: visible;
  }

  .lathe-cam-gang-advanced,
  .lathe-cam-gang-layout-summary {
    display: block !important;
  }

  .lathe-cam-tool-library-sidebar {
    min-height: 300px;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

.lathe-cam-tool-form {
    overflow: visible;
  }
}

/* Keep the first-run path visible without hiding the expert controls. */
.lathe-cam-beginner-guide {
  margin: 0 0 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface-soft));
  overflow: hidden;
}

.lathe-cam-beginner-guide > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  list-style: none;
}

.lathe-cam-beginner-guide > summary::-webkit-details-marker { display: none; }

.lathe-cam-beginner-guide > summary > svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  color: var(--accent);
}

.lathe-cam-beginner-guide > summary > span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.lathe-cam-beginner-guide > summary strong { color: var(--text); font-size: 13px; }
.lathe-cam-beginner-guide > summary small { color: var(--muted); font-size: 11px; }

.lathe-cam-beginner-steps {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0 14px 12px;
  list-style: none;
  counter-reset: beginner-step;
}

.lathe-cam-beginner-steps li {
  position: relative;
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px 4px 34px;
  border-top: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
}

.lathe-cam-beginner-steps li::before {
  counter-increment: beginner-step;
  content: counter(beginner-step);
  position: absolute;
  top: 11px;
  left: 0;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 48%, var(--line));
  border-radius: 50%;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.lathe-cam-beginner-steps strong { color: var(--text); font-size: 12px; }
.lathe-cam-beginner-steps span,
.lathe-cam-beginner-safety { color: var(--muted); font-size: 11px; line-height: 1.55; }

.lathe-cam-beginner-safety {
  margin: 0;
  padding: 9px 14px 12px;
  border-top: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
}

@media (max-width: 1080px) {
  .lathe-cam-beginner-steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .lathe-cam-beginner-steps { grid-template-columns: 1fr; }
  .lathe-cam-beginner-steps li { padding-right: 0; }
}

/* Keep the bulk toolbar in its own row after all responsive sidebar rules. */
.lathe-cam-tool-library-sidebar {
  grid-template-rows: auto auto minmax(0, 1fr);
}

