<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ $receipt->receipt_number }} — {{ $companySettings->company_name ?? config('app.name') }}</title>
    <style>
        * { box-sizing: border-box; }
        body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: #f4f4f5; color: #18181b; line-height: 1.5; }
        .wrap { max-width: 900px; margin: 0 auto; padding: 24px 16px 48px; }
        .badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #dcfce7; color: #166534; }
        .card { background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,.08); overflow-x: auto; }
        @media print {
            body { background: #fff; }
            .no-print { display: none !important; }
            .card { box-shadow: none; }
        }
    </style>
    @php
        $templateContent = view($templateView, ['payment' => $payment])->render();
        preg_match_all('/<style[^>]*>(.*?)<\/style>/is', $templateContent, $styleMatches);
        $styles = !empty($styleMatches[1]) ? '<style>' . implode('</style><style>', $styleMatches[1]) . '</style>' : '';
        $bodyContent = $templateContent;
        if (preg_match('/<body[^>]*>(.*?)<\/body>/is', $templateContent, $bodyMatches)) {
            $bodyContent = $bodyMatches[1];
        }
        $bodyContent = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', '', $bodyContent);
    @endphp
    {!! $styles !!}
    <style>
        .public-receipt-preview { color: #111827; }
    </style>
</head>
<body>
    <div class="wrap">
        <div class="no-print" style="margin-bottom: 16px;">
            <span class="badge">Payment receipt</span>
        </div>
        <div class="card public-receipt-preview">
            {!! $bodyContent !!}
        </div>
    </div>
</body>
</html>
