{# Search results #}
{% if q %}
  {% if cases and cases.exists %}
    <div class="list-group mb-2">
  {% for case in cases %}
  <div class="list-group-item d-flex justify-content-between align-items-center" data-case-pk="{{ case.pk }}">
          <div class="flex-fill me-3">
            <div class="fw-semibold">{{ case.title }}</div>
            <div class="small text-muted">{% if case.description %}{{ case.description|truncatechars:100 }}{% endif %}</div>
          </div>

          <form class="m-0" hx-post="{% url 'atlas:add_case_to_collection' collection.pk %}" hx-target="#full-question-list" hx-swap="beforeend">
            {% csrf_token %}
            <input type="hidden" name="case" value="{{ case.pk }}">
            <button type="submit" class="btn btn-sm btn-primary">Add</button>
          </form>
        </div>
      {% endfor %}
    </div>
  {% else %}
    <div class="text-muted small mb-2">No cases found.</div>
  {% endif %}
{% endif %}

{# Recent cases quick-add (rendered below search results) #}
{% if recent_cases and recent_cases|length > 0 %}
  <div>
    <div class="small text-muted mb-1">Recently created</div>
    <div class="list-group">
      {% for case in recent_cases %}
        <div class="list-group-item d-flex justify-content-between align-items-center" data-case-pk="{{ case.pk }}">
          <div class="flex-fill me-3">
            <div class="fw-semibold">{{ case.title }}</div>
            <div class="small text-muted">{% if case.description %}{{ case.description|truncatechars:100 }}{% endif %}</div>
          </div>
          <form class="m-0" hx-post="{% url 'atlas:add_case_to_collection' collection.pk %}" hx-target="#full-question-list" hx-swap="beforeend">
            {% csrf_token %}
            <input type="hidden" name="case" value="{{ case.pk }}">
            <button type="submit" class="btn btn-sm btn-outline-primary">Add</button>
          </form>
        </div>
      {% endfor %}
    </div>
  </div>
{% endif %}
