<?php
/**
 * Slate — shared error-page renderer.
 *
 * Used by 404.php / 403.php / 500.php at the root. Renders a tiny,
 * self-contained HTML page (no DB calls, no plugin code, no
 * template engine) styled to match the design system.
 *
 *   slate_render_error(404, 'Not found', 'We couldn\'t find that page.');
 */
if (!function_exists('slate_render_error')) {
    function slate_render_error(int $status, string $title, string $message): void {
        @http_response_code($status);

        $home = defined('SLATE_URL') ? SLATE_URL : '/';
        $home = htmlspecialchars($home, ENT_QUOTES, 'UTF-8');
        $title   = htmlspecialchars($title,   ENT_QUOTES, 'UTF-8');
        $message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');

        echo "<!doctype html><meta charset=\"utf-8\">"
           . "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"
           . "<title>{$status} · {$title}</title>"
           . "<style>"
           . "body{font-family:'DM Sans',-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;"
           . "background:#F5F4F1;color:#111217;display:grid;place-items:center;min-height:100vh;margin:0;padding:24px;}"
           . ".card{background:#fff;border:1px solid rgba(0,0,0,0.08);border-radius:12px;"
           . "padding:36px 32px;max-width:480px;text-align:center;}"
           . ".code{font-family:'DM Mono',ui-monospace,'SF Mono',Menlo,monospace;color:#9CA3AF;font-size:13px;"
           . "letter-spacing:0.08em;font-weight:600;text-transform:uppercase;margin:0 0 8px;}"
           . "h1{font-family:'Syne','DM Sans',sans-serif;margin:0 0 8px;font-size:24px;letter-spacing:-0.02em;}"
           . "p{margin:0 0 20px;color:#6B7280;font-size:14px;line-height:1.5;}"
           . "a.btn{display:inline-flex;align-items:center;gap:6px;padding:9px 14px;"
           . "background:#2563EB;color:#fff;border-radius:8px;text-decoration:none;font-weight:500;font-size:13.5px;}"
           . "a.btn:hover{background:#1D4ED8;}"
           . "</style>"
           . "<div class=\"card\">"
           . "<div class=\"code\">Error {$status}</div>"
           . "<h1>{$title}</h1>"
           . "<p>{$message}</p>"
           . "<a class=\"btn\" href=\"{$home}/\">Return home</a>"
           . "</div>";
    }
}
