<div class="mx-auto max-w-6xl"><div class="mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"><div><p class="text-xs font-bold uppercase tracking-[.15em] text-teal-600"><?= esc(ucwords(str_replace('_',' ',$visit['status']))) ?></p><h2 class="mt-1 font-display text-2xl font-extrabold"><?= esc($visit['service_name']) ?></h2><p class="mt-1 text-sm text-slate-500">Patient: <?= esc($visit['patient_name']) ?></p></div><a href="/practitioner/visits" class="text-sm font-bold text-slate-500">← Back to visits</a></div>
<div class="grid gap-6 lg:grid-cols-[.8fr_1.2fr]"><div class="space-y-6"><section class="rounded-2xl border border-slate-100 bg-white p-5 shadow-card"><h3 class="font-display text-lg font-extrabold">Visit workflow</h3><div class="mt-4 space-y-3 text-sm"><div class="rounded-xl bg-slate-50 p-4"><div class="text-xs text-slate-400">Address</div><div class="mt-1 font-semibold"><?= esc($visit['address_text']) ?></div></div><div class="rounded-xl bg-slate-50 p-4"><div class="text-xs text-slate-400">Patient notes</div><div class="mt-1 leading-6 text-slate-600"><?= esc($visit['chief_complaint']) ?></div></div></div><?php $next=match($visit['status']){'accepted','scheduled'=>'en_route','en_route'=>'arrived','arrived'=>'in_progress','in_progress'=>'completed',default=>null};if($next): ?><form action="/practitioner/visits/<?= $visit['id'] ?>/status" method="post" class="mt-5"><?= csrf_field() ?><input type="hidden" name="status" value="<?= $next ?>"><button class="w-full rounded-xl bg-teal-600 px-5 py-3 text-sm font-extrabold text-white"><?= match($next){'en_route'=>'Start journey','arrived'=>'Mark arrived','in_progress'=>'Start visit','completed'=>'Complete visit',default=>'Update visit'} ?></button></form><?php endif; ?></section>
<section class="relative h-[330px] overflow-hidden rounded-2xl border border-slate-100 map-grid shadow-card"><div class="absolute left-[12%] top-[22%] w-[75%] map-road rotate-6"></div><div class="pin" style="left:22%;top:28%"><span>ME</span></div><div class="absolute right-[18%] bottom-[24%] grid h-12 w-12 place-items-center rounded-full bg-coral text-white"><i data-lucide="house" class="h-5 w-5"></i></div></section></div>
<div class="space-y-6"><section class="rounded-2xl border border-slate-100 bg-white p-5 shadow-card"><h3 class="font-display text-lg font-extrabold">Clinical note</h3><p class="mt-1 text-xs leading-5 text-slate-400">Clinical documentation becomes part of the patient’s protected health record.</p><?php if($errors=session()->getFlashdata('errors')): ?><div class="mt-4 rounded-xl bg-rose-50 p-3 text-xs text-rose-700"><?php foreach($errors as $e): ?><div><?= esc($e) ?></div><?php endforeach; ?></div><?php endif; ?><form action="/practitioner/visits/<?= $visit['id'] ?>/notes" method="post" class="mt-5 grid gap-4"><?= csrf_field() ?><div><label class="mb-1.5 block text-xs font-bold text-slate-500">Subjective</label><textarea name="subjective" class="min-h-20 w-full rounded-xl border border-slate-200 px-4 py-3 text-sm" placeholder="Patient-reported symptoms and history"></textarea></div><div><label class="mb-1.5 block text-xs font-bold text-slate-500">Objective</label><textarea name="objective" class="min-h-20 w-full rounded-xl border border-slate-200 px-4 py-3 text-sm" placeholder="Observations and examination findings"></textarea></div><div><label class="mb-1.5 block text-xs font-bold text-slate-500">Assessment</label><textarea name="assessment" required class="min-h-20 w-full rounded-xl border border-slate-200 px-4 py-3 text-sm"></textarea></div><div><label class="mb-1.5 block text-xs font-bold text-slate-500">Plan</label><textarea name="plan" required class="min-h-20 w-full rounded-xl border border-slate-200 px-4 py-3 text-sm"></textarea></div><button class="justify-self-start rounded-xl bg-navy px-5 py-3 text-sm font-extrabold text-white">Save clinical note</button></form></section><div class="grid gap-4 md:grid-cols-2"><section class="rounded-2xl border border-slate-100 bg-white p-5 shadow-card"><h3 class="font-display font-extrabold">Issue prescription</h3><form action="/practitioner/visits/<?= $visit['id'] ?>/prescription" method="post" class="mt-4 space-y-3"><?= csrf_field() ?><input name="medication_name" required class="w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm" placeholder="Medication"><div class="grid grid-cols-2 gap-2"><input name="dose" class="rounded-xl border border-slate-200 px-3 py-2.5 text-sm" placeholder="Dose"><input name="frequency" class="rounded-xl border border-slate-200 px-3 py-2.5 text-sm" placeholder="Frequency"></div><input name="duration" class="w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm" placeholder="Duration"><textarea name="instructions" class="min-h-20 w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm" placeholder="Instructions"></textarea><button class="w-full rounded-xl bg-teal-600 px-4 py-3 text-sm font-bold text-white">Issue prescription</button></form></section><section class="rounded-2xl border border-slate-100 bg-white p-5 shadow-card"><h3 class="font-display font-extrabold">Request laboratory tests</h3><form action="/practitioner/visits/<?= $visit['id'] ?>/lab" method="post" class="mt-4 space-y-3"><?= csrf_field() ?><textarea name="tests" required class="min-h-32 w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm" placeholder="Tests requested"></textarea><select name="collection_type" class="w-full rounded-xl border border-slate-200 px-3 py-2.5 text-sm"><option value="home">Home sample collection</option><option value="facility">Facility collection</option></select><button class="w-full rounded-xl bg-navy px-4 py-3 text-sm font-bold text-white">Create lab request</button></form></section></div><section class="rounded-2xl border border-slate-100 bg-white p-5 shadow-card"><h3 class="font-display font-extrabold">Recent notes</h3><div class="mt-4 space-y-3"><?php if(!$notes): ?><p class="text-sm text-slate-400">No clinical notes recorded yet.</p><?php endif; ?><?php foreach($notes as $n): ?><div class="rounded-xl bg-slate-50 p-4 text-xs"><div class="font-bold text-navy">Assessment</div><p class="mt-1 line-clamp-2 leading-5 text-slate-500"><?= esc($n['assessment']) ?></p><div class="mt-2 text-[10px] text-slate-300"><?= date('M j, g:i A',strtotime($n['created_at'])) ?></div></div><?php endforeach; ?></div></section></div></div></div>
