<?php
function cp_h($v){ return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); }
$title = ($certificate['conference_title_ar'] ?? '') ?: ($certificate['conference_title_en'] ?? '');
$verify = $certificate['verification_url'] ?? ('/easychair/certificates/verify?token=' . ($certificate['verify_token'] ?? ''));
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title><?= cp_h($certificate['certificate_no'] ?? 'Certificate') ?></title>
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;700;900&display=swap" rel="stylesheet">
<style>
@page{size:A4 landscape;margin:12mm}
body{font-family:Cairo,sans-serif;background:#f1f5f9;margin:0}
.cert{background:white;margin:auto;border:10px solid #1d4ed8;min-height:690px;padding:55px;text-align:center;position:relative}
.cert:before{content:"";position:absolute;inset:22px;border:2px solid #93c5fd}
h1{font-size:46px;margin:15px 0;color:#0f172a}
h2{font-size:30px;color:#1d4ed8;margin:10px 0}
.name{font-size:40px;font-weight:900;color:#111827;margin:25px 0}
.body{font-size:22px;line-height:1.9;max-width:900px;margin:25px auto}
.meta{position:absolute;bottom:35px;left:55px;right:55px;display:flex;justify-content:space-between;font-size:14px;color:#475569}
button{position:fixed;top:12px;left:12px;padding:10px 18px}
@media print{button{display:none}body{background:white}.cert{border-color:#1d4ed8}}
</style>
</head>
<body>
<button onclick="window.print()">Print</button>
<div class="cert">
    <h2><?= cp_h($title) ?></h2>
    <h1><?= cp_h($certificate['title_ar'] ?: $certificate['title_en']) ?></h1>
    <div>تمنح هذه الشهادة إلى / This certificate is awarded to</div>
    <div class="name"><?= cp_h($certificate['recipient_name']) ?></div>
    <div class="body"><?= nl2br(cp_h($certificate['body_ar'] ?: $certificate['body_en'])) ?></div>
    <div class="meta">
        <div>
            Certificate No: <?= cp_h($certificate['certificate_no']) ?><br>
            Status: <?= cp_h($certificate['status']) ?>
        </div>
        <div>
            Issued: <?= cp_h($certificate['issued_at']) ?><br>
            Verify: <?= cp_h($verify) ?>
        </div>
    </div>
</div>
</body>
</html>
