<div class="ticket-grid" style="grid-template-columns:1fr 340px">
  <div class="card">
    <div class="card-header"><h3>Teams &amp; membership</h3></div>
    <div class="table-wrap">
      <table class="table">
        <thead><tr><th>Team</th><th>Members</th></tr></thead>
        <tbody>
        <?php foreach ($teams as $t) : ?>
          <tr>
            <td style="vertical-align:top"><strong><?= e($t['name']) ?></strong><div class="text-faint text-sm"><?= e($t['description']) ?></div>
              <form method="post" action="<?= url('/admin/teams/' . $t['id'] . '/members') ?>" class="mt-2 flex gap-2">
                <?= csrf_field() ?>
                <select name="user_id" required style="min-width:140px">
                  <?php foreach ($agents as $a) : ?><option value="<?= $a['id'] ?>"><?= e($a['name']) ?></option><?php endforeach; ?>
                </select>
                <input type="text" name="skills" placeholder="Skills (optional)" style="max-width:130px">
                <button class="btn btn-sm">Add</button>
              </form>
            </td>
            <td>
              <?php foreach ($members as $m) : if ($m['team_id'] != $t['id']) continue; ?>
                <span class="badge badge-outline mt-2" style="display:inline-block;margin:2px"><?= e($m['user_name']) ?><?= $m['skills'] ? ' · ' . e($m['skills']) : '' ?></span>
              <?php endforeach; ?>
            </td>
          </tr>
        <?php endforeach; ?>
        </tbody>
      </table>
    </div>
  </div>
  <div class="card">
    <div class="card-header"><h3>Add team</h3></div>
    <div class="card-body">
      <form method="post" action="<?= url('/admin/teams') ?>">
        <?= csrf_field() ?>
        <div class="form-group"><label>Name <span class="req">*</span></label><input type="text" name="name" required></div>
        <div class="form-group"><label>Description</label><input type="text" name="description"></div>
        <button class="btn btn-primary btn-block">Add team</button>
      </form>
    </div>
  </div>
</div>
