@if(!empty($account['fcuIndicatorTransactions']))
    @php
        $fcuData = $account['fcuIndicatorTransactions'];
        $sectionTitles = [
            'fraudIndicators' => 'Fraud Indicators',
            'behaviouralIndicators' => 'Behavioural Indicators',
            'riskIndicators' => 'Risk Indicators'
        ];
    @endphp

    @foreach($sectionTitles as $sectionKey => $sectionTitle)
        @if(isset($fcuData[$sectionKey]) && !empty($fcuData[$sectionKey]))
            <h5 class="mt-4 border-bottom pb-2"><strong class="text-secondary">{{ $sectionTitle }}</strong></h5>
            <div class="panel-group" id="accordion-{{ $accountId }}-{{ $sectionKey }}">
                @foreach($fcuData[$sectionKey] as $indicatorKey => $indicator)
                    @if(isset($indicator['transactions']) && count($indicator['transactions']) > 0)
                        <div class="card mt-2">
                            <div class="card-header p-2" style="cursor: pointer;" data-toggle="collapse" data-parent="#accordion-{{ $accountId }}-{{ $sectionKey }}" href="#collapse-{{ $accountId }}-{{ $sectionKey }}-{{ $loop->index }}">
                                <h6 class="panel-title mb-0">
                                    {{ ucwords(preg_replace('/([a-z])([A-Z])/', '$1 $2', str_replace('_', ' ', $indicatorKey))) }}
                                    <span class="badge badge-info float-right">{{ count($indicator['transactions']) }}</span>
                                </h6>
                            </div>
                            <div id="collapse-{{ $accountId }}-{{ $sectionKey }}-{{ $loop->index }}" class="panel-collapse collapse">
                                <div class="card-body" style="max-height: 400px; overflow-y: auto; padding: 10px;">
                                    <table class="table table-bordered table-hover table-sm">
                                        <thead class="thead-light">
                                            <tr>
                                                @foreach(array_keys($indicator['transactions'][0]) as $header)
                                                    <th>{{ ucwords(str_replace('_', ' ', $header)) }}</th>
                                                @endforeach
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach($indicator['transactions'] as $txn)
                                                <tr>
                                                    @foreach($txn as $value)
                                                        <td>{{ $value }}</td>
                                                    @endforeach
                                                </tr>
                                            @endforeach
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    @endif
                @endforeach
            </div>
        @endif
    @endforeach
@else
     <p class="text-muted">No risk events found for this account.</p>
@endif