<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>بوليصة شحن #{{ $order->id }}</title>
    <style>
        * { font-family: 'xbriyaz', sans-serif; }
        body { margin: 15px; font-size: 11px; color: #333; direction: rtl; text-align: right; }
        .header { text-align: center; padding-bottom: 10px; margin-bottom: 15px; border-bottom: 2px solid #10b981; }
        .title { font-size: 16px; font-weight: bold; color: #10b981; }
        .waybill-num { font-size: 12px; color: #666; margin-top: 3px; }
        .section { margin: 15px 0; padding: 12px; border: 1px solid #ddd; border-radius: 6px; }
        .section-title { font-weight: bold; margin-bottom: 8px; color: #10b981; font-size: 12px; }
        .info-row { padding: 4px 0; }
        .info-label { font-weight: bold; color: #555; display: inline-block; width: 100px; }
        .cod-box { background: #fef3c7; border: 2px dashed #f59e0b; padding: 15px; margin: 15px 0; text-align: center; border-radius: 8px; }
        .cod-amount { font-size: 20px; font-weight: bold; color: #b45309; }
        .notes-area { border: 1px dashed #999; min-height: 60px; margin: 15px 0; padding: 10px; background: #fafafa; }
        .notes-label { font-size: 10px; color: #888; margin-bottom: 5px; }
        .signature-area { margin-top: 25px; padding-top: 15px; border-top: 1px dashed #999; }
        .signature-label { font-size: 10px; color: #888; }
    </style>
</head>
<body dir="rtl">
    <div class="header">
        <div class="title">بوليصة شحن — تاجر بلس</div>
        <div class="waybill-num">طلب #{{ $order->id }} | {{ $order->created_at->format('Y-m-d') }}</div>
    </div>

    <div class="section" dir="rtl">
        <div class="section-title">بيانات التسليم</div>
        @php
            $addr = $order->shippingAddress ?? null;
            $snapshot = $order->shipping_address_snapshot;
        @endphp
        <div class="info-row"><span class="info-label">اسم العميل:</span> {{ $order->user->name }}</div>
        @if($addr)
        <div class="info-row"><span class="info-label">اسم المحل:</span> {{ $addr->shop_name ?: '—' }}</div>
        <div class="info-row"><span class="info-label">الهاتف:</span> {{ $addr->extra_phone ?: $order->user->phone ?: '—' }}</div>
        <div class="info-row"><span class="info-label">المحافظة:</span> {{ $addr->governorate }}</div>
        <div class="info-row"><span class="info-label">المركز/المدينة:</span> {{ $addr->city ?: '—' }}</div>
        <div class="info-row"><span class="info-label">العنوان:</span> {{ $addr->address_details }}</div>
        @if($addr->landmark)
        <div class="info-row"><span class="info-label">العلامة المميزة:</span> {{ $addr->landmark }}</div>
        @endif
        @else
        <div class="info-row"><span class="info-label">الهاتف:</span> {{ $order->user->phone ?: '—' }}</div>
        <div class="info-row"><span class="info-label">العنوان:</span> {{ $snapshot ?: '—' }}</div>
        @if($order->shipping_governorate)
        <div class="info-row"><span class="info-label">المحافظة:</span> {{ $order->shipping_governorate }}</div>
        @endif
        @endif
    </div>

    <div class="section" dir="rtl">
        <div class="section-title">محتويات الشحنة</div>
        <div class="info-row"><span class="info-label">عدد القطع الإجمالي:</span> {{ $order->getTotalPiecesCount() }} قطعة</div>
    </div>

    <div class="cod-box">
        <div style="font-size: 11px; color: #92400e; margin-bottom: 5px;">المبلغ المطلوب تحصيله (COD)</div>
        <div class="cod-amount">{{ number_format($order->total, 2) }} ج.م</div>
    </div>

    <div class="notes-area" dir="rtl">
        <div class="notes-label">ملاحظات الشحن:</div>
        @if($order->notes)
            {{ $order->notes }}
        @else
            &nbsp;
        @endif
    </div>

    <div class="signature-area">
        <div class="signature-label">توقيع المستلم: _________________________</div>
    </div>
</body>
</html>
