:root {
  color-scheme: dark;
  --bg: #101318;
  --panel: #181d24;
  --panel-2: #202732;
  --panel-3: #2a3441;
  --line: #344151;
  --line-soft: #293340;
  --text: #f4f7fa;
  --muted: #a7b2c0;
  --accent: #23b7a6;
  --accent-2: #d5a84a;
  --danger: #d95c62;
  --canvas: #0b0f14;
  --field: #10161d;
  --focus: #6ce2d5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #222a34;
  color: var(--text);
  padding: 0 10px;
  cursor: pointer;
}

button:hover {
  border-color: var(--focus);
  background: #2c3847;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary-action {
  border-color: rgba(35, 183, 166, 0.7);
  background: #1f665f;
  color: #eefdfb;
  font-weight: 700;
}

.primary-action:hover {
  border-color: var(--focus);
  background: #24796f;
}

.mode-chip {
  border-color: rgba(213, 168, 74, 0.38);
  background: rgba(213, 168, 74, 0.12);
  color: #f0d48c;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  padding: 0;
  font-weight: 800;
}

#undoBtn,
#redoBtn,
#deleteBtn,
#duplicateBtn,
#addRootBtn {
  display: none;
}

input,
select,
textarea {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
  padding: 6px 8px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px rgba(33, 168, 161, 0.2);
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-rows: 64px 32px 1fr 28px;
  width: 100%;
  height: 100%;
}

.topbar {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) minmax(360px, auto);
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #131922;
  padding: 0 16px;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(6, 9, 13, 0.92);
}

.login-overlay.is-hidden {
  display: none;
}

.login-panel {
  display: grid;
  gap: 14px;
  width: min(410px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171d26;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  padding: 24px;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-brand {
  margin-bottom: 4px;
}

.login-copy {
  margin: -2px 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.login-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: #061412;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-stack {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.brand-title,
.doc-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.brand-subtitle {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(52, 65, 81, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
  padding: 5px;
}

.zoom-tools {
  margin-left: auto;
}

.zoom-label {
  width: 54px;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status-text {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.global-status {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border-bottom: 1px solid var(--line);
  background: #0f141b;
  padding: 0 16px;
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.account-bar button {
  min-height: 30px;
  padding: 0 9px;
}

.current-user {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 330px) minmax(420px, 1fr) minmax(300px, 360px);
  min-height: 0;
}

.panel {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.studio-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  background: #0d1117;
  color: var(--muted);
  font-size: 12px;
  padding: 0 14px;
}

.studio-footer span:nth-child(2) {
  color: var(--accent-2);
  font-weight: 700;
}

.studio-footer span:last-child {
  justify-self: end;
}

.inspector-panel {
  display: grid;
  grid-template-rows: minmax(190px, 260px) minmax(0, 1fr);
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 12px;
}

.compact-header {
  min-height: 42px;
}

.panel-header h1,
.panel-header h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.tree-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.tree-actions button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.search {
  width: calc(100% - 24px);
  margin: 12px;
}

.source-panel {
  display: grid;
  grid-template-rows: 42px 56px 220px;
  border-bottom: 1px solid var(--line);
  min-height: 318px;
}

.source-search {
  align-self: start;
}

.json-list {
  overflow: auto;
  padding: 0 8px 10px;
}

.json-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 2px;
}

.json-open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 4px 8px;
  text-align: left;
}

.json-item:hover,
.json-item.is-selected {
  border-color: var(--accent);
  background: rgba(35, 183, 166, 0.12);
}

.json-open:hover {
  border-color: transparent;
  background: transparent;
}

.json-delete {
  min-height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

.json-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.json-size {
  color: var(--muted);
  font-size: 11px;
}

.json-source {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.asset-panel {
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  min-height: 0;
  border-bottom: 1px solid var(--line);
}

.preview-panel {
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr);
  min-height: 0;
}

.is-hidden {
  display: none !important;
}

.asset-list {
  max-height: 260px;
  overflow: auto;
  padding: 8px;
}

.uif-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.asset-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 4px 6px;
}

.asset-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-meta {
  color: var(--muted);
  font-size: 11px;
}

.uif-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
  margin-bottom: 8px;
  padding: 8px;
}

.uif-item:hover {
  border-color: rgba(35, 183, 166, 0.35);
  background: rgba(35, 183, 166, 0.08);
}

.uif-name,
.uif-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.uif-name {
  font-size: 13px;
  font-weight: 700;
}

.uif-meta {
  color: var(--muted);
  font-size: 11px;
}

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

.admin-modal {
  position: fixed;
  inset: 0;
  z-index: 16;
  display: grid;
  place-items: center;
  padding: 28px;
}

.admin-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 12, 0.72);
}

.admin-dialog {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1180px, calc(100vw - 40px));
  height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151a22;
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.56);
}

.admin-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #1a2029;
  padding: 16px 18px;
}

.admin-dialog-title h2,
.admin-card-header h3 {
  margin: 0;
  letter-spacing: 0;
}

.admin-dialog-title h2 {
  font-size: 18px;
}

.admin-dialog-title p,
.admin-card-header span {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.admin-dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.9fr) minmax(440px, 1.3fr);
  gap: 14px;
  min-height: 0;
  padding: 14px;
}

.admin-card {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel);
}

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

.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line-soft);
  padding: 12px 14px;
}

.admin-card-header h3 {
  font-size: 14px;
}

.admin-filter {
  display: grid;
  gap: 4px;
  min-width: 180px;
  color: var(--muted);
  font-size: 11px;
}

.admin-filter select {
  min-height: 30px;
}

.admin-create {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
  padding: 12px;
}

.admin-create #adminPassword,
.admin-create button {
  grid-column: span 2;
}

.admin-list,
.audit-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.admin-user,
.audit-entry {
  display: grid;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  margin-bottom: 8px;
  padding: 10px;
}

.admin-user {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.admin-user:hover,
.audit-entry:hover {
  border-color: rgba(35, 183, 166, 0.32);
  background: rgba(35, 183, 166, 0.07);
}

.admin-user-main,
.audit-main {
  min-width: 0;
}

.admin-user-name,
.audit-action {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user-meta,
.audit-meta,
.audit-target {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-pill {
  display: inline-block;
  border: 1px solid rgba(213, 168, 74, 0.45);
  border-radius: 999px;
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  text-transform: uppercase;
}

.audit-entry {
  grid-template-columns: minmax(0, 1fr);
}

.audit-entry.is-error {
  border-color: rgba(217, 92, 98, 0.45);
}

.audit-entry.is-denied {
  border-color: rgba(213, 168, 74, 0.55);
}

.portal-modal {
  position: fixed;
  inset: 0;
  z-index: 17;
  display: grid;
  place-items: center;
  padding: 28px;
}

.portal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 12, 0.72);
}

.portal-dialog {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(940px, calc(100vw - 40px));
  max-height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151a22;
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.56);
}

.compact-dialog {
  width: min(720px, calc(100vw - 40px));
}

.portal-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #1a2029;
  padding: 16px 18px;
}

.portal-dialog-header h2,
.portal-section h3 {
  margin: 0;
  letter-spacing: 0;
}

.portal-dialog-header h2 {
  font-size: 18px;
}

.portal-dialog-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.portal-body,
.portal-docs {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.portal-body {
  display: grid;
  gap: 12px;
}

.portal-docs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.portal-section {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.plugin-download-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.portal-section h3 {
  color: var(--accent-2);
  font-size: 13px;
}

.portal-section p,
.portal-section li {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.48;
}

.portal-section p {
  margin: 8px 0 12px;
}

.portal-section ol,
.portal-section ul {
  margin: 10px 0 0;
  padding-left: 20px;
}

.portal-section code {
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  background: #10161d;
  color: #f0d48c;
  padding: 1px 4px;
}

.tree {
  height: calc(100% - 422px);
  overflow: auto;
  padding: 6px 8px 14px;
}

.tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-node {
  position: relative;
  margin: 1px 0;
  padding-left: 18px;
}

.tree-node::before {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 10px;
  display: none;
  width: 1px;
  background: rgba(35, 183, 166, 0.72);
}

.tree-node::after {
  content: "";
  position: absolute;
  top: 16px;
  left: 10px;
  display: none;
  width: 12px;
  height: 1px;
  background: rgba(35, 183, 166, 0.72);
}

.tree > ul > .tree-node {
  padding-left: 0;
}

.tree-node.is-selected-node::before,
.tree-node.is-selected-node::after {
  display: block;
}

.tree > ul > .tree-node::before,
.tree > ul > .tree-node::after {
  display: none;
}

.tree-row {
  display: grid;
  grid-template-columns: 22px 22px minmax(0, 1fr);
  gap: 2px;
  align-items: center;
  min-height: 30px;
}

.tree-caret {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 22px;
  min-width: 22px;
  min-height: 24px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 0;
}

.tree-caret:not(:disabled):hover {
  color: var(--accent-2);
}

.tree-caret:disabled {
  opacity: 0.25;
}

.tree-visible-toggle {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 24px;
}

.tree-visible {
  width: 14px;
  min-height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.tree-content {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 3px 8px 3px 3px;
  text-align: left;
}

.tree-content:hover {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.035);
}

.tree-row.is-selected .tree-content {
  border-color: var(--accent);
  background: rgba(33, 168, 161, 0.14);
}

.tree-node.is-hidden-element .tree-content {
  opacity: 0.48;
}

.tree-node.is-hidden-element .tree-icon {
  background: rgba(167, 178, 192, 0.08);
  color: var(--muted);
}

.tree-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  background: rgba(240, 178, 71, 0.13);
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}

.tree-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.tree-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-type {
  color: var(--muted);
  font-size: 11px;
}

.tree-count {
  min-width: 20px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.tree-children {
  margin: 0;
  padding: 0;
}

.tree-node.is-collapsed > .tree-children {
  display: none;
}

.canvas-panel {
  display: grid;
  grid-template-rows: 44px 1fr;
  min-width: 0;
  min-height: 0;
  background: var(--canvas);
}

.canvas-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line-soft);
  background: #191d23;
  padding: 0 12px;
}

.check-control {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.canvas-meta {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#viewport {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

.add-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
  padding: 12px;
}

.properties {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.empty-state {
  color: var(--muted);
  line-height: 1.45;
}

.prop-section {
  border-bottom: 1px solid var(--line-soft);
  padding: 0 0 14px;
  margin: 0 0 14px;
}

.prop-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.prop-section h3 {
  margin: 0 0 10px;
  color: var(--accent-2);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.field {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.field label {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mini-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.danger {
  border-color: rgba(226, 93, 93, 0.65);
  color: #ffd9d9;
}

.danger:hover {
  border-color: var(--danger);
  background: rgba(226, 93, 93, 0.18);
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 154px;
    align-items: stretch;
    padding: 10px;
  }

  .toolbar {
    flex-wrap: wrap;
    overflow: visible;
  }

  .toolbar-group {
    flex-wrap: wrap;
  }

  .account-bar {
    justify-content: flex-start;
  }

  .app-shell {
    grid-template-rows: auto 32px 1fr 28px;
  }

  .workspace {
    grid-template-columns: 220px minmax(300px, 1fr);
  }

  .inspector-panel {
    display: none;
  }

  .admin-modal {
    padding: 12px;
  }

  .admin-dialog {
    width: calc(100vw - 24px);
    height: calc(100vh - 24px);
  }

  .portal-modal {
    padding: 12px;
  }

  .portal-dialog {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  .portal-docs {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-dialog-header {
    align-items: flex-start;
  }

  .admin-grid {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .admin-card {
    min-height: 360px;
  }

  .admin-create {
    grid-template-columns: 1fr;
  }

  .admin-create #adminPassword,
  .admin-create button {
    grid-column: auto;
  }
}
