* {
  box-sizing: border-box;
}

html,
body,
#workspace,
#app {
  height: 100%;
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: #223044;
  background: #f4f6fa;
}

editor-top-bar {
  display: block;
}

#workspace {
  height: calc(100% - 42px);
}

#menu-bar {
  height: 42px;
  background: linear-gradient(180deg, #f7f9fd 0%, #e9eef7 100%);
  border-bottom: 1px solid #cfd8e6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
}

#menu-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

#app-name {
  margin-right: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #2a3e5e;
  text-decoration: none;
}

.menu-root-wrap {
  position: relative;
}

.menu-root {
  background: transparent;
  border: 0;
  color: #1c2c44;
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: 600;
}

.menu-root:hover {
  background: #dce6f5;
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 160px;
  display: grid;
  gap: 2px;
  padding: 6px;
  background: #ffffff;
  border: 1px solid #c8d3e5;
  border-radius: 10px;
  box-shadow: 0 12px 22px rgba(34, 55, 88, 0.17);
  z-index: 30;
}

.menu-dropdown[hidden] {
  display: none !important;
}

.menu-dropdown button {
  border: 0;
  background: transparent;
  border-radius: 7px;
  text-align: left;
  font-weight: 500;
}

.menu-dropdown button:hover {
  background: #eaf1fd;
}

#menu-right {
  color: #465f82;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

#session-presence {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

#session-presence .session-avatar {
  --session-color: #5d7ea7;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  padding: 0;
  appearance: none;
  border-radius: 50%;
  border: 2px solid var(--session-color);
  background: rgba(255, 255, 255, 0.92);
  color: #2b405f;
  display: grid;
  place-items: center;
  box-shadow: 0 1px 4px rgba(35, 56, 92, 0.15);
}

#session-presence .session-avatar.self {
  background: rgba(255, 246, 238, 0.96);
  box-shadow: 0 0 0 1px rgba(255, 161, 99, 0.45), 0 1px 4px rgba(35, 56, 92, 0.15);
}

#session-presence .session-avatar-icon {
  width: 13px;
  height: 13px;
  stroke-width: 2.1;
}

#session-presence .session-avatar .lucide {
  width: 13px;
  height: 13px;
  stroke: var(--session-color);
}

#session-presence .session-avatar.other {
  cursor: pointer;
}

#session-presence .session-avatar.self {
  cursor: pointer;
}

#session-presence .session-avatar.following {
  box-shadow: 0 0 0 2px rgba(30, 41, 59, 0.18), 0 1px 4px rgba(35, 56, 92, 0.15);
}

#session-presence .session-avatar.self:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.session-avatar-tooltip {
  position: fixed;
  z-index: 9999;
  transform: translateX(-50%);
  background: #1e293b;
  color: #f1f5f9;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 80ms ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.session-avatar-tooltip.session-avatar-tooltip-visible {
  opacity: 1;
}

#app {
  display: grid;
  --right-sidebar-width: 320px;
  grid-template-columns: 280px 1fr 6px var(--right-sidebar-width);
}

body.observation-active::after {
  content: "";
  position: fixed;
  inset: 0;
  border: 4px solid var(--follow-session-color, #3b82f6);
  pointer-events: none;
  z-index: 500;
}

#panel {
  padding: 0;
  border-right: 1px solid #d4dbe7;
  background: linear-gradient(180deg, #ffffff 0%, #f1f5fb 100%);
  display: flex;
  min-height: 0;
  overflow: hidden;
}

#object-tree-panel {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

#object-tree {
  display: block;
  position: relative;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: #f6f9ff;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  font-size: 12px;
  line-height: 1.35;
}

#object-tree .object-tree-host-inner {
  height: calc(100% - 40px);
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  padding: 6px 8px 8px;
}

#object-tree .object-tree-search-wrap {
  height: 40px;
  width: 100%;
  padding: 8px 8px 4px;
}

#object-tree .object-tree-search-input {
  width: 100%;
  border: 1px solid #c5d2e4;
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  color: #223854;
  background: #ffffff;
}

#object-tree .object-tree-search-input:focus {
  outline: none;
  border-color: #7ea5e0;
  box-shadow: 0 0 0 2px rgba(126, 165, 224, 0.2);
}

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

.tree-list.root {
  padding-left: 0;
  width: max-content;
  min-width: 100%;
}

.tree-children {
  margin: 0 0 0 8px;
  padding: 0 0 0 8px;
  border-left: 1px solid #d5deea;
}

.tree-item {
  margin: 0;
}

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

.tree-dir > summary {
  list-style: none;
}

.tree-dir > summary::-webkit-details-marker {
  display: none;
}

#object-tree .tree-row {
  width: max-content;
  min-width: 100%;
  border: 0;
  background: transparent;
  border-radius: 6px;
  margin: 0;
  padding: 3px 6px;
  color: #2d4263;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
  font: inherit;
}

#object-tree .tree-row[data-action] {
  cursor: pointer;
}

#object-tree .tree-row:hover {
  background: #eaf0fb;
}

#object-tree .tree-row.active {
  background: #dbe8ff;
  color: #15448a;
  font-weight: 700;
  box-shadow: inset 2px 0 0 #3274de;
}

#object-tree .tree-row-muted {
  color: #7a8ca7;
}

#object-tree .tree-row-folder {
  color: #2c4468;
  font-weight: 600;
}

#object-tree .tree-row.drag-source {
  opacity: 0.55;
}

#object-tree .tree-row.drag-over {
  background: #dcf6e5;
  color: #1e6942;
  box-shadow: inset 2px 0 0 #2f9b5e;
}

#object-tree .tree-row.tree-row-locked {
  box-shadow: inset 2px 0 0 var(--lock-color, #8898ad);
}

.tree-label {
  flex: 1 1 auto;
  min-width: max-content;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.tree-count {
  flex: 0 0 auto;
  color: #6b7f9a;
  margin-left: 8px;
  font-variant-numeric: tabular-nums;
}

.tree-caret {
  width: 12px;
  flex: 0 0 12px;
  display: grid;
  place-items: center;
  color: #6a7f9a;
  transition: transform 120ms ease;
}

.tree-dir[open] > summary .tree-caret {
  transform: rotate(90deg);
}

.tree-dir.tree-object > summary {
  cursor: pointer;
}

.tree-empty {
  font-size: 12px;
  color: #607897;
}

#object-tree .tree-icon {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  color: #7388a6;
}

#object-tree .tree-row-folder .tree-icon {
  color: #5f7697;
}

#object-tree .tree-row.active .tree-icon {
  color: #1f63c2;
}

#object-tree .tree-row-muted .tree-icon {
  color: #8c9bb2;
}

.tree-lock-badge {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--lock-color, #888);
  background-color: rgba(255, 255, 255, 0.9);
  background-repeat: no-repeat;
  background-size: 9px 9px;
  background-position: center;
  display: inline-block;
}

#object-tree.object-tree-readonly .tree-row[data-action],
#object-tree.object-tree-readonly .tree-lock-badge {
  cursor: default;
}

#object-tree.object-tree-readonly .tree-row.tree-row-locked,
#object-tree.object-tree-readonly .tree-row.tree-row-locked .tree-lock-badge {
  cursor: pointer;
}

#object-tree.object-tree-readonly .tree-row:not(.tree-row-locked):hover {
  background: transparent;
}

.row {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

#tool-modes {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid #c7d4e7;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 22px rgba(34, 56, 91, 0.24);
  backdrop-filter: blur(6px);
  z-index: 80;
}

#tool-select-wrap {
  display: contents;
}

#tool-edit-group,
#tool-observe-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

#tool-edit-group[hidden],
#tool-observe-group[hidden] {
  display: none !important;
}

#tool-observe-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: 2px;
  line-height: 1.2;
}

#tool-observe-label {
  font-size: 11px;
  font-weight: 600;
  color: #1f3557;
  white-space: nowrap;
}

#tool-observe-hint {
  font-size: 10px;
  font-weight: 600;
  color: #9f1239;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

#tool-modes button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
}

#tool-modes button .lucide {
  width: 18px;
  height: 18px;
}

#tool-modes button[hidden] {
  display: none !important;
}

#tool-modes button.active {
  background: #dbe8ff;
  border-color: #8eaee6;
  color: #173b77;
}

#tool-modes button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: #c8d4e5;
  background: #f4f7fc;
  color: #8091aa;
}

#tool-modes button:disabled:hover {
  background: #f4f7fc;
}

#tree-context-menu {
  position: fixed;
  min-width: 170px;
  padding: 6px;
  border: 1px solid #c7d2e4;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(33, 55, 91, 0.2);
  z-index: 120;
  overflow: visible;
}

#tree-context-menu[hidden] {
  display: none !important;
}

#tree-context-menu button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #253b5d;
  padding: 7px 8px;
}

#tree-context-menu button:hover {
  background: #e8f0ff;
}

#tree-context-menu .tree-menu-submenu-wrap {
  position: relative;
}

#tree-context-menu .tree-menu-parent-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#tree-context-menu .tree-menu-arrow {
  color: #6c7f99;
  margin-left: 10px;
}

#tree-context-menu .tree-submenu {
  position: absolute;
  top: -6px;
  left: calc(100% - 2px);
  min-width: 140px;
  padding: 6px;
  border: 1px solid #c7d2e4;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(33, 55, 91, 0.2);
  z-index: 36;
  display: none;
}

#tree-context-menu .tree-menu-submenu-wrap:hover > .tree-submenu,
#tree-context-menu .tree-menu-submenu-wrap:focus-within > .tree-submenu,
#tree-context-menu .tree-menu-submenu-wrap.open > .tree-submenu {
  display: block;
}

#tree-context-menu > button {
  margin-top: 2px;
}

#object-select-menu {
  position: fixed;
  min-width: 190px;
  max-width: min(360px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid #c7d2e4;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 10px 22px rgba(33, 55, 91, 0.2);
  z-index: 140;
}

#object-select-menu[hidden] {
  display: none !important;
}

#object-select-menu .object-select-menu-title {
  padding: 4px 8px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #6d80a0;
}

#object-select-menu button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: #253b5d;
  padding: 7px 8px;
}

#object-select-menu button:hover {
  background: #e8f0ff;
}

#marquee-select {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  border: 1px solid rgba(56, 113, 198, 0.85);
  background: rgba(88, 146, 232, 0.18);
  border-radius: 4px;
  pointer-events: none;
  z-index: 90;
}

#marquee-select[hidden] {
  display: none !important;
}

#remote-cursor-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 96;
}

.remote-viewport-cursor {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-3px, -3px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  will-change: left, top;
}

.remote-viewport-cursor-pointer {
  --remote-cursor-color: #3b82f6;
  width: 0;
  height: 0;
  border-left: 12px solid var(--remote-cursor-color);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-radius: 1px;
  filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.35));
}

.remote-viewport-cursor-label {
  max-width: 140px;
  padding: 2px 6px;
  border-radius: 999px;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
}

button {
  border: 1px solid #bdc9db;
  background: #ffffff;
  color: #1f3350;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  background: #eef4ff;
}

#right-sidebar {
  padding: 0;
  border-left: 1px solid #d4dbe7;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fc 100%);
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  grid-template-rows: auto 1fr;
  gap: 8px;
  min-height: 0;
  overflow: hidden;
}

#right-sidebar-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 10px 8px;
  border-bottom: 1px solid #d4dbe7;
  background: linear-gradient(180deg, #f7f9fd 0%, #e9eef7 100%);
}

.right-tab {
  border: 1px solid #b9c7db;
  background: #fff;
  color: #2a3e5e;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 600;
}

.right-tab.active {
  background: #edf4ff;
  border-color: #8ca9cd;
  color: #1e395f;
}

#right-sidebar-panes {
  min-height: 0;
  height: 100%;
}

.right-pane {
  height: 100%;
}

.inspector-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(21, 35, 57, 0.05);
}

#pane-script {
  padding: 10px;
}

#script-pane-meta {
  height: 24px;
  display: flex;
  align-items: center;
  padding: 0 2px 6px;
}

#script-pane-title {
  font-size: 12px;
  font-weight: 700;
  color: #2f4d74;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

dsl-script-panel {
  display: block;
  width: 100%;
  height: calc(100% - 30px);
  min-height: 220px;
}

#script-merge-selection-btn {
  position: fixed;
  z-index: 220;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #9db0cd;
  background: #f7fbff;
  color: #284a78;
  box-shadow: 0 4px 10px rgba(37, 63, 101, 0.18);
}

#script-merge-selection-btn .lucide {
  width: 14px;
  height: 14px;
  stroke-width: 2.2;
}

#script-merge-selection-btn[hidden] {
  display: none !important;
}

#right-sidebar-resizer {
  cursor: col-resize;
  position: relative;
  overflow: hidden;
}

#right-sidebar-resizer::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0;
  width: 2px;
  height: 100%;
  background: #d4dbe7;
}

#top-error-banner {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 260;
  background: linear-gradient(180deg, #953131 0%, #842c2c 100%);
  color: #fff;
  border: 1px solid #6f2525;
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 10px 20px rgba(70, 18, 18, 0.22);
  font-size: 13px;
  font-weight: 600;
  max-width: min(72vw, 800px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  isolation: isolate;
  opacity: 1;
  transition: opacity 170ms ease, transform 170ms ease;
  will-change: opacity, transform;
}

#top-error-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  transform-origin: left center;
  transform: scaleX(0);
  opacity: 0;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.14) 0%,
    rgba(255, 255, 255, 0.08) 52%,
    rgba(255, 255, 255, 0.02) 100%
  );
}

#top-error-banner.auto-dismiss-active::after {
  opacity: 0.62;
  animation: top-error-dismiss-gradient var(--dismiss-duration-ms, 2200ms) linear forwards;
}

#top-error-banner.fading-out {
  opacity: 0;
  transform: translateX(-50%) translateY(-3px);
}

#top-error-banner .top-error-message {
  display: block;
  line-height: 1.25;
  position: relative;
  z-index: 1;
}

@keyframes top-error-dismiss-gradient {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

#top-error-banner[hidden] {
  display: none !important;
}

#viewport {
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 35% 20%, #f9fbff 0%, #edf2f9 62%, #e5ecf5 100%);
}

#gizmo {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 112px;
  height: 112px;
  border: 0;
  border-radius: 0;
  background: transparent;
  pointer-events: none;
  box-shadow: none;
  z-index: 20;
}

#gizmo canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  filter: none;
}

canvas {
  display: block;
}

#documents-page {
  min-height: calc(100vh - 42px);
  display: grid;
  place-items: center;
  padding: 20px;
}

#documents-card {
  width: min(820px, 100%);
  background: #ffffff;
  border: 1px solid #d3dceb;
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(41, 65, 102, 0.12);
  padding: 20px;
}

#documents-card h1 {
  margin: 0;
  font-size: 24px;
}

#docs-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.doc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid #d3dceb;
  border-radius: 10px;
  background: #f8fbff;
}

.doc-row:hover {
  background: #edf4ff;
}

.doc-row-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #1f3350;
  text-decoration: none;
}

.doc-delete-btn {
  border-color: #d7a7a7;
  color: #7c1f1f;
  background: #fff;
}

.doc-delete-btn:hover {
  background: #ffecec;
}

.doc-name {
  font-weight: 700;
}

.doc-meta {
  font-size: 13px;
  color: #50688b;
}

#left-sidebar-toggle,
#right-sidebar-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  width: 20px;
  height: 48px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #c7d4e7;
  box-shadow: 0 2px 8px rgba(34, 56, 91, 0.18);
  color: #4a6a96;
}

#left-sidebar-toggle {
  left: 0;
  border-radius: 0 6px 6px 0;
  border-left: 0;
}

#right-sidebar-toggle {
  right: 0;
  border-radius: 6px 0 0 6px;
  border-right: 0;
}

#left-sidebar-toggle:hover,
#right-sidebar-toggle:hover {
  background: #eef4ff;
  color: #1f3350;
}

#left-sidebar-toggle::after {
  content: "‹";
  font-size: 16px;
  line-height: 1;
}

#app.left-collapsed #left-sidebar-toggle::after {
  content: "›";
}

#right-sidebar-toggle::after {
  content: "›";
  font-size: 16px;
  line-height: 1;
}

#app.right-collapsed #right-sidebar-toggle::after {
  content: "‹";
}

#app.left-collapsed {
  grid-template-columns: 0 1fr 6px var(--right-sidebar-width);
}

#app.right-collapsed {
  grid-template-columns: 280px 1fr 0 0;
}

#app.left-collapsed.right-collapsed {
  grid-template-columns: 0 1fr 0 0;
}

@media (max-width: 900px) {
  #menu-bar {
    height: auto;
    min-height: 42px;
    flex-wrap: wrap;
    padding-bottom: 6px;
  }

  #workspace {
    height: calc(100% - 56px);
  }

  #top-error-banner {
    top: 66px;
    max-width: calc(100vw - 24px);
  }
}
