<!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: 36px 16px; background: #fff; }
        .header { text-align: center; margin-bottom: 40px; padding-bottom: 20px; border-bottom: 2px solid #e5e7eb; }
        .company-name { font-size: 30px; font-weight: 700; color: #111827; margin-bottom: 8px; }
        .company-logo-info-wrapper { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 15px; }
        .company-logo { width: 130px; max-height: 80px; object-fit: contain; flex-shrink: 0; }
        .company-info { font-size: 17px; font-weight: 500; color: #6b7280; line-height: 1.8; }
        .receipt-title { font-size: 26px; font-weight: 600; color: rgba(255, 255, 255, 1); letter-spacing: 3px; margin: 30px 0; padding-top: 20px; padding-bottom: 20px; background-color: var(--primary); }
        .receipt-info { display: flex; justify-content: space-between; margin: 30px 0; padding: 20px; background: #f9fafb; border-radius: 8px; }
        .info-item { }
        .info-label { font-size: 16px; color: #6b7280; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 5px; }
        .info-value { font-size: 16px; font-weight: 600; color: #111827; }
        .payment-details { background: #ecfdf5; border: 2px solid #10b981; border-radius: 8px; padding: 25px; margin: 30px 0; }
        .payment-title { font-size: 18px; font-weight: 700; color: #10b981; margin-bottom: 15px; }
        .payment-row { display: flex; justify-content: space-between; padding: 10px 0; font-size: 16px; border-bottom: 1px solid #d1fae5; }
        .payment-row:last-child { border-bottom: none; border-top: 2px solid #10b981; padding-top: 15px; }
        .payment-label { color: #065f46; }
        .payment-value { font-weight: 600; color: #111827; }
        .payment-total { font-size: 20px; font-weight: 700; color: #10b981; }
        .payment-total span:last-child { font-size: 23px; }
        .items-section { margin: 30px 0; color: rgba(0, 0, 0, 1); }
        .items-title { font-size: 14px; font-weight: 600; margin-bottom: 15px; color: rgba(0, 0, 0, 1); }
        .items-list { }
        .item-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid #e5e7eb; font-size: 13px; }
        .item-desc { flex: 1; font-size: 16px; color: rgba(0, 0, 0, 1); }
        .item-amount { font-weight: 600; }
        .footer { margin-top: 50px; padding-top: 20px; border-top: 1px solid #e5e7eb; text-align: center; }
        .thank-you { font-size: 18px; font-weight: 600; color: #10b981; margin-bottom: 10px; }
        .footer-text { font-size: 14px; color: #6b7280; }
        @media print {
            .receipt-container { padding: 0; }
        }
    </style>
</head>
<body style="background-color: #fff !important;">
    <div class="receipt-container">
        <div class="header">
            @php
                $companySettings = \App\Models\CompanySetting::getSettings();
            @endphp
            <div class="company-name">{{ $companySettings->company_name ?? config('app.name') }}</div>
            <div class="company-logo-info-wrapper">
                @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="{{ $companySettings->company_name ?? config('app.name') }}" class="company-logo">
                @endif
                <div class="company-info">
                    @if($companySettings->company_address){{ $companySettings->company_address }}<br>@endif
                    @if($companySettings->company_phone){{ $companySettings->company_phone }}<br>@endif
                    @if($companySettings->company_email){{ $companySettings->company_email }}@endif
                </div>
            </div>
            <div class="receipt-title">PAYMENT RECEIPT</div>
        </div>

        <div class="receipt-info">
            <div class="info-item">
                <div class="info-label">Receipt Number</div>
                <div class="info-value">{{ $payment->payment_number ?? 'PAY-001' }}</div>
            </div>
            <div class="info-item">
                <div class="info-label">Payment Date</div>
                <div class="info-value">{{ ($payment->payment_date ?? now())->format('M 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>
        </div>

        @if($payment->customer ?? null)
        <div style="margin: 30px 0;">
            <div style="font-size: 16px; color: #6b7280; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px;">Paid By</div>
            <div style="font-size: 16px; font-weight: 600; margin-bottom: 5px; color: rgba(0, 0, 0, 1);">{{ $payment->customer->name }}</div>
            <div style="font-size: 16px; color: rgba(0, 0, 0, 1);">
                @if($payment->customer->email){{ $payment->customer->email }}<br>@endif
                @if($payment->customer->phone){{ $payment->customer->phone }}@endif
            </div>
        </div>
        @endif

        @if($payment->invoice ?? null)
        <div class="items-section">
            <div class="items-title">Payment for Invoice</div>
            <div class="items-list">
                <div class="item-row">
                    <div class="item-desc">
                        <strong>Invoice #{{ $payment->invoice->invoice_number }}</strong><br>
                        <small style="color: #6b7280;">Due Date: {{ $payment->invoice->due_date->format('M d, Y') }}</small>
                    </div>
                    <div class="item-amount">{{ $payment->currency ?? 'USD' }} {{ number_format($payment->amount ?? 0, 2) }}</div>
                </div>
            </div>
        </div>
        @endif

        <div class="payment-details">
            <div class="payment-title">Payment Summary</div>
            <div class="payment-row">
                <span class="payment-label">Amount Paid</span>
                <span class="payment-value">{{ $payment->currency ?? 'USD' }} {{ number_format($payment->amount ?? 0, 2) }}</span>
            </div>
            @if($payment->transaction_id)
            <div class="payment-row">
                <span class="payment-label">Transaction ID</span>
                <span class="payment-value">{{ $payment->transaction_id }}</span>
            </div>
            @endif
            @if($payment->reference)
            <div class="payment-row">
                <span class="payment-label">Reference</span>
                <span class="payment-value">{{ $payment->reference }}</span>
            </div>
            @endif
            <div class="payment-row payment-total">
                <span>Total Received</span>
                <span>{{ $payment->currency ?? 'USD' }} {{ number_format($payment->amount ?? 0, 2) }}</span>
            </div>
        </div>

        @if($payment->notes)
        <div style="margin-top: 30px; padding: 20px; background: #f9fafb; border-radius: 8px;">
            <div style="font-size: 12px; font-weight: 600; margin-bottom: 8px;">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 proof of payment. Please keep it for your records.</div>
        </div>
    </div>
</body>
</html>
