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

.tree-svg {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: var(--surface-alt);
  display: block;
  overflow: hidden;
}

/* Legend pinned to the bottom-left of the canvas. It is a fixed overlay (it does
   not pan or zoom with the tree) and collapses to its title bar. Block kinds use
   solid fill swatches; edge kinds use real <line> swatches (see .tree-edge). */
.tree-legend {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 2;
  max-width: min(240px, calc(100% - 20px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.14);
  font-size: 12px;
}

.tree-legend-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 5px 9px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font: inherit;
}

.tree-legend-title {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tree-legend-chevron {
  color: var(--muted);
  transition: transform 0.15s ease;
}

.tree-legend[data-collapsed="true"] .tree-legend-chevron {
  transform: rotate(-90deg);
}

.tree-legend[data-collapsed="true"] .tree-legend-body {
  display: none;
}

.tree-legend-body {
  display: grid;
  gap: 5px;
  padding: 2px 9px 8px;
}

.tree-legend-group-title {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.tree-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  line-height: 1.4;
}

.tree-legend-node-swatch {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.tree-legend-edge-swatch {
  flex: 0 0 auto;
  width: 22px;
  height: 8px;
  display: block;
}

.status-line {
  min-height: 24px;
  padding: 5px 10px;
}

.status-line[data-state="error"] {
  color: var(--stale);
}

.badge,
.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--surface-alt);
  white-space: nowrap;
  font-size: 12px;
}

.kind-canonical { color: var(--canonical); }
.kind-stale { color: var(--stale); }
.kind-near { color: var(--near); }
.kind-unknown { color: var(--unknown); }
.kind-context { color: var(--context); }

.fill-canonical { background: var(--canonical); }
.fill-stale { background: var(--stale); }
.fill-near { background: var(--near); }
.fill-unknown { background: var(--unknown); }
.fill-context { background: var(--context); }
.fill-strict_btc_orphan { background: var(--orphan-strict); }
.fill-weak_btc_orphan { background: var(--orphan-weak); }
.fill-btc_stale_excluded { background: var(--orphan-excluded); }
.fill-pending { background: var(--orphan-pending); }
