:root {
  color-scheme: light;
  --brand: #2f3b97;
  --brand-dark: #202b78;
  --brand-soft: #eef0ff;
  --bg: #f4f5f6;
  --surface: #ffffff;
  --scene: #e9edef;
  --ink: #202528;
  --muted: #6e767c;
  --line: #d9dde0;
  --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, "Segoe UI", Arial, 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);
}

.state-mark {
  display: grid;
  place-items: center;
  background: var(--brand);
  color: white;
  font-weight: 900;
}

.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;
}

.scene-caption p,
.viewer-stats { color: var(--muted); }

.view-tabs {
  display: flex;
  align-items: center;
  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: var(--brand);
  content: "";
}

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

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

.catalog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  padding: 24px 18px 16px 24px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.catalog-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;
}

.catalog h1 {
  font-size: 22px;
  letter-spacing: -0.03em;
}

.icon-button,
.viewer-actions button,
.close-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-weight: 750;
}

.icon-button {
  width: 40px;
  font-size: 22px;
  line-height: 1;
}

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

.icon-button.loading { animation: spin 700ms linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.search input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: #f8faf9;
}

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

.document-list {
  min-height: 0;
  overflow: auto;
  padding-right: 5px;
}

.document-card {
  display: grid;
  gap: 8px;
  width: 100%;
  margin-bottom: 5px;
  padding: 13px 12px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 0 8px 8px 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.document-card:hover { background: #f5f7f6; }

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

.document-card strong,
.document-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-card strong { font-size: 13px; }

.document-card span {
  color: var(--muted);
  font-size: 11px;
}

.empty-list {
  padding: 28px 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--scene);
}

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

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

.viewer-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  background: rgba(233, 237, 239, 0.92);
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.viewer-state.hidden { display: none; }
.viewer-state strong { color: var(--ink); }
.viewer-state small { max-width: 340px; }

.state-mark {
  width: 46px;
  height: 46px;
  margin-bottom: 6px;
  border-radius: 13px 13px 13px 3px;
  box-shadow: inset -7px -7px 0 var(--brand-dark);
}

.scene-caption,
.viewer-actions,
.layer-palette,
.entity-inspector,
.viewer-stats {
  position: absolute;
  z-index: 2;
}

.scene-caption {
  top: 20px;
  left: 22px;
  max-width: min(560px, calc(100% - 370px));
  padding: 13px 15px;
  border: 1px solid rgba(216, 222, 219, 0.92);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

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

.scene-caption p:last-child {
  margin-top: 5px;
  font-size: 11px;
}

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

.viewer-actions button {
  min-height: 42px;
  padding: 0 14px;
  box-shadow: 0 8px 24px rgba(25, 31, 40, 0.08);
  font-size: 13px;
}

.viewer-actions button[aria-pressed="false"] {
  color: var(--muted);
  background: #f2f4f3;
}

.viewer-actions .primary {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.axis-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-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-toggle input:checked + .toggle-track { background: var(--brand); }
.axis-toggle input:checked + .toggle-track::after { transform: translateX(14px); }
.axis-toggle input:focus-visible + .toggle-track { outline: 2px solid var(--brand); outline-offset: 2px; }

.layer-palette {
  top: 74px;
  right: 20px;
  width: min(390px, calc(100% - 40px));
  max-height: calc(100% - 145px);
  overflow: hidden;
  border: 1px solid rgba(216, 222, 219, 0.94);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.layer-palette.hidden { display: none; }

.layer-palette-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 15px 12px;
  border-bottom: 1px solid var(--line);
}

.layer-palette-head h3 {
  margin: 0;
  font-size: 16px;
}

.layer-palette-head > div:last-child {
  display: flex;
  gap: 5px;
}

.layer-palette-head button,
.layer-reset {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font-size: 11px;
  font-weight: 750;
}

.layer-list {
  max-height: calc(100vh - 240px);
  overflow: auto;
  padding: 7px;
}

.layer-row {
  display: grid;
  grid-template-columns: 22px 34px minmax(90px, 1fr) 100px 34px;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 5px 6px;
  border-radius: 7px;
}

.layer-row:hover { background: #f5f7f6; }
.layer-row.changed { background: rgba(238, 240, 255, 0.56); }
.layer-row.disabled .layer-name { color: var(--muted); text-decoration: line-through; }

.layer-visible { width: 16px; height: 16px; }

.layer-color {
  width: 32px;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  cursor: pointer;
}

.layer-label { min-width: 0; }

.layer-name,
.layer-count {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-name { font-size: 11px; font-weight: 750; }
.layer-count { color: var(--muted); font-size: 9px; }

.layer-opacity-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  align-items: center;
  gap: 4px;
}

.layer-opacity { width: 100%; min-width: 0; }
.layer-opacity-value { color: var(--muted); font-size: 9px; text-align: right; }
.layer-reset { width: 32px; padding: 0; font-size: 16px; }

.entity-inspector {
  bottom: 20px;
  left: 22px;
  width: min(370px, calc(100% - 44px));
  max-height: calc(100% - 155px);
  overflow: auto;
  padding: 16px;
  border: 1px solid rgba(216, 222, 219, 0.92);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

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

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

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

.entity-props { display: grid; }

.entity-prop {
  display: grid;
  grid-template-columns: 135px 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 {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 13px;
  font-weight: 750;
  text-align: right;
}

.entity-color-prop { align-items: center; }

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

.viewer-stats {
  right: 20px;
  bottom: 18px;
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(216, 222, 219, 0.9);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.86);
  font-size: 11px;
  backdrop-filter: blur(8px);
}

.viewer-stats span + span::before {
  margin-right: 8px;
  color: #aeb7b3;
  content: "·";
}

@media (max-width: 780px) {
  .app-shell { grid-template-rows: 62px minmax(0, 1fr); }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 0 16px; }
  .topbar-spacer { display: none; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: 210px minmax(0, 1fr); }
  .catalog {
    grid-template-columns: minmax(0, 1fr) 180px;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 14px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .catalog-head { grid-column: 1; }
  .search { grid-column: 2; grid-row: 1; }
  .document-list { grid-column: 1 / -1; display: flex; gap: 6px; }
  .document-card { min-width: 210px; }
  .scene-caption { max-width: calc(100% - 44px); }
  .viewer-actions { top: auto; right: 14px; bottom: 14px; left: 14px; flex-wrap: wrap; justify-content: flex-end; }
  .entity-inspector { bottom: 68px; left: 14px; }
  .entity-prop { grid-template-columns: 110px minmax(0, 1fr); }
  .viewer-stats { display: none; }
}

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