<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Verify Consent</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: #f1f5f9; color: #1e293b; min-height: 100vh;
    display: flex; align-items: center; justify-content: center; padding: 18px;
}
.card {
    background: #fff; border-radius: 14px; padding: 26px 28px; max-width: 540px; width: 100%;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.08); border: 1px solid #e2e8f0;
}
.icon-bubble {
    width: 64px; height: 64px; border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 30px; margin: 0 auto 14px;
}
.icon-ok    { background: #ecfdf5; color: #059669; border: 2px solid #a7f3d0; }
.icon-warn  { background: #fef3c7; color: #b45309; border: 2px solid #fde68a; }
.icon-err   { background: #fef2f2; color: #b91c1c; border: 2px solid #fecaca; }

h1 { font-size: 19px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.subtitle { text-align: center; color: #64748b; font-size: 13px; margin-bottom: 22px; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.row .lbl { color: #64748b; font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; margin-bottom: 2px; }
.row .val { color: #1e293b; font-weight: 700; font-size: 13px; }

.hash {
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
    padding: 10px 12px; font-family: 'Consolas', 'Monaco', monospace; font-size: 11px;
    word-break: break-all; color: #475569; margin-top: 12px;
}

.divider { height: 1px; background: #e2e8f0; margin: 18px 0; }

.footer { text-align: center; font-size: 11px; color: #94a3b8; margin-top: 18px; }

.bad-msg { text-align: center; color: #475569; font-size: 14px; line-height: 1.6; }
</style>
</head>
<body>
<div class="card">

    @if(empty($ok))
        @php
            $r = $reason ?? '';
            $msg = $r === 'bad_format'
                ? 'The verification code in the link is not in a recognised format.'
                : 'No consent signature was found for this code.';
        @endphp
        <div class="icon-bubble icon-err">⚠</div>
        <h1>Verification failed</h1>
        <div class="subtitle">This signature could not be verified</div>
        <div class="bad-msg">{{ $msg }}</div>

    @elseif($is_active && !$is_archived)
        <div class="icon-bubble icon-ok">✓</div>
        <h1>Signature verified</h1>
        <div class="subtitle">This consent carries a valid digital signature.</div>

        <div class="row">
            <div><div class="lbl">Clinic</div><div class="val">{{ $business->name ?? '—' }}</div></div>
            <div><div class="lbl">Signed on</div><div class="val">{{ optional($sig->signed_at)->format('d M Y, H:i') }}</div></div>
        </div>
        <div class="row">
            <div><div class="lbl">Patient</div><div class="val">{{ optional($consent->pet)->petname ?? '—' }}</div></div>
            <div><div class="lbl">Owner</div><div class="val">{{ optional($consent->owner)->name ?? '—' }}</div></div>
        </div>
        <div class="row">
            <div><div class="lbl">Consent</div><div class="val">{{ $consent->title }}</div></div>
            <div><div class="lbl">Signed by</div><div class="val">{{ $sig->signed_by_name }}
                @if($sig->signed_by_relation)<span style="color:#64748b;font-weight:400;"> · {{ $sig->signed_by_relation }}</span>@endif
            </div></div>
        </div>
        <div class="row">
            <div><div class="lbl">Method</div><div class="val">{{ $sig->method_label }}</div></div>
            <div></div>
        </div>

        <div class="divider"></div>
        <div class="lbl" style="color:#64748b;font-size:10px;font-weight:700;letter-spacing:.5px;">Signature hash (SHA-256)</div>
        <div class="hash">{{ $sig->png_hash_sha256 }}</div>

    @else
        <div class="icon-bubble icon-warn">!</div>
        <h1>Signature is no longer current</h1>
        <div class="subtitle">
            @if($is_archived)
                The consent has since been archived.
            @else
                A newer signature has superseded this one.
            @endif
        </div>

        <div class="row">
            <div><div class="lbl">Originally signed</div><div class="val">{{ optional($sig->signed_at)->format('d M Y, H:i') }}</div></div>
            <div><div class="lbl">Status</div><div class="val">{{ $is_archived ? 'Archived' : 'Superseded' }}</div></div>
        </div>
        <div class="row">
            <div><div class="lbl">Consent</div><div class="val">{{ $consent->title }}</div></div>
            <div><div class="lbl">Patient</div><div class="val">{{ optional($consent->pet)->petname ?? '—' }}</div></div>
        </div>

        <div class="divider"></div>
        <div class="lbl">Hash</div>
        <div class="hash">{{ $sig->png_hash_sha256 }}</div>
    @endif

    <div class="footer">Veterinary Clinic Consent Verification</div>
</div>
</body>
</html>
