{{-- 상세 정보 모달 --}}
@php
    $tenant = $management->tenant;
    $prospect = $management->tenantProspect;

    // 테넌트 또는 가망고객에서 정보 가져오기
    $companyName = $tenant?->company_name ?? $prospect?->company_name ?? '알 수 없음';
    $businessNumber = $tenant?->business_number ?? $prospect?->business_number ?? '-';
    $representativeName = $tenant?->representative_name ?? $prospect?->ceo_name ?? '-';
    $phone = $tenant?->phone ?? $prospect?->contact_phone ?? '-';
    $address = $tenant?->address ?? $prospect?->address ?? '-';

    $currentHqStep = $hqStatusOrder[$management->hq_status ?? 'pending'] ?? 0;
@endphp

<div class="p-6">
    {{-- 헤더 --}}
    <div class="flex justify-between items-start mb-6">
        <div>
            <h3 class="text-xl font-bold text-gray-900">{{ $companyName }}</h3>
            <p class="text-sm text-gray-500 mt-1">{{ $businessNumber }}</p>
        </div>
        <button type="button" onclick="closeDetailModal()"
                class="text-gray-400 hover:text-gray-600 transition">
            <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="mb-6">
        <h4 class="text-sm font-semibold text-gray-700 mb-3">개발 진행 상태</h4>
        <div class="bg-gray-50 rounded-lg p-4">
            {{-- 8단계 프로그레스 바 --}}
            <div class="mb-4">
                <div class="flex items-center gap-1">
                    @foreach($hqStatuses as $statusKey => $statusLabel)
                        @php
                            $stepNum = $hqStatusOrder[$statusKey];
                            $isCompleted = $stepNum < $currentHqStep;
                            $isCurrent = $stepNum === $currentHqStep;
                        @endphp
                        <div class="group relative flex-1">
                            <div class="h-3 rounded-full transition-all {{ $isCompleted ? 'bg-purple-500' : ($isCurrent ? 'bg-purple-300' : 'bg-gray-200') }}"></div>
                            <div class="absolute bottom-full left-1/2 -translate-x-1/2 mb-1 px-2 py-1 bg-gray-800 text-white text-xs rounded opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap z-10 pointer-events-none">
                                {{ $statusLabel }}
                            </div>
                        </div>
                    @endforeach
                </div>
                <div class="flex justify-between mt-1 text-xs text-gray-500">
                    <span>대기</span>
                    <span>인계</span>
                </div>
            </div>
            <div class="text-center">
                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium
                    @if($management->hq_status === 'handover') bg-emerald-100 text-emerald-800
                    @elseif($management->hq_status === 'pending') bg-yellow-100 text-yellow-800
                    @else bg-purple-100 text-purple-800 @endif">
                    {{ $management->hq_status_label }}
                </span>
            </div>
        </div>
    </div>

    {{-- 진행률 정보 --}}
    <div class="grid grid-cols-2 gap-4 mb-6">
        <div class="bg-blue-50 rounded-lg p-4">
            <div class="text-xs text-blue-600 mb-1">영업 진행률</div>
            <div class="flex items-center gap-2">
                <div class="flex-1 bg-blue-200 rounded-full h-2">
                    <div class="bg-blue-500 h-2 rounded-full" style="width: {{ $management->sales_progress }}%"></div>
                </div>
                <span class="text-sm font-bold text-blue-700">{{ $management->sales_progress }}%</span>
            </div>
            <div class="text-xs text-blue-600 mt-2">
                담당: {{ $management->salesPartner?->user?->name ?? '-' }}
            </div>
        </div>
        <div class="bg-green-50 rounded-lg p-4">
            <div class="text-xs text-green-600 mb-1">매니저 진행률</div>
            <div class="flex items-center gap-2">
                <div class="flex-1 bg-green-200 rounded-full h-2">
                    <div class="bg-green-500 h-2 rounded-full" style="width: {{ $management->manager_progress }}%"></div>
                </div>
                <span class="text-sm font-bold text-green-700">{{ $management->manager_progress }}%</span>
            </div>
            <div class="text-xs text-green-600 mt-2">
                담당: {{ $management->manager?->name ?? '-' }}
            </div>
        </div>
    </div>

    {{-- 고객 정보 --}}
    <div class="mb-6">
        <h4 class="text-sm font-semibold text-gray-700 mb-3">고객 정보</h4>
        <div class="bg-gray-50 rounded-lg p-4">
            <dl class="grid grid-cols-2 gap-3 text-sm">
                <div>
                    <dt class="text-gray-500">업체명</dt>
                    <dd class="font-medium text-gray-900">{{ $companyName }}</dd>
                </div>
                <div>
                    <dt class="text-gray-500">사업자번호</dt>
                    <dd class="font-medium text-gray-900">{{ $businessNumber }}</dd>
                </div>
                <div>
                    <dt class="text-gray-500">대표자</dt>
                    <dd class="font-medium text-gray-900">{{ $representativeName }}</dd>
                </div>
                <div>
                    <dt class="text-gray-500">연락처</dt>
                    <dd class="font-medium text-gray-900">{{ $phone }}</dd>
                </div>
                <div class="col-span-2">
                    <dt class="text-gray-500">주소</dt>
                    <dd class="font-medium text-gray-900">{{ $address }}</dd>
                </div>
            </dl>
        </div>
    </div>

    {{-- 계약 상품 정보 --}}
    @if($management->contractProducts->count() > 0)
    <div class="mb-6">
        <h4 class="text-sm font-semibold text-gray-700 mb-3">계약 상품</h4>
        <div class="bg-gray-50 rounded-lg overflow-hidden">
            <table class="min-w-full divide-y divide-gray-200">
                <thead class="bg-gray-100">
                    <tr>
                        <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-500 uppercase">월 구독료</th>
                    </tr>
                </thead>
                <tbody class="bg-white divide-y divide-gray-200">
                    @foreach($management->contractProducts as $cp)
                    <tr>
                        <td class="px-4 py-2 text-sm text-gray-900">{{ $cp->product?->name ?? '-' }}</td>
                        <td class="px-4 py-2 text-sm text-gray-900 text-right">{{ number_format($cp->registration_fee ?? 0) }}원</td>
                        <td class="px-4 py-2 text-sm text-gray-900 text-right">{{ number_format($cp->subscription_fee ?? 0) }}원</td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
    @endif

    {{-- 메모 --}}
    @if($management->notes)
    <div class="mb-6">
        <h4 class="text-sm font-semibold text-gray-700 mb-3">메모</h4>
        <div class="bg-gray-50 rounded-lg p-4">
            <p class="text-sm text-gray-700 whitespace-pre-line">{{ $management->notes }}</p>
        </div>
    </div>
    @endif

    {{-- 닫기 버튼 --}}
    <div class="flex justify-end">
        <button type="button" onclick="closeDetailModal()"
                class="px-4 py-2 bg-gray-600 hover:bg-gray-700 text-white rounded-lg transition">
            닫기
        </button>
    </div>
</div>
