<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Eye care 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' => 'ophthalmology', '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>Visual acuity / refraction</h2>
    @if ($refraction)
        <dl>
            <dt>VA OD / OS</dt><dd>{{ $refraction->payload['va_od'] ?? '—' }} / {{ $refraction->payload['va_os'] ?? '—' }}</dd>
            <dt>Near VA</dt><dd>{{ $refraction->payload['va_od_near'] ?? '—' }} / {{ $refraction->payload['va_os_near'] ?? '—' }}</dd>
            <dt>OD Rx</dt>
            <dd>
                Sph {{ $refraction->payload['sphere_od'] ?? '—' }}
                Cyl {{ $refraction->payload['cylinder_od'] ?? '—' }}
                Axis {{ $refraction->payload['axis_od'] ?? '—' }}
            </dd>
            <dt>OS Rx</dt>
            <dd>
                Sph {{ $refraction->payload['sphere_os'] ?? '—' }}
                Cyl {{ $refraction->payload['cylinder_os'] ?? '—' }}
                Axis {{ $refraction->payload['axis_os'] ?? '—' }}
            </dd>
            <dt>Add / PD</dt><dd>{{ $refraction->payload['add'] ?? '—' }} / {{ $refraction->payload['pd'] ?? '—' }}</dd>
            <dt>Notes</dt><dd>{{ $refraction->payload['notes'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No refraction recorded.</p>
    @endif

    <h2>Examination</h2>
    @if ($exam)
        <dl>
            <dt>Chief complaint</dt><dd>{{ $exam->payload['chief_complaint'] ?? '—' }}</dd>
            <dt>History</dt><dd>{{ $exam->payload['history'] ?? '—' }}</dd>
            <dt>IOP OD / OS</dt><dd>{{ $exam->payload['iop_od'] ?? '—' }} / {{ $exam->payload['iop_os'] ?? '—' }}</dd>
            <dt>Pupils</dt><dd>{{ $exam->payload['pupils'] ?? '—' }}</dd>
            <dt>Anterior segment</dt><dd>{{ $exam->payload['anterior_segment'] ?? '—' }}</dd>
            <dt>Fundus</dt><dd>{{ $exam->payload['fundus'] ?? '—' }}</dd>
            <dt>Findings</dt><dd>{{ $exam->payload['findings'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No examination recorded.</p>
    @endif

    <h2>Investigations</h2>
    @if ($investigation)
        <dl>
            <dt>Modality</dt><dd>{{ $investigation->payload['modality'] ?? '—' }}</dd>
            <dt>Eye</dt><dd>{{ $investigation->payload['eye'] ?? '—' }}</dd>
            <dt>Findings</dt><dd>{{ $investigation->payload['findings'] ?? '—' }}</dd>
            <dt>Impression</dt><dd>{{ $investigation->payload['impression'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No investigation recorded.</p>
    @endif

    <h2>Diagnosis &amp; plan</h2>
    @if ($plan)
        <dl>
            <dt>Diagnosis</dt><dd>{{ $plan->payload['diagnosis'] ?? '—' }}</dd>
            <dt>Laterality</dt><dd>{{ $plan->payload['laterality'] ?? '—' }}</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 plan recorded.</p>
    @endif

    <h2>Procedure / treatment</h2>
    @if ($procedure)
        <dl>
            <dt>Procedure</dt><dd>{{ $procedure->payload['procedure'] ?? '—' }}</dd>
            <dt>Eye</dt><dd>{{ $procedure->payload['eye'] ?? '—' }}</dd>
            <dt>Outcome</dt><dd>{{ $procedure->payload['outcome'] ?? '—' }}</dd>
            <dt>Post-op plan</dt><dd>{{ $procedure->payload['post_op_plan'] ?? '—' }}</dd>
            <dt>Notes</dt><dd>{{ $procedure->payload['notes'] ?? '—' }}</dd>
        </dl>
    @else
        <p class="meta">No procedure recorded.</p>
    @endif

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