  // Reset file input to allow selecting files again
        fileInput.value = '';
        fileInfo.classList.add('hidden');
        
      } catch (error) {
        console.error('Upload failed:', error);
        alert('Upload failed. Please try again.');
        buttonText.textContent = 'Upload File';
      } finally {
        uploadButton.disabled = false;
        uploadIcon.classList.remove('hidden');
        loadingIcon.classList.add('hidden');
        es.close();
        
        // Re-enable file sel