/* ux-component-chat — MUI X Chat-faithful default styling.
 *
 * Custom properties driven by the config sidebar (set by the surfaces):
 *   --rr-chat-radius        bubble corner radius (px)
 *   --rr-chat-accent        accent color (own bubbles, badges, active states)
 *   --rr-chat-gap           row gap (density)
 *   --rr-chat-caption-scale captions font scale
 * Theme: the .rr-chat-dark modifier on the surface root flips the palette.
 */

.rr-chat-surface {
  --rr-chat-radius: 16px;
  --rr-chat-accent: #1976d2;
  --rr-chat-gap: 0.75rem;
  --rr-chat-bg: #ffffff;
  --rr-chat-fg: #1c1c1e;
  --rr-chat-muted: #6b6b70;
  --rr-chat-surface-2: #f4f5f7;
  --rr-chat-border: #e0e0e4;
  --rr-chat-own-bg: var(--rr-chat-accent);
  --rr-chat-own-fg: #ffffff;
  background: var(--rr-chat-bg);
  color: var(--rr-chat-fg);
  display: flex;
  min-height: 0;
  height: 100%;
  font-family: "Roboto", "Helvetica", "Arial", sans-serif;
}

.rr-chat-surface.rr-chat-dark {
  --rr-chat-bg: #121212;
  --rr-chat-fg: #e7e7ea;
  --rr-chat-muted: #9a9aa1;
  --rr-chat-surface-2: #1e1e22;
  --rr-chat-border: #33333a;
}

.rr-chat-hidden {
  display: none !important;
}

/* ── Avatar ───────────────────────────────────────────────────────────── */
.rr-chat-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--rr-chat-surface-2);
  color: var(--rr-chat-muted);
  font-size: 0.75rem;
  font-weight: 600;
  flex: none;
}

/* ── Message rows ─────────────────────────────────────────────────────── */
.rr-chat-message {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  max-width: 100%;
}

.rr-chat-message--end {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.rr-chat-message--start {
  align-self: flex-start;
}

.rr-chat-message-body {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  max-width: 42rem;
}

.rr-chat-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--rr-chat-muted);
}

.rr-chat-bubble {
  padding: 0.55rem 0.85rem;
  border-radius: var(--rr-chat-radius);
  background: var(--rr-chat-surface-2);
  color: var(--rr-chat-fg);
  overflow-wrap: anywhere;
}

.rr-chat-message--user.rr-chat-message--end .rr-chat-bubble {
  background: var(--rr-chat-own-bg);
  color: var(--rr-chat-own-fg);
  border-bottom-right-radius: 4px;
}

.rr-chat-message--start .rr-chat-bubble {
  border-bottom-left-radius: 4px;
}

/* Compact (messenger) variant: flat rows, no bubble chrome. */
.rr-chat-message--compact .rr-chat-bubble {
  background: transparent;
  color: var(--rr-chat-fg);
  padding: 0.1rem 0;
  border-radius: 0;
}

.rr-chat-message--dense .rr-chat-bubble {
  padding: 0.35rem 0.6rem;
}

.rr-chat-message--system .rr-chat-bubble {
  font-style: italic;
  color: var(--rr-chat-muted);
}

.rr-chat-message--tool .rr-chat-bubble {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.85rem;
}

.rr-chat-text,
.rr-chat-markdown {
  margin: 0;
  white-space: pre-wrap;
}

.rr-chat-image {
  max-width: 100%;
  border-radius: 8px;
}

.rr-chat-message-meta {
  display: inline-flex;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: var(--rr-chat-muted);
}

.rr-chat-message--end .rr-chat-message-meta {
  justify-content: flex-end;
}

/* Inside-the-bubble meta (message_presentation.*_position = inside, item F):
   the meta flows as the bubble's last row, end-aligned — the messenger-style
   bottom-corner timestamp/status. Own bubbles keep it readable over the
   accent background. */
.rr-chat-bubble .rr-chat-message-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.15rem;
}

.rr-chat-message--user.rr-chat-message--end .rr-chat-bubble .rr-chat-message-meta {
  color: rgba(255, 255, 255, 0.78);
}

/* Icon-form status glyphs (message_presentation.status_form = icon): keep
   ✓✓ tight and unwrapped. */
.rr-chat-meta-status {
  white-space: nowrap;
  letter-spacing: -0.08em;
}

/* Unread-badge silhouettes (message_presentation.unread_badge_shape, J):
   the conversation-list rows carry the shape class; the badge primitive's
   own radius is overridden per shape so both runtimes render identically. */
.rr-chat-convo-item--badge-circle .p-badge {
  border-radius: 50%;
}

.rr-chat-convo-item--badge-squircle .p-badge {
  border-radius: 30%;
}

.rr-chat-convo-item--badge-square .p-badge {
  border-radius: 0;
}

.rr-chat-message-actions {
  display: inline-flex;
  gap: 0.15rem;
  opacity: 0;
  transition: opacity 120ms ease;
}

.rr-chat-message:hover .rr-chat-message-actions {
  opacity: 1;
}

/* ── Code blocks ──────────────────────────────────────────────────────── */
.rr-chat-code {
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.85rem;
}

.rr-chat-code-header {
  padding: 0.3rem 0.7rem;
  background: #2d2d2d;
  color: #999999;
  font-size: 0.72rem;
}

.rr-chat-code pre {
  margin: 0;
  padding: 0.7rem;
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  line-height: 1.5;
}

/* ── Groups / thread ──────────────────────────────────────────────────── */
.rr-chat-message-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.rr-chat-group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.rr-chat-message-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: var(--rr-chat-gap);
}

.rr-chat-empty {
  margin: auto;
  color: var(--rr-chat-muted);
}

/* ── Dividers / markers ───────────────────────────────────────────────── */
.rr-chat-date-divider,
.rr-chat-step-divider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--rr-chat-muted);
  font-size: 0.72rem;
  margin: 0.4rem 0;
}

.rr-chat-date-divider-line,
.rr-chat-step-divider-line {
  flex: 1;
  height: 1px;
  background: var(--rr-chat-border);
}

.rr-chat-unread-marker {
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--rr-chat-accent);
  margin: 0.4rem 0;
}

.rr-chat-unread-marker-label {
  font-size: 0.7rem;
  color: var(--rr-chat-accent);
  transform: translateY(-50%);
  background: var(--rr-chat-bg);
  padding: 0 0.5rem;
}

/* ── Typing indicator ─────────────────────────────────────────────────── */
.rr-chat-typing {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.5rem 0.85rem;
}

.rr-chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rr-chat-muted);
  animation: rr-chat-typing-bounce 1.2s infinite ease-in-out;
}

.rr-chat-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.rr-chat-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes rr-chat-typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* ── Scroll affordance ────────────────────────────────────────────────── */
.rr-chat-scroll-affordance {
  position: sticky;
  bottom: 0.5rem;
  align-self: center;
}

/* ── Composer ─────────────────────────────────────────────────────────── */
.rr-chat-composer {
  border-top: 1px solid var(--rr-chat-border);
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: var(--rr-chat-bg);
}

.rr-chat-composer-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.rr-chat-composer-input {
  flex: 1;
  min-width: 0;
}

.rr-chat-composer-foot {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--rr-chat-muted);
}

.rr-chat-composer-counter {
  margin-left: auto;
}

/* ── Conversation list ────────────────────────────────────────────────── */
.rr-chat-convo-list {
  display: flex;
  flex-direction: column;
  width: var(--rr-chat-list-width, 280px);
  min-width: 0;
  border-right: 1px solid var(--rr-chat-border);
  background: var(--rr-chat-bg);
}

.rr-chat-convo-list-header {
  padding: 0.85rem 1rem 0.4rem;
}

.rr-chat-convo-list-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.rr-chat-convo-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.3rem 1rem 0.6rem;
}

.rr-chat-filter-chip {
  border: 1px solid var(--rr-chat-border);
  background: transparent;
  color: var(--rr-chat-fg);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.rr-chat-filter-chip--active {
  background: var(--rr-chat-accent);
  border-color: var(--rr-chat-accent);
  color: #ffffff;
}

.rr-chat-convo-items {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.rr-chat-convo-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  cursor: pointer;
}

.rr-chat-convo-item:hover {
  background: var(--rr-chat-surface-2);
}

.rr-chat-convo-item--active {
  background: var(--rr-chat-surface-2);
  box-shadow: inset 3px 0 0 var(--rr-chat-accent);
}

.rr-chat-convo-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.rr-chat-convo-title {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rr-chat-convo-preview {
  font-size: 0.78rem;
  color: var(--rr-chat-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rr-chat-convo-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  font-size: 0.7rem;
  color: var(--rr-chat-muted);
}

/* ── Conversation header ──────────────────────────────────────────────── */
.rr-chat-convo-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--rr-chat-border);
}

.rr-chat-convo-header-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rr-chat-convo-header-title {
  font-weight: 700;
}

.rr-chat-convo-header-subtitle {
  font-size: 0.75rem;
  color: var(--rr-chat-muted);
}

.rr-chat-convo-header-spacer {
  flex: 1;
}

/* ── Reasoning / tool cards / steps ───────────────────────────────────── */
.rr-chat-reasoning,
.rr-chat-tool {
  border: 1px solid var(--rr-chat-border);
  border-radius: 10px;
  background: var(--rr-chat-surface-2);
  font-size: 0.85rem;
  overflow: hidden;
}

.rr-chat-reasoning-summary,
.rr-chat-tool-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.7rem;
  background: transparent;
  border: none;
  color: var(--rr-chat-muted);
  cursor: pointer;
  font-size: 0.78rem;
  text-align: left;
}

.rr-chat-reasoning-caret::before {
  content: "▸";
}

.rr-chat-reasoning--open .rr-chat-reasoning-caret::before {
  content: "▾";
}

.rr-chat-reasoning-body,
.rr-chat-tool-body {
  padding: 0 0.7rem 0.6rem;
}

.rr-chat-reasoning-text,
.rr-chat-tool-io {
  margin: 0;
  white-space: pre-wrap;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.78rem;
  color: var(--rr-chat-fg);
}

.rr-chat-tool-name {
  font-weight: 700;
  color: var(--rr-chat-fg);
}

.rr-chat-tool-status {
  margin-left: auto;
}

.rr-chat-tool--ok .rr-chat-tool-status {
  color: #2e7d32;
}

.rr-chat-tool--failed .rr-chat-tool-status {
  color: #c62828;
}

.rr-chat-tool--approval .rr-chat-tool-status {
  color: #ed6c02;
}

.rr-chat-tool-section-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--rr-chat-muted);
  margin: 0.3rem 0 0.15rem;
}

.rr-chat-tool-approval {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-top: 1px dashed var(--rr-chat-border);
}

/* ── Confirmation card ────────────────────────────────────────────────── */
.rr-chat-confirmation {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  border: 1px solid #ed6c02;
  background: rgba(237, 108, 2, 0.08);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
}

.rr-chat-confirmation-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

/* ── Captions ─────────────────────────────────────────────────────────── */
.rr-chat-captions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.8rem 1rem;
  font-size: calc(1rem * var(--rr-chat-caption-scale, 1));
}

.rr-chat-captions--bottom {
  margin-top: auto;
}

.rr-chat-caption-line {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  color: var(--rr-chat-muted);
}

.rr-chat-caption-line--active {
  color: var(--rr-chat-fg);
  font-weight: 500;
}

.rr-chat-caption-speaker {
  font-weight: 700;
  color: var(--rr-chat-accent);
  flex: none;
}

.rr-chat-caption-time {
  font-size: 0.7em;
  flex: none;
}
