@tailwind base;
@tailwind components;
@tailwind utilities;

/* Scandinavian Design System - Clean, minimal, natural tones */

@layer base {
  :root {
    /* Core Scandinavian palette */
    --background: 0 0% 99%;
    --foreground: 220 15% 20%;

    /* Card system */
    --card: 0 0% 100%;
    --card-foreground: 220 15% 20%;

    /* Popover system */
    --popover: 0 0% 100%;
    --popover-foreground: 220 15% 20%;

    /* Primary - Deep Nordic blue-gray */
    --primary: 215 25% 27%;
    --primary-foreground: 0 0% 98%;
    --primary-hover: 215 30% 22%;

    /* Secondary - Warm stone gray */
    --secondary: 20 8% 95%;
    --secondary-foreground: 220 15% 25%;
    --secondary-hover: 20 10% 90%;

    /* Muted tones - Enhanced contrast for accessibility */
    --muted: 210 10% 96%;
    --muted-foreground: 220 10% 40%;

    /* Accent - Sage green with improved contrast för bättre läsbarhet */
    --accent: 145 25% 75%;
    --accent-foreground: 145 35% 20%;
    --accent-hover: 145 30% 70%;

    /* Natural warm accent */
    --warm-accent: 35 15% 88%;
    --warm-accent-foreground: 35 25% 25%;

    /* Destructive */
    --destructive: 0 65% 58%;
    --destructive-foreground: 0 0% 98%;

    /* Borders and inputs - Subtle Nordic */
    --border: 220 13% 91%;
    --input: 220 13% 91%;
    --ring: 215 25% 27%;

    --radius: 0.5rem;

    /* Scandinavian gradients */
    --gradient-hero: linear-gradient(135deg, hsl(var(--background)), hsl(var(--accent)));
    --gradient-card: linear-gradient(180deg, hsl(var(--card)), hsl(var(--secondary)));
    
    /* Shadows with Nordic feel */
    --shadow-soft: 0 4px 20px -4px hsl(var(--primary) / 0.1);
    --shadow-elegant: 0 10px 40px -10px hsl(var(--primary) / 0.15);
    
    /* Transitions */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --sidebar-background: 0 0% 98%;

    --sidebar-foreground: 240 5.3% 26.1%;

    --sidebar-primary: 240 5.9% 10%;

    --sidebar-primary-foreground: 0 0% 98%;

    --sidebar-accent: 240 4.8% 95.9%;

    --sidebar-accent-foreground: 240 5.9% 10%;

    --sidebar-border: 220 13% 91%;

    --sidebar-ring: 217.2 91.2% 59.8%;
  }

  .dark {
    --background: 215 25% 12%;
    --foreground: 0 0% 98%;

    --card: 215 25% 15%;
    --card-foreground: 0 0% 98%;

    --popover: 215 25% 15%;
    --popover-foreground: 0 0% 98%;

    --primary: 0 0% 98%;
    --primary-foreground: 215 25% 12%;
    --primary-hover: 0 0% 90%;

    --secondary: 215 20% 20%;
    --secondary-foreground: 0 0% 98%;
    --secondary-hover: 215 20% 25%;

    --muted: 215 20% 18%;
    --muted-foreground: 220 8% 65%;

    --accent: 145 20% 25%;
    --accent-foreground: 145 20% 85%;
    --accent-hover: 145 25% 30%;

    --warm-accent: 35 15% 25%;
    --warm-accent-foreground: 35 15% 85%;

    --destructive: 0 65% 45%;
    --destructive-foreground: 0 0% 98%;

    --border: 215 20% 22%;
    --input: 215 20% 22%;
    --ring: 0 0% 98%;
    --sidebar-background: 240 5.9% 10%;
    --sidebar-foreground: 240 4.8% 95.9%;
    --sidebar-primary: 224.3 76.3% 48%;
    --sidebar-primary-foreground: 0 0% 100%;
    --sidebar-accent: 240 3.7% 15.9%;
    --sidebar-accent-foreground: 240 4.8% 95.9%;
    --sidebar-border: 240 3.7% 15.9%;
    --sidebar-ring: 217.2 91.2% 59.8%;
  }
}

@layer base {
  * {
    @apply border-border;
  }

  body {
    @apply bg-background text-foreground;
  }
  
  html {
    scroll-behavior: smooth;
    /* Performance optimizations */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Critical performance optimizations */
  * {
    box-sizing: border-box;
  }

  /* Mobile-optimized typography with performance in mind */
  h1, h2, h3, h4, h5, h6 {
    @apply leading-tight;
    font-display: swap; /* Improve font loading performance */
  }

  /* Optimize image loading */
  img {
    height: auto;
    max-width: 100%;
  }

  /* Reduce layout shift for lazy-loaded content */
  .lazy-placeholder {
    background: linear-gradient(90deg, hsl(var(--muted)) 25%, transparent 50%, hsl(var(--muted)) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
  }

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

@layer components {
  /* Design System - Consistent Spacing & Sizing */
  
  /* Standard Card Padding System */
  .card-padding-sm {
    @apply p-3 sm:p-4;
  }
  
  .card-padding-md {
    @apply p-4 sm:p-6;
  }
  
  .card-padding-lg {
    @apply p-6 sm:p-8;
  }
  
  .card-content-padding-sm {
    @apply p-3 sm:p-4 pt-0 sm:pt-0;
  }
  
  .card-content-padding-md {
    @apply p-4 sm:p-6 pt-0 sm:pt-0;
  }
  
  .card-content-padding-lg {
    @apply p-6 sm:p-8 pt-0 sm:pt-0;
  }

  /* Icon Size System */
  .icon-xs {
    @apply h-3 w-3 sm:h-4 sm:w-4;
  }
  
  .icon-sm {
    @apply h-4 w-4 sm:h-5 sm:w-5;
  }
  
  .icon-md {
    @apply h-5 w-5 sm:h-6 sm:w-6;
  }
  
  .icon-lg {
    @apply h-6 w-6 sm:h-8 sm:w-8;
  }
  
  .icon-xl {
    @apply h-8 w-8 sm:h-10 sm:w-10 lg:h-12 lg:w-12;
  }
  
  .icon-2xl {
    @apply h-12 w-12 sm:h-14 sm:w-14 lg:h-16 lg:w-16;
  }

  /* Avatar/Profile Image Sizes */
  .avatar-sm {
    @apply w-8 h-8 sm:w-10 sm:h-10;
  }
  
  .avatar-md {
    @apply w-12 h-12 sm:w-14 sm:h-14;
  }
  
  .avatar-lg {
    @apply w-16 h-16 sm:w-20 sm:h-20;
  }
  
  .avatar-xl {
    @apply w-20 h-20 sm:w-24 sm:h-24;
  }

  /* Section Spacing System */
  .section-padding-sm {
    @apply py-8 sm:py-12;
  }
  
  .section-padding-md {
    @apply py-12 sm:py-16;
  }
  
  .section-padding-lg {
    @apply py-16 sm:py-20 lg:py-24;
  }

  /* Container Spacing System */
  .container-padding {
    @apply px-4 sm:px-6;
  }
  
  .container-padding-lg {
    @apply px-4 sm:px-6 lg:px-8;
  }

  /* Element Spacing System */
  .spacing-xs {
    @apply space-y-2 sm:space-y-3;
  }
  
  .spacing-sm {
    @apply space-y-3 sm:space-y-4;
  }
  
  .spacing-md {
    @apply space-y-4 sm:space-y-6;
  }
  
  .spacing-lg {
    @apply space-y-6 sm:space-y-8;
  }

  /* Grid Gap System */
  .grid-gap-sm {
    @apply gap-4 sm:gap-6;
  }
  
  .grid-gap-md {
    @apply gap-6 sm:gap-8;
  }
  
  .grid-gap-lg {
    @apply gap-8 sm:gap-12;
  }

  /* Text Spacing System */
  .text-spacing-sm {
    @apply mb-2 sm:mb-3;
  }
  
  .text-spacing-md {
    @apply mb-3 sm:mb-4 lg:mb-6;
  }
  
  .text-spacing-lg {
    @apply mb-4 sm:mb-6 lg:mb-8;
  }

  /* Mobile-friendly button improvements */
  .btn-touch {
    @apply min-h-[44px] min-w-[44px] touch-manipulation;
  }
  
  /* Mobile navigation improvements */
  .mobile-nav-link {
    @apply block py-3 px-4 text-base font-medium touch-manipulation min-h-[44px];
  }
  
  /* Responsive container with better mobile padding */
  .container-responsive {
    @apply container mx-auto px-4 sm:px-6 lg:px-8;
  }
  
  /* Mobile-optimized cards */
  .card-mobile {
    @apply p-4 sm:p-6 lg:p-8;
  }

  /* Button text handling - prevent truncation */
  .btn-responsive {
    @apply min-h-[44px] min-w-[44px] px-3 sm:px-4 lg:px-6 py-2 sm:py-3 text-xs sm:text-sm lg:text-base leading-tight;
    word-break: break-word;
    hyphens: auto;
  }

  /* Interactive element spacing */
  .interactive-spacing > * + * {
    @apply mt-2 sm:mt-3;
  }

  .interactive-spacing-horizontal > * + * {
    @apply ml-2 sm:ml-3;
  }
}

@layer utilities {
  /* Touch-friendly utilities */
  .touch-target {
    @apply min-h-[44px] min-w-[44px];
  }
  
  /* Safe area handling for mobile devices */
  .safe-top {
    padding-top: env(safe-area-inset-top);
  }
  
  .safe-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  /* Mobile viewport handling */
  .min-h-screen-mobile {
    min-height: 100vh;
    min-height: 100dvh;
  }
  
  /* Text handling utilities */
  .text-responsive {
    @apply text-xs sm:text-sm lg:text-base;
  }
  
  .text-button-responsive {
    @apply text-xs sm:text-sm leading-tight;
  }
  
  /* Prevent text overflow in buttons */
  .btn-text-safe {
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
  }
  
  /* Enhanced touch targets for all interactive elements */
  .touch-enhanced {
    @apply min-h-[44px] min-w-[44px] touch-manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Responsive button padding based on screen size */
  .btn-padding-responsive {
    @apply px-2 py-2 sm:px-4 sm:py-3 lg:px-6 lg:py-3;
  }
  
  /* Mobile Sticky CTA Animations */
  @keyframes slide-up {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  @keyframes scale-in {
    from {
      transform: scale(0.95);
      opacity: 0;
    }
    to {
      transform: scale(1);
      opacity: 1;
    }
  }

  .animate-slide-up {
    animation: slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .animate-scale-in {
    animation: scale-in 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
}