<div class="toolbar">
  <div class="pill-tabs">
    <a href="<?= url('/kb') ?>" class="pill-tab <?= $status===''?'active':'' ?>">All</a>
    <a href="<?= url('/kb?status=draft') ?>" class="pill-tab <?= $status==='draft'?'active':'' ?>">Draft</a>
    <a href="<?= url('/kb?status=published') ?>" class="pill-tab <?= $status==='published'?'active':'' ?>">Published</a>
    <a href="<?= url('/kb?status=retired') ?>" class="pill-tab <?= $status==='retired'?'active':'' ?>">Retired</a>
  </div>
  <a href="<?= url('/kb/new') ?>" class="btn btn-primary">+ New article</a>
</div>

<div class="card">
  <div class="table-wrap">
    <table class="table">
      <thead><tr><th>Title</th><th>Category</th><th>Visibility</th><th>Status</th><th>Views</th><th>Author</th><th>Updated</th></tr></thead>
      <tbody>
      <?php foreach ($articles as $a) : ?>
        <tr>
          <td><a class="row-link" href="<?= url('/kb/' . $a['id'] . '/edit') ?>"><?= e($a['title']) ?></a></td>
          <td class="text-sm"><?= e($a['category_name'] ?? '—') ?></td>
          <td><span class="badge badge-outline"><?= $a['visibility'] === 'customer' ? 'Customer-visible' : 'Internal' ?></span></td>
          <td><span class="badge <?= $a['status']==='published'?'badge-resolved':($a['status']==='retired'?'badge-closed':'badge-pending') ?>"><?= ucfirst($a['status']) ?></span></td>
          <td class="text-sm"><?= (int)$a['views'] ?></td>
          <td class="text-sm"><?= e($a['author_name'] ?? '—') ?></td>
          <td class="text-sm"><?= fmt_dt($a['updated_at']) ?></td>
        </tr>
      <?php endforeach; ?>
      <?php if (empty($articles)) : ?><tr><td colspan="7"><div class="empty-state">No articles yet.</div></td></tr><?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
