/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Chat container */
.chat-container {
  width: 100%;
  max-width: 900px;
  height: 90vh;
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-content {
  display: flex;
  align-items: center;
  gap: 15px;
}

.bot-avatar {
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.header-text h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 5px;
}

.header-text p {
  font-size: 14px;
  opacity: 0.9;
}

.clear-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 10px 15px;
  border-radius: 25px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.clear-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Messages container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Welcome message */
.welcome-message {
  text-align: center;
  padding: 40px 20px;
  color: #666;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 36px;
  color: white;
}

.welcome-message h3 {
  font-size: 24px;
  margin-bottom: 10px;
  color: #333;
}

.welcome-message p {
  font-size: 16px;
  line-height: 1.6;
  max-width: 400px;
  margin: 0 auto;
}

/* Message styles */
.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.bot {
  align-self: flex-start;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.message.bot .message-avatar {
  background: #f0f0f0;
  color: #666;
}

.message-content {
  background: #f8f9fa;
  padding: 15px 20px;
  border-radius: 18px;
  position: relative;
  min-width: 0;
}

.message.user .message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.message.bot .message-content {
  background: #f8f9fa;
  color: #333;
}

.message-text {
  line-height: 1.6;
  word-wrap: break-word;
}

.message-time {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 8px;
}

/* Markdown styles for bot messages */
.message.bot .message-text {
  /* Headers */
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
  }

  h1 {
    font-size: 24px;
  }
  h2 {
    font-size: 20px;
  }
  h3 {
    font-size: 18px;
  }
  h4 {
    font-size: 16px;
  }
  h5 {
    font-size: 14px;
  }
  h6 {
    font-size: 12px;
  }

  /* Paragraphs */
  p {
    margin: 8px 0;
    line-height: 1.6;
  }

  /* Lists */
  ul,
  ol {
    margin: 8px 0;
    padding-left: 24px;
  }

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

  /* Code blocks */
  pre {
    background: #f6f8fa;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 16px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 14px;
    line-height: 1.45;
  }

  code {
    background: #f6f8fa;
    border: 1px solid #e1e4e8;
    border-radius: 3px;
    padding: 2px 6px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
  }

  pre code {
    background: none;
    border: none;
    padding: 0;
  }

  /* Blockquotes */
  blockquote {
    border-left: 4px solid #667eea;
    margin: 12px 0;
    padding: 8px 16px;
    background: #f8f9fa;
    border-radius: 0 6px 6px 0;
  }

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

  th,
  td {
    border: 1px solid #e1e4e8;
    padding: 8px 12px;
    text-align: left;
  }

  th {
    background: #f6f8fa;
    font-weight: 600;
  }

  /* Links */
  a {
    color: #667eea;
    text-decoration: none;
  }

  a:hover {
    text-decoration: underline;
  }

  /* Strong and emphasis */
  strong {
    font-weight: 600;
  }

  em {
    font-style: italic;
  }

  /* Horizontal rule */
  hr {
    border: none;
    border-top: 1px solid #e1e4e8;
    margin: 16px 0;
  }
}

/* Input container */
.input-container {
  padding: 20px;
  border-top: 1px solid #e1e4e8;
  background: white;
}

.input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

#messageInput {
  flex: 1;
  border: 2px solid #e1e4e8;
  border-radius: 25px;
  padding: 12px 20px;
  font-size: 16px;
  resize: none;
  outline: none;
  transition: border-color 0.3s;
  font-family: inherit;
  max-height: 120px;
  min-height: 48px;
}

#messageInput:focus {
  border-color: #667eea;
}

#messageInput::placeholder {
  color: #999;
}

#sendBtn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: transform 0.2s;
  flex-shrink: 0;
}

#sendBtn:hover:not(:disabled) {
  transform: scale(1.05);
}

#sendBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading indicator */
.loading-indicator {
  padding: 20px;
  display: flex;
  justify-content: center;
}

.loading-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #667eea;
  animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
  animation-delay: -0.32s;
}

.dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* Error message */
.error-message {
  background: #fee;
  color: #c53030;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid #fed7d7;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: 10px 0;
}

/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
  width: 6px;
}

.messages-container::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.messages-container::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Responsive design */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .chat-container {
    height: 95vh;
    border-radius: 15px;
  }

  .message {
    max-width: 90%;
  }

  .header-text h1 {
    font-size: 20px;
  }

  .header-text p {
    font-size: 12px;
  }

  .clear-btn {
    padding: 8px 12px;
    font-size: 12px;
  }
}
