@if(!empty($relatedEntities) && count($relatedEntities) > 0)
<section class="mt-8">
    <div class="mb-4 flex items-center justify-between gap-3">
        <h2 class="text-lg font-semibold text-white/90">Connected in Nova</h2>
        <span class="text-xs uppercase tracking-[0.18em] text-white/35">{{ count($relatedEntities) }} linked</span>
    </div>
    <div class="grid gap-4 md:grid-cols-2 xl:grid-cols-3">
        @foreach($relatedEntities as $entity)
            <a href="{{ $entity['url'] ?? '#' }}" class="group overflow-hidden rounded-[24px] border border-white/[0.08] bg-white/[0.03] transition hover:-translate-y-0.5 hover:border-white/[0.16]">
                <div class="relative aspect-[16/9] overflow-hidden bg-black/20">
                    @if(!empty($entity['image']))
                        <img src="{{ $entity['image'] }}" alt="{{ $entity['title'] }}" class="h-full w-full object-cover transition duration-300 group-hover:scale-[1.04]">
                    @else
                        <div class="absolute inset-0 bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.14),transparent_45%),linear-gradient(180deg,rgba(15,23,42,0.92),rgba(2,6,23,0.98))]"></div>
                    @endif
                    <div class="absolute inset-0 bg-gradient-to-t from-[#020611cc] via-transparent to-transparent"></div>
                </div>
                <div class="p-4">
                    <div class="flex flex-wrap items-center gap-2 text-[11px] font-semibold uppercase tracking-[0.16em] text-white/40">
                        <span class="text-sky-200">{{ $entity['context_label'] ?? ($entity['entity_label'] ?? 'Related') }}</span>
                        <span class="rounded-full border border-white/[0.08] bg-white/[0.04] px-2 py-0.5 text-white/55">{{ $entity['entity_label'] ?? 'Link' }}</span>
                    </div>
                    <div class="mt-3 flex items-start gap-3">
                        @if(!empty($entity['avatar']))
                            <img src="{{ $entity['avatar'] }}" alt="{{ $entity['title'] }}" class="h-11 w-11 rounded-2xl border border-white/[0.08] object-cover">
                        @endif
                        <div class="min-w-0 flex-1">
                            <h3 class="text-lg font-semibold text-white">{{ $entity['title'] }}</h3>
                            @if(!empty($entity['subtitle']))
                                <p class="mt-1 text-xs uppercase tracking-[0.16em] text-white/35">{{ $entity['subtitle'] }}</p>
                            @endif
                        </div>
                    </div>
                    @if(!empty($entity['description']))
                        <p class="mt-3 text-sm leading-6 text-white/60">{{ $entity['description'] }}</p>
                    @endif
                    @if(!empty($entity['meta']))
                        <div class="mt-4 flex flex-wrap gap-2 text-xs text-white/40">
                            @foreach($entity['meta'] as $meta)
                                <span class="rounded-full border border-white/[0.08] bg-white/[0.04] px-2.5 py-1">{{ $meta }}</span>
                            @endforeach
                        </div>
                    @endif
                </div>
            </a>
        @endforeach
    </div>
</section>
@endif