@import "tailwindcss";
@import "katex/dist/katex.min.css";

/*
 * Bridge the legacy Tailwind v3 style config (tailwind.config.ts) into
 * Tailwind v4. Without @config, the JS config file is silently ignored,
 * which means:
 *   1. Theme tokens (success/warning/danger/info/purple) are never
 *      registered, so utilities like `bg-success-soft` don't exist.
 *   2. `darkMode: ["class", ".dark"]` is not applied, so `dark:` falls
 *      back to `prefers-color-scheme`, which fights with next-themes'
 *      class-based toggle and bleeds dark styles into light mode.
 */
@config "../../tailwind.config.ts";

/*
 * Belt-and-suspenders: ensure `dark:` always resolves through the
 * `.dark` class that next-themes toggles on <html>, regardless of OS
 * preference. This must agree with the darkMode setting above.
 */
@custom-variant dark (&:where(.dark, .dark *));

@layer base {
  :root {
    /* Brand primary: webUI blue (hue 221, #2563eb) */
    --primary: 221 83% 53%;
    --primary-foreground: 0 0% 100%;

    /* Ten-step primary ramp, used for tags, icons, subtle highlights */
    --primary-50: 214 100% 97%;
    --primary-100: 214 100% 93%;
    --primary-200: 214 95% 87%;
    --primary-300: 213 96% 78%;
    --primary-400: 217 91% 65%;
    --primary-500: 221 83% 53%;
    --primary-600: 222 78% 47%;
    --primary-700: 224 76% 40%;
    --primary-800: 226 71% 32%;
    --primary-900: 224 64% 25%;

    /* Soft primary tint for active/hover backgrounds (#eff6ff) */
    --primary-soft: 214 100% 96%;

    /* Page surface: webUI uses slate-50 (#f8fafc) for the page bg, white for cards */
    --background: 210 40% 98%;
    --foreground: 222 47% 11%;

    --card: 0 0% 100%;
    --card-foreground: 222 47% 11%;

    --popover: 0 0% 100%;
    --popover-foreground: 222 47% 11%;

    /* Layered neutral tokens */
    --secondary: 210 40% 96%;
    --secondary-foreground: 222 47% 11%;

    --muted: 214 32% 91%;
    --muted-foreground: 215 19% 35%;

    /* Accent = primary-soft so hover/active states pick up brand tint */
    --accent: 214 100% 96%;
    --accent-foreground: 221 83% 40%;

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

    --border: 214 32% 91%;
    --border-light: 210 40% 96%;
    --input: 214 32% 91%;
    --ring: 221 83% 53%;

    --radius: 0.5rem;

    /* Surface tokens */
    --surface: 0 0% 100%;
    --surface-secondary: 210 40% 98%;
    --surface-tertiary: 214 32% 91%;

    /* Subtle neutral tokens */
    --subtle: 215 20% 65%;
    --subtle-light: 215 16% 80%;
    --subtle-dark: 215 25% 27%;

    /* Sidebar tokens: white sidebar over gray page */
    --sidebar-bg: 0 0% 100%;
    --sidebar-border: 214 32% 91%;
    --sidebar-active-bg: 214 100% 96%;
    --sidebar-active-fg: 221 83% 53%;
    --sidebar-text: 215 25% 27%;

    /* Semantic five-color palette + soft tints for badges/icons/stat cards */
    --success: 142 71% 45%;
    --success-soft: 138 76% 97%;
    --warning: 38 92% 50%;
    --warning-soft: 48 100% 96%;
    --danger: 0 84% 60%;
    --danger-soft: 0 86% 97%;
    --info: 217 91% 60%;
    --info-soft: 214 100% 97%;
    --purple: 262 84% 58%;
    --purple-soft: 258 100% 97%;

    /* Motion tokens */
    --duration-fast: 150ms;
    --duration-base: 200ms;
    --duration-slow: 300ms;
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);

    /* Spacing scale (reference only) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;
  }

  .dark {
    --primary: 221 83% 62%;
    --primary-foreground: 0 0% 100%;

    --primary-50: 224 50% 14%;
    --primary-100: 224 55% 20%;
    --primary-200: 224 60% 26%;
    --primary-300: 222 65% 34%;
    --primary-400: 221 78% 48%;
    --primary-500: 221 83% 56%;
    --primary-600: 217 91% 65%;
    --primary-700: 213 96% 78%;
    --primary-800: 214 95% 87%;
    --primary-900: 214 100% 93%;

    /*
     * Dark-mode neutrals — GitHub primer-dark style.
     *
     * Earlier the dark theme ran on `222° 47% L` everywhere (a saturated
     * Tailwind-slate / Stripe-style blue). On a screen the high saturation
     * made every "neutral" surface feel blue-tinted, which fights against
     * the primary blue accent — `#2563eb` ended up sitting on a background
     * with the same hue, killing the contrast that gives a CTA its lift.
     *
     * Industry mainstream in 2024-2026 leans toward a desaturated dark
     * with a *subtle* cool tint (GitHub `#0d1117`, Linear `#0e0e10`).
     * We follow GitHub's hue (≈220°) and saturation (~13%) for the
     * grayscale tokens, and keep all primary/accent tokens unchanged so
     * the brand identity is preserved.
     */
    --primary-soft: 218 28% 18%; /* slightly desat to match new neutrals */

    --background: 220 13% 8%; /* was 222 47% 7%   ≈ #0d1117 */
    --foreground: 213 13% 92%;

    --card: 220 13% 11%; /* was 222 47% 11%  ≈ #161b22 */
    --card-foreground: 213 13% 92%;

    --popover: 220 13% 11%;
    --popover-foreground: 213 13% 92%;

    --secondary: 220 13% 18%; /* was 217 19% 18% */
    --secondary-foreground: 213 13% 92%;

    --muted: 220 13% 22%;
    --muted-foreground: 215 10% 65%;

    --accent: 218 28% 18%; /* hover/active tint, less blue-shift */
    --accent-foreground: 221 83% 80%;

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

    --border: 220 13% 22%; /* ≈ #21262d, GitHub border default */
    --border-light: 220 13% 16%;
    --input: 220 13% 22%;
    --ring: 221 83% 62%;

    --surface: 220 13% 11%;
    --surface-secondary: 220 13% 9%;
    --surface-tertiary: 220 13% 22%;

    --subtle: 215 10% 47%;
    --subtle-light: 215 10% 35%;
    --subtle-dark: 213 13% 80%;

    --sidebar-bg: 220 13% 9%;
    --sidebar-border: 220 13% 22%;
    --sidebar-active-bg: 218 28% 17%; /* slightly more chroma so active row reads */
    --sidebar-active-fg: 221 83% 80%;
    --sidebar-text: 213 13% 80%;

    --success: 142 71% 55%;
    --success-soft: 142 30% 18%;
    --warning: 38 92% 60%;
    --warning-soft: 38 30% 18%;
    --danger: 0 84% 65%;
    --danger-soft: 0 30% 20%;
    --info: 217 91% 70%;
    --info-soft: 217 30% 18%;
    --purple: 262 84% 65%;
    --purple-soft: 262 30% 22%;
  }
}

@theme inline {
  --font-sans: var(--font-sans);
  --font-display: var(--font-display);
  --font-mono: var(--font-mono);
}

@layer base {
  * {
    border-color: hsl(var(--border));
  }

  html {
    font-family:
      -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
      "Hiragino Sans GB", "Microsoft YaHei", ui-sans-serif, system-ui,
      sans-serif;
  }

  body {
    color: hsl(var(--foreground));
    background-color: hsl(var(--background));
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  h1,
  h2 {
    letter-spacing: -0.01em;
  }

  code,
  pre,
  kbd,
  samp {
    font-family:
      var(--font-mono), ui-monospace, SFMono-Regular, Menlo, monospace;
  }
}

/* Home page motion primitives. Transform + opacity only so the browser can
   run them entirely on the compositor thread without triggering layout. */
@keyframes home-float {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(0, -6px, 0);
  }
}

@keyframes home-reveal {
  from {
    opacity: 0;
    transform: translate3d(0, 8px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.animate-home-float {
  animation: home-float 4.5s ease-in-out infinite;
  will-change: transform;
}

.animate-home-float-delayed {
  animation: home-float 4.5s ease-in-out infinite;
  animation-delay: -2.25s;
  will-change: transform;
}

.animate-home-reveal {
  animation: home-reveal 420ms var(--ease-standard) both;
  will-change: transform, opacity;
}

/* Rerank strategy panel slide-in. Paired with a `key={rerankType}` remount
   so each segmented-control switch replays the animation. A horizontal
   offset reads as a "swap" rather than a "reveal". */
@keyframes rerank-slide {
  from {
    opacity: 0;
    transform: translate3d(8px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.animate-rerank-slide {
  animation: rerank-slide 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
  will-change: transform, opacity;
}

/* Text shimmer used for the "deep thinking" state badge during streaming. */
@keyframes text-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.animate-text-shimmer {
  animation: text-shimmer 2s linear infinite;
  will-change: background-position;
}

@keyframes thinking-aurora {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.85);
  }
  50% {
    opacity: 0.85;
    transform: scale(1.15);
  }
}

@keyframes thinking-icon-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

.animate-thinking-aurora {
  animation: thinking-aurora 1.6s ease-in-out infinite;
  will-change: transform, opacity;
}

.animate-thinking-icon {
  animation: thinking-icon-breathe 1.6s ease-in-out infinite;
  will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
  .animate-home-float,
  .animate-home-float-delayed,
  .animate-home-reveal,
  .animate-rerank-slide,
  .animate-text-shimmer,
  .animate-thinking-aurora,
  .animate-thinking-icon {
    animation: none !important;
  }
}
