/* Preloader Styles - Optimized for performance */
/* Hide main content initially to prevent FOUC */
main {
  visibility: hidden !important;
  opacity: 0 !important;
  transform: translateY(10px) !important;
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s !important;
}

/* Only show main content when preloader is hidden and body has content-loaded class */
body.content-loaded main {
  visibility: visible !important;
  opacity: 1 !important;
  transform: translateY(0) !important;
}

.preloader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #f5f8ff 0%, #ffffff 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  will-change: opacity;
}

.preloader-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.preloader-logo {
  width: 120px;
  height: 120px;
  margin-bottom: 20px;
  transform-origin: center;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 0 10px rgba(44, 114, 194, 0.2));
}

.preloader-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Enhanced Pulse animation for the logo */
.preloader-logo.pulse-animation {
  animation: enhancedLogoPulse 1.5s ease-in-out infinite;
}

@keyframes enhancedLogoPulse {
  0% {
    transform: scale(1);
    filter: drop-shadow(0 0 10px rgba(44, 114, 194, 0.2));
  }
  50% {
    transform: scale(1.08);
    filter: drop-shadow(0 0 15px rgba(44, 114, 194, 0.5));
  }
  100% {
    transform: scale(1);
    filter: drop-shadow(0 0 10px rgba(44, 114, 194, 0.2));
  }
}

/* SVG specific animations */
.preloader-logo svg circle:first-child {
  animation: colorPulse 3s ease-in-out infinite;
}

@keyframes colorPulse {
  0% {
    fill: #2C72C2;
  }
  50% {
    fill: #3a7fd0;
  }
  100% {
    fill: #2C72C2;
  }
}

.preloader-logo svg path {
  animation: pathGlow 2s ease-in-out infinite alternate;
}

@keyframes pathGlow {
  0% {
    opacity: 0.6;
  }
  100% {
    opacity: 0.9;
  }
}

.preloader-spinner {
  position: relative;
  width: 200px;
  height: 200px;
}

.circle {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 4px solid transparent;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
}

.circle-1 {
  border-top-color: #FFD700; /* Gold for prosperity */
  animation: spin 2s linear infinite;
}

.circle-2 {
  border-right-color: #2C5F43; /* IYC Green */
  animation: spin 1.5s linear infinite reverse;
  width: 175px;
  height: 175px;
  top: 12.5px;
  left: 12.5px;
}

.circle-3 {
  border-bottom-color: #E74C3C; /* Red for power */
  animation: spin 1.2s linear infinite;
  width: 150px;
  height: 150px;
  top: 25px;
  left: 25px;
}

.circle-4 {
  border-left-color: #2ECC71; /* Green for growth */
  animation: spin 2.5s linear infinite reverse;
  width: 125px;
  height: 125px;
  top: 37.5px;
  left: 37.5px;
}

.circle-5 {
  border-top-color: #9B59B6; /* Purple for innovation */
  animation: spin 1.8s linear infinite;
  width: 100px;
  height: 100px;
  top: 50px;
  left: 50px;
}

.preloader-text {
  margin-top: 30px;
  font-family: 'Poppins', sans-serif;
  color: #2C72C2;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  opacity: 0.9;
  animation: fadeInOut 1.5s ease-in-out infinite;
  background: linear-gradient(to right, #2C72C2, #0a4b94, #2C72C2);
  background-size: 200% auto;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: textShine 3s linear infinite;
}

.preloader-progress {
  width: 240px;
  height: 4px;
  background: rgba(44, 114, 194, 0.1);
  border-radius: 10px;
  margin-top: 20px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: #55AF47;
  border-radius: 10px;
  will-change: width;
  transform: translateZ(0);
}

.particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  opacity: 0.4;
}

.particle {
  position: absolute;
  display: block;
  width: 6px;
  height: 6px;
  background: rgba(44, 114, 194, 0.15);
  border-radius: 50%;
  animation: moveParticles 10s linear infinite;
  box-shadow: 0 0 5px rgba(44, 114, 194, 0.2);
}

.preloader-pattern {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  opacity: 0.03;
  mix-blend-mode: multiply;
}

.world-map {
  position: absolute;
  width: 120%;
  height: 120%;
  top: -10%;
  left: -10%;
  opacity: 0.05;
  animation: rotateMap 60s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

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

@keyframes fadeInOut {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

@keyframes gradientMove {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes moveParticles {
  0% {
    transform: translateY(0) translateX(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-100vh) translateX(100vw);
    opacity: 0;
  }
}

@keyframes textShine {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}

@keyframes flagPulse {
  0% {
    transform: scale(1);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.5);
    opacity: 0.8;
  }
  100% {
    transform: scale(1);
    opacity: 0.3;
  }
}

@keyframes rotateMap {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.preloader.fade-out {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.preloader.hidden {
  display: none;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .preloader-logo {
    animation: none;
  }
  
  .progress-bar {
    transition: none;
  }
  
  .preloader.fade-out {
    transition: none;
  }
}

/* Mobile specific optimizations */
@media (max-width: 768px) {
  .preloader-spinner {
    width: 150px;
    height: 150px;
  }
  
  .circle {
    border-width: 3px;
  }
  
  .circle-2 {
    width: 130px;
    height: 130px;
    top: 10px;
    left: 10px;
  }
  
  .circle-3 {
    width: 110px;
    height: 110px;
    top: 20px;
    left: 20px;
  }
  
  .circle-4 {
    width: 90px;
    height: 90px;
    top: 30px;
    left: 30px;
  }
  
  .circle-5 {
    width: 70px;
    height: 70px;
    top: 40px;
    left: 40px;
  }
  
  .preloader-logo {
    width: 100px;
    height: 100px;
  }
  
  .preloader-text {
    font-size: 12px;
  }
  
  .preloader-progress {
    width: 200px;
  }
  
  /* Reduce number of particles on mobile */
  .particle:nth-child(3n+1) {
    display: none;
  }
  
  /* Use simpler animations on mobile */
  .circle-1 {
    animation-duration: 3s;
  }
  
  .circle-2 {
    animation-duration: 2.5s;
  }
  
  .circle-3 {
    animation-duration: 2s;
  }
  
  .circle-4 {
    animation-duration: 3.5s;
  }
  
  .circle-5 {
    animation-duration: 3s;
  }
}

/* Small mobile devices */
@media (max-width: 480px) {
  .preloader-spinner {
    width: 120px;
    height: 120px;
  }
  
  .circle {
    border-width: 2px;
  }
  
  .circle-2 {
    width: 105px;
    height: 105px;
    top: 7.5px;
    left: 7.5px;
  }
  
  .circle-3 {
    width: 90px;
    height: 90px;
    top: 15px;
    left: 15px;
  }
  
  .circle-4 {
    width: 75px;
    height: 75px;
    top: 22.5px;
    left: 22.5px;
  }
  
  .circle-5 {
    width: 60px;
    height: 60px;
    top: 30px;
    left: 30px;
  }
  
  .preloader-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 15px;
  }
  
  .preloader-text {
    font-size: 10px;
    letter-spacing: 2px;
  }
  
  .preloader-progress {
    width: 180px;
    height: 3px;
  }
  
  /* Further reduce particles on small devices */
  .particle:nth-child(2n+1) {
    display: none;
  }
}

/* Mobile navbar width fix */
@media screen and (max-width: 768px) {
  /* Fix navbar container */
  nav {
    box-sizing: border-box !important;
    max-width: 100vw !important;
    width: 100vw !important;
    overflow-x: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Fix navbar inner containers */
  nav > div {
    box-sizing: border-box !important;
    max-width: 100vw !important;
    width: 100% !important;
    overflow-x: hidden !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
  }
  
  /* Fix mobile menu */
  #menu {
    box-sizing: border-box !important;
    max-width: 100vw !important;
    width: 100vw !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    left: 0 !important;
  }
  
  /* Fix all sections for mobile */
  section {
    box-sizing: border-box !important;
    max-width: 100vw !important;
    width: 100vw !important;
    overflow-x: hidden !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  /* Fix main containers within sections */
  section > main,
  section .w-\[90vw\] {
    box-sizing: border-box !important;
    max-width: 100vw !important;
    width: 100% !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  
  /* Fix all cooperation cards and content areas */
  .cooperation-card,
  .card-content,
  .light-hero,
  .enhanced-about-container,
  .gallery-container,
  .resource-cards,
  .countries-container {
    box-sizing: border-box !important;
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
  }
  
  /* Ensure text doesn't overflow on mobile */
  h1, h2, h3, p {
    max-width: 100% !important;
    overflow-wrap: break-word !important;
    word-wrap: break-word !important;
  }
  
  /* Fix dropdown buttons - override any inline styles */
  .mobile-dropdown-btn {
    box-sizing: border-box !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-direction: row !important;
    cursor: pointer !important;
    padding: 14px 16px !important;
    margin-bottom: 8px !important;
    background-color: #f9fafb !important;
    border-radius: 10px !important;
    font-weight: 500 !important;
    color: #1f2937 !important;
    transition: all 0.3s ease !important;
    flex-wrap: nowrap !important;
    position: relative !important;
    padding-right: 40px !important; /* Extra padding on right to accommodate arrow */
  }
  
  /* Make dropdown button contents properly aligned in a row */
  .mobile-dropdown-btn > div {
    display: flex !important;
    align-items: center !important;
    flex: 1 !important;
    min-width: 0 !important; /* Allow content to shrink if needed */
    overflow: hidden !important;
  }
  
  /* Fix icon in dropdown button */
  .mobile-dropdown-btn i {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-right: 0.5rem !important;
    width: 24px !important;
    flex-shrink: 0 !important;
  }
  
  /* Ensure text in dropdown doesn't overflow */
  .mobile-dropdown-btn span {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    max-width: 100% !important;
  }
  
  .mobile-dropdown-btn:active {
    background-color: #f3f4f6 !important;
  }
  
  /* Override space-x-2 which can cause overflow */
  .space-x-2 > *:not(:last-child) {
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
  }
  
  /* Make sure SVG icons are on the right */
  .mobile-dropdown-btn svg {
    flex-shrink: 0 !important;
    min-width: 20px !important;
    min-height: 20px !important;
    width: 20px !important;
    height: 20px !important;
    position: absolute !important;
    right: 16px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
  }
  
  /* Dropdown icon rotation */
  .mobile-dropdown-btn svg.rotate-180 {
    transform: translateY(-50%) rotate(180deg) !important;
  }
  
  /* Fix dropdowns */
  .mobile-dropdown {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    transition: max-height 0.3s ease !important;
  }
  
  /* Fix dropdown links */
  .mobile-dropdown a {
    box-sizing: border-box !important;
    width: 100% !important;
    display: block !important;
  }
  
  /* Prevent horizontal scrolling on body */
  body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    width: 100vw !important;
    margin: 0 !important;
  }
  
  /* Fix main container width */
  main.body {
    max-width: 100vw !important;
    width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
  }
  
  /* Fix card layouts on mobile */
  .cooperation-card {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  
  /* Mobile menu toggle button */
  .menu-toggle {
    cursor: pointer !important;
    z-index: 99 !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    outline: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    touch-action: manipulation !important;
  }
  
  /* Make toggle button tappable area larger on mobile */
  .menu-toggle svg {
    display: block !important;
    pointer-events: none !important;
  }
  
  button.menu-toggle {
    padding: 8px !important;
  }
}