<div class="container-fluid pb-5">
    <div class="row mb-4 align-items-center">
        <div class="col-md-8">
            <h4 class="text-primary fw-bold" style="letter-spacing: -0.5px;">
                <i class="fa-solid fa-cogs me-2"></i> Clinical Care Engine
            </h4>
            <p class="text-muted mb-0">Master configuration hub for clinical parameters, custom dictionaries, and ward billing.</p>
        </div>
    </div>

    <div class="row g-4">
        <!-- UNIFIED VERTICAL SIDEBAR -->
        <div class="col-md-3">
            <div class="card shadow-sm border-0 rounded-3 h-100">
                <div class="card-body p-0" style="max-height: 800px; overflow-y: auto;">
                    
                    <div class="nav flex-column nav-pills custom-v-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
                        
                        <!-- WARD BILLING & POC TESTS -->
                        <div class="px-3 py-2 text-muted fw-bold small text-uppercase mt-2">Ward Billing & Services</div>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom text-dark fw-bold" data-bs-toggle="pill" data-bs-target="#tab-ward-services">
                            <i class="fa-solid fa-file-invoice-dollar text-success me-2 w-20px"></i> Ward Services & POC Tests
                        </button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-svc-types">
                            <i class="fa-solid fa-tags me-2 w-20px"></i> Service Types
                        </button>

                        <!-- STANDARD CLINICAL PARAMETERS -->
                        <div class="px-3 py-2 text-muted fw-bold small text-uppercase mt-3 border-top pt-3">Standard Parameters</div>
                        <!-- NEW OUTCOMES TAB -->
                        <button class="nav-link text-start rounded-0 border-0 border-bottom text-dark fw-bold" data-bs-toggle="pill" data-bs-target="#tab-outcomes">
                            <i class="fa-solid fa-person-walking-arrow-right text-primary me-2 w-20px"></i> Clinical Outcomes
                        </button>
                        <button class="nav-link active text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-meds"><i class="fa-solid fa-pills me-2 w-20px"></i> Medications</button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-oxygen"><i class="fa-solid fa-wind me-2 w-20px"></i> Oxygen Therapy</button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-vitals"><i class="fa-solid fa-heart-pulse me-2 w-20px"></i> Vitals & Freq</button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-fluids"><i class="fa-solid fa-droplet me-2 w-20px"></i> Fluids (I/O)</button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-diet"><i class="fa-solid fa-utensils me-2 w-20px"></i> Diets</button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-blood"><i class="fa-solid fa-droplet text-danger me-2 w-20px"></i> Blood Transfusion</button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-isolation"><i class="fa-solid fa-shield-virus me-2 w-20px"></i> Isolation & PPE</button>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom" data-bs-toggle="pill" data-bs-target="#tab-equipment"><i class="fa-solid fa-wheelchair me-2 w-20px"></i> Ward Equipment</button>

                        <!-- CUSTOM DICTIONARIES -->
                        <div class="px-3 py-2 text-muted fw-bold small text-uppercase mt-3 border-top pt-3 d-flex justify-content-between align-items-center">
                            Custom Dictionaries
                            <button class="btn btn-xs btn-primary py-0 px-2" onclick="openMasterDictModal()"><i class="fa-solid fa-plus"></i></button>
                        </div>
                        <div id="dynamic-dict-menu">
                            <div class="text-center p-3"><div class="spinner-border spinner-border-sm text-primary"></div></div>
                        </div>

                        <!-- SYSTEM INTEGRATION -->
                        <div class="px-3 py-2 text-muted fw-bold small text-uppercase mt-3 border-top pt-3">System Maps</div>
                        <button class="nav-link text-start rounded-0 border-0 border-bottom text-dark fw-bold" data-bs-toggle="pill" data-bs-target="#tab-registry"><i class="fa-solid fa-database me-2 w-20px"></i> Core DB Registry Map</button>
                        
                        <button class="nav-link text-start rounded-0 border-0 border-bottom text-primary fw-bold bg-primary bg-opacity-10 mt-3" onclick="window.location.href='?cat=ipd&page=ipd/dynamicFormBuilder.php'">
                            <i class="fa-solid fa-hammer me-2 w-20px"></i> Launch Form Builder
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- CONTENT AREA -->
        <div class="col-md-9">
            <div class="card shadow-sm border-0 rounded-3">
                <div class="card-body p-4 tab-content bg-white min-vh-100" id="v-pills-tabContent">
                    
                    <!-- 0. WARD SERVICES & POC TESTS -->
                    <div class="tab-pane fade" id="tab-ward-services">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <div>
                                <h5 class="fw-bold mb-0 text-success"><i class="fa-solid fa-file-invoice-dollar"></i> Ward Services & POC Tests</h5>
                                <p class="small text-muted mb-0">Configure billable ward procedures and Point-of-Care tests (e.g. Sugar Strips).</p>
                            </div>
                            <button class="btn btn-success btn-sm shadow-sm" onclick="openIpdServiceModal()"><i class="fa-solid fa-plus"></i> Add Service / POC Test</button>
                        </div>
                        <table class="table table-hover w-100 m-0 align-middle" id="tblIpdServices">
                            <thead class="table-light"><tr><th>Service Details</th><th>Cash Pricing</th><th>NHIS (A/C)</th><th width="25%">Mappings & Config</th><th width="10%">Action</th></tr></thead>
                        </table>
                    </div>

                    <!-- 0.1 SERVICE TYPES -->
                    <div class="tab-pane fade" id="tab-svc-types">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <h5 class="fw-bold mb-0 text-dark">Ward Service Types</h5>
                            <button class="btn btn-primary btn-sm shadow-sm" onclick="openDictModal('svc_type', 'Service Type')"><i class="fa-solid fa-plus"></i> Add Type</button>
                        </div>
                        <table class="table table-hover align-middle w-100 m-0" id="tblSvcTypes">
                            <thead class="table-light"><tr><th>Sr.No</th><th>Service Type Category</th><th>Status</th><th>Action</th></tr></thead>
                        </table>
                    </div>

                    <!-- 0.2 CLINICAL OUTCOMES -->
                    <div class="tab-pane fade" id="tab-outcomes">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <div>
                                <h5 class="fw-bold mb-0 text-dark"><i class="fa-solid fa-person-walking-arrow-right"></i> Clinical Outcomes</h5>
                                <p class="small text-muted mb-0">Manage ward outcomes and their corresponding system triggers.</p>
                            </div>
                            <button class="btn btn-primary btn-sm shadow-sm" onclick="openDictModal('outcome', 'Clinical Outcome')"><i class="fa-solid fa-plus"></i> Add Outcome</button>
                        </div>
                        <table class="table table-hover align-middle w-100 m-0" id="tblOutcomes">
                            <thead class="table-light"><tr><th>Sr.No</th><th>Outcome Name</th><th>System Trigger</th><th>Status</th><th>Action</th></tr></thead>
                        </table>
                    </div>

                    <!-- 1. MEDICATIONS -->
                    <div class="tab-pane fade show active" id="tab-meds">
                        <div class="row g-4">
                            <div class="col-md-6">
                                <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Administration Routes</h5><button class="btn btn-primary btn-sm" onclick="openDictModal('med_route', 'Medication Route')"><i class="fa-solid fa-plus"></i></button></div>
                                <table class="table table-hover w-100 m-0" id="tblMedRoutes"><thead class="table-light"><tr><th>Sr.No</th><th>Route</th><th>Status</th><th>Action</th></tr></thead></table>
                            </div>
                            <div class="col-md-6">
                                <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Nursing Instructions</h5><button class="btn btn-primary btn-sm" onclick="openDictModal('med_inst', 'Nursing Instruction')"><i class="fa-solid fa-plus"></i></button></div>
                                <table class="table table-hover w-100 m-0" id="tblMedInst"><thead class="table-light"><tr><th>Sr.No</th><th>Instruction</th><th>Status</th><th>Action</th></tr></thead></table>
                            </div>
                        </div>
                    </div>

                    <!-- 2. OXYGEN THERAPY -->
                    <div class="tab-pane fade" id="tab-oxygen">
                        <div class="row g-4">
                            <div class="col-md-6">
                                <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Oxygen Delivery Modes</h5><button class="btn btn-primary btn-sm shadow-sm" onclick="openDictModal('o2_mode', 'Oxygen Mode')"><i class="fa-solid fa-plus"></i></button></div>
                                <table class="table table-hover align-middle w-100 m-0" id="tblO2Modes"><thead class="table-light"><tr><th>Sr.No</th><th>Delivery Mode</th><th>Status</th><th>Action</th></tr></thead></table>
                            </div>
                            <div class="col-md-6">
                                <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Oxygen Flow Rates</h5><button class="btn btn-primary btn-sm shadow-sm" onclick="openDictModal('o2_flow', 'Oxygen Flow Rate')"><i class="fa-solid fa-plus"></i></button></div>
                                <table class="table table-hover align-middle w-100 m-0" id="tblO2Flows"><thead class="table-light"><tr><th>Sr.No</th><th>Flow Rate Label</th><th>Liters/Min</th><th>Action</th></tr></thead></table>
                            </div>
                        </div>
                    </div>

                    <!-- 3. VITALS -->
                    <div class="tab-pane fade" id="tab-vitals">
                        <div class="row g-4">
                            <div class="col-md-7">
                                <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Vital Parameters</h5><button class="btn btn-primary btn-sm shadow-sm" onclick="openDictModal('vital', 'Vital Parameter')"><i class="fa-solid fa-plus"></i> Add Vital</button></div>
                                <table class="table table-hover align-middle w-100 m-0" id="tblVitals"><thead class="table-light"><tr><th>Sr.No</th><th>Parameter</th><th>Unit</th><th>Bounds</th><th>Action</th></tr></thead></table>
                            </div>
                            <div class="col-md-5">
                                <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Observation Freq</h5><button class="btn btn-primary btn-sm shadow-sm" onclick="openDictModal('obs_freq', 'Observation Frequency')"><i class="fa-solid fa-plus"></i> Add</button></div>
                                <table class="table table-hover align-middle w-100 m-0" id="tblFreqs"><thead class="table-light"><tr><th>Sr.No</th><th>Frequency</th><th>Interval (Mins)</th><th>Action</th></tr></thead></table>
                            </div>
                        </div>
                    </div>

                    <!-- 4. FLUIDS -->
                    <div class="tab-pane fade" id="tab-fluids">
                        <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Fluid Types (Intake & Output)</h5><button class="btn btn-primary btn-sm" onclick="openDictModal('fluid', 'Fluid Type')"><i class="fa-solid fa-plus"></i> Add</button></div>
                        <table class="table table-hover w-100 m-0" id="tblFluids"><thead class="table-light"><tr><th>Sr.No</th><th>Category</th><th>Fluid Name</th><th>Status</th><th>Action</th></tr></thead></table>
                    </div>
                    
                    <!-- 5. DIETS -->
                    <div class="tab-pane fade" id="tab-diet">
                        <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Diet Types</h5><button class="btn btn-primary btn-sm" onclick="openDictModal('diet', 'Diet Type')"><i class="fa-solid fa-plus"></i> Add</button></div>
                        <table class="table table-hover w-100 m-0" id="tblDiets"><thead class="table-light"><tr><th>Sr.No</th><th>Diet Name</th><th>Description</th><th>Status</th><th>Action</th></tr></thead></table>
                    </div>

                    <!-- 6. BLOOD -->
                    <div class="tab-pane fade" id="tab-blood">
                        <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Blood Transfusion Products</h5><button class="btn btn-primary btn-sm" onclick="openDictModal('blood_prod', 'Blood Product')"><i class="fa-solid fa-plus"></i> Add</button></div>
                        <table class="table table-hover w-100 m-0" id="tblBlood"><thead class="table-light"><tr><th>Sr.No</th><th>Product Name</th><th>Status</th><th>Action</th></tr></thead></table>
                    </div>

                    <!-- 7. ISOLATION -->
                    <div class="tab-pane fade" id="tab-isolation">
                        <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Isolation & Infection Control Types</h5><button class="btn btn-primary btn-sm" onclick="openDictModal('isolation', 'Isolation Type')"><i class="fa-solid fa-plus"></i> Add</button></div>
                        <table class="table table-hover w-100 m-0" id="tblIsolation"><thead class="table-light"><tr><th>Sr.No</th><th>Isolation Type</th><th>Status</th><th>Action</th></tr></thead></table>
                    </div>

                    <!-- 8. WARD EQUIPMENT -->
                    <div class="tab-pane fade" id="tab-equipment">
                        <div class="d-flex justify-content-between align-items-center mb-3"><h5 class="fw-bold mb-0 text-dark">Ward Equipment</h5><button class="btn btn-primary btn-sm" onclick="openDictModal('equipment', 'Ward Equipment')"><i class="fa-solid fa-plus"></i> Add</button></div>
                        <table class="table table-hover w-100 m-0" id="tblEquip"><thead class="table-light"><tr><th>Sr.No</th><th>Equipment Name</th><th>Status</th><th>Action</th></tr></thead></table>
                    </div>

                    <!-- 9. DYNAMIC DICTIONARY ITEMS VIEW -->
                    <div class="tab-pane fade" id="tab-custom-items">
                        <div id="welcome-state" class="text-center py-5 mt-5">
                            <i class="fa-solid fa-book-medical fa-4x text-muted mb-3"></i><h4 class="text-dark fw-bold">Clinical Dictionaries</h4><p class="text-muted">Select a dictionary from the left to manage its options.</p>
                        </div>
                        <div id="items-state" style="display:none;">
                            <div class="d-flex justify-content-between align-items-center mb-1">
                                <div><h5 class="fw-bold mb-0 text-primary" id="lblDictName">Dictionary Name</h5><p class="small text-muted mb-0" id="lblDictDesc">Description</p></div>
                                <div><button class="btn btn-outline-secondary btn-sm me-2" onclick="editMasterDict()"><i class="fa-solid fa-pen"></i> Edit Title</button><button class="btn btn-primary btn-sm shadow-sm" onclick="openItemModal()"><i class="fa-solid fa-plus"></i> Add Option / Parameter</button></div>
                            </div><hr>
                            <input type="hidden" id="active_dict_id">
                            <table class="table table-hover w-100 m-0 align-middle" id="tblDictItems"><thead class="table-light"><tr><th>Sr.No</th><th>Option / Parameter Details</th><th>Status</th><th width="15%">Action</th></tr></thead></table>
                        </div>
                    </div>

                    <!-- 10. CORE DATABASE REGISTRY MAP -->
                    <div class="tab-pane fade" id="tab-registry">
                        <div class="d-flex justify-content-between align-items-center mb-3">
                            <div><h5 class="fw-bold mb-0 text-dark">System Database Registry Map</h5><p class="small text-muted mb-0">Register core SQL tables so the Form Builder can pull from them.</p></div>
                            <button class="btn btn-dark btn-sm shadow-sm" onclick="openRegistryModal()"><i class="fa-solid fa-database"></i> Map Database Table</button>
                        </div>
                        <table class="table table-hover w-100 m-0 align-middle" id="tblRegistry"><thead class="table-light"><tr><th>Sr.No</th><th>Display Name in Builder</th><th>Target SQL Table</th><th>Filter</th><th>Status</th><th>Action</th></tr></thead></table>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!-- ============================================== -->
<!-- MODALS -->
<!-- ============================================== -->

<!-- MODAL: IPD WARD SERVICES & POC TESTS -->
<div class="modal fade" id="modalIpdService" tabindex="-1">
    <div class="modal-dialog modal-lg modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-success text-white">
                <h5 class="modal-title fw-bold">Ward Service / POC Test Profile</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form id="frmIpdService">
                <input type="hidden" name="action" value="save_ipd_service">
                <input type="hidden" name="id" id="svc_id" value="">
                <div class="modal-body p-4">
                    <div class="row">
                        <div class="col-md-7 mb-3">
                            <label class="form-label fw-bold">Service / Test Name <span class="text-danger">*</span></label>
                            <input type="text" name="service_name" id="svc_name" class="form-control" placeholder="e.g. RBS Strip, Wound Dressing" required>
                        </div>
                        <div class="col-md-5 mb-3">
                            <label class="form-label fw-bold">Service Type <span class="text-danger">*</span></label>
                            <select name="service_type_id" id="svc_type" class="form-select bg-light" required></select>
                        </div>
                    </div>

                    <!-- Cash Pricing -->
                    <div class="card bg-light border-0 mb-3"><div class="card-body py-2">
                        <h6 class="fw-bold text-dark mb-2">Cash Pricing (Out-of-Pocket)</h6>
                        <div class="row">
                            <div class="col-6"><label class="form-label small">Adult Price</label><input type="number" step="0.01" name="cash_price_adult" id="svc_cash_adult" class="form-control" value="0.00" required></div>
                            <div class="col-6"><label class="form-label small">Child Price</label><input type="number" step="0.01" name="cash_price_child" id="svc_cash_child" class="form-control" value="0.00" required></div>
                        </div>
                    </div></div>

                    <!-- NHIS Configuration -->
                    <div class="form-check form-switch mb-2">
                        <input class="form-check-input" type="checkbox" name="is_nhis_covered" id="svc_nhis_covered" value="1">
                        <label class="form-check-label fw-bold text-primary" for="svc_nhis_covered">Covered by National Health Insurance (NHIS)</label>
                    </div>
                    <div class="card border-primary bg-primary bg-opacity-10 mb-3" id="div_nhis_pricing" style="display:none;"><div class="card-body py-2">
                        <div class="row mb-2">
                            <div class="col-6"><label class="form-label small text-primary">NHIS Tariff (Adult)</label><input type="number" step="0.01" name="nhis_tariff_adult" id="svc_nhis_adult" class="form-control border-primary" value="0.00"></div>
                            <div class="col-6"><label class="form-label small text-primary">NHIS Tariff (Child)</label><input type="number" step="0.01" name="nhis_tariff_child" id="svc_nhis_child" class="form-control border-primary" value="0.00"></div>
                        </div>
                        <div class="row">
                            <div class="col-6"><label class="form-label small text-danger">NHIS Co-Pay (Adult)</label><input type="number" step="0.01" name="nhis_copay_adult" id="svc_nhis_copay_adult" class="form-control border-danger" value="0.00"></div>
                            <div class="col-6"><label class="form-label small text-danger">NHIS Co-Pay (Child)</label><input type="number" step="0.01" name="nhis_copay_child" id="svc_nhis_copay_child" class="form-control border-danger" value="0.00"></div>
                        </div>
                    </div></div>

                    <!-- Point of Care Charting Logic -->
                    <hr>
                    <div class="form-check form-switch mb-3">
                        <input class="form-check-input" type="checkbox" name="requires_result" id="svc_req_res" value="1">
                        <label class="form-check-label fw-bold text-success" for="svc_req_res">Requires Point-of-Care Charting (Generates a Result Entry block in the Ward Form)</label>
                    </div>

                    <div id="div_poc_config" style="display:none;" class="p-3 border border-success rounded bg-success bg-opacity-10">
                        <h6 class="fw-bold text-success mb-2"><i class="fa-solid fa-chart-line"></i> Main Result Configuration</h6>
                        <div class="row">
                            <div class="col-md-4 mb-2">
                                <label class="form-label small">Unit of Measure</label>
                                <input type="text" name="unit_of_measure" id="svc_unit" class="form-control" placeholder="e.g. mmol/L">
                            </div>
                            <div class="col-md-4 mb-2">
                                <label class="form-label small">Result Input Type</label>
                                <select name="result_type" id="svc_result_type" class="form-select">
                                    <option value="Numeric">Numeric</option>
                                    <option value="Options">Dropdown / Options</option>
                                    <option value="Text">Short Text</option>
                                </select>
                            </div>
                            <div class="col-md-4 mb-2" id="div_svc_options" style="display:none;">
                                <label class="form-label small text-danger">Options (Comma separated)</label>
                                <input type="text" name="options_csv" id="svc_options" class="form-control border-danger" placeholder="e.g. Positive,Negative">
                            </div>
                        </div>
                        <p class="small text-muted mt-2 mb-0"><i class="fa fa-info-circle"></i> <b>Note:</b> If this test requires MULTIPLE parameters (e.g. Urinalysis dipstick), save this form first, then click "Parameters" in the table.</p>
                    </div>

                </div>
                <div class="modal-footer bg-light">
                    <button type="button" class="btn btn-light border" data-bs-dismiss="modal">Close</button>
                    <button type="submit" class="btn btn-success px-4 shadow-sm">Save Service Configuration</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- MODAL: POC SUB-PARAMETERS -->
<div class="modal fade" id="modalPocParameters" tabindex="-1">
    <div class="modal-dialog modal-xl modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-info text-dark">
                <h5 class="modal-title fw-bold"><i class="fa-solid fa-list-check me-2"></i> Parameters for: <span id="lblPocParamName"></span></h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-4 bg-light">
                <form id="frmPocParameter" class="card p-3 border-0 shadow-sm mb-4">
                    <input type="hidden" name="action" value="save_poc_param">
                    <input type="hidden" name="ipd_service_id" id="param_svc_id" value="">
                    <input type="hidden" name="id" id="param_id" value="">
                    
                    <div class="row align-items-end mb-3">
                        <div class="col-md-4">
                            <label class="form-label small fw-bold">Parameter Name <span class="text-danger">*</span></label>
                            <input type="text" name="parameter_name" id="param_name" class="form-control border-info" placeholder="e.g. Leukocytes, pH" required>
                        </div>
                        <div class="col-md-2">
                            <label class="form-label small fw-bold">Unit</label>
                            <input type="text" name="unit_of_measure" id="param_unit" class="form-control" placeholder="e.g. g/dL">
                        </div>
                        <div class="col-md-2">
                            <label class="form-label small fw-bold">Input Type <span class="text-danger">*</span></label>
                            <select name="result_type" id="param_res_type" class="form-select bg-light" required>
                                <option value="Numeric">Numeric</option><option value="Options">Dropdown</option><option value="Text">Short Text</option>
                            </select>
                        </div>
                        <div class="col-md-4" id="div_param_options" style="display:none;">
                            <label class="form-label small fw-bold text-danger">Dropdown Options (CSV)</label>
                            <input type="text" name="options_csv" id="param_options" class="form-control border-danger" placeholder="e.g. Neg, Trace, +, ++">
                        </div>
                    </div>
                    <div class="text-end"><button type="submit" class="btn btn-info px-4 fw-bold">Save Parameter</button></div>
                </form>

                <div class="table-responsive bg-white rounded border">
                    <table class="table table-sm table-hover m-0 align-middle" id="tblPocParams">
                        <thead class="table-light"><tr><th>Parameter Name</th><th>Unit</th><th>Input Type</th><th>Options</th><th>Action</th></tr></thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- MODAL: POC REFERENCE RANGES -->
<div class="modal fade" id="modalPocRanges" tabindex="-1">
    <div class="modal-dialog modal-xl modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-primary text-white">
                <h5 class="modal-title fw-bold"><i class="fa-solid fa-chart-bar me-2"></i> Reference Ranges: <span id="lblPocRangeName"></span></h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-4 bg-light">
                <form id="frmPocRange" class="card p-3 border-0 shadow-sm mb-4">
                    <input type="hidden" name="action" value="save_poc_range">
                    <input type="hidden" name="ipd_service_id" id="rng_svc_id" value="">
                    
                    <div class="row align-items-end mb-3">
                        <div class="col-md-2">
                            <label class="form-label small fw-bold">Target Gender <span class="text-danger">*</span></label>
                            <select name="gender_target" class="form-select bg-light" required>
                                <option value="All">All Genders</option><option value="Male">Male Only</option><option value="Female">Female Only</option>
                            </select>
                        </div>
                        <div class="col-md-2">
                            <label class="form-label small fw-bold">Min Age (Yrs) <span class="text-danger">*</span></label>
                            <input type="number" name="min_age_years" class="form-control" value="0" required>
                        </div>
                        <div class="col-md-2">
                            <label class="form-label small fw-bold">Max Age (Yrs) <span class="text-danger">*</span></label>
                            <input type="number" name="max_age_years" class="form-control" value="150" required>
                        </div>
                    </div>
                    <div class="row align-items-end">
                        <div class="col-md-2">
                            <label class="form-label small fw-bold text-success">Normal Min</label>
                            <input type="number" step="0.0001" name="min_value" class="form-control border-success">
                        </div>
                        <div class="col-md-2">
                            <label class="form-label small fw-bold text-success">Normal Max</label>
                            <input type="number" step="0.0001" name="max_value" class="form-control border-success">
                        </div>
                        <div class="col-md-2">
                            <label class="form-label small fw-bold text-danger">Critical Low</label>
                            <input type="number" step="0.0001" name="critical_low" class="form-control border-danger">
                        </div>
                        <div class="col-md-2">
                            <label class="form-label small fw-bold text-danger">Critical High</label>
                            <input type="number" step="0.0001" name="critical_high" class="form-control border-danger">
                        </div>
                        <div class="col-md-2 offset-md-2 text-end">
                            <button type="submit" class="btn btn-primary w-100">Save Range</button>
                        </div>
                    </div>
                </form>

                <div class="table-responsive bg-white rounded border">
                    <table class="table table-sm table-hover m-0 align-middle text-center" id="tblPocRanges">
                        <thead class="table-light"><tr><th>Gender</th><th>Age Group (Yrs)</th><th>Normal Range</th><th>Critical Bounds</th><th>Action</th></tr></thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- MODAL: CORPORATE TARIFFS MANAGER -->
<div class="modal fade" id="modalCorpTariffs" tabindex="-1">
    <div class="modal-dialog modal-xl modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-dark text-white">
                <h5 class="modal-title fw-bold">Corporate / Private Insurance Tariffs</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body p-4 bg-light">
                <h6 class="text-primary fw-bold mb-3" id="lblCorpServiceName">Service Name</h6>
                <form id="frmCorpTariff" class="card p-3 border-0 shadow-sm mb-4">
                    <input type="hidden" name="action" value="save_corp_tariff">
                    <input type="hidden" name="ipd_service_id" id="corp_svc_id" value="">
                    
                    <div class="row align-items-end mb-2">
                        <div class="col-md-4">
                            <label class="form-label small fw-bold">Insurance Provider <span class="text-danger">*</span></label>
                            <select name="insurance_type_id" id="corp_ins_id" class="form-select" required></select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label small fw-bold text-primary">Adult Tariff <span class="text-danger">*</span></label>
                            <input type="number" step="0.01" name="tariff_amount_adult" id="corp_tariff_a" class="form-control border-primary" required>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label small fw-bold text-primary">Child Tariff <span class="text-danger">*</span></label>
                            <input type="number" step="0.01" name="tariff_amount_child" id="corp_tariff_c" class="form-control border-primary" required>
                        </div>
                    </div>
                    <div class="row align-items-end">
                        <div class="col-md-4">
                            <div class="form-check form-switch pt-4">
                                <input class="form-check-input" type="checkbox" name="is_copay_required" id="corp_req_copay" value="1">
                                <label class="form-check-label fw-bold text-danger" for="corp_req_copay">Requires Co-Payment</label>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <label class="form-label small fw-bold text-danger">Co-Pay Adult</label>
                            <input type="number" step="0.01" name="copay_amount_adult" id="corp_copay_a" class="form-control" value="0">
                        </div>
                        <div class="col-md-3">
                            <label class="form-label small fw-bold text-danger">Co-Pay Child</label>
                            <input type="number" step="0.01" name="copay_amount_child" id="corp_copay_c" class="form-control" value="0">
                        </div>
                        <div class="col-md-2 text-end">
                            <button type="submit" class="btn btn-dark w-100">Save Map</button>
                        </div>
                    </div>
                </form>

                <div class="table-responsive bg-white rounded border">
                    <table class="table table-sm table-hover m-0 align-middle" id="tblCorpTariffs">
                        <thead class="table-light"><tr><th>Insurance Provider</th><th>Tariff (Adult/Child)</th><th>Co-Pay (Adult/Child)</th><th width="10%">Action</th></tr></thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- MODAL: UNIVERSAL DYNAMIC FOR STANDARD TABLES -->
<div class="modal fade" id="modalUniversalDict" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-primary text-white">
                <h5 class="modal-title fw-bold" id="dictModalTitle">Add Entry</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form id="frmUniversalDict">
                <input type="hidden" name="action" value="save_dictionary">
                <input type="hidden" name="id" id="dict_id" value="">
                <input type="hidden" name="dict_type" id="dict_type" value="">
                <div class="modal-body p-4" id="dict_body_content"></div>
                <div class="modal-footer bg-light"><button type="submit" class="btn btn-primary px-4 shadow-sm">Save Entry</button></div>
            </form>
        </div>
    </div>
</div>

<!-- MODAL: CREATE CUSTOM MASTER DICTIONARY -->
<div class="modal fade" id="modalMasterDict" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-primary text-white">
                <h5 class="modal-title fw-bold">Custom Dictionary Profile</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form id="frmMasterDict">
                <input type="hidden" name="action" value="save_master_dict">
                <input type="hidden" name="id" id="m_dict_id" value="">
                <div class="modal-body p-4">
                    <div class="mb-3"><label class="form-label fw-bold">Dictionary Name <span class="text-danger">*</span></label><input type="text" name="dict_name" id="m_dict_name" class="form-control" required></div>
                    <div class="mb-2"><label class="form-label text-muted">Description (Optional)</label><input type="text" name="description" id="m_dict_desc" class="form-control"></div>
                </div>
                <div class="modal-footer bg-light"><button type="submit" class="btn btn-primary px-4 shadow-sm w-100">Save & Proceed</button></div>
            </form>
        </div>
    </div>
</div>

<!-- MODAL: DICTIONARY ITEM / PARAMETER -->
<div class="modal fade" id="modalDictItem" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-success text-white">
                <h6 class="modal-title fw-bold">Add Option / Parameter</h6>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form id="frmDictItem">
                <input type="hidden" name="action" value="save_dict_item">
                <input type="hidden" name="id" id="i_item_id" value="">
                <input type="hidden" name="dict_id" id="i_dict_id" value="">
                <div class="modal-body p-4">
                    <div class="mb-3">
                        <label class="form-label fw-bold">Parameter / Option Name <span class="text-danger">*</span></label>
                        <input type="text" name="item_name" id="i_item_name" class="form-control" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label fw-bold">Data Input Type <span class="text-danger">*</span></label>
                        <select name="input_type" id="i_input_type" class="form-select bg-light">
                            <option value="Standard Option / Text">Standard Option / Text</option>
                            <option value="Long Textarea">Long Textarea</option>
                            <option value="Number">Numeric Value</option>
                            <option value="Checkbox (Multiple)">Checkbox (Multiple)</option>
                            <option value="Radio (Single)">Radio (Single)</option>
                            <option value="Date">Date</option>
                        </select>
                    </div>
                    <div class="mb-1" id="div_dict_item_opts" style="display:none;">
                        <label class="form-label fw-bold text-success">Options (Comma separated)</label>
                        <textarea name="options_csv" id="i_options_csv" class="form-control border-success" placeholder="e.g. Yes, No, N/A"></textarea>
                    </div>
                </div>
                <div class="modal-footer p-3 bg-light"><button type="submit" class="btn btn-success px-4 shadow-sm">Save Parameter</button></div>
            </form>
        </div>
    </div>
</div>

<!-- MODAL: DB REGISTRY MAP -->
<div class="modal fade" id="modalRegistry" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow">
            <div class="modal-header bg-dark text-white">
                <h5 class="modal-title fw-bold">Register Core Database</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form id="frmRegistry">
                <input type="hidden" name="action" value="save_registry">
                <input type="hidden" name="id" id="reg_id" value="">
                <div class="modal-body p-4">
                    <div class="mb-3"><label class="form-label fw-bold">Display Name in Form Builder <span class="text-danger">*</span></label><input type="text" name="dictionary_name" id="reg_name" class="form-control" required></div>
                    <div class="mb-3"><label class="form-label text-primary fw-bold">Target Database Table <span class="text-danger">*</span></label><input type="text" name="target_table" id="reg_table" class="form-control border-primary" required></div>
                    <div class="row">
                        <div class="col-6 mb-3"><label class="form-label">Display Column <span class="text-danger">*</span></label><input type="text" name="display_column" id="reg_disp" class="form-control" required></div>
                        <div class="col-6 mb-3"><label class="form-label">Value Column <span class="text-danger">*</span></label><input type="text" name="value_column" id="reg_val" class="form-control" value="id" required></div>
                    </div>
                    <div class="mb-1"><label class="form-label text-secondary fw-bold">SQL Filter Condition <span class="text-muted fw-normal">(Optional)</span></label><input type="text" name="filter_condition" id="reg_filter" class="form-control bg-light" placeholder="e.g. location_type = 'Dispensary'"></div>
                </div>
                <div class="modal-footer bg-light"><button type="submit" class="btn btn-dark px-4 shadow-sm">Save Mapping</button></div>
            </form>
        </div>
    </div>
</div>