/*
 * LSS Copilot -- custom UI polish (Chainlit 2.9.6)
 * Loaded via [UI].custom_css in lss_gui/.chainlit/config.toml.
 *
 * Complements public/theme.json (does not fight it): every rule below reads
 * colors through the same shadcn/Tailwind CSS custom properties theme.json
 * already defines (--card, --border, --muted, --primary, ...), so both the
 * light and dark variants stay correct automatically -- Chainlit toggles
 * dark mode by adding a `.dark` class to the app root and swapping those
 * variables at runtime; nothing here needs its own dark-mode branch.
 *
 * Cascade note (verified against the installed package, not guessed):
 * chainlit/frontend/dist/index.html injects this stylesheet at the
 * "<!-- CSS INJECTION PLACEHOLDER -->" marker, which sits ABOVE the
 * compiled `<link ... href="/assets/index-*.css">` tag for Chainlit's own
 * bundle (chainlit/server.py ~L406-427, index.html L20 vs L25). That means
 * Chainlit's own Tailwind utility classes load *after* this file and would
 * normally win any same-specificity tie. Instead of sprinkling !important,
 * every selector below is scoped under `#root` (the app's mount node,
 * index.html L28) to add one extra selector of specificity -- enough to
 * beat a lone Tailwind utility class without touching layout-critical
 * properties (display/position/width/height/overflow) that could clip or
 * break the UI.
 *
 * Stable hooks used below were confirmed present in the shipped bundle
 * (chainlit/frontend/dist/assets/index-*.js / index-*.css):
 *   .ai-message / .message-content / .message-name  -- chat message DOM
 *   .custom-scrollbar                                -- scrollable panes
 *   [data-sidebar="..."]                             -- shadcn sidebar primitive
 *   code.hljs (highlight.js)                         -- fenced code blocks
 * Markdown tables/blockquotes/links get no Chainlit classes at all (plain
 * react-markdown output), so they are free to style without any conflict.
 */

#root {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--border)) transparent;
}

/* ---------- Scrollbars (all panes: sidebar, chat, code blocks) ---------- */

#root ::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

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

#root ::-webkit-scrollbar-thumb {
  background-color: hsl(var(--border));
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

#root ::-webkit-scrollbar-thumb:hover {
  background-color: hsl(var(--primary) / 0.55);
}

/* ---------- Message readability: line-height, width, rhythm ---------- */

#root .message-content {
  line-height: 1.65;
  font-size: 0.9375rem;
  max-width: 72ch; /* caps prose width on wide screens; never forces overflow */
}

#root .message-content p {
  margin: 0.35em 0;
}

#root .message-content ul,
#root .message-content ol {
  margin: 0.35em 0;
  padding-left: 1.4em;
}

#root .message-content li + li {
  margin-top: 0.15em;
}

#root .message-content h1,
#root .message-content h2,
#root .message-content h3,
#root .message-content h4 {
  line-height: 1.3;
}

/* ---------- Message "cards": subtle framing per turn ---------- */

#root .ai-message {
  padding: 0.85rem 1rem;
  margin-bottom: 0.35rem;
  border-radius: var(--radius);
  background: hsl(var(--card) / 0.55);
  border: 1px solid hsl(var(--border) / 0.6);
  transition: background-color 150ms ease, border-color 150ms ease;
}

#root .ai-message:hover {
  border-color: hsl(var(--border));
}

#root .message-name {
  font-weight: 600;
  letter-spacing: 0.01em;
  color: hsl(var(--primary));
}

/* ---------- Code: fenced blocks (highlight.js) + inline spans ---------- */

#root .message-content pre {
  margin: 0.6rem 0;
  max-width: 100%;
}

#root .message-content pre code.hljs {
  font-size: 0.85rem;
  line-height: 1.55;
  border-radius: var(--radius);
}

/* Inline `code` spans are plain <code> (no hljs class) -- style them as a
   small teal-tinted pill instead of touching highlight.js's own block theme. */
#root .message-content code:not(.hljs) {
  font-family: var(--font-mono, ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace);
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: 0.35rem;
  padding: 0.15em 0.4em;
  font-size: 0.85em;
  color: hsl(var(--foreground));
}

/* ---------- Tables (plain react-markdown output, no existing classes) --- */

#root .message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.875rem;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  overflow: hidden;
}

#root .message-content thead th {
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border));
}

#root .message-content td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid hsl(var(--border) / 0.6);
}

#root .message-content tbody tr:last-child td {
  border-bottom: none;
}

#root .message-content tbody tr:nth-child(even) {
  background: hsl(var(--muted) / 0.35);
}

/* ---------- Blockquotes, links, rules ---------- */

#root .message-content blockquote {
  border-left: 3px solid hsl(var(--primary));
  padding-left: 0.9rem;
  color: hsl(var(--muted-foreground));
}

#root .message-content a {
  color: hsl(var(--primary));
  text-underline-offset: 2px;
}

#root .message-content a:hover {
  color: hsl(var(--primary) / 0.8);
}

#root .message-content hr {
  border-color: hsl(var(--border));
}

/* ---------- Sidebar density (shadcn [data-sidebar] primitive) ---------- */

#root [data-sidebar="header"],
#root [data-sidebar="footer"] {
  padding: 0.5rem 0.65rem;
}

#root [data-sidebar="content"] {
  gap: 0.15rem;
}

#root [data-sidebar="group-label"] {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

#root [data-sidebar="menu-button"] {
  border-radius: calc(var(--radius) - 4px);
  padding-top: 0.35rem !important;
  padding-bottom: 0.35rem !important;
}

#root [data-sidebar="menu-button"][data-active="true"] {
  background: hsl(var(--sidebar-accent));
  color: hsl(var(--sidebar-accent-foreground));
}

/* ---------- Focus states (keyboard nav, accessible teal ring) ---------- */

#root button:focus-visible,
#root [role="button"]:focus-visible,
#root a:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}
