{# Unified single case item used by search results and recent-created lists #}
<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="d-flex w-100 justify-content-between">
      <h6 class="mb-1">{{ case.title }}</h6>
      <small class="text-muted">{{ case.created_date|date:"Y-m-d" }}</small>
    </div>
    <div class="mb-1">
      <small class="text-muted me-2">{% if case.author.all %}By {{ case.author.all|join:", " }}{% endif %}</small>
      {% for cond in case.condition.all %}
        {% if cond.name %}<span class="badge bg-secondary me-1" title="Condition: {{ cond.name }}">{{ cond.name }}</span>{% endif %}
      {% endfor %}
      {% for pres in case.presentation.all %}
        {% if pres.name %}<span class="badge bg-secondary me-1" title="Presentation: {{ pres.name }}">{{ pres.name }}</span>{% endif %}
      {% endfor %}
      {% for ss in case.subspecialty.all %}
        {% if ss.name %}<span class="badge bg-secondary" title="Subspecialty: {{ ss.name }}">{{ ss.name }}</span>{% endif %}
      {% endfor %}
      {% with case.get_series_info as series_info %}
        {% if series_info.in_series %}
          <span class="badge bg-info text-dark ms-1" title="Linked case series position: {{ series_info.position }} of {{ series_info.total }}">
            Series ({{ series_info.position }}/{{ series_info.total }})
          </span>
        {% endif %}
      {% endwith %}
    </div>
    <p class="mb-1 text-truncate">{% if case.description %}{{ case.description|truncatechars:140 }}{% endif %}</p>
  </div>
  <div class="ms-2 d-flex align-items-center">
    {% if collection %}
      <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>
      <a class="btn btn-sm btn-outline-secondary ms-2" href="{% url 'atlas:case_detail' case.pk %}" target="_blank" rel="noopener">View</a>
    {% else %}
      {% if show_select_button %}
        <button type="button" class="btn btn-sm btn-outline-primary case-select-btn" data-case-select="{{ case.pk }}">Select</button>
        <a class="btn btn-sm btn-outline-secondary ms-2" href="{% url 'atlas:case_detail' case.pk %}">View</a>
      {% else %}
        <a class="btn btn-sm btn-outline-secondary" href="{% url 'atlas:case_detail' case.pk %}">View</a>
      {% endif %}
    {% endif %}
  </div>
</div>
