.detail-drawer {
  width: min(1040px, calc(100vw - 32px));
}

.detail-drawer .compact-metric-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 3px;
}

.compact-metric-row .metric {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  min-width: 116px;
  padding: 7px 9px;
}

.compact-metric-row .metric--wide {
  min-width: 156px;
}

.compact-metric-row .metric small,
.compact-metric-row .metric strong {
  white-space: nowrap;
}

.compact-metric-row .metric strong.metric-rich,
.compact-metric-row .metric strong.metric-rich *,
.compact-metric-row .metric strong.reduction-path,
.compact-metric-row .metric strong.reduction-path * {
  white-space: normal;
}

.compact-metric-row .metric small {
  color: var(--muted);
  font-size: 0.72rem;
}

.compact-metric-row .metric strong {
  display: inline;
  font-size: 0.95rem;
}

.compact-metric-row .metric strong.reduction-path {
  display: flex;
  flex-wrap: wrap;
}

.compact-metric-row .metric--wide {
  align-items: flex-start;
  flex: 1 1 min(520px, 70vw);
  min-width: min(360px, 82vw);
  max-width: min(640px, 100%);
}

.compact-metric-row .metric--wide .metric-rich {
  display: block;
  width: 100%;
  min-width: 0;
}

.compact-metric-row .metric--wide .numeric-relation-pill {
  flex: 1 1 150px;
}

.relation-map-section {
  margin-top: 14px;
}

.relation-map {
  position: relative;
  min-height: 356px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0a0710;
  overflow: hidden;
  box-shadow: inset 0 0 28px rgba(134, 242, 214, 0.07);
}

.relation-map-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.relation-edge {
  stroke: rgba(244, 239, 227, 0.2);
  stroke-width: 0.45;
}

.relation-edge-chip {
  position: absolute;
  left: var(--mx);
  top: var(--my);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  max-width: 148px;
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid rgba(244, 239, 227, 0.2);
  border-radius: 999px;
  background: rgba(10, 7, 16, 0.9);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
  transform: translate(-50%, -50%);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.32);
}

.relation-edge-chip span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation-edge-chip:hover,
.relation-edge-chip:focus-visible {
  outline: none;
  border-color: rgba(244, 239, 227, 0.64);
  box-shadow: 0 0 0 2px rgba(244, 239, 227, 0.12), 0 12px 24px rgba(0, 0, 0, 0.42);
}

.relation-edge-chip--same-value {
  color: var(--gold);
  border-color: rgba(254, 198, 48, 0.48);
}

.relation-edge-chip--same-source {
  color: var(--green-2);
  border-color: rgba(134, 242, 214, 0.44);
}

.relation-edge-chip--same-tags {
  color: #c8c1ff;
  border-color: rgba(154, 142, 255, 0.5);
}

.relation-edge-detail {
  position: absolute;
  left: var(--mx);
  top: var(--my);
  z-index: 7;
  display: grid;
  gap: 7px;
  width: min(340px, calc(100% - 24px));
  max-height: 236px;
  overflow: auto;
  padding: 10px;
  border: 1px solid rgba(134, 242, 214, 0.28);
  border-radius: 8px;
  background: rgba(12, 8, 17, 0.98);
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 14px));
  transition: opacity 0.16s ease, transform 0.16s ease;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.46);
}

.relation-edge-detail--lower {
  transform: translate(-50%, 14px);
}

.relation-edge-chip:hover + .relation-edge-detail,
.relation-edge-chip:focus + .relation-edge-detail,
.relation-edge-chip:focus-visible + .relation-edge-detail,
.relation-edge-detail:hover {
  opacity: 1;
  pointer-events: auto;
}

.relation-edge-detail strong {
  color: var(--gold);
  font-size: 0.88rem;
}

.relation-edge-detail p {
  margin: 0;
  color: var(--ink);
  font-size: 0.8rem;
  line-height: 1.35;
}

.relation-edge-detail dl {
  display: grid;
  gap: 5px;
  margin: 0;
}

.relation-edge-detail dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.relation-edge-detail dd {
  margin: 0;
  color: var(--green-2);
  font-size: 0.76rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.relation-detail-value--formula {
  max-height: 82px;
  overflow: auto;
  color: var(--ink);
  direction: ltr;
  text-align: left;
  unicode-bidi: plaintext;
}

.relation-edge--same-value {
  stroke: rgba(254, 198, 48, 0.46);
}

.relation-edge--same-source {
  stroke: rgba(134, 242, 214, 0.42);
}

.relation-edge--same-tags {
  stroke: rgba(154, 142, 255, 0.46);
}

.relation-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 4;
  display: grid;
  gap: 2px;
  align-content: center;
  justify-items: center;
  width: 142px;
  min-height: 58px;
  padding: 7px 9px;
  border: 1px solid rgba(244, 239, 227, 0.16);
  border-radius: var(--radius);
  background: rgba(33, 21, 41, 0.94);
  color: var(--ink);
  text-align: center;
  transform: translate(-50%, -50%);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
}

button.relation-node {
  font: inherit;
}

.relation-node strong,
.relation-node small,
.relation-node span,
.relation-node em {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation-node strong {
  color: var(--gold);
  font-size: 1.2rem;
}

.relation-node small,
.relation-node span {
  color: var(--muted);
  font-size: 0.72rem;
}

.relation-node span {
  color: var(--green-2);
  font-weight: 800;
}

.relation-node em {
  color: var(--gold);
  font-size: 0.74rem;
  font-style: normal;
  font-weight: 900;
}

.relation-node--center {
  z-index: 5;
  width: 168px;
  min-height: 82px;
  border-color: rgba(254, 198, 48, 0.58);
  background: linear-gradient(150deg, rgba(254, 198, 48, 0.18), rgba(33, 21, 41, 0.96));
}

.relation-node--center strong {
  font-size: 1.55rem;
}

.relation-node--same-value {
  border-color: rgba(254, 198, 48, 0.54);
}

.relation-node--same-source {
  border-color: rgba(134, 242, 214, 0.52);
}

.relation-node--same-tags {
  border-color: rgba(154, 142, 255, 0.52);
}

.relation-node--satellite:hover,
.relation-node--satellite:focus-visible {
  border-color: rgba(134, 242, 214, 0.82);
  outline: none;
  box-shadow: 0 0 0 2px rgba(134, 242, 214, 0.14), 0 18px 34px rgba(0, 0, 0, 0.36);
}

@media (max-width: 620px) {
  .detail-drawer {
    width: calc(100vw - 20px);
  }

  .relation-map {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: 0;
    padding: 10px;
  }

  .relation-map-lines {
    display: none;
  }

  .relation-edge-chip {
    position: static;
    width: 100%;
    max-width: none;
    min-height: 34px;
    transform: none;
  }

  .relation-edge-detail {
    position: static;
    display: none;
    width: 100%;
    max-height: 220px;
    opacity: 1;
    pointer-events: auto;
    transform: none;
  }

  .relation-edge-chip:hover + .relation-edge-detail,
  .relation-edge-chip:focus + .relation-edge-detail,
  .relation-edge-chip:focus-visible + .relation-edge-detail,
  .relation-edge-detail:hover {
    display: grid;
  }

  .relation-node {
    position: static;
    width: 100%;
    min-height: 48px;
    transform: none;
  }

  .relation-node--center {
    min-height: 62px;
  }
}
