@php
    $intake = $childWelfareIntake?->payload ?? [];
    $assessment = $childWelfareAssessment?->payload ?? [];
    $plan = $childWelfarePlan?->payload ?? [];
@endphp

<section class="rounded-2xl border border-slate-200 bg-white p-5">
    <div class="flex flex-wrap items-start justify-between gap-3">
        <div>
            <h3 class="text-sm font-semibold text-slate-900">Child Welfare overview</h3>
            <p class="mt-0.5 text-xs text-slate-500">Intake, assessment, care plan, and follow-up for this CWC episode. Sensitive notes use the same clinical-record access controls as other specialty modules.</p>
        </div>
        <div class="flex flex-wrap gap-3 text-sm">
            <a href="{{ route('care.specialty.child-welfare.print', $workspaceVisit) }}" target="_blank" class="font-medium text-indigo-600">Print summary</a>
            <a href="{{ route('care.specialty.child-welfare.reports') }}" class="font-medium text-indigo-600">Child Welfare reports</a>
        </div>
    </div>

    <div class="mt-4 grid gap-3 sm:grid-cols-3">
        <div class="rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
            <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Visit reason</p>
            <p class="mt-1 text-sm font-semibold text-slate-900">{{ $intake['visit_reason'] ?? '—' }}</p>
            <p class="mt-1 text-xs text-slate-500">{{ $intake['caregiver'] ?? '—' }}</p>
        </div>
        <div class="rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
            <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Growth / assessment</p>
            <p class="mt-1 text-sm font-semibold text-slate-900">{{ $assessment['growth_status'] ?? 'Not assessed' }}</p>
            <p class="mt-1 text-xs text-slate-500">
                @if (! empty($assessment['weight_kg']))
                    {{ $assessment['weight_kg'] }} kg
                    @if (! empty($assessment['age_months'])) · {{ $assessment['age_months'] }} mo @endif
                @else
                    —
                @endif
            </p>
        </div>
        <div class="rounded-xl border border-slate-100 bg-slate-50 px-3 py-3">
            <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Care plan</p>
            <p class="mt-1 text-sm font-semibold text-slate-900">{{ \Illuminate\Support\Str::limit($plan['goals'] ?? 'Not set', 40) }}</p>
            <p class="mt-1 text-xs text-slate-500">{{ $plan['follow_up'] ?? '—' }}</p>
        </div>
    </div>

    <dl class="mt-4 grid gap-3 text-sm sm:grid-cols-2">
        <div>
            <dt class="text-slate-500">Interval history</dt>
            <dd class="font-medium text-slate-900">{{ $intake['history'] ?? '—' }}</dd>
        </div>
        <div>
            <dt class="text-slate-500">Assessment summary</dt>
            <dd class="font-medium text-slate-900">{{ $assessment['assessment_summary'] ?? '—' }}</dd>
        </div>
        <div>
            <dt class="text-slate-500">Queue</dt>
            <dd class="font-medium text-slate-900">
                {{ $workspaceVisit->appointment?->queue_ticket_number ?? '—' }}
                @if ($workspaceVisit->appointment?->queue_ticket_status)
                    <span class="text-slate-500">({{ $workspaceVisit->appointment->queue_ticket_status }})</span>
                @endif
            </dd>
        </div>
        <div>
            <dt class="text-slate-500">Checked in</dt>
            <dd class="font-medium text-slate-900">{{ $workspaceVisit->checked_in_at?->format('d M Y H:i') ?? '—' }}</dd>
        </div>
    </dl>

    @if (! empty($clinicalAlerts))
        <div class="mt-4 space-y-1.5 border-t border-slate-100 pt-4">
            <p class="text-xs font-semibold uppercase tracking-wide text-slate-500">Alerts</p>
            @foreach ($clinicalAlerts as $alert)
                <p class="text-sm {{ ($alert['severity'] ?? '') === 'critical' ? 'text-rose-700' : 'text-amber-800' }}">
                    {{ $alert['message'] ?? '' }}
                </p>
            @endforeach
        </div>
    @endif
</section>
