<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>سند صرف #{{ $payment->id }}</title>
    <style>
        @page {
            size: A4;
            margin: 10mm;
        }
        @media print {
            .no-print { display: none; }
            body { 
                margin: 0; 
                padding: 0; 
                background: #fff;
            }
            .container {
                border: none !important;
                box-shadow: none !important;
                width: 100% !important;
                max-width: none !important;
                margin: 0 !important;
                padding: 10mm !important;
            }
        }
        body {
            font-family: 'XBRiyaz', 'DejaVu Sans', sans-serif;
            margin: 0;
            padding: 20px;
            color: #333;
            line-height: 1.4;
            background: #f4f4f4;
        }
        .container {
            width: 210mm;
            min-height: 297mm;
            margin: 0 auto;
            border: 1px solid #eee;
            padding: 20mm;
            background: #fff;
            box-sizing: border-box;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 2px solid #333;
            padding-bottom: 15px;
            margin-bottom: 20px;
        }
        .company-info {
            text-align: right;
            flex: 1;
        }
        .company-logo {
            text-align: center;
            flex: 0 0 150px;
        }
        .company-logo img {
            max-width: 100px;
            height: auto;
        }
        .receipt-title {
            text-align: center;
            margin: 15px 0;
        }
        .receipt-title h2 {
            display: inline-block;
            border: 1px solid #333;
            padding: 8px 30px;
            background: #f9f9f9;
            margin: 0;
        }
        .details-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
            margin-bottom: 20px;
        }
        .detail-item {
            display: flex;
            border-bottom: 1px solid #eee;
            padding: 5px 0;
        }
        .detail-label {
            font-weight: bold;
            width: 100px;
        }
        .detail-value {
            flex: 1;
        }
        .description-box {
            border: 1px solid #eee;
            padding: 12px;
            margin-bottom: 20px;
            min-height: 80px;
            background: #fcfcfc;
        }
        .amount-row {
            font-size: 1.1em;
            font-weight: bold;
            text-align: left;
            margin-bottom: 30px;
            padding: 8px;
            background: #eee;
        }
        .signatures {
            display: flex;
            justify-content: space-between;
            margin-top: 40px;
            text-align: center;
        }
        .signature-item {
            flex: 1;
        }
        .signature-line {
            margin-top: 30px;
            border-top: 1px solid #333;
            width: 70%;
            margin-left: auto;
            margin-right: auto;
        }
        .footer {
            margin-top: 30px;
            text-align: center;
            font-size: 0.8em;
            border-top: 1px solid #eee;
            padding-top: 10px;
            color: #777;
        }
        .btn-print {
            background: #28a745;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            margin-bottom: 20px;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="no-print" style="text-align: center;">
        <button onclick="window.print()" class="btn-print">طباعة السند</button>
        <button onclick="window.history.back()" class="btn-print" style="background: #6c757d;">العودة</button>
    </div>

    <div class="container">
        <div class="header">
            <div class="company-info">
                <h1 style="margin: 0; font-size: 24px;">{{ $company->name }}</h1>
                <p style="margin: 5px 0;">{{ $company->address }}</p>
                <p style="margin: 5px 0;">هاتف: {{ $company->phone }}</p>
                <p style="margin: 5px 0;">البريد: {{ $company->email }}</p>
                @if($company->tax_number)
                    <p style="margin: 5px 0;">الرقم الضريبي: {{ $company->tax_number }}</p>
                @endif
            </div>
            <div class="company-logo">
                @if($company->logo)
                    <img src="{{ asset('storage/' . $company->logo) }}" alt="Logo">
                @else
                    <div style="width: 120px; height: 80px; border: 1px dashed #ccc; display: flex; align-items: center; justify-content: center;">Logo</div>
                @endif
            </div>
        </div>

        <div class="receipt-title">
            <h2>سند صرف</h2>
        </div>

        <div class="details-grid">
            <div class="detail-item">
                <span class="detail-label">رقم السند:</span>
                <span class="detail-value">{{ $payment->id }}</span>
            </div>
            <div class="detail-item">
                <span class="detail-label">رقم المرجع:</span>
                <span class="detail-value">{{ $payment->reference_number ?: '---' }}</span>
            </div>
            <div class="detail-item">
                <span class="detail-label">التاريخ:</span>
                <span class="detail-value">{{ $payment->payment_date->format('Y-m-d') }}</span>
            </div>
            <div class="detail-item">
                <span class="detail-label">الخزينة:</span>
                <span class="detail-value">{{ $payment->treasury->name }}</span>
            </div>
            <div class="detail-item">
                <span class="detail-label">الحساب:</span>
                <span class="detail-value">{{ $payment->account ? $payment->account->name : 'غير محدد' }}</span>
            </div>
            @if($payment->beneficiary_type)
            <div class="detail-item">
                <span class="detail-label">المستفيد:</span>
                <span class="detail-value">{{ $payment->beneficiary_type }}</span>
            </div>
            @endif
        </div>

        <div style="font-weight: bold; margin-bottom: 10px;">البيان / الوصف:</div>
        <div class="description-box">
            {{ $payment->description ?: 'لا يوجد وصف' }}
        </div>

        <div class="amount-row">
            المبلغ: {{ number_format($payment->amount, 2) }} {{ $company->currency ?: 'ريال سعودي' }}
        </div>

        <div class="signatures">
            <div class="signature-item">
                <div>المستلم</div>
                <div class="signature-line"></div>
            </div>
            <div class="signature-item">
                <div>أمين الخزينة</div>
                <div class="signature-line"></div>
            </div>
            <div class="signature-item">
                <div>المحاسب</div>
                <div class="signature-line"></div>
            </div>
        </div>

        <div class="footer">
            تم طباعة هذا السند بواسطة نظام المقاولات والإنشاءات - {{ date('Y-m-d H:i') }}
        </div>
    </div>
</body>
</html>