@import 'tailwindcss';
@import 'tw-animate-css';

@source "../../../../packages/agent-playground/src";
@source "../../../../packages/agent-web/src";

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

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

/* ========================================
   Studio Design System — Color Tokens
   ======================================== */
:root {
  --radius: 0.5rem;

  /* Studio palette */
  --studio-bg: #1e1e2e;
  --studio-bg-elevated: #262637;
  --studio-bg-surface: #2a2a3d;
  --studio-border: #363650;
  --studio-border-subtle: #2d2d44;
  --studio-text: #e4e4ef;
  --studio-text-secondary: #8b8ba3;
  --studio-text-muted: #5c5c7a;
  --studio-accent-violet: #a78bfa;
  --studio-accent-violet-dim: rgba(167, 139, 250, 0.15);
  --studio-accent-amber: #fbbf24;
  --studio-accent-amber-dim: rgba(251, 191, 36, 0.15);
  --studio-accent-rose: #fb7185;
  --studio-accent-rose-dim: rgba(251, 113, 133, 0.15);
  --studio-accent-emerald: #34d399;
  --studio-accent-emerald-dim: rgba(52, 211, 153, 0.15);
  --studio-accent-cyan: #22d3ee;

  /* Tailwind/shadcn semantic tokens mapped to Studio palette */
  --background: #1e1e2e;
  --foreground: #e4e4ef;

  --card: #262637;
  --card-foreground: #e4e4ef;

  --popover: #262637;
  --popover-foreground: #e4e4ef;

  --primary: #a78bfa;
  --primary-foreground: #1e1e2e;

  --secondary: #2a2a3d;
  --secondary-foreground: #e4e4ef;

  --muted: #2a2a3d;
  --muted-foreground: #8b8ba3;

  --accent: #a78bfa;
  --accent-foreground: #1e1e2e;

  --destructive: #fb7185;
  --destructive-foreground: #1e1e2e;

  --border: #363650;
  --input: #363650;
  --ring: #a78bfa;

  --chart-1: #a78bfa;
  --chart-2: #22d3ee;
  --chart-3: #fb7185;
  --chart-4: #34d399;
  --chart-5: #fbbf24;

  --sidebar: #1e1e2e;
  --sidebar-foreground: #e4e4ef;
  --sidebar-primary: #a78bfa;
  --sidebar-primary-foreground: #1e1e2e;
  --sidebar-accent: #2a2a3d;
  --sidebar-accent-foreground: #e4e4ef;
  --sidebar-border: #363650;
  --sidebar-ring: #a78bfa;
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }

  html,
  body {
    height: 100%;
  }

  body {
    background: var(--studio-bg);
    color: var(--studio-text);
    font-family: var(--font-sans), ui-sans-serif, system-ui, sans-serif;
    font-feature-settings:
      'rlig' 1,
      'calt' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Studio dark theme for all form elements */
  input,
  textarea,
  select {
    background-color: var(--studio-bg-surface);
    border: 1px solid var(--studio-border);
    color: var(--studio-text);
    border-radius: 6px;
  }

  input:focus,
  textarea:focus,
  select:focus {
    outline: none;
    border-color: var(--studio-accent-violet);
    box-shadow: 0 0 0 1px var(--studio-accent-violet);
  }

  input::placeholder,
  textarea::placeholder {
    color: var(--studio-text-muted);
  }

  select option {
    background-color: var(--studio-bg-elevated);
    color: var(--studio-text);
  }
}

/* ========================================
   Custom Scrollbar — Studio
   ======================================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--studio-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--studio-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--studio-text-muted);
}

/* ========================================
   Accessibility Utilities
   ======================================== */
@layer utilities {
  .sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

  .focus-visible {
    @apply outline-none ring-2 ring-ring ring-offset-2 ring-offset-background;
  }

  @media (prefers-reduced-motion: reduce) {
    .reduce-motion *,
    .reduce-motion *::before,
    .reduce-motion *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* ========================================
   React Flow Node Styles — Studio Theme
   ======================================== */

/* === UNIVERSAL NODE STYLES === */
.react-flow__node {
  background: var(--studio-bg-elevated);
  color: var(--studio-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

.react-flow__node:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* === USER INPUT === */
.react-flow__node-user_message {
  border: 2px solid #a78bfa;
}

/* === AGENT NODES === */
.react-flow__node-agent {
  border: 2px solid #3b82f6;
}

.react-flow__node-team {
  border: 2px solid #34d399;
}

.react-flow__node-tool {
  border: 2px solid #fbbf24;
}

/* === THINKING PROCESS === */
.react-flow__node-agent_thinking {
  border: 2px solid #22d3ee;
}

/* === TOOL ACTIONS === */
.react-flow__node-tool_call {
  border: 2px solid #ea580c;
}

/* === RESPONSES === */
.react-flow__node-response {
  border: 2px solid #34d399;
}

.react-flow__node-tool_response {
  border: 2px solid #34d399;
}

/* === MERGE POINTS === */
.react-flow__node-tool_result {
  border: 2px solid #a78bfa;
}

/* === COMPATIBILITY NODE TYPES (camelCase) === */
.react-flow__node-toolCall {
  border: 2px solid #ea580c;
}

.react-flow__node-agentResponse {
  border: 2px solid #34d399;
}

/* === STATUS INDICATORS === */
@keyframes studio-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(52, 211, 153, 0);
  }
}

@keyframes bounce {
  0%,
  20%,
  53%,
  80%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  40%,
  43% {
    transform: translate3d(0, -8px, 0);
  }
  70% {
    transform: translate3d(0, -4px, 0);
  }
  90% {
    transform: translate3d(0, -2px, 0);
  }
}

.react-flow__node[data-status='running'] {
  animation: studio-pulse 2s infinite;
  border-color: var(--studio-accent-emerald) !important;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.2);
}

.react-flow__node[data-status='completed'] {
  border-color: var(--studio-accent-emerald) !important;
}

.react-flow__node[data-status='error'] {
  border-color: var(--studio-accent-rose) !important;
  background: var(--studio-accent-rose-dim) !important;
}

/* Selected node — violet glow */
.react-flow__node.selected,
.react-flow__node:focus {
  box-shadow:
    0 0 0 2px var(--studio-accent-violet),
    0 0 24px rgba(167, 139, 250, 0.25);
}

/* === EDGES === */
.react-flow__edge-path {
  stroke: var(--studio-border);
  stroke-width: 2;
}

.react-flow__edge.selected .react-flow__edge-path {
  stroke: var(--studio-accent-violet);
}

/* === HANDLES === */
.react-flow__handle {
  background: var(--studio-text-muted);
  border: 2px solid var(--studio-bg-elevated);
  width: 10px;
  height: 10px;
}

.react-flow__handle:hover {
  background: var(--studio-accent-violet);
}

/* === MINIMAP === */
.react-flow__minimap {
  background: var(--studio-bg) !important;
  border: 1px solid var(--studio-border) !important;
  border-radius: 8px;
}

/* === CONTROLS === */
.react-flow__controls {
  background: var(--studio-bg-elevated) !important;
  border: 1px solid var(--studio-border) !important;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.react-flow__controls-button {
  background: var(--studio-bg-elevated) !important;
  border-color: var(--studio-border) !important;
  color: var(--studio-text-secondary) !important;
  fill: var(--studio-text-secondary) !important;
}

.react-flow__controls-button:hover {
  background: var(--studio-bg-surface) !important;
  color: var(--studio-text) !important;
  fill: var(--studio-text) !important;
}

/* === BACKGROUND === */
.react-flow__background {
  background: var(--studio-bg) !important;
}
