<?php
$accent = preg_match("/^#[0-9a-fA-F]{6}$/", $template["accent_color"])
    ? $template["accent_color"]
    : "#ff6846";
$ctaUrl = $template["cta_url"] ?? "";
$safeCtaUrl = preg_match("/^(https?:|mailto:)/i", $ctaUrl) === 1 ? $ctaUrl : "";
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= esc($template["subject"]) ?></title>
</head>
<body style="margin:0;padding:0;background:#edf0eb;color:#142522;font-family:Arial,Helvetica,sans-serif">
    <div style="display:none;max-height:0;overflow:hidden;opacity:0"><?= esc(
        $template["preheader"],
    ) ?></div>
    <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#edf0eb">
        <tr>
            <td align="center" style="padding:38px 16px">
                <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:640px;background:#ffffff;border-collapse:collapse;box-shadow:0 18px 48px rgba(20,37,34,.10)">
                    <tr>
                        <td style="height:7px;background:<?= esc(
                            $accent,
                        ) ?>"></td>
                    </tr>
                    <tr>
                        <td style="padding:30px 42px;background:#142522">
                            <table role="presentation" width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="font-size:24px;font-weight:800;color:#ffffff;letter-spacing:-1px">Brand<span style="color:#caff62">Square.</span></td>
                                    <td align="right" style="font-size:10px;font-weight:700;color:#91a09b;letter-spacing:1.5px;text-transform:uppercase">Brand identity studio</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding:48px 42px 42px">
                            <div style="width:38px;height:4px;background:<?= esc(
                                $accent,
                            ) ?>;margin-bottom:24px"></div>
                            <h1 style="margin:0 0 20px;font-size:34px;line-height:1.12;letter-spacing:-1.4px;color:#142522"><?= esc(
                                $template["heading"],
                            ) ?></h1>
                            <div style="font-size:16px;line-height:1.75;color:#53615d"><?= nl2br(
                                esc($template["body"]),
                            ) ?></div>
                            <?php if ($template["cta_label"] && $safeCtaUrl): ?>
                                <table role="presentation" cellpadding="0" cellspacing="0" style="margin-top:30px">
                                    <tr>
                                        <td style="background:#142522;border-radius:4px">
                                            <a href="<?= esc(
                                                $safeCtaUrl,
                                            ) ?>" style="display:inline-block;padding:15px 22px;color:#ffffff;text-decoration:none;font-size:14px;font-weight:700"><?= esc(
    $template["cta_label"],
) ?> <span style="color:#caff62">→</span></a>
                                        </td>
                                    </tr>
                                </table>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding:24px 42px;background:#f4f1e9;border-top:1px solid #e3e6df">
                            <p style="margin:0 0 5px;font-size:12px;font-weight:700;color:#142522">BrandSquare · Logos people remember.</p>
                            <p style="margin:0;font-size:11px;line-height:1.6;color:#7a8581">This message was sent because you contacted BrandSquare or have an active project with us.</p>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>
