/* Atlas — página del grafo */

.atlas-page {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: var(--container-max);
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--space-3) var(--space-2);
}

.atlas-page::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.atlas-page > * {
  position: relative;
  z-index: 1;
}

.atlas-header {
  flex-shrink: 0;
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--rule);
}

.atlas-title {
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 2px;
}

.atlas-lead {
  font-size: 0.8125rem;
  color: var(--ink-muted);
  max-width: 52ch;
  margin: 0;
  line-height: 1.4;
}

/* Grid PC: grafo + leyenda */
.atlas-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: var(--space-2);
}

.atlas-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Marco cartográfico */
.graph-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    linear-gradient(var(--rule) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, var(--rule) 1px, transparent 1px) 0 0 / 40px 40px,
    var(--bg-sheet);
  border: 2px solid var(--ink);
  box-shadow:
    inset 0 0 0 1px var(--bg-sheet),
    inset 0 0 0 3px var(--ink),
    4px 4px 0 color-mix(in srgb, var(--ink) 12%, transparent);
}

.graph-frame::before,
.graph-frame::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  pointer-events: none;
  z-index: 2;
}

.graph-frame::before {
  top: 6px;
  left: 6px;
  border-right: none;
  border-bottom: none;
}

.graph-frame::after {
  bottom: 6px;
  right: 6px;
  border-left: none;
  border-top: none;
}

#graph-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  cursor: grab;
}

#graph-svg.is-panning {
  cursor: grabbing;
}

.graph-hint {
  position: absolute;
  bottom: var(--space-2);
  left: var(--space-2);
  margin: 0;
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  background: color-mix(in srgb, var(--bg-sheet) 88%, transparent);
  border: 1px solid var(--rule);
  pointer-events: none;
}

.graph-error {
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--action);
}

/* Sidebar leyenda */
.atlas-sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--space-2);
  padding: 0;
  background: transparent;
  border: none;
}

.sidebar-block {
  padding: var(--space-2);
  background: var(--bg-sheet);
  border: 1px solid var(--rule);
  box-shadow: 2px 2px 0 color-mix(in srgb, var(--ink) 6%, transparent);
}

.sidebar-block--index {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
  overflow: hidden;
}

.sidebar-block--index .sidebar-heading {
  flex-shrink: 0;
  padding-bottom: var(--space-1);
  margin-bottom: var(--space-1);
  border-bottom: 1px dashed var(--rule);
}

.sidebar-block--index .topic-index {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0 calc(var(--space-2) * -1);
  padding: 0 var(--space-1);
}

.sidebar-legend {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-legend .sidebar-block {
  padding: var(--space-1) var(--space-2);
}

.sidebar-heading {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 var(--space-1);
}

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

.topic-index li {
  margin: 0;
}

.index-item {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  width: 100%;
  padding: 5px 8px 5px 12px;
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--ink);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background var(--motion-fast) var(--ease-out),
    color var(--motion-fast) var(--ease-out);
}

.index-item:hover {
  background: var(--bg-paper);
}

.index-item.is-active {
  background: color-mix(in srgb, var(--topic-accent, var(--rule)) 10%, var(--bg-paper));
  font-weight: 500;
}

.index-num {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--ink-muted);
  flex-shrink: 0;
  min-width: 1.25rem;
}

.index-item.is-active .index-num {
  color: var(--topic-accent, var(--ink));
}

.index-label {
  line-height: 1.3;
}

/* Leyenda relaciones */
.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 0;
  font-size: 0.75rem;
}

.legend-swatch {
  display: inline-block;
  width: 24px;
  height: 0;
  flex-shrink: 0;
  border-top: 2px solid var(--ink);
}

.legend-swatch.legend-prerequisito {
  border-top-width: 3px;
}

.legend-swatch.legend-amplia {
  border-top-style: dashed;
  border-top-width: 2px;
}

.legend-code {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  min-width: 24px;
}

.legend-name {
  color: var(--ink);
  text-transform: capitalize;
}

/* ── SVG grafo ─────────────────────────────────────────────── */

.graph-node {
  cursor: pointer;
  outline: none;
}

.graph-node .node-bg {
  fill: var(--bg-sheet);
  stroke: var(--rule-strong);
  stroke-width: 1;
  rx: 3;
  transition:
    stroke var(--motion-fast) var(--ease-out),
    stroke-width var(--motion-fast) var(--ease-out);
}

.graph-node[data-topic-category] .node-bg {
  fill: color-mix(in srgb, var(--topic-accent) 10%, var(--bg-sheet));
}

.graph-node[data-topic-category] .node-stripe {
  fill: var(--topic-accent);
}

.graph-node .node-label {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  fill: var(--ink);
  pointer-events: none;
  dominant-baseline: central;
}

.graph-node .node-index {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 600;
  fill: var(--ink-muted);
  pointer-events: none;
  dominant-baseline: central;
}

.graph-node:hover .node-bg,
.graph-node:focus-visible .node-bg {
  stroke: var(--ink);
  stroke-width: 1.5;
}

.graph-node.is-selected .node-bg {
  stroke: var(--ink);
  stroke-width: 2;
}

.graph-node.is-dragging .node-bg {
  stroke: var(--action);
  stroke-width: 2;
}

.graph-node.is-dimmed {
  opacity: 0.28;
}

.graph-node.is-highlighted {
  opacity: 1;
}

.graph-node.is-entering {
  transform-box: fill-box;
  transform-origin: center;
  animation: node-enter var(--motion-base) var(--ease-out) both;
  animation-delay: calc(var(--enter-i, 0) * 40ms);
}

@keyframes node-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.graph-edge {
  fill: none;
  stroke: var(--ink-muted);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  transition:
    stroke var(--motion-fast) var(--ease-out),
    stroke-width var(--motion-fast) var(--ease-out),
    opacity var(--motion-fast) var(--ease-out);
}

.graph-edge.edge-prerequisito {
  stroke: var(--ink);
  stroke-width: 2;
}

.graph-edge.edge-amplia {
  stroke: var(--ink-muted);
  stroke-width: 1.5;
  stroke-dasharray: 6 4;
}

.graph-edge.edge-relacionado {
  stroke: var(--rule-strong);
  stroke-width: 1.5;
}

.graph-edge.is-highlighted {
  stroke: var(--action);
  stroke-width: 2.5;
  opacity: 1;
}

.graph-edge.is-dimmed {
  opacity: 0.15;
}
