/* ============================================
   SMOOTH PAGE TRANSITIONS
   Eliminates shake, jerk, and wave-like movements
   ============================================ */

/* Prevent layout shifts and reflow */
html {
    scroll-behavior: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    /* Prevent jerky movements */
    overflow-x: hidden;
    position: relative;
    min-height: 100vh;
    /* Smooth rendering — no perspective/transform (breaks position:fixed header) */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* Smooth page transition overlay */
.page-transition-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 9998;
    /* Below header overlays but still high */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-transition-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Smooth fade transition for page content */
.page-content {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.page-content.loading {
    opacity: 0;
    transform: translateY(10px);
}

.page-content.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Prevent layout shifts during load */
* {
    box-sizing: border-box;
}

/* Smooth image loading */
img {
    max-width: 100%;
    height: auto;
    display: block;
    /* Prevent layout shift */
    opacity: 1;
    /* FIXED: Default to visible to prevent invisible images if JS fails */
    transition: opacity 0.3s ease;
}

img, img.loaded { opacity: 1 !important; visibility: visible !important; }

/* Smooth link transitions */
a {
    transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
    text-decoration: none;
}

a:hover {
    transform: translateY(-1px);
}

a:active {
    transform: translateY(0);
}

/* Smooth button transitions */
button,
.button,
input[type="submit"],
input[type="button"] {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

button:hover,
.button:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    transform: translateY(-2px) translateZ(0);
    -webkit-transform: translateY(-2px) translateZ(0);
}

button:active,
.button:active,
input[type="submit"]:active,
input[type="button"]:active {
    transform: translateY(0) translateZ(0);
    -webkit-transform: translateY(0) translateZ(0);
}

/* Smooth form element transitions */
input,
textarea,
select {
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

input:focus,
textarea:focus,
select:focus {
    transform: translateZ(0) scale(1.01);
    -webkit-transform: translateZ(0) scale(1.01);
}

/* Prevent jerky scroll — instant scroll on all viewports */
html,
body,
* {
    scroll-behavior: auto !important;
}

/* Smooth container transitions */
.container,
.container-fluid,
section,
article {
    transition: opacity 0.3s ease;
}

/* Eliminate wave-like animations */
@keyframes smoothFadeIn {
    from {
        opacity: 0;
        transform: translateY(0) translateZ(0);
    }

    to {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

@keyframes smoothSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px) translateZ(0);
    }

    to {
        opacity: 1;
        transform: translateX(0) translateZ(0);
    }
}

/* Smooth modal transitions */
.modal,
.popup,
.overlay {
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Prevent layout shifts from dynamic content */
.dynamic-content {
    min-height: 50px;
    transition: opacity 0.3s ease, min-height 0.3s ease;
}

/* Smooth navigation transitions */
nav,
.navbar,
.navigation {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Smooth header transitions */
header {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* Smooth footer transitions */
footer {
    transition: opacity 0.3s ease;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Eliminate shake on hover */
*:hover {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Smooth table transitions */
table {
    transition: opacity 0.3s ease;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Smooth card transitions */
.card,
.panel,
.box {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.card:hover,
.panel:hover,
.box:hover {
    transform: translateY(-4px) translateZ(0);
    -webkit-transform: translateY(-4px) translateZ(0);
}

/* Prevent jerky animations */
@keyframes noShake {
    from {
        transform: translateZ(0);
    }

    to {
        transform: translateZ(0);
    }
}

/* Smooth loading states */
.loading,
.spinner {
    animation: smoothSpin 0.8s linear infinite;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

@keyframes smoothSpin {
    from {
        transform: rotate(0deg) translateZ(0);
    }

    to {
        transform: rotate(360deg) translateZ(0);
    }
}

/* GPU acceleration for smooth transitions */
.smooth-transition {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
}

/* Prevent reflow on page load */
body.loading {
    overflow: hidden;
}

body.loaded {
    overflow: auto;
}

/* Smooth page change indicator */
.page-change-indicator {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, #667eea, #764ba2);
    z-index: 10000;
    transition: width 0.3s ease;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

/* Mobile optimizations */
@media (max-width: 768px) {

    /* Reduce transitions on mobile for better performance */
    * {
        transition-duration: 0.2s !important;
    }

    /* Prevent layout shifts */
    body {
        -webkit-overflow-scrolling: touch;
    }
}

/* Print styles - no transitions */
@media print {
    * {
        transition: none !important;
        animation: none !important;
    }
}