/* Mobile Performance Optimizations */

/* Smooth tab transitions */
.tab-content.active {
    animation: fadeInScale 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.98) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Bottom nav smooth indicator */
.nav-item {
    position: relative;
    overflow: hidden;
}

.nav-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
    transform: scaleX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item.active::after {
    transform: scaleX(1);
}

/* Hardware acceleration for animations */
.vehicle-card,
.threat-card,
.maintenance-card,
.btn,
.icon-btn,
.nav-item,
.bottom-sheet,
.toast {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Optimize font rendering */
body {
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .status-dot {
        animation: none;
    }
    
    .skeleton {
        animation: none;
        background: var(--bg-tertiary);
    }
    
    .pipeline-step {
        transition: none;
    }
    
    .pipeline-step.active {
        transform: none;
    }
}

/* Optimize scrolling performance */
.app-content,
.vehicle-list,
.threat-list,
.maintenance-list,
.bottom-sheet,
.filters,
.pipeline-container {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* Contain layout and paint for better performance */
.vehicle-card,
.threat-card,
.maintenance-card,
.stat-card {
    contain: layout paint;
}

.nav-item {
    contain: layout paint style;
}

/* Optimize images and icons */
.stat-icon,
.pipeline-step i,
.nav-item i {
    contain: strict;
}

/* Lazy loading animations */
.tab-content {
    content-visibility: auto;
}

/* Optimize transitions */
.vehicle-card,
.threat-card,
.maintenance-card {
    transition-property: transform, box-shadow;
    transition-duration: var(--transition-speed);
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

.btn,
.icon-btn {
    transition-property: transform, background-color, opacity;
    transition-duration: var(--transition-speed);
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-item {
    transition-property: color, opacity, transform;
    transition-duration: var(--transition-speed);
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Optimize filter performance */
.filter-select {
    transition-property: border-color, box-shadow;
    transition-duration: var(--transition-speed);
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* GPU-accelerated animations only where needed */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate3d(0, 10px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate3d(0, 20px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.95);
    }
}

/* Optimize bottom sheet animation */
.bottom-sheet {
    transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.bottom-sheet.open {
    will-change: auto;
}

/* Optimize toast animations */
.toast {
    animation: slideUp 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Prevent layout shifts */
.app-header,
.bottom-nav {
    contain: strict;
}

/* Optimize grid layouts */
.stats-grid,
.vehicle-list,
.threat-list,
.maintenance-list {
    contain: layout;
}

/* Optimize flexbox performance */
.header-content,
.vehicle-header,
.threat-header,
.maintenance-header,
.section-header {
    contain: layout style;
}

/* Prevent reflow on hover/active states */
.vehicle-card:active,
.threat-card:active,
.maintenance-card:active {
    will-change: transform;
}

/* Remove will-change after interaction */
.vehicle-card,
.threat-card,
.maintenance-card {
    transition: transform var(--transition-speed), will-change 0s var(--transition-speed);
}

/* Optimize skeleton loading */
.skeleton {
    contain: strict;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Optimize pipeline animation */
.pipeline-step.active {
    animation: pipelineStep 300ms ease-out;
}

@keyframes pipelineStep {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
    100% {
        transform: scale(1.1);
    }
}

/* Battery-friendly animations on low battery */
@media (prefers-reduced-motion: reduce), (prefers-color-scheme: dark) and (max-width: 640px) {
    .status-dot {
        animation-duration: 3s;
    }
    
    .skeleton {
        animation-duration: 2s;
    }
}

/* Optimize for slow connections */
@media (prefers-reduced-data: reduce) {
    .skeleton {
        animation: none;
        background: var(--bg-tertiary);
    }
    
    .status-dot {
        animation: none;
    }
}

/* Reduce GPU usage on older devices */
@media (max-width: 360px) {
    .vehicle-card,
    .threat-card,
    .maintenance-card,
    .btn,
    .icon-btn,
    .nav-item {
        will-change: auto;
    }
    
    .tab-content {
        animation: none;
        opacity: 1;
    }
}

/* Optimize scroll performance */
.app-content {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    .app-content {
        scroll-behavior: auto;
    }
}

/* Optimize rendering layers */
.app-header,
.bottom-nav,
.bottom-sheet,
.toast-container {
    isolation: isolate;
}

/* Reduce paint areas */
.stat-icon::before,
.pipeline-step::before {
    content: none;
}

/* Optimize z-index stacking */
.app-header { z-index: 100; }
.offline-banner { z-index: 150; }
.bottom-sheet { z-index: 200; }
.toast-container { z-index: 300; }
.demo-notice { z-index: 50; }

/* Prevent text selection on UI elements */
.app-header,
.bottom-nav,
.stat-card,
.demo-notice {
    user-select: none;
    -webkit-user-select: none;
}

/* Enable text selection on content */
.vehicle-card,
.threat-card,
.maintenance-card,
.bottom-sheet-content {
    user-select: text;
    -webkit-user-select: text;
}

/* Optimize list rendering */
.vehicle-list > *,
.threat-list > *,
.maintenance-list > * {
    contain: content;
}

/* Optimize icon rendering */
i {
    display: inline-block;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Optimize button states */
button:disabled,
.btn:disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed;
}

/* Reduce repaints during scroll */
.app-header,
.bottom-nav {
    pointer-events: auto;
}

.app-content {
    pointer-events: auto;
}

/* Optimize touch interactions */
* {
    -webkit-tap-highlight-color: transparent;
}

button,
.btn,
.nav-item {
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.1);
}

/* Optimize for high refresh rate displays */
@media (min-resolution: 120dpi) {
    .vehicle-card,
    .threat-card,
    .maintenance-card,
    .btn,
    .icon-btn,
    .nav-item {
        transition-duration: 150ms;
    }
}
