<?php $pageTitle=$record['crossing_number'];$approved=count(array_filter($record['checklist'],fn($x)=>in_array($x['status'],['approved','waived'],true)));$required=count(array_filter($record['checklist'],fn($x)=>(int)$x['is_required']===1)); ?>
<div class="page-heading"><div><p class="eyebrow">Border Crossing</p><h1><?= e($record['crossing_number'].' · '.$record['crossing_name']) ?></h1><p><?= e($record['origin_country'].' → '.$record['destination_country']) ?> · Load <?= e($record['load_number']) ?></p></div><div class="page-actions"><a class="btn btn-light" href="<?= url('/borders/packet?id='.$record['id']) ?>">Download Border Packet</a><?php if(can('border.manage')):?><a class="btn btn-primary" href="<?= url('/borders/edit?id='.$record['id']) ?>">Edit</a><?php endif;?></div></div>
<div class="stats-grid"><div class="stat-card"><span>Status</span><strong class="status-text"><?= e(readable_status($record['status'])) ?></strong><small><?= e(datetime_display($record['planned_at'])) ?></small></div><div class="stat-card"><span>Documents Ready</span><strong><?= e($approved.' / '.$required) ?></strong><small>Approved or waived required items</small></div><div class="stat-card"><span>Queue / Waiting</span><strong><?= e((string)$record['detention_minutes']) ?> min</strong><small>Detention <?= money($record['detention_amount']) ?></small></div><div class="stat-card"><span>Equipment</span><strong><?= e($record['unit_number']??'-') ?></strong><small><?= e($record['trailer_number']??'-') ?> · Seal <?= e($record['seal_number']??'-') ?></small></div></div>
<div class="content-grid two-col"><div class="panel"><div class="panel-header"><div><p class="eyebrow">Driver Workflow</p><h2>Crossing Progress</h2></div></div><form method="post" action="<?= url('/borders/status') ?>" class="form-stack"><?= csrf_field() ?><input type="hidden" name="id" value="<?= e((string)$record['id']) ?>"><select name="status"><?php foreach(BorderCrossing::STATUSES as$s):?><option value="<?= e($s) ?>" <?= $record['status']===$s?'selected':'' ?>><?= e(readable_status($s)) ?></option><?php endforeach;?></select><button class="btn btn-primary">Update Crossing Status</button></form><div class="detail-grid"><div><small>Driver</small><strong><?= e($record['driver_name']??'-') ?></strong></div><div><small>Customs Broker</small><strong><?= e($record['customs_broker_name']??'-') ?></strong></div><div><small>Reference</small><strong><?= e($record['reference_number']??'-') ?></strong></div><div><small>Entry Number</small><strong><?= e($record['entry_number']??'-') ?></strong></div><div class="span-2"><small>Instructions</small><strong><?= e($record['driver_instructions']??'-') ?></strong></div></div></div><div class="panel"><div class="panel-header"><div><p class="eyebrow">Upload</p><h2>Border Photo / Document</h2></div></div><form method="post" action="<?= url('/borders/upload') ?>" enctype="multipart/form-data" class="form-stack" data-location-form><?= csrf_field() ?><input type="hidden" name="crossing_id" value="<?= e((string)$record['id']) ?>"><input type="hidden" name="latitude" data-latitude><input type="hidden" name="longitude" data-longitude><label><span>Type</span><select name="document_type"><option>Commercial Invoice</option><option>Customs Document</option><option>Inspection Document</option><option>Seal Photo</option><option>Border / Location Photo</option><option>Challan / Ticket</option><option>Receipt</option><option>Other</option></select></label><label><span>Checklist Item</span><select name="checklist_item_id"><option value="">Not linked</option><?php foreach($record['checklist'] as$i):?><option value="<?= e((string)$i['id']) ?>"><?= e($i['item_name']) ?></option><?php endforeach;?></select></label><label><span>File</span><input type="file" name="file" accept="image/*,application/pdf" capture="environment" required></label><label><span>Location</span><input name="location_address" data-location-address></label><label><span>Notes</span><textarea name="notes"></textarea></label><button class="btn btn-primary">Upload</button></form></div></div>
<div class="content-grid two-col"><div class="panel"><div class="panel-header"><div><p class="eyebrow">Readiness</p><h2>Document Checklist</h2></div></div><div class="checklist-list"><?php foreach($record['checklist'] as$i):?><form method="post" action="<?= url('/borders/checklist') ?>" class="checklist-row"><?= csrf_field() ?><input type="hidden" name="crossing_id" value="<?= e((string)$record['id']) ?>"><input type="hidden" name="item_id" value="<?= e((string)$i['id']) ?>"><div><strong><?= e($i['item_name']) ?></strong><small><?= e($i['file_name']??'No linked file') ?></small></div><select name="status" <?= can('border.manage')?'':'disabled' ?>><option value="missing" <?= $i['status']==='missing'?'selected':'' ?>>Missing</option><option value="uploaded" <?= $i['status']==='uploaded'?'selected':'' ?>>Uploaded</option><option value="approved" <?= $i['status']==='approved'?'selected':'' ?>>Approved</option><option value="rejected" <?= $i['status']==='rejected'?'selected':'' ?>>Rejected</option><option value="waived" <?= $i['status']==='waived'?'selected':'' ?>>Waived</option></select><?php if(can('border.manage')):?><button class="btn btn-light btn-sm">Save</button><?php endif;?></form><?php endforeach;?></div></div><div class="panel"><div class="panel-header"><div><p class="eyebrow">Exceptions</p><h2>Holds, Inspections & Problems</h2></div></div><form method="post" action="<?= url('/borders/issue') ?>" class="form-stack"><?= csrf_field() ?><input type="hidden" name="crossing_id" value="<?= e((string)$record['id']) ?>"><div class="form-grid two"><label><span>Issue Type</span><select name="issue_type"><option>Missing Document</option><option>Cargo Inspection</option><option>Equipment Inspection</option><option>Seal Issue</option><option>Weight Issue</option><option>Driver Document Issue</option><option>Broker Delay</option><option>Returned Shipment</option><option>Other</option></select></label><label><span>Authority</span><input name="authority_name"></label><label><span>Reference</span><input name="reference_number"></label><label><span>Amount / Fee</span><input type="number" step="0.01" name="amount" value="0"></label></div><label><span>Description</span><textarea name="description"></textarea></label><button class="btn btn-light">Record Issue</button></form><div class="mini-list"><?php foreach($record['issues'] as$i):?><div class="mini-card warning-left"><strong><?= e($i['issue_type']) ?> · <?= money($i['amount']) ?></strong><span><?= e($i['description']??'') ?> · <?= e(readable_status($i['status'])) ?></span></div><?php endforeach;?></div></div></div>
<div class="panel"><div class="panel-header"><div><p class="eyebrow">Files</p><h2>Border Documents & Images</h2></div></div><div class="doc-gallery"><?php foreach($documents as$d):?><a class="doc-tile" href="<?= url('/documents/download?id='.$d['id']) ?>"><strong><?= e($d['document_type']) ?></strong><span><?= e($d['file_name']) ?></span><small><?= e(datetime_display($d['created_at'])) ?></small></a><?php endforeach;?><?php if(!$documents):?><p class="empty">No files uploaded.</p><?php endif;?></div></div>
