<!-- Resume Modal -->
<template x-teleport="body">
    <div x-show="resumeModal.open" 
         x-cloak
         class="fixed inset-0 z-50 flex items-center justify-center overflow-y-auto overflow-x-hidden bg-black/80 backdrop-blur-sm p-4 md:p-6"
         style="z-index: 9999; position: fixed; top: 0; left: 0; right: 0; bottom: 0;"
         x-transition:enter="transition ease-out duration-300"
         x-transition:enter-start="opacity-0"
         x-transition:enter-end="opacity-100"
         x-transition:leave="transition ease-in duration-200"
         x-transition:leave-start="opacity-100"
         x-transition:leave-end="opacity-0"
         @keydown.escape.window="resumeModal.open = false">
        
        <!-- Modal Panel -->
        <div class="relative w-full max-w-2xl transform rounded-2xl bg-terminal-bg border border-white/10 shadow-2xl transition-all flex flex-col max-h-[90vh]"
             @click.away="resumeModal.open = false"
             x-transition:enter="transition ease-out duration-300"
             x-transition:enter-start="opacity-0 scale-95 translate-y-4"
             x-transition:enter-end="opacity-100 scale-100 translate-y-0"
             x-transition:leave="transition ease-in duration-200"
             x-transition:leave-start="opacity-100 scale-100 translate-y-0"
             x-transition:leave-end="opacity-0 scale-95 translate-y-4">
             
            <!-- Header -->
            <div class="flex items-center justify-between border-b border-white/5 bg-terminal-bg-light/50 px-6 py-4">
                <h3 class="text-lg font-bold text-terminal-text-bright flex items-center gap-2">
                    <span>Resume Execution</span>
                    <span class="text-terminal-text-muted/50 text-sm font-normal">from</span>
                    <span class="text-accent-blue font-mono text-base" x-text="resumeModal.stepName"></span>
                </h3>
                <button @click="resumeModal.open = false"
                    class="rounded-lg p-1 text-terminal-text-muted hover:bg-white/5 hover:text-white transition-colors">
                    <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"></path>
                    </svg>
                </button>
            </div>

            <!-- Content -->
            <div class="flex-1 overflow-y-auto p-6 custom-scrollbar">
                <div class="mb-6 rounded-lg bg-accent-blue/5 p-4 border border-accent-blue/10">
                    <div class="flex items-start gap-3">
                        <div class="text-accent-blue mt-0.5">
                            <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="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                            </svg>
                        </div>
                        <p class="text-sm text-terminal-text-muted leading-relaxed">
                            You can modify the inputs for this step before resuming. The workflow will replay from this point using the new input data provided below.
                        </p>
                    </div>
                </div>

                <div class="space-y-3">
                    <label class="flex justify-between items-center">
                        <span class="text-xs font-bold text-terminal-text-dim uppercase tracking-wider">Inputs (JSON)</span>
                        <span class="text-[10px] font-mono text-terminal-text-muted opacity-50">Editable</span>
                    </label>
                    <div class="relative group">
                        <div class="absolute inset-0 bg-gradient-to-r from-accent-blue/20 to-accent-purple/20 rounded-xl blur opacity-0 group-focus-within:opacity-100 transition-opacity duration-500"></div>
                        <textarea x-model="resumeModal.inputs"
                            class="relative w-full h-64 bg-terminal-bg-dark border border-white/10 rounded-xl p-4 font-mono text-sm text-terminal-text placeholder-terminal-text-muted/30 focus:border-accent-blue/50 focus:ring-1 focus:ring-accent-blue/50 outline-none transition-all custom-scrollbar resize-none shadow-inner"
                            spellcheck="false"
                            placeholder="{ ... }"></textarea>
                    </div>
                </div>

                <!-- Error Message -->
                <div x-show="resumeModal.error"
                     x-transition
                     class="mt-4 p-4 bg-status-error/10 border border-status-error/20 rounded-xl text-status-error text-sm flex items-start gap-3 shadow-lg shadow-status-error/5">
                    <svg class="w-5 h-5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                    </svg>
                    <div class="flex-1">
                        <p class="font-bold text-xs uppercase tracking-wide mb-1 opacity-80">Error</p>
                        <span x-text="resumeModal.error" class="break-all font-mono text-xs"></span>
                    </div>
                </div>
            </div>

            <!-- Footer -->
            <div class="flex items-center justify-end gap-3 border-t border-white/5 bg-terminal-bg-light/30 px-6 py-4">
                <button @click="resumeModal.open = false"
                    class="px-4 py-2 text-sm font-medium text-terminal-text-muted hover:text-white transition-colors hover:bg-white/5 rounded-lg">
                    Cancel
                </button>
                <button @click="confirmResume()"
                    class="relative overflow-hidden px-6 py-2 bg-accent-blue text-white text-sm font-bold rounded-lg hover:bg-accent-blue/90 transition-all shadow-lg shadow-accent-blue/20 group">
                    <span class="relative z-10 flex items-center gap-2">
                        <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="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                        </svg>
                        Resume Execution
                    </span>
                    <div class="absolute inset-0 bg-white/20 translate-y-full group-hover:translate-y-0 transition-transform duration-300"></div>
                </button>
            </div>
        </div>
    </div>
</template>
