{{-- 상세 모달 내용 --}}
<div class="p-6">
    <!-- 헤더 -->
    <div class="flex items-center justify-between mb-6 pb-4 border-b border-gray-200">
        <div>
            <h2 class="text-xl font-bold text-gray-900">{{ $prospect->company_name }}</h2>
            <p class="text-sm text-gray-500">{{ $prospect->business_number }}</p>
        </div>
        <button type="button" data-close-modal class="text-gray-400 hover:text-gray-600">
            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
            </svg>
        </button>
    </div>

    <!-- 기본 정보 -->
    <div class="grid grid-cols-2 gap-4 mb-6">
        <div>
            <p class="text-sm text-gray-500">대표자</p>
            <p class="font-medium">{{ $prospect->ceo_name ?? '-' }}</p>
        </div>
        <div>
            <p class="text-sm text-gray-500">연락처</p>
            <p class="font-medium">{{ $prospect->contact_phone ?? '-' }}</p>
        </div>
        <div>
            <p class="text-sm text-gray-500">이메일</p>
            <p class="font-medium">{{ $prospect->contact_email ?? '-' }}</p>
        </div>
        <div>
            <p class="text-sm text-gray-500">상태</p>
            <span class="px-2 py-1 text-xs font-medium rounded-full {{ $prospect->status_color }}">
                {{ $prospect->status_label }}
            </span>
        </div>
    </div>

    <!-- 담당자 정보 -->
    <div class="bg-gray-50 rounded-lg p-4 mb-6">
        <h3 class="text-sm font-semibold text-gray-700 mb-3">담당자 정보</h3>
        <div class="grid grid-cols-3 gap-4">
            <div>
                <p class="text-sm text-gray-500">담당 파트너</p>
                <p class="font-medium">{{ $prospect->registeredBy?->name ?? '-' }}</p>
            </div>
            <div>
                <p class="text-sm text-gray-500">담당 매니저</p>
                <p class="font-medium">{{ $management->manager?->name ?? '미지정' }}</p>
            </div>
            <div>
                <p class="text-sm text-gray-500">구분</p>
                @if($partnerType === 'corporate')
                    <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-indigo-100 text-indigo-700">단체</span>
                @else
                    <span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-600">개인</span>
                @endif
            </div>
        </div>
    </div>

    <!-- 진행 현황 -->
    <div class="bg-blue-50 rounded-lg p-4 mb-6">
        <h3 class="text-sm font-semibold text-blue-700 mb-3">영업 진행 현황</h3>
        <div class="space-y-3">
            <div>
                <div class="flex justify-between text-sm mb-1">
                    <span class="text-blue-600">영업 시나리오</span>
                    <span class="font-medium">{{ $progress['sales']['percentage'] }}%</span>
                </div>
                <div class="w-full bg-blue-200 rounded-full h-2">
                    <div class="bg-blue-500 h-2 rounded-full" style="width: {{ $progress['sales']['percentage'] }}%"></div>
                </div>
            </div>
            <div>
                <div class="flex justify-between text-sm mb-1">
                    <span class="text-green-600">매니저 시나리오</span>
                    <span class="font-medium">{{ $progress['manager']['percentage'] }}%</span>
                </div>
                <div class="w-full bg-green-200 rounded-full h-2">
                    <div class="bg-green-500 h-2 rounded-full" style="width: {{ $progress['manager']['percentage'] }}%"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- 개발 진행 상태 -->
    <div class="bg-purple-50 rounded-lg p-4 mb-6">
        <h3 class="text-sm font-semibold text-purple-700 mb-3">개발 진행 상태</h3>
        <div class="flex items-center gap-3">
            <span class="px-3 py-1 text-sm font-medium rounded-full
                @if($management->hq_status === 'handover') bg-emerald-100 text-emerald-700
                @elseif($management->hq_status === 'pending') bg-gray-100 text-gray-600
                @else bg-purple-100 text-purple-700 @endif">
                {{ $management->hq_status_label }}
            </span>
            @if($management->hq_status === 'handover' && $management->handover_at)
                <span class="text-sm text-emerald-600">
                    (인계일: {{ $management->handover_at->format('Y-m-d') }})
                </span>
            @endif
        </div>
    </div>

    <!-- 계약 및 납입 정보 -->
    <div class="bg-emerald-50 rounded-lg p-4 mb-6">
        <div class="flex items-center justify-between mb-3">
            <h3 class="text-sm font-semibold text-emerald-700">계약 및 납입 정보</h3>
            <button type="button"
                onclick="var p=document.getElementById('contractDetailPanel'),i=document.getElementById('contractDetailIcon'),t=document.getElementById('contractDetailBtnText'),h=p.classList.toggle('hidden');i.style.transform=h?'':'rotate(180deg)';t.textContent=h?'정보보기':'접기';"
                class="inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium text-emerald-700 bg-emerald-100 hover:bg-emerald-200 rounded-md transition">
                <svg id="contractDetailIcon" class="w-3.5 h-3.5 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
                </svg>
                <span id="contractDetailBtnText">정보보기</span>
            </button>
        </div>
        @php
            $totalRegFee = $management->total_registration_fee ?? $management->contractProducts->sum('registration_fee') ?? 0;
            $totalSubFee = $management->contractProducts->sum('subscription_fee') ?? 0;
        @endphp
        <div class="grid grid-cols-3 gap-4 mb-3">
            <div>
                <p class="text-sm text-gray-500">계약일</p>
                <p class="font-medium {{ $management->contracted_at ? 'text-blue-600' : 'text-gray-400' }}">
                    {{ $management->contracted_at ? $management->contracted_at->format('Y-m-d') : '-' }}
                </p>
            </div>
            <div>
                <p class="text-sm text-gray-500">총 개발비</p>
                <p class="font-medium {{ $totalRegFee > 0 ? 'text-emerald-700' : 'text-gray-400' }}">
                    {{ $totalRegFee > 0 ? number_format($totalRegFee) . '원' : '-' }}
                </p>
            </div>
            <div>
                <p class="text-sm text-gray-500">구독료 (월)</p>
                <p class="font-medium {{ $totalSubFee > 0 ? 'text-emerald-700' : 'text-gray-400' }}">
                    {{ $totalSubFee > 0 ? number_format($totalSubFee) . '원' : '-' }}
                </p>
            </div>
        </div>
        <div class="grid grid-cols-3 gap-4">
            <div>
                <p class="text-sm text-gray-500">1차 납입</p>
                <p class="font-medium {{ $commission?->first_payment_at ? 'text-emerald-600' : 'text-gray-400' }}">
                    {{ $commission?->first_payment_at ? \Carbon\Carbon::parse($commission->first_payment_at)->format('Y-m-d') : '-' }}
                </p>
            </div>
            <div>
                <p class="text-sm text-gray-500">2차 납입</p>
                <p class="font-medium {{ $commission?->second_payment_at ? 'text-emerald-600' : 'text-gray-400' }}">
                    {{ $commission?->second_payment_at ? \Carbon\Carbon::parse($commission->second_payment_at)->format('Y-m-d') : '-' }}
                </p>
            </div>
        </div>

        {{-- 상세 정보 패널 (기본 숨김) --}}
        <div id="contractDetailPanel" class="hidden mt-4 pt-4 border-t border-emerald-200 space-y-4">
            {{-- 계약 상품 목록 --}}
            <div>
                <h4 class="text-xs font-semibold text-emerald-600 mb-2">계약 상품 내역</h4>
                @if($management->contractProducts->count() > 0)
                    <div class="bg-white rounded-md overflow-hidden">
                        <table class="w-full text-xs">
                            <thead class="bg-emerald-100/50">
                                <tr>
                                    <th class="px-3 py-1.5 text-left text-emerald-700 font-medium">카테고리</th>
                                    <th class="px-3 py-1.5 text-left text-emerald-700 font-medium">상품명</th>
                                    <th class="px-3 py-1.5 text-right text-emerald-700 font-medium">개발비</th>
                                    <th class="px-3 py-1.5 text-right text-emerald-700 font-medium">구독료(월)</th>
                                    <th class="px-3 py-1.5 text-right text-emerald-700 font-medium">할인율</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-emerald-50">
                                @foreach($management->contractProducts as $cp)
                                    <tr>
                                        <td class="px-3 py-1.5 text-gray-600">{{ $cp->category?->name ?? '-' }}</td>
                                        <td class="px-3 py-1.5 text-gray-900 font-medium">{{ $cp->product?->name ?? '-' }}</td>
                                        <td class="px-3 py-1.5 text-right text-gray-700">{{ $cp->registration_fee > 0 ? number_format($cp->registration_fee) . '원' : '-' }}</td>
                                        <td class="px-3 py-1.5 text-right text-gray-700">{{ $cp->subscription_fee > 0 ? number_format($cp->subscription_fee) . '원' : '-' }}</td>
                                        <td class="px-3 py-1.5 text-right text-gray-500">{{ $cp->discount_rate > 0 ? number_format($cp->discount_rate, 0) . '%' : '-' }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                            <tfoot class="bg-emerald-50/50">
                                <tr class="font-medium">
                                    <td colspan="2" class="px-3 py-1.5 text-emerald-700">합계</td>
                                    <td class="px-3 py-1.5 text-right text-emerald-700">{{ number_format($management->contractProducts->sum('registration_fee')) }}원</td>
                                    <td class="px-3 py-1.5 text-right text-emerald-700">{{ number_format($management->contractProducts->sum('subscription_fee')) }}원</td>
                                    <td class="px-3 py-1.5"></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                @else
                    <p class="text-xs text-gray-400 italic">등록된 계약 상품이 없습니다.</p>
                @endif
            </div>

            {{-- 수당 정산 내역 --}}
            <div>
                <h4 class="text-xs font-semibold text-emerald-600 mb-2">수당 정산 내역</h4>
                @if($commissions->count() > 0)
                    <div class="space-y-2">
                        @foreach($commissions as $comm)
                            <div class="bg-white rounded-md p-3">
                                <div class="flex items-center gap-2 mb-2">
                                    <span class="px-1.5 py-0.5 text-xs font-medium rounded
                                        {{ $comm->payment_type === 'deposit' ? 'bg-blue-100 text-blue-700' : 'bg-orange-100 text-orange-700' }}">
                                        {{ $comm->payment_type_label }}
                                    </span>
                                    <span class="px-1.5 py-0.5 text-xs rounded
                                        {{ $comm->status === 'paid' ? 'bg-emerald-100 text-emerald-700' : ($comm->status === 'approved' ? 'bg-blue-100 text-blue-700' : 'bg-gray-100 text-gray-600') }}">
                                        {{ $comm->status_label }}
                                    </span>
                                </div>
                                <div class="grid grid-cols-2 gap-x-4 gap-y-1 text-xs">
                                    <div class="flex justify-between">
                                        <span class="text-gray-500">입금액</span>
                                        <span class="font-medium {{ $comm->payment_amount > 0 ? 'text-gray-900' : 'text-gray-400' }}">
                                            {{ $comm->payment_amount > 0 ? number_format($comm->payment_amount) . '원' : '-' }}
                                        </span>
                                    </div>
                                    <div class="flex justify-between">
                                        <span class="text-gray-500">입금일</span>
                                        <span class="font-medium {{ $comm->payment_date ? 'text-gray-900' : 'text-gray-400' }}">
                                            {{ $comm->payment_date ? $comm->payment_date->format('Y-m-d') : '-' }}
                                        </span>
                                    </div>
                                    <div class="flex justify-between">
                                        <span class="text-gray-500">기준금액</span>
                                        <span class="font-medium {{ $comm->base_amount > 0 ? 'text-gray-900' : 'text-gray-400' }}">
                                            {{ $comm->base_amount > 0 ? number_format($comm->base_amount) . '원' : '-' }}
                                        </span>
                                    </div>
                                    <div class="flex justify-between">
                                        <span class="text-gray-500">지급예정일</span>
                                        <span class="font-medium {{ $comm->scheduled_payment_date ? 'text-gray-900' : 'text-gray-400' }}">
                                            {{ $comm->scheduled_payment_date ? $comm->scheduled_payment_date->format('Y-m-d') : '-' }}
                                        </span>
                                    </div>
                                    <div class="flex justify-between">
                                        <span class="text-gray-500">파트너 수당</span>
                                        <span class="font-medium {{ $comm->partner_commission > 0 ? 'text-emerald-700' : 'text-gray-400' }}">
                                            {{ $comm->partner_commission > 0 ? number_format($comm->partner_commission) . '원' : '-' }}
                                            @if($comm->partner_rate > 0)
                                                <span class="text-gray-400">({{ number_format($comm->partner_rate, 1) }}%)</span>
                                            @endif
                                        </span>
                                    </div>
                                    <div class="flex justify-between">
                                        <span class="text-gray-500">매니저 수당</span>
                                        <span class="font-medium {{ $comm->manager_commission > 0 ? 'text-emerald-700' : 'text-gray-400' }}">
                                            {{ $comm->manager_commission > 0 ? number_format($comm->manager_commission) . '원' : '-' }}
                                            @if($comm->manager_rate > 0)
                                                <span class="text-gray-400">({{ number_format($comm->manager_rate, 1) }}%)</span>
                                            @endif
                                        </span>
                                    </div>
                                    @if($comm->referrer_commission > 0)
                                        <div class="flex justify-between col-span-2">
                                            <span class="text-gray-500">협업지원금</span>
                                            <span class="font-medium text-purple-700">
                                                {{ number_format($comm->referrer_commission) }}원
                                            </span>
                                        </div>
                                    @endif
                                </div>
                                @if($comm->notes)
                                    <p class="mt-2 text-xs text-gray-500 italic">{{ $comm->notes }}</p>
                                @endif
                            </div>
                        @endforeach
                    </div>
                @else
                    <p class="text-xs text-gray-400 italic">등록된 수당 정산 내역이 없습니다.</p>
                @endif
            </div>
        </div>
    </div>


    <!-- 등록 정보 -->
    <div class="text-sm text-gray-500">
        <p>등록일: {{ $prospect->created_at->format('Y-m-d H:i') }}</p>
        @if($prospect->expires_at)
        <p>영업권 만료: {{ $prospect->expires_at->format('Y-m-d') }}</p>
        @endif
    </div>

    <!-- 버튼 -->
    <div class="flex justify-end gap-2 mt-6 pt-4 border-t border-gray-200">
        <button type="button" data-close-modal class="px-4 py-2 text-gray-600 hover:bg-gray-100 rounded-lg transition">
            닫기
        </button>
    </div>
</div>
