/**
 * Anti-flicker CSS to prevent content jumping and layout shifts
 */

/* Hide elements until fully loaded */
.js-loading {
  visibility: hidden !important;
  opacity: 0 !important;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.js-loaded {
  visibility: visible !important;
  opacity: 1 !important;
}

/* Prevent layout shift for vehicle container */
#vehicle-options-container {
  min-height: 400px;
  position: relative;
}

/* Loading spinner styles */
.md-loading-vehicles {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 20px;
}

.md-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 10px;
  border: 3px solid rgba(0,0,0,0.1);
  border-top-color: #c22055;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Prevent accordion jumping */
.md-accordion {
  will-change: height;
  transition: height 0.3s ease;
}

.md-accordion-content {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  max-height: 0;
  opacity: 0;
}

.md-accordion.active .md-accordion-content {
  max-height: 2000px;
  opacity: 1;
}

/* Prevent form input jumping */
.md-input-group {
  position: relative;
  min-height: 56px;
}

.md-label {
  transition: all 0.2s ease;
  pointer-events: none;
}

/* Prevent button flickering */
.md-button {
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Prevent image loading flicker */
img {
  display: block;
  max-width: 100%;
  height: auto;
  background: #f5f5f5;
}

/* Smooth page load */
body {
  animation: fadeIn 0.3s ease;
}

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

/* Prevent modal flicker */
.md-modal {
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.md-modal.show {
  display: block;
  opacity: 1;
}

/* Skeleton loading for vehicles */
.vehicle-skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: 8px;
  height: 120px;
  margin-bottom: 16px;
}

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

/* Prevent font loading flicker */
.md-body {
  font-display: swap;
}

/* Hardware acceleration for smooth animations */
.md-accordion,
.md-accordion-content,
.md-button,
.md-modal {
  transform: translateZ(0);
  will-change: transform, opacity;
}

/* Prevent select dropdown flicker */
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.7em center;
  background-size: 1.2em;
  padding-right: 2.5em;
}

/* Disable animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}