/* ux-compound-chat-window — surface-level layout for the four chat surfaces.
 *
 * Builds on the ux-component-chat primitive stylesheet (chat.css) and its
 * custom properties. Surface-set properties consumed here:
 *   --rr-chat-list-width    messenger sidebar width (px)
 *   --rr-chat-panel-width   widget panel width (px)
 *   --rr-chat-panel-height  widget panel height (px)
 */

/* ── Messenger (two-pane) ─────────────────────────────────────────────── */
.rr-chat-messenger {
  border: 1px solid var(--rr-chat-border);
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
  min-height: 420px;
  max-height: 560px;
  position: relative;
  display: flex;
}

.rr-chat-messenger .rr-chat-list-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: none;
  min-height: 0;
  /* The pane IS the overview window: exactly --rr-chat-list-width so the
     checklist chip row, the convo list, AND the left viz pane all render at
     the window's width and track the divider drag live (round-2 item B —
     previously the pane sized to its max-content, so the viz pane sat at its
     own fixed intrinsic width). */
  width: var(--rr-chat-list-width, 280px);
  overflow: hidden;
}

.rr-chat-messenger .rr-chat-convo-list {
  width: var(--rr-chat-list-width, 280px);
  /* Round-4 item A (Rust): the aside STRETCHES to the pane's full height —
     its `border-right` IS the visible divider line, so the line must reach
     the surface's bottom edge, not stop at the list content's height
     (`flex: none` left the bottom band line-less when the thread pane was
     the taller sibling; the items region already absorbs the extra height
     via `ul.rr-chat-convo-items { flex: 1; overflow-y: auto }`). */
  flex: 1 1 auto;
  border-right: 1px solid var(--rr-chat-border);
  min-height: 0;
}

/* ── Draggable pane divider (chat_messenger.resizable_divider) ────────── */
.rr-chat-pane-divider {
  flex: none;
  width: 6px;
  margin: 0 -3px;
  z-index: 3;
  cursor: col-resize;
  background: transparent;
  touch-action: none;
}

.rr-chat-pane-divider:hover,
.rr-chat-pane-divider:focus-visible {
  background: var(--rr-chat-accent, currentColor);
  opacity: 0.35;
  outline: none;
}

/* ── Pane minimize affordances (chat_messenger.pane_minimize_controls) ─── */
/* The cluster is ONE absolutely positioned flex row anchored at the
   configured corner (inset-based, operator item I): every button keeps its
   INTRINSIC compact size — no full-width stretch, no mangled corners. The
   row hosts the viz pane-mode toggle (item C, leftmost) + the ⟨ ⟩ pair. */
.rr-chat-pane-min-controls {
  position: absolute;
  display: flex;
  gap: 4px;
  z-index: 4;
}

.rr-chat-pane-min-controls--upper-right { top: 6px; right: 6px; }
.rr-chat-pane-min-controls--upper-left { top: 6px; left: 6px; }
.rr-chat-pane-min-controls--lower-right { bottom: 6px; right: 6px; }
.rr-chat-pane-min-controls--lower-left { bottom: 6px; left: 6px; }

.rr-chat-pane-minimize {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border: 1px solid var(--rr-chat-border);
  border-radius: 6px;
  background: var(--rr-chat-bg, #fff);
  color: inherit;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
}

/* The viz pane-mode toggle (item C): the active state carries the accent. */
.rr-chat-pane-viz-toggle--active {
  background: var(--rr-chat-accent, #1976d2);
  border-color: var(--rr-chat-accent, #1976d2);
  color: #ffffff;
}

.rr-chat-pane-restore {
  display: grid;
  place-items: center;
  width: 20px;
  min-height: 100%;
  border: 1px solid var(--rr-chat-border);
  background: var(--rr-chat-bg, #fff);
  color: inherit;
  cursor: pointer;
  font-size: 0.8rem;
  flex: none;
}

/* The wide variant (the right-pane viz "‹ Overview" back button). */
.rr-chat-pane-restore--wide {
  width: auto;
  min-height: 0;
  padding: 0 8px;
  height: 22px;
  border-radius: 6px;
}

.rr-chat-messenger--left-minimized .rr-chat-list-pane {
  width: 22px;
  flex: none;
}

.rr-chat-messenger--left-minimized .rr-chat-convo-list,
.rr-chat-messenger--left-minimized .rr-chat-pane-divider {
  display: none;
}

.rr-chat-messenger--right-minimized .rr-chat-thread-pane {
  flex: 0 0 22px;
  min-width: 22px;
  overflow: hidden;
}

/* Right pane minimized (the `>` button): the LEFT overview window fully
   extends — the pane itself must FLEX to absorb the freed space (a
   content-sized `flex:none` pane would leave the convo-list's width:100%
   resolving against an indefinite containing block, stranding it at the
   configured px width — operator item B: a maximize, not a no-op). */
.rr-chat-messenger--right-minimized .rr-chat-list-pane {
  flex: 1 1 auto;
  min-width: 0;
}

.rr-chat-messenger--right-minimized .rr-chat-convo-list {
  width: 100%;
  flex: 1 1 auto;
  border-right: none;
}

.rr-chat-messenger--right-minimized .rr-chat-message-list,
.rr-chat-messenger--right-minimized .rr-chat-thread-pane > *:not(.rr-chat-pane-restore) {
  display: none;
}

/* ── Right-pane viz mode (the pane-mode toggle, operator item C) ──────── */
/* The thread pane's viz content: the conversations-with-retrieved-data
   overview, or the resolved visualization (host-provided view). */
.rr-chat-right-viz {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 0.5rem;
}

.rr-chat-right-viz-groups {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Round-3 item A: the overview's `search visualizations` input — the SAME
   input pattern the retired left-pane viz list used, now scoping the
   SELECTED conversation's entry set. */
.rr-chat-right-viz-search {
  border-bottom: none;
  padding: 0;
}

.rr-chat-right-viz-group-items {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.rr-chat-right-viz-empty {
  padding: 1rem 0.5rem;
  font-size: 0.8rem;
  opacity: 0.65;
  text-align: center;
}

.rr-chat-right-viz-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border: 1px solid var(--rr-chat-border);
  border-radius: 8px;
  padding: 0.5rem;
}

.rr-chat-right-viz-group-title {
  font-weight: 600;
  font-size: 0.85rem;
}

.rr-chat-right-viz-resolution {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.rr-chat-right-viz-back {
  display: flex;
}

/* ── Viz entry styling (the right-pane overview's search + entries) ──── */
.rr-chat-viz-search {
  padding: 6px 8px;
  border-bottom: 1px solid var(--rr-chat-border);
}

.rr-chat-viz-search-input {
  width: 100%;
  /* min-width:0 so the input's INTRINSIC preferred width cannot force the
     list pane wider than `--rr-chat-list-width` (round-2 item B — the viz
     pane tracked its own fixed intrinsic width instead of the window). */
  min-width: 0;
  box-sizing: border-box;
  padding: 4px 8px;
  border: 1px solid var(--rr-chat-border);
  border-radius: 8px;
  font: inherit;
  background: inherit;
  color: inherit;
}

.rr-chat-viz-item-button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.rr-chat-viz-item-button:hover,
.rr-chat-viz-item-button:focus-visible {
  background: color-mix(in srgb, var(--rr-chat-accent, #3b82f6) 12%, transparent);
}

.rr-chat-viz-name { font-weight: 600; font-size: 0.85rem; }
.rr-chat-viz-family { font-size: 0.75rem; opacity: 0.75; }
.rr-chat-viz-reason { font-size: 0.72rem; opacity: 0.6; }

/* ── Shared thread pane (messenger + agent) ───────────────────────────── */
.rr-chat-thread-pane {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.rr-chat-thread-pane .rr-chat-message-list {
  flex: 1 1 auto;
}

/* ── Agent (thread-only) ──────────────────────────────────────────────── */
.rr-chat-agent {
  border: 1px solid var(--rr-chat-border);
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
  min-height: 420px;
  max-height: 560px;
}

.rr-chat-agent-reply .rr-chat-message-body {
  max-width: 100%;
}

.rr-chat-source {
  color: var(--rr-chat-accent);
  font-size: 0.8rem;
  text-decoration: underline;
}

.rr-chat-attachment {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--rr-chat-border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.78rem;
  color: var(--rr-chat-muted);
}

/* ── Grounded answer card (chat→TypeQL bridge) ────────────────────────── */
.rr-chat-grounded-answer {
  border: 1px solid var(--rr-chat-border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin: 0.35rem 0;
  font-size: 0.82rem;
}

.rr-chat-grounded-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}

.rr-chat-grounded-badge {
  border-radius: 999px;
  padding: 0.08rem 0.55rem;
  font-size: 0.74rem;
  font-weight: 600;
}

.rr-chat-grounded-badge--ok {
  color: #0a7a3d;
  border: 1px solid #0a7a3d;
}

.rr-chat-grounded-badge--warn {
  color: #b45309;
  border: 1px solid #b45309;
}

.rr-chat-grounded-meta {
  color: var(--rr-chat-muted);
  font-size: 0.76rem;
}

.rr-chat-grounded-actions {
  display: inline-flex;
  gap: 0.45rem;
  margin-left: auto;
}

.rr-chat-grounded-action {
  border: 1px solid var(--rr-chat-border);
  border-radius: 6px;
  background: transparent;
  color: var(--rr-chat-accent);
  padding: 0.12rem 0.5rem;
  font-size: 0.74rem;
  cursor: pointer;
  text-decoration: none;
}

.rr-chat-grounded-query {
  overflow-x: auto;
  border: 1px solid var(--rr-chat-border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.4;
}

.rr-chat-grounded-rows summary {
  cursor: pointer;
  color: var(--rr-chat-muted);
  font-size: 0.76rem;
  margin: 0.3rem 0;
}

.rr-chat-grounded-rows pre {
  overflow-x: auto;
  max-height: 260px;
  border: 1px dashed var(--rr-chat-border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.74rem;
}

.rr-chat-grounded-provenance {
  color: var(--rr-chat-muted);
  font-size: 0.72rem;
  margin-top: 0.35rem;
}

/* ── Widget (floating launcher + corner panel) ────────────────────────── */
/* Anchors inside the nearest positioned ancestor (the preview stage), not
 * the viewport, so the demo floats over the stage's mock page backdrop. */
.rr-chat-widget {
  position: absolute;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  background: transparent;
  height: auto;
}

.rr-chat-widget--right {
  right: 1rem;
}

.rr-chat-widget--left {
  left: 1rem;
  align-items: flex-start;
}

.rr-chat-widget-panel {
  display: flex;
  flex-direction: column;
  width: var(--rr-chat-panel-width, 360px);
  height: var(--rr-chat-panel-height, 480px);
  max-width: 100%;
  background: var(--rr-chat-bg);
  color: var(--rr-chat-fg);
  border: 1px solid var(--rr-chat-border);
  border-radius: 16px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.22);
  overflow: hidden;
}

.rr-chat-widget-panel .rr-chat-message-list {
  flex: 1 1 auto;
}

.rr-chat-widget--branded .rr-chat-convo-header {
  background: var(--rr-chat-accent);
}

.rr-chat-widget--branded .rr-chat-convo-header-title,
.rr-chat-widget--branded .rr-chat-convo-header-subtitle,
.rr-chat-widget--branded .rr-chat-widget-minimize {
  color: #ffffff;
}

.rr-chat-widget-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: 3.25rem;
  min-height: 3.25rem;
  padding: 0 1rem;
  border: none;
  border-radius: 999px;
  background: var(--rr-chat-accent, #1976d2);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

.rr-chat-widget-minimize {
  border: none;
  background: transparent;
  color: var(--rr-chat-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

/* ── Captions (overlay stage) ─────────────────────────────────────────── */
.rr-chat-captions-surface {
  position: relative;
  width: 100%;
  min-height: 320px;
  border-radius: 12px;
  overflow: hidden;
  /* Mock video frame the captions overlay sits on. */
  background:
    radial-gradient(ellipse at 30% 20%, rgba(56, 89, 138, 0.55), transparent 55%),
    radial-gradient(ellipse at 75% 70%, rgba(28, 50, 80, 0.6), transparent 60%),
    #16202e;
}

.rr-chat-captions-surface .rr-chat-captions {
  position: absolute;
  left: 0;
  right: 0;
}

.rr-chat-captions-surface .rr-chat-captions--bottom {
  bottom: 0;
}

.rr-chat-captions-surface .rr-chat-captions--top {
  top: 0;
}

/* The mock video frame is dark regardless of theme — force readable caption
 * contrast over it (the primitive colors assume the surface palette). */
.rr-chat-captions-surface .rr-chat-captions {
  background: linear-gradient(rgba(8, 12, 18, 0), rgba(8, 12, 18, 0.72));
}

.rr-chat-captions-surface .rr-chat-captions--top {
  background: linear-gradient(rgba(8, 12, 18, 0.72), rgba(8, 12, 18, 0));
}

.rr-chat-captions-surface .rr-chat-caption-line {
  color: rgba(231, 231, 234, 0.78);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.rr-chat-captions-surface .rr-chat-caption-line--active {
  color: #ffffff;
}
