<?php $pageTitle=$carrier['company_name']; ?>
<div class="page-heading">
  <div><p class="eyebrow">Carrier Overview</p><h1><?= e($carrier['company_name']) ?></h1><p><?= e($carrier['dba_name']?:'External carrier / owner-operator account') ?> · <?= e($carrier['mc_number']?:'MC not entered') ?> · <?= e($carrier['dot_number']?:'DOT not entered') ?></p></div>
  <div class="page-actions"><a class="btn btn-primary" href="<?= url('/loads/create?carrier_id='.$carrier['id']) ?>">Create Load</a><a class="btn btn-light" href="<?= url('/carriers/edit?id='.$carrier['id']) ?>">Edit Carrier</a><a class="btn btn-light" href="<?= url('/documents/create?related_type=carrier&related_id='.$carrier['id']) ?>">Upload Compliance</a></div>
</div>
<div class="stats-grid compact-stats">
  <div class="stat-card"><span>Drivers</span><strong><?= (int)$carrier['driver_count'] ?></strong><small>Linked to this carrier</small></div>
  <div class="stat-card"><span>Trucks</span><strong><?= (int)$carrier['truck_count'] ?></strong><small>Carrier or leased power units</small></div>
  <div class="stat-card"><span>Trailers</span><strong><?= (int)$carrier['trailer_count'] ?></strong><small>Including reefer equipment</small></div>
  <div class="stat-card highlight"><span>Dispatch Fee</span><strong><?= $carrier['dispatch_fee_type']==='percentage'?e((string)$carrier['dispatch_fee_value']).'%':money($carrier['dispatch_fee_value']) ?></strong><small><?= e(readable_status($carrier['dispatch_fee_type'])) ?></small></div>
</div>
<div class="content-grid two-col">
  <section class="panel">
    <div class="panel-header"><div><p class="eyebrow">Daily Operations</p><h2>Assigned Loads</h2></div></div>
    <div class="mobile-card-list">
      <?php foreach(array_slice($loads,0,12) as $load): ?><a class="mobile-record-card" href="<?= url('/loads/edit?id='.$load['id']) ?>"><div><strong><?= e($load['load_number']) ?> · <?= e($load['pickup_location']) ?> → <?= e($load['delivery_location']) ?></strong><span><?= e($load['driver_name']?:'Unassigned driver') ?> · <?= e($load['truck_number']?:'No truck') ?> · Pickup <?= e(datetime_display($load['pickup_datetime'])) ?></span></div><div class="align-right"><span class="badge badge-<?= status_class($load['status']) ?>"><?= e(readable_status($load['status'])) ?></span><small><?= money($load['dispatch_fee_amount']) ?> fee</small></div></a><?php endforeach; ?>
      <?php if(!$loads): ?><p class="empty">No loads assigned to this carrier.</p><?php endif; ?>
    </div>
  </section>
  <section class="panel">
    <div class="panel-header"><div><p class="eyebrow">Compliance</p><h2>Carrier Details</h2></div></div>
    <div class="info-list">
      <div><span>Primary contact</span><strong><?= e($carrier['contact_name']?:'-') ?></strong><small><?= e($carrier['phone']?:'') ?> <?= e($carrier['email']?:'') ?></small></div>
      <div><span>Authority / safety</span><strong><?= e(readable_status($carrier['authority_status'])) ?></strong><small><?= e($carrier['safety_rating']?:'Safety rating not entered') ?></small></div>
      <div><span>Insurance expiry</span><strong><?= e(date_display($carrier['insurance_expiry'])) ?></strong><small>Cargo: <?= e(date_display($carrier['cargo_insurance_expiry'])) ?></small></div>
      <div><span>Onboarding</span><strong><?= e(readable_status($carrier['onboarding_status'])) ?></strong><small><?= e(readable_status($carrier['status'])) ?></small></div>
    </div>
  </section>
</div>
<div class="content-grid two-col">
  <section class="panel"><div class="panel-header"><div><p class="eyebrow">Equipment</p><h2>Power Units & Trailers</h2></div></div><div class="mobile-card-list"><?php foreach($equipment as $item): ?><div class="mobile-record-card"><div><strong><?= e($item['kind'].' '.$item['identifier']) ?></strong><span><?= e(readable_status($item['ownership_type'])) ?><?= $item['equipment_type']?' · '.e($item['equipment_type']):'' ?></span></div><div class="align-right"><span class="badge badge-<?= status_class($item['status']) ?>"><?= e(readable_status($item['status'])) ?></span><?php if($item['current_temperature']!==null): ?><small><?= e((string)$item['current_temperature'].$item['temperature_unit']) ?></small><?php endif; ?></div></div><?php endforeach; ?><?php if(!$equipment): ?><p class="empty">No equipment linked yet.</p><?php endif; ?></div></section>
  <section class="panel"><div class="panel-header"><div><p class="eyebrow">Documents</p><h2>Compliance Files</h2></div></div><div class="mini-list"><?php foreach($documents as $doc): ?><a class="mini-card" href="<?= url('/documents/download?id='.$doc['id']) ?>"><strong><?= e($doc['document_type']) ?></strong><span><?= e($doc['file_name']) ?><?= $doc['expires_at']?' · expires '.e(date_display($doc['expires_at'])):'' ?></span></a><?php endforeach; ?><?php if(!$documents): ?><p class="empty">No carrier documents uploaded.</p><?php endif; ?></div></section>
</div>
