:root {
  --bg: #0e1116;
  --bg-2: #151a22;
  --panel: #171d27;
  --line: #2a3342;
  --text: #e8edf5;
  --muted: #8b97a8;
  --accent: #d4a017;
  --accent-2: #3d8bfd;
  --ok: #3dd68c;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --aside-w: 380px;
  --ta-primary: #0056b3;
  --ta-primary-dark: #004494;
  --ta-orange: #F97316;
  --ta-text: #0f172a;
  --ta-muted: #64748b;
  --ta-dark: #010101;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  min-height: 100dvh;
}
h1, h2, h3 { font-family: inherit; }
h1 { font-size: 22px; font-weight: 700; line-height: 1.2; margin: 0; }
h2 { font-size: 15px; font-weight: 700; line-height: 1.3; margin: 0; }
h3 { font-size: 12px; font-weight: 600; line-height: 1.3; margin: 0; color: var(--muted); }
button, input, select { font: inherit; color: inherit; }

.app-header {
  flex: 0 0 auto;
  width: 100%;
  height: 78px;
  min-height: 78px;
  max-height: 78px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(219, 228, 240, 0.9);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  color: var(--ta-text);
  z-index: 12;
}
.app-header .header-container {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  align-items: center;
  max-width: 1920px;
  margin: 0 auto;
  padding: 0 40px;
  gap: 16px;
  height: 78px;
  box-sizing: border-box;
}
.app-header .logo-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  justify-self: start;
}
.app-header .logo-icon {
  width: 40px;
  height: 40px;
  display: block;
  flex-shrink: 0;
  border-radius: 50%;
}
.app-header .logo-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}
.app-header .logo-copy h2,
.app-header .logo-copy p {
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header .logo-copy h2 {
  color: var(--ta-text);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.app-header .logo-copy p {
  color: var(--ta-muted);
  font-size: 13px;
  font-weight: 500;
}
.app-header .nav-modules {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  justify-self: center;
  min-width: 0;
}
.app-header .module-btn,
.app-header .tab {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
  border-radius: 4px;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}
.app-header .module-btn:hover,
.app-header .tab:hover {
  background: #f8f9fa;
  border-color: #007bff;
  color: #333;
}
.app-header .tab.is-active,
.app-header .tab.is-on {
  background: #007bff;
  color: #fff;
  border-color: #007bff;
}
.app-header .user-info,
.app-header .top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  gap: 12px;
  min-width: 0;
}
.app-header #btn-save {
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  border: 0;
  background: var(--ta-primary);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.app-header #btn-save:hover {
  background: var(--ta-primary-dark);
}
.app-header #btn-save.is-unsaved {
  background: linear-gradient(135deg, #F97316 0%, #e8650d 100%);
  color: #fff;
  border: 0;
}

.app-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 6px 14px;
  background: rgba(1, 1, 1, 0.78);
  color: #fff;
  pointer-events: none;
}
.app-footer .footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  min-width: 0;
}
.app-footer .footer-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.app-footer .footer-brand strong {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
}
.app-footer .footer-brand span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-footer .footer-copy {
  margin: 0;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  white-space: nowrap;
}

.file-btn, .stage-tools button {
  background: #202838;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
}
.stage-tools button.is-on {
  background: #2b3a22;
  border-color: #4a6a2e;
  color: #e7f3c9;
}
.file-btn { background: var(--accent); color: #1b1403; border-color: transparent; font-weight: 600; }

.assembly-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  overflow-x: auto;
}
.assembly-bar span {
  font-size: 12px;
  color: var(--ta-muted);
  white-space: nowrap;
  margin-right: 4px;
}
.assembly-bar button {
  padding: 6px 10px;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 12px;
}
.assembly-bar button.is-on {
  background: #007bff;
  border-color: #007bff;
  color: #fff;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, var(--aside-w, 380px)) minmax(0, 1fr);
  grid-template-areas: "panel stage";
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.panel { grid-area: panel; }
.stage { grid-area: stage; }
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #232a36, #0b0d11 70%);
}
#viewport { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; overflow: hidden; }
#viewport, #viewport canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  max-width: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
}
.label-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
}
.rack-label {
  position: absolute;
  transform: translate(-50%, -100%);
  margin-top: -8px;
  pointer-events: auto;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(18, 23, 34, 0.88);
  border: 1px solid rgba(232, 237, 245, 0.18);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  padding: 3px 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 5;
}
.rack-label.is-active {
  background: #2a2416;
  border-color: var(--accent);
  color: #f2e4b3;
}
.dim-label {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  white-space: nowrap;
  background: rgba(18, 23, 34, 0.92);
  border: 1px solid #d4a017;
  border-radius: 6px;
  color: #f2e4b3;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 6px;
  z-index: 5;
}
.rack-dock {
  position: absolute;
  top: 58px;
  right: 14px;
  z-index: 6;
  width: min(250px, calc(100% - 28px));
  max-height: calc(100% - 90px);
  overflow: auto;
}
.rack-dock .rack-add {
  margin: 8px 0 0;
  padding: 9px 10px;
  font-size: 13px;
}
.rack-dock .section-row {
  background: rgba(18, 23, 34, 0.88);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 6px;
  box-shadow: var(--shadow);
}
.rack-dock .section-row.is-on {
  background: #2a2416;
  border-color: #d4a017;
}
.rack-dock input.rack-pick {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 6px;
}
.rack-dock input.rack-pick:focus {
  outline: none;
}
.rack-dock .section-row.is-on input.rack-pick {
  color: #f2e4b3;
}
.stage-hud {
  position: absolute; left: 16px; bottom: 40px;
  color: var(--muted); font-size: 12px; pointer-events: none;
  max-width: calc(100% - 32px);
  overflow-wrap: anywhere;
}
.stage-hud p { margin: 0 0 4px; }
#hud-status.is-warn { color: #f07171; }
.tier-table tr.is-collide td {
  background: rgba(198, 40, 40, 0.22);
  color: #ffd6d6;
}
.tier-table tr.is-collide td:first-child::after {
  content: " пересечение";
  color: #f07171;
  font-size: 11px;
}
.stage-tools {
  position: absolute; top: 14px; left: 14px;
  display: flex; flex-wrap: wrap; gap: 6px;
  z-index: 5;
  max-width: calc(50% - 140px);
}
.stage-name {
  display: none !important;
}
.stage-name input {
  display: block;
  width: 100%;
  min-width: 160px;
  background: rgba(18, 23, 34, 0.72);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  padding: 6px 14px;
}
.stage-name input:hover,
.stage-name input:focus {
  border-color: var(--accent);
  outline: none;
  background: rgba(18, 23, 34, 0.92);
}

.panel {
  position: relative;
  display: flex;
  flex-direction: row;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 0;
}
.panel-body {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 14px;
}
.panel-resizer {
  flex: 0 0 8px;
  cursor: col-resize;
  align-self: stretch;
}
.panel-resizer:hover,
.panel.is-resizing .panel-resizer {
  background: rgba(232, 237, 245, 0.14);
}
body.is-col-resize,
body.is-col-resize * {
  cursor: col-resize !important;
  user-select: none !important;
}
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card h2 {
  margin: 16px 0 8px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
.card > h2:first-child { margin-top: 0; }
.card h3, .param-block h3 {
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--muted);
}
.control-stack {
  display: grid;
  gap: 10px;
  margin: 0 0 14px;
}
.range-field {
  padding: 12px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #121820;
}
.range-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 10px;
  min-width: 0;
}
.range-title {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}
.range-head output {
  float: none;
  margin: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: #2a2416;
  border: 1px solid #d4a017;
  color: #f2e4b3;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.range-unit {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.range-field .field-hint {
  margin: 8px 0 0;
  line-height: 1.45;
}
.range-field input[type="range"] {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  height: 22px;
  background: transparent;
  border: 0;
  border-radius: 0;
  accent-color: #d4a017;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.range-field input[type="range"]:focus {
  outline: none;
}
.range-field input[type="range"]:focus-visible {
  outline: 2px solid rgba(212, 160, 23, 0.55);
  outline-offset: 3px;
  border-radius: 8px;
}
.range-field input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #2a2416, #3a4250);
  border: 1px solid #4a5568;
}
.range-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: #d4a017;
  border: 2px solid #f2e4b3;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.range-field input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, #2a2416, #3a4250);
  border: 1px solid #4a5568;
}
.range-field input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #d4a017;
  border: 2px solid #f2e4b3;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.range-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  margin: 6px 1px 0;
  letter-spacing: 0.02em;
}
.field-group {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #121820;
}
.field-group > h2,
.field-group > h3 { margin-top: 0; }
.field-group .field-hint { margin: 8px 0 0; }
.field-group.angle-group { margin-top: 0; }
.field-group.angle-group .depth-grid { margin-bottom: 0; }
.card label { display: block; margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.card input[type="range"], .card select, .card input[type="number"] {
  width: 100%;
  margin-top: 4px;
  background: #10151c;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}
.card input[type="range"] { padding: 0; }
.card label output { float: right; color: var(--text); font-weight: 600; }
.price-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.price-row strong { font-size: 28px; color: var(--ok); }
.price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.muted, .note { color: var(--muted); font-size: 12px; }
.note ol { padding-left: 18px; }
.note code { color: #f2d58a; }
.bom { width: 100%; max-width: 100%; border-collapse: collapse; font-size: 12px; }
.bom th, .bom td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: left; }
.spec-table th:nth-child(1),
.spec-table td:nth-child(1),
.spec-table th:nth-child(3),
.spec-table td:nth-child(3),
.spec-table th:nth-child(4),
.spec-table td:nth-child(4),
.spec-table th:nth-child(5),
.spec-table td:nth-child(5),
.spec-table th:nth-child(7),
.spec-table td:nth-child(7) { text-align: right; white-space: nowrap; }
.spec-table tr.bom-group td {
  background: #1a222c;
  color: var(--text);
  font-weight: 700;
  text-align: left;
  padding-top: 10px;
}
.bom-block {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.bom-wrap { max-height: 480px; overflow: auto; margin: 0 0 8px; max-width: 100%; }
.bom tfoot td { font-weight: 700; border-bottom: none; padding-top: 8px; }
.bom-actions { display: grid; grid-template-columns: 1fr; gap: 6px; }
.ghost-btn {
  width: 100%;
  margin: 0;
  background: #10151c;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
}
.ghost-btn:hover { border-color: #d4a017; }
.ghost-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.ghost-btn:disabled:hover { border-color: var(--line); }
.undo-bar {
  position: absolute;
  left: 50%;
  bottom: 52px;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100% - 32px);
  min-width: 0;
  box-sizing: border-box;
  background: #1c2430;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 36px 8px 12px;
  box-shadow: var(--shadow);
  font-size: 13px;
}
.undo-bar.is-hidden { display: none; }
.undo-bar .ghost-btn { width: auto; padding: 6px 12px; }
.undo-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.undo-close:hover { color: var(--text); background: #2a3342; }
.leave-actions { display: grid; gap: 8px; margin-top: 12px; }
.add-section-choices { display: grid; gap: 10px; margin-top: 14px; }
.add-choice {
  display: block;
  width: 100%;
  text-align: left;
  background: #121820;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
}
.add-choice strong {
  display: block;
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
}
.add-choice .field-hint { display: block; margin: 0; }
.add-choice:hover { border-color: var(--accent); background: #1a222c; }
.add-choice:disabled { opacity: 0.45; cursor: default; border-color: var(--line); background: #121820; }
.leave-btn { width: 100%; text-align: center; display: block; }
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 14, 0.62);
  padding: 16px;
  overflow: hidden;
}
.modal-back.is-hidden { display: none; }
.modal {
  width: min(1080px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px 18px;
  box-shadow: var(--shadow);
}
.modal-back--float {
  background: transparent;
  pointer-events: none;
  padding: 0;
  overflow: hidden;
  align-items: stretch;
  justify-content: stretch;
}
.modal-back--float .modal-part {
  pointer-events: auto;
  position: absolute;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 118px);
}
.modal-part.is-dragging,
.modal-part.is-dragging .modal-head--drag { cursor: grabbing; }
.modal-head--drag { cursor: grab; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.modal-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}
.modal-part { width: min(520px, 100%); }
.choice-row { grid-template-columns: repeat(auto-fit, minmax(min(100%, 128px), 1fr)) !important; }
.modal-part .choice {
  white-space: normal;
  line-height: 1.2;
  padding: 10px 8px;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.modal-block {
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #121820;
}
.modal-block h2 {
  margin: 0 0 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
.modal-block .field-hint { margin: 0 0 10px; }
.choice-field h3 {
  margin: 10px 0 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--muted);
}
.modal-block > .choice-field:first-of-type h3,
.modal-block > .field-hint + .choice-field h3 {
  margin-top: 0;
}
.modal .field-label { margin-top: 4px; }
.modal-close { width: auto; padding: 8px 12px; }
.tier-wrap { max-height: 380px; overflow: auto; margin: 0 0 10px; max-width: 100%; }
.tier-table select, .tier-table input[type="number"],
.bom select, .bom input[type="number"] {
  width: 100%;
  background: #10151c;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}
.bom .bom-name {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.bom .bom-name select { width: auto; min-width: 76px; }
.bom input[type="number"] { width: 64px; text-align: right; }
.tier-table .ghost-btn { width: auto; padding: 6px 10px; }
.tier-shift {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}
.tier-shift .ghost-btn { width: 100%; }
.tier-shift-value {
  min-width: 64px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tier-table tr.tier-group td {
  background: #1a222c;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.02em;
  padding-top: 10px;
}
.tier-table tr.tier-add td { border-bottom: none; padding-top: 4px; padding-bottom: 10px; }
.parts-list { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow: auto; }
.details-list { max-height: min(62vh, 720px); }
.details-search {
  width: 100%;
  margin: 8px 0;
  background: #10151c;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.details-meta { color: var(--muted); font-size: 12px; }
.part-btn {
  text-align: left;
  background: #10151c;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.part-btn small { display: block; color: var(--muted); }
.part-btn.is-on { border-color: #d4a017; background: #2a2416; }
.swatch-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.swatches { display: flex; flex-wrap: wrap; gap: 7px; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #3a4454; padding: 0; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
.swatch.is-on { outline: 2px solid #d4a017; outline-offset: 2px; }
.ral-row { align-items: flex-end; }
.ral-chip {
  min-width: 48px;
  padding: 5px 6px 4px;
  border-radius: 10px;
  background: #10151c;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.ral-chip-tone {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.28);
}
.ral-chip small { font-size: 10px; color: var(--muted); line-height: 1; }
.ral-chip.is-on { border-color: #d4a017; background: #2a2416; }
.ral-chip.is-on small { color: #f2e4b3; }
.ral-more {
  min-height: 52px;
  max-width: 100%;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.2;
  white-space: normal;
  background: #202838;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
}
.ral-more:hover { border-color: #d4a017; }
.modal-ral { width: min(920px, 100%); }
.modal-ral #ral-search {
  width: 100%;
  margin: 0 0 14px;
  background: #10151c;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: inherit;
}
.ral-groups { max-height: min(62vh, 560px); overflow: auto; min-width: 0; }
.ral-group { margin: 0 0 16px; }
.ral-group h2 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}
.ral-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
}
.ral-tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 6px;
  background: #10151c;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.ral-tile-tone {
  display: block;
  height: 34px;
  border-radius: 7px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.28);
}
.ral-tile strong { font-size: 12px; font-weight: 700; }
.ral-tile small { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; }
.ral-tile.is-on { border-color: #d4a017; background: #2a2416; }
.ral-tile.is-on small { color: #f2e4b3; }
.field-label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 12px; }
.card > .field-label:first-child { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  background: #10151c; border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 10px; cursor: pointer;
}
.chip.is-on { background: #2a2416; border-color: #d4a017; color: #f2e4b3; }
.height-grid { max-height: 168px; overflow: auto; margin-top: 8px; }
.height-grid .chip { padding: 4px 8px; font-size: 12px; }
.section-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; min-width: 0; }
.section-row.is-on {
  background: #2a2416;
  border: 1px solid #d4a017;
  border-radius: 8px;
  padding: 4px 6px;
}
.rack-row-head { margin: 12px 0 6px; }
.rack-row-head:first-child { margin-top: 0; }
.section-row button.rack-pick {
  flex: 1;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 4px;
}
.section-row span { flex: 1; color: var(--text); font-size: 13px; }
.section-row select { flex: 1; background: #10151c; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.section-row button.rack-del { background: #202838; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; }
.assemble-btn {
  width: 100%; margin: 8px 0 12px;
  background: #d4a017; color: #1b1403; border: none;
  border-radius: 8px; padding: 10px 12px; font-weight: 700; cursor: pointer;
}
.side-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 14px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #121820;
}
.side-toggle .choice {
  margin: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  padding: 11px 8px;
  font-weight: 600;
}
.side-toggle .choice:hover {
  background: rgba(232, 237, 245, 0.06);
}
.side-toggle .choice.is-on {
  background: #2a2416;
  color: #f2e4b3;
  box-shadow: inset 0 0 0 1px #d4a017;
}
.choice {
  width: 100%;
  text-align: center;
  background: #10151c;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 8px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 14px;
  white-space: normal;
  line-height: 1.2;
  overflow-wrap: anywhere;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.choice:hover { border-color: #8b97a8; }
.choice.is-on { border-color: #d4a017; background: #2a2416; color: #f2e4b3; }
.choice.is-missing { border-color: #c43c3c; color: #f3c4c4; }
.choice.is-missing.is-on { background: #2a1416; border-color: #ff3b3b; color: #ffd0d0; }
.param-trio {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
  align-items: stretch;
  min-width: 0;
}
.param-block {
  min-width: 0;
  background: #121820;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px 8px;
}
.param-block h3 {
  margin: 0 0 8px;
  padding: 0 2px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.param-block .field-label {
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  line-height: 1.25;
  color: #eef2f8;
}
.param-block .depth-grid { margin-bottom: 0; }
.param-block .choice {
  padding: 8px 4px;
  font-size: 13px;
  background: #10151c;
  border-color: var(--line);
}
.param-block .choice.is-on {
  background: #2a2416;
  border-color: #d4a017;
}
.pitch-grid { grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
.pitch-grid .choice { padding: 7px 2px; font-size: 12px; border-radius: 8px; }
.depth-grid { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 14px; }
.depth-grid .choice { margin: 0; }
#cfg-depth { grid-template-columns: 1fr; }
#cfg-angle { grid-template-columns: 1fr 1fr 1fr; }
.rail-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 8px;
}
.rail-checks .check-row { margin: 0; }
#cfg-rail-h, #cfg-rail-finish { grid-template-columns: 1fr 1fr 1fr; margin: 0 0 10px; }
#cfg-rail-opts h3, #cfg-rail-opts .field-label { margin: 8px 0 6px; }
#cfg-rail-opts.is-hidden { display: none; }
.field-hint { color: var(--muted); font-size: 12px; margin: -6px 0 14px; line-height: 1.45; }
.card.is-hidden, .is-hidden { display: none; }
#btn-add-section:disabled { opacity: 0.45; cursor: default; }
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #5c6573;
  border: 1px solid #717b8c;
  border-radius: 10px;
  color: #eef2f8;
  cursor: pointer;
  font-size: 14px;
}
.check-row input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #d4a017;
  cursor: pointer;
}
#cfg-panel-kind {
  grid-template-columns: 1fr 1fr;
  margin: 8px 0 8px;
}
#cfg-panel-kind .choice {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 8px 6px;
}
#cfg-panel-kind.is-hidden { display: none; }

@media (min-width: 1921px) {
  :root { --aside-w: 420px; }
  h1 { font-size: 24px; }
  .modal-head h1 { font-size: 24px; }
  .rack-dock { width: 280px; top: 64px; }
  .card { padding: 16px; }
  .stage-tools { max-width: min(640px, calc(100% - 300px)); }
}

@media (max-width: 1920px) {
  :root { --aside-w: 380px; }
}

@media (max-width: 1600px) {
  :root { --aside-w: 360px; }
  .rack-dock { width: min(230px, calc(100% - 24px)); }
}

@media (max-width: 1400px) {
  :root { --aside-w: 340px; }
  .param-trio { gap: 8px; }
  .stage-tools { max-width: min(520px, calc(100% - 240px)); }
  .modal { width: min(1000px, 100%); }
}

@media (max-width: 1200px) {
  :root { --aside-w: 300px; }
  .file-btn { font-size: 13px; padding: 8px 10px; }
  .rack-dock { width: min(210px, calc(100% - 20px)); top: 52px; }
  .modal { width: min(960px, 100%); }
  #cfg-angle { grid-template-columns: 1fr 1fr; }
  .app-header .header-container { padding: 0 20px; }
  .app-footer { padding-left: 20px; padding-right: 20px; }
  .param-trio { grid-template-columns: 1fr; }
}

@media (max-width: 992px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 42vh);
    grid-template-areas: "stage" "panel";
  }
  .stage { min-height: 0; }
  .panel {
    border-right: none;
    border-top: 1px solid var(--line);
    max-height: none;
    min-height: 0;
  }
  .panel-resizer { display: none; }
  .stage-tools { max-width: calc(100% - 20px); }
  .stage-name { top: 52px; max-width: calc(100% - 20px); }
  .rack-dock { width: min(190px, 40vw); right: 10px; }
  .bom-actions { grid-template-columns: 1fr; }
  .param-trio { grid-template-columns: 1fr; }
  .app-header .header-container {
    grid-template-columns: minmax(0, auto) 1fr auto;
    padding: 0 16px;
    gap: 10px;
  }
  .file-btn { white-space: normal; }
}

@media (max-width: 768px) {
  .app-header,
  .app-header .header-container {
    height: 70px;
    min-height: 70px;
    max-height: 70px;
  }
  .app-header .header-container { padding: 0 16px; }
  .app-header .logo-icon { width: 36px; height: 36px; }
  .app-header .logo-copy h2 { font-size: 18px; }
  .app-header .logo-copy p { font-size: 12px; }
  .app-header .tab { padding: 7px 10px; font-size: 13px; }
  .app-header #btn-save { padding: 10px 12px; }
  .app-footer { padding: 6px 12px; }
  .app-footer .footer-brand span { display: none; }
  .app-footer .footer-inner { justify-content: space-between; }
  .rail-checks { grid-template-columns: 1fr; }
  #cfg-angle,
  #cfg-rail-h,
  #cfg-rail-finish,
  #cfg-panel-kind { grid-template-columns: 1fr 1fr; }
  .modal { padding: 12px; }
  .modal-head { flex-wrap: wrap; }
  .modal-head h1 { font-size: 18px; }
  .stage-hud { left: 10px; right: 10px; bottom: 36px; font-size: 11px; }
  .layout { grid-template-rows: minmax(0, 1fr) minmax(0, 46vh); }
  .rack-dock { width: min(170px, 38vw); font-size: 13px; }
  .bom, .tier-table { font-size: 11px; }
  .spec-table th,
  .spec-table td { white-space: normal; }
  .bom-actions { grid-template-columns: 1fr; }
  .ral-palette { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

@media (max-width: 420px) {
  h1 { font-size: 18px; }
  .app-header .logo-copy h2 { font-size: 16px; }
  .app-header .tab { padding: 6px 8px; font-size: 12px; }
  .app-header #btn-save { padding: 8px 10px; font-size: 13px; }
  .file-btn, .stage-tools button {
    padding: 7px 8px;
    font-size: 12px;
    white-space: normal;
  }
  .card { padding: 10px; border-radius: 10px; }
  .choice { padding: 8px 6px; font-size: 12px; }
  .check-row { padding: 8px 10px; font-size: 13px; }
  .pitch-grid { grid-template-columns: 1fr 1fr; }
  .stage-tools { left: 8px; top: 8px; }
  .rack-dock {
    top: auto;
    bottom: 48px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 26vh;
  }
  .undo-bar { bottom: 8px; font-size: 12px; }
  .rack-label { font-size: 11px; max-width: 140px; padding: 2px 6px; }
  #cfg-angle,
  #cfg-rail-h,
  #cfg-rail-finish,
  #cfg-panel-kind { grid-template-columns: 1fr; }
  .layout { grid-template-rows: minmax(0, 1fr) minmax(0, 50vh); }
  .ral-more { width: 100%; }
  .ral-palette { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
}

/* Authentication UI is appended and scoped so editor styles stay unchanged. */
.app-header .user-name {
  font-weight: 600;
  color: #0f172a;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header .user-name.is-hidden,
.app-header .header-logout.is-hidden,
.app-header .header-login.is-hidden,
.app-header #btn-save.is-hidden {
  display: none;
}
.app-header #btn-login,
.app-header .header-login {
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  border: 1px solid #ddd;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
  white-space: nowrap;
}
.app-header #btn-login:hover,
.app-header .header-login:hover {
  border-color: #007bff;
  background: #f8f9fa;
}
.app-header #btn-logout,
.app-header .header-logout {
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
  border: 0;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.app-header #btn-logout:hover,
.app-header .header-logout:hover {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  transform: translateY(-1px);
}
.auth-modal .login-container {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  color: #333;
}
.auth-modal .login-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 30px 20px;
  text-align: center;
  position: relative;
}
.auth-modal .auth-close-x {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.auth-modal .login-header h1 {
  color: #fff;
  font-size: 24px;
  margin: 0 0 10px;
}
.auth-modal .login-header p {
  margin: 0;
  opacity: 0.9;
}
.auth-modal .login-body { padding: 30px; }
.auth-modal .alert {
  padding: 12px 15px;
  border-radius: 5px;
  margin: 0 0 20px;
  font-size: 14px;
}
.auth-modal .alert:empty { display: none; }
.auth-modal .alert-danger {
  background: #fee;
  border: 1px solid #f5c6cb;
  color: #721c24;
}
.auth-modal .alert-warning {
  background: #fff3cd;
  border: 1px solid #ffc107;
  color: #856404;
}
.auth-modal .alert-success {
  background: #d1e7dd;
  border: 1px solid #badbcc;
  color: #0f5132;
}
.auth-modal .form-group { margin-bottom: 20px; }
.auth-modal .form-group.is-hidden { display: none; }
.auth-modal label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: #333;
}
.auth-modal .form-control {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
  color: #333;
  background: #fff;
  transition: border-color 0.3s;
}
.auth-modal .form-control:focus {
  outline: none;
  border-color: #667eea;
}
.auth-modal .password-toggle { position: relative; }
.auth-modal .password-toggle-btn {
  position: absolute;
  right: 10px;
  top: 35px;
  padding: 0;
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 12px;
}
.auth-modal .btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}
.auth-modal .btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}
.auth-modal .btn-primary:hover { opacity: 0.9; }
.auth-modal .btn-secondary {
  margin-top: 8px;
  background: #fff;
  border: 1px solid #ddd;
  color: #667eea;
}
.auth-modal .btn-secondary:hover { background: #f8f9fa; }
.auth-modal .back-link {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 15px;
  text-align: center;
}
.auth-modal .back-link button {
  padding: 0;
  border: 0;
  background: none;
  color: #667eea;
  font-size: 14px;
  cursor: pointer;
}
.auth-modal .back-link button:hover { text-decoration: underline; }
.auth-modal .verify-hint {
  margin: 0 0 16px;
  color: #666;
  font-size: 14px;
  line-height: 1.4;
}
.auth-modal .login-footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid #eee;
  font-size: 12px;
  color: #666;
}
