<div class="rounded-3xl border border-slate-200 bg-white shadow-soft">
  <div class="flex flex-col gap-3 border-b border-slate-100 p-5 md:flex-row md:items-center md:justify-between">
    <div><h2 class="text-lg font-bold text-slate-900">Firms / Tenants</h2><p class="text-sm text-slate-500">Firm readiness snapshot with admin, branch, FY and service counts.</p></div>
    <a href="/wizards/system/firm/new" class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-semibold text-white hover:bg-brand-700">+ Create Firm</a>
  </div>
  <div class="overflow-x-auto">
    <table class="min-w-full divide-y divide-slate-100 text-sm">
      <thead class="bg-slate-50 text-left text-xs font-semibold uppercase tracking-wide text-slate-500"><tr><th class="px-5 py-3">Code</th><th class="px-5 py-3">Firm</th><th class="px-5 py-3">Status</th><th class="px-5 py-3">Primary Branch</th><th class="px-5 py-3">Firm Admin</th><th class="px-5 py-3 text-right">Branches</th><th class="px-5 py-3 text-right">Users</th><th class="px-5 py-3 text-right">FY</th><th class="px-5 py-3 text-right">Services</th><th class="px-5 py-3">Action</th></tr></thead>
      <tbody class="divide-y divide-slate-100">
        {% for firm in firms %}
        <tr class="hover:bg-slate-50">
          <td class="px-5 py-3 font-semibold text-slate-900">{{ firm.code }}</td>
          <td class="px-5 py-3"><div class="font-medium text-slate-900">{{ firm.name }}</div><div class="text-xs text-slate-500">{{ firm.firm_type or '-' }}{% if firm.contact_email %} &gt; {{ firm.contact_email }}{% endif %}</div></td>
          <td class="px-5 py-3"><span class="rounded-full px-2.5 py-1 text-xs font-semibold {% if firm.is_active %}bg-emerald-50 text-emerald-700{% else %}bg-slate-100 text-slate-600{% endif %}">{% if firm.is_active %}Active{% else %}Inactive{% endif %}</span>{% if firm.pending_invites %}<div class="mt-1 text-xs font-semibold text-amber-700">{{ firm.pending_invites }} invite pending</div>{% endif %}</td>
          <td class="px-5 py-3 text-slate-700">{{ firm.primary_branch }}</td>
          <td class="px-5 py-3 text-slate-700">{{ firm.primary_admin }}</td>
          <td class="px-5 py-3 text-right font-semibold">{{ firm.branch_count }}</td>
          <td class="px-5 py-3 text-right font-semibold">{{ firm.user_count }}</td>
          <td class="px-5 py-3 text-right font-semibold">{{ firm.fy_count }}</td>
          <td class="px-5 py-3 text-right font-semibold">{{ firm.selected_service_count }}</td>
          <td class="px-5 py-3"><a href="/system-settings/tenants" class="text-sm font-semibold text-brand-700 hover:text-brand-900">Open Settings</a></td>
        </tr>
        {% else %}
        <tr><td colspan="10" class="px-5 py-8 text-center text-slate-500">No firms found.</td></tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div>