<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Refund Voucher — {{ $businessName }}</title>
    <style>
        @page { margin: 12mm 15mm; }
        body {
            font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
            color: #1e293b;
            font-size: 13px;
            line-height: 1.5;
        }
        .invoice-box {
            max-width: 800px;
            margin: auto;
            padding: 15px;
            background-color: #fff;
        }
        .header {
            border-bottom: 2px solid #f43f5e;
            padding-bottom: 20px;
            margin-bottom: 20px;
        }
        .header-logo {
            max-height: 60px;
            max-width: 240px;
            object-fit: contain;
        }
        .header-text {
            font-size: 26px;
            font-weight: bold;
            color: #f43f5e;
        }
        .invoice-title {
            font-size: 18px;
            font-weight: bold;
            color: #f43f5e;
            text-align: right;
        }
        .details-table {
            width: 100%;
            margin-bottom: 30px;
            border-collapse: collapse;
        }
        .details-table td {
            padding: 5px;
            vertical-align: top;
        }
        .receipt-items {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 30px;
        }
        .receipt-items th {
            background-color: #f43f5e;
            color: #fff;
            border-bottom: 2px solid #e11d48;
            padding: 10px;
            text-align: left;
            font-size: 11px;
            text-transform: uppercase;
        }
        .receipt-items td {
            padding: 10px;
            border-bottom: 1px solid #e2e8f0;
        }
        .receipt-items tr:nth-child(even) td {
            background-color: #fef2f2;
        }
        .total-row td {
            border-top: 2px solid #cbd5e1;
            font-weight: bold;
            padding-top: 15px;
        }
        .footer {
            margin-top: 40px;
            font-size: 11px;
            color: #94a3b8;
            text-align: center;
            border-top: 1px solid #e2e8f0;
            padding-top: 15px;
        }
    </style>
</head>
<body>

    <div class="invoice-box">
        <table style="width: 100%;" class="header">
            <tr>
                <td style="width: 50%;">
                    @if(!empty($invoiceLogo) && file_exists(public_path($invoiceLogo)))
                        <img src="{{ public_path($invoiceLogo) }}" alt="Invoice Logo" class="header-logo">
                    @else
                        <span class="header-text">{{ $businessName }}</span>
                    @endif
                </td>
                <td style="width: 50%; text-align: right; vertical-align: bottom;">
                    <span class="invoice-title">Custom Account Refund Voucher</span><br>
                    <span style="font-size: 11px; color: #64748b;">Voucher #: INV-CO-{{ $cashOut->id }}</span>
                </td>
            </tr>
        </table>

        <table class="details-table">
            <tr>
                <td style="width: 50%;">
                    <strong style="color: #475569; font-size: 12px;">{{ $businessName }}</strong><br>
                    @if(!empty($businessAddress))
                        {!! nl2br(e($businessAddress)) !!}<br>
                    @endif
                    @if(!empty($businessPhone))
                        Phone: {{ $businessPhone }}<br>
                    @endif
                    @if(!empty($businessEmail))
                        Email: {{ $businessEmail }}
                    @endif
                </td>
                <td style="text-align: right; width: 50%;">
                    <strong style="color: #475569;">Account Detail:</strong><br>
                    {{ $cashOut->customAccount?->name ?? 'N/A' }}<br>
                    @if($cashOut->bookingChannel)
                        Booking Channel: {{ $cashOut->bookingChannel->name }}<br>
                    @endif
                    Email: {{ $cashOut->customAccount?->email ?? 'N/A' }}
                </td>
            </tr>
        </table>

        <div style="background-color: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 12px; margin-bottom: 25px;">
            <table style="width: 100%; font-size: 12px;">
                @php
                    $fields = [];
                    if ($cashOut->date) {
                        $fields[] = ['label' => 'Payment Date', 'value' => $cashOut->date->format('d-m-Y')];
                    }
                    if ($cashOut->bookingChannel) {
                        $fields[] = [
                            'label' => 'Booking Channel', 
                            'value' => $cashOut->bookingChannel->name
                        ];
                    }
                    if ($cashOut->paymentMethod?->name) {
                        $fields[] = ['label' => 'Payment Method', 'value' => $cashOut->paymentMethod->name];
                    }
                    if ($cashOut->paymentType?->name) {
                        $fields[] = ['label' => 'Payment Type', 'value' => $cashOut->paymentType->name];
                    }
                    
                    if (!empty($cashOut->transaction_id)) {
                        $fields[] = ['label' => 'Transaction ID', 'value' => $cashOut->transaction_id];
                    }
                    if (!empty($cashOut->booking_no)) {
                        $fields[] = ['label' => 'Booking Ref #', 'value' => $cashOut->booking_no];
                    }
                    if (!empty($cashOut->guest_bank_name)) {
                        $fields[] = ['label' => 'Recipient Bank Name', 'value' => $cashOut->guest_bank_name];
                    }
                    if (!empty($cashOut->guest_account_no)) {
                        $fields[] = ['label' => 'Recipient Account #', 'value' => $cashOut->guest_account_no];
                    }
                    // 'Bank Account' (bankAccount) is EXPLICITLY excluded.
                @endphp
                
                @for ($i = 0; $i < count($fields); $i += 2)
                    <tr>
                        <td style="width: 50%;"><strong>{{ $fields[$i]['label'] }}:</strong> {{ $fields[$i]['value'] }}</td>
                        <td style="width: 50%;">
                            @if (isset($fields[$i+1]))
                                <strong>{{ $fields[$i+1]['label'] }}:</strong> {{ $fields[$i+1]['value'] }}
                            @endif
                        </td>
                    </tr>
                @endfor
            </table>
        </div>

        <table class="receipt-items">
            <thead>
                <tr>
                    <th style="width: 70%;">Description</th>
                    <th style="width: 30%; text-align: right;">Amount</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        {{ $cashOut->paymentType?->name ?? 'Refund Payment' }}
                    </td>
                    <td style="text-align: right; font-family: monospace; font-size: 13px;">
                        {{ $currencySymbol }}{{ number_format($cashOut->amount, 2) }}
                    </td>
                </tr>
                @if($cashOut->vat_rate)
                <tr>
                    <td style="color: #64748b; font-size: 12px;">Net Amount</td>
                    <td style="text-align: right; font-family: monospace; font-size: 12px; color: #64748b;">
                        {{ $currencySymbol }}{{ number_format($cashOut->net_amount, 2) }}
                    </td>
                </tr>
                <tr>
                    <td style="color: #64748b; font-size: 12px;">VAT ({{ $cashOut->vat_rate }}%)</td>
                    <td style="text-align: right; font-family: monospace; font-size: 12px; color: #64748b;">
                        {{ $currencySymbol }}{{ number_format($cashOut->vat_amount, 2) }}
                    </td>
                </tr>
                @endif
                <tr class="total-row">
                    <td style="text-align: right;">Total Refunded:</td>
                    <td style="text-align: right; color: #e11d48; font-family: monospace; font-size: 14px;">
                        {{ $currencySymbol }}{{ number_format($cashOut->net_amount + $cashOut->vat_amount, 2) }}
                    </td>
                </tr>
            </tbody>
        </table>

        <!-- Notes removed as per request -->

        <div class="footer">
            Thank you for your business. This is a computer generated document. No signature required.
        </div>
    </div>

</body>
</html>