<?php $e=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8'); ?>
<section class="page-header"><div><p class="eyebrow">System</p><h1>Notifications</h1><p>Recent CRM alerts and actions.</p></div><?php if(($unread??0)>0): ?><form method="post" action="/crm/public/notifications/read-all"><input type="hidden" name="_csrf" value="<?= $e($csrf) ?>"><button class="btn btn-secondary" type="submit">Mark all read</button></form><?php endif; ?></section>
<?php if(!empty($message)): ?><div class="alert alert-success"><?= $e($message) ?></div><?php endif; ?>
<section class="card"><div class="card-header"><div><h2><?= (int)($unread??0) ?> unread</h2><p>Latest activity for your account.</p></div></div>
<?php if(empty($notifications)): ?><div class="empty-state"><h3>You're all caught up</h3><p>No notifications yet.</p></div><?php else: ?><div style="display:grid;gap:10px"><?php foreach($notifications as $n): ?><div class="card" style="margin:0;border:1px solid #e5e7eb;box-shadow:none;opacity:<?= $n['read_at']?'0.72':'1' ?>"><div style="display:flex;justify-content:space-between;gap:12px;align-items:flex-start"><div><strong><?= $e($n['title']) ?></strong><p style="margin:.35rem 0"><?= $e($n['message']) ?></p><small class="muted"><?= $e($n['created_at']) ?></small></div><?php if(!$n['read_at']): ?><form method="post" action="/crm/public/notifications/<?= (int)$n['id'] ?>/read"><input type="hidden" name="_csrf" value="<?= $e($csrf) ?>"><input type="hidden" name="link" value="<?= $e($n['link']??'') ?>"><button class="btn btn-small btn-secondary" type="submit"><?= !empty($n['link'])?'Open':'Read' ?></button></form><?php elseif(!empty($n['link'])): ?><a class="btn btn-small btn-secondary" href="<?= $e($n['link']) ?>">Open</a><?php endif; ?></div></div><?php endforeach; ?></div><?php endif; ?></section>
