<div id="checkoutOtpModal" class="fixed inset-0 bg-gray-900 bg-opacity-60 overflow-y-auto h-full w-full z-50 hidden">
    <div class="relative top-10 sm:top-20 mx-auto p-4 sm:p-6 border border-gray-200 w-full max-w-sm shadow-2xl rounded-2xl bg-white">
        <div class="flex justify-between items-center mb-4">
            <h3 class="text-lg font-bold text-gray-900">ফোন নম্বর যাচাই করুন</h3>
            <button type="button" class="text-gray-400 hover:text-gray-600" onclick="closeCheckoutOtpModal()">
                <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"></path>
                </svg>
            </button>
        </div>

        <!-- Choice Step -->
        <div id="checkoutChoiceStep">
            <div class="mb-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
                <p class="text-sm text-blue-800 leading-relaxed">
                    আপনার সর্বশেষ যাচাইকৃত <strong>OTP</strong> এখন আপনার পাসওয়ার্ড হিসেবে কাজ করবে। 
                    নতুন কোড অনুরোধ না করে সেটি ব্যবহার করতে পারেন।
                </p>
            </div>

            <p class="text-sm text-gray-600 mb-4">
                আপনি নিচের যেকোনো একটি বিকল্প বেছে নিতে পারেন:
            </p>

            <div id="checkoutChoiceError" class="mb-4 p-3 bg-red-50 border border-red-200 text-red-700 rounded-lg text-sm hidden"></div>

            <div class="space-y-3">
                <button type="button" id="checkoutLastOtpOptionBtn" onclick="showCheckoutLastOtp()"
                        class="w-full flex items-center p-4 border-2 border-blue-200 rounded-lg hover:bg-blue-50 hover:border-blue-400 transition-colors text-left">
                    <div class="flex-shrink-0 mr-4">
                        <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center">
                            <svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path>
                            </svg>
                        </div>
                    </div>
                    <div>
                        <div class="font-medium text-gray-900">শেষ OTP দিয়ে যাচাই করুন</div>
                        <div class="text-xs text-gray-500 mt-0.5">আপনার আগের যাচাইকৃত কোড ব্যবহার করুন</div>
                    </div>
                </button>

                <button type="button" id="checkoutSendNewOtpOptionBtn" onclick="sendCheckoutNewOtp()"
                        class="w-full flex items-center p-4 border-2 border-green-200 rounded-lg hover:bg-green-50 hover:border-green-400 transition-colors text-left">
                    <div class="flex-shrink-0 mr-4">
                        <div class="w-10 h-10 bg-green-100 rounded-full flex items-center justify-center">
                            <svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"></path>
                            </svg>
                        </div>
                    </div>
                    <div>
                        <div class="font-medium text-gray-900">নতুন OTP পাঠান</div>
                        <div class="text-xs text-gray-500 mt-0.5">মোবাইলে নতুন কোড পাঠান</div>
                    </div>
                    <span id="checkoutSendNewOtpLoading" class="hidden ml-auto">
                        <svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-green-600 inline" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                            <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                            <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                        </svg>
                    </span>
                </button>
            </div>
        </div>

        <!-- Last OTP Step -->
        <div id="checkoutLastOtpStep" class="hidden">
            <div class="mb-4 p-3 bg-gray-50 border border-gray-200 rounded-lg">
                <p class="text-sm text-gray-600">ফোন নম্বর:</p>
                <p id="checkoutLastOtpPhoneDisplay" class="text-lg font-semibold text-gray-900"></p>
            </div>

            <div class="mb-4 p-4 bg-blue-50 border border-blue-200 rounded-lg">
                <p class="text-sm text-blue-800 leading-relaxed">
                    আপনার সর্বশেষ যাচাইকৃত <strong>OTP</strong> এখন আপনার পাসওয়ার্ড হিসেবে সংরক্ষিত আছে। 
                    নিচে সেই কোডটি লিখুন এবং অর্ডার কনফার্ম করুন।
                </p>
            </div>

            <div id="checkoutLastOtpError" class="mb-4 p-3 bg-red-50 border border-red-200 text-red-700 rounded-lg text-sm hidden"></div>

            <form id="checkoutLastOtpForm" class="space-y-4">
                @csrf
                <input type="hidden" id="checkoutLastOtpPhone" name="phone" value="">

                <div>
                    <label for="checkoutLastOtpCode" class="block text-sm font-medium text-gray-700 mb-2">পাসওয়ার্ড / OTP</label>
                    <input type="text" id="checkoutLastOtpCode" name="password"
                           inputmode="numeric" autocomplete="one-time-code"
                           class="w-full px-4 py-3 border border-gray-300 rounded-lg text-center text-2xl tracking-widest focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
                           placeholder="0000" maxlength="4" required>
                </div>

                <div class="flex space-x-3">
                    <button type="button" onclick="backToCheckoutChoice()"
                            class="flex-1 bg-gray-200 text-gray-700 px-4 py-2 rounded-md hover:bg-gray-300 transition-colors">
                        ফিরে যান
                    </button>
                    <button type="submit" id="checkoutLastOtpSubmitBtn"
                            class="flex-1 bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-colors flex items-center justify-center">
                        <span id="checkoutLastOtpBtnText">যাচাই করুন</span>
                        <span id="checkoutLastOtpBtnLoading" class="hidden ml-2">
                            <svg class="animate-spin h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                            </svg>
                        </span>
                    </button>
                </div>
            </form>
        </div>

        <!-- New OTP Step -->
        <div id="checkoutNewOtpStep" class="hidden">
            <div class="mb-4 text-sm text-gray-600">
                আমরা আপনার মোবাইল নম্বরে একটি <strong>৪-সংখ্যার কোড</strong> পাঠিয়েছি। নিচে কোডটি লিখুন অথবা SMS থেকে অটো-ফিল করুন।
            </div>

            <div id="checkoutOtpError" class="mb-4 p-3 bg-red-50 border border-red-200 text-red-700 rounded-lg text-sm hidden"></div>
            <div id="checkoutOtpSuccess" class="mb-4 p-3 bg-green-50 border border-green-200 text-green-700 rounded-lg text-sm hidden"></div>

            <form id="checkoutOtpForm">
                @csrf
                <input type="hidden" id="checkoutOtpPhone" name="phone" value="">

                <div class="mb-4">
                    <label for="checkoutOtpCode" class="block text-sm font-medium text-gray-700 mb-2">যাচাইকরণ কোড</label>
                    <input type="text" id="checkoutOtpCode" name="otp" inputmode="numeric" autocomplete="one-time-code"
                           maxlength="4" required
                           class="w-full px-4 py-3 border border-gray-300 rounded-lg text-center text-2xl tracking-widest focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
                           placeholder="0000">
                </div>

                <button type="submit" id="checkoutOtpSubmitBtn"
                        class="w-full bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 text-white font-bold py-3 px-4 rounded-lg transition-colors flex items-center justify-center">
                    <span id="checkoutOtpBtnText">অর্ডার কনফার্ম করুন</span>
                    <span id="checkoutOtpBtnLoading" class="hidden ml-2">
                        <svg class="animate-spin h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                            <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                            <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                        </svg>
                    </span>
                </button>
            </form>

            <div class="mt-4 text-center">
                <button type="button" id="checkoutResendOtpBtn" onclick="resendCheckoutOtp()"
                        class="text-blue-600 hover:text-blue-500 text-sm font-medium">
                    কোড পুনরায় পাঠান
                </button>
                <p id="checkoutResendTimer" class="text-sm text-gray-500 mt-1 hidden">
                    <span id="checkoutTimerCount">60</span> সেকেন্ডের মধ্যে আবার পাঠানো যাবে
                </p>
            </div>
        </div>
    </div>
</div>
