/* ==========================================================================
   Fast Dash design tokens. Layered on Mantine's CSS variables so everything
   (cards, chat, aside, motion) draws from one system and adapts to light/dark.
   ========================================================================== */
:root {
  --fd-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --fd-transition: 200ms var(--fd-ease);
  --fd-transition-fast: 120ms ease;
  --fd-radius: var(--mantine-radius-md);
  --fd-radius-sm: var(--mantine-radius-sm);
  --fd-shadow-card: var(--mantine-shadow-sm);
  --fd-shadow-float: var(--mantine-shadow-lg);
  --fd-border: 1px solid var(--mantine-color-default-border);
  --fd-accent: var(--mantine-primary-color-filled);
}

/* Respect the user's motion preference (a11y). */
@media (prefers-reduced-motion: reduce) {
  :root { --fd-transition: 0ms; --fd-transition-fast: 0ms; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Sidecar drive affordance: flash a control the agent set, pulse the output
   when it runs the app. Trust comes from *seeing* what the assistant touched. */
@keyframes fd-drive-flash {
  0%   { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
  12%  { box-shadow: 0 0 0 3px color-mix(in srgb, var(--mantine-primary-color-filled) 55%, transparent); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}
.fd-drive-flash {
  animation: fd-drive-flash 1.1s var(--fd-ease);
  border-radius: var(--fd-radius-sm);
}
@keyframes fd-drive-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
  20%  { box-shadow: 0 0 0 4px color-mix(in srgb, var(--mantine-primary-color-filled) 35%, transparent); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}
.fd-drive-pulse { animation: fd-drive-pulse 1.2s var(--fd-ease); }

/* Skeleton loader: while .fd-loading is on the output column, each card shows
   a shimmer over the (hidden) content instead of a bare spinner. */
.fd-output-skeleton {
  display: none;
  position: absolute;
  inset: 0;
  padding: 18px 18px 20px;
  flex-direction: column;
  gap: 12px;
  z-index: 3;
  background: var(--mantine-color-body);
}
.fd-loading .fd-output-skeleton { display: flex; }
.fd-loading .fd-output-content { visibility: hidden; }
.fd-skeleton-bar { height: 12px; border-radius: 6px; flex: 0 0 auto; }
.fd-skeleton-block { flex: 1 1 auto; border-radius: 10px; min-height: 60px; }
.fd-skeleton-bar, .fd-skeleton-block {
  background: linear-gradient(90deg,
    var(--mantine-color-default-hover) 25%,
    var(--mantine-color-default-border) 37%,
    var(--mantine-color-default-hover) 63%);
  background-size: 400% 100%;
  animation: fd-shimmer 1.4s ease infinite;
}
@keyframes fd-shimmer {
  0%   { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
/* The loading overlay is now only a signal — hide its spinner (skeleton is UI). */
#loading-overlay .mantine-Loader-root,
#loading-overlay [class*="LoadingOverlay-loader"] { display: none !important; }

/* Fast Dash output cards — modern card treatment, overflow containment, and
   empty state. Uses Mantine CSS variables so it adapts to light/dark. */

.fd-output-card {
  /* min-* 0 lets the card sit inside its grid cell without being forced wider
     (or taller) by a big child — wide tables / long text scroll inside the
     card instead of pushing it out of the allocated space. */
  min-width: 0;
  min-height: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.fd-output-card:hover {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06), 0 6px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

/* Header strip: title + a hairline divider separating it from the body. */
.fd-output-header {
  flex: 0 0 auto;
  padding: 10px 16px;
  border-bottom: 1px solid var(--mantine-color-default-border);
}

/* Body is the scroll container: content larger than the cell scrolls here
   (both axes) instead of growing the card. min-height/min-width 0 are required
   so the flex child can shrink below its content size and actually scroll. */
.fd-output-body {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  padding: 16px;
}

.fd-output-content {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

/* Centered hint shown before any output exists. It sits behind the content
   (z-index 0); pointer-events:none keeps it from intercepting clicks. It is
   hidden as soon as a real output renders (rules below) so it never shows
   through transparent text/markdown. */
.fd-output-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mantine-color-dimmed);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

.fd-output-placeholder-icon {
  opacity: 0.35;
}

/* Before the first Run, show the placeholder OVER the (empty) output component
   so a Graph's blank axes don't read as a finished result. Overrides the
   content-detection :has() rules below. */
.fd-not-run .fd-output-placeholder {
  display: flex !important;
  z-index: 4;
  background: var(--mantine-color-body);
}
.fd-not-run .fd-output-content { visibility: hidden; }

/* Hide the empty-state hint once any real output content has rendered, across
   the Fast Dash output types (plot, table, image, markdown/text). */
.fd-output-body:has(.fd-output-content .js-plotly-plot) .fd-output-placeholder,
.fd-output-body:has(.fd-output-content .dash-table-container) .fd-output-placeholder,
.fd-output-body:has(.fd-output-content table) .fd-output-placeholder,
.fd-output-body:has(.fd-output-content img) .fd-output-placeholder,
.fd-output-body:has(.fd-output-content p) .fd-output-placeholder,
.fd-output-body:has(.fd-output-content li) .fd-output-placeholder,
.fd-output-body:has(.fd-output-content pre) .fd-output-placeholder,
.fd-output-body:has(.fd-output-content h1, .fd-output-content h2, .fd-output-content h3) .fd-output-placeholder {
  display: none;
}

/* --- Input sidebar overflow containment -------------------------------------
   Keep every control within the navbar width: the sidebar never scrolls
   horizontally; a wide value / label / widget wraps or clips inside its own
   box instead of pushing the sidebar (or the page) wider. Mirrors the output
   card's min-width:0 containment. */
#input-group-wrapper {
  overflow-x: hidden;
}

.fd-input-group {
  min-width: 0;
  max-width: 100%;
}

/* Direct children (label, the input widget, the acknowledge slot) must not
   exceed the column; min-width:0 lets a flex/grid widget shrink and scroll
   internally rather than forcing the sidebar wider. */
.fd-input-group > * {
  min-width: 0;
  max-width: 100%;
}

/* A long, unbreakable label (e.g. a custom label_ with no spaces) wraps
   instead of overflowing. Param-name labels already wrap on spaces. */
.fd-input-label {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Docstring-derived help caption sits tight under the label, above the widget. */
.fd-input-help {
  margin-top: -2px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* --- Native chat mode (RFC #133) -------------------------------------------- */

.fd-chat-main { max-width: 900px; margin: 0 auto; width: 100%; }

.fd-chat-list { scrollbar-gutter: stable; }

/* A message row; the bubble sizes to its content and caps its width. */
.fd-chat-msg { display: flex; width: 100%; }
.fd-chat-user { justify-content: flex-end; }
.fd-chat-assistant { justify-content: flex-start; }

.fd-chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;      /* long tokens/urls wrap, never widen the row */
}

/* User bubble: filled with the primary color. */
.fd-chat-user .fd-chat-bubble {
  background: var(--mantine-primary-color-filled);
  color: var(--mantine-color-white);
  border-bottom-right-radius: 4px;
}

/* Assistant bubble: subtle surface that adapts to light/dark. */
.fd-chat-assistant .fd-chat-bubble {
  background: var(--mantine-color-default-hover);
  color: var(--mantine-color-text);
  border-bottom-left-radius: 4px;
}

/* Raw streaming text keeps newlines while a turn is in flight, with a soft
   blinking caret so an in-flight reply reads as "typing". */
.fd-chat-stream { white-space: pre-wrap; }
.fd-chat-stream::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--mantine-primary-color-filled);
  animation: fd-caret-blink 1s steps(2, start) infinite;
}
@keyframes fd-caret-blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* Markdown inside a bubble should not add outer margins that break the padding. */
.fd-chat-bubble p:first-child { margin-top: 0; }
.fd-chat-bubble p:last-child { margin-bottom: 0; }

/* Code blocks: a proper surface + a hover copy button (added by JS). */
.fd-chat-bubble pre {
  position: relative;
  overflow-x: auto;             /* wide code scrolls inside the bubble */
  max-width: 100%;
  background: var(--mantine-color-default-hover);
  padding: 10px 12px;
  border-radius: var(--fd-radius-sm);
  font-size: 12.5px;
  line-height: 1.5;
}
.fd-chat-bubble code { font-size: 0.92em; }
.fd-code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  border: var(--fd-border);
  background: var(--mantine-color-body);
  color: var(--mantine-color-dimmed);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--fd-transition-fast);
}
.fd-chat-bubble pre:hover .fd-code-copy { opacity: 1; }
.fd-chat-bubble table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 13px;
}
.fd-chat-bubble th, .fd-chat-bubble td {
  border: var(--fd-border);
  padding: 5px 10px;
  text-align: left;
}
.fd-chat-bubble th { background: var(--mantine-color-default-hover); font-weight: 600; }

/* Floating sidecar button: gentle motion on hover. */
#chat-sidecar-toggle { transition: transform var(--fd-transition-fast), box-shadow var(--fd-transition-fast); }
#chat-sidecar-toggle:hover { transform: translateY(-1px); }

/* Composer pinned at the bottom of the chat area. */
.fd-chat-composer-wrap {
  flex: 0 0 auto;
  padding: 12px 8px 16px;
  border-top: 1px solid var(--mantine-color-default-border);
  background: var(--mantine-color-body);
}
.fd-chat-composer { max-width: 900px; margin: 0 auto; width: 100%; }

/* --- Chat rich frames (RFC #133 Phase 2) ----------------------------------- */

.fd-chat-blocks { display: flex; flex-direction: column; gap: 10px; }
.fd-chat-text { }

/* Reasoning: a collapsible "thinking" block. */
.fd-chat-reasoning {
  border-left: 2px solid var(--mantine-color-default-border);
  padding-left: 10px;
}
.fd-chat-reasoning-summary {
  cursor: pointer;
  color: var(--mantine-color-dimmed);
  font-size: 13px;
  user-select: none;
}
.fd-chat-reasoning-body { color: var(--mantine-color-dimmed); font-size: 13px; }

/* Tool-call card. */
.fd-chat-tool { background: var(--mantine-color-body); }
.fd-chat-tool-name { font-weight: 600; font-size: 13px; }
.fd-chat-tool-status {
  font-size: 11px; color: var(--mantine-color-dimmed);
  margin-left: auto; text-transform: uppercase; letter-spacing: 0.04em;
}
.fd-chat-tool-args, .fd-chat-tool-result {
  margin: 6px 0 0; padding: 8px; border-radius: 6px;
  background: var(--mantine-color-default-hover);
  font-size: 12px; overflow-x: auto; white-space: pre-wrap; max-width: 100%;
}
.fd-chat-tool-result { color: var(--mantine-color-text); }

/* Spinner for a running tool. */
.fd-chat-tool-spin { animation: fd-chat-spin 1s linear infinite; }
@keyframes fd-chat-spin { to { transform: rotate(360deg); } }

/* Inline artifacts sized to the bubble. */
.fd-chat-artifact { max-width: 100%; margin-top: 4px; }
.fd-chat-artifact-pending {
  color: var(--mantine-color-dimmed); font-size: 13px; font-style: italic;
}

/* HITL interrupt card (Phase 4). */
.fd-chat-interrupt {
  margin-top: 6px;
  border-color: var(--mantine-color-yellow-4);
  background: var(--mantine-color-yellow-light);
}
.fd-chat-interrupt-title { font-weight: 600; font-size: 13px; }
.fd-chat-interrupt-action { font-size: 13px; margin-top: 4px; font-weight: 500; }
.fd-chat-interrupt-actions { margin-top: 8px; }
.fd-chat-interrupt-decided {
  display: inline-block; margin-top: 8px; font-size: 12px;
  color: var(--mantine-color-dimmed);
}

/* Canvas (chat ⇄ DynamicDash hybrid): assistant-driven output region. */
.fd-chat-canvas-wrap { background: var(--mantine-color-body); }
.fd-chat-canvas { display: flex; flex-direction: column; gap: 16px; }
.fd-chat-canvas:empty::before {
  content: "The assistant will build here.";
  color: var(--mantine-color-dimmed); font-size: 14px; font-style: italic;
}

/* Developer-declared settings (model, temperature, upload) — static, on the
   chat side, above the composer. */
.fd-chat-settings {
  flex: 0 0 auto;
  max-height: 40vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 10px;
  border-top: 1px solid var(--mantine-color-default-border);
}

/* Empty-transcript hint. Text comes from the chat list's data-placeholder
   (set from FastDash(chat_placeholder=...)), so it fits the app and mode. */
.fd-chat-list:empty::before {
  content: attr(data-placeholder);
  margin: auto;
  padding: 0 24px;
  color: var(--mantine-color-dimmed);
  font-size: 14px;
  font-style: italic;
  text-align: center;
}
