@import 'tailwindcss';

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

/* bits-ui components (Slider, and any future orientation/disabled-aware
   primitive) style themselves via shorthand data-* variants that Tailwind
   v4 doesn't ship — it only auto-generates variants for bare boolean data
   attributes (data-disabled), not attribute=value pairs like
   data-orientation="horizontal". Without these, e.g. Slider's track silently
   collapses to 0 height (no h-1.5 class survives), leaving only the thumb
   visible with no visible rail. */
@custom-variant data-horizontal (&[data-orientation='horizontal']);
@custom-variant data-vertical (&[data-orientation='vertical']);
@custom-variant data-disabled (&[data-disabled]);

@theme inline {
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-heading: 'Inknut Antiqua', Georgia, serif;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --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-success: var(--success);
  --color-warning: var(--warning);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-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);
}

/* ── Terracotta Light Theme ── */
:root {
  --radius: 0.625rem;
  --background: oklch(0.94 0.02 55);
  --foreground: oklch(0.18 0.03 45);
  --card: oklch(0.91 0.025 55);
  --card-foreground: oklch(0.18 0.03 45);
  --popover: oklch(0.91 0.025 55);
  --popover-foreground: oklch(0.18 0.03 45);
  --primary: oklch(0.55 0.14 45);
  --primary-foreground: oklch(0.95 0.02 55);
  --secondary: oklch(0.86 0.03 55);
  --secondary-foreground: oklch(0.18 0.03 45);
  --muted: oklch(0.86 0.025 55);
  --muted-foreground: oklch(0.45 0.04 45);
  --accent: oklch(0.84 0.035 55);
  --accent-foreground: oklch(0.18 0.03 45);
  --destructive: oklch(0.5 0.2 25);
  --destructive-foreground: oklch(0.95 0.02 55);
  --border: oklch(0.6 0.08 45);
  --input: oklch(0.78 0.04 55);
  --ring: oklch(0.55 0.14 45);
  --chart-1: oklch(0.55 0.14 45);
  --chart-2: oklch(0.65 0.1 70);
  --chart-3: oklch(0.5 0.08 30);
  --chart-4: oklch(0.6 0.06 90);
  --chart-5: oklch(0.4 0.04 45);
  --sidebar: oklch(0.9 0.025 55);
  --sidebar-foreground: oklch(0.18 0.03 45);
  --sidebar-primary: oklch(0.55 0.14 45);
  --sidebar-primary-foreground: oklch(0.95 0.02 55);
  --sidebar-accent: oklch(0.84 0.035 55);
  --sidebar-accent-foreground: oklch(0.18 0.03 45);
  --sidebar-border: oklch(0.6 0.08 45);
  --sidebar-ring: oklch(0.55 0.14 45);
  --success: #3fb950;
  --warning: #d29922;

  --bg: var(--background);
  --bg-surface: var(--card);
  --bg-deeper: oklch(0.98 0.01 55);
  --bg-hover: var(--secondary);
  --bg-active: var(--accent);
  --text: var(--foreground);
  --text-muted: var(--muted-foreground);
  --accent-blue: var(--primary);
  --accent-green: var(--success);
  --accent-red: var(--destructive);
  --accent-orange: var(--warning);
}

/* ── Carbon Dark Theme ── */
.dark {
  --radius: 0.625rem;
  --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.922 0 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);
  --destructive-foreground: oklch(0.985 0 0);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);
  --chart-1: oklch(0.488 0.243 264.376);
  --chart-2: oklch(0.6 0.15 220);
  --chart-3: oklch(0.5 0.1 160);
  --chart-4: oklch(0.7 0.08 60);
  --chart-5: oklch(0.45 0.05 320);
  --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.269 0 0);
  --sidebar-accent-foreground: oklch(0.985 0 0);
  --sidebar-border: oklch(1 0 0 / 10%);
  --sidebar-ring: oklch(0.439 0 0);
  --success: #3fb950;
  --warning: #d29922;

  --bg: var(--background);
  --bg-surface: var(--card);
  --bg-deeper: oklch(0.11 0 0);
  --bg-hover: var(--secondary);
  --bg-active: var(--accent);
  --text: var(--foreground);
  --text-muted: var(--muted-foreground);
  --accent-blue: var(--sidebar-primary);
  --accent-green: var(--success);
  --accent-red: var(--destructive);
  --accent-orange: var(--warning);
}

/* Terminal-style block cursor — outside @layer so it overrides CodeMirror */
.cm-cursor,
.cm-cursor-primary {
  border-left-color: var(--primary) !important;
  border-left-width: 0.5em !important;
}

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

  html,
  body {
    @apply bg-background text-foreground;
    height: 100%;
    font-size: 15px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-family: var(--font-heading);
  }

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

  .cm-content {
    background: var(--background);
  }

  /* Theme-aware scrollbars */
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }

  *::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }

  *::-webkit-scrollbar-track {
    background: transparent;
  }

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

  *::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
  }

  *::-webkit-scrollbar-corner {
    background: transparent;
  }

  /* Pointer cursor on all interactive elements */
  button:not(:disabled),
  [role='button']:not([aria-disabled='true']),
  a[href],
  summary,
  select {
    cursor: pointer;
  }

  a,
  [role='link'],
  [role='tab'],
  [role='option'],
  [data-slot='popover-trigger'],
  [data-slot='toggle-group-item'],
  [data-slot='alert-dialog-action'],
  [data-slot='alert-dialog-cancel'],
  .cm-tooltip-autocomplete [role='option'] {
    cursor: pointer;
  }

  [data-slot='table-container'] {
    border: none;
    box-shadow: none;
  }
}

#app {
  height: 100%;
}

/* wmkit floating windows (EntityDesktop.svelte) — mapped onto the app's own
   card/border/ring tokens instead of an imported wmkit theme, so windows
   follow the terracotta/dark theme toggle for free. */
[data-wm-desktop] {
  overflow: visible;
}

[data-wm-window] {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  pointer-events: auto;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px oklch(0 0 0 / 0.18);
  overflow: hidden;
  outline: none;
}

[data-wm-window][data-wm-focused] {
  border-color: var(--ring);
  box-shadow: 0 12px 32px oklch(0 0 0 / 0.28);
}

[data-wm-window][data-wm-dragging],
[data-wm-window][data-wm-resizing] {
  user-select: none;
}

[data-wm-window][data-wm-stage='minimized'] {
  display: none;
}

[data-wm-resize] {
  position: absolute;
}

a {
  color: var(--accent-blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* svelte-splitpanes theming (TaskContextPanel, SessionChatWindow rail) —
   mapped onto the app's border/primary tokens instead of the library's
   default-theme, so splitters follow the terracotta/dark theme toggle. */
.splitpanes.oikos-theme .splitpanes__pane {
  background: transparent;
}

.splitpanes.oikos-theme .splitpanes__splitter {
  background-color: transparent;
  transition: background-color 0.15s;
}

.splitpanes.oikos-theme .splitpanes__splitter:hover,
.splitpanes.oikos-theme .splitpanes__splitter.splitpanes__splitter__active {
  background-color: color-mix(in oklab, var(--primary) 30%, transparent);
}

.oikos-theme.splitpanes--horizontal > .splitpanes__splitter {
  height: 6px;
  border-bottom: 1px solid var(--border);
  cursor: row-resize;
}

.oikos-theme.splitpanes--vertical > .splitpanes__splitter {
  width: 6px;
  border-left: 1px solid var(--border);
  cursor: col-resize;
}

/* Base markdown rendering — used by every {@html marked.parse(...)} output
   (EntityDetailContent, the Knowledge wiki's WikiReader, and as the
   foundation ChatThread's fuller "Art Nouveau" chat styling builds on top
   of). Global rather than a per-component <style> block: Svelte scopes
   <style> to one component, so three separate copies of this same ~50-line
   ruleset had accumulated (EntityDetailContent's copy was already a
   documented "can't share, Svelte scopes styles" duplicate of ChatThread's,
   and WikiReader added a third when the Knowledge wiki was built). Anything
   that renders sanitized markdown into an .markdown-body container gets
   this for free; a component only needs its own <style> block for looks
   that genuinely diverge from this baseline (see ChatThread.svelte's
   trimmed-down block for the pattern: same class, only the deltas kept,
   using a two-class selector so its overrides win on specificity rather
   than depending on <style> injection order).
   Includes explicit list-style-type — Tailwind's preflight reset (@import
   'tailwindcss' above) strips it from every <ul>/<ol>, so without this,
   markdown bullet/numbered lists silently render with no markers. */
.markdown-body p {
  margin: 0 0 0.5rem;
}
.markdown-body p:last-child {
  margin-bottom: 0;
}
.markdown-body ul,
.markdown-body ol {
  margin: 0 0 0.5rem;
  padding-left: 1.25rem;
}
.markdown-body ul {
  list-style-type: disc;
}
.markdown-body ol {
  list-style-type: decimal;
}
.markdown-body li {
  margin-bottom: 0.125rem;
}
.markdown-body code {
  background: var(--muted);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.markdown-body pre {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.625rem 0.75rem;
  overflow-x: auto;
  margin: 0 0 0.5rem;
}
.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 0.8125rem;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  font-weight: 600;
  margin: 0.75rem 0 0.375rem;
  font-size: 1em;
}
.markdown-body table {
  border-collapse: collapse;
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
}
.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  text-align: left;
}
.markdown-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.75rem;
  color: var(--muted-foreground);
  margin: 0 0 0.5rem;
}
.markdown-body a {
  color: var(--primary);
  text-decoration: none;
}
.markdown-body a:hover {
  text-decoration: underline;
}
