@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
  --background: 245 246 250;
  --surface: 255 255 255;
  --surface-muted: 240 242 248;
  --border: 228 231 239;
  --border-strong: 205 210 224;
  --foreground: 15 20 36;
  --muted-foreground: 91 99 120;
  --subtle-foreground: 138 146 166;
  --primary: 79 70 229;
  --primary-hover: 67 56 202;
  --primary-soft: 238 240 255;
  --primary-foreground: 255 255 255;
  --accent: 124 58 237;
  --success: 18 183 106;
  --success-soft: 231 248 240;
  --warning: 247 144 9;
  --warning-soft: 255 244 224;
  --danger: 229 72 77;
  --danger-soft: 253 236 236;
  --info: 46 144 250;
  --info-soft: 232 242 255;
  --ring: 79 70 229;
  --card: var(--surface);
  --muted: var(--muted-foreground);
  --neutral: var(--subtle-foreground);
  /* Always-dark "ink" surface used by the marketing stats band in both themes */
  --ink-from: 30 27 75;
  --ink-to: 10 12 20;
  /* Brand gradient stops for surfaces that carry white text (buttons, CTA panels) */
  --brand-from: 79 70 229;
  --brand-to: 124 58 237;
  color-scheme: light;
}

.dark {
  --background: 10 12 20;
  --surface: 17 20 31;
  --surface-muted: 23 27 40;
  --border: 35 40 56;
  --border-strong: 50 58 82;
  --foreground: 238 240 248;
  --muted-foreground: 163 171 194;
  --subtle-foreground: 111 120 147;
  --primary: 124 131 255;
  --primary-hover: 144 150 255;
  --primary-soft: 27 31 64;
  --primary-foreground: 255 255 255;
  --accent: 167 139 250;
  --success: 61 214 140;
  --success-soft: 15 42 31;
  --warning: 253 176 34;
  --warning-soft: 46 34 16;
  --danger: 242 104 108;
  --danger-soft: 46 21 23;
  --info: 90 169 255;
  --info-soft: 16 34 59;
  --ring: 124 131 255;
  --card: var(--surface);
  --muted: var(--muted-foreground);
  --neutral: var(--subtle-foreground);
  --ink-from: 30 27 75;
  --ink-to: 10 12 20;
  /* Deeper than the dark-theme primary so white text keeps >= 4.5:1 contrast */
  --brand-from: 88 80 236;
  --brand-to: 124 58 237;
  color-scheme: dark;
}

@layer base {
  * {
    @apply border-border;
  }

  html {
    scroll-behavior: smooth;
  }

  body {
    @apply bg-background text-foreground antialiased;
    font-family: var(--font-inter), ui-sans-serif, system-ui, sans-serif;
    font-feature-settings: 'tnum' 1;
  }

  ::selection {
    background: rgb(var(--primary-soft));
    color: rgb(var(--foreground));
  }

  :focus-visible {
    @apply outline-none focus-ring;
  }
}

@layer utilities {
  .bg-brand-gradient {
    background-image: linear-gradient(135deg, rgb(var(--brand-from)), rgb(var(--brand-to)));
  }

  .text-brand-gradient {
    background-image: linear-gradient(135deg, rgb(var(--primary)), rgb(var(--accent)));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .glass {
    background: rgb(var(--surface) / 0.7);
    backdrop-filter: blur(12px);
    border: 1px solid rgb(var(--border));
  }

  .bg-grid {
    background-image:
      linear-gradient(rgb(var(--border) / 0.55) 1px, transparent 1px),
      linear-gradient(90deg, rgb(var(--border) / 0.55) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(ellipse at center, black 35%, transparent 75%);
  }

  .bg-mesh {
    background:
      radial-gradient(ellipse 50% 40% at 15% 20%, rgb(var(--primary) / 0.16), transparent 60%),
      radial-gradient(ellipse 45% 35% at 85% 15%, rgb(var(--accent) / 0.14), transparent 55%),
      radial-gradient(ellipse 40% 40% at 70% 80%, rgb(var(--primary) / 0.1), transparent 50%);
  }

  .bg-ink {
    background-image: linear-gradient(135deg, rgb(var(--ink-from)), rgb(var(--ink-to)));
  }

  .focus-ring {
    box-shadow: 0 0 0 2px rgb(var(--background)), 0 0 0 4px rgb(var(--primary) / 0.5);
  }

  .gradient-border {
    position: relative;
    background: rgb(var(--surface));
    border-radius: 1.25rem;
  }

  .gradient-border::before {
    content: '';
    position: absolute;
    inset: 0;
    padding: 1px;
    border-radius: inherit;
    background: linear-gradient(135deg, rgb(var(--primary)), rgb(var(--accent)));
    mask:
      linear-gradient(#000 0 0) content-box,
      linear-gradient(#000 0 0);
    mask-composite: exclude;
    pointer-events: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
  }

  @keyframes fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes float {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
  }

  @keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.35); opacity: 0.55; }
  }

  @keyframes gradient-pan {
    0% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
  }

  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
  }

  @keyframes marquee {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
  }

  .animate-shimmer {
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
  }

  .animate-fade-up {
    animation: fade-up 180ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }

  .animate-float {
    animation: float 6s ease-in-out infinite alternate;
  }

  .animate-pulse-dot {
    animation: pulse-dot 1.6s ease-in-out infinite;
  }

  @keyframes sweep {
    0%, 75% { transform: translateX(-120%) skewX(-18deg); }
    100% { transform: translateX(320%) skewX(-18deg); }
  }

  @keyframes field-error {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes sheen {
    from { transform: translateX(-100%); }
    to { transform: translateX(250%); }
  }

  @keyframes ring-pulse {
    0% { transform: scale(0.9); opacity: 0.55; }
    100% { transform: scale(1.6); opacity: 0; }
  }

  @keyframes progress-indeterminate {
    0% { transform: translateX(-100%) scaleX(0.4); }
    100% { transform: translateX(250%) scaleX(0.4); }
  }

  @keyframes route-travel {
    0% { left: 0%; opacity: 0; }
    15%, 85% { opacity: 1; }
    100% { left: calc(100% - 12px); opacity: 0; }
  }

  @keyframes row-flash {
    0%, 40% { background-color: rgb(var(--primary-soft)); }
    100% { background-color: transparent; }
  }

  @keyframes preset-flash {
    0% { background-color: rgb(var(--primary-soft)); box-shadow: 0 0 0 4px rgb(var(--primary) / 0.18); }
    100% { background-color: rgb(var(--surface)); box-shadow: 0 0 0 0 rgb(var(--primary) / 0); }
  }

  @keyframes route-dot {
    0% { offset-distance: 0%; opacity: 0; }
    12%, 88% { opacity: 1; }
    100% { offset-distance: 100%; opacity: 0; }
  }

  .animate-sweep {
    animation: sweep 8s cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
  }

  .animate-marquee {
    animation: marquee 40s linear infinite;
  }

  .group:hover .animate-marquee,
  .animate-marquee:hover {
    animation-play-state: paused;
  }
}

@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;
    scroll-behavior: auto !important;
  }
}

@layer base {
  ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
  }

  ::-webkit-scrollbar-thumb {
    background: rgb(var(--border-strong));
    border-radius: 999px;
  }

  ::-webkit-scrollbar-track {
    background: transparent;
  }
}

/* Recharts theming: token colors instead of library defaults */
@layer components {
  .chart .recharts-cartesian-grid line {
    stroke: rgb(var(--border));
    stroke-dasharray: 4 4;
  }

  .chart .recharts-cartesian-axis-tick-value,
  .chart .recharts-cartesian-axis-tick-value tspan {
    fill: rgb(var(--subtle-foreground));
    font-size: 12px;
  }

  .chart .recharts-tooltip-cursor {
    fill: rgb(var(--surface-muted));
  }

  .chart .recharts-surface:focus,
  .chart .recharts-wrapper:focus {
    outline: none;
  }
}
