<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Receipt {{ $payment->payment_number ?? 'PAY-001' }}</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: #111827; line-height: 1.6; }
        .receipt-container { width: 100%; max-width: 100%; padding: 24px 20px; background: #fff; }
        .header-box { background: rgba(52, 0, 128, 1); color: #fff; padding: 30px; border-radius: 12px; margin-bottom: 30px; }
        .header-content { display: flex; justify-content: space-between; align-items: center; }
        .logo-section { display: flex; align-items: center; gap: 15px; }
        .logo { max-height: 50px; width: 130px; }
        .company-name { font-size: 25px; font-weight: 700; }
        .receipt-badge { background: rgba(255,255,255,0.2); padding: 15px 25px; border-radius: 8px; text-align: center; }
        .receipt-label { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; opacity: 0.9; margin-bottom: 8px; }
        .receipt-number { font-size: 17px; font-weight: 700; }
        .header { margin-bottom: 30px; }
        .receipt-title { padding-top: 20px; padding-bottom: 20px; padding-left: 20px; padding-right: 20px; color: rgba(0, 0, 0, 1); background-color: rgba(240, 242, 244, 1); font-size: 22px; font-weight: 500; }
        .content-box { border: 2px solid #e5e7eb; border-radius: 12px; padding: 30px; margin-bottom: 20px; }
        .box-title { font-size: 18px; font-weight: 700; text-transform: uppercase; color: #1e3a5f; letter-spacing: 1px; margin-bottom: 15px; }
        .info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 30px; }
        .info-item { }
        .info-label { font-size: 18px; color: #6b7280; text-transform: uppercase; margin-bottom: 5px; }
        .info-value { font-size: 16px; font-weight: 600; color: #111827; }
        .payment-breakdown { background: #f9fafb; padding: 25px; border-radius: 8px; margin: 30px 0; }
        .breakdown-title { font-size: 14px; font-weight: 700; color: #1e3a5f; margin-bottom: 15px; }
        .breakdown-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid #e5e7eb; font-size: 16px; }
        .breakdown-row:last-child { border-bottom: none; border-top: 2px solid #1e3a5f; padding-top: 15px; }
        .breakdown-label { color: #6b7280; }
        .breakdown-value { font-weight: 600; color: #111827; }
        .breakdown-total { font-size: 20px; font-weight: 700; color: #1e3a5f; }
        .balance-info { background: #eff6ff; border-left: 4px solid #1e3a5f; padding: 20px; border-radius: 8px; margin-top: 30px; }
        .balance-title { font-size: 13px; font-weight: 600; color: #1e3a5f; margin-bottom: 8px; }
        .balance-text { font-size: 13px; color: #1e40af; }
        .footer { margin-top: 40px; padding-top: 20px; border-top: 1px solid #e5e7eb; text-align: center; }
        .thank-you { font-size: 16px; font-weight: 600; color: #1e3a5f; margin-bottom: 8px; }
        .footer-text { font-size: 12px; color: #6b7280; }
        @media print {
            .receipt-container { padding: 0; }
        }
    </style>
</head>
<body style="background-color: #fff !important;">
    <div class="receipt-container">
        <div class="header-box">
            <div class="header-content">
                <div class="logo-section">
                    @php
                        $companySettings = \App\Models\CompanySetting::getSettings();
                    @endphp
                    @if($companySettings && $companySettings->company_logo && \Illuminate\Support\Facades\Storage::disk('public')->exists($companySettings->company_logo))
                        <img src="{{ \Illuminate\Support\Facades\Storage::url($companySettings->company_logo) }}" alt="Logo" class="logo">
                    @endif
                    <div class="company-name">{{ $companySettings->company_name ?? config('app.name') }}</div>
                </div>
                <div class="receipt-badge">
                    <div class="receipt-label">Payment Receipt</div>
                    <div class="receipt-number">{{ $payment->payment_number ?? 'PAY-001' }}</div>
                </div>
            </div>
        </div>

        <div class="header">
            <div class="receipt-title">PAYMENT RECEIPT</div>
        </div>

        <div class="content-box">
            <div class="box-title">Payment Information</div>
            <div class="info-grid">
                <div class="info-item">
                    <div class="info-label">Payment Date</div>
                    <div class="info-value">{{ ($payment->payment_date ?? now())->format('F d, Y') }}</div>
                </div>
                <div class="info-item">
                    <div class="info-label">Payment Method</div>
                    <div class="info-value">{{ ucfirst($payment->payment_method ?? 'Bank Transfer') }}</div>
                </div>
                @if($payment->transaction_id)
                <div class="info-item">
                    <div class="info-label">Transaction ID</div>
                    <div class="info-value">{{ $payment->transaction_id }}</div>
                </div>
                @endif
                @if($payment->reference)
                <div class="info-item">
                    <div class="info-label">Reference</div>
                    <div class="info-value">{{ $payment->reference }}</div>
                </div>
                @endif
            </div>
        </div>

        @if($payment->customer)
        <div class="content-box">
            <div class="box-title">Customer Information</div>
            <div style="font-size: 16px; font-weight: 600; margin-bottom: 8px; color: rgba(0, 0, 0, 1);">{{ $payment->customer->name }}</div>
            <div style="font-size: 19px; color: #6b7280; line-height: 1.8;">
                @if($payment->customer->email){{ $payment->customer->email }}<br>@endif
                @if($payment->customer->phone){{ $payment->customer->phone }}@endif
            </div>
        </div>
        @endif

        @if($payment->invoice)
        <div class="payment-breakdown">
            <div class="breakdown-title">Payment Breakdown</div>
            <div class="breakdown-row">
                <span class="breakdown-label">Invoice Number</span>
                <span class="breakdown-value">{{ $payment->invoice->invoice_number }}</span>
            </div>
            <div class="breakdown-row">
                <span class="breakdown-label">Invoice Total</span>
                <span class="breakdown-value">{{ $payment->currency ?? 'USD' }} {{ number_format($payment->invoice->total ?? 0, 2) }}</span>
            </div>
            <div class="breakdown-row">
                <span class="breakdown-label">Previously Paid</span>
                <span class="breakdown-value">{{ $payment->currency ?? 'USD' }} {{ number_format(($payment->invoice->paid_amount ?? 0) - ($payment->amount ?? 0), 2) }}</span>
            </div>
            <div class="breakdown-row breakdown-total">
                <span>Amount Paid</span>
                <span>{{ $payment->currency ?? 'USD' }} {{ number_format($payment->amount ?? 0, 2) }}</span>
            </div>
            @if($payment->invoice->balance > 0)
            <div class="breakdown-row">
                <span class="breakdown-label">Remaining Balance</span>
                <span class="breakdown-value" style="color: #dc2626;">{{ $payment->currency ?? 'USD' }} {{ number_format($payment->invoice->balance ?? 0, 2) }}</span>
            </div>
            @endif
        </div>
        @else
        <div class="payment-breakdown">
            <div class="breakdown-title">Payment Summary</div>
            <div class="breakdown-row breakdown-total">
                <span>Amount Paid</span>
                <span>{{ $payment->currency ?? 'USD' }} {{ number_format($payment->amount ?? 0, 2) }}</span>
            </div>
        </div>
        @endif

        @if($payment->invoice && $payment->invoice->balance > 0)
        <div class="balance-info">
            <div class="balance-title">Outstanding Balance</div>
            <div class="balance-text">
                Your remaining balance is {{ $payment->currency ?? 'USD' }} {{ number_format($payment->invoice->balance ?? 0, 2) }}. 
                Please make payment by {{ $payment->invoice->due_date->format('F d, Y') }}.
            </div>
        </div>
        @endif

        @if($payment->notes)
        <div class="content-box">
            <div class="box-title">Notes</div>
            <div style="font-size: 13px; color: #6b7280; line-height: 1.8;">{{ $payment->notes }}</div>
        </div>
        @endif

        <div class="footer">
            <div class="thank-you">Thank You for Your Payment!</div>
            <div class="footer-text">This receipt serves as official proof of payment. Please retain for your records.</div>
        </div>
    </div>
</body>
</html>
