/**
 * ═══════════════════════════════════════════════════════════════════
 * LEXOR LUXURY REDESIGN - Part 5: Additional Animation Fixes
 * ═══════════════════════════════════════════════════════════════════
 */

/* ==================== PREVENT ANIMATION GLITCHES ==================== */

/* Ensure modal container doesn't cause layout shifts during animations */
#modal-container {
    pointer-events: none;
}

#modal-container > * {
    pointer-events: auto;
}

/* Prevent double-click issues on modal buttons */
.modal-backdrop button,
.document-viewer-overlay button,
.folder-explorer-overlay button {
    pointer-events: auto;
    user-select: none;
}

/* Smooth button state transitions */
button {
    transition: all 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

button:active {
    transform: scale(0.95);
}

/* Prevent animation stacking */
.closing {
    pointer-events: none !important;
}

.closing * {
    pointer-events: none !important;
}

/* ==================== FILE EXPLORER BUTTON TEXT ALIGNMENT ==================== */

/* Ensure text and icons are properly centered */
.folder-explorer-btn {
    text-align: center;
    vertical-align: middle;
    line-height: 1.2;
}

/* X button specific centering */
.folder-explorer-btn.close-btn,
.modal-close,
.doc-viewer-btn.close-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1;
    font-size: 18px;
}

/* ==================== CHAT POPUP SPECIFIC FIXES ==================== */

/* Ensure chat popup has proper opening and closing animations */
#chat-expand-overlay {
    animation: fadeIn 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

#chat-expand-overlay .document-viewer-window {
    animation: modalSlideUp 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

#chat-expand-overlay.closing {
    animation: fadeOut 0.3s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

#chat-expand-overlay.closing .document-viewer-window {
    animation: modalSlideDown 0.3s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

/* ==================== BUDGET STATS MODAL FIX ==================== */

/* Prevent glitchy open/close on budget stats */
#budget-stats-btn {
    position: relative;
}

#budget-stats-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Debounce visual feedback */
#budget-stats-btn:active::after {
    background: rgba(107, 124, 255, 0.1);
    animation: buttonPress 0.2s ease;
}

@keyframes buttonPress {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

/* ==================== GENERAL BUTTON IMPROVEMENTS ==================== */

/* Prevent button spam clicks */
button[disabled],
button.loading {
    pointer-events: none;
    opacity: 0.6;
    cursor: not-allowed;
}

/* Smooth hover transitions for all interactive elements */
.folder-explorer-btn,
.doc-viewer-btn,
.file-editor-btn,
.secondary-btn,
.primary-btn,
.ai-btn {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ==================== FIX RAPID MODAL OPENING ==================== */

/* Prevent interaction during closing - pointer-events only */
.modal-backdrop.closing {
    pointer-events: none !important;
}

/* ==================== DOCUMENT/FOLDER VIEWER IMPROVEMENTS ==================== */

/* Ensure proper layering during animations */
.document-viewer-overlay,
.folder-explorer-overlay,
.file-editor-overlay {
    z-index: 1000;
}

.document-viewer-overlay.closing,
.folder-explorer-overlay.closing,
.file-editor-overlay.closing {
    z-index: 999; /* Lower priority when closing */
}

/* ==================== LOADING OVERLAY IMPROVEMENTS ==================== */

/* Ensure loading overlays don't interfere with closing animations */
#loading-overlay,
#canvas-overlay {
    pointer-events: auto;
    z-index: 99999 !important; /* FORCE above modals */
}

#loading-overlay.hidden,
#canvas-overlay.hidden {
    pointer-events: none;
}

/* ==================== SMOOTH SCROLL ANIMATIONS ==================== */

/* Smooth scrolling in modals */
.document-viewer-content,
.folder-explorer-content,
.chat-messages,
.expanded-chat-messages {
    scroll-behavior: smooth;
}

/* ==================== PREVENT TEXT SELECTION DURING ANIMATIONS ==================== */

.closing {
    user-select: none;
    -webkit-user-select: none;
}

/* ==================== GPU ACCELERATION ==================== */

/* Force GPU acceleration for smooth animations */
.modal-backdrop,
.modal,
.document-viewer-overlay,
.document-viewer-window,
.folder-explorer-overlay,
.folder-explorer-window,
#chat-expand-overlay {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}
