/* Performance + flow tweaks layered on top of Next.js output */
:root {
  --rumsa-section-min-height: 100vh;
}

/* Prevent heavy sections from blocking initial paint */
:where(.hero, section, footer) {
  content-visibility: auto;
  contain-intrinsic-size: var(--rumsa-section-min-height);
  contain: layout style paint;
}

/* Optimize rendering for off-screen content */
:where(.hero, section, footer):not(:target) {
  content-visibility: auto;
}

/* Mobile-specific optimizations */
@media (max-width: 768px) {
  :where(.hero, section) {
    contain-intrinsic-size: 60vh;
  }
  
  /* Reduce repaints on mobile */
  * {
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Optimize scrolling performance */
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Reduce shadow complexity on mobile */
  :where(.mesa-card, .service-card, .project-card) {
    box-shadow: 0 8px 16px rgba(15, 27, 61, 0.1) !important;
  }
}

/* smoother anchor jumps */
[id] {
  scroll-margin-top: 120px;
  scroll-padding-top: 120px;
}

/* Prevent layout shift - ensure images have dimensions */
img {
  max-width: 100%;
  height: auto;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Optimize iframe loading */
iframe {
  max-width: 100%;
  border: 0;
}

/* Optimize scroll performance */
html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

.section-subtitle {
  white-space: normal !important;
  text-wrap: balance;
}

nav a.active {
  color: #f39c12 !important;
}

.hero-bg-slide {
  opacity: 0;
  transition: opacity 0.6s ease, transform 0.6s ease;
  background-size: cover;
  background-position: center;
  will-change: opacity, transform;
  transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  /* GPU acceleration */
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
}

.hero-bg-slide.is-loaded {
  opacity: 1;
}

.hero-bg-slide.is-priority {
  opacity: 1;
  transform: scale(1.02);
}

/* Global motion safeguards */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .hero-bg-slide {
    transition: none;
  }
}

/* Performance: Reduce paint complexity */
* {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Optimize animations with GPU acceleration */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reduce animation complexity on low-end devices */
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
  @media (max-resolution: 1.5dppx) {
    * {
      animation-duration: 0.3s !important;
      transition-duration: 0.2s !important;
    }
  }
}

/* Card grid flow */
.services-grid,
.projects-grid,
.contact-values,
.contact-info {
  gap: clamp(16px, 3vw, 32px) !important;
}

:where(.mesa-card, .service-card, .project-card, .contact-card, .value-card) {
  will-change: transform, box-shadow;
  transform: translateZ(0);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  scroll-margin-top: 120px;
  contain: layout style paint;
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:where(.mesa-card, .service-card, .project-card, .contact-card, .value-card):hover {
  transform: translateY(-6px);
  box-shadow: 0 14px 28px rgba(15, 27, 61, 0.15);
}

:where(.mesa-card, .service-card, .project-card, .contact-card, .value-card).is-active {
  transform: translateY(-4px);
  box-shadow: 0 18px 32px rgba(15, 27, 61, 0.18);
}

:where(.mesa-card, .service-card, .project-card, .contact-card, .value-card):focus-visible {
  outline: 2px solid rgba(255, 195, 0, 0.8);
  outline-offset: 4px;
}

.mesa-card[style*="position:fixed"] {
  width: min(640px, calc(100vw - 48px)) !important;
  height: auto !important;
  max-height: min(85vh, 760px) !important;
  overflow-y: auto !important;
  margin: 0 auto !important;
  left: 50% !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translate3d(-50%, -50%, 0) !important;
  padding: clamp(28px, 3vw, 40px) !important;
}

.mesa-card[style*="position:fixed"]::-webkit-scrollbar {
  width: 6px;
}

.mesa-card[style*="position:fixed"]::-webkit-scrollbar-thumb {
  background: rgba(44, 62, 80, 0.3);
  border-radius: 999px;
}

/* Keep form usable on mobile */
.contact-form form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.contact-form .form-row {
  gap: 15px;
}

/* Lazy loaded images optimization */
img[loading="lazy"] {
  content-visibility: auto;
}

/* Font loading optimization */
@font-face {
  font-display: swap;
}

/* Mobile touch optimizations */
@media (max-width: 768px) {
  * {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  
  /* Reduce animations on mobile for better performance */
  :where(.mesa-card, .service-card, .project-card, .contact-card, .value-card) {
    transition-duration: 0.15s;
  }
  
  /* Optimize scrolling on mobile */
  body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  
  /* Reduce backdrop-filter on mobile (performance) */
  .modal-overlay {
    backdrop-filter: blur(5px);
  }
}

@media (max-width: 640px) {
  .hero-content h1 {
    font-size: clamp(1.8rem, 6vw, 2.4rem);
  }
  .hero-buttons .btn {
    width: 100%;
    justify-content: center;
  }
  
  /* Further reduce animations on small screens */
  * {
    animation-duration: 0.2s !important;
    transition-duration: 0.15s !important;
  }
  
  /* Optimize grid layouts for mobile */
  .services-grid,
  .projects-grid {
    grid-template-columns: 1fr;
  }
}

.cta-lang-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.language-icon-cta {
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  background: #fff;
  color: #2c3e50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.language-icon-cta:hover {
  border-color: #ffc300;
  color: #ffc300;
  box-shadow: 0 4px 15px rgba(255, 195, 0, 0.25);
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 25, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 9999;
  padding: clamp(20px, 4vw, 60px);
  box-sizing: border-box;
  /* GPU acceleration */
  transform: translateZ(0);
  will-change: opacity, backdrop-filter;
  /* Optimize rendering */
  contain: layout style paint;
}

.modal-overlay.is-open {
  display: flex;
}

.modal-window {
  width: min(700px, 100%);
  max-height: min(85vh, 900px);
  background: linear-gradient(145deg, #ffffff, #f8f9fa);
  border-radius: 32px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  box-shadow: 0 35px 70px rgba(9, 16, 32, 0.45);
  position: relative;
  padding: clamp(28px, 3vw, 48px);
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 24px;
  /* GPU acceleration */
  transform: translateZ(0);
  will-change: transform, opacity;
  /* Optimize rendering */
  contain: layout style paint;
  backface-visibility: hidden;
}

.modal-window__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(212, 175, 55, 0.25);
}

.modal-window__title {
  font-size: clamp(1.6rem, 2vw, 2.1rem);
  font-weight: 700;
  color: #1b2744;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-window__close {
  border: none;
  background: rgba(212, 175, 55, 0.15);
  color: #d4af37;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.modal-window__close:hover {
  transform: scale(1.05);
  background: rgba(212, 175, 55, 0.3);
}

.modal-window__body {
  overflow-y: auto;
  padding-right: 12px;
  font-size: 1.1rem;
  line-height: 1.7;
  color: #374259;
}

.modal-window__body::-webkit-scrollbar {
  width: 6px;
}

.modal-window__body::-webkit-scrollbar-thumb {
  background: rgba(23, 37, 84, 0.3);
  border-radius: 999px;
}

.modal-open {
  overflow: hidden;
  padding-right: var(--scrollbar-compensation, 0px);
}

.modal-window__body p {
  margin-bottom: 16px;
}

.modal-window__body p:last-child {
  margin-bottom: 0;
}


.language-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 10px;
}

.language-dropdown__trigger.language-icon-cta {
  margin-left: 0;
}

.language-dropdown__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 35px rgba(15, 27, 61, 0.15);
  padding: 8px;
  display: none;
  min-width: 140px;
  z-index: 50;
}

.language-dropdown.is-open .language-dropdown__menu {
  display: block;
}

.language-dropdown__item {
  width: 100%;
  border: none;
  background: transparent;
  color: #2c3e50;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.language-dropdown__item + .language-dropdown__item {
  margin-top: 4px;
}

.language-dropdown__item:hover {
  background: rgba(255, 195, 0, 0.12);
  color: #d18a00;
}

.language-dropdown__item.is-active {
  background: linear-gradient(135deg, #ffc300, #ff7a00);
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 122, 0, 0.25);
}

.language-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

.language-toggle__label,
.language-toggle__pills {
  display: none !important;
}

.language-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #ffffff, #f4f6fb);
  border-radius: 999px;
  border: 1px solid rgba(44, 62, 80, 0.08);
  box-shadow: 0 12px 24px rgba(15, 27, 61, 0.12);
  margin-left: 16px;
  position: relative;
}

.language-card__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2c3e50;
}

.language-card .language-dropdown__menu {
  right: 8px;
}

@media (max-width: 768px) {
  .language-card {
    margin-left: 8px;
    padding: 8px 10px;
  }
  .language-card__label {
    display: none;
  }
}

.language-icon-cta {
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  margin-left: 12px;
  background: #fff;
  color: #2c3e50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.language-icon-cta:hover {
  border-color: #ffc300;
  color: #ffc300;
  box-shadow: 0 4px 15px rgba(255, 195, 0, 0.25);
}

