/**
 * 4MUR Global Interactions & Animation System
 * Covers micro-interactions, layout glitch fixes, page transitions, and focus states.
 */

/* ═══════════════════════════════════════════════════════════════════════════
   1. PAGE TRANSITIONS
   — NEVER use transform on body/html — it breaks position:fixed for
     ALL descendants (back-to-top, chat widget, modals, etc.)
   ═══════════════════════════════════════════════════════════════════════════ */
body {
    animation: fadePageIn 0.3s ease forwards;
}

@keyframes fadePageIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Page exit state (applied via JS before navigation) */
body.page-exit {
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* ═══════════════════════════════════════════════════════════════════════════
   2. BUTTON MICRO-INTERACTIONS
   ═══════════════════════════════════════════════════════════════════════════ */
button, .btn, .mr-btn {
    transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1), 
                box-shadow 0.2s cubic-bezier(0.25, 0.8, 0.25, 1),
                background-color 0.2s ease,
                filter 0.2s ease !important;
    will-change: transform, opacity;
}

button:hover:not(:disabled), 
.btn:hover:not(.disabled):not(:disabled),
.mr-btn:hover:not(.disabled):not(:disabled) {
    transform: translateY(-2px);
    filter: brightness(1.05);
}

button:active:not(:disabled), 
.btn:active:not(.disabled):not(:disabled),
.mr-btn:active:not(.disabled):not(:disabled) {
    transform: scale(0.97) translateY(0);
    filter: brightness(0.95);
    transition: transform 0.1s ease;
}

/* Disabled states explicitly visible */
button:disabled, .btn:disabled, .mr-btn:disabled,
button.disabled, .btn.disabled, .mr-btn.disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none !important;
    filter: grayscale(100%);
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. CARD & ELEMENT LIFT
   ═══════════════════════════════════════════════════════════════════════════ */
.card, .mr-card, .hover-lift {
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), 
                box-shadow 0.3s cubic-bezier(0.25, 0.8, 0.25, 1) !important;
    will-change: transform, box-shadow;
}

.card:hover:not(.no-hover), 
.mr-card:hover:not(.no-hover), 
.hover-lift:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08) !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   4. FORM FOCUS & INTERACTION
   ═══════════════════════════════════════════════════════════════════════════ */
input, select, textarea, .form-control, .form-select {
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus, select:focus, textarea:focus, 
.form-control:focus, .form-select:focus {
    border-color: var(--sw-primary, #0d6efd) !important;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.15) !important;
    transform: translateY(-1px);
    outline: none !important;
}

/* Error states and Shake animation */
.is-invalid, .has-error {
    animation: formShake 0.4s cubic-bezier(.36,.07,.19,.97) both;
    border-color: var(--sw-danger, #dc3545) !important;
}

@keyframes formShake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
}

/* ═══════════════════════════════════════════════════════════════════════════
   5. LINK INTERACTIONS
   ═══════════════════════════════════════════════════════════════════════════ */
a.smooth-link {
    position: relative;
    text-decoration: none;
    color: inherit;
    transition: color 0.2s ease;
}

a.smooth-link::after {
    content: '';
    position: absolute;
    width: 100%;
    transform: scaleX(0);
    height: 2px;
    bottom: -2px;
    left: 0;
    background-color: var(--sw-primary, #0d6efd);
    transform-origin: bottom right;
    transition: transform 0.25s ease-out;
}

a.smooth-link:hover::after {
    transform: scaleX(1);
    transform-origin: bottom left;
}

/* ═══════════════════════════════════════════════════════════════════════════
   6. UI GLITCH FIXES & PERFORMANCE
   ═══════════════════════════════════════════════════════════════════════════ */
/* Fix dropdowns and modals from flickering */
.dropdown-menu, .modal-content {
    animation: popIn 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: top;
    will-change: transform, opacity;
}

@keyframes popIn {
    0% { opacity: 0; transform: scaleY(0.95) translateY(-5px); }
    100% { opacity: 1; transform: scaleY(1) translateY(0); }
}

/* Fix missing overflow logic to prevent horizontal scroll layout thrashing */
html, body {
    overflow-x: hidden;
    scroll-behavior: smooth; /* Smooth anchor scrolling */
}

/* GPU acceleration for heavy elements */
.gpu-accel {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   7. MOBILE TOUCH FEEDBACK
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Disable hover-only effects that stick on mobile */
    button:hover:not(:disabled), 
    .btn:hover:not(.disabled):not(:disabled),
    .mr-btn:hover:not(.disabled):not(:disabled) {
        transform: none;
    }
    
    .card:hover:not(.no-hover), 
    .mr-card:hover:not(.no-hover), 
    .hover-lift:hover {
        transform: none;
    }

    /* Emphasize active states for touch feedback */
    button:active, a:active, .card:active {
        transform: scale(0.98) !important;
        transition: transform 0.1s ease !important;
    }

    /* Remove annoying blue tap highlight on mobile */
    * {
        -webkit-tap-highlight-color: transparent;
    }
}
