{% set is_edit = row is defined and row %}
<div class="grid gap-6 xl:grid-cols-3">
  <section class="rounded-2xl bg-white p-6 shadow-soft xl:col-span-2">
    <h3 class="text-base font-semibold text-slate-900">Basic Profile</h3>
    <div class="mt-4 grid gap-4 md:grid-cols-2">
      <div>
        <label class="block text-sm font-medium text-slate-700">Client Code</label>
        <input name="client_code" value="{{ form_data.client_code or (row.client_code if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm" {% if is_edit %}readonly{% endif %}>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Client Name</label>
        <input name="client_name" value="{{ form_data.client_name or (row.client_name if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Trade Name</label>
        <input name="trade_name" value="{{ form_data.trade_name or (row.trade_name if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Legal Constitution</label>
        <select name="client_type" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          {% for opt in client_types %}
          <option value="{{ opt }}" {% if (form_data.client_type or (row.client_type if is_edit else 'Other')) == opt %}selected{% endif %}>{{ opt }}</option>
          {% endfor %}
        </select>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">PAN</label>
        <input name="pan" value="{{ form_data.pan or (row.pan if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">GSTIN</label>
        <input name="gstin" value="{{ form_data.gstin or (row.gstin if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">TAN</label>
        <input name="tan" value="{{ form_data.tan or (row.tan if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">CIN / LLPIN</label>
        <input name="cin_llpin" value="{{ form_data.cin_llpin or (row.cin_llpin if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">MSME Number</label>
        <input name="msme_no" value="{{ form_data.msme_no or (row.msme_no if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">IEC Code</label>
        <input name="iec_code" value="{{ form_data.iec_code or (row.iec_code if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Mobile</label>
        <input name="mobile" value="{{ form_data.mobile or (row.mobile if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Alternate Mobile</label>
        <input name="alternate_mobile" value="{{ form_data.alternate_mobile or (row.alternate_mobile if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Email (used for frontend login)</label>
        <input name="email" value="{{ form_data.email or (row.email if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Alternate Email</label>
        <input name="alternate_email" value="{{ form_data.alternate_email or (row.alternate_email if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Contact Person</label>
        <input name="contact_person_name" value="{{ form_data.contact_person_name or (row.contact_person_name if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Designation</label>
        <input name="contact_person_designation" value="{{ form_data.contact_person_designation or (row.contact_person_designation if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      {# Legacy client_category is retained as a hidden compatibility value.
         Service selection belongs to the engagement workflow. #}
      <input type="hidden" name="client_category" value="{{ form_data.client_category or (row.client_category if is_edit else '') }}">

      <div>
        <label class="block text-sm font-medium text-slate-700">Risk Category</label>
        <select name="risk_category" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Select --</option>
          {% for opt in risk_categories %}
          <option value="{{ opt }}" {% if (form_data.risk_category or (row.risk_category if is_edit else '')) == opt %}selected{% endif %}>{{ opt }}</option>
          {% endfor %}
        </select>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Onboarding Date</label>
        <input type="date" name="onboarding_date" value="{{ form_data.onboarding_date or (row.onboarding_date if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Closing Date</label>
        <input type="date" name="closing_date" value="{{ form_data.closing_date or (row.closing_date if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div class="md:col-span-2">
        <label class="block text-sm font-medium text-slate-700">Address Line 1</label>
        <input name="address_line_1" value="{{ form_data.address_line_1 or (row.address_line_1 if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div class="md:col-span-2">
        <label class="block text-sm font-medium text-slate-700">Address Line 2</label>
        <input name="address_line_2" value="{{ form_data.address_line_2 or (row.address_line_2 if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">City</label>
        <input name="city" value="{{ form_data.city or (row.city if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">State</label>
        <input name="state" value="{{ form_data.state or (row.state if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Pincode</label>
        <input name="pincode" value="{{ form_data.pincode or (row.pincode if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Country</label>
        <input name="country" value="{{ form_data.country or (row.country if is_edit else 'India') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>

      {# Client master is intentionally free of AQMM controls.
         AQMM/quality workflow now starts only at assurance engagement creation.
         Hidden compatibility fields prevent older backend handlers from failing
         if Phase 2 client acceptance columns still exist in the database. #}
      <input type="hidden" name="acceptance_status" value="{{ form_data.acceptance_status or (row.acceptance_status if is_edit else 'pending_review') }}">
      <input type="hidden" name="acceptance_required" value="0">
      <input type="hidden" name="independence_check_completed" value="0">
      <input type="hidden" name="conflict_check_completed" value="0">
      <input type="hidden" name="kyc_completed" value="0">
      <input type="hidden" name="engagement_letter_required" value="0">
      <input type="hidden" name="engagement_letter_received" value="0">
      <input type="hidden" name="acceptance_review_notes" value="{{ form_data.acceptance_review_notes or (row.acceptance_review_notes if is_edit else '') }}">
      <input type="hidden" name="acceptance_rejection_reason" value="{{ form_data.acceptance_rejection_reason or (row.acceptance_rejection_reason if is_edit else '') }}">

      <div class="md:col-span-2">
        <label class="block text-sm font-medium text-slate-700">Notes</label>
        <textarea name="notes" rows="4" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">{{ form_data.notes or (row.notes if is_edit else '') }}</textarea>
      </div>
    </div>
  </section>

  
  <section class="rounded-2xl border border-slate-200 p-5 md:col-span-2">
    <h3 class="text-sm font-semibold text-slate-900">Client Group / Family</h3>
    <p class="mt-1 text-xs text-slate-500">Link this client to an existing family, promoter or related business group. Consultant access remains client-specific.</p>
    <div class="mt-4 grid gap-4 md:grid-cols-3">
      <label class="text-sm font-medium text-slate-700">Client Group
        <select name="client_group_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- No group --</option>
          {% for g in form_options.client_groups or [] %}<option value="{{ g.id }}" {% if (form_data.client_group_id or (row.client_group_id if is_edit else None)) == g.id %}selected{% endif %}>{{ g.group_code }} — {{ g.group_name }}</option>{% endfor %}
        </select>
      </label>
      <label class="text-sm font-medium text-slate-700">Relationship within group
        <input name="group_relationship" value="{{ form_data.group_relationship or (row.group_relationship if is_edit else '') }}" placeholder="Spouse, HUF, Company, Trust..." class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </label>
      <label class="mt-7 inline-flex items-center gap-2 text-sm font-medium text-slate-700"><input type="checkbox" name="is_group_head" {% if form_data.is_group_head or (is_edit and row.is_group_head) %}checked{% endif %}> Group head</label>
    </div>
    <div class="mt-3"><a href="/client-groups/new" class="text-sm font-medium text-brand-700 hover:underline">Create a new client group</a></div>
  </section>
<section class="rounded-2xl bg-white p-6 shadow-soft">
    <h3 class="text-base font-semibold text-slate-900">Assignment & Scope</h3>
    <div class="mt-4 space-y-4">
      <div>
        <label class="block text-sm font-medium text-slate-700">Engagement Mode</label>
        <select name="engagement_mode" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          {% for opt in ['internal_managed','self_tracked','hybrid'] %}
          <option value="{{ opt }}" {% if (form_data.engagement_mode or (row.engagement_mode if is_edit else ('hybrid' if form_mode == 'firm_admin' else 'internal_managed'))) == opt %}selected{% endif %}>{{ opt }}</option>
          {% endfor %}
        </select>
      </div>

      {% if form_mode == 'firm_admin' %}
      {# Firm Admin is always scoped by the active tenant in the shared header. #}
      <input type="hidden" name="tenant_id" value="{{ form_data.tenant_id or (row.tenant_id if is_edit else form_options.active_tenant_id) }}">

      <div>
        <label class="block text-sm font-medium text-slate-700">Branch</label>
        <select name="branch_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          {% for b in form_options.branches %}
          <option value="{{ b.id }}" {% if (form_data.branch_id or (row.branch_id if is_edit else form_options.active_branch_id)) == b.id %}selected{% endif %}>{{ b.name }}</option>
          {% endfor %}
        </select>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Partner</label>
        <select name="partner_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Select Partner --</option>
          {% for p in form_options.partners %}
          <option value="{{ p.id }}" {% if (form_data.partner_id or (row.partner_id if is_edit else None)) == p.id %}selected{% endif %}>{{ p.full_name or p.email }}</option>
          {% endfor %}
        </select>
      </div>

      {% elif form_mode == 'system_admin' %}
      <div>
        <label class="block text-sm font-medium text-slate-700">Audit Firm</label>
        <select name="tenant_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          {% for t in form_options.tenants %}
          <option value="{{ t.id }}" {% if (form_data.tenant_id or (row.tenant_id if is_edit else form_options.active_tenant_id)) == t.id %}selected{% endif %}>{{ t.name }}</option>
          {% endfor %}
        </select>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Branch</label>
        <select name="branch_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Select Branch --</option>
          {% for b in form_options.branches %}
          <option value="{{ b.id }}" {% if (form_data.branch_id or (row.branch_id if is_edit else form_options.active_branch_id)) == b.id %}selected{% endif %}>
            {{ b.name }}{% if b.tenant_name %} ({{ b.tenant_name }}){% endif %}
          </option>
          {% endfor %}
        </select>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Partner</label>
        <select name="partner_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Select Partner --</option>
          {% for p in form_options.partners %}
          <option value="{{ p.id }}" {% if (form_data.partner_id or (row.partner_id if is_edit else None)) == p.id %}selected{% endif %}>
            {{ p.full_name or p.email }}{% if p.tenant_name %} ({{ p.tenant_name }}){% endif %}
          </option>
          {% endfor %}
        </select>
      </div>

      {% elif form_mode == 'partner' %}
      <div class="rounded-xl border border-slate-200 bg-slate-50 p-4 text-sm text-slate-700">
        Partner assignment is locked to your own user.
        <input type="hidden" name="tenant_id" value="{{ form_data.tenant_id or (row.tenant_id if is_edit else form_options.active_tenant_id) }}">
        <input type="hidden" name="branch_id" value="{{ form_data.branch_id or (row.branch_id if is_edit else form_options.active_branch_id) }}">
        <input type="hidden" name="partner_id" value="{{ current_user.id }}">
      </div>

      {% elif form_mode == 'consultant' %}
      <div class="rounded-xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-800">
        Consultant users cannot assign or reassign partner mappings.
        <input type="hidden" name="tenant_id" value="{{ form_data.tenant_id or (row.tenant_id if is_edit else form_options.active_tenant_id) }}">
        <input type="hidden" name="branch_id" value="{{ form_data.branch_id or (row.branch_id if is_edit else form_options.active_branch_id) }}">
        <input type="hidden" name="partner_id" value="{{ form_data.partner_id or (row.partner_id if is_edit else '') }}">
      </div>

      {% elif form_mode == 'self_service' %}
      <div class="rounded-xl border border-slate-200 bg-slate-50 p-4 text-sm text-slate-700">
        This client is currently unassigned. Initial association to firm, branch, and partner must be done by System Admin.
      </div>
      {% endif %}



      <div class="md:col-span-2 border-t border-slate-200 pt-4">
        <h4 class="text-sm font-semibold text-slate-900">Consultant Referral & Communication</h4>
        <p class="mt-1 text-xs text-slate-500">Referral records who introduced the client. Primary consultant controls the operational client link.</p>
      </div>
      <div>
        <label class="block text-sm font-medium text-slate-700">Referred By Consultant</label>
        <select name="referred_by_consultant_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Direct / No consultant --</option>
          {% for c in form_options.consultants or [] %}
          <option value="{{ c.id }}" {% if (form_data.referred_by_consultant_id or (row.referred_by_consultant_id if is_edit else None)) == c.id %}selected{% endif %}>{{ c.contact_person }}{% if c.firm_name %} — {{ c.firm_name }}{% endif %}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="block text-sm font-medium text-slate-700">Primary Consultant</label>
        <select name="primary_consultant_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Firm managed only --</option>
          {% for c in form_options.consultants or [] %}
          <option value="{{ c.id }}" {% if form_data.primary_consultant_id == c.id %}selected{% endif %}>{{ c.contact_person }}{% if c.firm_name %} — {{ c.firm_name }}{% endif %}</option>
          {% endfor %}
        </select>
      </div>
      <div>
        <label class="block text-sm font-medium text-slate-700">Referral Date</label>
        <input type="date" name="referral_date" value="{{ form_data.referral_date or (row.referral_date if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
      </div>
      <div>
        <label class="block text-sm font-medium text-slate-700">Referral Status</label>
        <select name="referral_status" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          {% for value, label in [('active','Active'),('inactive','Inactive'),('ended','Ended')] %}<option value="{{ value }}" {% if (form_data.referral_status or (row.referral_status if is_edit else 'active')) == value %}selected{% endif %}>{{ label }}</option>{% endfor %}
        </select>
      </div>
      <div>
        <label class="block text-sm font-medium text-slate-700">Communication Routing</label>
        <select name="communication_routing_mode" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          {% for value, label in [('client_direct','Client Direct'),('consultant_primary','Primary Consultant'),('client_and_consultant','Client and Consultant'),('firm_only','Firm Only')] %}<option value="{{ value }}" {% if (form_data.communication_routing_mode or (row.communication_routing_mode if is_edit else 'client_and_consultant')) == value %}selected{% endif %}>{{ label }}</option>{% endfor %}
        </select>
      </div>
      <div>
        <label class="block text-sm font-medium text-slate-700">Referral Reference</label>
        <input name="referral_reference" value="{{ form_data.referral_reference or (row.referral_reference if is_edit else '') }}" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm" placeholder="Source, campaign, agreement or note">
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Default Performing Partner</label>
        <select name="default_performing_partner_user_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Same as Engagement Partner --</option>
          {% for p in form_options.performing_partners or [] %}
          <option value="{{ p.id }}" {% if (form_data.default_performing_partner_user_id or (row.default_performing_partner_user_id if is_edit else None)) == p.id %}selected{% endif %}>
            {{ p.full_name or p.email }}{% if p.tenant_name %} ({{ p.tenant_name }}){% endif %}
          </option>
          {% endfor %}
        </select>
        <p class="mt-1 text-xs text-slate-500">Defaults the Partner who directly performs or supervises the engagement. When blank, the Engagement Partner is used.</p>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Default Review Partner</label>
        <select name="default_review_partner_user_id" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          <option value="">-- Not required / Select later --</option>
          {% for p in form_options.review_partners or [] %}
          <option value="{{ p.id }}" {% if (form_data.default_review_partner_user_id or (row.default_review_partner_user_id if is_edit else None)) == p.id %}selected{% endif %}>
            {{ p.full_name or p.email }}{% if p.tenant_name %} ({{ p.tenant_name }}){% endif %}
          </option>
          {% endfor %}
        </select>
        <p class="mt-1 text-xs text-slate-500">Used automatically for assurance engagements only when the audit firm is a partnership firm.</p>
      </div>

      <div>
        <label class="block text-sm font-medium text-slate-700">Status</label>
        <select name="status" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm">
          {% for opt in client_statuses %}
          <option value="{{ opt }}" {% if (form_data.status or (row.status if is_edit else 'active')) == opt %}selected{% endif %}>{{ opt|title }}</option>
          {% endfor %}
        </select>
      </div>

      <div class="border-t border-slate-200 pt-4">
        <h4 class="mb-3 text-sm font-semibold text-slate-900">Client Frontend Login</h4>
        <div class="rounded-xl border border-sky-200 bg-sky-50 p-3 text-xs text-sky-800">
          {% if is_edit and row.portal_user_id %}
            Linked portal user already exists. Leave password blank to keep the current password, or enter a new password to reset it.
          {% elif is_edit %}
            This existing client does not yet have a linked login. Enter email and password below to create the client login now.
          {% else %}
            Creating a client will also create a frontend login using the client email and password below.
          {% endif %}
        </div>

        <div class="mt-4 grid gap-4">
          <div>
            <label class="block text-sm font-medium text-slate-700">{% if is_edit and row.portal_user_id %}New Password{% else %}Password{% endif %}</label>
            <input name="portal_password" type="password" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm" {% if not is_edit %}required{% endif %}>
          </div>

          <div>
            <label class="block text-sm font-medium text-slate-700">{% if is_edit and row.portal_user_id %}Confirm New Password{% else %}Confirm Password{% endif %}</label>
            <input name="portal_password_confirm" type="password" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm" {% if not is_edit %}required{% endif %}>
          </div>

          {% if is_edit and row.portal_user_id %}
          <div class="text-xs text-slate-500">
            Portal user id linked: {{ row.portal_user_id }}
          </div>
          {% endif %}
        </div>
      </div>

      {% if is_edit %}
      <div class="border-t border-slate-200 pt-4">
        <h4 class="mb-3 text-sm font-semibold text-slate-900">Compliance Applicability</h4>

        <div class="grid gap-3">
          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="gst_applicable" value="1" {% if form_data.gst_applicable or (row.gst_applicable if is_edit else false) %}checked{% endif %}>
            GST Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="income_tax_applicable" value="1" {% if form_data.income_tax_applicable or (row.income_tax_applicable if is_edit else false) %}checked{% endif %}>
            Income Tax Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="tds_applicable" value="1" {% if form_data.tds_applicable or (row.tds_applicable if is_edit else false) %}checked{% endif %}>
            TDS Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="roc_applicable" value="1" {% if form_data.roc_applicable or (row.roc_applicable if is_edit else false) %}checked{% endif %}>
            ROC Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="audit_applicable" value="1" {% if form_data.audit_applicable or (row.audit_applicable if is_edit else false) %}checked{% endif %}>
            Audit Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="pf_applicable" value="1" {% if form_data.pf_applicable or (row.pf_applicable if is_edit else false) %}checked{% endif %}>
            PF Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="esi_applicable" value="1" {% if form_data.esi_applicable or (row.esi_applicable if is_edit else false) %}checked{% endif %}>
            ESI Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="professional_tax_applicable" value="1" {% if form_data.professional_tax_applicable or (row.professional_tax_applicable if is_edit else false) %}checked{% endif %}>
            Professional Tax Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="payroll_applicable" value="1" {% if form_data.payroll_applicable or (row.payroll_applicable if is_edit else false) %}checked{% endif %}>
            Payroll Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="msme_applicable" value="1" {% if form_data.msme_applicable or (row.msme_applicable if is_edit else false) %}checked{% endif %}>
            MSME Applicable
          </label>

          <label class="flex items-center gap-2 text-sm text-slate-700">
            <input type="checkbox" name="import_export_applicable" value="1" {% if form_data.import_export_applicable or (row.import_export_applicable if is_edit else false) %}checked{% endif %}>
            Import / Export Applicable
          </label>
        </div>
      </div>
      {% else %}
      <div class="border-t border-slate-200 pt-4">
        <div class="rounded-xl border border-sky-200 bg-sky-50 p-4 text-sm text-sky-900">
          <div class="font-semibold">Services and AQMM requirements are configured at engagement level</div>
          <p class="mt-2 leading-6">Create the client master first. After creation, assign one or more firm-enabled services through an engagement. The existing Assurance / Non-Assurance classification will continue to activate the applicable acceptance, independence, conflict, engagement-letter and other AQMM requirements.</p>
        </div>
      </div>
      {% endif %}
    </div>
  </section>
</div>
