: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%);
  --primary: hsl(222.2 47.4% 11.2%);
  --primary-foreground: hsl(210 40% 98%);
  --secondary: hsl(210 40% 96.1%);
  --muted: hsl(210 40% 96.1%);
  --muted-foreground: hsl(215.4 16.3% 46.9%);
  --border: hsl(214.3 31.8% 91.4%);
  --destructive: hsl(0 84.2% 60.2%);
  --ring: hsl(222.2 84% 4.9%);
  --radius: 0.5rem;
  --input: hsl(214.3 31.8% 91.4%);
  --background-secondary: hsl(210 40% 98%);
  --trace-assistant-border: hsl(215 22% 72%);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--foreground);
  background: var(--background);
  line-height: 1.5;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}

input {
  font-family: inherit;
  outline: none;
}

/* Markdown Content Styling */
.markdown-body {
  word-break: break-word;
  overflow-x: hidden;
  max-width: 100%;
  width: 100%;
}

.markdown-body p {
  margin-bottom: 0.75rem;
}

.markdown-body p:last-child {
  margin-bottom: 0;
}

.markdown-body h1, 
.markdown-body h2, 
.markdown-body h3, 
.markdown-body h4, 
.markdown-body h5, 
.markdown-body h6 {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
}

.markdown-body h1 { font-size: 1.5rem; }
.markdown-body h2 { font-size: 1.25rem; }
.markdown-body h3 { font-size: 1.125rem; }

.markdown-body ul, 
.markdown-body ol {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.markdown-body ul { list-style-type: disc; }
.markdown-body ol { list-style-type: decimal; }

.markdown-body li {
  margin-bottom: 0.25rem;
}

.markdown-body blockquote {
  padding: 0 1rem;
  color: var(--muted-foreground);
  border-left: 0.25rem solid var(--border);
  margin: 1rem 0;
}

.markdown-body code:not(pre code) {
  background-color: var(--muted);
  padding: 0.2em 0.4em;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 85%;
}

.markdown-body pre {
  margin: 1rem 0;
}

.code-block-container pre {
  margin: 0 !important;
}

.code-block-container {
  display: flex;
  flex-direction: column;
}

.markdown-body hr {
  height: 0.25em;
  padding: 0;
  margin: 1.5rem 0;
  background-color: var(--border);
  border: 0;
}

.markdown-body a {
  color: #0969da;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

/* User message specific overrides for markdown */
.user-message.markdown-body {
  color: var(--primary-foreground);
}

.user-message.markdown-body code:not(pre code) {
  background-color: rgba(255, 255, 255, 0.2);
  color: inherit;
}

.user-message.markdown-body a {
  color: inherit;
  text-decoration: underline;
}

.user-message.markdown-body blockquote {
  color: rgba(255, 255, 255, 0.8);
  border-left-color: rgba(255, 255, 255, 0.3);
}

.user-message.markdown-body .hljs {
  color: var(--foreground) !important;
}

/* Highlight.js theme overrides */
.hljs {
  background: var(--background-secondary) !important;
  color: inherit !important;
}

/* Custom scrollbar for sidebar */
#threads-list::-webkit-scrollbar {
  width: 6px;
}

#threads-list::-webkit-scrollbar-track {
  background: transparent;
}

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

#threads-list::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

#message-input::-webkit-scrollbar {
  width: 6px;
}

#message-input::-webkit-scrollbar-track {
  background: transparent;
}

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

#message-input::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

#message-input {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Hide sidebar-toggle on small screens, show menu-toggle only */
@media (max-width: 767px) {
  #sidebar-toggle {
    display: none !important;
  }
  #menu-toggle {
    display: flex !important;
  }
  #sidebar-resize-handle {
    display: none !important;
  }
}

/* Show sidebar-toggle on medium+ screens, hide menu-toggle */
@media (min-width: 768px) {
  #sidebar-toggle {
    display: flex !important;
  }
  #menu-toggle {
    display: none !important;
  }
}

/* Sidebar resize handle styling */
#sidebar-resize-handle {
  touch-action: none;
  user-select: none;
}

#sidebar-resize-handle:active {
  cursor: col-resize;
}

#sidebar-resize-handle.resizing {
  cursor: col-resize;
}

#sidebar-resize-handle.resizing::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  cursor: col-resize;
  z-index: 9999;
}

/* Prevent text selection during resize */
#sidebar.resizing {
  user-select: none;
}

/* Assistant block - groups text + tools together */
.assistant-block {
  margin-bottom: 0.25rem;
}

/* Collapsible tool container */
.tool-container {
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--background);
  transition: border-color 0.2s ease;
}

.tool-container:hover {
  border-color: hsl(214.3 31.8% 80%);
}

.tool-container-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  transition: background 0.15s ease;
  border-radius: 0.5rem 0.5rem 0 0;
}

.tool-container:not(.open) .tool-container-header {
  border-radius: 0.5rem;
}

.tool-container-header:hover {
  background: var(--muted);
}

.tool-container-chevron {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.tool-container.open .tool-container-chevron {
  transform: rotate(90deg);
}

.tool-container-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease-out;
}

.tool-container.open .tool-container-content {
  max-height: 2000px;
  overflow-y: auto;
  transition: max-height 0.3s ease-in;
}

.tool-container-inner {
  padding: 0 0.875rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tool-item {
  padding: 0.5rem 0.75rem;
  background: var(--muted);
  border-radius: 0.375rem;
  font-size: 0.8125rem;
}

.tool-item-header {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 500;
  color: var(--foreground);
  margin-bottom: 0.25rem;
}

.tool-item-result {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Processing animation */
.tool-container.processing .tool-container-header {
  color: var(--foreground);
}

.processing-indicator {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

/* Single processing dot - faded pulsing indicator */
.processing-dot {
  width: 6px;
  height: 6px;
  background: var(--muted-foreground);
  border-radius: 50%;
  opacity: 0.4;
  animation: singlePulse 1.2s ease-in-out infinite;
}

@keyframes singlePulse {
  0%, 100% {
    opacity: 0.25;
    transform: scale(0.85);
  }
  50% {
    opacity: 0.6;
    transform: scale(1);
  }
}

/* Tool icon */
.tool-icon {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}

/* Tool dots indicator - replaces icon + counter */
.tool-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tool-dot {
  width: 6px;
  height: 6px;
  background: var(--muted-foreground);
  border-radius: 50%;
  opacity: 0;
  animation: dotPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  position: relative;
}

.tool-dot:hover {
  transform: scale(1.4);
  opacity: 1;
}

/* Custom tooltip - shows immediately, positioned below */
.tool-dot::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-2px);
  background: var(--foreground);
  color: var(--background);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease, transform 0.1s ease;
  z-index: 1000;
}

.tool-dot:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes dotPop {
  0% { 
    opacity: 0; 
    transform: scale(0); 
  }
  70% { 
    transform: scale(1.3); 
  }
  100% { 
    opacity: 0.7; 
    transform: scale(1); 
  }
}

.tool-summary {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Shimmer effect for processing */
.tool-container.processing {
  background: linear-gradient(
    90deg,
    var(--background) 0%,
    var(--muted) 50%,
    var(--background) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Thread status indicators */
.thread-status-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  min-width: 18px;
}

.thread-status-badge {
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  box-shadow: none;
}

.thread-status-icon {
  width: 14px;
  height: 14px;
}

.thread-status-icon-spin {
  animation: threadStatusSpin 1s linear infinite;
}

.thread-status-processing {
  color: var(--muted-foreground);
}

.thread-status-ready {
  color: var(--foreground);
}

.thread-status-error {
  color: var(--destructive);
}

@keyframes threadStatusSpin {
  to {
    transform: rotate(360deg);
  }
}

.thread-status-indicator:empty {
  display: none !important;
}

/* Context usage widget */
#context-usage-widget.is-warn #context-usage-bar {
  background: #f59e0b;
}

#context-usage-widget.is-danger #context-usage-bar {
  background: #ef4444;
}

/* Dark mode support for status indicators */
html.dark {
  --background: hsl(0 0% 7%);
  --foreground: hsl(0 0% 95%);
  --card: hsl(0 0% 9%);
  --card-foreground: hsl(0 0% 95%);
  --primary: hsl(0 0% 98%);
  --primary-foreground: hsl(0 0% 9%);
  --secondary: hsl(0 0% 15%);
  --secondary-foreground: hsl(0 0% 98%);
  --muted: hsl(0 0% 15%);
  --muted-foreground: hsl(0 0% 64%);
  --border: hsl(0 0% 20%);
  --destructive: hsl(0 62% 50%);
  --ring: hsl(0 0% 30%);
  --input: hsl(0 0% 20%);
  --background-secondary: hsl(0 0% 11%);
  --trace-assistant-border: hsl(0 0% 88%);
}

@property --border-angle {
  inherits: false;
  initial-value: 0deg;
  syntax: '<angle>';
}

@keyframes border-spin {
  to {
    --border-angle: 360deg;
  }
}

/* Trace block - collapsible container for all intra-messages */
.trace-block {
  margin-bottom: 0.5rem;
}

.trace-container {
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--background);
  transition: border-color 0.2s ease, background 0.2s ease;
  position: relative;
  z-index: 0;
}

/* Base style for the Cruip-inspired animated border */
.trace-container.open,
.trace-container:hover {
  border: 1px solid transparent;
  background: 
    linear-gradient(var(--background), var(--background)) padding-box,
    conic-gradient(
      from var(--border-angle),
      transparent 80%,
      #3b82f6 88%,
      #60a5fa 92%,
      #3b82f6 96%,
      transparent
    ) border-box;
  animation: border-spin 3s linear infinite;
}

.trace-header, .trace-content {
  position: relative;
  z-index: 1;
}

.trace-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  transition: color 0.15s ease;
  border-radius: 0.5rem 0.5rem 0 0;
}

.trace-container:not(.open) .trace-header {
  border-radius: 0.5rem;
}

.trace-chevron {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.trace-container.open .trace-chevron {
  transform: rotate(90deg);
}

.trace-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.trace-dots {
  display: inline-flex;
  align-items: center;
  min-height: 12px;
}

.trace-dot {
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  border: 1px solid color-mix(in oklab, var(--border) 68%, var(--foreground) 32%);
  box-shadow:
    0 1px 3px color-mix(in oklab, var(--foreground) 12%, transparent),
    0 0 0 1px color-mix(in oklab, var(--background) 45%, transparent) inset;
  opacity: 0;
  animation: traceDotPop 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.trace-dot + .trace-dot {
  margin-left: -9px;
}

.trace-dot-assistant {
  background: color-mix(in oklab, var(--background-secondary) 92%, var(--background) 8%);
  border-color: var(--trace-assistant-border);
}

.trace-dot-tool {
  background: color-mix(in oklab, var(--muted) 90%, var(--background) 10%);
}

.trace-dot-more {
  margin-left: 0.375rem;
  font-size: 0.6875rem;
  line-height: 1;
  font-weight: 700;
  color: var(--muted-foreground);
  letter-spacing: 0.01em;
}

@keyframes traceDotPop {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  100% {
    opacity: 0.98;
    transform: scale(1);
  }
}

.trace-timer {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  margin-left: auto;
}

.trace-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease-out;
}

.trace-container.open .trace-content {
  max-height: 2000px;
  overflow-y: auto;
  transition: max-height 0.3s ease-in;
}

.trace-inner {
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Trace text message */
.trace-text {
  padding: 0.75rem;
  background: var(--background-secondary);
  border: 1px solid var(--trace-assistant-border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--foreground);
}

.trace-text-content {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Trace tool result */
.trace-tool {
  padding: 0.5rem 0.75rem;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.8125rem;
}

.trace-tool-header {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 600;
  color: var(--muted-foreground);
  margin-bottom: 0.25rem;
}

.trace-tool-result {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Processing state for trace block */

.trace-container.processing,

.trace-container.open,

.trace-container:hover {

  border: 1px solid transparent;

  background: 

    linear-gradient(var(--background), var(--background)) padding-box,

    conic-gradient(

      from var(--border-angle),

      transparent 80%,

      #3b82f6 88%,

      #60a5fa 92%,

      #3b82f6 96%,

      transparent

    ) border-box;

  animation: border-spin 3s linear infinite;

}



.trace-container.processing .trace-header {

  color: var(--foreground);

}

/* Message hover footer - appears on user prompts and AI final responses */
.message-wrapper {
  position: relative;
  margin-bottom: 0.5rem;
}

.message-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message-bubble {
  position: relative;
}

.message-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  font-size: 0.75rem;
}

.message-container:hover .message-footer {
  opacity: 1;
  transform: translateY(0);
}

.footer-model {
  color: var(--muted-foreground);
  font-weight: 500;
}

.footer-btn {
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.footer-btn svg {
  flex-shrink: 0;
}

.footer-btn:hover {
  background: var(--muted);
  color: var(--foreground);
}

/* Copy button success state */
.footer-btn.text-green-600 {
  color: hsl(142, 76%, 36%);
}

/* Theme toggle button styling */
#theme-toggle {
  background: var(--muted);
}

#theme-toggle .theme-btn {
  color: var(--muted-foreground);
}

#theme-toggle .theme-btn.active {
  background: var(--background);
  color: var(--foreground);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Messages container overflow */
#messages-container {
  overflow-x: hidden;
  overflow-y: auto;
}

#messages {
  overflow-x: hidden;
}

/* Table horizontal scrolling */
.table-render-wrapper {
  max-width: 100%;
  overflow: hidden;
}

.table-render-wrapper .overflow-x-auto {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--muted-foreground) transparent;
}

.table-render-wrapper .overflow-x-auto table {
  min-width: max-content;
}

.table-render-wrapper .overflow-x-auto::-webkit-scrollbar {
  height: 8px;
}

.table-render-wrapper .overflow-x-auto::-webkit-scrollbar-track {
  background: transparent;
}

.table-render-wrapper .overflow-x-auto::-webkit-scrollbar-thumb {
  background: var(--muted-foreground);
  border-radius: 4px;
}

.table-render-wrapper .overflow-x-auto {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--muted-foreground) transparent;
  width: 100%;
}

/* Error message block */
.error-message-block {
  animation: errorFadeIn 0.2s ease-out;
}

@keyframes errorFadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.retry-error-btn {
  border: 1px solid hsl(0 72% 78%);
  background: hsl(0 100% 99%);
  color: hsl(0 74% 38%);
  border-radius: 0.55rem;
  padding: 0.38rem 0.72rem;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.retry-error-btn:hover {
  background: hsl(0 100% 97%);
  border-color: hsl(0 72% 72%);
}

.retry-error-btn:active {
  transform: translateY(1px);
}

.error-card {
  border: 1px solid hsl(0 72% 82%);
  background: hsl(0 100% 98%);
  color: hsl(0 62% 24%);
  border-radius: 0.8rem;
  overflow: hidden;
}

.error-card-body {
  padding: 0.9rem 1rem 0.55rem;
}

.error-card-title {
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0.01em;
  margin-bottom: 0.25rem;
  color: hsl(0 74% 35%);
}

.error-card-message {
  font-size: 0.84rem;
  line-height: 1.45;
  color: hsl(0 55% 30%);
}

.error-card-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 1rem 0.8rem;
}

.error-card .markdown-body code:not(pre code) {
  background: hsl(0 55% 93%);
  color: hsl(0 56% 28%);
}

.error-card .markdown-body a {
  color: hsl(0 74% 36%);
}
