<!-- ===================== LOST REASONS TAB ===================== -->
<div class="tab-pane <?= ($requested_tab === 'lost') ? 'active' : '' ?>" id="tab-lost">
  <div class="toolbar">
    <span class="card-title">Lost Reasons</span>
    <?php if ($is_admin): ?>
    <button class="btn btn-primary btn-sm" onclick="openModal('addLostModal')" style="margin-left:auto">+ Add Reason</button>
    <?php endif; ?>
  </div>
  <div class="card">
    <div class="table-wrapper">
      <table class="crm-table" id="lostReasonsTable">
        <thead><tr><th>Reason</th><th>Status</th><th>Created</th><th>Actions</th></tr></thead>
        <tbody>
          <?php while ($lr = $lost_reasons->fetch_assoc()): $lr_eid = crmEid($lr['id']); ?>
          <tr id="lr_<?= $lr_eid ?>">
            <td class="font-bold">
              <?php if ($is_admin): ?>
              <input type="text" class="form-control form-control-sm" id="lr_name_<?= $lr_eid ?>" value="<?= htmlspecialchars($lr['name']) ?>" style="display:none;">
              <span id="lr_name_span_<?= $lr_eid ?>"><?= htmlspecialchars($lr['name']) ?></span>
              <?php else: ?>
              <?= htmlspecialchars($lr['name']) ?>
              <?php endif; ?>
            </td>
            <td>
              <?php if ($is_admin): ?>
              <select class="form-control form-control-sm" id="lr_status_<?= $lr_eid ?>" style="display:none;">
                <option value="active" <?= $lr['status']=='active'?'selected':'' ?>>Active</option>
                <option value="inactive" <?= $lr['status']=='inactive'?'selected':'' ?>>Inactive</option>
              </select>
              <?php endif; ?>
              <span class="badge badge-<?= $lr['status']==='active'?'green':'gray' ?>" id="lr_status_span_<?= $lr_eid ?>"><?= ucfirst($lr['status']) ?></span>
            </td>
            <td class="text-muted text-xs"><?= formatDate($lr['date_created']) ?></td>
            <td>
              <?php if ($is_admin): ?>
              <button class="btn btn-warning btn-sm" id="lr_edit_btn_<?= $lr_eid ?>" onclick="editLostReason('<?= $lr_eid ?>')">Edit</button>
              <button class="btn btn-success btn-sm" id="lr_save_btn_<?= $lr_eid ?>" style="display:none;" onclick="saveLostReason('<?= $lr_eid ?>')">Save</button>
              <button class="btn btn-danger btn-sm" onclick="deleteLostReason('<?= $lr_eid ?>')">Del</button>
              <?php endif; ?>
            </td>
          </tr>
          <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>
