@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";

@custom-variant dark (&:is(.dark *));

@source "../components/*.{js,ts,jsx,tsx}";
@source "../components/ui/*.{js,ts,jsx,tsx}";
@source "*.{js,ts,jsx,tsx}";

@theme {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;

  /* Category colors for 23 unit types - Tailored to Tailwind 500 shades */
  --color-category-angle: oklch(0.645 0.246 16.439); /* Rose 500 */
  --color-category-apparent-power: oklch(0.606 0.25 273.428); /* Violet 500 */
  --color-category-area: oklch(0.696 0.17 162.48); /* Emerald 500 */
  --color-category-current: oklch(0.769 0.188 70.08); /* Amber 500 */
  --color-category-digital: oklch(0.623 0.214 259.815); /* Blue 500 */
  --color-category-each: oklch(0.539 0.047 258.337); /* Slate 500 */
  --color-category-energy: oklch(0.769 0.188 70.08); /* Amber 500 */
  --color-category-frequency: oklch(0.606 0.25 273.428); /* Violet 500 */
  --color-category-illuminance: oklch(0.773 0.174 91.249); /* Yellow 500 */
  --color-category-length: oklch(0.623 0.214 259.815); /* Blue 500 */
  --color-category-mass: oklch(0.696 0.17 162.48); /* Emerald 500 */
  --color-category-pace: oklch(0.704 0.14 182.503); /* Teal 500 */
  --color-category-parts-per: oklch(0.707 0.022 261.325); /* Slate 400 */
  --color-category-power: oklch(0.606 0.25 273.428); /* Violet 500 */
  --color-category-pressure: oklch(0.585 0.233 277.117); /* Indigo 500 */
  --color-category-reactive-energy: oklch(0.769 0.188 70.08); /* Amber 500 */
  --color-category-reactive-power: oklch(0.606 0.25 273.428); /* Violet 500 */
  --color-category-speed: oklch(0.704 0.14 182.503); /* Teal 500 */
  --color-category-temperature: oklch(0.627 0.225 31.038); /* Red 500 */
  --color-category-tempo: oklch(0.705 0.213 47.591); /* Orange 500 */
  --color-category-time: oklch(0.585 0.233 277.117); /* Indigo 500 */
  --color-category-voltage: oklch(0.769 0.188 70.08); /* Amber 500 */
  --color-category-volume: oklch(0.696 0.17 162.48); /* Emerald 500 */
  --color-category-volume-flow-rate: oklch(0.696 0.17 162.48); /* Emerald 500 */

  /* Custom animations */
  --animate-gradient: gradient 8s linear infinite;
  --animate-float: float 3s ease-in-out infinite;
  --animate-glow: glow 2s ease-in-out infinite alternate;
  --animate-fade-in: fadeIn 0.3s ease-in-out;
  --animate-slide-up: slideUp 0.4s ease-out;
  --animate-slide-down: slideDown 0.4s ease-out;
  --animate-scale-in: scaleIn 0.2s ease-out;

  @keyframes gradient {
    0%, 100% {
      background-size: 200% 200%;
      background-position: left center;
    }
    50% {
      background-size: 200% 200%;
      background-position: right center;
    }
  }

  @keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-20px); }
  }

  @keyframes glow {
    from {
      box-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
    }
    to {
      box-shadow: 0 0 30px rgba(139, 92, 246, 0.6), 0 0 40px rgba(139, 92, 246, 0.3);
    }
  }

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

  @keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

  @keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

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

:root, .dark {
  color-scheme: dark;
  /* CORPORATE DARK THEME (The Standard) */
  --background: #0a0a0f;
  --foreground: #ffffff;
  --card: rgba(255, 255, 255, 0.03);
  --card-foreground: #ffffff;
  --popover: #0f0f15;
  --popover-foreground: #ffffff;
  --primary: #8b5cf6;
  --primary-foreground: #ffffff;
  --secondary: rgba(255, 255, 255, 0.05);
  --secondary-foreground: #ffffff;
  --muted: rgba(255, 255, 255, 0.05);
  --muted-foreground: #a1a1aa;
  --accent: rgba(255, 255, 255, 0.08);
  --accent-foreground: #ffffff;
  --destructive: #ef4444;
  --destructive-foreground: #ffffff;
  --border: rgba(255, 255, 255, 0.15);
  --input: rgba(255, 255, 255, 0.05);
  --ring: rgba(139, 92, 246, 0.5);
  --radius: 1rem;
}

.light {
  color-scheme: light;
  /* LIGHT ADAPTATION (Keeping the "Glass" look) */
  --background: oklch(98% 0.005 255);
  --foreground: oklch(20% 0.04 255);
  --card: rgba(255, 255, 255, 0.4);
  --card-foreground: oklch(20% 0.04 255);
  --popover: oklch(100% 0 0);
  --popover-foreground: oklch(20% 0.04 255);
  --primary: oklch(55% 0.22 270);
  --primary-foreground: oklch(100% 0 0);
  --secondary: rgba(0, 0, 0, 0.02);
  --secondary-foreground: oklch(20% 0.04 255);
  --muted: rgba(0, 0, 0, 0.02);
  --muted-foreground: oklch(45% 0.04 255);
  --accent: rgba(0, 0, 0, 0.03);
  --accent-foreground: oklch(15% 0.05 255);
  --destructive: oklch(60% 0.2 25);
  --destructive-foreground: oklch(100% 0 0);
  --border: rgba(0, 0, 0, 0.12);
  --input: rgba(0, 0, 0, 0.01);
  --ring: rgba(139, 92, 246, 0.2);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background text-foreground;
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  /* Fix native select dropdown styling */
  select option {
    @apply bg-popover text-popover-foreground;
  }
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@utility text-balance {
  text-wrap: balance;
}

@utility glass {
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
}

@utility gradient-purple-blue {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

@utility gradient-cyan-purple {
  background: linear-gradient(135deg, #2dd4bf 0%, #8b5cf6 100%);
}

@utility gradient-indigo-purple {
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
}

@utility gradient-yellow-amber {
  background: linear-gradient(135deg, #eab308 0%, #f59e0b 100%);
}

@utility gradient-brand {
  background: linear-gradient(to right, #a78bfa, #f472b6, #22d3ee);
}

@theme inline {
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --radius-2xl: calc(var(--radius) + 8px);
  --radius-3xl: calc(var(--radius) + 12px);
  --radius-4xl: calc(var(--radius) + 16px);
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
}

:root {
  --radius: 0.625rem;
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --chart-1: oklch(0.646 0.222 41.116);
  --chart-2: oklch(0.6 0.118 184.704);
  --chart-3: oklch(0.398 0.07 227.392);
  --chart-4: oklch(0.828 0.189 84.429);
  --chart-5: oklch(0.769 0.188 70.08);
  --sidebar: oklch(0.985 0 0);
  --sidebar-foreground: oklch(0.145 0 0);
  --sidebar-primary: oklch(0.205 0 0);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.97 0 0);
  --sidebar-accent-foreground: oklch(0.205 0 0);
  --sidebar-border: oklch(0.922 0 0);
  --sidebar-ring: oklch(0.708 0 0);
}

.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);
  --chart-1: oklch(0.488 0.243 264.376);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.627 0.265 303.9);
  --chart-5: oklch(0.645 0.246 16.439);
  --sidebar: oklch(0.205 0 0);
  --sidebar-foreground: oklch(0.985 0 0);
  --sidebar-primary: oklch(0.488 0.243 264.376);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.269 0 0);
  --sidebar-accent-foreground: oklch(0.985 0 0);
  --sidebar-border: oklch(1 0 0 / 10%);
  --sidebar-ring: oklch(0.556 0 0);
}