@import 'tailwindcss';

/* ===========================================================================
   WrongStack WebUI — "Engineering Instrument Deck"
   IBM Plex typography · warm graphite (dark) / warm paper (light) ·
   signal-amber accent · blueprint grid atmosphere · status LEDs.
   =========================================================================== */

@theme {
  --font-sans: 'IBM Plex Sans Variable', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* shadcn-compatible color tokens bridged to Tailwind 4 */
  --color-border: hsl(var(--border));
  --color-input: hsl(var(--input));
  --color-ring: hsl(var(--ring));
  --color-background: hsl(var(--background));
  --color-foreground: hsl(var(--foreground));
  --color-success: hsl(var(--success));
  --color-warning: hsl(var(--warning));
  --color-info: hsl(var(--info));
  --color-running: hsl(var(--running));
  --color-primary: hsl(var(--primary));
  --color-primary-foreground: hsl(var(--primary-foreground));
  --color-secondary: hsl(var(--secondary));
  --color-secondary-foreground: hsl(var(--secondary-foreground));
  --color-destructive: hsl(var(--destructive));
  --color-destructive-foreground: hsl(var(--destructive-foreground));
  --color-muted: hsl(var(--muted));
  --color-muted-foreground: hsl(var(--muted-foreground));
  --color-accent: hsl(var(--accent));
  --color-accent-foreground: hsl(var(--accent-foreground));
  --color-popover: hsl(var(--popover));
  --color-popover-foreground: hsl(var(--popover-foreground));
  --color-card: hsl(var(--card));
  --color-card-foreground: hsl(var(--card-foreground));

  --radius-lg: var(--radius);
  --radius-md: calc(var(--radius) - 2px);
  --radius-sm: calc(var(--radius) - 4px);
}

@layer base {
  :root {
    /* — Light: warm paper — */
    --background: 40 33% 97%;
    --foreground: 222 24% 13%;
    --card: 40 33% 99%;
    --card-foreground: 222 24% 13%;
    --popover: 40 33% 99%;
    --popover-foreground: 222 24% 13%;

    --primary: 28 92% 46%;            /* deep signal amber for paper contrast */
    --primary-foreground: 40 40% 99%;
    --secondary: 40 22% 92%;
    --secondary-foreground: 222 24% 16%;
    --muted: 40 20% 92%;
    --muted-foreground: 222 10% 42%;
    --accent: 40 24% 90%;
    --accent-foreground: 28 92% 38%;
    --destructive: 0 72% 48%;
    --destructive-foreground: 40 40% 99%;

    --border: 40 16% 85%;
    --input: 40 16% 87%;
    --ring: 28 92% 46%;

    /* Semantic signals (shared names, theme-tuned) */
    --success: 150 58% 36%;
    --warning: 32 92% 44%;
    --info: 200 80% 40%;
    --running: 28 92% 46%;

    --radius: 0.625rem;
    --font-sans: 'IBM Plex Sans Variable', ui-sans-serif, system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    --grid-line: 222 24% 13%;
    --grid-opacity: 0.05;
    --shadow-color: 222 30% 30%;
  }

  .dark {
    /* — Dark (hero): warm graphite — */
    --background: 225 17% 8%;
    --foreground: 40 22% 92%;
    --card: 225 15% 11%;
    --card-foreground: 40 22% 92%;
    --popover: 225 16% 10%;
    --popover-foreground: 40 22% 92%;

    --primary: 36 96% 56%;            /* CRT signal amber */
    --primary-foreground: 28 60% 8%;
    --secondary: 225 12% 16%;
    --secondary-foreground: 40 22% 92%;
    --muted: 225 12% 15%;
    --muted-foreground: 225 9% 60%;
    --accent: 225 13% 17%;
    --accent-foreground: 36 96% 62%;
    --destructive: 0 70% 55%;
    --destructive-foreground: 40 40% 96%;

    --border: 225 12% 18%;
    --input: 225 12% 17%;
    --ring: 36 96% 56%;

    --success: 150 64% 46%;
    --warning: 36 96% 56%;
    --info: 198 82% 56%;
    --running: 36 96% 56%;

    --grid-line: 40 22% 92%;
    --grid-opacity: 0.045;
    --shadow-color: 225 60% 2%;
  }
}

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

  html {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  body {
    @apply bg-background text-foreground;
    font-family: var(--font-sans);
    font-feature-settings: 'liga' 1, 'calt' 1, 'ss03' 1;
  }

  /* Content sits above the blueprint atmosphere. */
  #root {
    position: relative;
    z-index: 1;
    isolation: isolate;
    height: 100%;
  }

  /* Blueprint grid — a faint engineering substrate that fades from the top.
     Theme-aware via --grid-line; fixed so it reads as the deck surface. */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
      linear-gradient(hsl(var(--grid-line) / var(--grid-opacity)) 1px, transparent 1px),
      linear-gradient(90deg, hsl(var(--grid-line) / var(--grid-opacity)) 1px, transparent 1px);
    background-size: 34px 34px;
    mask-image: radial-gradient(140% 90% at 50% -10%, #000 30%, transparent 82%);
    -webkit-mask-image: radial-gradient(140% 90% at 50% -10%, #000 30%, transparent 82%);
  }

  ::selection {
    background-color: hsl(var(--primary) / 0.28);
    color: hsl(var(--foreground));
  }

  /* Monospace numerics line up in data readouts. */
  .tabular {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
  }
}

/* — Status LED: a glowing instrument dot. Color via `color:` (currentColor). — */
@layer components {
  .led {
    @apply inline-block rounded-full;
    width: 0.5rem;
    height: 0.5rem;
    background: currentColor;
    box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 8px 0 currentColor;
  }
  .led-pulse {
    animation: ledPulse 1.4s ease-in-out infinite;
  }
}

@keyframes ledPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 7px 0 currentColor; }
  50% { opacity: 0.55; box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 13px 1px currentColor; }
}

/* — Scrollbars — */
::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
::-webkit-scrollbar-track {
  @apply bg-transparent;
}
::-webkit-scrollbar-thumb {
  background-color: hsl(var(--muted-foreground) / 0.28);
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background-color: hsl(var(--primary) / 0.6);
}

/* — Message bubble depth — */
.msg-bubble {
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}
.msg-bubble:hover {
  box-shadow: 0 2px 12px -2px hsl(var(--shadow-color) / 0.08);
}

/* — Chat turn separator — subtle horizontal divider between turns */
.chat-turn + .chat-turn {
  border-top: 1px solid hsl(var(--border) / 0.3);
  padding-top: 1.25rem;
  margin-top: 1.25rem;
}

/* — Tool card expansion animation — */
.tool-details {
  animation: toolExpand 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toolExpand {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 2000px; }
}

/* — Jump-to-bottom button pulse — */
.jump-bottom {
  animation: jumpPulse 2s ease-in-out infinite;
}
@keyframes jumpPulse {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-2px); }
}

/* — Keyboard shortcut bar at bottom — */
.shortcut-bar {
  background: linear-gradient(to top, hsl(var(--background)), transparent);
}

/* — Better stream cursor — */
.streaming-cursor::after {
  content: '▍';
  animation: blink 1s step-end infinite;
  color: hsl(var(--primary));
  opacity: 0.8;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* — Motion — */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes shimmer {
  100% { transform: translateX(100%); }
}
.animate-message { animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
.animate-tool { animation: slideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1); }

/* Indeterminate progress sweep for "working" bars. */
.bar-sweep { position: relative; overflow: hidden; }
.bar-sweep::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, hsl(var(--primary) / 0.7), transparent);
  animation: shimmer 1.5s infinite;
}

/* — Markdown content — */
.markdown-content { @apply leading-relaxed; }
.markdown-content p { @apply mb-3; }
.markdown-content code {
  font-family: var(--font-mono);
  @apply bg-muted px-1.5 py-0.5 rounded text-[0.85em];
  border: 1px solid hsl(var(--border));
}
.markdown-content pre {
  font-family: var(--font-mono);
  @apply bg-muted p-4 rounded-lg overflow-x-auto mb-3;
  border: 1px solid hsl(var(--border));
}
.markdown-content pre code { @apply bg-transparent p-0; border: 0; }
.markdown-content ul, .markdown-content ol { @apply mb-3 pl-6; }
.markdown-content ul { list-style: disc; }
.markdown-content ol { list-style: decimal; }
.markdown-content li { @apply mb-1; }
.markdown-content a { @apply text-primary underline underline-offset-2; }
.markdown-content h1, .markdown-content h2, .markdown-content h3 {
  @apply font-semibold mt-4 mb-2; letter-spacing: -0.01em;
}
.markdown-content blockquote {
  @apply border-l-2 border-primary pl-4 italic text-muted-foreground;
}

/* — Search highlight (CSS Custom Highlights API) — */
::highlight(chat-search) { background-color: hsl(var(--primary) / 0.3); color: inherit; }
::highlight(chat-search-active) { background-color: hsl(var(--primary) / 0.85); color: hsl(var(--primary-foreground)); }

/* — Vim-style chat focus marker — */
[data-message-id][data-focused="true"] {
  position: relative;
  background-color: hsl(var(--primary) / 0.05);
  border-radius: 0.5rem;
  transition: background-color 0.15s ease-out;
}
[data-message-id][data-focused="true"]::before {
  content: "";
  position: absolute;
  left: -8px; top: 4px; bottom: 4px;
  width: 3px; border-radius: 2px;
  background-color: hsl(var(--primary));
  box-shadow: 0 0 10px 0 hsl(var(--primary) / 0.6);
  pointer-events: none;
}

/* ── IDE layout: file explorer & code editor ── */

/* File tree — compact, VS Code-style indentation */
.ide-tree-item {
  @apply flex items-center gap-1 w-full text-left px-1 py-0.5 text-[11px] rounded;
  @apply hover:bg-muted/60 transition-colors cursor-pointer;
}

/* Editor tab bar — VS Code-style active indicator */
.editor-tab {
  @apply flex items-center gap-1.5 px-3 py-1.5 text-[11px] border-r whitespace-nowrap min-w-0 max-w-[180px] transition-colors;
}

/* Monaco editor container — fill available space */
.monaco-editor-container {
  @apply flex-1 relative;
}

/* Dirty file indicator dot */
.dirty-dot {
  @apply h-2 w-2 rounded-full bg-primary shrink-0;
  box-shadow: 0 0 4px 0 hsl(var(--primary) / 0.6);
}

/* kbds in editor shortcuts bar */
kbd {
  @apply px-1 py-0.5 rounded bg-muted text-[9px] font-mono border;
}
