{{-- 유치 파트너 활동 현황 --}}
@php
    $first = $summaryStats['first_commission'] ?? ['total' => 0, 'pending' => 0, 'scheduled' => 0, 'paid' => 0];
    $second = $summaryStats['second_commission'] ?? ['total' => 0, 'pending' => 0, 'scheduled' => 0, 'paid' => 0];
    $totalCommissionAmount = $first['total'] + $second['total'];
    $totalPending = $first['pending'] + $second['pending'];
    $totalScheduled = $first['scheduled'] + $second['scheduled'];
    $totalPaid = $first['paid'] + $second['paid'];
    $paidPercent = $totalCommissionAmount > 0 ? round(($totalPaid / $totalCommissionAmount) * 100) : 0;
@endphp
<div class="space-y-6">
    {{-- 요약 카드 섹션 --}}
    <div class="bg-white rounded-xl shadow-sm p-5">
        {{-- 헤더 --}}
        <div class="flex items-center gap-2 mb-4">
            <div class="p-1.5 bg-indigo-100 rounded-lg">
                <svg class="w-5 h-5 text-indigo-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                </svg>
            </div>
            <h2 class="text-lg font-bold text-gray-800">유치 파트너 현황</h2>
        </div>

        {{-- 상단 요약 카드 (5개) --}}
        <div class="grid grid-cols-2 md:grid-cols-5 gap-3 mb-4">
            {{-- 유치 파트너 --}}
            <div class="bg-indigo-50 border border-indigo-200 rounded-lg p-3">
                <div class="flex items-center justify-between">
                    <span class="text-xs text-indigo-600">유치 파트너</span>
                    <svg class="w-4 h-4 text-indigo-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                    </svg>
                </div>
                <p class="text-xl font-bold text-indigo-700 mt-1">{{ $summaryStats['partner_count'] }}<span class="text-sm font-normal">명</span></p>
            </div>

            {{-- 총 영업권 --}}
            <div class="bg-slate-50 border border-slate-200 rounded-lg p-3">
                <div class="flex items-center justify-between">
                    <span class="text-xs text-slate-500">총 영업권</span>
                    <svg class="w-4 h-4 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />
                    </svg>
                </div>
                <p class="text-xl font-bold text-slate-800 mt-1">{{ $summaryStats['total_prospects'] }}<span class="text-sm font-normal">건</span></p>
            </div>

            {{-- 총 계약 --}}
            <div class="bg-green-50 border border-green-200 rounded-lg p-3">
                <div class="flex items-center justify-between">
                    <span class="text-xs text-green-600">총 계약</span>
                    <svg class="w-4 h-4 text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                    </svg>
                </div>
                <p class="text-xl font-bold text-green-700 mt-1">{{ $summaryStats['total_conversions'] }}<span class="text-sm font-normal">건</span></p>
            </div>

            {{-- 예상 수당 --}}
            <div class="bg-emerald-50 border border-emerald-200 rounded-lg p-3">
                <div class="flex items-center justify-between">
                    <span class="text-xs text-emerald-600">예상 수당</span>
                    <svg class="w-4 h-4 text-emerald-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                    </svg>
                </div>
                <p class="text-xl font-bold text-emerald-700 mt-1">{{ number_format($totalCommissionAmount) }}<span class="text-sm font-normal">원</span></p>
            </div>

            {{-- 지급 완료 --}}
            <div class="bg-blue-50 border border-blue-200 rounded-lg p-3">
                <div class="flex items-center justify-between">
                    <span class="text-xs text-blue-600">지급완료</span>
                    <span class="text-xs font-medium text-blue-500">{{ $paidPercent }}%</span>
                </div>
                <p class="text-xl font-bold text-blue-700 mt-1">{{ number_format($totalPaid) }}<span class="text-sm font-normal">원</span></p>
            </div>
        </div>

        {{-- 1차/2차 수당 지급 현황 (합계표) --}}
        <div class="border border-gray-200 rounded-xl overflow-hidden">
            <div class="bg-gray-50 px-4 py-2 border-b border-gray-200">
                <h3 class="text-sm font-semibold text-gray-700 flex items-center gap-2">
                    <svg class="w-4 h-4 text-amber-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4" />
                    </svg>
                    매니저 수당 지급 현황
                    <span class="text-xs text-gray-400 font-normal">(1개월 구독료 기준, 1차/2차 분할)</span>
                </h3>
            </div>

            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr class="bg-gray-50 border-b border-gray-200">
                            <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">구분</th>
                            <th class="px-4 py-2 text-right text-xs font-medium text-gray-500 uppercase">총액</th>
                            <th class="px-4 py-2 text-right text-xs font-medium text-gray-400 uppercase">입금대기</th>
                            <th class="px-4 py-2 text-right text-xs font-medium text-amber-600 uppercase">지급예정</th>
                            <th class="px-4 py-2 text-right text-xs font-medium text-emerald-600 uppercase">지급완료</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-100">
                        {{-- 1차 수당 --}}
                        <tr class="hover:bg-blue-50/50">
                            <td class="px-4 py-2.5">
                                <div class="flex items-center gap-2">
                                    <span class="inline-flex items-center justify-center w-5 h-5 text-xs font-bold text-white bg-blue-500 rounded-full">1</span>
                                    <span class="font-medium text-gray-800">1차 수당</span>
                                </div>
                            </td>
                            <td class="px-4 py-2.5 text-right font-semibold text-blue-700">{{ number_format($first['total']) }}원</td>
                            <td class="px-4 py-2.5 text-right text-gray-500">{{ number_format($first['pending']) }}원</td>
                            <td class="px-4 py-2.5 text-right text-amber-600">{{ number_format($first['scheduled']) }}원</td>
                            <td class="px-4 py-2.5 text-right text-emerald-600">{{ number_format($first['paid']) }}원</td>
                        </tr>
                        {{-- 2차 수당 --}}
                        <tr class="hover:bg-purple-50/50">
                            <td class="px-4 py-2.5">
                                <div class="flex items-center gap-2">
                                    <span class="inline-flex items-center justify-center w-5 h-5 text-xs font-bold text-white bg-purple-500 rounded-full">2</span>
                                    <span class="font-medium text-gray-800">2차 수당</span>
                                </div>
                            </td>
                            <td class="px-4 py-2.5 text-right font-semibold text-purple-700">{{ number_format($second['total']) }}원</td>
                            <td class="px-4 py-2.5 text-right text-gray-500">{{ number_format($second['pending']) }}원</td>
                            <td class="px-4 py-2.5 text-right text-amber-600">{{ number_format($second['scheduled']) }}원</td>
                            <td class="px-4 py-2.5 text-right text-emerald-600">{{ number_format($second['paid']) }}원</td>
                        </tr>
                    </tbody>
                    <tfoot>
                        {{-- 합계 --}}
                        <tr class="bg-gray-100 border-t-2 border-gray-300">
                            <td class="px-4 py-2.5">
                                <span class="font-bold text-gray-800">합계</span>
                            </td>
                            <td class="px-4 py-2.5 text-right font-bold text-gray-900">{{ number_format($totalCommissionAmount) }}원</td>
                            <td class="px-4 py-2.5 text-right font-semibold text-gray-600">{{ number_format($totalPending) }}원</td>
                            <td class="px-4 py-2.5 text-right font-semibold text-amber-700">{{ number_format($totalScheduled) }}원</td>
                            <td class="px-4 py-2.5 text-right font-semibold text-emerald-700">{{ number_format($totalPaid) }}원</td>
                        </tr>
                    </tfoot>
                </table>
            </div>

            {{-- 수당 지급 안내 --}}
            <div class="px-4 py-2 bg-gray-50 border-t border-gray-200 text-[11px] text-gray-500 flex items-center gap-2">
                <svg class="w-3.5 h-3.5 text-gray-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                </svg>
                <span>
                    <span class="text-gray-500">입금대기</span> →
                    개발비 입금 →
                    <span class="text-amber-600 font-medium">지급예정</span> →
                    익월 10일 →
                    <span class="text-emerald-600 font-medium">지급완료</span>
                </span>
            </div>
        </div>
    </div>

    {{-- 내가 매니저로만 참여하는 건 --}}
    @if(isset($managerOnlyProspects) && count($managerOnlyProspects) > 0)
        <div class="bg-white rounded-xl shadow-sm overflow-hidden border border-green-200">
            <div class="p-4 bg-green-50 border-b border-green-200">
                <div class="flex items-center gap-3">
                    <div class="p-2 bg-green-100 rounded-lg">
                        <svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
                        </svg>
                    </div>
                    <div>
                        <h3 class="font-bold text-green-800">매니저로 참여 중인 건</h3>
                        <p class="text-xs text-green-600">다른 영업파트너가 등록하고 내가 매니저로 지정된 고객</p>
                    </div>
                    <span class="ml-auto px-3 py-1 bg-green-100 text-green-700 text-sm font-medium rounded-full">
                        {{ count($managerOnlyProspects) }}건
                    </span>
                </div>
            </div>
            <div class="divide-y divide-gray-100">
                @foreach($managerOnlyProspects as $item)
                    @php
                        $prospect = $item['prospect'] ?? null;
                        $tenant = $item['tenant'] ?? null;
                        $management = $item['management'];
                        $registeredBy = $item['registeredBy'];
                        $progress = $item['progress'];
                        $prospectHqStatuses = \App\Models\Sales\SalesTenantManagement::$hqStatusLabels;
                        $prospectHqStatusOrder = \App\Models\Sales\SalesTenantManagement::$hqStatusOrder;
                        $prospectCurrentHqStep = $prospectHqStatusOrder[$management->hq_status ?? 'pending'] ?? 0;
                        $isProspectHqEnabled = $progress['sales']['percentage'] >= 100 && $progress['manager']['percentage'] >= 100;
                    @endphp
                    <div class="p-4 hover:bg-gray-50 transition-colors">
                        <div class="flex items-center justify-between mb-3">
                            <div class="flex items-center gap-3">
                                <div>
                                    <p class="font-bold text-gray-900">{{ $item['company_name'] }}</p>
                                    <p class="text-xs text-gray-500">{{ $item['business_number'] ?? '-' }}</p>
                                </div>
                                <span class="px-2 py-0.5 text-xs font-medium rounded-full bg-green-100 text-green-700">
                                    매니저만 진행
                                </span>
                            </div>
                            <div class="text-right">
                                <p class="text-xs text-gray-400">등록자</p>
                                <p class="text-sm font-medium text-gray-700">{{ $registeredBy?->name ?? '-' }}</p>
                            </div>
                        </div>
                        {{-- 매니저 진행률만 표시 --}}
                        <div class="grid grid-cols-2 gap-4 mb-3">
                            <div class="opacity-50">
                                <div class="flex items-center gap-2 mb-1">
                                    <span class="text-xs font-medium text-blue-600">영업</span>
                                    <span class="text-xs text-gray-400">({{ $progress['sales']['percentage'] }}%)</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2">
                                    <div class="bg-blue-300 h-2 rounded-full" style="width: {{ $progress['sales']['percentage'] }}%"></div>
                                </div>
                            </div>
                            <div>
                                <div class="flex items-center gap-2 mb-1">
                                    <span class="text-xs font-medium text-green-600">매니저</span>
                                    <span class="text-xs text-gray-500">{{ $progress['manager']['percentage'] }}%</span>
                                </div>
                                <div class="w-full bg-gray-200 rounded-full h-2">
                                    <div class="bg-green-500 h-2 rounded-full transition-all" style="width: {{ $progress['manager']['percentage'] }}%"></div>
                                </div>
                            </div>
                        </div>
                        {{-- 개발 진행 상태 (100% 완료 시) --}}
                        @if($isProspectHqEnabled)
                            <div class="pt-2 border-t border-gray-100">
                                <div class="flex items-center gap-2">
                                    <span class="text-xs font-medium text-purple-600">개발</span>
                                    <div class="flex-1 flex items-center gap-0.5">
                                        @foreach($prospectHqStatuses as $statusKey => $statusLabel)
                                            @php
                                                $stepNum = $prospectHqStatusOrder[$statusKey];
                                                $isCompleted = $stepNum < $prospectCurrentHqStep;
                                                $isCurrent = $stepNum === $prospectCurrentHqStep;
                                            @endphp
                                            <div class="flex-1 h-1.5 rounded-full {{ $isCompleted ? 'bg-purple-500' : ($isCurrent ? 'bg-purple-300' : 'bg-gray-200') }}"></div>
                                        @endforeach
                                    </div>
                                    <span class="text-xs px-2 py-0.5 rounded-full bg-purple-100 text-purple-700">{{ $management->hq_status_label }}</span>
                                </div>
                            </div>
                        @endif
                        {{-- 계약 금액 정보 --}}
                        @if($item['total_subscription_fee'] > 0)
                            <div class="mt-3 pt-3 border-t border-gray-100 flex items-center justify-between">
                                <div class="text-xs text-gray-500">예상 매니저 수당 (1개월 구독료)</div>
                                <div class="text-sm font-bold text-green-600">₩{{ number_format($item['total_subscription_fee']) }}</div>
                            </div>
                        @endif
                    </div>
                @endforeach
            </div>
        </div>
    @endif

    {{-- 파트너별 영업 현황 --}}
    @if(count($partnerActivities) === 0)
        <div class="bg-white rounded-xl shadow-sm">
            <div class="text-center py-16">
                <div class="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <svg class="w-8 h-8 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                    </svg>
                </div>
                <p class="text-gray-600 font-medium mb-1">유치한 파트너가 없습니다</p>
                <p class="text-sm text-gray-400">파트너를 유치하면 이곳에서 활동 현황을 확인할 수 있습니다</p>
            </div>
        </div>
    @else
        @foreach($partnerActivities as $activity)
            @php
                $statusColors = [
                    'active' => 'bg-green-100 text-green-800 border-green-200',
                    'moderate' => 'bg-yellow-100 text-yellow-800 border-yellow-200',
                    'inactive' => 'bg-gray-100 text-gray-600 border-gray-200',
                ];
                $statusLabels = [
                    'active' => '활동중',
                    'moderate' => '보통',
                    'inactive' => '비활동',
                ];
                $borderColors = [
                    'active' => 'border-green-300',
                    'moderate' => 'border-yellow-300',
                    'inactive' => 'border-gray-200',
                ];
            @endphp
            <div class="bg-white rounded-xl shadow-sm overflow-hidden border {{ $borderColors[$activity['status']] ?? 'border-gray-200' }}"
                 x-data="{ expanded: false }">
                {{-- 파트너 헤더 --}}
                <div class="p-4 cursor-pointer hover:bg-gray-50 transition-colors" @click="expanded = !expanded">
                    <div class="flex items-center justify-between">
                        <div class="flex items-center gap-4">
                            {{-- 펼침 아이콘 --}}
                            <button type="button" class="p-1 text-gray-400 hover:text-gray-600 transition-transform"
                                :class="{ 'rotate-90': expanded }">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
                                </svg>
                            </button>
                            {{-- 파트너 정보 --}}
                            <div class="flex items-center gap-3">
                                <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center">
                                    <span class="text-indigo-600 font-bold text-sm">{{ mb_substr($activity['partner']->name, 0, 1) }}</span>
                                </div>
                                <div>
                                    <p class="font-bold text-gray-900">{{ $activity['partner']->name }}</p>
                                    <p class="text-xs text-gray-500">{{ $activity['partner']->email }}</p>
                                </div>
                            </div>
                            {{-- 역할 배지 --}}
                            <span class="px-2.5 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
                                {{ $activity['role_label'] }}
                            </span>
                            {{-- 유형 배지 --}}
                            @if($activity['partner']->salesPartner)
                                @if($activity['partner']->salesPartner->partner_type === 'corporate')
                                    <span class="px-2.5 py-1 rounded-full text-xs font-medium bg-amber-100 text-amber-800">단체</span>
                                @else
                                    <span class="px-2.5 py-1 rounded-full text-xs font-medium bg-sky-100 text-sky-800">개인</span>
                                @endif
                            @endif
                            {{-- 상태 배지 --}}
                            <span class="px-2.5 py-1 rounded-full text-xs font-medium {{ $statusColors[$activity['status']] ?? $statusColors['inactive'] }}">
                                {{ $statusLabels[$activity['status']] ?? '비활동' }}
                            </span>
                        </div>
                        {{-- 요약 통계 --}}
                        <div class="flex items-center gap-6 text-sm">
                            <div class="text-center">
                                <p class="text-gray-400 text-xs">영업권</p>
                                <p class="font-bold text-gray-900">{{ $activity['prospect_count'] }}</p>
                            </div>
                            @if(isset($activity['manager_prospects']) && count($activity['manager_prospects']) > 0)
                            <div class="text-center">
                                <p class="text-gray-400 text-xs">매니저</p>
                                <p class="font-bold text-green-600">{{ count($activity['manager_prospects']) }}</p>
                            </div>
                            @endif
                            <div class="text-center">
                                <p class="text-gray-400 text-xs">진행중</p>
                                <p class="font-bold text-blue-600">{{ $activity['active_prospects'] }}</p>
                            </div>
                            <div class="text-center">
                                <p class="text-gray-400 text-xs">인계완료</p>
                                <p class="font-bold text-green-600">{{ $activity['conversions'] }}</p>
                            </div>
                            <div class="text-center">
                                <p class="text-gray-400 text-xs">예상수당</p>
                                @if($activity['has_registration_fee'])
                                    <p class="font-bold text-amber-600">₩{{ number_format($activity['manager_commission']) }}</p>
                                @else
                                    <p class="font-medium text-gray-400 text-xs">계약전</p>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>

                {{-- 가망고객 목록 (펼침 영역) --}}
                <div x-show="expanded" x-collapse x-cloak class="border-t border-gray-100">
                    @php
                        $hasManagerProspects = isset($activity['manager_prospects']) && count($activity['manager_prospects']) > 0;
                    @endphp
                    @if($activity['all_prospects']->isEmpty() && $activity['recent_tenants']->isEmpty() && !$hasManagerProspects)
                        <div class="p-8 text-center text-gray-500">
                            <svg class="w-12 h-12 mx-auto text-gray-300 mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
                            </svg>
                            <p class="text-sm">등록된 영업권이 없습니다</p>
                        </div>
                    @else
                        <div class="divide-y divide-gray-100">
                            {{-- 매니저로 진행 중인 건 (다른 사람이 등록, 이 파트너가 매니저) --}}
                            @if($hasManagerProspects)
                                <div class="p-4 bg-green-50/50">
                                    <div class="flex items-center gap-2 mb-3">
                                        <span class="text-sm font-semibold text-green-600">매니저로 진행 중</span>
                                        <span class="px-2 py-0.5 bg-green-100 text-green-700 text-xs font-medium rounded-full">{{ count($activity['manager_prospects']) }}건</span>
                                    </div>
                                    <div class="space-y-2">
                                        @foreach($activity['manager_prospects'] as $item)
                                            @php
                                                $mManagement = $item['management'];
                                                $mRegisteredBy = $item['registeredBy'];
                                                $mCompanyName = $item['company_name'];
                                                $mBusinessNumber = $item['business_number'];
                                                $mType = $item['type'] ?? 'prospect';
                                                $mHqStatuses = \App\Models\Sales\SalesTenantManagement::$hqStatusLabels;
                                                $mHqStatusOrder = \App\Models\Sales\SalesTenantManagement::$hqStatusOrder;
                                                $mCurrentHqStep = $mHqStatusOrder[$mManagement->hq_status ?? 'pending'] ?? 0;

                                                // prospect 기반인 경우 진행률 조회
                                                $mProgress = null;
                                                $isMHqEnabled = false;
                                                if ($mType === 'prospect' && isset($item['prospect'])) {
                                                    $mProgress = \App\Models\Sales\SalesScenarioChecklist::getProspectProgress($item['prospect']->id);
                                                    $isMHqEnabled = $mProgress['sales']['percentage'] >= 100 && $mProgress['manager']['percentage'] >= 100;
                                                } elseif ($mType === 'tenant') {
                                                    // tenant 기반은 이미 계약 완료
                                                    $isMHqEnabled = true;
                                                }
                                            @endphp
                                            <div class="bg-white rounded-lg p-3 border border-green-200">
                                                <div class="flex items-center justify-between mb-2">
                                                    <div>
                                                        <p class="font-medium text-gray-900 text-sm">{{ $mCompanyName }}</p>
                                                        <p class="text-xs text-gray-500">{{ $mBusinessNumber ?? '-' }}</p>
                                                    </div>
                                                    <div class="flex items-center gap-2">
                                                        @if($mType === 'tenant')
                                                            <span class="px-2 py-0.5 text-xs font-medium rounded-full bg-emerald-100 text-emerald-700">
                                                                계약 고객
                                                            </span>
                                                        @else
                                                            <span class="px-2 py-0.5 text-xs font-medium rounded-full bg-green-100 text-green-700">
                                                                매니저만 진행
                                                            </span>
                                                        @endif
                                                    </div>
                                                </div>
                                                @if($mRegisteredBy)
                                                    {{-- 등록자 정보 (prospect 기반인 경우) --}}
                                                    <div class="flex items-center gap-2 text-xs text-gray-500 mb-2">
                                                        <span>등록자:</span>
                                                        <span class="font-medium text-gray-700">{{ $mRegisteredBy->name }}</span>
                                                    </div>
                                                @endif
                                                @if($mType === 'prospect' && $mProgress)
                                                    {{-- 영업/매니저 진행률 (prospect 기반) --}}
                                                    <div class="grid grid-cols-2 gap-4">
                                                        <div class="opacity-50">
                                                            <div class="flex items-center gap-2 mb-1">
                                                                <span class="text-xs font-medium text-blue-600">영업</span>
                                                                <span class="text-xs text-gray-400">({{ $mProgress['sales']['percentage'] }}%)</span>
                                                            </div>
                                                            <div class="w-full bg-gray-200 rounded-full h-2">
                                                                <div class="bg-blue-300 h-2 rounded-full" style="width: {{ $mProgress['sales']['percentage'] }}%"></div>
                                                            </div>
                                                        </div>
                                                        <div>
                                                            <div class="flex items-center gap-2 mb-1">
                                                                <span class="text-xs font-medium text-green-600">매니저</span>
                                                                <span class="text-xs text-gray-500">{{ $mProgress['manager']['percentage'] }}%</span>
                                                            </div>
                                                            <div class="w-full bg-gray-200 rounded-full h-2">
                                                                <div class="bg-green-500 h-2 rounded-full transition-all" style="width: {{ $mProgress['manager']['percentage'] }}%"></div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                @elseif($mType === 'tenant')
                                                    {{-- 계약 고객 상태 표시 --}}
                                                    <div class="flex items-center gap-2 text-xs text-emerald-600 mb-2">
                                                        <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
                                                            <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
                                                        </svg>
                                                        <span class="font-medium">계약 완료 고객</span>
                                                    </div>
                                                @endif
                                                {{-- 개발 진행 상태 --}}
                                                @if($isMHqEnabled)
                                                    <div class="mt-2 pt-2 border-t border-gray-100">
                                                        <div class="flex items-center gap-2">
                                                            <span class="text-xs font-medium text-purple-600">개발</span>
                                                            <div class="flex-1 flex items-center gap-0.5">
                                                                @foreach($mHqStatuses as $statusKey => $statusLabel)
                                                                    @php
                                                                        $stepNum = $mHqStatusOrder[$statusKey];
                                                                        $isCompleted = $stepNum < $mCurrentHqStep;
                                                                        $isCurrent = $stepNum === $mCurrentHqStep;
                                                                    @endphp
                                                                    <div class="flex-1 h-1.5 rounded-full {{ $isCompleted ? 'bg-purple-500' : ($isCurrent ? 'bg-purple-300' : 'bg-gray-200') }}"></div>
                                                                @endforeach
                                                            </div>
                                                            <span class="text-xs px-2 py-0.5 rounded-full bg-purple-100 text-purple-700">{{ $mManagement->hq_status_label }}</span>
                                                        </div>
                                                    </div>
                                                @endif
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                            @endif

                            {{-- 진행 중인 가망고객 --}}
                            @if($activity['all_prospects']->isNotEmpty())
                                <div class="p-4 bg-orange-50/50">
                                    <div class="flex items-center gap-2 mb-3">
                                        <span class="text-sm font-semibold text-orange-600">영업 진행중</span>
                                        <span class="px-2 py-0.5 bg-orange-100 text-orange-700 text-xs font-medium rounded-full">{{ $activity['all_prospects']->count() }}건</span>
                                    </div>
                                    <div class="space-y-2">
                                        @foreach($activity['all_prospects'] as $prospect)
                                            @php
                                                $prospectProgress = \App\Models\Sales\SalesScenarioChecklist::getProspectProgress($prospect->id);
                                                $prospectManagement = \App\Models\Sales\SalesTenantManagement::findOrCreateByProspect($prospect->id);
                                                $prospectHqStatuses = \App\Models\Sales\SalesTenantManagement::$hqStatusLabels;
                                                $prospectHqStatusOrder = \App\Models\Sales\SalesTenantManagement::$hqStatusOrder;
                                                $prospectCurrentHqStep = $prospectHqStatusOrder[$prospectManagement->hq_status ?? 'pending'] ?? 0;
                                                $isProspectHqEnabled = $prospectProgress['sales']['percentage'] >= 100 && $prospectProgress['manager']['percentage'] >= 100;
                                            @endphp
                                            <div class="bg-white rounded-lg p-3 border border-orange-200">
                                                <div class="flex items-center justify-between mb-2">
                                                    <div>
                                                        <p class="font-medium text-gray-900 text-sm">{{ $prospect->company_name }}</p>
                                                        <p class="text-xs text-gray-500">{{ $prospect->business_number ?? '-' }}</p>
                                                    </div>
                                                    @if($prospect->isActive())
                                                        <span class="text-xs text-orange-600 font-medium">D-{{ $prospect->remaining_days }}</span>
                                                    @endif
                                                </div>
                                                {{-- 영업/매니저 진행률 --}}
                                                <div class="grid grid-cols-2 gap-4">
                                                    <div>
                                                        <div class="flex items-center gap-2 mb-1">
                                                            <span class="text-xs font-medium text-blue-600">영업</span>
                                                            <span class="text-xs text-gray-500">{{ $prospectProgress['sales']['percentage'] }}%</span>
                                                        </div>
                                                        <div class="w-full bg-gray-200 rounded-full h-2">
                                                            <div class="bg-blue-500 h-2 rounded-full transition-all" style="width: {{ $prospectProgress['sales']['percentage'] }}%"></div>
                                                        </div>
                                                    </div>
                                                    <div>
                                                        <div class="flex items-center gap-2 mb-1">
                                                            <span class="text-xs font-medium text-green-600">매니저</span>
                                                            <span class="text-xs text-gray-500">{{ $prospectProgress['manager']['percentage'] }}%</span>
                                                        </div>
                                                        <div class="w-full bg-gray-200 rounded-full h-2">
                                                            <div class="bg-green-500 h-2 rounded-full transition-all" style="width: {{ $prospectProgress['manager']['percentage'] }}%"></div>
                                                        </div>
                                                    </div>
                                                </div>
                                                {{-- 개발 진행 상태 (100% 완료 시) --}}
                                                @if($isProspectHqEnabled)
                                                    <div class="mt-2 pt-2 border-t border-gray-100">
                                                        <div class="flex items-center gap-2">
                                                            <span class="text-xs font-medium text-purple-600">개발</span>
                                                            <div class="flex-1 flex items-center gap-0.5">
                                                                @foreach($prospectHqStatuses as $statusKey => $statusLabel)
                                                                    @php
                                                                        $stepNum = $prospectHqStatusOrder[$statusKey];
                                                                        $isCompleted = $stepNum < $prospectCurrentHqStep;
                                                                        $isCurrent = $stepNum === $prospectCurrentHqStep;
                                                                    @endphp
                                                                    <div class="flex-1 h-1.5 rounded-full {{ $isCompleted ? 'bg-purple-500' : ($isCurrent ? 'bg-purple-300' : 'bg-gray-200') }}"></div>
                                                                @endforeach
                                                            </div>
                                                            <span class="text-xs px-2 py-0.5 rounded-full bg-purple-100 text-purple-700">{{ $prospectManagement->hq_status_label }}</span>
                                                        </div>
                                                    </div>
                                                @endif
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                            @endif

                            {{-- 인계 완료 (계약 성사) --}}
                            @if($activity['recent_tenants']->isNotEmpty())
                                <div class="p-4 bg-emerald-50/50">
                                    <div class="flex items-center gap-2 mb-3">
                                        <span class="text-sm font-semibold text-emerald-600">인계 완료</span>
                                        <span class="px-2 py-0.5 bg-emerald-100 text-emerald-700 text-xs font-medium rounded-full">{{ $activity['conversions'] }}건</span>
                                    </div>
                                    <div class="space-y-2">
                                        @foreach($activity['recent_tenants'] as $prospect)
                                            <div class="bg-white rounded-lg p-3 border border-emerald-200">
                                                <div class="flex items-center justify-between">
                                                    <div>
                                                        <p class="font-medium text-gray-900 text-sm">{{ $prospect->company_name }}</p>
                                                        <p class="text-xs text-gray-500">{{ $prospect->business_number ?? '-' }}</p>
                                                    </div>
                                                    <div class="flex items-center gap-3">
                                                        <span class="text-xs text-gray-500">{{ $prospect->converted_at?->format('Y-m-d') ?? '-' }}</span>
                                                        <span class="px-2 py-0.5 rounded-full text-xs font-medium bg-emerald-100 text-emerald-700">
                                                            <svg class="w-3 h-3 inline mr-0.5" fill="currentColor" viewBox="0 0 20 20">
                                                                <path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" />
                                                            </svg>
                                                            완료
                                                        </span>
                                                    </div>
                                                </div>
                                                {{-- 완료 프로그레스 바 --}}
                                                <div class="grid grid-cols-2 gap-4 mt-2">
                                                    <div>
                                                        <div class="flex items-center gap-2 mb-1">
                                                            <span class="text-xs font-medium text-blue-600">영업</span>
                                                            <span class="text-xs text-gray-500">100%</span>
                                                        </div>
                                                        <div class="w-full bg-blue-500 rounded-full h-2"></div>
                                                    </div>
                                                    <div>
                                                        <div class="flex items-center gap-2 mb-1">
                                                            <span class="text-xs font-medium text-green-600">매니저</span>
                                                            <span class="text-xs text-gray-500">100%</span>
                                                        </div>
                                                        <div class="w-full bg-green-500 rounded-full h-2"></div>
                                                    </div>
                                                </div>
                                            </div>
                                        @endforeach
                                    </div>
                                </div>
                            @endif
                        </div>
                    @endif
                </div>
            </div>
        @endforeach
    @endif
</div>
