:root {
  color-scheme: light;
  --brand: #2f3b97;
  --brand-dark: #202b78;
  --brand-soft: #eef0ff;
  --bg: #f4f5f6;
  --surface: #ffffff;
  --scene: #e9edef;
  --ink: #202528;
  --muted: #6e767c;
  --line: #d9dde0;
  --danger: #a93c3c;
  --shadow: 0 16px 42px rgba(22, 30, 43, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
p,
dl {
  margin: 0;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-rows: 76px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
}

.topbar {
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto minmax(210px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: inline-flex;
  align-items: flex-end;
  gap: 9px;
  width: max-content;
  color: var(--brand);
}

.brand-logo {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.brand-name {
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.brand-product {
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
  line-height: 1;
}

.view-tabs {
  display: flex;
  align-items: center;
  gap: 30px;
  height: 100%;
}

.segment {
  position: relative;
  height: 100%;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.segment::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 4px;
  background: transparent;
  content: "";
}

.segment:hover,
.segment.active {
  color: var(--brand);
}

.segment.active::after {
  background: var(--brand);
}

.dashboard-body,
.workspace-grid,
.viewer-panel,
.canvas-frame {
  min-width: 0;
  min-height: 0;
}

.dashboard-body {
  position: relative;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: 100%;
}

.catalog-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 20px 20px 20px 28px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.search-field input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: #fafbfb;
  color: var(--ink);
}

.search-field input:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(47, 59, 151, 0.1);
}

.catalog-list {
  display: grid;
  align-content: start;
  gap: 2px;
  min-height: 0;
  overflow: auto;
  padding-right: 5px;
}

.catalog-item {
  display: grid;
  gap: 7px;
  width: 100%;
  min-height: 68px;
  padding: 12px 12px 12px 14px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0 6px 6px 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.catalog-item:hover {
  background: #f5f6f7;
}

.catalog-item.active {
  border-left-color: var(--brand);
  background: var(--brand-soft);
}

.catalog-item-head,
.catalog-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.catalog-item strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.3;
}

.catalog-item-meta {
  justify-content: flex-start;
  color: var(--muted);
  font-size: 12px;
}

.tag {
  flex: none;
  padding: 3px 6px;
  border: 1px solid rgba(47, 59, 151, 0.18);
  border-radius: 5px;
  color: var(--brand);
  font-size: 10px;
  font-weight: 800;
}

.muted {
  padding: 14px 4px;
  color: var(--muted);
  font-size: 13px;
}

.viewer-panel {
  position: relative;
  overflow: hidden;
  background: var(--scene);
}

.canvas-frame {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--scene);
}

#viewer-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

#viewer-canvas:active {
  cursor: grabbing;
}

.viewer-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(233, 237, 239, 0.92);
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.scene-caption {
  position: absolute;
  top: 20px;
  left: 22px;
  max-width: min(620px, calc(100% - 260px));
  padding: 12px 15px;
  border: 1px solid rgba(217, 221, 224, 0.92);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 24px rgba(25, 31, 40, 0.08);
  backdrop-filter: blur(10px);
}

.scene-caption h2 {
  overflow: hidden;
  font-size: 17px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-actions {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.axis-visibility-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(25, 31, 40, 0.08);
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
  user-select: none;
}

.axis-visibility-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.toggle-track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: #b8c0c7;
  transition: background 140ms ease;
}

.toggle-track::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(25, 31, 40, 0.28);
  content: "";
  transition: transform 140ms ease;
}

.axis-visibility-toggle input:checked + .toggle-track {
  background: var(--brand);
}

.axis-visibility-toggle input:checked + .toggle-track::after {
  transform: translateX(14px);
}

.axis-visibility-toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.scene-button,
.text-button,
.close-button,
.icon-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
}

.scene-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(25, 31, 40, 0.08);
  font-size: 13px;
  font-weight: 750;
}

.scene-button:hover,
.scene-button[aria-expanded="true"] {
  border-color: var(--brand);
  color: var(--brand);
}

.layer-palette,
.entity-inspector {
  position: absolute;
  z-index: 5;
  border: 1px solid rgba(211, 216, 220, 0.96);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.layer-palette {
  top: 74px;
  right: 20px;
  bottom: 20px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(390px, calc(100% - 40px));
  padding: 16px;
}

.entity-inspector {
  bottom: 20px;
  left: 22px;
  width: min(370px, calc(100% - 44px));
  padding: 16px;
}

.overlay-head {
  margin-bottom: 14px;
}

.overlay-head h2 {
  font-size: 17px;
}

.layer-palette-head h2 span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.overlay-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.text-button {
  min-height: 32px;
  padding: 0 9px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.close-button {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border-radius: 5px;
  font-size: 22px;
  line-height: 1;
}

.text-button:hover,
.close-button:hover,
.icon-button:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.entity-props {
  display: grid;
  gap: 0;
}

.entity-prop {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.entity-prop dt,
.entity-prop dd {
  margin: 0;
}

.entity-prop dt {
  color: var(--muted);
  font-size: 12px;
}

.entity-prop dd {
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 750;
  text-align: right;
}

.layer-palette-list {
  display: grid;
  align-content: start;
  gap: 0;
  min-height: 0;
  overflow: auto;
  padding-right: 3px;
}

.layer-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto minmax(84px, 112px) 30px;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  border-top: 1px solid var(--line);
}

.layer-row.changed {
  background: rgba(238, 240, 255, 0.56);
}

.layer-name {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-count,
.layer-opacity-value {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.layer-color {
  width: 30px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
}

.layer-opacity-control {
  display: grid;
  grid-template-columns: minmax(50px, 1fr) 34px;
  align-items: center;
  gap: 5px;
}

.layer-opacity {
  width: 100%;
  accent-color: var(--brand);
}

.layer-opacity-value {
  text-align: right;
}

.icon-button {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 5px;
  font-size: 15px;
}

.error-panel {
  position: absolute;
  z-index: 20;
  top: 24px;
  left: 50%;
  width: min(520px, calc(100% - 32px));
  padding: 18px;
  border: 1px solid #e1bcbc;
  border-radius: 6px;
  background: #fffafa;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.error-panel h2 {
  margin-bottom: 7px;
  color: var(--danger);
  font-size: 18px;
}

.error-panel p:last-child {
  color: var(--muted);
  font-size: 13px;
}

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

  .app-shell {
    grid-template-rows: auto auto;
    height: auto;
    min-height: 100vh;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 14px 18px 0;
  }

  .view-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: center;
    height: 48px;
  }

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

  .catalog-panel {
    grid-template-rows: auto auto 260px;
    padding: 20px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .viewer-panel,
  .canvas-frame {
    height: 70vh;
    min-height: 520px;
  }
}

@media (max-width: 620px) {
  .brand-name {
    font-size: 25px;
  }

  .brand-product {
    font-size: 16px;
  }

  .scene-caption {
    top: 12px;
    left: 12px;
    max-width: calc(100% - 150px);
  }

  .viewer-actions {
    top: 12px;
    right: 12px;
  }

  .viewer-actions .scene-button:first-child {
    display: none;
  }

  .layer-palette {
    top: 66px;
    right: 12px;
    bottom: 12px;
    width: calc(100% - 24px);
  }

  .entity-inspector {
    bottom: 12px;
    left: 12px;
    width: calc(100% - 24px);
  }
}
