@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';

@layer base {
  :root {
    --background: 240 249 255;
    --foreground: 15 23 42;
    --card: 255 255 255;
    --card-foreground: 15 23 42;
    --popover: 255 255 255;
    --popover-foreground: 15 23 42;
    --primary: 37 99 235;
    --primary-foreground: 240 249 255;
    --secondary: 56 189 248;
    --secondary-foreground: 15 23 42;
    --muted: 241 245 249;
    --muted-foreground: 100 116 139;
    --accent: 2 132 199;
    --accent-foreground: 240 249 255;
    --destructive: 239 68 68;
    --destructive-foreground: 255 255 255;
    --border: 226 232 240;
    --input: 226 232 240;
    --ring: 37 99 235;
    --radius: 0.5rem;
  }

  /* Optimize lazy loading images */
  /* Ensure images are visible by default; JS will still add a smooth fade-in */
  img[loading="lazy"] {
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
  }
  
  img.loaded {
    opacity: 1;
  }
  
  /* Prevent layout shift during image loading */
  .portfolio-image-container {
    position: relative;
    overflow: hidden;
    height: 192px; /* match h-48 to ensure visible area after skeleton hides */
  }
  
  .portfolio-image-container::before {
    content: '';
    display: block;
    width: 100%;
    height: 192px; /* h-48 equivalent */
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
  }
  
  @keyframes loading {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }
  
  .portfolio-image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .dark {
    --background: 15 23 42;
    --foreground: 226 232 240;
    --card: 30 41 59;
    --card-foreground: 226 232 240;
    --popover: 30 41 59;
    --popover-foreground: 226 232 240;
    --primary: 56 189 248;
    --primary-foreground: 15 23 42;
    --secondary: 37 99 235;
    --secondary-foreground: 240 249 255;
    --muted: 51 65 85;
    --muted-foreground: 148 163 184;
    --accent: 14 165 233;
    --accent-foreground: 240 249 255;
    --destructive: 239 68 68;
    --destructive-foreground: 255 255 255;
    --border: 51 65 85;
    --input: 51 65 85;
    --ring: 56 189 248;
  }
}

@layer base {
  * {
    @apply border-[rgb(var(--border))];
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  html {
    scroll-behavior: smooth;
  }

  body {
    @apply bg-background text-foreground pt-16;
    background: linear-gradient(135deg, 
      rgb(240, 249, 255) 0%,
      rgb(224, 242, 254) 50%,
      rgb(186, 230, 253) 100%
    );
    color: rgb(var(--foreground));
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .dark body {
    background: linear-gradient(135deg,
      rgb(15, 23, 42) 0%,
      rgb(30, 41, 59) 50%,
      rgb(51, 65, 85) 100%
    );
  }

  /* Performance optimizations */
  img {
    max-width: 100%;
    height: auto;
    display: block;
  }

  a {
    text-decoration: none;
    color: inherit;
  }

  button {
    cursor: pointer;
  }

  /* Reduce motion */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer components {
  .container {
    @apply mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl;
  }

  .btn-primary {
    @apply inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 bg-primary text-primary-foreground shadow hover:bg-primary/90 h-10 px-4 py-2;
  }

  .btn-secondary {
    @apply inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground h-10 px-4 py-2;
  }

  .card {
    @apply rounded-lg border bg-card text-card-foreground shadow-sm;
  }

  .section-title {
    @apply text-3xl font-bold tracking-tight sm:text-4xl;
  }

  .section-subtitle {
    @apply max-w-[700px] text-muted-foreground md:text-xl;
  }

  /* Navbar Styles */
  header {
    @apply fixed top-0 left-0 right-0 z-50 backdrop-blur-sm border-b border-[rgb(var(--border))] bg-background/70;
    transition: all 0.3s ease;
  }

  header.scrolled {
    @apply shadow-md backdrop-blur-md bg-background/90;
  }

  /* Container styles */
  header .container {
    @apply h-14 md:h-16 lg:h-20 mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl flex items-center justify-between;
  }

  /* Logo Styles */
  .logo {
    @apply font-bold flex items-center gap-2 hover:text-primary transition-colors shrink-0;
  }

  .logo span {
    font-size: clamp(1rem, 2.5vw, 1.25rem);
  }

  .logo i {
    @apply text-primary transition-colors;
    font-size: clamp(1.25rem, 3vw, 1.75rem);
  }

  /* Desktop Navigation */
  nav.md\:flex {
    @apply items-center ml-4 lg:ml-8 flex-1;
  }

  nav.md\:flex .nav-link {
    @apply relative py-2 transition-colors hover:text-primary font-medium text-center;
    padding-left: clamp(0.5rem, 1.5vw, 1rem);
    padding-right: clamp(0.5rem, 1.5vw, 1rem);
    font-size: clamp(0.875rem, 1.8vw, 1rem);
  }

  nav.md\:flex .nav-link::after {
    content: '';
    @apply absolute bottom-0 left-0 w-0 h-0.5 bg-primary transition-all duration-300;
  }

  nav.md\:flex .nav-link:hover::after {
    @apply w-full;
  }

  /* Controls Section */
  .controls-section {
    @apply flex items-center;
  }

  /* Theme and Language Controls */
  .theme-language-controls {
    @apply hidden md:flex items-center;
    gap: clamp(0.25rem, 1vw, 0.75rem);
  }

  .theme-language-controls button {
    @apply flex items-center justify-center transition-all duration-300 hover:bg-accent/10 rounded-xl;
  }

  

  #dark-mode-toggle {
    width: clamp(2.25rem, 4vw, 2.5rem);
    height: clamp(2.25rem, 4vw, 2.5rem);
  }

  #language-switcher {
    height: clamp(2.25rem, 4vw, 2.5rem);
    padding-left: clamp(0.75rem, 1.5vw, 1rem);
    padding-right: clamp(0.75rem, 1.5vw, 1rem);
    font-size: clamp(0.875rem, 1.8vw, 1rem);
  }

  /* Mobile Menu Button */
  #mobile-menu-button {
    @apply md:hidden flex items-center justify-center rounded-xl hover:bg-accent/10 transition-transform duration-300;
    width: 2.5rem;
    height: 2.5rem;
  }

  #mobile-menu-button i {
    font-size: 1.25rem;
    transition: transform 0.3s ease;
  }

  #mobile-menu-button.active i {
    transform: rotate(90deg);
  }

  /* Mobile Menu Styles */
  #mobile-menu {
    @apply fixed inset-0 z-50 bg-background;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
  }

  #mobile-menu.active {
    transform: translateX(0);
    visibility: visible;
  }

  #mobile-menu .container {
    @apply h-full flex flex-col px-4 bg-background;
    height: 100dvh;
    max-width: 100%;
    margin: 0;
  }

  #mobile-menu .header {
    @apply flex justify-between items-center border-b border-[rgb(var(--border))] py-4;
    height: auto;
  }

  #mobile-menu nav {
    @apply flex-1 flex flex-col justify-start overflow-y-auto py-6;
  }

  #mobile-menu .nav-group {
    @apply flex flex-col gap-4;
  }

  #mobile-menu .nav-link {
    @apply flex items-center gap-3 rounded-xl transition-all duration-300 font-medium hover:bg-accent/10 hover:text-primary;
    padding: 1rem 1.25rem;
    font-size: 1.125rem;
  }

  #mobile-menu .nav-link i {
    @apply text-primary opacity-90;
    font-size: 1.25rem;
    width: 1.5rem;
    text-align: center;
  }

  #mobile-menu .controls {
    @apply flex items-center justify-center gap-4 py-6 border-t border-[rgb(var(--border))];
  }

  #mobile-menu .controls button {
    @apply flex items-center justify-center rounded-xl hover:bg-accent/10 transition-all duration-300;
    width: 2.5rem;
    height: 2.5rem;
  }

  #mobile-menu #mobile-dark-mode-toggle {
    width: 2.5rem;
    height: 2.5rem;
  }

  #mobile-menu #mobile-language-switcher {
    height: 2.5rem;
    padding: 0 1rem;
    font-size: 0.875rem;
  }

  /* Close Menu Button */
  #close-menu {
    @apply flex items-center justify-center rounded-xl hover:bg-accent/10 transition-all duration-300;
    width: 2.5rem;
    height: 2.5rem;
  }

  #close-menu i {
    font-size: 1.25rem;
  }

  /* Add padding to body to account for fixed header */
  body {
    padding-top: clamp(3.5rem, 6vw, 5rem);
  }

  /* Prevent body scroll when menu is open */
  body.menu-open {
    overflow: hidden;
  }
} 

.whatsapp-button {
  @apply fixed bottom-6 right-6 z-40 flex items-center justify-center rounded-full bg-[#25D366] text-white shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-110;
  width: 3.5rem;
  height: 3.5rem;
}

.whatsapp-button i {
  font-size: 1.75rem;
}

/* Add animation for the button */
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.4);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(37, 211, 102, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(37, 211, 102, 0);
  }
}

.whatsapp-button {
  animation: pulse 2s infinite;
}

/* Portfolio Styles */
.portfolio-item {
  transition: all 0.3s ease;
}

.portfolio-item:hover {
  transform: translateY(-4px);
}

.portfolio-image-container {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

.portfolio-image {
  transition: transform 0.3s ease;
  will-change: transform;
}

.portfolio-image:hover {
  transform: scale(1.05);
}

.portfolio-overlay {
  transition: opacity 0.3s ease;
}

/* Lazy Loading Styles */
.portfolio-image[data-src] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.portfolio-image[data-src].loaded {
  opacity: 1;
}

/* Loading placeholder */
.portfolio-image-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  z-index: 1;
}

/* Hide skeleton when the container is marked as loaded */
.portfolio-image-container.loaded::before {
  display: none;
}

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

/* Dark mode portfolio styles */
.dark .portfolio-image-container {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.dark .portfolio-image-container::before {
  background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
}

/* Responsive portfolio grid */
@media (max-width: 768px) {
  .portfolio-item {
    margin-bottom: 1rem;
  }
}

/* Intersection Observer fallback */
.no-intersection-observer .portfolio-image[data-src] {
  opacity: 1;
}

.no-intersection-observer .portfolio-image-container::before {
  display: none;
}