<!-- Edit Speakers Modal -->
<div v-if="showEditSpeakersModal" @click.self="closeEditSpeakersModal" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 p-4 backdrop-blur-sm">
    <div class="bg-[var(--bg-secondary)] rounded-xl shadow-2xl w-full max-w-md max-h-[80vh] flex flex-col">
        <div class="p-6 border-b border-[var(--border-primary)] flex-shrink-0">
            <div class="flex items-center justify-between">
                <h3 class="text-lg font-semibold" v-text="t('modal.editSpeakers')"></h3>
                <button @click="closeEditSpeakersModal" class="text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors">
                    <i class="fas fa-times text-xl"></i>
                </button>
            </div>
        </div>
        <div class="p-6 overflow-y-auto flex-1">
            <p class="text-sm text-[var(--text-muted)] mb-4">Rename speakers in the transcript.</p>

            <div class="space-y-3">
                <div v-for="(speaker, index) in editingSpeakersList" :key="index" class="relative">
                    <div class="flex items-center gap-2">
                        <span class="w-24 text-sm text-[var(--text-muted)] truncate">${speaker.original || 'New'}</span>
                        <i class="fas fa-arrow-right text-[var(--text-muted)]"></i>
                        <div class="flex-1 relative" :ref="'editSpeakerInput' + index">
                            <input v-model="speaker.current"
                                   @input="filterEditingSpeakerSuggestions(index)"
                                   @focus="filterEditingSpeakerSuggestions(index)"
                                   @blur="onEditSpeakerBlur(index)"
                                   type="text"
                                   class="w-full px-3 py-2 bg-[var(--bg-input)] border border-[var(--border-secondary)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--ring-focus)] text-sm"
                                   placeholder="New name...">
                        </div>
                        <!-- Teleported Suggestions dropdown -->
                        <teleport to="body">
                            <div v-if="editingSpeakerSuggestions[index]?.length > 0"
                                 class="fixed z-[100] bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-lg shadow-lg max-h-32 overflow-y-auto"
                                 :style="getEditSpeakerDropdownPosition(index)">
                                <button v-for="suggestion in editingSpeakerSuggestions[index]" :key="suggestion.id"
                                        @mousedown="selectEditingSpeakerSuggestion(index, suggestion.name)"
                                        class="w-full px-3 py-2 text-left hover:bg-[var(--bg-tertiary)] transition-colors text-sm">
                                    ${suggestion.name}
                                </button>
                            </div>
                        </teleport>
                        <button @click="removeEditingSpeaker(index)"
                                class="p-1 text-[var(--text-muted)] hover:text-red-500 transition-colors">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>
                </div>
            </div>

            <button @click="addEditingSpeaker"
                    class="mt-4 w-full px-3 py-2 border border-dashed border-[var(--border-secondary)] rounded-lg text-sm text-[var(--text-muted)] hover:border-[var(--border-accent)] hover:text-[var(--text-accent)] transition-colors">
                <i class="fas fa-plus mr-2"></i>Add Speaker
            </button>
        </div>
        <div class="p-6 border-t border-[var(--border-primary)] flex justify-end gap-3">
            <button @click="closeEditSpeakersModal" class="px-4 py-2 text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)] rounded-lg transition-colors">
                Cancel
            </button>
            <button @click="saveEditingSpeakers" class="px-4 py-2 bg-[var(--bg-button)] text-[var(--text-button)] rounded-lg hover:bg-[var(--bg-button-hover)] transition-colors">
                Save Changes
            </button>
        </div>
    </div>
</div>
