body {
  margin: 0;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', sans-serif;
}

#sidebar {
  position: relative;
  top: 0;
  bottom: 0;
  flex-shrink: 0;
  width: 280px;
  height: 100%;
  overflow: hidden;
  padding: 0;
  color: #0f172a;
  box-sizing: border-box;
  border-radius: 0;
  background: #ffffff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border-right: 1px solid #e2e8f0;
}




.sidebar-controls button {
  background: #f1f5f9;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  padding: 8px;
  min-width: 52px;
  cursor: pointer;
  position: relative;
  transition: all 0.25s ease;
  color: #0f172a;
}

.sidebar-controls button i {
  width: 26px;
  height: 26px;
  stroke-width: 2px;
  color: #0f172a;
  transition: color 0.2s;
}

.sidebar-controls button:hover i {
  color: #0f172a;
}

.sidebar-controls button:hover {
  border-color: #94a3b8;
  background: #e2e8f0;
}

.sidebar-controls button::after,
.sidebar-category-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  /* 🟢 показва се над бутона */
  left: 50%;
  transform: translateX(-50%) translateY(-5px) scale(0);
  background: rgba(16, 26, 45, 0.9);
  color: #fff;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.15s ease-in-out;
  z-index: 1000;
}

/* Стрелка под tooltip-а */
.sidebar-controls button::before,
.sidebar-category-btn::before {
  content: "";
  position: absolute;
  bottom: calc(100% - 2px);
  left: 50%;
  transform: translateX(-50%) scale(0);
  border-width: 5px;
  border-style: solid;
  border-color: rgba(16, 26, 45, 0.9) transparent transparent transparent;
  opacity: 0;
  transition: all 0.15s ease-in-out;
  z-index: 1000;
}

.sidebar-controls button:hover::after,
.sidebar-category-btn:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.sidebar-controls button:hover::before,
.sidebar-category-btn:hover::before {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}



#modules {
  display: block;
}

.sidebar-section {
  margin: 0;
  padding: 18px 20px;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  color: #eff5ff;
}

.sidebar-dimensions {
  margin-top: 12px;
  margin-bottom: 18px;
}

.run-height-row {
  border-radius: 999px;
  font-size: 11px;
  background: #cbd5e1;
  color: #0f172a;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.sidebar-section h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #0f172a;
}

.button-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.button-row button {
  flex: 1 1 45%;
  font-size: 12px;
  padding: 8px 10px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  color: #0f172a;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.button-row button:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.sidebar-note {
  font-size: 12px;
  color: #64748b;
  margin: 6px 0 10px;
}

#controls .active,
.button-row button.active {
  background: rgba(141, 178, 255, 0.35);
  border-color: rgba(110, 156, 255, 0.65);
}

#combinations {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#comboCreateBtn {
  display: none;
}

.combo-card {
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #ffffff;
  cursor: pointer;
  transition: box-shadow 120ms ease, transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.combo-card:hover {
  transform: translateY(-1px);
  border-color: #94a3b8;
  background: #f8fafc;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.combo-thumb {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.2) center / cover no-repeat;
  flex-shrink: 0;
}

.combo-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  color: #f0f6ff;
}

.combo-title {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
}

.combo-meta {
  font-size: 11px;
  color: #64748b;
}

.combo-apply {
  align-self: flex-start;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  cursor: pointer;
  transition: background 120ms ease;
  color: #0f172a;
}

.combo-apply:hover {
  background: #e2e8f0;
}

.combo-empty {
  font-size: 12px;
  color: #64748b;
  margin: 0;
}

.module-section {
  margin: 0 0 12px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
  overflow: hidden;
  color: #0f172a;
}

.module-section__summary {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.module-section__summary::-webkit-details-marker {
  display: none;
}

.module-section__summary::after {
  content: '\25BC';
  font-size: 10px;
  transition: transform 0.2s ease;
}

.module-section[open]>.module-section__summary::after {
  transform: rotate(180deg);
}

.module-section__body {
  padding: 10px 14px 14px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

.module-section[open]>.module-section__body {
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.module-section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.module-part-select {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  margin-bottom: 6px;
}

.module-part-select span {
  font-weight: 600;
  color: #0f172a;
}

.module-part-select__control {
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

#modules .module-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  cursor: pointer;
  color: #0f172a;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

#modules .module-card:hover {
  transform: translateY(-2px);
  border-color: #94a3b8;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.module-header {
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
}

.module-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  /* square thumbs */
  object-fit: cover;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.module-thumb:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(10, 16, 28, 0.28);
}

.module-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}

.module-controls select {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #000000;
  padding: 4px 6px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.module-controls select option,
.module-part-select__control option {
  color: #0f1a2b;
  background: #f5f8ff;
}

.module-controls button {
  flex: 1;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #0f172a;
  transition: all 0.15s ease;
}

.module-controls button:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.planner-wrapper {
  --planner-sidebar-width: 320px;
  position: relative;
  display: flex;
  width: 100%;
  height: 100vh;
  /* или 100% ако контейнерът има дефинирана височина */
  overflow: hidden;
}

.module-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: rgba(230, 236, 255, 0.75);
  font-size: 11px;
  margin-top: 6px;
}

.module-tag {
  display: inline-block;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #000000;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 500;
}

.planner-stage {
  position: relative;
  flex: 1;
  display: flex;
}

#scene {
  flex: 1;
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.planner-camera-controls {
  position: absolute;
  left: calc(var(--planner-sidebar-width, 320px) + (100% - var(--planner-sidebar-width, 320px)) * 0.03);
  bottom: 153px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transform: translateX(-50%);
  z-index: 40;
}

.planner-camera-controls button {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(15, 26, 43, 0.85);
  color: #eef4ff;
  cursor: pointer;
  box-shadow: 0 18px 36px rgba(7, 10, 18, 0.55);
  backdrop-filter: blur(8px);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, color 0.2s ease;
  position: relative;
}

.planner-camera-controls button i {
  width: 32px;
  height: 32px;
  stroke-width: 2px;
  color: currentColor;
  transition: color 0.2s;
}

.planner-camera-controls button::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) scale(0.85);
  background: rgba(16, 26, 45, 0.94);
  color: #fff;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.15s ease-in-out;
}

.planner-camera-controls button::before {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 6px 6px 6px 0;
  border-color: transparent rgba(16, 26, 45, 0.94) transparent transparent;
  left: calc(100% + 2px);
  top: 50%;
  transform: translateY(-50%) scale(0.8);
  opacity: 0;
  pointer-events: none;
  transition: all 0.15s ease-in-out;
}

.planner-camera-controls button:hover {
  background: rgba(33, 51, 78, 0.92);
  border-color: rgba(138, 177, 255, 0.65);
  transform: translateY(-2px);
  color: #fff;
}

.planner-camera-controls button.active {
  background: rgba(33, 51, 78, 0.98);
  border-color: rgba(138, 177, 255, 0.8);
  color: #fff;
}

.planner-camera-controls button:hover::after,
.planner-camera-controls button:hover::before {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

@media (max-width: 960px) {
  .planner-wrapper {
    --planner-sidebar-width: 0px;
  }

  .planner-camera-controls {
    left: 50%;
    bottom: 16px;
    gap: 10px;
    transform: translateX(-50%);
  }

  .planner-camera-controls button {
    width: 48px;
    height: 48px;
  }
}

#sidebarMenuToggle {
  width: 40px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: rgb(39 166 217 / 70%);
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

#sidebarMenuToggle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: #f5f7ff;
  display: block;
}

#sidebarMenuToggle:hover {
  background: rgba(173, 207, 255, 0.25);
  border-color: rgba(173, 207, 255, 0.6);
}

.lighting-toggle {
  position: absolute;
  right: 32px;
  bottom: 150px;
  z-index: 30;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 10px 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 26, 43, 0.85);
  color: #eef4ff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 18px 40px rgba(7, 10, 18, 0.5);
  backdrop-filter: blur(8px);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.lighting-toggle:hover {
  transform: translateY(-1px);
  background: rgba(33, 51, 78, 0.92);
  box-shadow: 0 22px 42px rgba(7, 10, 18, 0.65);
}

.lighting-toggle__icon {
  font-size: 1.1rem;
  line-height: 1;
}

.lighting-toggle[data-mode="night"] {
  border-color: rgba(132, 173, 255, 0.45);
  background: rgba(7, 12, 22, 0.9);
}

@media (max-width: 768px) {
  .lighting-toggle {
    right: 16px;
    bottom: 16px;
    padding: 8px 14px;
  }
}

/* Toolbar at top of sidebar */
#toolbar {
  position: relative;
  top: 0;
  background: #f1f5f9;
  padding-bottom: 6px;
  z-index: 11;
  border-bottom: 1px solid #e2e8f0;
}

#priceBox {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #0f172a;
}

#controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

#controls button {
  flex: 1 1 48%;
  font-size: 12px;
}

.toolbar-panel {
  margin-bottom: 10px;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.toolbar-panel__summary {
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  color: #1f1f1f;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toolbar-panel__summary::-webkit-details-marker {
  display: none;
}

.toolbar-panel__summary::after {
  content: '\25BC';
  font-size: 10px;
  transition: transform 0.2s ease;
}

.toolbar-panel[open]>.toolbar-panel__summary::after {
  transform: rotate(180deg);
}

.toolbar-panel__body {
  padding: 8px 10px 12px;
  max-height: 240px;
  overflow: auto;
}

#sizeTooltipTop,
#sizeTooltipRight {
  position: fixed;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 1001;
  transform: translate(-50%, -70%);
}

#sizeTooltipRight {
  transform: translate(0, -50%);
}

/* Small shelf rung up/down controls */
.rung-controls {
  display: inline-flex;
  gap: 6px;
  margin-left: 8px;
  vertical-align: middle;
}

.rung-btn {
  padding: 2px 6px;
  line-height: 1;
  font-size: 12px;
  cursor: pointer;
}

.rung-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Floating shelf rung stepper near the selected shelf */
.rung-float {
  position: absolute;
  z-index: 4000;
  display: none;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 4px 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  overflow: visible;
}

.rung-float .rung-btn {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 2px;
  background: transparent;
  border: none;
  color: #333;
  cursor: pointer;
  border-radius: 6px;
  pointer-events: auto;
}

.rung-float .rung-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.rung-float .rung-btn i {
  font-size: 14px;
  line-height: 1;
}

.rung-float .rung-select {
  pointer-events: auto;
  font-size: 12px;
  height: 26px;
  min-width: 140px;
}

/* [NEW] Elevation Control (Vertical Slider) */
.rung-elevation-control {
  position: absolute;
  bottom: 40px;
  /* Above the button row */
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 5000;
  min-width: 60px;
  pointer-events: auto;
}

.rung-elevation-control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: 100px;
  /* Logical length of slider */
  height: 24px;
  /* Touch target size */
  cursor: pointer;
  /* Rotate to make vertical */
  transform: rotate(-90deg);
  /* Compensate for rotation layout shift */
  margin: 38px -38px;
}

/* Custom Track Styles */
.rung-elevation-control input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
}

.rung-elevation-control input[type="range"]::-moz-range-track {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
}

/* Custom Thumb Styles */
.rung-elevation-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: #0f172a;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  margin-top: -7px;
  /* (TrackHeight 6 - ThumbHeight 18) / 2 */
  transition: transform 0.1s ease;
}

.rung-elevation-control input[type="range"]::-moz-range-thumb {
  border: none;
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: #0f172a;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s ease;
}

.rung-elevation-control input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.1);
  background: #3b82f6;
}

.rung-elevation-control input[type="range"]:active::-moz-range-thumb {
  transform: scale(1.1);
  background: #3b82f6;
}

.rung-elevation-control input[type="number"] {
  width: 60px;
  text-align: center;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  padding: 2px;
}

.rung-elevation-control span {
  font-size: 10px;
  color: #666;
}

.project-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 6px;
}

.project-item button {
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: #1a4d8f;
  cursor: pointer;
}

.project-item button:hover {
  text-decoration: underline;
}

.project-meta {
  font-size: 11px;
  color: #777;
}

.module-footer {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
}

.module-price {
  font-size: 12px;
  font-weight: 600;
  color: #1d2d44;
  margin-right: auto;
}

.module-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  text-decoration: none;
  color: #f1f6ff;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.module-action:hover {
  background: rgba(148, 188, 255, 0.22);
  border-color: rgba(148, 188, 255, 0.35);
  color: #f1f6ff;
}

.module-action.cart {
  border-color: rgba(47, 176, 117, 0.6);
  color: #1fd48c;
}

.module-action.cart:hover {
  background: rgba(31, 212, 140, 0.28);
  border-color: rgba(31, 212, 140, 0.45);
}

.module-action.view {
  border-color: rgba(255, 255, 255, 0.26);
  color: #f4f7ff;
}

.module-action.view:hover {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.32);
}

.module-action.scene {
  border-color: rgba(90, 140, 255, 0.6);
}

.sidebar-top-controls {
  margin-bottom: 10px;
  position: relative;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 0;
  position: relative;
}

.sidebar-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-header-top #priceBox {
  flex: 1;
}

.sidebar-header .sidebar-primary-btn {
  align-self: stretch;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  display: inline-flex;
  justify-content: flex-start;
}

.sidebar-menu-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  flex-shrink: 0;
}

.sidebar-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: #0f172a;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.sidebar-menu-btn span:nth-child(2) {
  width: 14px;
}

.sidebar-menu-btn span:nth-child(3) {
  width: 10px;
}

.sidebar-menu-btn:hover {
  border-color: #94a3b8;
  background: #e2e8f0;
}

.sidebar-menu-btn.is-active span:nth-child(1) {
  transform: translateY(5px) rotate(45deg);
}

.sidebar-menu-btn.is-active span:nth-child(2) {
  opacity: 0;
}

.sidebar-menu-btn.is-active span:nth-child(3) {
  width: 18px;
  transform: translateY(-5px) rotate(-45deg);
}

.sidebar-primary-btn,
.sidebar-secondary-btn,
.sidebar-category-btn,
.sidebar-back-btn {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sidebar-primary-btn {
  background: linear-gradient(135deg, #66a6ff 0%, #89f7fe 100%);
  border-color: transparent;
  color: #0b1a33;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 18px 30px rgba(64, 138, 255, 0.28);
}

.sidebar-primary-btn:hover {
  background: linear-gradient(135deg, #5b96ff 0%, #7defff 100%);
}

.sidebar-secondary-btn {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #0f172a;
  font-weight: 500;
  text-align: center;
}

.sidebar-secondary-btn:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
  color: #0f172a;
}

.sidebar-category-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.sidebar-category-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #000000;
  text-align: center;
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px !important;
  font-size: 9px;
  font-weight: 500;
  line-height: 1.2;
  aspect-ratio: 1 / 1;
  min-height: auto;


  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  border-radius: 12px;
  position: relative;
}

.sidebar-category-btn span {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}


.sidebar-category-btn:hover {
  border-color: #94a3b8;
  background: #f1f5f9;
  transform: translateY(-2px);
  color: #0f172a;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
}

.sidebar-category-btn.is-active {
  background: #eff6ff;
  border-color: #60a5fa;
  color: #1d4ed8;
  box-shadow: 0 8px 16px rgba(59, 130, 246, 0.15);
}

.sidebar-screen {
  display: none;
}

.sidebar-screen.is-active {
  display: block;
}

.sidebar-screen-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.sidebar-screen-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1d2a3b;
}

.sidebar-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: #f4f7ff;
  padding: 8px 12px;
  border-radius: 999px;
}

.sidebar-back-btn:hover {
  background: rgba(154, 191, 255, 0.25);
  border-color: rgba(157, 198, 255, 0.4);
}

.sidebar-screen-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
  justify-content: center;
}

/* Global button override for reset.css conflict */
.sidebar-category-list button {
  background-color: #f1f5f9 !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 12px !important;
  color: #000000 !important;
  display: inline-block !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  padding: 8px 10px !important;
  text-align: center !important;
  transition: all .25s ease !important;
  cursor: pointer !important;
}

.sidebar-screen-header button {
  background-color: #f1f5f9 !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: 12px !important;
  color: #000000 !important;
  display: inline-block !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  padding: 8px 10px !important;
  text-align: center !important;
  transition: all .25s ease !important;
  cursor: pointer !important;
}

[type=button]:hover,
[type=submit]:hover,
button:hover {
  background: #e2e8f0 !important;
  border-color: #94a3b8 !important;
  color: #0f172a !important;
}

.sidebar-controls button {
  background: #f1f5f9;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  padding: 8px;
  min-width: 52px;
  margin: 0;
  cursor: pointer;
  position: relative;
  transition: all 0.25s ease;
  color: #000000;
}

.sidebar-controls button:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.sidebar-price {
  font-weight: 600;
  font-size: 18px;
  color: #000;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.sidebar-category-btn i,
.sidebar-combos-btn i {
  width: 18px;
  height: 18px;
  color: currentColor;
}

.sidebar-combos-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  transition: all 0.2s ease;
}

.sidebar-combos-btn:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.sidebar-menu-panel {
  /* Moved to root, position absolute to overlay everything */
  position: absolute;
  top: 80px;
  left: 20px;
  width: 260px;
  /* Fixed width to fit content */
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  /* Always on top */
}

.sidebar-menu-panel.is-open {
  display: flex !important;
  z-index: 9999;
}

.sidebar-menu-link {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  background: transparent;
  color: #0f172a;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.sidebar-menu-link i {
  width: 18px;
  height: 18px;
}

.sidebar-menu-link span {
  flex: 1;
  text-align: left;
}

.sidebar-menu-link:hover {
  background: #f1f5f9;
  color: #0f172a;
  transform: translateY(-1px);
}

.planner-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(1px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  /* [FIX] Ensure above mobile sidebar (2000) */
}

.planner-modal.hidden {
  display: none;
}

.planner-modal__dialog {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.96) 0%, rgba(230, 238, 255, 0.92) 100%);
  border-radius: 16px;
  width: min(460px, 92%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 28px 60px rgba(12, 22, 42, 0.28);
}

.planner-modal__header,
.planner-modal__footer {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.planner-modal__body {
  padding: 12px 20px 20px;
  overflow-y: auto;
}

.finalize-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.finalize-preview {
  position: relative;
  border: 1px solid rgba(15, 26, 43, 0.12);
  border-radius: 12px;
  overflow: visible;
  background: rgba(12, 22, 39, 0.08);
}

.finalize-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: rgba(12, 22, 39, 0.12);
}

.finalize-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.planner-modal__list {
  margin-bottom: 12px;
}

.planner-modal__items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.planner-modal__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(12, 32, 58, 0.12);
}

.planner-modal__item:last-child {
  border-bottom: none;
}

.planner-modal__item-name {
  font-weight: 600;
  color: #22355a;
}

.planner-modal__item-qty,
.planner-modal__item-color {
  font-size: 12px;
  color: #4c5c7d;
}

.planner-modal__total {
  font-weight: 600;
  font-size: 13px;
  color: #203457;
}

.planner-modal__close {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #3a4c70;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.planner-modal__close:hover {
  color: #17284b;
}

.planner-modal__empty {
  font-size: 13px;
  color: #4c5c7d;
}

body.planner-modal-open {
  overflow: hidden;
}

@media (max-width: 640px) {
  .planner-modal__dialog {
    width: min(100%, 420px);
  }

  .finalize-layout {
    flex-direction: column;
  }
}

#sidebar .sidebar-inner {
  height: 100%;
  box-sizing: border-box;
  padding: 28px 24px 20px;
  overflow-y: auto;
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

#sidebar .sidebar-inner::-webkit-scrollbar {
  width: 8px;
}

#sidebar .sidebar-inner::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 999px;
}



#sidebar .sidebar-inner::-webkit-scrollbar-track {
  background: transparent;
}

/* Yellow gap lines and labels - hidden by default, visible during drag */
.run-gap-line {
  position: absolute;
  height: 2px;
  background: rgba(255, 214, 102, 0.9);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.run-gap-label {
  position: absolute;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  pointer-events: none;
  transform: translate(-50%, -120%);
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* Show lines and labels during drag */
body.dragging-active .run-gap-line,
body.dragging-active .run-gap-label {
  opacity: 1;
  transition: none;
  /* Disable transition during drag for instant updates */
}

/* Arrow styles for gap lines */
.run-gap-line::before,
.run-gap-line::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border-style: solid;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.run-gap-line::before {
  left: 0;
  transform: translate(-100%, -50%);
  border-width: 5px 8px 5px 0;
  border-color: transparent rgba(255, 214, 102, 0.9) transparent transparent;
}

.run-gap-line::after {
  right: 0;
  transform: translate(100%, -50%);
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent rgba(255, 214, 102, 0.9);
}

/* Show arrows during drag */
body.dragging-active .run-gap-line::before,
body.dragging-active .run-gap-line::after {
  opacity: 1;
  transition: none;
  /* Disable transition during drag */
}

/* --- SIDEBAR SCREEN NAVIGATION --- */
.sidebar-screen {
  display: none;
  width: 100%;
  animation: fadeOut 0.2s ease forwards;
  /* [FIX] Mobile Layout: Flex to fill/shrink correctly */
  flex: none;
  min-height: auto;
  flex-direction: column;
}

.sidebar-screen.is-active {
  display: flex !important;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.3s ease forwards;
  padding-bottom: 150px;
}

.sidebar-screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e2e8f0;
}

.sidebar-screen-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
}

.sidebar-back-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  cursor: pointer;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  transition: all 0.2s;
  border-radius: 8px;
}

.sidebar-back-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #94a3b8;
}

.sidebar-back-btn i {
  width: 16px;
  height: 16px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* --- Flyout Sidebar Redesign --- */
#sidebar {
  overflow: visible !important;
  /* Allow flyout to overflow */
}

/* Category Screen (Flyout) */
#sidebarCategoryScreen {
  position: absolute;
  top: 0;
  left: 100%;
  width: 280px;
  height: 100%;
  background: #ffffff;
  border-left: 1px solid #e2e8f0;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.05);
  transform: translateX(-20px);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease, visibility 0.3s;
  z-index: 10;
}

#sidebarCategoryScreen.is-active,
#sidebarCategoryScreen.is-open {
  transform: translateX(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Ensure Home stays visible */
#sidebarHome {
  position: relative;
  z-index: 20;
  /* Above flyout shadow */
  background: inherit;
  /* Maintain background */
}

/* Adjust Module Grid in Flyout */
#sidebarCategoryContent {
  padding: 12px;
  overflow-y: auto;
  height: calc(100% - 50px);
  /* Header height */
}

/* Category List Items - Add active state styling */
/* Category List Items - Add active state styling */
.sidebar-category-list button.is-active {
  background: #eff6ff;
  border-color: #60a5fa;
  color: #1d4ed8;
}

/* Mobile check */
@media (max-width: 960px) {
  #sidebarCategoryScreen {
    position: absolute;
    left: 0;
    width: 100%;
    z-index: 30;
    /* On top of home on mobile */
  }
}


/* --- Fixed Flyout Positioning (Post-Reparenting) --- */
#sidebarCategoryScreen {
  position: absolute !important;
  top: 32px !important;
  /* Match sidebar top */
  left: 360px !important;
  /* 340px sidebar + 20px gap */
  height: calc(100vh - 64px) !important;
  /* Match sidebar height approx */
  bottom: auto !important;
  right: auto !important;
  border-radius: 12px !important;
  z-index: 100 !important;
  /* Above canvas */
}


/* --- Mobile Responsive Sidebar (Bottom Sheet) --- */
@media (max-width: 960px) {

  /* Transform Sidebar into Bottom Sheet */
  #sidebar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    top: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: 80vh !important;
    border-radius: 20px 20px 0 0 !important;
    transform: translateY(110%);
    /* Hidden by default */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000 !important;
    border-top: 1px solid #cbd5e1;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15) !important;
    border-right: none !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }

  /* Open State */
  #sidebar.mobile-open {
    transform: translateY(0);
  }

  /* Ensure Category Screen fills the Sheet */
  #sidebarCategoryScreen {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    box-shadow: none !important;
  }

  /* [FIX] Fix White Screen / Mobile Height */
  #sidebarCategoryContent {
    height: auto !important;
    min-height: 0 !important;
    flex: 1 !important;
    overflow-y: auto !important;
  }

  /* Hide Desktop Toggle inside sidebar */
  #sidebarMenuToggle {
    display: none !important;
  }

  /* New Mobile Toggle FAB (Created via JS) */
  #mobileSidebarToggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #0f172a;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    z-index: 2005;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
  }

  #mobileSidebarToggle:active {
    transform: scale(0.95);
    background: #1e293b;
  }

  #mobileSidebarToggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: white;
    border-radius: 2px;
    position: absolute;
    transition: all 0.2s ease;
  }

  #mobileSidebarToggle span:nth-child(1) {
    transform: translateY(-6px);
  }

  #mobileSidebarToggle span:nth-child(2) {
    opacity: 1;
  }

  #mobileSidebarToggle span:nth-child(3) {
    transform: translateY(6px);
  }

  /* Close State Icon (X) */
  #mobileSidebarToggle.is-active span:nth-child(1) {
    transform: rotate(45deg);
  }

  #mobileSidebarToggle.is-active span:nth-child(2) {
    opacity: 0;
  }

  #mobileSidebarToggle.is-active span:nth-child(3) {
    transform: rotate(-45deg);
  }

  /* [FIX] Mobile Scene Controls: Horizontal Toolbar (Bottom Right) */
  .planner-camera-controls {
    position: fixed !important;
    top: auto !important;
    bottom: 20px !important;
    left: auto !important;
    right: 20px !important;
    transform: none !important;

    display: flex !important;
    flex-direction: row !important;
    gap: 8px !important;
    /* [FIX] Smaller gap */

    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    padding: 6px 12px;
    /* [FIX] Compact padding */
    border-radius: 999px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    z-index: 50;
    /* Above canvas */
    width: max-content;
  }

  .planner-camera-controls button {
    width: 32px !important;
    /* [FIX] Smaller buttons (Was 40px) */
    height: 32px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: center !important;
    background: transparent !important;
    border: none !important;
    color: #0f172a !important;
  }

  .planner-camera-controls button.active {
    background: #e2e8f0 !important;
    border-radius: 50% !important;
    color: #2563eb !important;
  }
}

/* Floating Color Palette */
.rung-palette {
  position: absolute;
  bottom: 45px;
  /* Above the toolbar */
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  display: block;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  width: max-content;
  max-width: 450px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 9999;
  border: 1px solid #e5e7eb;
  pointer-events: auto !important;
}

.rung-palette::-webkit-scrollbar {
  width: 4px;
}

.rung-palette::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.palette-swatch {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  cursor: pointer;
  background-size: cover;
  pointer-events: auto !important;
  background-position: center;
  background-repeat: no-repeat;
  transition: all 0.15s ease;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  position: relative;
  background-color: #f0f0f0;
  appearance: none;
  -webkit-appearance: none;
}

.palette-swatch:hover {
  transform: translateY(-2px);
  border-color: #999;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  z-index: 2;
}

.palette-swatch.active {
  border: 2px solid #2563eb;
  /* Blue highlight */
  box-shadow: 0 0 0 1px #2563eb;
}