<div class="card mb-2 transaction-item">
    <div class="card-body p-2 tw-flex tw-items-center tw-gap-3" data-bs-toggle="collapse" data-bs-target="#{{ transaction.id }}" role="button" aria-expanded="false" aria-controls="{{ transaction.id }}">
        <!-- Main visible content -->
        <div class="tw-flex flex-lg-row flex-column lg:tw-items-center tw-w-full tw-gap-3">
            <!-- Type indicator -->
            <div class="tw-w-8">
                {% if transaction.type == 'IN' %}
                    <span class="badge bg-success">↑</span>
                {% else %}
                    <span class="badge bg-danger">↓</span>
                {% endif %}
            </div>

            <!-- Payment status -->
            <div class="tw-w-8">
                {% if transaction.is_paid %}
                    <span class="badge bg-success">✓</span>
                {% else %}
                    <span class="badge bg-warning">○</span>
                {% endif %}
            </div>

            <!-- Description -->
            <div class="tw-flex-grow">
                <span class="tw-font-medium">{{ transaction.description }}</span>
            </div>

            <!-- Amount -->
            <div class="tw-text-right tw-whitespace-nowrap">
                <span class="{% if transaction.type == 'IN' %}tw-text-green-400{% else %}tw-text-red-400{% endif %}">
                    {{ transaction.amount }}
                </span>
                {% if transaction.exchanged_amount %}
                    <br>
                    <small class="text-muted">
                        {{ transaction.exchanged_amount.prefix }}{{ transaction.exchanged_amount.amount }}{{ transaction.exchanged_amount.suffix }}
                    </small>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- Expandable details -->
    <div class="collapse" id="{{ transaction.id }}">
      <div class="card-body p-3 transaction-details">
        <div class="row">
            <div class="col-md-6">
                <dl class="row">
                    <dt class="col-sm-4">Date</dt>
                    <dd class="col-sm-8">{{ transaction.date|date:"Y-m-d" }}</dd>

                    <dt class="col-sm-4">Reference Date</dt>
                    <dd class="col-sm-8">{{ transaction.reference_date|date:"Y-m" }}</dd>

                    <dt class="col-sm-4">Account</dt>
                    <dd class="col-sm-8">{{ transaction.account.name }}</dd>

                    <dt class="col-sm-4">Category</dt>
                    <dd class="col-sm-8">{{ transaction.category|default:"-" }}</dd>
                </dl>
            </div>
            <div class="col-md-6">
                <dl class="row">
                    {% if transaction.tags.exists %}
                        <dt class="col-sm-4">Tags</dt>
                        <dd class="col-sm-8">
                            {% for tag in transaction.tags.all %}
                                <span class="badge bg-secondary">{{ tag.name }}</span>
                            {% endfor %}
                        </dd>
                    {% endif %}

                    {% if transaction.installment_plan %}
                        <dt class="col-sm-4">Installment</dt>
                        <dd class="col-sm-8">
                            {{ transaction.installment_id }} of {{ transaction.installment_plan.total_installments }}
                        </dd>
                    {% endif %}

                    {% if transaction.recurring_transaction %}
                        <dt class="col-sm-4">Recurring</dt>
                        <dd class="col-sm-8">Yes</dd>
                    {% endif %}

                    {% if transaction.notes %}
                        <dt class="col-sm-4">Notes</dt>
                        <dd class="col-sm-8">{{ transaction.notes }}</dd>
                    {% endif %}
                </dl>
            </div>
        </div>
    </div>
    </div>
</div>