<!-- 의약품 마스터 검색 페이지 -->
<div id="medicine-master" class="main-content">
    <h3 class="mb-4"><i class="bi bi-search"></i> 의약품 마스터 검색</h3>

    <!-- 검색 영역 -->
    <div class="card mb-4">
        <div class="card-body">
            <div class="row g-2 align-items-end">
                <div class="col-md-5">
                    <label class="form-label">검색어</label>
                    <input type="text" class="form-control" id="medSearchInput"
                           placeholder="상품명, 업체명, 표준코드 검색..." autofocus>
                </div>
                <div class="col-md-2">
                    <label class="form-label">분류</label>
                    <select class="form-select" id="medCategoryFilter">
                        <option value="">전체</option>
                        <option value="일반의약품">일반의약품</option>
                        <option value="전문의약품">전문의약품</option>
                        <option value="한약재">한약재</option>
                        <option value="원료의약품">원료의약품</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <label class="form-label">포장형태</label>
                    <select class="form-select" id="medPackageFilter">
                        <option value="">전체</option>
                        <option value="병">병</option>
                        <option value="포">포</option>
                        <option value="박스">박스</option>
                        <option value="기타">기타</option>
                    </select>
                </div>
                <div class="col-md-1">
                    <button class="btn btn-primary w-100" id="medSearchBtn">
                        <i class="bi bi-search"></i>
                    </button>
                </div>
                <div class="col-md-2">
                    <span class="text-muted" id="medSearchCount"></span>
                </div>
            </div>
        </div>
    </div>

    <!-- 검색 결과 -->
    <div class="card">
        <div class="card-header bg-light d-flex justify-content-between align-items-center">
            <h5 class="mb-0">검색 결과</h5>
            <div>
                <span class="badge bg-primary" id="medResultCount">0</span>건
            </div>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive" style="max-height: 600px; overflow-y: auto;">
                <table class="table table-hover table-sm mb-0">
                    <thead class="table-light sticky-top">
                        <tr>
                            <th>상품명</th>
                            <th>업체명</th>
                            <th>규격</th>
                            <th>포장</th>
                            <th>분류</th>
                            <th>표준코드</th>
                            <th>비고</th>
                            <th width="100">작업</th>
                        </tr>
                    </thead>
                    <tbody id="medSearchResults">
                        <tr>
                            <td colspan="8" class="text-center text-muted py-5">
                                <i class="bi bi-search" style="font-size: 2rem;"></i>
                                <p class="mt-2">검색어를 입력하세요 (2자 이상)</p>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- 입고 장바구니 -->
    <div class="card mt-4" id="cartPanel" style="display:none;">
        <div class="card-header bg-light d-flex justify-content-between align-items-center">
            <h5 class="mb-0"><i class="bi bi-cart3"></i> 입고 장바구니 (<span id="cartCount">0</span>건)</h5>
            <button class="btn btn-sm btn-outline-danger" id="cartClearBtn" title="비우기">
                <i class="bi bi-trash"></i> 비우기
            </button>
        </div>
        <div class="card-body">
            <!-- 입고 정보 -->
            <div class="row g-2 mb-3">
                <div class="col-md-4">
                    <label class="form-label">도매상 <span class="text-danger">*</span></label>
                    <select class="form-select form-select-sm" id="cartSupplier">
                        <option value="">-- 선택 --</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label">입고일 <span class="text-danger">*</span></label>
                    <input type="date" class="form-control form-control-sm" id="cartReceiptDate">
                </div>
                <div class="col-md-5">
                    <label class="form-label">비고</label>
                    <input type="text" class="form-control form-control-sm" id="cartNotes" placeholder="비고 입력...">
                </div>
            </div>

            <!-- 장바구니 테이블 -->
            <div class="table-responsive">
                <table class="table table-sm table-bordered mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>상품명</th>
                            <th>업체</th>
                            <th>규격</th>
                            <th width="70">수량</th>
                            <th width="110">단가(원)</th>
                            <th width="90">금액</th>
                            <th width="80">g당단가</th>
                            <th width="100">원산지</th>
                            <th width="40"></th>
                        </tr>
                    </thead>
                    <tbody id="cartBody"></tbody>
                    <tfoot class="table-light">
                        <tr class="fw-bold">
                            <td colspan="3" class="text-end">합계</td>
                            <td id="cartTotalQty" class="text-end">0</td>
                            <td></td>
                            <td id="cartTotalAmt" class="text-end">0</td>
                            <td colspan="3"></td>
                        </tr>
                    </tfoot>
                </table>
            </div>

            <!-- 입고장 생성 버튼 -->
            <div class="text-end mt-3">
                <button class="btn btn-primary" id="createReceiptBtn">
                    <i class="bi bi-clipboard-check"></i> 입고장 생성
                </button>
            </div>
        </div>
    </div>

    <!-- 제품 상세 모달 -->
    <div class="modal fade" id="medDetailModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="medDetailTitle">제품 상세</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body" id="medDetailBody">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
                </div>
            </div>
        </div>
    </div>
</div>
