{% extends "ui/templates/base/layout.html" %}
{% block content %}
<div class="space-y-6">
  <div class="flex flex-wrap items-center justify-between gap-3">
    <div>
      <h2 class="text-xl font-semibold text-slate-900">Permanent Client Documents</h2>
      <p class="text-sm text-slate-500">Store standing records like registration documents, GST, PAN/TAN, KYC, bank and agreements outside financial-year folders.</p>
    </div>
    <a href="/documents" class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Engagement Documents</a>
  </div>

  <form method="get" class="flex flex-wrap items-end gap-3 rounded-2xl bg-white p-4 shadow-soft">
    <div>
      <label class="mb-1 block text-xs font-semibold uppercase tracking-wide text-slate-500">Search Client</label>
      <input type="text" name="q" value="{{ q or '' }}" placeholder="Client name or code" class="w-80 rounded-xl border border-slate-300 px-3 py-2 text-sm">
    </div>
    <button class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Filter</button>
  </form>

  <div class="overflow-hidden rounded-2xl bg-white shadow-soft">
    <table class="min-w-full divide-y divide-slate-200">
      <thead class="bg-slate-50">
        <tr>
          <th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Client</th>
          <th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Code</th>
          <th class="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">Branch</th>
          <th class="px-4 py-3 text-right text-xs font-semibold uppercase tracking-wide text-slate-500">Action</th>
        </tr>
      </thead>
      <tbody class="divide-y divide-slate-100">
        {% for client in clients %}
        <tr>
          <td class="px-4 py-3 text-sm font-medium text-slate-900">{{ client.client_name }}</td>
          <td class="px-4 py-3 text-sm text-slate-600">{{ client.client_code or '-' }}</td>
          <td class="px-4 py-3 text-sm text-slate-600">{{ client.branch_id or '-' }}</td>
          <td class="px-4 py-3 text-right text-sm"><a href="/documents/permanent/clients/{{ client.id }}" class="font-medium text-brand-700 hover:underline">Open Permanent Vault</a></td>
        </tr>
        {% else %}
        <tr><td colspan="4" class="px-4 py-8 text-center text-sm text-slate-500">No clients available for permanent document access.</td></tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div>
{% endblock %}
