<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Receipt - {{ $receipt->receipt_number }}</title>
    <style>
        @page { size: A4; margin: 15px; }
        html, body {
            font-family: 'DejaVu Sans', sans-serif;
            font-size: 9pt;
            margin: 0; padding: 0;
            color: #333;
        }
        body { padding: 15px; box-sizing: border-box; }
        .document-title { 
            text-align: center; 
            font-size: 15pt; 
            font-weight: bold; 
            color: #6f42c1; 
            margin-bottom: 15px;
            text-transform: uppercase; 
        }
        .header-container { 
            border-bottom: 1px solid #e2e8f0; 
            padding-bottom: 15px; 
            margin-bottom: 15px; 
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .logo-full img { max-width: 120px; }
        .info-block { width: 48%; }
        .section-title { 
            font-size: 10pt; 
            font-weight: bold; 
            color: #6f42c1; 
            text-transform: uppercase; 
            margin-bottom: 5px; 
            border-bottom: 1px solid #6f42c1; 
            padding-bottom: 2px; 
            display: block; 
        }
        .label { font-size: 9pt; color: #6f42c1; font-weight: normal; }
        .value { font-size: 9pt; }
        .doc-info { 
            display: flex; 
            justify-content: space-between; 
            font-size: 9pt; 
            padding: 10px; 
            background-color: #f8fafc; 
            border: 1px solid #e2e8f0; 
            border-radius: 4px; 
            margin-bottom: 15px; 
        }
        .items-table { 
            width: 100%; 
            border-collapse: collapse; 
            font-size: 9pt; 
            margin-bottom: 15px; 
        }
        .items-table th { 
            background-color: #6f42c1; 
            color: #fff; 
            padding: 8px; 
            text-align: center; 
        }
        .items-table td { 
            border: 1px solid #e2e8f0; 
            padding: 8px; 
            text-align: center; 
        }
        .items-table tr:nth-child(even) { 
            background-color: #f8fafc; 
        }
        .totals-panel { 
            width: 50%; 
            margin-left: auto; 
            padding: 10px;
        }
        .total-row { 
            border-top: 1px solid #333; 
            font-weight: bold; 
        }
        .banking-details { 
            padding: 10px; 
            background-color: #f8fafc; 
            border: 1px solid #e2e8f0; 
            border-radius: 4px; 
            font-size: 9pt; 
            margin-top: 20px;
        }
        .bottom-footer { 
            position: fixed; 
            bottom: 15px; 
            left: 0; 
            right: 0; 
            text-align: center; 
            font-size: 8pt; 
            color: #666;
        }
        .text-right { text-align: right; }
    </style>
</head>
<body>
    <div class="header-container">
        <div class="logo-full">
            @if($company && $company->logo_path)
                <img src="file://{{ public_path($company->logo_path) }}" alt="Company Logo">
            @endif
        </div>
        <div class="info-block">
            <span class="section-title">Company Information</span>
            <div><span class="label">Name:</span> <span class="value">{{ $company->company_name }}</span></div>
            <div><span class="label">Address:</span> <span class="value">{{ $company->address }}</span></div>
            <div><span class="label">Phone:</span> <span class="value">{{ $company->phone }}</span></div>
            <div><span class="label">Email:</span> <span class="value">{{ $company->email }}</span></div>
        </div>
    </div>

    <div class="document-title">Receipt</div>

    <div class="doc-info">
        <div>
            <div>Receipt #: <strong>{{ $receipt->receipt_number }}</strong></div>
            <div>Date: <strong>{{ $receipt->receipt_date->format('d M Y') }}</strong></div>
        </div>
        <div>
            <div>Payment Method: <strong>{{ $receipt->payment_method }}</strong></div>
            <div>Customer: <strong>{{ $receipt->customer->customer_account }}</strong></div>
        </div>
    </div>

    <table class="items-table">
        <thead>
            <tr>
                <th width="5%">#</th>
                <th width="35%">Description</th>
                <th width="20%">Invoice #</th>
                <th width="25%">Deposit Account</th>
                <th width="15%">Amount</th>
            </tr>
        </thead>
        <tbody>
            @foreach($receipt->lines as $idx => $line)
                <tr>
                    <td>{{ $idx + 1 }}</td>
                    <td>{{ $line->description }}</td>
                    <td>
                        @if($line->invoice)
                            {{ $line->invoice->document_number }}
                        @else
                            &mdash;
                        @endif
                    </td>
                    <td>
                        @if($line->account)
                            {{ $line->account->code }} – {{ $line->account->account_name }}
                        @else
                            &mdash;
                        @endif
                    </td>
                    <td>${{ number_format($line->amount, 2) }}</td>
                </tr>
            @endforeach
        </tbody>
    </table>

    <div class="totals-panel">
        <table width="100%">
            <tr>
                <td><strong>Total Amount:</strong></td>
                <td class="text-right">${{ number_format($receipt->total_amount, 2) }}</td>
            </tr>
        </table>
    </div>

    <div class="banking-details">
        <span class="section-title">Banking Details</span>
        <div><span class="label">Bank Name:</span> <span class="value">{{ $company->bank_name }}</span></div>
        <div><span class="label">Account Name:</span> <span class="value">{{ $company->account_name }}</span></div>
        <div><span class="label">Account Number:</span> <span class="value">{{ $company->account_number }}</span></div>
        <div><span class="label">Branch:</span> <span class="value">{{ $company->branch_name }}</span></div>
    </div>

    <div class="bottom-footer">
        &copy; {{ date('Y') }} {{ $company->company_name }}. All rights reserved. | Printed: {{ now()->format('d M Y H:i') }}
    </div>
</body>
</html>