@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@import "@xterm/xterm/css/xterm.css";

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

:root {
  font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 24px;
  font-weight: 400;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.58 0.22 27);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --chart-1: oklch(0.809 0.105 251.813);
  --chart-2: oklch(0.623 0.214 259.815);
  --chart-3: oklch(0.546 0.245 262.881);
  --chart-4: oklch(0.488 0.243 264.376);
  --chart-5: oklch(0.424 0.199 265.638);
  --radius: 0.625rem;
  --sidebar: oklch(0.985 0 0);
  --sidebar-foreground: oklch(0.145 0 0);
  --sidebar-primary: oklch(0.205 0 0);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.94 0 0);
  --sidebar-accent-foreground: oklch(0.205 0 0);
  --sidebar-border: oklch(0.922 0 0);
  --sidebar-ring: oklch(0.708 0 0);
}

.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.87 0.00 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.371 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);
  --chart-1: oklch(0.809 0.105 251.813);
  --chart-2: oklch(0.623 0.214 259.815);
  --chart-3: oklch(0.546 0.245 262.881);
  --chart-4: oklch(0.488 0.243 264.376);
  --chart-5: oklch(0.424 0.199 265.638);
  --sidebar: oklch(0.205 0 0);
  --sidebar-foreground: oklch(0.985 0 0);
  --sidebar-primary: oklch(0.488 0.243 264.376);
  --sidebar-primary-foreground: oklch(0.985 0 0);
  --sidebar-accent: oklch(0.28 0 0);
  --sidebar-accent-foreground: oklch(0.985 0 0);
  --sidebar-border: oklch(1 0 0 / 10%);
  --sidebar-ring: oklch(0.556 0 0);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --background: oklch(0.145 0 0);
    --foreground: oklch(0.985 0 0);
    --card: oklch(0.205 0 0);
    --card-foreground: oklch(0.985 0 0);
    --popover: oklch(0.205 0 0);
    --popover-foreground: oklch(0.985 0 0);
    --primary: oklch(0.87 0.00 0);
    --primary-foreground: oklch(0.205 0 0);
    --secondary: oklch(0.269 0 0);
    --secondary-foreground: oklch(0.985 0 0);
    --muted: oklch(0.269 0 0);
    --muted-foreground: oklch(0.708 0 0);
    --accent: oklch(0.371 0 0);
    --accent-foreground: oklch(0.985 0 0);
    --destructive: oklch(0.704 0.191 22.216);
    --border: oklch(1 0 0 / 10%);
    --input: oklch(1 0 0 / 15%);
    --ring: oklch(0.556 0 0);
    --sidebar: oklch(0.205 0 0);
    --sidebar-foreground: oklch(0.985 0 0);
    --sidebar-primary: oklch(0.488 0.243 264.376);
    --sidebar-primary-foreground: oklch(0.985 0 0);
    --sidebar-accent: oklch(0.28 0 0);
    --sidebar-accent-foreground: oklch(0.985 0 0);
    --sidebar-border: oklch(1 0 0 / 10%);
    --sidebar-ring: oklch(0.556 0 0);
  }
}

@theme inline {
  --font-sans: var(--font-sans);
  --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);
  --color-foreground: var(--foreground);
  --color-background: var(--background);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --radius-2xl: calc(var(--radius) + 8px);
  --radius-3xl: calc(var(--radius) + 12px);
  --radius-4xl: calc(var(--radius) + 16px);
}

@layer base {
  * {
    @apply border-border outline-ring/50;
  }
  body {
    @apply bg-background text-foreground;
  }
}

/* Streamdown code blocks: dark mode via shiki dual-theme CSS variables */
.dark [data-streamdown="code-block-body"] {
  background-color: var(--shiki-dark-bg, var(--sdm-bg, transparent)) !important;
  color: var(--shiki-dark, var(--sdm-fg, inherit)) !important;
}

.dark [data-streamdown="code-block-body"] code > span > span {
  color: var(--shiki-dark, var(--sdm-c, inherit)) !important;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) [data-streamdown="code-block-body"] {
    background-color: var(--shiki-dark-bg, var(--sdm-bg, transparent)) !important;
    color: var(--shiki-dark, var(--sdm-fg, inherit)) !important;
  }

  :root:not(.light) [data-streamdown="code-block-body"] code > span > span {
    color: var(--shiki-dark, var(--sdm-c, inherit)) !important;
  }
}

/* Streamdown table overrides */
[data-streamdown="table-wrapper"] {
  position: relative;
}

/* Toolbar: float over table top-right, no vertical space */
[data-streamdown="table-wrapper"] > div:first-child:has(button) {
  position: absolute;
  top: -2rem;
  right: 0;
  z-index: 10;
}

/* Streamdown code line number width by total line digits */
[data-streamdown="code-block-body"] code {
  --sd-line-number-width: 1ch;
}

[data-streamdown="code-block-body"] code:has(> span:nth-child(n + 10)) {
  --sd-line-number-width: 2ch;
}

[data-streamdown="code-block-body"] code:has(> span:nth-child(n + 100)) {
  --sd-line-number-width: 3ch;
}

[data-streamdown="code-block-body"] code:has(> span:nth-child(n + 1000)) {
  --sd-line-number-width: 4ch;
}

[data-streamdown="code-block-body"] code:has(> span:nth-child(n + 10000)) {
  --sd-line-number-width: 5ch;
}

[data-streamdown="code-block-body"] code:has(> span:nth-child(n + 100000)) {
  --sd-line-number-width: 6ch;
}

[data-streamdown="code-block-body"] code > span::before {
  width: var(--sd-line-number-width) !important;
  font-variant-numeric: tabular-nums;
}


/* Tool collapsible: fade-in on expand (height must change instantly for virtualizer) */
.tool-collapsible-content[data-state="open"] > * {
  animation: tool-content-fade 150ms ease-out;
}

@keyframes tool-content-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.select-none {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Monaco widgets: align popups/menus with shadcn surface style */
.context-view .monaco-menu,
.monaco-editor .suggest-widget,
.monaco-editor .editor-widget,
.monaco-editor .peekview-widget,
.monaco-hover.workbench-hover {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 18px 36px -24px rgb(0 0 0 / 55%) !important;
}

.context-view .monaco-menu .monaco-action-bar.vertical .action-item .action-menu-item,
.monaco-editor .suggest-widget .monaco-list-row,
.monaco-editor .peekview-widget .monaco-list-row {
  border-radius: calc(var(--radius) - 2px);
}

.monaco-editor .codeg-dirty-diff-glyph {
  margin-left: 5px;
  position: relative;
  border-left-style: solid;
  border-left-width: 2px;
  z-index: 5;
}

.monaco-editor .codeg-dirty-diff-added {
  border-left-color: #2ea043;
}

.monaco-editor .codeg-dirty-diff-modified {
  border-left-color: #1f6feb;
}

.monaco-editor .codeg-dirty-diff-deleted {
  border-left-color: #cf222e;
}

.monaco-editor .codeg-dirty-diff-deleted::after {
  content: "";
  position: absolute;
  bottom: -4px;
  left: -4px;
  border: 4px solid transparent;
  border-top-color: #cf222e;
}

.monaco-editor .codeg-session-diff-line-added {
  background-color: rgba(46, 160, 67, 0.14);
}

.monaco-editor .codeg-session-diff-line-modified {
  background-color: rgba(31, 111, 235, 0.12);
}

.monaco-editor .codeg-session-diff-line-deleted {
  background-color: rgba(207, 34, 46, 0.12);
}

.dark .monaco-editor .codeg-dirty-diff-added {
  border-left-color: #3fb950;
}

.dark .monaco-editor .codeg-dirty-diff-modified {
  border-left-color: #388bfd;
}

.dark .monaco-editor .codeg-dirty-diff-deleted {
  border-left-color: #f85149;
}

.dark .monaco-editor .codeg-dirty-diff-deleted::after {
  border-top-color: #f85149;
}

.dark .monaco-editor .codeg-session-diff-line-added {
  background-color: rgba(63, 185, 80, 0.18);
}

.dark .monaco-editor .codeg-session-diff-line-modified {
  background-color: rgba(56, 139, 253, 0.2);
}

.dark .monaco-editor .codeg-session-diff-line-deleted {
  background-color: rgba(248, 81, 73, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) .monaco-editor .codeg-dirty-diff-added {
    border-left-color: #3fb950;
  }

  :root:not(.light) .monaco-editor .codeg-dirty-diff-modified {
    border-left-color: #388bfd;
  }

  :root:not(.light) .monaco-editor .codeg-dirty-diff-deleted {
    border-left-color: #f85149;
  }

  :root:not(.light) .monaco-editor .codeg-dirty-diff-deleted::after {
    border-top-color: #f85149;
  }

  :root:not(.light) .monaco-editor .codeg-session-diff-line-added {
    background-color: rgba(63, 185, 80, 0.18);
  }

  :root:not(.light) .monaco-editor .codeg-session-diff-line-modified {
    background-color: rgba(56, 139, 253, 0.2);
  }

  :root:not(.light) .monaco-editor .codeg-session-diff-line-deleted {
    background-color: rgba(248, 81, 73, 0.2);
  }
}

/* Merge editor: hunk type decorations (IDEA-style) */

/* Left pane (ours) & Right pane (theirs) — diff highlights */
.monaco-editor .merge-hunk-added-bg {
  background-color: rgba(46, 160, 67, 0.12);
}

.monaco-editor .merge-hunk-modified-bg {
  background-color: rgba(31, 111, 235, 0.12);
}

.monaco-editor .merge-hunk-removed-bg {
  background-color: rgba(128, 128, 128, 0.15);
}

/* Center pane — conflict regions */
.monaco-editor .merge-hunk-conflict-bg {
  background-color: rgba(248, 81, 73, 0.12);
}

/* Center pane — applied hunk */
.monaco-editor .merge-hunk-applied-bg {
  background-color: rgba(46, 160, 67, 0.08);
}

/* Center pane — pending non-conflict hunk */
.monaco-editor .merge-hunk-pending-bg {
  background-color: rgba(234, 179, 8, 0.06);
}

/* Dark mode overrides */
.dark .monaco-editor .merge-hunk-added-bg {
  background-color: rgba(63, 185, 80, 0.18);
}

.dark .monaco-editor .merge-hunk-modified-bg {
  background-color: rgba(56, 139, 253, 0.18);
}

.dark .monaco-editor .merge-hunk-removed-bg {
  background-color: rgba(128, 128, 128, 0.2);
}

.dark .monaco-editor .merge-hunk-conflict-bg {
  background-color: rgba(248, 81, 73, 0.18);
}

.dark .monaco-editor .merge-hunk-applied-bg {
  background-color: rgba(63, 185, 80, 0.1);
}

.dark .monaco-editor .merge-hunk-pending-bg {
  background-color: rgba(234, 179, 8, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) .monaco-editor .merge-hunk-added-bg {
    background-color: rgba(63, 185, 80, 0.18);
  }

  :root:not(.light) .monaco-editor .merge-hunk-modified-bg {
    background-color: rgba(56, 139, 253, 0.18);
  }

  :root:not(.light) .monaco-editor .merge-hunk-removed-bg {
    background-color: rgba(128, 128, 128, 0.2);
  }

  :root:not(.light) .monaco-editor .merge-hunk-conflict-bg {
    background-color: rgba(248, 81, 73, 0.18);
  }

  :root:not(.light) .monaco-editor .merge-hunk-applied-bg {
    background-color: rgba(63, 185, 80, 0.1);
  }

  :root:not(.light) .monaco-editor .merge-hunk-pending-bg {
    background-color: rgba(234, 179, 8, 0.08);
  }
}

/* Merge arrow gutter columns */
.merge-gutter-column {
  position: relative;
  width: 24px;
  min-width: 24px;
  height: 100%;
  overflow: hidden;
  background: var(--background);
}

.merge-gutter-arrow-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 18px;
  border-radius: 3px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  opacity: 0.75;
  transition: opacity 0.15s, background-color 0.15s;
}

.merge-gutter-arrow-btn:hover {
  opacity: 1;
}

.merge-gutter-arrow-accept {
  background-color: rgba(46, 160, 67, 0.25);
  color: #2ea043;
}

.merge-gutter-arrow-accept:hover {
  background-color: rgba(46, 160, 67, 0.45);
}

.merge-gutter-arrow-conflict {
  background-color: rgba(248, 81, 73, 0.2);
  color: #f85149;
}

.merge-gutter-arrow-conflict:hover {
  background-color: rgba(248, 81, 73, 0.4);
}

.dark .merge-gutter-arrow-accept {
  background-color: rgba(63, 185, 80, 0.2);
  color: #3fb950;
}

.dark .merge-gutter-arrow-accept:hover {
  background-color: rgba(63, 185, 80, 0.4);
}

.dark .merge-gutter-arrow-conflict {
  background-color: rgba(248, 81, 73, 0.15);
  color: #f85149;
}

.dark .merge-gutter-arrow-conflict:hover {
  background-color: rgba(248, 81, 73, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) .merge-gutter-arrow-accept {
    background-color: rgba(63, 185, 80, 0.2);
    color: #3fb950;
  }

  :root:not(.light) .merge-gutter-arrow-accept:hover {
    background-color: rgba(63, 185, 80, 0.4);
  }

  :root:not(.light) .merge-gutter-arrow-conflict {
    background-color: rgba(248, 81, 73, 0.15);
    color: #f85149;
  }

  :root:not(.light) .merge-gutter-arrow-conflict:hover {
    background-color: rgba(248, 81, 73, 0.35);
  }
}
