/* Chat Messages */
.message {
  margin-bottom: 16px;
}

.message.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message.user .content {
  background: var(--user-bg);
  border-radius: 16px 16px 4px 16px;
  max-width: 90%;
}

.message.user .message-context-tag {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding: 3px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.message.user .message-context-tag::before {
  content: "@ ";
  opacity: 0.6;
}

.message.assistant .content {
  background: var(--assistant-bg);
  border-radius: 16px 16px 16px 4px;
  max-width: 90%;
}

.message .content {
  padding: 12px 16px;
  line-height: 1.5;
  border: 1px solid var(--border);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.message .content ul {
  margin: 8px 0 0 20px;
}

.message .content li {
  margin: 4px 0;
}

.message .content code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
}

.message .content pre {
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.message .content pre code {
  padding: 0;
  background: none;
}

.message .content h1,
.message .content h2,
.message .content h3 {
  margin: 12px 0 6px;
  line-height: 1.3;
}

.message .content h1 { font-size: 1.4em; }
.message .content h2 { font-size: 1.2em; }
.message .content h3 { font-size: 1.05em; }

.message .content table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}

.message .content th,
.message .content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.message .content th {
  background: var(--bg-lighter);
  font-weight: 600;
}

.message .content tr:nth-child(even) {
  background: var(--bg-light);
}

.message .content a {
  color: var(--accent-hover);
  text-decoration: underline;
}

.message .content ol {
  margin: 8px 0 0 20px;
}

.message .content blockquote {
  border-left: 3px solid var(--border);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-muted);
}

.message .content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.message .content p {
  margin: 4px 0;
}

.message .content p:first-child {
  margin-top: 0;
}

.message .content p:last-child {
  margin-bottom: 0;
}

.suggested-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  animation: card-fade-in 0.25s ease-out both;
}

/* ── Shared chat-thread entrance/exit animations ── */

@keyframes card-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes word-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.word-fade {
  animation: word-fade-in 0.15s ease-out both;
}

@keyframes reply-btn-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.suggested-reply-btn {
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
  animation: reply-btn-in 0.3s ease-out both;
}

.suggested-reply-btn:hover {
  background: var(--accent-hover);
}

/* Copy button on assistant messages */
.message-copy-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 2px 8px;
  font-size: 11px;
  background: var(--bg-lighter);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.message.assistant {
  position: relative;
}

.message.assistant:hover .message-copy-btn {
  opacity: 1;
}

.message-copy-btn:hover {
  background: var(--bg-light);
  color: var(--text);
}

/* Thinking block (collapsible extended thinking) */
.thinking-block {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.thinking-block summary {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  background: var(--bg);
}

.thinking-block summary:hover {
  color: var(--text);
}

.thinking-body {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
  line-height: 1.5;
}

.thinking-body p {
  margin: 4px 0;
}

.thinking-body p:first-child { margin-top: 0; }
.thinking-body p:last-child { margin-bottom: 0; }

.thinking-body ul,
.thinking-body ol {
  margin: 8px 0 0 20px;
}

.thinking-body li {
  margin: 4px 0;
}

.thinking-body code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.thinking-body pre {
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.thinking-body pre code {
  padding: 0;
  background: none;
}

.thinking-body blockquote {
  border-left: 3px solid var(--border);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-muted);
}

.thinking-body a {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* Text part styling */
.text-part {
  margin-bottom: 8px;
}

.text-part:last-child {
  margin-bottom: 0;
}

/* Inline images rendered from markdown ![alt](url) */
.message .content img {
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 8px;
  margin: 8px 0;
  cursor: pointer;
}

/* Image gallery for consecutive images */
.image-gallery {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: 8px 0;
  padding-bottom: 4px;
}

.image-gallery img {
  height: 180px;
  max-width: none;
  max-height: none;
  width: auto;
  object-fit: cover;
  border-radius: 6px;
  margin: 0;
  flex-shrink: 0;
}

.image-gallery::-webkit-scrollbar {
  height: 4px;
}

.image-gallery::-webkit-scrollbar-track {
  background: transparent;
}

.image-gallery::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* OpenCode question.asked UI */
.opencode-question-group {
  max-width: 85%;
  background: var(--bg-light);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  animation: card-fade-in 0.3s ease-out both;
}

.opencode-question-header {
  font-size: 13px;
  color: var(--accent-hover);
  margin-bottom: 4px;
}

.opencode-question-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.opencode-question-item {
  margin-bottom: 10px;
}

.opencode-question-item:last-child {
  margin-bottom: 0;
}

.opencode-question-text {
  margin-bottom: 6px;
  font-size: 14px;
}

.opencode-question-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.opencode-question-btn {
  padding: 6px 14px;
  background: var(--bg-lighter);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.opencode-question-btn:hover {
  background: var(--accent);
}

.opencode-question-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.opencode-question-btn.selected {
  background: var(--accent);
  border-color: var(--accent-hover);
  color: white;
  opacity: 1;
}

.opencode-question-input-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.opencode-question-input {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-lighter);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  outline: none;
}

.opencode-question-input:focus {
  border-color: var(--accent);
}

.opencode-question-send-btn {
  padding: 6px 14px;
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent-hover);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}

.opencode-question-send-btn:hover {
  background: var(--accent-hover);
}

.opencode-question-custom-answer {
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--bg-lighter);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
}

/* Stale card state — card is no longer actionable (generation was stopped or replaced) */
.stale {
  pointer-events: none;
  position: relative;
}

.stale::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg, #1a1a2e);
  opacity: 0.55;
  border-radius: inherit;
}
