/* MCP Chatbot Styles */

:root {
  --chat-bg: var(--cdc-white, #ffffff);
  --chat-muted: var(--cdc-light-gray, #f5f5f5);
  --chat-border: var(--cdc-gray, #e2e8f0);
  --chat-text: var(--cdc-text, #333333);
  --chat-accent: var(--cdc-accent, #555555);
  --chat-accent-dark: var(--cdc-dark-gray, #333333);
}

/* Full page layout styles */
.chatbot-full-page {
  min-height: calc(100vh - 100px);
  background: #f8f9fa;
}

.chatbot-page-header {
  background: var(--chat-bg);
  border-bottom: 1px solid var(--chat-border);
  padding: 20px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}

.header-text h1 {
  margin: 0 0 8px 0;
  font-size: 2rem;
  font-weight: 600;
  color: var(--chat-text);
}

.page-subtitle {
  margin: 0;
  color: #6c757d;
  font-size: 1.1rem;
}

/* Streaming toggle styles */
.streaming-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  color: var(--chat-text);
}

.toggle-label input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 44px;
  height: 24px;
  background: #ccc;
  border-radius: 24px;
  transition: background 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider {
  background: var(--chat-accent);
}

.toggle-label input[type="checkbox"]:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-text {
  font-weight: 500;
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }
  
  .streaming-toggle {
    align-self: flex-end;
  }
}

.chatbot-main-area {
  display: flex;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 200px); /* Adjusted for taller chatbot */
}

.chatbot-container {
  flex: 1;
  background: var(--chat-bg);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 75vh; /* 70% of viewport height */
  max-height: 75vh; /* Prevent stretching beyond 70% */
  min-height: 600px; /* Minimum height for smaller screens */
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  height: calc(75vh - 140px); /* 70vh minus header and input areas */
  max-height: calc(75vh - 140px); /* Prevent expansion */
  min-height: 460px; /* Minimum height for smaller screens */
  scrollbar-width: thin;
  scrollbar-color: #dee2e6 transparent;
  position: relative; /* For fade effect positioning */
}

.message {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.message-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.bot-message .message-content {
  justify-content: flex-start;
}

.user-message .message-content {
  justify-content: flex-end;
}

.bot-avatar {
  color: #ffffff;
  font-size: 1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-accent);
  border-radius: 50%;
  flex-shrink: 0;
}

.user-avatar {
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-accent-dark);
  border-radius: 50%;
  flex-shrink: 0;
}

.message-text {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.4;
  word-wrap: break-word;
}

.bot-message .message-text {
  background: #ffffff;

  color: #333333;
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}

.user-message .message-text {
  background: #30D158;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.chat-input-container {
  padding: 20px;
  background: white;
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--chat-muted);
  border: 2px solid var(--chat-border);
  border-radius: 24px;
  padding: 8px 12px;
  transition: border-color 0.2s ease;
}

.chat-input-wrapper:focus-within {
  /* Keep the same border on focus so the box doesn't highlight */
  border-color: var(--chat-border);
  outline: none;
  box-shadow: none;
}

.chat-input {
  flex: 1;
  border: none !important;
  background: transparent;
  resize: none;
  outline: none;
  box-shadow: none !important;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  max-height: 120px;
  min-height: 20px;
  padding: 6px 0;
}

/* Remove any focus ring or highlight on the input itself */
.chat-input:focus,
.chat-input:focus-visible {
  outline: none;
  box-shadow: none;
}

/* Ensure the wrapper also never shows a focus ring */
.chat-input-wrapper,
.chat-input-wrapper:focus,
.chat-input-wrapper:focus-visible {
  outline: none;
  box-shadow: none;
}

.send-button {
  background: var(--chat-accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.send-button:hover {
  background: var(--chat-accent-dark);
  transform: scale(1.05);
}

.send-button:active {
  transform: scale(0.95);
}

.send-button:disabled {
  background: #6c757d;
  cursor: not-allowed;
  transform: none;
}

/* Clear chat button (next to input) */
.clear-button {
  background: transparent;
  color: var(--chat-accent);
  border: 1px solid var(--chat-border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.clear-button:hover {
  background: var(--chat-muted);
  border-color: var(--chat-accent);
  transform: scale(1.03);
}

.clear-button:active {
  transform: scale(0.97);
}

.clear-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.loading-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  background: white;
  border-top: 1px solid #e9ecef;
}

.typing-indicator {
  display: flex;
  gap: 4px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-accent);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.loading-text {
  color: #6c757d;
  font-size: 0.9rem;
}

.example-questions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 0 0 0;
}

.example-question {
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  color: var(--chat-text);
}

.example-question:hover {
  background: #eeeeee;
  border-color: var(--chat-accent);
  color: var(--chat-accent);
}

.example-question:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Side panel styles */
.chatbot-side-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-section {
  background: var(--chat-bg);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.panel-section h3 {
  margin: 0 0 16px 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--chat-text);
}

.tips-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tips-list li {
  padding: 8px 0;
  color: var(--chat-text);
  border-bottom: 1px solid var(--chat-border);
}

.tips-list li:last-child {
  border-bottom: none;
}

.tips-list li:before {
  content: "💡";
  margin-right: 8px;
}

/* Responsive design */
@media (max-width: 1024px) {
  .chatbot-main-area {
    flex-direction: column;
  }
  
  .chatbot-side-panel {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
  }
  
  .panel-section {
    flex-shrink: 0;
    min-width: 280px;
  }
}

@media (max-width: 768px) {
  .chatbot-main-area {
    padding: 10px;
    gap: 15px;
  }
  
  .chatbot-container {
    margin: 0;
    border-radius: 8px;
    height: 75vh; /* 70% of viewport height on mobile */
    max-height: 75vh;
    min-height: 500px; /* Minimum height for mobile */
  }
  
  .chat-messages {
    height: calc(75vh - 120px); /* Adjusted for mobile */
    max-height: calc(75vh - 120px);
    min-height: 380px; /* Minimum height for mobile */
  }
  
  .message-text {
    max-width: 85%;
  }
  
  .chatbot-side-panel {
    flex-direction: column;
  }
  
  .panel-section {
    min-width: auto;
    padding: 15px;
  }
  
  .chatbot-page-header {
    padding: 15px 0;
  }
  
  .chatbot-page-header h1 {
    font-size: 1.5rem;
  }
  
  .page-subtitle {
    font-size: 1rem;
  }
}



/* Floating Button */
.chatbot-floating-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--chat-accent);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2000001;
  box-shadow: 0 6px 18px rgba(0,0,0,0.15);
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-floating-btn:hover {
  background-color: var(--chat-accent-dark);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0,0,0,0.2);
}

.chatbot-floating-btn-icon {
  font-size: 22px;
  line-height: 1;
}

/* Modal */
.chatbot-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 20px;
  z-index: 2000000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.chatbot-modal-backdrop[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
}

.chatbot-modal {
  width: 100%;
  max-width: 420px;
  background: var(--chat-bg);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  overflow: hidden;
  transform: translateY(20px);
  transition: transform 0.2s ease;
}

.chatbot-modal-backdrop[aria-hidden="false"] .chatbot-modal {
  transform: translateY(0);
}

.chatbot-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-muted);
}

.chatbot-modal-title {
  margin: 0;
  font-size: 1rem;
  color: var(--chat-text);
}

.chatbot-modal-close {
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--chat-text);
  cursor: pointer;
}

.chatbot-modal-body {
  padding: 0;
}

.chatbot-examples-panel {
  padding: 12px 16px 16px 16px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-bg);
}

/* Prevent body scroll when modal is open */
.chatbot-modal-open {
  overflow: hidden;
}

/* Enhanced scrollbar styling */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: #f1f3f4;
  border-radius: 4px;
  margin: 8px 0;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #c1c8cd;
  border-radius: 4px;
  border: 2px solid #f1f3f4;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #9aa0a6;
}

.chat-messages::-webkit-scrollbar-thumb:active {
  background: #80868b;
}

/* Smooth scroll behavior */
.chat-messages {
  scroll-behavior: smooth;
}

/* Fade effect for overflow content - REMOVED */

/* Markdown Content Styles */
.message-text h1,
.message-text h2,
.message-text h3,
.message-text h4,
.message-text h5,
.message-text h6 {
  margin: 16px 0 12px 0;
  font-weight: 600;
  line-height: 1.25;
  color: var(--chat-text);
}

.message-text h1 {
  font-size: 1.5rem;
  border-bottom: 2px solid var(--chat-border);
  padding-bottom: 8px;
}

.message-text h2 {
  font-size: 1.3rem;
  border-bottom: 1px solid var(--chat-border);
  padding-bottom: 6px;
}

.message-text h3 {
  font-size: 1.15rem;
}

.message-text h4 {
  font-size: 1.05rem;
}

.message-text h5,
.message-text h6 {
  font-size: 0.95rem;
}

.message-text p {
  margin: 8px 0;
  line-height: 1.6;
}

.message-text ul,
.message-text ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-text li {
  margin: 4px 0;
  line-height: 1.5;
}

.message-text li > ul,
.message-text li > ol {
  margin: 4px 0;
}

.message-text code {
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.85em;
  color: #c7254e;
}

.message-text pre {
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  border-radius: 6px;
  padding: 12px;
  margin: 12px 0;
  overflow-x: auto;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.85em;
  line-height: 1.4;
}

.message-text pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--chat-text);
}

/* Analysis details pill */
.details-pill {
  margin-top: 10px;
}

.details-toggle {
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  border-radius: 9999px;
  padding: 6px 10px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.details-toggle:hover {
  background: #eeeeee;
  border-color: var(--chat-accent);
}

.details-content {
  margin-top: 8px;
  padding: 10px;
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
}

.details-section-title {
  font-weight: 600;
  margin-bottom: 6px;
}

.details-tools-list {
  list-style: disc;
  padding-left: 18px;
  margin: 0;
}

.details-tools-list li {
  margin: 6px 0;
}

.message-text blockquote {
  border-left: 4px solid var(--chat-accent);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--chat-muted);
  font-style: italic;
  border-radius: 0 4px 4px 0;
}

.message-text blockquote p {
  margin: 4px 0;
}

.message-text img {
  max-width: 600px;
  max-height: 500px;
  width: auto;
  height: auto;
  border-radius: 8px;
  margin: 16px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  object-fit: contain; /* Maintain aspect ratio */
  cursor: pointer; /* Indicate the image is clickable */
}

/* Add hover effect to make images feel interactive */
.message-text img:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transform: scale(1.01);
  transition: all 0.2s ease;
}

.message-text a {
  color: #0066cc;
  text-decoration: underline;
  text-decoration-color: rgba(0, 102, 204, 0.3);
  transition: all 0.2s ease;
  font-weight: 500;
}

.message-text a:hover {
  color: #0052a3;
  text-decoration-color: #0052a3;
  text-decoration-thickness: 2px;
}

.message-text hr {
  border: none;
  border-top: 2px solid var(--chat-border);
  margin: 16px 0;
}

.message-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  border: 1px solid var(--chat-border);
  border-radius: 6px;
  overflow: hidden;
}

.message-text th,
.message-text td {
  border: 1px solid var(--chat-border);
  padding: 8px 12px;
  text-align: left;
}

.message-text th {
  background: var(--chat-muted);
  font-weight: 600;
}

.message-text tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}

.message-text strong {
  font-weight: 600;
  color: var(--chat-text);
}

.message-text em {
  font-style: italic;
}

.message-text del {
  text-decoration: line-through;
  opacity: 0.7;
}

/* Task lists (GitHub Flavored Markdown) */
.message-text input[type="checkbox"] {
  margin-right: 8px;
  transform: scale(1.1);
}

.message-text ul.task-list {
  list-style: none;
  padding-left: 0;
}

.message-text .task-list-item {
  margin: 6px 0;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* Code syntax highlighting placeholder */
.message-text .highlight {
  background: var(--chat-muted);
  border-radius: 4px;
  padding: 2px 4px;
}

/* Streaming message styles */
.message.streaming .message-text {
  position: relative;
}

.streaming-text.typing::after {
  content: '▋';
  animation: blink 1s infinite;
  color: var(--chat-accent);
  font-weight: bold;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Message spinner for streaming content */
.message-spinner {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 0;
}

.message-spinner .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #e3f2fd;
  border-top: 2px solid var(--chat-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Message status text */
.message-status {
  color: #6c757d;
  font-style: italic;
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border: 1px solid #6c757d;
  border-top: 1px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Streaming animation improvements */
.streaming-text {
  transition: all 0.1s ease;
}

/* Enhanced message appearance during streaming */
.message.streaming {
  opacity: 0.95;
}

.message.streaming .message-text {
  background: #ffffff;
}

/* Plotly Chart Styles */
.plotly-chart-container {
  margin: 16px 0;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid var(--chat-border);
}

.plotly-chart {
  width: 100%;
  min-height: 300px;
  margin-bottom: 8px;
}

.chart-info {
  text-align: center;
  color: #6c757d;
  font-style: italic;
  margin-top: 8px;
}

.chart-info small {
  font-size: 0.85rem;
}

/* Responsive chart sizing */
@media (max-width: 768px) {
  .plotly-chart {
    min-height: 250px;
  }
  
  .plotly-chart-container {
    padding: 12px;
    margin: 12px 0;
  }
}

/* Responsive adjustments for markdown content */
@media (max-width: 768px) {
  .message-text h1 {
    font-size: 1.3rem;
  }
  
  .message-text h2 {
    font-size: 1.2rem;
  }
  
  .message-text pre {
    padding: 8px;
    font-size: 0.8em;
  }
  
  .message-text table {
    font-size: 0.85rem;
  }
  
  .message-text th,
  .message-text td {
    padding: 6px 8px;
  }
  
  .message-text img {
    max-width: 90%;
    max-height: 350px;
  }
  

}
