<?php $e=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8'); ?>
<section class="page-header"><div><p class="eyebrow">Clinical · Patient</p><h1><?= $e($patient['first_name'].' '.$patient['last_name']) ?></h1><p><?= $e($patient['patient_reference']) ?></p></div><div class="action-row"><a class="btn btn-secondary" href="/crm/public/patients">Back to Patients</a><?php if(\App\Core\Auth::hasPermission('sessions.create')): ?><a class="btn btn-primary" href="/crm/public/sessions/create">Record Session</a><?php endif; ?></div></section>
<section class="card section-gap"><div class="card-header"><div><h2>Patient information</h2><p>Current demographic record.</p></div></div><div class="detail-grid"><div><span class="detail-label">Date of birth</span><strong><?= $e($patient['date_of_birth']??'—') ?></strong></div><div><span class="detail-label">Gender</span><strong><?= $e($patient['gender']??'—') ?></strong></div><div><span class="detail-label">Phone</span><strong><?= $e($patient['phone']??'—') ?></strong></div><div><span class="detail-label">Email</span><strong><?= $e($patient['email']??'—') ?></strong></div><div><span class="detail-label">Parent / Guardian</span><strong><?= $e($patient['parent_guardian']??'—') ?></strong></div><div><span class="detail-label">Emergency contact</span><strong><?= $e($patient['emergency_contact']??'—') ?></strong></div><div class="detail-wide"><span class="detail-label">Address</span><strong><?= nl2br($e($patient['address']??'—')) ?></strong></div></div></section>
<section class="card table-card"><div class="card-header"><div><h2>Care team</h2><p>Current and historical therapist assignments.</p></div></div><div class="table-wrap"><table class="data-table"><thead><tr><th>Therapist</th><th>Role</th><th>Start</th><th>End</th><th>Status</th></tr></thead><tbody><?php foreach($assignments as $a): ?><tr><td><?= $e($a['therapist_name']) ?></td><td><?= $e(ucfirst($a['role'])) ?></td><td><?= $e($a['assigned_at']) ?></td><td><?= $e($a['ended_at']??'—') ?></td><td><span class="badge <?= $a['status']==='active'?'badge-success':'badge-muted' ?>"><?= $e(ucfirst($a['status'])) ?></span></td></tr><?php endforeach; if(empty($assignments)): ?><tr><td colspan="5">No assignment history.</td></tr><?php endif; ?></tbody></table></div></section>
