/* Chat Container */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  background: var(--bg-dark);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  /*padding-bottom: 220px;*/
  /* Space for input area */
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

/* Message Bubbles */
.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.5;
  position: relative;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 2px;
}

.message.agent {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 2px;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.8;
}

.agent-icon {
  width: 16px;
  height: 16px;
  color: var(--primary-light);
}

/* Input Area */
.chat-input-area {
  /*position: absolute;*/
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 0px 4px 0px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  /*gap: 8px;*/
  z-index: 100;
  overflow: visible;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  /*align-items: flex-end;*/
  width: 100%;
}

.chat-disclaimer {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.7;
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  transition: var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

#chat-input {
  width: 100%;
  /* min-height: 40px; */
  max-height: 120px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.7rem;
  resize: none;
  outline: none;
  display: block;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: var(--bg-card-hover);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.send-btn.stop-mode {
  background: var(--danger);
  cursor: pointer;
}

.send-btn.stop-mode:hover {
  background: #dc2626;
  transform: scale(1.05);
}

/* Citations */
/* Citations */
.citation-wrapper {
  position: relative;
  display: inline-block;
  line-height: 1;
}

.citation-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary-light);
  background: rgba(37, 99, 235, 0.1);
  border: 1px solid rgba(37, 99, 235, 0.3);
  border-radius: 50%;
  margin: 0 2px;
  cursor: pointer;
  vertical-align: super;
  text-decoration: none;
  transition: var(--transition);
  padding: 0;
  line-height: 1;
}

.citation-badge:hover,
.citation-badge.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Non-interactive badges shown during streaming — same look, no pointer/hover */
.citation-badge-stream {
  cursor: default;
  pointer-events: none;
}

.citation-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 100;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  animation: fadeIn 0.15s ease-out;
  pointer-events: none;
  /* Prevent interaction when hidden */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0.15s, transform 0.15s;
}

.citation-wrapper.active .citation-tooltip {
  pointer-events: auto;
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Arrow for tooltip */
.citation-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border-width: 6px;
  border-style: solid;
  border-color: var(--border-color) transparent transparent transparent;
}

.citation-tooltip::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: var(--bg-card) transparent transparent transparent;
  z-index: 1;
}

.citation-tooltip-title {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-primary);
  line-height: 1.3;
}

.citation-tooltip-snippet {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: -webkit-box;
  line-clamp: 3;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
  font-style: italic;
}

.citation-tooltip-link {
  font-size: 0.75rem;
  color: var(--primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-weight: 500;
  padding: 4px 8px;
  background: rgba(37, 99, 235, 0.1);
  border-radius: 4px;
  align-self: flex-start;
  transition: var(--transition);
}

.citation-tooltip-link:hover {
  background: rgba(37, 99, 235, 0.2);
}

/* Sources List */
.sources-container {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  font-size: 0.85rem;
}

.sources-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: color 0.2s;
}

.sources-toggle:hover {
  color: var(--text-primary);
}

.sources-toggle .chevron-icon {
  width: 14px;
  height: 14px;
  transition: transform 0.3s ease;
}

.sources-toggle.active .chevron-icon {
  transform: rotate(180deg);
}

.sources-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
  opacity: 0;
}

.sources-list.expanded {
  max-height: 800px;
  /* Arbitrary large enough height */
  opacity: 1;
  margin-top: 12px;
}

.source-item {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  color: var(--text-secondary);
}

.source-index {
  color: var(--primary-light);
  font-weight: 600;
  min-width: 16px;
}

.source-content {
  flex: 1;
}

.source-title {
  font-weight: 500;
  color: var(--text-primary);
  display: block;
  margin-bottom: 2px;
}

.source-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-link {
  font-size: 0.75rem;
  color: var(--primary-light);
  text-decoration: none;
  margin-top: 2px;
  display: inline-block;
}

.source-link:hover {
  text-decoration: underline;
}

/* Markdown Content Styling */
.message-content {
  line-height: 1.6;
}

.message-content p {
  margin-bottom: 0.8em;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ul,
.message-content ol {
  margin: 0.5em 0 0.8em 1.5em;
  padding-left: 0.5em;
}

.message-content li {
  margin-bottom: 0.3em;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  font-weight: 600;
  margin-top: 1em;
  margin-bottom: 0.5em;
  line-height: 1.3;
  color: var(--text-primary);
}

.message-content h1 {
  font-size: 1.3em;
}

.message-content h2 {
  font-size: 1.2em;
}

.message-content h3 {
  font-size: 1.1em;
}

.message-content h4 {
  font-size: 1em;
}

.message-content strong {
  font-weight: 600;
  color: var(--primary-light);
  /* Optional: highlight key terms */
}

.message-content code {
  background: rgba(0, 0, 0, 0.2);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.8em 0;
}

.message-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* Code block copy button */
.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-muted);
  padding: 5px;
  border-radius: 5px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-content pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-primary);
}

/* Streaming cursor */
.streaming-content::after {
  content: '▊';
  color: var(--primary);
  animation: blink 0.8s infinite;
  font-weight: 300;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

/* Follow-up suggestions */
.follow-up-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(71, 85, 105, 0.3);
}

.follow-up-chip {
  padding: 6px 12px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.2);
  border-radius: 16px;
  color: var(--primary-light);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.follow-up-chip:hover {
  background: rgba(37, 99, 235, 0.15);
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* Credit usage per message */
.message-usage {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
  opacity: 0.7;
}

.message-content blockquote {
  border-left: 3px solid var(--primary);
  margin: 0.8em 0;
  padding-left: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {

  0%,
  80%,
  100% {
    transform: scale(0);
  }

  40% {
    transform: scale(1);
  }
}

/* Empty State */
.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
  margin-top: 20px;
  gap: 28px;
}

.chat-empty-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.chat-empty-icon {
  color: var(--primary);
  opacity: 0.8;
  margin-bottom: 4px;
}

.chat-empty-hero h3 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.chat-empty-hero p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
  max-width: 300px;
  line-height: 1.5;
}

.chat-empty-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}

.capability-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.capability-card:hover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.capability-icon {
  flex-shrink: 0;
  color: var(--primary-light);
  opacity: 0.8;
}

.capability-card:hover .capability-icon {
  opacity: 1;
}

.capability-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.capability-text strong {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.capability-text span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ============================================
   AGENT THINKING / TOOL ACTIVITY
   ============================================ */

.agent-thinking {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 0 12px;
  transition: opacity 0.5s ease, max-height 0.5s ease;
  overflow: hidden;
}

.agent-thinking:empty {
  display: none;
}

.agent-thinking.thinking-complete {
  opacity: 0.5;
  padding-bottom: 4px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-color, #334155);
}

.thinking-step,
.tool-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary, #94a3b8);
  line-height: 1.5;
  padding: 2px 0;
}

.step-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--text-muted, #64748b);
}

.step-icon svg {
  width: 14px;
  height: 14px;
}

.step-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-meta {
  font-size: 11px;
  color: var(--text-muted, #64748b);
  flex-shrink: 0;
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.step-done .step-meta {
  opacity: 1;
}

/* --- Shimmer animation for active steps --- */
.step-active .step-label {
  background: linear-gradient(90deg,
      var(--text-muted, #64748b) 0%,
      var(--text-primary, #f8fafc) 40%,
      var(--text-primary, #f8fafc) 60%,
      var(--text-muted, #64748b) 100%);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: step-shimmer 2s ease-in-out infinite;
}

.step-active .step-icon {
  color: var(--primary-light, #3b82f6);
}

@keyframes step-shimmer {
  0% {
    background-position: 100% 50%;
  }

  100% {
    background-position: -100% 50%;
  }
}

/* --- Completed step --- */
.step-done .step-icon {
  color: #10b981;
}

.step-done .step-label {
  color: var(--text-muted, #64748b);
  background: none;
  -webkit-text-fill-color: unset;
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .step-active .step-label {
    animation: none;
    background: none;
    -webkit-text-fill-color: unset;
    color: var(--text-secondary, #94a3b8);
  }
}

/* Source Tooltip (simple implementation used in chat flow) */
/* We'll use title attribute for native tooltip initially, or implement a custom one if needed */

/* Free-limit sign-up CTA */
.chat-limit-cta {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.chat-limit-cta-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chat-limit-btn-primary {
  padding: 8px 18px;
  background: var(--primary, #2563eb);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.15s;
}

.chat-limit-btn-primary:hover {
  background: var(--primary-dark, #1d4ed8);
  transform: translateY(-1px);
}

.chat-limit-btn-secondary {
  padding: 8px 18px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s, transform 0.15s;
}

.chat-limit-btn-secondary:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  transform: translateY(-1px);
}