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

@layer base {
  html {
    scroll-behavior: smooth;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }

  body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }
  
  * {
    box-sizing: border-box;
  }
}

@layer utilities {
  .bg-grid-pattern {
    background-image: 
      repeating-linear-gradient(0deg, transparent, transparent 35px, currentColor 35px, currentColor 36px),
      repeating-linear-gradient(90deg, transparent, transparent 35px, currentColor 35px, currentColor 36px);
  }
}

/* LIGHT MODE */
:root {
  --button-outline: rgba(0,0,0, .10);
  --badge-outline: rgba(0,0,0, .05);

  /* Automatic computation of border around primary / danger buttons */
  --opaque-button-border-intensity: -8; /* In terms of percentages */

  /* Backgrounds applied on top of other backgrounds when hovered/active */
  --elevate-1: rgba(0,0,0, .03);
  --elevate-2: rgba(0,0,0, .08);

  --background: 0 0% 98%;

  --foreground: 220 10% 15%;

  --border: 220 10% 88%;

  --card: 0 0% 100%;

  --card-foreground: 220 10% 15%;

  --card-border: 220 8% 92%;

  --sidebar: 220 5% 96%;

  --sidebar-foreground: 220 10% 15%;

  --sidebar-border: 220 8% 90%;

  --sidebar-primary: 200 75% 45%;

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

  --sidebar-accent: 220 12% 88%;

  --sidebar-accent-foreground: 220 10% 20%;

  --sidebar-ring: 200 75% 45%;

  --popover: 0 0% 99%;

  --popover-foreground: 220 10% 15%;

  --popover-border: 220 10% 91%;

  --primary: 200 75% 45%;

  --primary-foreground: 0 0% 100%;

  --secondary: 220 8% 91%;

  --secondary-foreground: 220 10% 20%;

  --muted: 220 12% 94%;

  --muted-foreground: 220 8% 40%;

  --accent: 220 15% 92%;

  --accent-foreground: 220 10% 20%;

  --destructive: 0 72% 51%;

  --destructive-foreground: 0 0% 100%;

  --input: 220 10% 75%;
  --ring: 200 75% 45%;
  --chart-1: 200 75% 42%;
  --chart-2: 140 65% 45%;
  --chart-3: 30 85% 55%;
  --chart-4: 260 70% 50%;
  --chart-5: 340 65% 50%;

  /* Optimized font stack with system fallbacks for instant text rendering */
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-mono: "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --radius: .5rem; /* 8px */
  --shadow-2xs: 0px 1px 2px 0px hsl(220 10% 15% / 0.04);
  --shadow-xs: 0px 1px 3px 0px hsl(220 10% 15% / 0.08);
  --shadow-sm: 0px 2px 4px -1px hsl(220 10% 15% / 0.06), 0px 1px 2px -1px hsl(220 10% 15% / 0.04);
  --shadow: 0px 4px 6px -1px hsl(220 10% 15% / 0.08), 0px 2px 4px -2px hsl(220 10% 15% / 0.05);
  --shadow-md: 0px 6px 12px -2px hsl(220 10% 15% / 0.10), 0px 3px 6px -3px hsl(220 10% 15% / 0.06);
  --shadow-lg: 0px 10px 20px -4px hsl(220 10% 15% / 0.12), 0px 5px 10px -5px hsl(220 10% 15% / 0.08);
  --shadow-xl: 0px 20px 35px -5px hsl(220 10% 15% / 0.15), 0px 10px 15px -6px hsl(220 10% 15% / 0.10);
  --shadow-2xl: 0px 30px 60px -10px hsl(220 10% 15% / 0.20);
  --tracking-normal: 0em;
  --spacing: 0.25rem;

  /* Automatically computed borders - intensity can be controlled by the user by the --opaque-button-border-intensity setting */

  /* Fallback for older browsers */
  --sidebar-primary-border: hsl(var(--sidebar-primary));
  --sidebar-primary-border: hsl(from hsl(var(--sidebar-primary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --sidebar-accent-border: hsl(var(--sidebar-accent));
  --sidebar-accent-border: hsl(from hsl(var(--sidebar-accent)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --primary-border: hsl(var(--primary));
  --primary-border: hsl(from hsl(var(--primary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --secondary-border: hsl(var(--secondary));
  --secondary-border: hsl(from hsl(var(--secondary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --muted-border: hsl(var(--muted));
  --muted-border: hsl(from hsl(var(--muted)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --accent-border: hsl(var(--accent));
  --accent-border: hsl(from hsl(var(--accent)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --destructive-border: hsl(var(--destructive));
  --destructive-border: hsl(from hsl(var(--destructive)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);
}

.dark {
  --button-outline: rgba(255,255,255, .10);
  --badge-outline: rgba(255,255,255, .05);

  --opaque-button-border-intensity: 9;  /* In terms of percentages */

  /* Backgrounds applied on top of other backgrounds when hovered/active */
  --elevate-1: rgba(255,255,255, .04);
  --elevate-2: rgba(255,255,255, .09);

  --background: 220 15% 12%;

  --foreground: 0 0% 95%;

  --border: 220 12% 20%;

  --card: 220 14% 15%;

  --card-foreground: 0 0% 95%;

  --card-border: 220 12% 18%;

  --sidebar: 220 14% 18%;

  --sidebar-foreground: 0 0% 95%;

  --sidebar-border: 220 12% 22%;

  --sidebar-primary: 200 70% 60%;

  --sidebar-primary-foreground: 220 15% 12%;

  --sidebar-accent: 220 15% 22%;

  --sidebar-accent-foreground: 0 0% 92%;

  --sidebar-ring: 200 70% 60%;

  --popover: 220 14% 16%;

  --popover-foreground: 0 0% 95%;

  --popover-border: 220 12% 20%;

  --primary: 200 70% 55%;

  --primary-foreground: 220 15% 12%;

  --secondary: 220 12% 24%;

  --secondary-foreground: 0 0% 92%;

  --muted: 220 15% 20%;

  --muted-foreground: 220 8% 65%;

  --accent: 220 18% 22%;

  --accent-foreground: 0 0% 92%;

  --destructive: 0 68% 48%;

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

  --input: 220 12% 35%;
  --ring: 200 70% 60%;
  --chart-1: 200 70% 65%;
  --chart-2: 140 60% 60%;
  --chart-3: 30 80% 65%;
  --chart-4: 260 65% 65%;
  --chart-5: 340 60% 65%;

  --shadow-2xs: 0px 1px 2px 0px hsl(0 0% 0% / 0.15);
  --shadow-xs: 0px 1px 3px 0px hsl(0 0% 0% / 0.20);
  --shadow-sm: 0px 2px 4px -1px hsl(0 0% 0% / 0.18), 0px 1px 2px -1px hsl(0 0% 0% / 0.12);
  --shadow: 0px 4px 6px -1px hsl(0 0% 0% / 0.22), 0px 2px 4px -2px hsl(0 0% 0% / 0.15);
  --shadow-md: 0px 6px 12px -2px hsl(0 0% 0% / 0.28), 0px 3px 6px -3px hsl(0 0% 0% / 0.18);
  --shadow-lg: 0px 10px 20px -4px hsl(0 0% 0% / 0.35), 0px 5px 10px -5px hsl(0 0% 0% / 0.22);
  --shadow-xl: 0px 20px 35px -5px hsl(0 0% 0% / 0.42), 0px 10px 15px -6px hsl(0 0% 0% / 0.28);
  --shadow-2xl: 0px 30px 60px -10px hsl(0 0% 0% / 0.50);

  /* Automatically computed borders - intensity can be controlled by the user by the --opaque-button-border-intensity setting */

  /* Fallback for older browsers */
  --sidebar-primary-border: hsl(var(--sidebar-primary));
  --sidebar-primary-border: hsl(from hsl(var(--sidebar-primary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --sidebar-accent-border: hsl(var(--sidebar-accent));
  --sidebar-accent-border: hsl(from hsl(var(--sidebar-accent)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --primary-border: hsl(var(--primary));
  --primary-border: hsl(from hsl(var(--primary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --secondary-border: hsl(var(--secondary));
  --secondary-border: hsl(from hsl(var(--secondary)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --muted-border: hsl(var(--muted));
  --muted-border: hsl(from hsl(var(--muted)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --accent-border: hsl(var(--accent));
  --accent-border: hsl(from hsl(var(--accent)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);

  /* Fallback for older browsers */
  --destructive-border: hsl(var(--destructive));
  --destructive-border: hsl(from hsl(var(--destructive)) h s calc(l + var(--opaque-button-border-intensity)) / alpha);
}

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

  body {
    @apply font-sans antialiased bg-background text-foreground;
  }
}

@layer utilities {
  /* Custom container for 1080px max width */
  .container-1080 {
    max-width: 1080px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Enhanced responsive adjustments with more granular breakpoints */
  @media (max-width: 1024px) {
    .container-1080 {
      padding-left: 1.5rem;
      padding-right: 1.5rem;
    }
  }

  @media (max-width: 768px) {
    .container-1080 {
      padding-left: 1rem;
      padding-right: 1rem;
    }
  }

  @media (max-width: 640px) {
    .container-1080 {
      padding-left: 0.75rem;
      padding-right: 0.75rem;
    }
  }

  @media (max-width: 480px) {
    .container-1080 {
      padding-left: 0.625rem;
      padding-right: 0.625rem;
    }
  }

  @media (max-width: 374px) {
    .container-1080 {
      padding-left: 0.5rem;
      padding-right: 0.5rem;
    }
  }

  /* Safe area insets for notched devices */
  @supports (padding: max(0px)) {
    .container-1080 {
      padding-left: max(0.5rem, env(safe-area-inset-left));
      padding-right: max(0.5rem, env(safe-area-inset-right));
    }
  }

  /* Mobile-first responsive utilities */
  .mobile-hidden {
    @apply hidden sm:block;
  }

  .mobile-only {
    @apply block sm:hidden;
  }

  .tablet-hidden {
    @apply hidden md:block;
  }

  .tablet-only {
    @apply block md:hidden;
  }

  /* Touch-friendly button sizing */
  .touch-target {
    min-height: 44px;
    min-width: 44px;
  }

  /* Enhanced touch target for better mobile UX */
  .touch-target-lg {
    min-height: 48px;
    min-width: 48px;
  }

  /* Mobile typography utilities */
  .text-mobile-xs {
    font-size: 0.625rem;
    line-height: 0.875rem;
  }

  .text-mobile-sm {
    font-size: 0.75rem;
    line-height: 1rem;
  }

  .text-mobile-base {
    font-size: 0.875rem;
    line-height: 1.25rem;
  }

  /* Prevent horizontal overflow */
  .no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  .no-scrollbar::-webkit-scrollbar {
    display: none;
  }

  /* Mobile-optimized spacing */
  .mobile-section-spacing {
    @apply py-8 sm:py-12 md:py-16 lg:py-20;
  }

  .mobile-card-spacing {
    @apply p-3 xs:p-4 sm:p-6 md:p-8;
  }

  .mobile-gap {
    @apply gap-3 xs:gap-4 sm:gap-5 md:gap-6;
  }

  /* Hide ugly search cancel button in Chrome until we can style it properly */
  input[type="search"]::-webkit-search-cancel-button {
    @apply hidden;
  }

  /* Placeholder styling for contentEditable div */
  [contenteditable][data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: hsl(var(--muted-foreground));
    pointer-events: none;
  }

  /* Placeholder class to disable default hover elevation */
  .no-default-hover-elevate {
    /* Intentionally empty - used as a flag class */
  }

  /* Placeholder class to disable default active elevation */
  .no-default-active-elevate {
    /* Intentionally empty - used as a flag class */
  }

  .toggle-elevate::before,
  .toggle-elevate-2::before {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0px;
    border-radius: inherit;
    z-index: -1;
  }

  .toggle-elevate.toggle-elevated::before {
    background-color: var(--elevate-2);
  }

  .border.toggle-elevate::before {
    inset: -1px;
  }

  .hover-elevate:not(.no-default-hover-elevate),
  .active-elevate:not(.no-default-active-elevate),
  .hover-elevate-2:not(.no-default-hover-elevate),
  .active-elevate-2:not(.no-default-active-elevate) {
    position: relative;
    z-index: 0;
  }

  .hover-elevate:not(.no-default-hover-elevate)::after,
  .active-elevate:not(.no-default-active-elevate)::after,
  .hover-elevate-2:not(.no-default-hover-elevate)::after,
  .active-elevate-2:not(.no-default-active-elevate)::after {
    content: "";
    pointer-events: none;
    position: absolute;
    inset: 0px;
    border-radius: inherit;
    z-index: 999;
  }

  .hover-elevate:hover:not(.no-default-hover-elevate)::after,
  .active-elevate:active:not(.no-default-active-elevate)::after {
    background-color: var(--elevate-1);
  }

  .hover-elevate-2:hover:not(.no-default-hover-elevate)::after,
  .active-elevate-2:active:not(.no-default-active-elevate)::after {
    background-color: var(--elevate-2);
  }

  .border.hover-elevate:not(.no-hover-interaction-elevate)::after,
  .border.active-elevate:not(.no-active-interaction-elevate)::after,
  .border.hover-elevate-2:not(.no-hover-interaction-elevate)::after,
  .border.active-elevate-2:not(.no-active-interaction-elevate)::after,
  .border.hover-elevate:not(.no-hover-interaction-elevate)::after {
    inset: -1px;
  }
}