<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{ $order->order_no }}</title>
<style>
*, *::before, *::after { box-sizing:border-box; margin:0; padding:0; }
body { font-family:'Segoe UI', Arial, sans-serif; font-size:13px; color:#1e293b; background:#fff; }
* { -webkit-print-color-adjust:exact !important; print-color-adjust:exact !important; }
.page { max-width:800px; margin:0 auto; min-height:100vh; display:flex; flex-direction:column; }
.letterhead { background:linear-gradient(135deg,#1a3a5c 0%,#2980b9 60%,#3498db 100%); color:#fff; padding:22px 32px 18px; }
.letterhead-inner { display:flex; align-items:center; gap:20px; }
.clinic-icon { width:58px; height:58px; background:rgba(255,255,255,.18); border:1.5px solid rgba(255,255,255,.32); border-radius:14px; display:flex; align-items:center; justify-content:center; font-size:26px; flex-shrink:0; }
.clinic-name { font-size:22px; font-weight:800; margin-bottom:3px; }
.clinic-contact { font-size:11.5px; color:rgba(255,255,255,.82); display:flex; flex-wrap:wrap; gap:12px; }
.ord-strip { background:#f8fafc; border-bottom:2px solid #e2e8f0; padding:12px 32px; display:flex; align-items:center; gap:14px; }
.ord-label { background:linear-gradient(135deg,#1a3a5c,#2980b9); color:#fff; padding:4px 14px; border-radius:20px; font-size:11px; font-weight:700; letter-spacing:.5px; }
.ord-ref { font-size:16px; font-weight:800; color:#1a3a5c; }
.ord-meta { margin-left:auto; font-size:11.5px; color:#64748b; }
.body-content { padding:22px 32px; flex:1; }
.info-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-bottom:18px; }
.info-box { border:1px solid #e2e8f0; border-radius:8px; overflow:hidden; }
.info-box-hd { background:#f1f5f9; padding:5px 12px; font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:#64748b; border-bottom:1px solid #e2e8f0; }
.info-box-body { padding:10px 12px; }
.info-name { font-size:14px; font-weight:700; margin-bottom:2px; }
.info-sub { font-size:11.5px; color:#64748b; }
.indication-box { background:#fefce8; border:1px solid #fde68a; border-left:4px solid #f59e0b; border-radius:8px; padding:10px 14px; margin-bottom:18px; font-size:13px; color:#78350f; white-space:pre-wrap; }
.section-hd { font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:#475569; border-bottom:2px solid #e2e8f0; padding-bottom:7px; margin-bottom:12px; }
table.items { width:100%; border-collapse:collapse; font-size:12.5px; }
table.items th, table.items td { border:1px solid #e2e8f0; padding:7px 10px; text-align:left; }
table.items th { background:#f8fafc; font-size:10.5px; text-transform:uppercase; letter-spacing:.4px; color:#64748b; }
.crit { color:#dc2626; font-weight:700; }
.footer { margin-top:22px; padding:10px 32px; border-top:1px solid #e2e8f0; display:flex; justify-content:space-between; font-size:10.5px; color:#94a3b8; background:#f8fafc; }
@media print { @page { margin:0; } .page { max-width:100%; } }
</style>
</head>
<body>
<div class="page">
    <div class="letterhead">
        <div class="letterhead-inner">
            <div class="clinic-icon"><i>&#9670;</i></div>
            <div>
                <div class="clinic-name">{{ $business->name ?? 'Clinic' }}</div>
                <div class="clinic-contact">
                    @if(!empty($business->mobile))<span>{{ $business->mobile }}</span>@endif
                    @if(!empty($business->email))<span>{{ $business->email }}</span>@endif
                    @if(!empty($business->city))<span>{{ $business->city }}</span>@endif
                </div>
            </div>
        </div>
    </div>

    <div class="ord-strip">
        <span class="ord-label">{{ strtoupper($order->order_type) }} ORDER</span>
        <span class="ord-ref">{{ $order->order_no }}</span>
        <span class="ord-meta">
            {{ __('clinicCore::lang.order_priority') }}: {{ ucfirst($order->priority) }}
            &nbsp;·&nbsp; {{ __('clinicCore::lang.status') }}: {{ ucfirst(str_replace('_',' ', $order->status)) }}
            &nbsp;·&nbsp; {{ optional($order->created_at)->format('d M Y H:i') }}
        </span>
    </div>

    <div class="body-content">
        <div class="info-grid">
            <div class="info-box">
                <div class="info-box-hd">Patient</div>
                <div class="info-box-body">
                    <div class="info-name">{{ optional($order->patient)->patient_name ?? '—' }}</div>
                    @if(config('cliniccore.show_animal_fields', false))
                    <div class="info-sub">{{ optional($order->patient)->species }}</div>
                    @endif
                </div>
            </div>
            @if(optional($order->doctor)->name)
            <div class="info-box">
                <div class="info-box-hd">Ordering Doctor</div>
                <div class="info-box-body">
                    <div class="info-name">{{ $order->doctor->name }}</div>
                </div>
            </div>
            @endif
        </div>

        @if($order->clinical_indication)
        <div class="indication-box">
            <strong>{{ __('clinicCore::lang.clinical_indication') }}:</strong> {{ $order->clinical_indication }}
        </div>
        @endif

        <div class="section-hd">{{ __('clinicCore::lang.orders') }}</div>
        <table class="items">
            <thead><tr>
                <th>{{ __('clinicCore::lang.service_name') }}</th>
                <th>{{ __('clinicCore::lang.service_code') }}</th>
                <th>{{ __('clinicCore::lang.laterality') }}</th>
                <th>{{ __('clinicCore::lang.quantity') }}</th>
                <th>{{ __('clinicCore::lang.status') }}</th>
                <th>{{ __('clinicCore::lang.result_summary') }}</th>
            </tr></thead>
            <tbody>
                @forelse($order->items as $it)
                <tr>
                    <td>{{ $it->service_name }}</td>
                    <td>{{ $it->service_code ?: '—' }}</td>
                    <td>{{ ucfirst($it->laterality) }}</td>
                    <td>{{ $it->quantity }}</td>
                    <td>{{ ucfirst(str_replace('_',' ', $it->status)) }}</td>
                    <td class="{{ in_array($it->abnormal_flag, ['critical_high','critical_low']) ? 'crit' : '' }}">
                        {{ $it->result_summary ?: '—' }}
                        @if($it->abnormal_flag && $it->abnormal_flag !== 'normal')
                            <br><small>({{ str_replace('_',' ', $it->abnormal_flag) }})</small>
                        @endif
                    </td>
                </tr>
                @empty
                <tr><td colspan="6" style="text-align:center;color:#94a3b8;">{{ __('clinicCore::lang.no_orders') }}</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="footer">
        <span>Generated: {{ now()->format('d M Y, H:i') }}</span>
        <span>{{ $order->order_no }} &bull; {{ $business->name ?? '' }}</span>
    </div>
</div>

@includeIf('clinicCore::partials._print_branding', ['mode' => 'footer'])

<script>window.onload = function () { window.print(); };</script>
</body>
</html>
