/* ============================================
   app-markdown.css — Markdown rendering styles
   for the AI Assistant chat UI (v2)
   ============================================ */

/* Code blocks */
pre {
  background: #1e1e2e;
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}

pre code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #cdd6f4;
}

/* Inline code */
code:not(pre code) {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: #f38ba8;
}

/* Copy button */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #cdd6f4;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: rgba(255,255,255,0.2);
}

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 0.9rem;
}

th, td {
  border: 1px solid rgba(255,255,255,0.15);
  padding: 8px 12px;
  text-align: left;
}

th {
  background: rgba(255,255,255,0.08);
  font-weight: 600;
}

tr:nth-child(even) {
  background: rgba(255,255,255,0.03);
}

/* Headings in chat */
.message .bubble h1,
.message .message-bubble h1,
.message .bubble h2,
.message .message-bubble h2,
.message .bubble h3,
.message .message-bubble h3 {
  margin: 16px 0 8px 0;
  line-height: 1.3;
}

.message .bubble h1,
.message .message-bubble h1 { font-size: 1.4rem; }

.message .bubble h2,
.message .message-bubble h2 { font-size: 1.2rem; }

.message .bubble h3,
.message .message-bubble h3 { font-size: 1.05rem; }

/* Lists */
.message .bubble ul,
.message .message-bubble ul,
.message .bubble ol,
.message .message-bubble ol {
  padding-left: 20px;
  margin: 8px 0;
}

.message .bubble li,
.message .message-bubble li {
  margin: 4px 0;
}

/* Links */
.message .bubble a,
.message .message-bubble a {
  color: #89b4fa;
  text-decoration: underline;
  text-decoration-color: rgba(137,180,250,0.3);
}

.message .bubble a:hover,
.message .message-bubble a:hover {
  text-decoration-color: rgba(137,180,250,0.8);
}

/* Tool status indicator */
.tool-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  color: rgba(255,255,255,0.7);
  font-style: italic;
}

.tool-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #89b4fa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Rate limit message */
.rate-limit-msg {
  padding: 16px;
  background: rgba(243,139,168,0.1);
  border: 1px solid rgba(243,139,168,0.3);
  border-radius: 8px;
}

.rate-limit-msg strong {
  color: #f38ba8;
}

.rate-limit-msg p {
  margin: 6px 0;
}

.upgrade-link {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 16px;
  background: #89b4fa;
  color: #1e1e2e !important;
  border-radius: 6px;
  text-decoration: none !important;
  font-weight: 600;
}

.upgrade-link:hover {
  background: #a6c8ff;
}

/* Artifact download card (legacy inline link style) */
.artifact-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(166,227,161,0.1);
  border: 1px solid rgba(166,227,161,0.3);
  border-radius: 6px;
  color: #a6e3a1 !important;
  text-decoration: none !important;
  font-weight: 500;
  margin: 4px 0;
}

.artifact-link::before {
  content: '\1F4CE';
}

.artifact-link:hover {
  background: rgba(166,227,161,0.2);
}

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: currentColor;
  margin-left: 2px;
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Blockquotes */
.message .bubble blockquote,
.message .message-bubble blockquote {
  border-left: 3px solid rgba(255,255,255,0.2);
  padding-left: 12px;
  margin: 8px 0;
  color: rgba(255,255,255,0.7);
}

/* Horizontal rules */
.message .bubble hr,
.message .message-bubble hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.15);
  margin: 16px 0;
}

/* Task lists (checkboxes in markdown) */
.message .bubble input[type="checkbox"],
.message .message-bubble input[type="checkbox"] {
  margin-right: 6px;
}

/* Images in markdown */
.message .bubble img,
.message .message-bubble img {
  max-width: 100%;
  border-radius: 6px;
  margin: 8px 0;
}

/* Paragraphs in rendered markdown */
.message .bubble p,
.message .message-bubble p {
  margin: 6px 0;
}

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

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

/* ============================================
   v2 ADDITIONS
   ============================================ */

/* Thinking indicator */
.thinking-indicator {
  padding: 12px;
}

.thinking-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.thinking-dots span {
  width: 8px;
  height: 8px;
  background: rgba(255,255,255,0.4);
  border-radius: 50%;
  animation: thinking-bounce 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Artifact preview card */
.artifact-card {
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  overflow: hidden;
  margin: 12px 0;
  background: rgba(255,255,255,0.05);
}

.artifact-card-inline {
  display: block;
}

.artifact-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-weight: 600;
}

.artifact-icon {
  font-size: 1.2rem;
}

.artifact-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-preview {
  width: 100%;
  height: 300px;
  border: none;
  background: white;
}

.artifact-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}

.artifact-btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none !important;
  cursor: pointer;
  border: none;
  display: inline-block;
  text-align: center;
}

.artifact-btn-open {
  background: #89b4fa;
  color: #1e1e2e !important;
}

.artifact-btn-download {
  background: rgba(166,227,161,0.15);
  color: #a6e3a1 !important;
  border: 1px solid rgba(166,227,161,0.3);
}

.artifact-btn:hover {
  opacity: 0.85;
}

/* Quick action chips */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}

.quick-action-chip {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-action-chip:hover {
  background: rgba(255,255,255,0.15);
  border-color: var(--gold, #d4a843);
  color: var(--gold, #d4a843);
}

/* Feedback buttons */
.feedback-row {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  padding: 2px 0;
  opacity: 0;
  transition: opacity 0.2s;
}

.message:hover .feedback-row,
.feedback-row:has(.active) {
  opacity: 1;
}

.feedback-btn {
  background: none;
  border: 1px solid transparent;
  color: rgba(255,255,255,0.3);
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
}

.feedback-btn:hover {
  color: rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.05);
}

.feedback-btn.active.feedback-up {
  color: #a6e3a1;
  border-color: rgba(166,227,161,0.3);
  background: rgba(166,227,161,0.1);
}

.feedback-btn.active.feedback-down {
  color: #f38ba8;
  border-color: rgba(243,139,168,0.3);
  background: rgba(243,139,168,0.1);
}

/* Message edit button */
.msg-edit-btn {
  position: absolute;
  top: 4px;
  right: -24px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.2);
  cursor: pointer;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.message.user {
  position: relative;
}

.message.user:hover .msg-edit-btn {
  opacity: 1;
}

.msg-edit-btn:hover {
  color: rgba(255,255,255,0.6);
}
