:root {
  --bg: #f0f0f0;
  --panel: #ffffff;
  --panel-2: #fcfcfc;
  --border: #e0e0e0;
  --text: #37373a;
  --text-2: #6b6f7d;
  --accent: #344358;
  --accent-hover: #2c3849;
  --accent-soft: #f0f4f8;
  --shadow: 0 6px 24px rgba(20, 22, 30, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- App Layout ---------- */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ---------- Canvas area ---------- */
.canvas-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

.scene-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
  user-select: none;
}

/* ---------- Right sidebar (modeled on zzcustom-furniture-modeller) ---------- */
#sidebar {
  width: 400px;
  flex-shrink: 0;
  background: #fff;
  border-left: 1px solid var(--border);
  height: 100%;
  min-height: 0;
  z-index: 10;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  touch-action: pan-y;
}

.brand {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.4px;
  color: var(--accent);
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 4px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: background 0.15s, color 0.15s;
}

.tab:hover { background: var(--panel-2); }

.tab.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Scrollable middle (parts/fabric) ---------- */
#ui-scroll-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#ui {
  padding: 14px 18px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: pan-y;
  box-sizing: border-box;
}

#ui h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hint {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--text-2);
}

/* ---------- Field controls ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}

.field input,
.field select {
  font-family: inherit;
  font-size: 13px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  outline: none;
  text-transform: none;
  font-weight: 400;
  letter-spacing: normal;
}

.field input:focus,
.field select:focus { border-color: var(--accent); }

.field input[type="color"] {
  height: 36px;
  padding: 4px;
  cursor: pointer;
}

/* ---------- Part library ---------- */
.part-library {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.part-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}

.part-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.part-card svg {
  width: 60px;
  height: 60px;
}

.part-card .name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.part-card .price {
  font-size: 11px;
  color: var(--text-2);
}

/* ---------- Swatches ---------- */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
  cursor: pointer;
}

.swatch.active {
  box-shadow: 0 0 0 2px var(--accent);
}

/* ---------- Price panel (bottom of sidebar) — exact match to zzcustom-furniture-modeller ---------- */
#pricePanel {
  padding: 18px;
  background: #fcfcfc;
  box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.03);
  flex-shrink: 0;
}

#pricePanel h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: #344358;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.view-price-details-btn {
  background: none;
  border: none;
  color: #344358;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 12px;
  transition: background 0.2s;
}

.view-price-details-btn:hover {
  background: rgba(52, 67, 88, 0.1);
}

.priceItem {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13px;
  border-bottom: 1px solid #eee;
}

.priceLabel { color: #37373a; }

.priceValue {
  font-weight: 600;
  color: #37373a;
  font-family: 'Poppins', sans-serif;
}

.empty-summary {
  font-size: 12px;
  color: var(--text-2);
  text-align: center;
  padding: 12px 4px;
}

/* Total */
#totalPrice {
  margin: 0;
  padding-top: 0;
  border-top: 1px solid #ddd;
}

.delivery-divider {
  border-top: 1px solid #ddd;
  margin: 8px 0;
}

.totalPriceRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
}

.totalLabel {
  font-size: 16px;
  font-weight: 700;
  color: #37373a;
}

.totalValue {
  font-size: 20px;
  font-weight: 700;
  color: #37373a;
  font-family: 'Poppins', sans-serif;
}

/* Delivery */
.delivery-time-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 1px;
  background: #f8f9fa;
  border-radius: 8px;
  margin-top: 1px;
  margin-bottom: 0;
  width: 100%;
  box-sizing: border-box;
}

.delivery-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.delivery-icon {
  width: 18px;
  height: auto;
  opacity: 0.9;
}

.delivery-label {
  font-size: 12px;
  font-weight: 600;
  color: #344358;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.delivery-date {
  font-size: 12px;
  font-weight: 700;
  color: #344358;
}

/* Buttons */
.addToCartButton {
  width: 100%;
  padding: 15px;
  background: #344358;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 10px;
  transition: background 0.15s;
}

.addToCartButton:hover { background: #2c3849; }

.saveConfigButton {
  width: 100%;
  padding: 15px;
  background: white;
  color: #344358;
  border: 1px solid #344358;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 10px;
  transition: background 0.15s;
}

.saveConfigButton:hover { background: #f0f4f8; }

/* ---------- Price drawer (slides up from bottom of sidebar) ---------- */
.price-slider-overlay {
  background: rgba(0, 0, 0, 0.45);
  z-index: 5000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.price-slider-overlay:has(.active) {
  opacity: 1;
  visibility: visible;
}

.price-slider-content {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 18px 20px 20px;
  box-shadow: 0 -6px 22px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
  max-height: 80%;
  display: flex;
  flex-direction: column;
}

.price-slider-content.active { transform: translateY(0); }

.price-slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f0f0f0;
}

.price-slider-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
}

.price-slider-close {
  background: #f5f5f5;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}

.price-slider-close:hover { background: #e0e0e0; }

.price-slider-list {
  overflow-y: auto;
  margin-bottom: 14px;
  flex: 1;
  min-height: 0;
}

.priceItem {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f4f4f4;
  font-size: 13px;
}

.priceLabel { color: #555; }

.priceValue {
  color: var(--text);
  font-weight: 600;
  font-family: 'Poppins', sans-serif;
}

.price-slider-total {
  margin-top: auto;
  padding-top: 12px;
  border-top: 2px solid #f5f5f5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

/* ---------- SVG part styles ---------- */
.scene-part { cursor: grab; }
.scene-part.dragging { cursor: grabbing; }
.scene-part .selection-outline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 4 3;
  pointer-events: none;
}
.scene-part .rotate-handle {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2;
  cursor: grab;
}
.scene-part .delete-handle {
  fill: #c64646;
  stroke: #fff;
  stroke-width: 2;
  cursor: pointer;
}

.scene-floor { /* fill set inline */ }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app {
    flex-direction: column;
  }
  #sidebar {
    width: 100%;
    max-height: 55vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}
