/* layout.css — estructura principal */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: var(--border-solid); border-radius: 2px; }

.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 22px;
  gap: 16px;
  flex-shrink: 0;
  background: var(--surface);
  z-index: 10;
}

.app {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.left-panel {
  width: 290px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface);
}

#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#graph {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

.right-panel {
  width: 0;
  border-left: 1px solid transparent;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.22s ease;
  background: var(--surface);
}
.right-panel.open {
  width: 290px;
  border-left-color: var(--border);
}

#review-panel {
  position: fixed;
  top: 56px; right: 0; bottom: 0;
  width: 340px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow: hidden;
}
#review-panel.show { transform: translateX(0); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26,24,20,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.show { opacity: 1; pointer-events: all; }

/* Modales que no usan .modal-overlay en el HTML — se ocultan aquí */
#apimodal, #diagmodal, #custommodal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26,24,20,0.4);
  align-items: center;
  justify-content: center;
  z-index: 300;
}
#apimodal.show, #diagmodal.show, #custommodal.show { display: flex; }

#legend {
  position: absolute;
  bottom: 20px; left: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 28px 14px 16px;
  font-size: 0.66rem;
  color: var(--muted);
  box-shadow: var(--shadow);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
#legend.hidden { opacity: 0; pointer-events: none; }

#legend-toggle {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 50;
  display: none;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-btn);
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
#legend-toggle:hover { color: var(--ink); }

#toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: #1a1814;
  color: #f5f2ec;
  padding: 9px 20px;
  border-radius: var(--r-btn);
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.2s;
  pointer-events: none;
  z-index: 400;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#loading {
  position: fixed;
  inset: 0;
  background: rgba(240,244,248,0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#loading.show { opacity: 1; pointer-events: all; }

.spinner {
  width: 30px; height: 30px;
  border: 2.5px solid var(--border-solid);
  border-top-color: var(--ai);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform