@forelse($servicesByCategory as $categoryId => $serviceCards)
  @php
    $categoryName = $serviceCards->first()['category_name'] ?? 'More';
    $categoryFilterId = (int) $categoryId;
    $viewAllParams = $categoryFilterId > 0 ? ['category_id' => $categoryFilterId] : ['q' => $categoryName];
  @endphp

  <div class="d-flex justify-content-between align-items-center category-head">
    <h4 class="category-title">{{ $categoryName }}</h4>
    <a href="{{ route('subscriptions.index', $viewAllParams) }}" class="category-view-all">View all &gt;&gt;</a>
  </div>

  <div class="row g-3 mb-4">
    @foreach($serviceCards as $card)
      <div class="col-lg-4 col-md-4 col-sm-6">
        <a href="{{ route('subscriptions.show', $card['target_subscription_id']) }}" class="market-card">
          @if($card['has_incentive_badge'])
            {{-- <span class="incentive-badge">Share for incentive</span> --}}
          @endif

          <div class="d-flex align-items-start">
            <div class="service-logo">
              <span class="service-logo-fallback">{{ strtoupper(substr($card['service_name'], 0, 3)) }}</span>
              @if(!empty($card['logo']))
                <img src="{{ asset($card['logo']) }}" alt="{{ $card['service_name'] }}" onerror="this.remove()">
              @endif
            </div>

            <div class="profile-stack">
              @foreach($card['profiles'] as $profile)
                <span class="profile-dot" title="{{ $profile['name'] }}">{{ $profile['initials'] }}</span>
              @endforeach
              @if($card['extra_profiles'] > 0)
                <span class="profile-more">+{{ $card['extra_profiles'] }}</span>
              @endif
            </div>
          </div>

          <div class="mt-3 fw-semibold">{{ $card['service_name'] }}</div>
          <p class="minimum-text">Minimum per month</p>
          <div class="minimum-price">{{ number_format($card['min_price'], 2) }} &euro;</div>
        </a>
      </div>
    @endforeach
  </div>
@empty
  <div class="card">
    <div class="card-body py-5 text-center">
      No subscriptions found.
    </div>
  </div>
@endforelse
