<!-- ===================== SOURCES TAB ===================== -->
<div class="tab-pane <?= ($requested_tab === 'sources') ? 'active' : '' ?>" id="tab-sources">
  <div class="toolbar">
    <span class="card-title">Customer Sources</span>
    <button class="btn btn-primary btn-sm" onclick="openModal('addSourceModal')" style="margin-left:auto">+ Add Source</button>
  </div>
  <div class="card"><div class="table-wrapper"><table class="crm-table">
    <thead><tr><th>Source</th><th>Status</th><th>Actions</th></tr></thead><tbody>
    <?php if($sources_settings && $sources_settings->num_rows): while($src=$sources_settings->fetch_assoc()): ?>
      <tr id="source_<?= crmEid($src['id']) ?>">
        <td><input id="source_name_<?= crmEid($src['id']) ?>" class="form-control form-control-sm" value="<?= htmlspecialchars($src['name']) ?>" style="display:none"><span id="source_name_span_<?= crmEid($src['id']) ?>"><?= htmlspecialchars($src['name']) ?></span></td>
        <td><select id="source_status_<?= crmEid($src['id']) ?>" class="form-control form-control-sm" style="display:none"><option value="1" <?= (int)$src['status']===1?'selected':'' ?>>Active</option><option value="0" <?= (int)$src['status']===0?'selected':'' ?>>Inactive</option></select><span id="source_status_span_<?= crmEid($src['id']) ?>" class="badge <?= (int)$src['status']===1?'badge-green':'badge-gray' ?>"><?= (int)$src['status']===1?'Active':'Inactive' ?></span></td>
        <td><button class="btn btn-warning btn-sm" id="source_edit_btn_<?= crmEid($src['id']) ?>" onclick="editSource('<?= crmEid($src['id']) ?>')">Edit</button> <button class="btn btn-success btn-sm" id="source_save_btn_<?= crmEid($src['id']) ?>" style="display:none" onclick="saveSource('<?= crmEid($src['id']) ?>')">Save</button> <button class="btn btn-danger btn-sm" onclick="deleteSource('<?= crmEid($src['id']) ?>')">Delete</button></td>
      </tr>
    <?php endwhile; else: ?><tr><td colspan="3" class="text-center text-muted" style="padding:30px">No sources yet</td></tr><?php endif; ?>
    </tbody></table></div></div>
</div>
<div class="modal-overlay" id="addSourceModal"><div class="modal"><div class="modal-header"><span class="modal-title">Add Source</span><button class="modal-close">✕</button></div><div class="modal-body"><label class="form-label">Source Name *</label><input type="text" id="sourceNameInput" class="form-control" placeholder="Facebook, Instagram, Referral..."></div><div class="modal-footer"><button class="btn btn-secondary" onclick="closeModal('addSourceModal')">Cancel</button><button class="btn btn-primary" onclick="addSource()">Add</button></div></div></div>
