.editor-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.editor-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  min-height: 0;
}

.pane { background: var(--paper); display: flex; flex-direction: column; min-height: 0; }

/* ---- Toolbar ---- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-height: 56px;
}

.toolbar .hint-text {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.toolbar input[type="text"],
.toolbar input[type="url"] {
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 180px;
  background: var(--paper);
}
.toolbar input[type="text"]:focus,
.toolbar input[type="url"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toolbar select {
  font-family: var(--font-body);
  font-size: 0.85rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.toolbar .divider {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  margin: 0 0.25rem;
}

.toolbar-spacer { flex: 1; }

/* Full label ("+ Child") by default; short label ("+ ↓") only shows on
   mobile — see the consolidated mobile block at the end of this file. */
.toolbar .btn .short-label { display: none; }

.btn.danger { border-color: #fecaca; color: #b91c1c; }
.btn.danger:hover { background: #fef2f2; }

.color-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 2px solid currentColor;
  margin-right: 0.4rem;
  vertical-align: -1px;
}

/* ---- Canvas ---- */

.canvas-scroll {
  flex: 1;
  overflow: auto;
  padding: 2rem;
}

#canvas {
  position: relative; /* positioning context for inline rename + edge-add overlays */
}

#canvas svg { max-width: 100%; height: auto; }
#canvas .node rect,
#canvas .node polygon,
#canvas .node circle {
  cursor: pointer;
  transition: filter 0.15s ease, stroke-width 0.15s ease;
}
#canvas .node:hover rect,
#canvas .node:hover polygon,
#canvas .node:hover circle {
  filter: brightness(0.95) saturate(1.25);
}
#canvas .node.gsw-selected rect,
#canvas .node.gsw-selected polygon,
#canvas .node.gsw-selected circle {
  stroke-width: 3.5px !important;
}

/* Box labels are UI chrome here, not document text — selecting them
   fights with click/drag-to-select-box interactions. */
#canvas .node,
#canvas .node * {
  user-select: none;
  -webkit-user-select: none;
}

/* Inline "rename on the box" editor (double-click a box) */
.gsw-inline-rename {
  position: absolute;
  z-index: 40;
  box-sizing: border-box;
  resize: none;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  padding: 2px 4px;
  overflow: hidden;
}
.gsw-inline-rename:focus { outline: none; }

/* Hover edge strips — invisible until hovered, reveal a + to add a box */
.gsw-edge-strip {
  position: absolute;
  z-index: 30;
}
.gsw-add-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: var(--panel);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.gsw-edge-strip:hover .gsw-add-btn {
  opacity: 1;
  pointer-events: auto;
}
.gsw-add-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ---- Code pane ---- */

.code-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-height: 56px;
}
.code-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: text;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.code-title:hover { background: var(--paper); }

#export-btn { margin-left: auto; flex-shrink: 0; }

.code-toggle {
  display: none; /* only shown on mobile, see the block at the end */
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.code-toggle:hover { border-color: var(--accent); background: var(--accent-soft); }

.filename-input {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink);
  padding: 0.15rem 0.35rem;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--paper);
  width: 12rem;
  min-width: 0;
}

.code-view {
  flex: 1;
  margin: 0;
  overflow: auto;
  padding: 1.25rem 1.5rem;
  background: #14201d;
  color: #d8f3ec;
}
.code-view code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.65;
  white-space: pre;
}

/* ---- Right-click context menu ---- */

.gsw-context-menu {
  position: fixed;
  z-index: 200;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  min-width: 160px;
}

.gsw-context-item {
  font-family: var(--font-body);
  font-size: 0.85rem;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}
.gsw-context-item:hover { background: var(--accent-soft); }
.gsw-context-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: none;
}

/* ============================================================
   Mobile (≤860px) — consolidated here, deliberately last, so
   nothing above can win a property fight by source order alone.
   ============================================================ */

@media (max-width: 860px) {
  :root { --mobile-code-bar: 3.4rem; }

  .editor-grid {
    display: flex;
    flex-direction: column;
    background: transparent;
    gap: 0;
  }

  .canvas-pane {
    flex: 1 1 auto;
    min-height: 0;
    padding-bottom: var(--mobile-code-bar); /* room for the fixed bar below */
  }

  /* The code pane no longer takes part in the normal flex flow at all —
     its header bar and preview are both position:fixed, anchored to the
     viewport directly rather than sized/clipped through flex + max-height
     (which depended on several nested flex/overflow calculations
     resolving exactly right, and in practice sometimes didn't). Fixed
     positioning can't be squeezed away by an ancestor's layout — it's
     anchored to the screen itself, which is what "anchored at the
     bottom" means literally. */
  .code-pane { display: contents; }

  .code-header {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    height: var(--mobile-code-bar);
    padding: 0.6rem 0.75rem;
    box-sizing: border-box;
    box-shadow: 0 -2px 10px rgba(28, 35, 33, 0.08);
  }
  .code-toggle { display: inline-flex; }
  .code-title { font-size: 0.78rem; flex: 1 1 auto; }
  .code-header .btn { font-size: 0.78rem; padding: 0.42rem 0.65rem; }

  .code-view {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--mobile-code-bar);
    z-index: 54;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease;
  }
  .code-pane.expanded .code-view {
    max-height: 62vh;
    padding-top: 1.25rem;
    padding-bottom: 1.25rem;
  }

  .toolbar {
    flex-wrap: wrap;
    gap: 0.3rem;
    padding: 0.55rem 0.6rem;
    min-height: 0;
  }
  .toolbar .divider { display: none; }
  .toolbar-spacer { flex: 0 0 0; width: 0; }
  .toolbar .btn {
    flex-shrink: 0;
    font-size: 0.74rem;
    padding: 0.4rem 0.5rem;
  }
  .toolbar .hint-text { font-size: 0.75rem; white-space: nowrap; }
  .toolbar input[type="text"],
  .toolbar input[type="url"],
  .toolbar select {
    font-size: 0.78rem;
    padding: 0.42rem 0.55rem;
    min-width: 0;
    flex: 1 1 120px;
  }
  .toolbar .btn .full-label { display: none; }
  .toolbar .btn .short-label { display: inline; }

  .canvas-scroll { padding: 1rem; }
}
