<!-- ===================== 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()): ?>
          <tr id="lr_<?= $lr['id'] ?>">
            <td class="font-bold">
              <?php if ($is_admin): ?>
              <input type="text" class="form-control form-control-sm" id="lr_name_<?= $lr['id'] ?>" value="<?= htmlspecialchars($lr['name']) ?>" style="display:none;">
              <span id="lr_name_span_<?= $lr['id'] ?>"><?= 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['id'] ?>" 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['id'] ?>"><?= 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['id'] ?>" onclick="editLostReason(<?= $lr['id'] ?>)">Edit</button>
              <button class="btn btn-success btn-sm" id="lr_save_btn_<?= $lr['id'] ?>" style="display:none;" onclick="saveLostReason(<?= $lr['id'] ?>)">Save</button>
              <button class="btn btn-danger btn-sm" onclick="deleteLostReason(<?= $lr['id'] ?>)">Del</button>
              <?php endif; ?>
            </td>
          </tr>
          <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>
</div>
