*, *::before, *::after { box-sizing: border-box; }

body {
  font-size: 13px;
  background: #e8e8e8;
  margin: 0;
  overflow: hidden;
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.label-xs  { font-size: 11px; color: #555; display: block; margin-bottom: 1px; }
.label-xs.label-inline { display: inline; margin-bottom: 0; }
.label-sm  { font-size: 12px; color: #333; }
.btn-xs    { font-size: 11px; padding: 2px 7px; line-height: 1.4; border-radius: 3px; }
.form-control-xs  { font-size: 12px; padding: 2px 6px; height: 26px; }
.form-select-xs   { font-size: 12px; padding: 2px 22px 2px 6px; height: 26px; }

/* ── App layout ──────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════════════════
   LEFT PANEL
══════════════════════════════════════════════════════════════════════════ */
.panel-left {
  width: 250px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #ccc;
  flex-shrink: 0;
}

/* ── Left tab nav ──────────────────────────────────────────────────────── */
.left-tab-nav {
  display: flex;
  border-bottom: 1px solid #ddd;
  background: #f5f5f5;
  flex-shrink: 0;
}
.left-tab {
  flex: 1;
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  cursor: pointer;
  color: #666;
  transition: color .12s, border-color .12s;
}
.left-tab:hover  { color: #333; background: #ececec; }
.left-tab.active { color: #0d6efd; border-bottom-color: #0d6efd; background: #fff; }

/* ── Left panes ────────────────────────────────────────────────────────── */
.left-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 8px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

/* Toolpath list */
.tp-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
}

.tp-list-footer {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 8px;
  background: #f5f5f5;
  border-top: 1px solid #ddd;
}

.tp-icon-btn {
  padding: 2px 7px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
}
.tp-icon-btn img {
  width: 18px;
  height: 18px;
  display: block;
  pointer-events: none;
}
.tp-icon-btn:disabled img {
  opacity: 0.45;
}
.tp-add-icons .tp-icon-btn {
  padding: 3px 8px;
}
.tp-footer-icon-actions {
  max-width: 100%;
}

/* Each toolpath row */
.tp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  user-select: none;
  min-width: 0;
  width: 100%;
}
.tp-row:hover   { background: #eef4ff; }
.tp-row.active  { background: #d0e4ff; }

.tp-type-icon {
  flex-shrink: 0;
  width: 16px; height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #5a6b80;
}
.tp-row.active .tp-type-icon { color: #1c4e8a; }
.tp-type-icon svg { display: block; }
/* Per-type accent so the icon also reads by color, not shape alone */
.tp-type-icon svg[data-tp-type="drill"]   { color: #c0392b; }
.tp-type-icon svg[data-tp-type="pocket"]  { color: #2e7d32; }
.tp-type-icon svg[data-tp-type="profile"] { color: #2b6cb0; }
.tp-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.2);
}
.tp-info {
  flex: 1;
  min-width: 0;
}
.tp-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tp-meta {
  font-size: 10px;
  color: #888;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tp-row-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #aaa;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.1s, color 0.1s;
}
.tp-row:hover .tp-row-delete { opacity: 1; }
.tp-row-delete:hover { color: #dc3545; }
.tp-arrows {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.tp-arrows button {
  font-size: 9px;
  padding: 0 3px;
  border: 1px solid #bbb;
  background: none;
  border-radius: 2px;
  cursor: pointer;
  line-height: 1.4;
}
.tp-arrows button:hover { background: #ddd; }

.tp-order-btns {
  flex-shrink: 0;
}

/* ── Layers pane ───────────────────────────────────────────────────────── */
.layer-list {
  flex: 1;
  overflow-y: auto;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-bottom: 1px solid #f0f0f0;
}
.layer-swatch {
  width: 28px;
  height: 20px;
  border: 1px solid #bbb;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.layer-name {
  flex: 1;
  font-size: 12px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layer-empty {
  padding: 20px 12px;
  font-size: 12px;
  color: #aaa;
  font-style: italic;
  text-align: center;
}

/* ── Tools pane ─────────────────────────────────────────────────────────── */
.tool-list {
  flex: 1;
  overflow-y: auto;
}
.tool-item {
  border-bottom: 1px solid #eee;
}
.tool-item-chevron {
  font-size: 10px;
  line-height: 1;
  color: #888;
  width: 14px;
  flex-shrink: 0;
  text-align: center;
}
.tool-item--expanded .tool-item-chevron {
  color: #0d6efd;
}
.tool-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  cursor: pointer;
  user-select: none;
}
.tool-row:focus {
  outline: 2px solid rgba(13, 110, 253, 0.45);
  outline-offset: -2px;
}
.tool-row:hover  { background: #eef4ff; }
.tool-row.active { background: #d0e4ff; }

.tool-num-badge {
  font-size: 10px;
  font-weight: 700;
  font-family: monospace;
  background: #6c757d;
  color: #fff;
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
  min-width: 24px;
  text-align: center;
}
.tool-row.active .tool-num-badge { background: #0d6efd; }

.tool-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: #222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-del {
  font-size: 10px;
  padding: 0 5px;
  line-height: 1.6;
  flex-shrink: 0;
}

.tool-editor-body {
  padding: 6px 8px 10px;
  background: #f8f9fa;
  border-top: 1px solid #dce3ec;
}
.tool-section-hdr {
  font-size: 10px;
  font-weight: 700;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #dee2e6;
  padding-bottom: 2px;
  margin: 7px 0 4px;
}

/* Footer */
.panel-footer {
  padding: 8px;
  border-top: 1px solid #ddd;
  background: #f5f5f5;
  flex-shrink: 0;
}

.post-name-inline {
  font-size: 10px;
  line-height: 1.2;
  max-width: 11em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-bar {
  font-size: 11px;
  word-break: break-all;
}

/* ══════════════════════════════════════════════════════════════════════════
   RIGHT PANEL
══════════════════════════════════════════════════════════════════════════ */
.panel-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Preview toolbar */
.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

/* ── Right tab nav ──────────────────────────────────────────────────────── */
.right-tab-nav {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.right-tab {
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid #ccc;
  border-radius: 3px 3px 0 0;
  background: #e8e8e8;
  cursor: pointer;
  color: #666;
  transition: background .1s, color .1s;
}
.right-tab:hover  { background: #ddd; color: #333; }
.right-tab.active { background: #fff; color: #0d6efd; border-bottom-color: #fff; }

/* ── Right panes (preview areas) ────────────────────────────────────────── */
.right-pane {
  flex: 1;
  overflow: auto;
  background: #6e6e6e;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 12px;
  min-height: 0;
}

.preview-hint {
  width: 100%;
  color: #bbb;
  font-size: 14px;
  text-align: center;
  padding: 40px 0;
  pointer-events: none;
}

/* Individual sheet card */
.sheet-container {
  display: inline-flex;
  flex-direction: column;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 3px;
  padding: 2px;
  transition: border-color .12s;
}
.sheet-container:hover          { border-color: rgba(255,255,255,.35); }
.sheet-container.active         { border-color: #5ba4f5; }

.sheet-label {
  font-size: 10px;
  font-weight: 600;
  color: #ddd;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.sheet-container svg {
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
}

/* ── Toolpath tool selector ──────────────────────────────────────────────── */
.ed-tool-row { }
.ed-tool-display {
  font-size: 12px;
  color: #888;
  padding: 3px 6px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background: #f8f9fa;
  min-height: 26px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ed-tool-display.has-tool {
  color: #212529;
  background: #eef4ff;
  border-color: #c5d8ff;
}

/* Tool picker modal rows */
.tp-tool-pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.tp-tool-pick-row:hover  { background: #f0f4ff; }
.tp-tool-pick-row.active { background: #d0e4ff; }
.tp-tool-pick-row.muted  { opacity: 0.55; }
.tp-tool-pick-info {
  flex: 1;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tp-tool-pick-note {
  font-size: 10px;
  color: #dc3545;
  white-space: nowrap;
}

/* ── Toolpath editor ─────────────────────────────────────────────────────── */
.tp-editor {
  background: #fff;
  border-top: 2px solid #0d6efd;
  flex-shrink: 0;
}
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  background: #e8f0ff;
  border-bottom: 1px solid #c5d8ff;
  flex-shrink: 0;
  gap: 8px;
}
.editor-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
  user-select: none;
}
.editor-toggle:hover {
  opacity: 0.92;
}
.editor-arrow {
  flex-shrink: 0;
  font-size: 10px;
  width: 1em;
}
.editor-body {
  padding: 6px 8px;
  max-height: 300px;
  overflow-y: auto;
}

/* ── Compact editor layout helpers ───────────────────────────────────────── */
.ed-inline-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-end;
}
.ed-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
/* Name field: grows to fill space */
.ed-field-grow { flex: 1 1 80px; }
/* Tool field: grows more to accommodate display + buttons */
.ed-field-tool  { flex: 2 1 120px; }
.ed-field-tags { flex: 1 1 280px; min-width: 280px; }
.ed-profile-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.ed-profile-col-main {
  min-width: 0;
}
.ed-profile-col-start {
  min-width: 0;
}
/* Compact number inputs — ~10 chars wide */
.ed-input-num   { width: 72px !important; }

/* ── btn-group size override (xs) ────────────────────────────────────────── */
.btn-group-xs > .btn,
.btn-group-xs > .btn-check + .btn {
  font-size: 11px;
  padding: 2px 6px;
  line-height: 1.5;
}

.profile-feed-markers {
  opacity: 0.7;
  z-index: 0;
  position: relative;
}

.profile-toolpath-stroke {
  z-index: 1;
  position: relative;
}

/* ── Starting-point picker grid ──────────────────────────────────────────── */
.start-pt-grid {
  display: grid;
  grid-template-columns: repeat(3, 22px);
  grid-template-rows:    repeat(3, 22px);
  gap: 3px;
}
.start-pt-cell {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #9ab;
  background: #fff;
  padding: 0;
  cursor: pointer;
  transition: background .1s, border-color .1s;
}
.start-pt-cell:hover   { border-color: #0d6efd; background: #eef4ff; }
.start-pt-cell.active  { background: #0d6efd; border-color: #0a58ca; }
.start-pt-grid-spacer {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

/* Tag chips */
.tag-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  padding: 5px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  min-height: 30px;
  max-height: 30px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}
.profile-tag-chips {
  flex-wrap: wrap;
  white-space: normal;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 46px;
  max-height: 46px;
}
.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid #adb5bd;
  background: #e9ecef;
  color: #555;
  user-select: none;
  transition: background .12s, color .12s;
}
.chip.on {
  background: #0d6efd;
  color: #fff;
  border-color: #0a58ca;
}
.chip.no-tags {
  color: #aaa;
  cursor: default;
  font-style: italic;
}
.chip.chip-assigned {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-right: 4px;
}
.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
  border: none;
  background: rgba(0,0,0,0.12);
  color: inherit;
  padding: 0;
}
.chip.chip-assigned.on .chip-remove {
  background: rgba(255,255,255,0.25);
}
.chip-remove:hover {
  opacity: 1;
}
/* Tag picker modal rows */
.tag-picker-list {
  max-height: 50vh;
}
.tag-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}
.tag-picker-row:hover { background: #f0f4ff; }
.tag-picker-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,.15);
  flex-shrink: 0;
}
.tag-picker-label {
  flex: 1;
  font-size: 12px;
  color: #333;
  cursor: pointer;
}

.ms-datum-grid {
  display: grid;
  grid-template-columns: repeat(3, 28px);
  grid-template-rows: repeat(3, 28px);
  gap: 5px;
}
.ms-datum-cell {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #444;
  background: #fff;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}
.ms-datum-cell:hover { background: #f0f4ff; }
.ms-datum-cell.active {
  background: #212529;
  border-color: #212529;
}

.gcode-result-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
  line-height: 1.35;
  max-height: min(55vh, 520px);
  overflow: auto;
  white-space: pre;
  word-break: normal;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background: #f8f9fa;
  color: #212529;
}
