<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Psychiatry summary · {{ $patient->fullName() }}</title>
    <style>
        body { font-family: system-ui, sans-serif; color: #0f172a; margin: 2rem; }
        h1 { font-size: 1.25rem; margin: 0 0 .25rem; }
        h2 { font-size: .95rem; margin: 1.25rem 0 .5rem; border-bottom: 1px solid #e2e8f0; padding-bottom: .25rem; }
        .meta { color: #64748b; font-size: .875rem; }
        dl { display: grid; grid-template-columns: 10rem 1fr; gap: .35rem .75rem; font-size: .875rem; }
        dt { color: #64748b; }
        dd { margin: 0; font-weight: 500; }
        @media print { .no-print { display: none; } }
    </style>
</head>
<body>
    <p class="no-print"><a href="{{ route('care.specialty.workspace', ['module' => 'psychiatry', 'visit' => $visit]) }}">Back</a></p>

    <h1>{{ $patient->fullName() }}</h1>
    <p class="meta">
        {{ $patient->patient_number }}
        · Visit #{{ $visit->id }}
        · Stage {{ $visit->specialty_stage ?? '—' }}
        · {{ $visit->checked_in_at?->format('d M Y H:i') ?? '—' }}
    </p>

    <h2>History / MSE</h2>
    @if ($history)
        <dl>
            <dt>Presenting</dt><dd>{{ $history->payload['chief_complaint'] ?? '—' }}</dd>
            <dt>History</dt><dd>{{ $history->payload['history'] ?? '—' }}</dd>
            <dt>Mood / affect</dt><dd>{{ $history->payload['mood_affect'] ?? '—' }}</dd>
            <dt>Thought</dt><dd>{{ $history->payload['thought'] ?? '—' }}</dd>
            <dt>MSE summary</dt><dd>{{ $history->payload['mse_summary'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No MSE recorded.</p>
    @endif

    <h2>Risk assessment</h2>
    @if ($risk)
        <dl>
            <dt>Overall risk</dt><dd>{{ $risk->payload['overall_risk'] ?? '—' }}</dd>
            <dt>Self-harm</dt><dd>{{ $risk->payload['self_harm'] ?? '—' }}</dd>
            <dt>Risk to others</dt><dd>{{ $risk->payload['harm_others'] ?? '—' }}</dd>
            <dt>Summary</dt><dd>{{ $risk->payload['risk_summary'] ?? '—' }}</dd>
            <dt>Actions</dt><dd>{{ $risk->payload['immediate_actions'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No risk assessment recorded.</p>
    @endif

    <h2>Formulation / plan</h2>
    @if ($plan)
        <dl>
            <dt>Formulation</dt><dd>{{ $plan->payload['formulation'] ?? '—' }}</dd>
            <dt>Diagnosis</dt><dd>{{ $plan->payload['diagnosis'] ?? '—' }}</dd>
            <dt>Plan</dt><dd>{{ $plan->payload['plan'] ?? '—' }}</dd>
            <dt>Medications</dt><dd>{{ $plan->payload['medications'] ?? '—' }}</dd>
            <dt>Follow-up</dt><dd>{{ $plan->payload['follow_up'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No formulation recorded.</p>
    @endif

    <h2>Follow-up</h2>
    @if ($followup)
        <dl>
            <dt>Review type</dt><dd>{{ $followup->payload['review_type'] ?? '—' }}</dd>
            <dt>Progress</dt><dd>{{ $followup->payload['progress'] ?? '—' }}</dd>
            <dt>Outcome</dt><dd>{{ $followup->payload['outcome'] ?? '—' }}</dd>
            <dt>Next steps</dt><dd>{{ $followup->payload['next_steps'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No follow-up recorded.</p>
    @endif

    <script>window.print();</script>
</body>
</html>
