@php
    $brandName = $brandName ?? ($settings->site_name ?? ($demo->sender ?? config('app.name')));
    $brandEmail = $brandEmail ?? ($settings->contact_email ?? ($demo->contact_email ?? config('mail.from.address')));
    $brandAddress = $brandAddress ?? ($settings->site_address ?? '');
    $logoPath = $logoPath ?? ($settings->logo ?? null);
    $logoUrl = $logoUrl ?? ($logoPath ? asset('storage/app/public/' . $logoPath) : '');
    $accent = $accent ?? ($settings->brand_secondary_color ?? '#155c9d');
    $accent2 = $accent2 ?? ($settings->brand_accent_color ?? '#0f766e');
    $brandPrimary = $settings->brand_primary_color ?? '#f7931a';
    $brandDark = $settings->brand_dark_color ?? '#102033';
    $brandLight = $settings->brand_light_color ?? '#fff7ed';
    $brandWarning = $settings->brand_warning_color ?? '#f59e0b';
    $title = $title ?? 'Service Notification';
    $preheader = $preheader ?? 'A courier service update from ' . $brandName;
    $details = $details ?? [];
@endphp
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ $title }}</title>
</head>
<body style="margin:0;padding:0;background:#eef3f8;font-family:Arial,Helvetica,sans-serif;color:{{ $brandDark }};">
    <div style="display:none;max-height:0;overflow:hidden;color:transparent;">{{ $preheader }}</div>
    <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#eef3f8;padding:24px 12px;">
        <tr>
            <td align="center">
                <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:680px;background:#ffffff;border-radius:22px;overflow:hidden;box-shadow:0 22px 55px rgba(15,35,70,.16);">
                    <tr>
                        <td style="background:linear-gradient(135deg,{{ $accent }},{{ $accent2 }} 58%,{{ $brandPrimary }});padding:26px 28px;color:#ffffff;">
                            <table role="presentation" width="100%" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="vertical-align:middle;">
                                        @if($logoUrl)
                                            <img src="{{ $logoUrl }}" alt="{{ $brandName }}" style="max-height:48px;max-width:180px;background:#ffffff;border-radius:12px;padding:8px;margin-bottom:14px;">
                                        @endif
                                        <div style="font-size:12px;font-weight:700;letter-spacing:.1em;text-transform:uppercase;opacity:.82;">Courier Service Notice</div>
                                        <h1 style="margin:8px 0 0;font-size:27px;line-height:1.2;font-weight:800;color:#ffffff;">{{ $title }}</h1>
                                    </td>
                                    <td align="right" style="vertical-align:top;font-size:12px;line-height:1.5;color:rgba(255,255,255,.82);">
                                        <strong style="display:block;color:#fff;font-size:15px;">{{ $brandName }}</strong>
                                        {{ now()->format('M d, Y h:i A') }}
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="padding:28px;">
                            @if(!empty($greeting))
                                <p style="margin:0 0 14px;font-size:17px;font-weight:700;color:{{ $brandDark }};">{{ $greeting }}</p>
                            @endif
                            @if(!empty($intro))
                                <div style="font-size:15px;line-height:1.75;color:#42526b;margin-bottom:18px;">{!! $intro !!}</div>
                            @endif
                            @if(!empty($imageUrl))
                                <div style="margin:18px 0;text-align:center;">
                                    <img src="{{ $imageUrl }}" alt="Attachment" style="max-width:100%;border-radius:16px;border:1px solid #e5edf7;">
                                </div>
                            @endif
                            @if(!empty($details))
                                <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:separate;border-spacing:0;margin:18px 0;border:1px solid #e5edf7;border-radius:16px;overflow:hidden;">
                                    @foreach($details as $label => $value)
                                        <tr>
                                            <td style="width:38%;padding:12px 14px;background:#f8fbff;border-bottom:1px solid #edf2f8;font-size:12px;font-weight:800;text-transform:uppercase;letter-spacing:.04em;color:#64748b;">{{ $label }}</td>
                                            <td style="padding:12px 14px;border-bottom:1px solid #edf2f8;font-size:14px;font-weight:700;color:{{ $brandDark }};">{!! $value !!}</td>
                                        </tr>
                                    @endforeach
                                </table>
                            @endif
                            @if(!empty($notice))
                                <div style="background:{{ $brandLight }};border:1px solid {{ $brandWarning }};color:{{ $brandDark }};border-radius:16px;padding:14px 16px;font-size:14px;line-height:1.65;margin:18px 0;">{!! $notice !!}</div>
                            @endif
                            @if(!empty($actionUrl) && !empty($actionText))
                                <div style="margin:22px 0;">
                                    <a href="{{ $actionUrl }}" style="display:inline-block;background:{{ $brandPrimary }};color:#ffffff;text-decoration:none;border-radius:999px;padding:12px 20px;font-weight:800;font-size:14px;">{{ $actionText }}</a>
                                </div>
                            @endif
                            @if(!empty($outro))
                                <div style="font-size:14px;line-height:1.75;color:#42526b;margin-top:18px;">{!! $outro !!}</div>
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <td style="padding:20px 28px;background:{{ $brandDark }};color:#cbd5e1;">
                            <div style="font-size:12px;line-height:1.6;color:#94a3b8;">
                                {{ $brandName }}@if($brandAddress) | {{ $brandAddress }}@endif @if($brandEmail) | {{ $brandEmail }}@endif<br>
                                &copy; {{ date('Y') }} {{ $brandName }}. All rights reserved.
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>
