{{-- 매니저로 참여 중인 건 --}}
<div class="bg-white rounded-xl shadow-sm overflow-hidden border border-green-200" x-data="{
    openProspectScenarioModal(prospectId, type, readonly = false) {
        let url = type === 'sales'
            ? `/sales/scenarios/prospect/${prospectId}/sales`
            : `/sales/scenarios/prospect/${prospectId}/manager`;
        if (readonly) {
            url += '?readonly=1';
        }
        htmx.ajax('GET', url, {
            target: '#modal-portal',
            swap: 'innerHTML'
        });
    }
}">
    <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
                $itemType = $item['type'] ?? 'prospect';
                $management = $item['management'];
                $registeredBy = $item['registeredBy'];
                $progress = $item['progress'];
                $companyName = $item['company_name'];
                $businessNumber = $item['business_number'];
                $hqStatuses = \App\Models\Sales\SalesTenantManagement::$hqStatusLabels;
                $hqStatusOrder = \App\Models\Sales\SalesTenantManagement::$hqStatusOrder;
                $currentHqStep = $hqStatusOrder[$management->hq_status ?? 'pending'] ?? 0;
                $isHqEnabled = $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">{{ $companyName }}</p>
                            <p class="text-xs text-gray-500">{{ $businessNumber ?? '-' }}</p>
                        </div>
                        @if($itemType === '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>
                    @if($registeredBy)
                        <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>
                    @endif
                </div>

                @if($itemType === 'prospect')
                    {{-- prospect 기반: 시나리오 버튼들 --}}
                    <div class="flex items-center gap-3 mb-3">
                        {{-- 영업 시나리오 (읽기 전용) --}}
                        <button type="button"
                            x-on:click="openProspectScenarioModal({{ $item['prospect']->id }}, 'sales', true)"
                            class="flex-1 flex items-center justify-between gap-2 px-3 py-2 bg-blue-50 border border-blue-200 rounded-lg hover:bg-blue-100 transition-colors">
                            <div class="flex items-center gap-2">
                                <svg class="w-4 h-4 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
                                </svg>
                                <span class="text-sm font-medium text-blue-700">영업 시나리오</span>
                                <span class="text-xs text-blue-500">(참조용)</span>
                            </div>
                            <span class="text-xs font-bold text-blue-600">{{ $progress['sales']['percentage'] }}%</span>
                        </button>

                        {{-- 매니저 시나리오 (체크 가능) --}}
                        <button type="button"
                            x-on:click="openProspectScenarioModal({{ $item['prospect']->id }}, 'manager', false)"
                            class="flex-1 flex items-center justify-between gap-2 px-3 py-2 bg-green-50 border border-green-200 rounded-lg hover:bg-green-100 transition-colors">
                            <div class="flex items-center gap-2">
                                <svg class="w-4 h-4 text-green-600" 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-sm font-medium text-green-700">매니저 시나리오</span>
                            </div>
                            <span class="text-xs font-bold text-green-600">{{ $progress['manager']['percentage'] }}%</span>
                        </button>
                    </div>
                @else
                    {{-- tenant 기반: 계약 완료 상태 표시 --}}
                    <div class="flex items-center gap-2 text-emerald-600 mb-3 p-3 bg-emerald-50 rounded-lg">
                        <svg class="w-5 h-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 class="font-medium">계약 완료 고객 - 매니저로 관리 중</span>
                    </div>
                @endif

                @if($itemType === 'prospect')
                    {{-- 진행률 바 (prospect 기반만) --}}
                    <div class="grid grid-cols-2 gap-4 mb-3">
                        <div class="opacity-60">
                            <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-400 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>
                @endif

                {{-- 개발 진행 상태 (100% 완료 시) --}}
                @if($isHqEnabled)
                    <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($hqStatuses as $statusKey => $statusLabel)
                                    @php
                                        $stepNum = $hqStatusOrder[$statusKey];
                                        $isCompleted = $stepNum < $currentHqStep;
                                        $isCurrent = $stepNum === $currentHqStep;
                                    @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>
