@import "tailwindcss";
@import "tw-animate-css";
@import "streamdown/styles.css";

/* Streamdown's Shiki tokens set --sdm-c / --shiki-dark inline; apply them. */
:root pre code [style*="--sdm-c"] { color: var(--sdm-c); }
.dark pre code [style*="--shiki-dark"] { color: var(--shiki-dark); }

/* Collapse Streamdown's empty code-block header when the AI didn't specify a
   language (e.g. plain ``` fences). Without this it reserves a row for the
   filename label, leaving a visible gap above the actions row. */
[class*="bg-sidebar"][class*="rounded-xl"] > div:first-child:empty { display: none; }
[class*="bg-sidebar"][class*="rounded-xl"] > div:first-child:empty + [class*="sticky"] { margin-top: 0; }

@custom-variant dark (&:is(.dark *));
@plugin "@tailwindcss/typography";

/* Step 1: Define CSS Variables at Root Level */
:root {
  --background: hsl(0 0% 100%);
  --foreground: hsl(222.2 84% 4.9%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(222.2 84% 4.9%);
  --popover: hsl(0 0% 100%);
  --popover-foreground: hsl(222.2 84% 4.9%);
  --primary: hsl(221.2 83.2% 53.3%);
  --primary-foreground: hsl(210 40% 98%);
  --secondary: hsl(210 40% 96.1%);
  --secondary-foreground: hsl(222.2 47.4% 11.2%);
  --muted: hsl(210 40% 96.1%);
  --muted-foreground: hsl(215.4 16.3% 46.9%);
  --accent: hsl(210 40% 96.1%);
  --accent-foreground: hsl(222.2 47.4% 11.2%);
  /* P5-002/P5-003: deepened from hsl(0 84.2% 60.2%) to lift contrast above
     WCAG AA on small text. With white foreground, lifted from 3.76:1 to
     ~5.4:1. Equivalent to Tailwind red-600 / red-700 midpoint. */
  --destructive: hsl(0 72% 47%);
  --destructive-foreground: hsl(210 40% 98%);
  --border: hsl(214.3 31.8% 91.4%);
  --input: hsl(214.3 31.8% 91.4%);
  --ring: hsl(221.2 83.2% 53.3%);
  --radius: 0.5rem;
  --chart-1: hsl(12 76% 61%);
  --chart-2: hsl(173 58% 39%);
  --chart-3: hsl(197 37% 24%);
  --chart-4: hsl(43 74% 66%);
  --chart-5: hsl(27 87% 67%);
  --sidebar: hsl(0 0% 98%);
  --sidebar-foreground: hsl(240 5.3% 26.1%);
  --sidebar-primary: hsl(240 5.9% 10%);
  --sidebar-primary-foreground: hsl(0 0% 98%);
  --sidebar-accent: hsl(240 4.8% 95.9%);
  --sidebar-accent-foreground: hsl(240 5.9% 10%);
  --sidebar-border: hsl(220 13% 91%);
  --sidebar-ring: hsl(217.2 91.2% 59.8%);
}

.dark {
  --background: hsl(222.2 84% 4.9%);
  --foreground: hsl(210 40% 98%);
  --card: hsl(222.2 84% 4.9%);
  --card-foreground: hsl(210 40% 98%);
  --popover: hsl(222.2 84% 4.9%);
  --popover-foreground: hsl(210 40% 98%);
  --primary: hsl(217.2 91.2% 59.8%);
  --primary-foreground: hsl(222.2 47.4% 11.2%);
  --secondary: hsl(217.2 32.6% 17.5%);
  --secondary-foreground: hsl(210 40% 98%);
  --muted: hsl(217.2 32.6% 17.5%);
  --muted-foreground: hsl(215 20.2% 65.1%);
  --accent: hsl(217.2 32.6% 17.5%);
  --accent-foreground: hsl(210 40% 98%);
  --destructive: hsl(0 62.8% 30.6%);
  --destructive-foreground: hsl(210 40% 98%);
  --border: hsl(217.2 32.6% 17.5%);
  --input: hsl(217.2 32.6% 17.5%);
  --ring: hsl(224.3 76.3% 48%);
  --chart-1: hsl(220 70% 50%);
  --chart-2: hsl(160 60% 45%);
  --chart-3: hsl(30 80% 55%);
  --chart-4: hsl(280 65% 60%);
  --chart-5: hsl(340 75% 55%);
  --sidebar: hsl(240 5.9% 10%);
  --sidebar-foreground: hsl(240 4.8% 95.9%);
  --sidebar-primary: hsl(224.3 76.3% 48%);
  --sidebar-primary-foreground: hsl(0 0% 100%);
  --sidebar-accent: hsl(240 3.7% 15.9%);
  --sidebar-accent-foreground: hsl(240 4.8% 95.9%);
  --sidebar-border: hsl(240 3.7% 15.9%);
  --sidebar-ring: hsl(217.2 91.2% 59.8%);
}

/* Step 2: Map Variables to Tailwind Utilities */
@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-chart-5: var(--chart-5);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --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);
}

/* Step 3: Apply Base Styles */
@layer base {
  * {
    border-color: var(--border);
  }

  body {
    background-color: var(--background);
    color: var(--foreground);
    font-feature-settings: "rlig" 1, "calt" 1;
  }
}

/* Thin claude.ai-style scrollbars.
 *
 * Applied globally via *, not on body, because the chat scroller and sidebar
 * list are nested scroll containers — each needs its own styled scrollbar.
 * Radix ScrollArea components (used in command palette, select dropdowns)
 * hide the native scrollbar themselves via data-radix-scroll-area-viewport,
 * so this doesn't conflict with them.
 *
 * - 10px wide, transparent track, muted-foreground thumb at 20% opacity
 * - Hover brightens to 40% so the thumb becomes visible when reaching for it
 * - scrollbar-gutter: stable avoids the "content reflows when scrollbar
 *   appears" jump that plagues inset layouts
 * - Firefox: scrollbar-width: thin + scrollbar-color handles the same idea
 */
@supports selector(::-webkit-scrollbar) {
  *::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }
  *::-webkit-scrollbar-track {
    background: transparent;
  }
  *::-webkit-scrollbar-thumb {
    background-color: color-mix(in hsl, var(--muted-foreground) 20%, transparent);
    border-radius: 9999px;
    /* Inset border creates the "pill inside a 10px gutter" effect so the
       thumb doesn't hug the content edge — same trick claude.ai uses. */
    border: 2px solid transparent;
    background-clip: padding-box;
  }
  *::-webkit-scrollbar-thumb:hover {
    background-color: color-mix(in hsl, var(--muted-foreground) 40%, transparent);
  }
  *::-webkit-scrollbar-corner {
    background: transparent;
  }
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in hsl, var(--muted-foreground) 25%, transparent) transparent;
}

/* Syntax Highlighting (lowlight/highlight.js) */
.hljs {
  background: var(--muted);
  color: var(--foreground);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Light theme syntax colors */
.hljs-comment,
.hljs-quote {
  color: hsl(215 16% 47%);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-addition {
  color: hsl(262 80% 50%);
}

.hljs-number,
.hljs-string,
.hljs-meta .hljs-meta-string,
.hljs-literal,
.hljs-doctag,
.hljs-regexp {
  color: hsl(142 70% 35%);
}

.hljs-title,
.hljs-section,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
  color: hsl(221 83% 53%);
}

.hljs-attribute,
.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-class .hljs-title,
.hljs-type {
  color: hsl(35 80% 45%);
}

.hljs-symbol,
.hljs-bullet,
.hljs-subst,
.hljs-meta,
.hljs-meta .hljs-keyword,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-link {
  color: hsl(350 70% 50%);
}

.hljs-built_in,
.hljs-deletion {
  color: hsl(0 70% 50%);
}

.hljs-formula {
  background: var(--muted);
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: bold;
}

/* Dark theme syntax colors */
.dark .hljs-comment,
.dark .hljs-quote {
  color: hsl(215 20% 65%);
}

.dark .hljs-keyword,
.dark .hljs-selector-tag,
.dark .hljs-addition {
  color: hsl(280 80% 70%);
}

.dark .hljs-number,
.dark .hljs-string,
.dark .hljs-meta .hljs-meta-string,
.dark .hljs-literal,
.dark .hljs-doctag,
.dark .hljs-regexp {
  color: hsl(142 60% 55%);
}

.dark .hljs-title,
.dark .hljs-section,
.dark .hljs-name,
.dark .hljs-selector-id,
.dark .hljs-selector-class {
  color: hsl(210 90% 70%);
}

.dark .hljs-attribute,
.dark .hljs-attr,
.dark .hljs-variable,
.dark .hljs-template-variable,
.dark .hljs-class .hljs-title,
.dark .hljs-type {
  color: hsl(35 80% 65%);
}

.dark .hljs-symbol,
.dark .hljs-bullet,
.dark .hljs-subst,
.dark .hljs-meta,
.dark .hljs-meta .hljs-keyword,
.dark .hljs-selector-attr,
.dark .hljs-selector-pseudo,
.dark .hljs-link {
  color: hsl(350 70% 65%);
}

.dark .hljs-built_in,
.dark .hljs-deletion {
  color: hsl(0 70% 60%);
}

/* TipTap Task Lists */
.tiptap ul[data-type="taskList"] {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.tiptap ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.tiptap ul[data-type="taskList"] li > label {
  flex-shrink: 0;
  margin-top: 0.25rem;
}

.tiptap ul[data-type="taskList"] li > label input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary);
}

.tiptap ul[data-type="taskList"] li > div {
  flex: 1;
}

.tiptap ul[data-type="taskList"] li[data-checked="true"] > div {
  text-decoration: line-through;
  opacity: 0.6;
}

/* TipTap Tables */
.tiptap table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
}

.tiptap table th,
.tiptap table td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.tiptap table th {
  background-color: var(--muted);
  font-weight: 600;
}

.tiptap table td {
  vertical-align: top;
}

.tiptap table .selectedCell {
  background-color: var(--accent);
}

/* Subtle placeholders — bright placeholders look like real content and
   confuse the eye, especially in dark mode. Kept at 40% so the hint is
   legible but never mistaken for a filled-in value. */
::placeholder,
::-webkit-input-placeholder {
  color: color-mix(in oklch, var(--muted-foreground), transparent 60%);
  opacity: 1;
}

/* Motion language — locked-in tokens used across the app.
 *
 *   --motion-fast:    60–120ms   tap, hover, focus feedback
 *   --motion-normal:  150–220ms  list rows, cards, drawers, popovers
 *   --motion-slow:    300–400ms  page transitions, big surfaces
 *
 * Pick the right token instead of typing literal ms values everywhere.
 * Easings: linear/in-out for predictable UI; the spring is reserved
 * for novel motion that benefits from emphasis (drawer/sheet open).
 */
:root {
  --motion-fast: 120ms;
  --motion-normal: 200ms;
  --motion-slow: 320ms;
  --ease-out: cubic-bezier(0.2, 0.6, 0.2, 1);
  --ease-spring: cubic-bezier(0.16, 1.2, 0.3, 1);
}

/* Reduce motion when the user has opted out — applies to all transitions
   on common UI primitives. Doesn't disable purposeful animation (loaders,
   live progress) — those are handled per-component. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
