<!-- 회원사 등록/수정 모달 -->
<div id="memberModal" class="hidden fixed inset-0 z-50 overflow-y-auto">
    <div class="flex items-center justify-center min-h-screen px-4 pt-4 pb-20 text-center sm:p-0">
        <!-- 배경 오버레이 (클릭해도 닫히지 않음) -->
        <div class="fixed inset-0 bg-black/40 backdrop-blur-sm transition-opacity"></div>

        <!-- 모달 컨텐츠 -->
        <div class="relative inline-block w-full max-w-2xl bg-white rounded-2xl text-left overflow-hidden shadow-xl transform transition-all sm:my-8">
            <!-- 헤더 -->
            <div class="px-6 py-4 border-b border-gray-100 flex justify-between items-center bg-gray-50/50">
                <h3 id="modalTitle" class="font-bold text-gray-800 flex items-center gap-2">
                    <span class="w-1.5 h-6 bg-blue-500 rounded-full"></span>
                    회원사 등록
                </h3>
                <div class="flex items-center gap-2">
                    <!-- 자동완성 버튼 -->
                    <button
                        type="button"
                        onclick="MemberModal.fillTestData()"
                        class="flex items-center gap-1 px-3 py-1.5 bg-amber-100 text-amber-700 rounded-lg hover:bg-amber-200 transition-all text-xs font-bold"
                        title="테스트 데이터 자동 입력"
                    >
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
                        </svg>
                        자동완성
                    </button>
                    <button
                        type="button"
                        onclick="MemberModal.close()"
                        class="w-10 h-10 flex items-center justify-center rounded-full text-gray-600 hover:text-gray-900 hover:bg-gray-200 transition-all bg-white/50 shadow-sm border border-gray-200"
                    >
                        <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="M6 18L18 6M6 6l12 12" />
                        </svg>
                    </button>
                </div>
            </div>

            <!-- 폼 -->
            <form id="memberForm" onsubmit="MemberModal.submit(event)" class="p-6">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <!-- 테넌트 선택 (전체 테넌트 모드에서만 표시) -->
                    <div id="tenantSelectField" class="col-span-2 hidden">
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">테넌트 (회원사) <span class="text-red-500">*</span></label>
                        <select name="tenant_id" class="w-full px-3 py-2 bg-indigo-50 border border-indigo-200 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
                            <option value="">테넌트 선택...</option>
                            @foreach($tenants ?? [] as $tenant)
                                <option value="{{ $tenant->id }}">{{ $tenant->company_name }}</option>
                            @endforeach
                        </select>
                        <p class="text-xs text-indigo-600 mt-1">이 회원사가 속할 테넌트를 선택하세요</p>
                    </div>

                    <!-- 사업자번호 -->
                    <div>
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">사업자번호 <span class="text-red-500">*</span></label>
                        <input type="text" name="biz_no" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 disabled:opacity-50" required placeholder="123-45-67890">
                    </div>

                    <!-- 상호명 -->
                    <div>
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">상호명 <span class="text-red-500">*</span></label>
                        <input type="text" name="corp_name" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required placeholder="(주)회사명">
                    </div>

                    <!-- 대표자명 -->
                    <div>
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">대표자명 <span class="text-red-500">*</span></label>
                        <input type="text" name="ceo_name" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" required placeholder="홍길동">
                    </div>

                    <!-- 업태/종목 -->
                    <div class="grid grid-cols-2 gap-2">
                        <div>
                            <label class="block text-xs font-bold text-gray-400 uppercase mb-1">업태</label>
                            <input type="text" name="biz_type" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="서비스">
                        </div>
                        <div>
                            <label class="block text-xs font-bold text-gray-400 uppercase mb-1">종목</label>
                            <input type="text" name="biz_class" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="소프트웨어">
                        </div>
                    </div>

                    <!-- 주소 -->
                    <div class="col-span-2">
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">주소</label>
                        <input type="text" name="addr" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="서울특별시 강남구...">
                    </div>

                    <!-- 바로빌 계정 -->
                    <div id="passwordFields" class="col-span-2 grid grid-cols-2 gap-4">
                        <div id="barobillIdField">
                            <label class="block text-xs font-bold text-gray-400 uppercase mb-1">
                                바로빌 아이디 <span id="idRequired" class="text-red-500">*</span>
                            </label>
                            <input type="text" name="barobill_id" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="barobill_id">
                            <p id="idHint" class="hidden text-xs text-gray-500 mt-1">변경 시에만 입력</p>
                        </div>
                        <div>
                            <label id="pwdLabel" class="block text-xs font-bold text-gray-400 uppercase mb-1">
                                비밀번호 <span id="pwdRequired" class="text-red-500">*</span>
                                <span id="pwdStatusBadge" class="hidden ml-2 px-2 py-0.5 text-xs font-medium rounded-full"></span>
                            </label>
                            <input type="password" name="barobill_pwd" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="********">
                            <p id="pwdHint" class="hidden text-xs text-gray-500 mt-1">변경 시에만 입력</p>
                        </div>
                    </div>

                    <!-- 구분선 -->
                    <div class="col-span-2 border-t border-gray-100 my-2"></div>

                    <!-- 담당자명 -->
                    <div>
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">담당자명</label>
                        <input type="text" name="manager_name" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="김철수">
                    </div>

                    <!-- 담당자 HP -->
                    <div>
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">담당자 연락처</label>
                        <input type="text" name="manager_hp" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="010-1234-5678">
                    </div>

                    <!-- 담당자 이메일 -->
                    <div>
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">담당자 이메일</label>
                        <input type="email" name="manager_email" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" placeholder="manager@example.com">
                    </div>

                    <!-- 상태 -->
                    <div>
                        <label class="block text-xs font-bold text-gray-400 uppercase mb-1">상태</label>
                        <select name="status" class="w-full px-3 py-2 bg-gray-50 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                            <option value="active">활성</option>
                            <option value="inactive">비활성</option>
                            <option value="pending">대기중</option>
                        </select>
                    </div>

                    <!-- 바로빌 API 검증 건너뛰기 (신규 등록 시에만 표시) -->
                    <div id="skipApiField" class="col-span-2 hidden">
                        <label class="flex items-center gap-3 p-3 bg-amber-50 border border-amber-200 rounded-lg cursor-pointer hover:bg-amber-100 transition-colors">
                            <input type="checkbox" name="skip_api" value="1" class="w-5 h-5 rounded border-amber-300 text-amber-600 focus:ring-amber-500">
                            <div>
                                <span class="font-bold text-amber-800">바로빌 API 검증 건너뛰기</span>
                                <p class="text-xs text-amber-600 mt-0.5">이미 바로빌에 등록된 회원사를 로컬 DB에만 저장합니다</p>
                            </div>
                        </label>
                    </div>
                </div>

                <!-- 버튼 -->
                <div class="flex gap-2 pt-6 mt-4 border-t border-gray-100">
                    <button
                        type="submit"
                        id="submitBtn"
                        class="flex-1 py-3 bg-blue-600 text-white rounded-lg font-bold hover:bg-blue-700 transition-colors"
                    >
                        등록하기
                    </button>
                    <button
                        type="button"
                        onclick="MemberModal.close()"
                        class="px-6 py-3 bg-gray-100 text-gray-600 rounded-lg font-bold hover:bg-gray-200 transition-colors"
                    >
                        취소
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
