{% load i18n admin_urls %}
<div class="js-inline-admin-formset inline-group "
     id="{{ inline_admin_formset.formset.prefix }}-group"
     data-inline-type="stacked"
     data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
     
<fieldset class="module {{ inline_admin_formset.classes }}" aria-labelledby="{{ inline_admin_formset.formset.prefix }}-heading">
  {% if inline_admin_formset.is_collapsible %}<details><summary>{% endif %}
  <h2 id="{{ inline_admin_formset.formset.prefix }}-heading" class="inline-heading">
  {% if inline_admin_formset.formset.max_num == 1 %}
    {{ inline_admin_formset.opts.verbose_name|capfirst }}
  {% else %}
    {{ inline_admin_formset.opts.verbose_name_plural|capfirst }}
  {% endif %}
  </h2>
  {% if inline_admin_formset.is_collapsible %}</summary>{% endif %}
{{ inline_admin_formset.formset.management_form }}
{{ inline_admin_formset.formset.non_form_errors }}


{% for inline_admin_form in inline_admin_formset %}
<div>
  <div class="br-card">
    <div class="inline-related card-content {% if inline_admin_form.original or inline_admin_form.show_url %} has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form last-related{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if forloop.last and inline_admin_formset.has_add_permission %}empty{% else %}{{ forloop.counter0 }}{% endif %}">
      {% comment %}
      <p><b>{{ inline_admin_formset.opts.verbose_name|capfirst }}:</b> <span class="inline_label">
        {% if inline_admin_form.original %}
          {{ inline_admin_form.original }}
          {% if inline_admin_form.model_admin.show_change_link and inline_admin_form.model_admin.has_registered_model %} 
            <a href="{% url inline_admin_form.model_admin.opts|admin_urlname:'change' inline_admin_form.original.pk|admin_urlquote %}" class="{{ inline_admin_formset.has_change_permission|yesno:'inlinechangelink,inlineviewlink' }}">
              {% if inline_admin_formset.has_change_permission %}{% translate "Change" %}{% else %}{% translate "View" %}{% endif %}
            </a>
          {% endif %}
        {% else %}#{{ forloop.counter }}{% endif %}
          </span>
          {% if inline_admin_form.show_url %}
            <a href="{{ inline_admin_form.absolute_url }}">{% translate "View on site" %}</a>
          {% endif %}
          {% if inline_admin_formset.formset.can_delete and inline_admin_formset.has_delete_permission and inline_admin_form.original %}
            <span class="delete">{{ inline_admin_form.deletion_field.field }} {{ inline_admin_form.deletion_field.label_tag }}</span>
          {% endif %}
        </p>
        {% endcomment %}

        {% if inline_admin_form.form.non_field_errors %}{{ inline_admin_form.form.non_field_errors }}{% endif %}

        {% with parent_counter=forloop.counter0 %}
          {% for fieldset in inline_admin_form %}
            {% include "admin/includes/fieldset.html" with heading_level=4 prefix=fieldset.formset.prefix id_prefix=parent_counter id_suffix=forloop.counter0 %}
          {% endfor %}
        {% endwith %}
    </div>

  </div> <!-- card -->

      {% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
      {% if inline_admin_form.fk_field %}{{ inline_admin_form.fk_field.field }}{% endif %}</div>
{% endfor %}
  {% if inline_admin_formset.is_collapsible %}</details>{% endif %}
</fieldset>
</div>

<style>
.inline-related .delete {
    float: right;
}
.add-row > .addlink {
    margin-top: 1em;
    position: absolute;
    background-color: var(--background-light);
    border: 1px solid var(--interactive);
    align-items: center;
    border-radius: var(--button-radius);
    color: var(--interactive);
    cursor: pointer;
    display: inline-flex;
    font-size: var(--font-size-scale-up-01);
    font-weight: var(--font-weight-semi-bold);
    height: var(--button-size);
    justify-content: center;
    padding: 0 var(--spacing-scale-3x);
    /* position: relative; */
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    width: auto;
    --button-radius: 100em;
    --button-xsmall: 24px;
    --button-small: 32px;
    --button-medium: 40px;
    --button-large: 48px;
    text-decoration: none;
}
</style>