:root {
  --bg: #1e1f24;
  --panel: #262932;
  --panel-2: #2c2f3a;
  --border: #363a46;
  --text: #e7ecf3;
  --muted: #9aa3b2;
  --accent: #ffd166;
  --accent-2: #4a9eff;
  --sauna: #c8853c;
  --steamroom: #3c8fc8;
  --shower: #3cc89a;
  --custom: #b07cff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  user-select: none;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 250px 1fr 300px;
  grid-template-rows: auto 1fr 30px 24px;
  grid-template-areas:
    "toolbar toolbar toolbar"
    "products drawing properties"
    "products viewtabs properties"
    "statusbar statusbar statusbar";
  height: 100vh;
}
#view-tabs {
  grid-area: viewtabs;
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 6px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow-x: auto;
}
.view-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 0 12px;
  cursor: pointer;
  border-top: 2px solid transparent;
  white-space: nowrap;
}
.view-tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.view-tab.active {
  color: var(--text);
  background: var(--panel-2);
  border-top-color: #4aa3ff;
}
.view-tab-add { color: var(--muted); font-weight: 700; padding: 0 10px; }
.view-tab-rename {
  align-self: center;
  height: 22px;
  margin: 0 6px;
  width: 96px;
  border: 1px solid var(--accent-2, #4aa3ff);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  padding: 0 6px;
}

/* Toolbar */
#toolbar {
  position: relative;
  grid-area: toolbar;
  display: flex;
  align-items: flex-start;
  padding: 5px 12px;
  min-height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
/* Brand pinned to the top-left at a single row's height, so toolbar rows can
   stack (and be attached) directly below it. */
.brand {
  position: absolute;
  left: 12px;
  top: 5px;
  height: 36px;
  display: flex;
  align-items: center;
  z-index: 2;
}
/* Dock: a vertical stack of toolbar rows that grows the header downward. */
#toolbar-dock {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tb-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
}
/* Only the first row shares its line with the brand, so inset it to clear the
   wordmark; rows below run the full width, under the brand. */
.tb-row:first-child { padding-left: 100px; }
/* A movable toolbar section: a grip + its buttons. */
.tb-section {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 2px 4px 2px 2px;
  border: 1px solid transparent;
  border-radius: 6px;
}
.tb-section:hover { border-color: var(--border); background: rgba(255, 255, 255, 0.02); }
.tb-section.tb-empty { display: none; }
.tb-section.tb-dragging { opacity: 0.4; }
/* Drag handle (dotted grip) on the left of each section. */
.tb-grip {
  width: 9px;
  align-self: stretch;
  min-height: 24px;
  border-radius: 3px;
  cursor: grab;
  flex-shrink: 0;
  background:
    radial-gradient(currentColor 1px, transparent 1.2px) 0 0 / 4px 4px;
  color: var(--muted);
  opacity: 0.55;
}
.tb-grip:hover { opacity: 0.9; }
.tb-grip:active { cursor: grabbing; }
/* Floating chip shown under the cursor while dragging a section. */
.tb-drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--accent, #4aa3ff);
  font-size: 12px;
  font-weight: 600;
  color: var(--text, #e7ecf3);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
/* Insertion indicator: a vertical caret (between sections) or a horizontal bar (new row). */
.tb-drop-indicator {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  background: var(--accent, #4aa3ff);
  border-radius: 2px;
}
.brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
}
.brand span {
  color: #ffd166; /* the "CAD" half in the app's yellow */
}
.tb-group {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
#toolbar button {
  flex-shrink: 0;
}
/* Compact icon-only toolbar buttons (e.g. the Arrange z-order group). */
.tb-icon {
  width: 30px;
  padding: 4px 0;
  font-size: 15px;
  line-height: 1;
  text-align: center;
}
.tb-icon:disabled {
  opacity: 0.35;
}
/* Width/height link toggle in the properties panel. */
.chain-toggle {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 14px;
  cursor: pointer;
}
.chain-toggle.active {
  border-color: var(--accent, #4aa3ff);
  background: rgba(74, 163, 255, 0.15);
}

/* Per-language translation inputs (product editor: name, preparations, connections) */
.i18n-inputs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.i18n-row {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 6px;
  align-items: center;
}
.i18n-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  background: var(--panel-2);
  border-radius: 3px;
  padding: 2px 0;
}
.i18n-row input,
.i18n-row textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 12px;
  min-width: 0;
}
.i18n-row textarea {
  min-height: 5.5em;
  line-height: 1.35;
  resize: vertical;
  font-family: inherit;
}
.np-i18n {
  flex: 1;
  min-width: 0;
}

/* Colour editor (Modify → Colour Editor…) */
.color-list {
  max-height: 50vh;
  overflow-y: auto;
  margin: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.color-row,
.color-add {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: center;
}
.color-add {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.color-row input[type='color'],
.color-add input[type='color'] {
  width: 34px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel-2);
  cursor: pointer;
}
.color-row input[type='text'],
.color-add input[type='text'] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 7px;
  font-size: 13px;
  min-width: 0;
}
.tb-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}
.tb-spacer {
  flex: 1;
}
.tb-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
}
/* Inline text-comment editor: overlaps the box on the canvas, schedule style. */
.text-editor {
  position: absolute;
  z-index: 5;
  margin: 0;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: transparent;
  color: #e7ecf3;
  font: 12px/17px sans-serif;
  padding: 7px;
  resize: none;
  overflow: hidden;
  outline: none;
  box-sizing: border-box;
}
.text-editor.hidden {
  display: none;
}

/* Inline editor for a schedule-table cell (part name / description). Light, to
   match the white table it overlays. */
.cell-editor {
  position: absolute;
  z-index: 6;
  margin: 0;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: #ffffff;
  color: #1a1d24;
  font: 13px/18px sans-serif;
  padding: 5px 8px;
  resize: none;
  overflow: hidden;
  outline: none;
  box-sizing: border-box;
}
.cell-editor.hidden {
  display: none;
}

/* Inline editor for typing a new value on a dimension line. */
.dim-input {
  position: absolute;
  z-index: 5;
  width: 88px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: #0e1116;
  color: #e7ecf3;
  font: 12px sans-serif;
  padding: 3px 5px;
  outline: none;
}
.dim-input.hidden {
  display: none;
}

/* Direct distance-entry chip shown while drawing a polygon/wall/line vertex. */
.dist-entry {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  border: 1px solid var(--accent, #4aa3ff);
  border-radius: 4px;
  background: #0e1116;
  color: #ffd166;
  font: 600 12px/1.2 sans-serif;
  padding: 3px 7px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.dist-entry::after {
  content: '▏';
  color: #ffd166;
  animation: dist-blink 1s steps(1) infinite;
}
@keyframes dist-blink { 50% { opacity: 0; } }
/* Passive length/angle readout (nothing typed yet): dimmer, no caret. */
.dist-entry.readout {
  border-color: rgba(74, 163, 255, 0.5);
  color: #cbd5e1;
  font-weight: 500;
}
.dist-entry.readout::after { content: none; }
.dist-entry.hidden {
  display: none;
}

/* Bottom status bar */
#statusbar {
  grid-area: statusbar;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
}
#statusbar .status-tool {
  overflow: hidden;
  text-overflow: ellipsis;
}
#statusbar .status-info {
  flex-shrink: 0;
}
#statusbar .status-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
}
#statusbar .status-controls button {
  padding: 2px 8px;
  font-size: 12px;
}
#statusbar .status-controls .tb-select {
  padding: 2px 6px;
  font-size: 12px;
}
#discipline-filters {
  display: inline-flex;
  gap: 4px;
}
.disc-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
button:hover {
  background: #353945;
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button:disabled:hover {
  background: var(--panel-2);
}
button.toggle.active {
  border-color: var(--accent);
  color: var(--accent);
}
button.mini {
  padding: 3px 8px;
  font-size: 12px;
}
button.primary {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #06121f;
  font-weight: 600;
}
button.ghost {
  background: transparent;
}

/* Panels */
aside {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#products {
  grid-area: products;
  border-right: 1px solid var(--border);
}
#properties {
  grid-area: properties;
  border-left: 1px solid var(--border);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.search {
  margin: 8px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
}
.search::placeholder {
  color: var(--muted);
}

/* Product list */
.product-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.product-cat {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 10px 0 4px;
  padding: 4px 4px;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
.product-cat:hover {
  color: var(--text);
}
.product-cat .cat-caret {
  width: 10px;
  font-size: 10px;
}
.product-cat .cat-count {
  margin-left: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 6px;
  font-size: 10px;
}
.product-card {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px;
  margin-bottom: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: grab;
}
.product-card:hover {
  border-color: var(--accent-2);
}
.product-card:active {
  cursor: grabbing;
}
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.product-info {
  flex: 1;
  min-width: 0;
}
.product-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-dims {
  font-size: 11px;
  color: var(--muted);
}
.hint {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.left-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
}
.left-tools .toggle {
  flex: 1;
}

/* Drawing area */
#drawing {
  grid-area: drawing;
  position: relative;
  overflow: hidden;
  background: #22242b;
}
#canvas,
#bgcanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
/* Static backdrop (page, grid, imported DXF) sits behind the interactive layer. */
#bgcanvas {
  z-index: 0;
}
#canvas {
  z-index: 1;
}
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(74, 158, 255, 0.08);
  border: 2px dashed var(--accent-2);
  pointer-events: none;
}
.drop-overlay.show {
  display: flex;
}
/* Non-blocking badge shown while the product catalogue syncs with the database. */
.db-spinner {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.db-spinner.hidden {
  display: none;
}
/* While the database is responding, show a busy cursor everywhere. */
body.busy,
body.busy * {
  cursor: progress !important;
}
.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent, #4aa3ff);
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.empty-hint {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  gap: 6px;
}
.empty-hint h2 {
  color: var(--text);
  margin: 0;
}
.empty-hint p {
  max-width: 380px;
}
.empty-hint button {
  pointer-events: auto;
}
.empty-hint.hidden {
  display: none;
}

/* Properties */
.properties-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.prop-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text);
  opacity: 0.72;
  /* A hairline divider above each section, plus generous spacing, so groups
     read as distinct blocks instead of one dense list. */
  margin: 20px 0 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
/* No divider/extra gap before the very first section, or the first section
   right after the tab bar (which already carries a bottom border). */
.properties-body > .prop-section-title:first-child,
.prop-tabs + .prop-section-title {
  margin-top: 2px;
  padding-top: 0;
  border-top: none;
}
/* Faint section cards: each section's title + rows wrapped in a subtle panel. */
.prop-card {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px 9px;
  margin-bottom: 10px;
}
.prop-card > .prop-section-title {
  margin: 0 0 9px;
  padding-top: 0;
  border-top: none;
}
.prop-card > .prop-row:last-child { margin-bottom: 0; }
/* Properties-panel tab bar. */
.prop-tabs {
  display: flex;
  gap: 2px;
  margin: -4px -4px 8px;
  border-bottom: 1px solid var(--border, #2a2f3a);
}
.prop-tab {
  flex: 1;
  padding: 6px 4px;
  font-size: 11px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
}
.prop-tab:hover:not(:disabled) { color: inherit; }
.prop-tab.active {
  color: inherit;
  border-bottom-color: #4aa3ff;
}
.prop-tab:disabled { opacity: 0.4; cursor: default; }
/* Parts list rows. */
.part-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin: 8px 0 2px;
}
.part-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.part-row:hover { background: rgba(255, 255, 255, 0.06); }
.part-row.active { background: rgba(74, 163, 255, 0.18); }
.part-name { font-size: 13px; }
/* Inline rename field (Parts tab › right-click › Rename). */
.part-rename-input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  padding: 1px 4px;
  border: 1px solid #4aa3ff;
  border-radius: 3px;
  background: #1b1d22;
  color: #e6e8eb;
  outline: none;
}
/* Snowflake freeze toggle at the right edge of a part row. */
.part-freeze {
  margin-left: auto;
  flex: none;
  background: none;
  border: none;
  color: #6b7280;
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.55; /* always visible so every part shows its freeze toggle */
}
.part-row:hover .part-freeze { opacity: 0.85; }
.part-freeze:hover { color: #8fd0ff; opacity: 1; }
.part-freeze.frozen { color: #8fd0ff; opacity: 1; }
/* Parts tree view */
.tree-row { padding: 4px 6px; gap: 6px; }
.tree-twisty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 12px;
  width: 12px;
  font-size: 9px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.tree-twisty.leaf { cursor: inherit; }
.tree-children {
  margin-left: 12px;
  border-left: 1px solid var(--border);
}
.tree-children > .tree-node > .tree-row { position: relative; }
.tree-children > .tree-node > .tree-row::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 50%;
  width: 6px;
  height: 1px;
  background: var(--border);
}
/* Product change-log table. */
.changelog-body {
  max-height: 60vh;
  overflow: auto;
  margin: 10px 0;
}
.changelog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.changelog-table th,
.changelog-table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border, #2a2f3a);
  white-space: nowrap;
}
.changelog-table th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--panel, #1b1f27);
}
.changelog-table td:last-child { white-space: normal; }
.changelog-diff {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.changelog-diff-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: baseline;
  gap: 6px;
}
.changelog-field {
  color: var(--muted);
  font-weight: 600;
}
.changelog-old {
  color: #e0708a;
  text-decoration: line-through;
  word-break: break-word;
}
.changelog-arrow { color: var(--muted); }
.changelog-new {
  color: #6cc28a;
  word-break: break-word;
}
.prop-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.prop-row label {
  font-size: 12px;
  line-height: 1.25;
  color: var(--muted);
}
.prop-row input,
.prop-row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 7px;
  font-size: 13px;
  width: 100%;
}
/* A greyed-out row whose input is disabled (e.g. a resize-locked part's size). */
.prop-row.disabled { opacity: 0.5; }
.prop-row input:disabled { cursor: not-allowed; }

/* Sauna bench slat (doghe) editor — a compact table: Width / Gap / Thickness. */
.slat-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 8px;
  font-size: 13px;
}
.slat-table th {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  padding: 2px 3px 5px;
  border-bottom: 1px solid var(--border);
}
.slat-table th:first-child { width: 20px; }
.slat-table th:last-child { width: 26px; }
.slat-table td {
  padding: 2px 3px;
  text-align: center;
}
.slat-table td.slat-idx { color: var(--muted); opacity: 0.7; }
.slat-table input {
  width: 100%;
  box-sizing: border-box;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 4px 5px;
  font-size: 13px;
  text-align: right;
}
.slat-table button.mini { padding: 3px 6px; }
.prop-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 0;
  margin-top: -2px;
}
.link-btn:hover {
  color: var(--text, #fff);
}
/* Full-width secondary action inside the properties panel. */
.panel-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
}
.panel-btn:hover {
  border-color: var(--accent, #4aa3ff);
  color: var(--accent, #4aa3ff);
}
.prep-edit {
  display: grid;
  grid-template-columns: 0.9fr 1.6fr auto;
  gap: 5px;
  align-items: center;
  margin-bottom: 5px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 5px;
}
.prep-edit select,
.prep-edit input,
.conn-add select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 6px;
  font-size: 12px;
  min-width: 0;
}

/* ---- Connection editor cards (shared by the product modal and the
   properties panel) ---- */
.conn-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.conn-badge {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent, #4aa3ff);
  color: #0b0c0f;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.conn-summary {
  flex: 1 1 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Routed length of a connection, shown in its card header. */
.conn-len {
  flex: 0 0 auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}
.disc-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35) inset;
}
.conn-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.field.span-2 {
  grid-column: 1 / -1;
}
.field-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.field select,
.field input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 6px;
  font-size: 12px;
  min-width: 0;
  width: 100%;
}
.disc-select {
  display: flex;
  align-items: center;
  gap: 6px;
}
.disc-select select {
  flex: 1 1 auto;
}
.field-hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
  margin: 2px 0 6px;
}
.np-empty {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  padding: 6px 2px;
}
.conn-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  margin-top: 4px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #11141a;
}

/* Modal */
/* Right-click product menu */
.ctx-menu {
  position: fixed;
  z-index: 200;
  min-width: 170px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.ctx-menu.hidden {
  display: none;
}
.ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 5px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
}
.ctx-menu button:hover {
  background: var(--panel-2);
}
.ctx-menu button.danger {
  color: #ff8080;
}
.ctx-menu .sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.ctx-menu .ctx-heading {
  padding: 4px 10px 2px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.rename-input {
  background: var(--panel-2);
  border: 1px solid var(--accent-2);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 2px 4px;
  width: 100%;
}

.modal.print {
  width: 640px;
  max-width: 92vw;
}
/* The preview step expands to fill ~80% of the screen. */
.modal.print.preview-wide {
  width: 80vw;
  max-width: 80vw;
}
.modal.print.preview-wide .print-preview {
  max-height: 80vh;
}
.print-q {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}
.print-choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.print-choice:hover {
  border-color: var(--accent-2);
}
.print-choice b {
  font-size: 14px;
}
.print-choice span {
  font-size: 12px;
  color: var(--muted);
}
.print-preview {
  background: #14161c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  max-height: 62vh;
  overflow: auto;
  text-align: center;
}
.print-preview img {
  max-width: 100%;
  height: auto;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden {
  display: none;
}
.modal {
  width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
/* The product editor is a wide, sectioned workspace (80% of the screen). */
.modal.modal-wide {
  width: 80vw;
  max-width: none;
  height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal h3 {
  margin: 0 0 2px;
}
.modal-sub {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}
.modal-wide .np-head {
  flex: 0 0 auto;
}
.modal-wide .modal-sub {
  margin: 0;
}
/* Three columns: column 1 stacks details over properties; column 2 is parts;
   column 3 is connections. */
.np-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  /* Left column: details (top) + parts tree (bottom). Centre: selected part's
     drawing/properties/preparations. Right: connections. */
  grid-template-columns: 0.9fr 1.3fr 0.9fr;
  grid-template-rows: minmax(0, auto) minmax(0, 1fr);
  grid-template-areas:
    "meta   detail conns"
    "tree   detail conns";
  gap: 14px;
}
.np-area-meta { grid-area: meta; }
.np-area-tree { grid-area: tree; }
.np-area-detail { grid-area: detail; }
.np-area-conns { grid-area: conns; }

/* Parts tree (bottom-left): a selectable list of the product's parts. */
.np-tree-row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.np-tree-row:hover {
  background: rgba(255, 255, 255, 0.04);
}
.np-tree-row.active {
  background: rgba(74, 163, 255, 0.14);
  border-color: rgba(74, 163, 255, 0.5);
}
.np-tree-name {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.np-part-tree {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

/* Part detail (centre): sub-headings between drawing / properties / preparations. */
.np-detail-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  margin: 14px 0 8px;
}
.np-detail-head:first-child {
  margin-top: 0;
}
.np-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.np-section-head {
  flex: 0 0 auto;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--border);
}
.np-section-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}
.np-section-body .form-row:last-child {
  margin-bottom: 0;
}
.form-row {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-row.two {
  flex-direction: row;
  gap: 12px;
}
.form-row.two > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-row > label {
  font-size: 12px;
  color: var(--muted);
}
.np-bench-heights {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.np-bench-heights > label {
  font-size: 12px;
  color: var(--muted);
}
.np-bench-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 6px;
}
.np-bench-row > span {
  font-size: 12px;
  color: var(--muted);
}
.np-bench-row input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 13px;
}
.np-cat-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  margin: 10px 0 2px;
}
.np-cat-fields .form-row {
  margin-bottom: 8px;
}
.np-cat-fields input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 13px;
}
.np-cat-fields input[type='color'] {
  width: 44px;
  height: 30px;
  padding: 2px;
}
.view3d-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: #20242b;
}
.view3d-overlay.hidden {
  display: none;
}
.view3d-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.view3d-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.view3d-spacer {
  flex: 1;
}
.view3d-canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
}
.form-row input,
.form-row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 9px;
  font-size: 13px;
}
.file-pick {
  display: flex;
  align-items: center;
  gap: 10px;
}
.np-file {
  font-size: 12px;
  color: var(--muted);
}
.np-props {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.np-prop {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
}
.np-prop input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 12px;
}
.np-prop .del {
  padding: 4px 8px;
}
.np-parts,
.np-connections {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}
.np-part-block {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent, #4aa3ff);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.025);
}
.np-part-block:last-child {
  margin-bottom: 6px;
}
/* Header: numbered badge · live part name · delete. */
.np-part-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 9px;
  margin-bottom: 9px;
  border-bottom: 1px solid var(--border);
}
.np-part-title {
  flex: 1 1 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Body: thumbnail next to a grid of labelled fields. */
.np-part-body {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  align-items: start;
}
.np-part-thumb {
  width: 96px;
  height: 96px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.np-part-thumb img,
.np-part-thumb canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.np-part-thumb.empty {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}
.np-part-thumb.editable {
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.np-part-thumb.editable:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.np-part-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: 0;
}
.np-part-pick {
  width: 100%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
}
.np-part-block .prep-edit {
  margin-top: 8px;
}
.np-conn-block {
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  margin-bottom: 8px;
}
/* Connection card in the properties panel (parts-list style). */
.conn-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
/* Coloured schedule number (E1/P1/M1) — matches the on-canvas schedule box:
   discipline-coloured text, same family/size, no pill background. */
.conn-num {
  flex: 0 0 auto;
  min-width: 28px;
  font-family: sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  display: inline-flex;
  align-items: center;
}
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.modal-wide .modal-actions {
  flex: 0 0 auto;
  margin-top: 0;
}
.np-error {
  color: #ff6b6b;
  font-size: 12px;
  margin-top: 8px;
  white-space: pre-wrap;
}
/* In the editor footer the error sits to the left, buttons to the right. */
.modal-wide .np-error {
  margin-top: 0;
  margin-right: auto;
}

/* ---- Cartigli editor ---- */
.cart-layout { display: flex; gap: 14px; max-height: 62vh; }
.cart-side { width: 190px; flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; }
.cart-list { flex: 1; overflow-y: auto; border: 1px solid var(--border, #3a3f4b); border-radius: 6px; }
.cart-list-item { padding: 7px 9px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border, #2c313c); display: flex; justify-content: space-between; gap: 6px; }
.cart-list-item:hover { background: rgba(120,140,180,0.12); }
.cart-list-item.active { background: rgba(74,163,255,0.18); }
.cart-list-item .cart-badge { font-size: 10px; color: #4aa3ff; align-self: center; }
.cart-main { flex: 1; overflow-y: auto; padding-right: 6px; }
.cart-check { display: flex; align-items: center; gap: 6px; }
.cart-logo-row { display: flex; align-items: center; gap: 8px; }
.cart-logo-prev { height: 26px; max-width: 120px; object-fit: contain; background: #fff; border-radius: 3px; padding: 2px; }
.cart-fields { display: flex; flex-direction: column; gap: 5px; }
.cart-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cart-scope-row { align-items: center; gap: 8px; }
.cart-side-sel { font-size: 12px; opacity: 0.85; }
.cart-geom { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; margin-top: 6px; }
.cart-geom .cart-geom-group { grid-column: 1 / -1; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; opacity: 0.6; margin-top: 6px; }
.cart-geom label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; opacity: 0.85; }
.cart-geom input { width: 100%; }
.cart-delete-btn { margin-right: auto; color: #e0736a; }

/* Bench presets editor: 3-column layout (list · slat editor · preview). */
.bench-layout { display: grid; grid-template-columns: 190px 1fr 300px; gap: 14px; max-height: 64vh; }
.bench-side { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.bench-main { overflow-y: auto; padding-right: 6px; min-width: 0; }
.bench-main .form-row { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
.bench-preview { display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--border, #3a3f4b); border-radius: 6px; padding: 8px; background: var(--panel-2, #222834); }
.bench-preview-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; opacity: 0.6; }
.bench-preview canvas { width: 100%; flex: 1; min-height: 0; border-radius: 4px; }

/* Opacity / value sliders: a custom track whose filled portion reaches exactly
   the value. Native range thumbs are inset by half their width, so a plain
   slider at 100% only looks ~90% full; painting the fill from a --fill variable
   makes 100% look 100%. */
input[type="range"].opacity-range {
  -webkit-appearance: none;
  appearance: none;
  height: 16px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type="range"].opacity-range::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent-2) 0 var(--fill, 100%), var(--panel-2) var(--fill, 100%) 100%);
  border: 1px solid var(--border);
}
input[type="range"].opacity-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  border: 1px solid var(--border);
  margin-top: -5px;
}
input[type="range"].opacity-range::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
input[type="range"].opacity-range::-moz-range-progress {
  height: 5px;
  border-radius: 3px;
  background: var(--accent-2);
}
input[type="range"].opacity-range::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text);
  border: 1px solid var(--border);
}

/* Live cursor-coordinate readout in the status bar. */
.status-coord {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
  min-width: 96px;
  text-align: right;
  opacity: 0.85;
}

/* Disabled items in the right-click context menu. */
.ctx-menu button:disabled {
  opacity: 0.4;
  cursor: default;
}
.ctx-menu button:disabled:hover {
  background: transparent;
}

/* Keyboard-shortcuts cheat sheet (a centred modal overlay). */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  z-index: 6000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
.shortcuts-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  max-height: 82vh;
  overflow-y: auto;
  min-width: 460px;
  max-width: 92vw;
  padding: 0 18px 16px;
}
.shortcuts-head {
  position: sticky;
  top: 0;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.shortcuts-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.shortcuts-close:hover { color: var(--text); }
.shortcuts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.shortcuts-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text);
}
.shortcuts-table tr:last-child td { border-bottom: none; }
.shortcuts-key {
  white-space: nowrap;
  color: var(--accent-2);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-weight: 600;
  width: 45%;
}

/* Interface-language selector in the status bar. */
.lang-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  padding: 2px 4px;
  cursor: pointer;
}
