:root {
  --bg: #141a26;
  --bg2: #202d42;
  --panel: rgba(32, 45, 66, 0.82);
  --panel2: rgba(59, 69, 86, 0.72);
  --accent: #f2cc83;
  --accentStrong: #d6a94f;
  --green: #296117;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: rgba(148, 163, 184, 0.32);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
  --radius: 22px;
  --radius2: 14px;
  --danger: #fb7185;
  --ok: #86efac;
  --warn: #facc15;
  --input: rgba(15, 23, 42, 0.58);
}

[data-theme="light"] {
  --bg: #f7ecd4;
  --bg2: #faefdc;
  --panel: rgba(255, 247, 231, 0.9);
  --panel2: rgba(242, 204, 131, 0.32);
  --accent: #296117;
  --accentStrong: #1f4d12;
  --green: #296117;
  --text: #1f2937;
  --muted: #6b7280;
  --border: rgba(120, 113, 108, 0.28);
  --shadow: 0 18px 42px rgba(88, 70, 30, 0.16);
  --input: rgba(255, 255, 255, 0.76);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at top left, rgba(242, 204, 131, 0.16), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(41, 97, 23, 0.18), transparent 32rem),
    linear-gradient(135deg, var(--bg), var(--bg2));
  color: var(--text);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.62rem 0.9rem;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

button:hover {
  border-color: rgba(242, 204, 131, 0.75);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

select,
.numberInput {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--text);
  border-radius: 12px;
  padding: 9px 10px;
  outline: none;
}

select:focus,
.numberInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(242, 204, 131, 0.14);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="checkbox"] {
  width: 40px;
  height: 22px;
  margin: 0;
  appearance: none;
  border: 1px solid rgba(242, 204, 131, 0.48);
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  position: relative;
  cursor: pointer;
  transition: 160ms ease;
}

input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 2px;
  left: 3px;
  border-radius: 50%;
  background: var(--muted);
  transition: 160ms ease;
}

input[type="checkbox"]:checked {
  background: rgba(242, 204, 131, 0.28);
}

input[type="checkbox"]:checked::after {
  left: 19px;
  background: var(--accent);
}

.appShell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  padding: 14px;
}

/* Topbar */

.topbar {
  min-height: 72px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(32, 45, 66, 0.9), rgba(32, 45, 66, 0.62));
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
}

[data-theme="light"] .topbar {
  background: linear-gradient(135deg, rgba(255, 247, 231, 0.92), rgba(250, 239, 220, 0.76));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brandMark {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: #141a26;
  font-weight: 900;
  background: linear-gradient(135deg, #f7e4b5, #f2cc83 48%, #c79c45);
  box-shadow: 0 12px 28px rgba(242, 204, 131, 0.22);
}

.brandText strong {
  display: block;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}

.brandText span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.topActions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.primaryBtn {
  background: linear-gradient(135deg, var(--accent), var(--accentStrong));
  color: #141a26;
  border-color: rgba(242, 204, 131, 0.85);
  font-weight: 850;
}

[data-theme="light"] .primaryBtn {
  color: #f9fafb;
}

.ghostBtn {
  background: rgba(255, 255, 255, 0.04);
}

.homeLink {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--panel2);
  border-radius: 999px;
  padding: 0.58rem 0.86rem;
  white-space: nowrap;
  transition: 160ms ease;
}

.homeLink:hover {
  border-color: rgba(242, 204, 131, 0.75);
  transform: translateY(-1px);
}

.homeLogo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}

.arrow {
  margin-left: 6px;
  opacity: 0.78;
}

/* Workspace */

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 292px minmax(420px, 1fr) 360px;
  gap: 14px;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panelHeader {
  min-height: 58px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.panelHeader h2 {
  margin: 0;
  font-size: 0.94rem;
  letter-spacing: 0.02em;
}

.panelHeader span {
  color: var(--muted);
  font-size: 0.78rem;
}

.panelBody {
  padding: 14px;
}

.leftPanel,
.rightPanel,
.viewerPanel {
  min-height: 680px;
}

/* Left panel */

.microHint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.sectionTitle {
  margin: 18px 0 9px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 850;
}

.sectionTitle:first-of-type {
  margin-top: 0;
}

.productGroup {
  display: grid;
  gap: 8px;
}

.productItem {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
}

.productItem strong {
  display: block;
  font-size: 0.9rem;
}

.productItem small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  font-size: 0.76rem;
}

.productItem.active {
  border-color: rgba(242, 204, 131, 0.85);
  background: rgba(242, 204, 131, 0.13);
}

.productItem.planned {
  opacity: 0.88;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.7rem;
  border: 1px solid var(--border);
  color: var(--muted);
  font-style: normal;
}

.badge.active {
  color: #141a26;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 850;
}

.modelTree {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.modelTree li {
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  font-size: 0.86rem;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.modelTree li strong {
  color: var(--accent);
}

/* Viewer */

.viewerPanel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.viewerHeader {
  align-items: flex-start;
}

.viewerToolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.viewerToolbar button {
  padding: 0.5rem 0.74rem;
  font-size: 0.82rem;
}

.viewerToolbar button.isActive {
  background: rgba(242, 204, 131, 0.16);
  border-color: rgba(242, 204, 131, 0.72);
  color: var(--accent);
}

.viewerWrap {
  position: relative;
  min-height: 600px;
  margin: 14px;
  border-radius: calc(var(--radius) + 4px);
  overflow: hidden;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at 50% 28%, rgba(242, 204, 131, 0.13), transparent 28rem),
    linear-gradient(145deg, rgba(15, 23, 42, 0.94), rgba(20, 26, 38, 0.98));
}

[data-theme="light"] .viewerWrap {
  background:
    radial-gradient(circle at 50% 28%, rgba(41, 97, 23, 0.13), transparent 28rem),
    linear-gradient(145deg, rgba(255, 252, 242, 0.96), rgba(250, 239, 220, 0.98));
}

.sceneMount {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.sceneMount canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.viewerOverlay {
  position: absolute;
  z-index: 5;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.62);
  color: var(--text);
  border-radius: 14px;
  padding: 9px 11px;
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
  pointer-events: none;
}

[data-theme="light"] .viewerOverlay {
  background: rgba(255, 247, 231, 0.76);
}

.viewerOverlay strong {
  display: block;
  font-size: 0.86rem;
}

.viewerOverlay span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 3px;
}

.topLeft {
  top: 14px;
  left: 14px;
}

.topRight {
  top: 14px;
  right: 14px;
}

.bottomLeft {
  left: 14px;
  bottom: 14px;
}

.axisOverlay {
  display: grid;
  gap: 4px;
  min-width: 70px;
}

.axisOverlay span {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 0;
}

.axisOverlay i {
  width: 18px;
  height: 3px;
  border-radius: 999px;
  display: inline-block;
}

.axisX {
  background: #fb7185;
}

.axisY {
  background: #86efac;
}

.axisZ {
  background: #60a5fa;
}

/* Controls */

.controlsBody {
  display: grid;
  gap: 12px;
}

.controlGroup {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.035);
}

.controlGroup h3 {
  margin: 0 0 12px;
  font-size: 0.88rem;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field > span:first-child {
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field strong {
  color: var(--text);
  font-weight: 850;
}

.rangeRow {
  display: grid;
  grid-template-columns: 1fr 78px 38px;
  gap: 8px;
  align-items: center;
}

.rangeRow.compact {
  grid-template-columns: 1fr 72px 42px;
}

.rangeRow em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.82rem;
}

.toggleGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.82rem;
}

.materialPreview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.matChip {
  min-height: 54px;
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 8px;
  display: grid;
  align-items: end;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 850;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.48);
  overflow: hidden;
}

.matChip.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mLight {
  background: linear-gradient(135deg, #e0bd7c, #8b5a2b);
}

.mDark {
  background: linear-gradient(135deg, #7a4e27, #2b1a0d);
}

.mWhite {
  background: linear-gradient(135deg, #ffffff, #cbd5e1);
  color: #1f2937;
  text-shadow: none;
}

.mBlack {
  background: linear-gradient(135deg, #111827, #020617);
}

.mGray {
  background: linear-gradient(135deg, #9ca3af, #374151);
}

.mAccent {
  background: linear-gradient(135deg, #f2cc83, #296117);
}

/* Bottom */

.bottomPanel {
  min-height: 164px;
}

.bottomPanel.isCollapsed {
  min-height: 0;
}

.bottomPanel.isCollapsed .bottomContent {
  display: none;
}

.bottomContent {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 14px;
  padding: 14px;
}

.tableWrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 14px;
  font-size: 0.86rem;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.035);
}

td {
  color: var(--text);
}

.statusStack {
  display: grid;
  gap: 9px;
  align-content: start;
}

.statusCard {
  border: 1px solid var(--border);
  border-radius: 15px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.statusCard strong {
  color: var(--text);
  display: block;
  margin-bottom: 3px;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  max-width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.88);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 200ms ease;
  z-index: 50;
}

[data-theme="light"] .toast {
  background: rgba(255, 247, 231, 0.95);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.visuallyHidden {
  position: fixed;
  left: -9999px;
  top: -9999px;
  opacity: 0;
}

/* Responsive */

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 260px minmax(390px, 1fr) 330px;
  }

  .rangeRow {
    grid-template-columns: 1fr 70px 34px;
  }
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .leftPanel,
  .rightPanel,
  .viewerPanel {
    min-height: auto;
  }

  .viewerPanel {
    order: 1;
  }

  .leftPanel {
    order: 2;
  }

  .rightPanel {
    order: 3;
  }

  .viewerWrap {
    min-height: 680px;
  }

  .bottomContent {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topActions {
    justify-content: flex-start;
    width: 100%;
  }
}

@media (max-width: 740px) {
  .appShell {
    padding: 10px;
    gap: 10px;
  }

  .topbar,
  .panel {
    border-radius: 18px;
  }

  .brand {
    min-width: 0;
  }

  .brandMark {
    width: 42px;
    height: 42px;
  }

  .topActions button,
  .homeLink {
    flex: 1 1 auto;
    justify-content: center;
  }

  .viewerHeader {
    flex-direction: column;
  }

  .viewerToolbar {
    justify-content: flex-start;
  }

  .viewerToolbar button {
    flex: 1 1 auto;
  }

  .viewerWrap {
    min-height: 540px;
    margin: 10px;
  }

  .topRight {
    display: none;
  }

  .bottomLeft {
    right: 14px;
  }

  .rangeRow,
  .rangeRow.compact {
    grid-template-columns: 1fr 72px 34px;
  }

  .materialPreview {
    grid-template-columns: repeat(2, 1fr);
  }

  .toggleGrid {
    grid-template-columns: 1fr;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.03);
  }

  td {
    border-bottom: 0;
    padding: 6px 8px;
  }

  td::before {
    content: attr(data-label) ": ";
    color: var(--muted);
    font-weight: 800;
  }
}