/* ---------- conversation ---------- */
.chat-conversation {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  /* Stop scroll-chaining: hitting the top/bottom of the log shouldn't
     pull the body. Critical on mobile where rubber-banding the page
     behind the chat feels broken. */
  overscroll-behavior: contain;
  padding: 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-log::-webkit-scrollbar {
  width: 8px;
}
.chat-log::-webkit-scrollbar-track {
  background: transparent;
}
.chat-log::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.chat-log::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
  background-clip: padding-box;
  border: 2px solid transparent;
}

.bubble {
  max-width: 86%;
  padding: 0.75rem 1rem;
  border-radius: 18px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 0.96rem;
  animation: bubble-in 0.28s ease-out both;
}
@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.bubble--user {
  align-self: flex-end;
  background: linear-gradient(
    135deg,
    var(--brand) 0%,
    var(--brand-strong) 100%
  );
  color: var(--on-brand);
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-brand);
}
.bubble--user a {
  color: var(--on-brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.bubble--bot {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.bubble--bot a {
  color: var(--link);
}
.bubble--bot a:hover {
  color: var(--link-hover);
}
.bubble p {
  margin: 0 0 0.5rem;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.bubble ul,
.bubble ol {
  margin: 0.25rem 0 0.5rem 1.25rem;
  padding: 0;
}
.bubble code {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* subtle "stopped" pill appended to a bot bubble after user abort */
.bubble-stopped {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 10%, transparent);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  vertical-align: 1px;
}
.bubble--bot .bubble-stopped {
  background: color-mix(in srgb, var(--text) 10%, transparent);
}
.bubble--user .bubble-stopped {
  background: color-mix(in srgb, var(--on-brand) 22%, transparent);
  color: color-mix(in srgb, var(--on-brand) 85%, transparent);
}

/* typing indicator */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 6px 2px;
  align-items: center;
}
/* When the bubble is mid-stream, the typing dots sit below the partial
   text. Empty text slot collapses to zero height so the dots show in
   place of the message until the first token lands. */
.bubble--streaming .bubble-text:not(:empty) {
  margin-bottom: 0.25rem;
}
.bubble--streaming .typing {
  display: flex;
  padding: 2px 0 0;
}
.bubble--streaming .typing span {
  opacity: 0.6;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--brand) 0%,
    var(--brand-strong) 100%
  );
  opacity: 0.55;
  animation: typing 1.3s infinite ease-in-out;
}
.typing span:nth-child(2) {
  animation-delay: 0.18s;
}
.typing span:nth-child(3) {
  animation-delay: 0.36s;
}
@keyframes typing {
  0%,
  80%,
  100% {
    transform: translateY(0) scale(0.85);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-5px) scale(1);
    opacity: 1;
  }
}

/* error block */
.chat-error {
  margin: 0 1.1rem 0.5rem;
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  color: var(--text);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.chat-error p {
  margin: 0;
  flex: 1;
  font-size: 0.92rem;
}

/* composer */
.chat-composer {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  padding: 1rem 1.5rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--surface-2) 30%, var(--surface)),
    var(--surface)
  );
}

.composer-hint {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0;
  padding: 0rem 1.5rem 0.7rem;
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: center;
  color: color-mix(in srgb, var(--text-muted) 60%, transparent);
  background: transparent;
}

.composer-hint svg {
  display: none;
}
.composer-hint__cta {
  background: none;
  border: 0;
  padding: 0;
  margin: 0 0.2rem;
  color: color-mix(in srgb, var(--brand) 70%, var(--text-muted));
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.composer-hint__cta:hover,
.composer-hint__cta:focus-visible {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 2px;
  outline: none;
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  min-height: 46px;
  max-height: 140px;
  padding: 0.8rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.96rem;
  line-height: 1.45;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
  /* subtle inner highlight to read as a tactile, raised input */
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--text) 4%, transparent),
    0 1px 2px rgba(0, 0, 0, 0.02);
}
.chat-composer textarea::placeholder {
  color: color-mix(in srgb, var(--text-muted) 75%, transparent);
}
.chat-composer textarea:hover:not(:disabled):not(:focus) {
  background: color-mix(in srgb, var(--surface) 60%, var(--bg));
  border-color: color-mix(in srgb, var(--border) 60%, var(--text-muted));
}
.chat-composer textarea:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--text) 4%, transparent),
    0 0 0 4px var(--brand-soft);
  outline: none;
}
.chat-composer textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--surface-2);
  box-shadow: none;
}

