@import "tailwindcss";
@import "highlight.js/styles/base16/material-palenight.min.css";

@theme {
  /* Theme-aware colors mapped to CSS custom properties */
  --color-pc-base: var(--pc-bg-base);
  --color-pc-surface: var(--pc-bg-surface);
  --color-pc-elevated: var(--pc-bg-elevated);
  --color-pc-input: var(--pc-bg-input);
  --color-pc-code: var(--pc-bg-code);
  --color-pc-border: var(--pc-border);
  --color-pc-border-strong: var(--pc-border-strong);
  --color-pc-text: var(--pc-text-primary);
  --color-pc-text-secondary: var(--pc-text-secondary);
  --color-pc-text-muted: var(--pc-text-muted);
  --color-pc-text-faint: var(--pc-text-faint);
  --color-pc-accent: var(--pc-accent);
  --color-pc-accent-light: var(--pc-accent-light);
}

:root {
  --pc-bg-base: #1e1e24;
  --pc-bg-surface: #232329;
  --pc-bg-elevated: #27272a;
  --pc-bg-input: #1a1a20;
  --pc-bg-sidebar: rgba(30,30,36,0.95);
  --pc-bg-code: #1a1a20;
  --pc-border: rgba(255,255,255,0.08);
  --pc-border-strong: rgba(255,255,255,0.1);
  --pc-text-primary: #d4d4d8;
  --pc-text-secondary: #a1a1aa;
  --pc-text-muted: #71717a;
  --pc-text-faint: #52525b;
  --pc-scrollbar-thumb: #52525b;
  --pc-scrollbar-track: #27272a;
  --pc-scrollbar-thumb-hover: #71717a;
  --pc-accent: #22d3ee;
  --pc-accent-light: #67e8f9;
  --pc-accent-dim: rgba(34,211,238,0.3);
  --pc-accent-glow: rgba(34,211,238,0.1);
  --pc-accent-rgb: 34,211,238;
  --pc-hover: rgba(255,255,255,0.05);
  --pc-hover-strong: rgba(255,255,255,0.08);
  --pc-separator: rgba(255,255,255,0.05);
}

/* Global focus-visible ring for keyboard navigation (a11y).
   Elements with Tailwind focus:ring-* already handle their own styling,
   so we target elements that don't have explicit ring classes. */
:focus-visible {
  outline: 2px solid var(--pc-accent-dim);
  outline-offset: 2px;
}

/* Chat textarea: no focus ring (container handles visual feedback) */
#chat-input:focus-visible,
#chat-input:focus {
  outline: none;
}

/* Remove default outline for mouse/touch users */
:focus:not(:focus-visible) {
  outline: none;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--pc-scrollbar-thumb) var(--pc-scrollbar-track);
}

/* WebKit scrollbar styling (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

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

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

/* Textarea-specific: even thinner scrollbar, no horizontal scroll */
textarea::-webkit-scrollbar {
  width: 4px;
  height: 0;
}

textarea::-webkit-scrollbar:horizontal {
  display: none;
}

textarea::-webkit-scrollbar-thumb {
  background: var(--pc-scrollbar-thumb);
  border-radius: 2px;
}

textarea::-webkit-scrollbar-thumb:hover {
  background: var(--pc-scrollbar-thumb-hover);
}

textarea {
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: break-word;
  word-break: break-word;
}

html, body {
  margin: 0;
  background: var(--pc-bg-base);
  color: var(--pc-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow-x: hidden;
  max-width: 100vw;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes bounce-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.animate-fade-in {
  animation: fade-in 0.3s ease-out;
}

.pulse-dot {
  animation: pulse-dot 2s ease-in-out infinite;
}

.bounce-dot {
  animation: bounce-dot 0.9s infinite ease-in-out;
}
.bounce-dot:nth-child(1) { animation-delay: 0s; }
.bounce-dot:nth-child(2) { animation-delay: 0.12s; }
.bounce-dot:nth-child(3) { animation-delay: 0.24s; }

/* Markdown styles */
.markdown-body pre {
  background: var(--pc-bg-code) !important;
  border: 1px solid var(--pc-border);
  border-radius: 12px;
  padding: 16px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.82em;
  line-height: 1.6;
  max-width: 100%;
  box-sizing: border-box;
}

.markdown-body pre code {
  white-space: pre;
  word-break: normal;
  overflow-wrap: normal;
}

.markdown-body code {
  background: var(--pc-accent-glow);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

/* Override highlight.js theme bg to match */
.hljs {
  background: var(--pc-bg-code) !important;
}

.markdown-body p { margin: 4px 0; }
.markdown-body ul, .markdown-body ol { margin: 4px 0; padding-left: 20px; }
.markdown-body ul { list-style-type: disc; }
.markdown-body ol { list-style-type: decimal; }
.markdown-body li { margin: 2px 0; }
.markdown-body li > ul, .markdown-body li > ol { margin: 2px 0; }
.markdown-body li > ul { list-style-type: circle; }
.markdown-body li > ul > li > ul { list-style-type: square; }
.markdown-body blockquote { border-left: 3px solid var(--pc-accent-dim); padding-left: 12px; margin: 8px 0; opacity: 0.8; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 12px 0 4px; }
.markdown-body a { color: var(--pc-accent-light); text-decoration: underline; }
.markdown-body table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; max-width: 100%; }
.markdown-body th, .markdown-body td { border: 1px solid var(--pc-border); padding: 6px 12px; }
.markdown-body th { background: var(--pc-accent-glow); }
.markdown-body img { max-width: 100%; border-radius: 8px; }

/* Accessibility: respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  .animate-fade-in {
    animation: none;
  }
  .pulse-dot {
    animation: none;
  }
  .bounce-dot {
    animation: none;
    opacity: 0.7;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ── Print styles ── */
@media print {
  /* Hide non-content UI elements */
  aside[role="navigation"],
  header[role="banner"],
  [aria-label="Scroll to bottom"],
  .print-hide {
    display: none !important;
  }

  /* Reset background/colors for printing */
  body,
  html,
  #root,
  main {
    background: white !important;
    color: black !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Main content fills the page */
  main {
    flex: 1 !important;
    overflow: visible !important;
  }

  /* Messages readable in print */
  [class*="ChatMessage"],
  [class*="chat-message"] {
    break-inside: avoid;
    page-break-inside: avoid;
    color: black !important;
    border-color: #ccc !important;
  }

  /* Make message text dark */
  .text-pc-text,
  .text-pc-text-secondary,
  .text-pc-text-muted {
    color: #222 !important;
  }

  /* Code blocks print-friendly */
  pre, code {
    background: #f5f5f5 !important;
    color: #333 !important;
    border: 1px solid #ddd !important;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
  }

  /* Tool calls: keep them visible but compact */
  [class*="ToolCall"] {
    border: 1px solid #ccc !important;
    background: #fafafa !important;
    color: #333 !important;
    break-inside: avoid;
  }

  /* Remove box shadows and backdrop filters */
  * {
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  /* Links show their URL */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
    word-break: break-all;
  }

  /* Ensure chat scroll area is fully visible */
  [class*="overflow-y-auto"],
  [class*="overflow-y-scroll"] {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
  }
}
