/* ==========================================================================
   Refinement chat (refine-chat/index.html)

   A full-page chat, white and low-fi on purpose: the control in the input
   box is what is being tested, not the chat around it. Tokens, the prose
   box and each control's look come from proto-ui.css and the control files.
   Behaviour lives in js/refine-chat.js.
   ========================================================================== */

html,
body {
  height: 100%;
  margin: 0;
  background: #fff;
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.proto-ui.rc-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  gap: 0;
}

.rc-app a {
  color: inherit;
}

.rc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bd-border);
  color: var(--bd-muted-foreground);
  font-size: 13px;
}

/* The way back to the note, as an outline button so it reads as one. */
.rc-back {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--bd-border);
  border-radius: calc(var(--bd-radius) - 2px);
  color: var(--bd-foreground);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  outline: none;
}

.rc-header > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (hover: hover) {
  .rc-back:hover {
    background: var(--bd-muted);
  }
}

.rc-back:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--bd-ring) 50%, transparent);
}

/* ---------- Thread ---------- */

.rc-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.rc-column {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px;
}

.rc-empty {
  margin: 0;
  color: var(--bd-muted-foreground);
  text-align: center;
}

/* Before the first message, the box and chips sit in the middle of the
   page, under the hint. js/refine-chat.js slides them down after. */
.rc-app.is-empty .rc-thread {
  flex: 0 0 auto;
  margin-top: auto;
  overflow: visible;
}

.rc-app.is-empty .rc-column {
  padding-bottom: 16px;
}

.rc-app.is-empty .rc-dock {
  margin-bottom: auto;
}

.rc-msg p,
.rc-msg li {
  margin: 0;
  line-height: 1.55;
}

.rc-msg > :not(:first-child),
.rc-msg blockquote > :not(:first-child) {
  margin-top: 8px;
}

.rc-msg ul,
.rc-msg ol {
  margin-bottom: 0;
  padding-left: 20px;
}

.rc-msg li + li {
  margin-top: 2px;
}

.rc-msg blockquote {
  margin-left: 0;
  margin-right: 0;
  padding: 12px 14px;
  border: 1px solid var(--bd-border);
  border-radius: var(--bd-radius);
}

/* User turns sit on the right in a bubble; assistant turns are plain text. */
.rc-msg--user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  align-self: flex-end;
  gap: 4px;
  max-width: 85%;
}

.rc-msg--user > :not(:first-child) {
  margin-top: 0;
}

.rc-bubble {
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--bd-muted);
  line-height: 1.5;
  white-space: pre-wrap;
}

.rc-meta {
  padding-right: 6px;
  color: var(--bd-muted-foreground);
  font-size: 11px;
}

/* What the request changed: a box at the top of the reply, and the changed
   parts of the answer highlighted below it. A guess the model had to make
   is set apart, since that is where a vague request shows. */
.rc-changes {
  padding: 10px 14px;
  border-radius: var(--bd-radius);
  background: var(--bd-muted);
}

.rc-changes > :not(:first-child) {
  margin-top: 6px;
}

.rc-changes li.rc-assumed {
  color: oklch(0.5 0.13 60);
}

.rc-msg mark {
  padding: 0 2px;
  border-radius: 3px;
  background: oklch(0.94 0.09 98);
  color: inherit;
}

.rc-msg--error {
  color: oklch(0.5 0.17 27);
}

.rc-typing {
  display: flex;
  gap: 4px;
  padding: 6px 0;
}

.rc-typing > :not(:first-child) {
  margin-top: 0;
}

.rc-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bd-muted-foreground);
  animation: rc-blink 1s ease-in-out infinite;
}

.rc-typing span:nth-child(2) { animation-delay: 150ms; }
.rc-typing span:nth-child(3) { animation-delay: 300ms; }

@keyframes rc-blink {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* ---------- Dock: the input box, the demo chips ---------- */

.rc-dock {
  padding: 0 16px 12px;
}

.rc-composer,
.rc-chips {
  max-width: 720px;
  margin-inline: auto;
}

.rc-composer {
  display: grid;
  border: 1px solid var(--bd-border);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.06);
}

.rc-composer:focus-within {
  border-color: var(--bd-ring);
}

/* The control is part of the input box, above the text field. */
.rc-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  max-height: 58vh;
  padding: 12px 14px;
  border-bottom: 1px solid var(--bd-border);
  overflow-y: auto;
}

.rc-card[hidden] {
  display: none;
}

.rc-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 20px;
  color: var(--bd-muted-foreground);
  font-size: 12px;
  font-weight: 500;
}

.rc-card-extra {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rc-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-left: auto;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--bd-muted-foreground);
  cursor: pointer;
  outline: none;
}

.rc-toggle svg {
  transition: transform 150ms ease-out;
}

@media (hover: hover) {
  .rc-toggle:hover {
    background: var(--bd-muted);
    color: var(--bd-foreground);
  }
}

.rc-toggle:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--bd-ring) 50%, transparent);
}

/* Collapsed: only the head row stays, with the chevron to open it again. */
.rc-card.is-collapsed .rc-toggle svg {
  transform: rotate(180deg);
}

.rc-card.is-collapsed .rc-host {
  display: none;
}

.rc-card .bd-graph {
  max-width: 300px;
  margin: 0 auto;
}

.rc-card .bc-stage {
  max-width: 560px;
  margin: 0 auto;
}

.rc-card.tone-picker .tp-picker {
  grid-template-columns: auto minmax(0, 220px);
}

.rc-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 14px;
}

.rc-row textarea {
  flex: 1;
  min-width: 0;
  max-height: 220px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--bd-foreground);
  font: inherit;
  font-size: 16px; /* 16px keeps phones from zooming in on focus */
  line-height: 1.4;
  resize: none;
  outline: none;
}

.rc-send {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--bd-primary);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  outline: none;
}

.rc-send:disabled {
  opacity: 0.25;
  cursor: default;
}

.rc-send:focus-visible,
.rc-chip:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--bd-ring) 50%, transparent);
}

.rc-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.rc-chip {
  padding: 6px 12px;
  border: 1px solid var(--bd-border);
  border-radius: 999px;
  background: #fff;
  color: var(--bd-foreground);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.rc-chip[aria-pressed="true"] {
  border-color: var(--bd-foreground);
}

@media (hover: hover) {
  .rc-chip:hover {
    background: var(--bd-muted);
  }
}

@media (prefers-reduced-motion: reduce) {
  .rc-typing span {
    animation: none;
    opacity: 0.6;
  }
}
