<div class="af-card">
  <div class="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
    <div><h3 class="text-lg font-semibold text-slate-900">My Services</h3><p class="mt-1 text-sm text-slate-500">Client-facing status of services handled by the firm.</p></div>
    <a href="/client/compliance" class="af-btn af-btn-primary">Full Compliance Page</a>
  </div>
  <div class="mt-5 grid gap-4 md:grid-cols-4 text-sm">
    <div class="rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3"><div class="text-amber-700">Pending From You</div><div class="mt-1 text-2xl font-semibold text-amber-700">{{ pending_from_client or 0 }}</div></div>
    <div class="rounded-2xl border border-brand-200 bg-brand-50 px-4 py-3"><div class="text-brand-700">With Firm</div><div class="mt-1 text-2xl font-semibold text-brand-700">{{ with_firm or 0 }}</div></div>
    <div class="rounded-2xl border border-blue-200 bg-blue-50 px-4 py-3"><div class="text-blue-700">Clarification</div><div class="mt-1 text-2xl font-semibold text-blue-700">{{ clarification_required or 0 }}</div></div>
    <div class="rounded-2xl border border-emerald-200 bg-emerald-50 px-4 py-3"><div class="text-emerald-700">Completed</div><div class="mt-1 text-2xl font-semibold text-emerald-700">{{ completed_engagements or 0 }}</div></div>
  </div>
  <div class="mt-5 overflow-x-auto">
    <table class="min-w-full divide-y divide-slate-200 text-sm">
      <thead class="bg-slate-50 text-left text-xs font-semibold uppercase tracking-wide text-slate-500"><tr><th class="px-4 py-3">Service</th><th class="px-4 py-3">FY / AY</th><th class="px-4 py-3">Due Date</th><th class="px-4 py-3">Assigned Team</th><th class="px-4 py-3">Action</th></tr></thead>
      <tbody class="divide-y divide-slate-100 bg-white">
        {% for row in engagements or [] %}
        <tr>
          <td class="px-4 py-3 font-semibold text-slate-900">{{ row.catalogue.service_name if row.catalogue else 'Service' }}</td>
          <td class="px-4 py-3 text-slate-600">FY {{ row.financial_year or '-' }}{% if row.assessment_year %} / AY {{ row.assessment_year }}{% endif %}</td>
          <td class="px-4 py-3 text-slate-600">{{ row.current_due_date.strftime('%d-%m-%Y') if row.current_due_date else '-' }}</td>
          <td class="px-4 py-3 text-slate-600">{{ row.assigned_partner.full_name if row.assigned_partner else 'Firm team' }}</td>
          <td class="px-4 py-3"><a href="/client/engagements/{{ row.id }}" class="font-semibold text-brand-700 hover:underline">View</a></td>
        </tr>
        {% else %}
        <tr><td colspan="5" class="px-4 py-8 text-center text-slate-500">No active services found.</td></tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div>
