* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #007c23;
  --primary-hover: #006119;
  --secondary-color: #64748b;
  --background: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --user-message-bg: #007c23;
  --assistant-message-bg: #f1f5f9;
  --success: #10b981;
  --error: #ef4444;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1),
    0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
    "Ubuntu", "Cantarell", sans-serif;
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.header {
  background: var(--surface);
  padding: 1rem 2rem;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  position: relative;
}

.header-content {
  text-align: center;
}

.support-link {
  position: absolute;
  top: 1rem;
  right: 2rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--primary-color);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.2s ease;
}

.support-link:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.support-link svg {
  flex-shrink: 0;
  vertical-align: middle;
}

.logo {
  max-width: 200px;
  height: auto;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--background);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--secondary-color);
}

.welcome-message {
  max-width: 600px;
  margin: 2rem auto;
  text-align: center;
  color: var(--text-secondary);
}

.welcome-message h2 {
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.example-queries {
  margin-top: 2rem;
  text-align: left;
  background: var(--background);
  padding: 1.5rem;
  border-radius: 8px;
}

.example-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.example-query {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  text-align: left;
  color: var(--primary-color);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.example-query:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  transform: translateX(4px);
}

.message {
  display: flex;
  margin-bottom: 1.5rem;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

.message-content {
  max-width: 70%;
  padding: 1rem 1.25rem;
  border-radius: 12px;
  position: relative;
}

.message.user .message-content {
  background: var(--user-message-bg);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: var(--assistant-message-bg);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message.assistant .message-content.streaming::after {
  content: "▋";
  animation: blink 1s infinite;
  margin-left: 2px;
}

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

.message-header {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  opacity: 0.8;
}

.message.user .message-header {
  color: rgba(255, 255, 255, 0.9);
}

.message.assistant .message-header {
  color: var(--primary-color);
}

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

/* Markdown styling for assistant messages */
.message.assistant .message-text h1,
.message.assistant .message-text h2,
.message.assistant .message-text h3 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

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

.message.assistant .message-text h2 {
  font-size: 1.25rem;
}

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

.message.assistant .message-text p {
  margin: 0.75rem 0;
}

.message.assistant .message-text ul,
.message.assistant .message-text ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

.message.assistant .message-text li {
  margin: 0.25rem 0;
}

.message.assistant .message-text code {
  background: var(--background);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 0.9em;
}

.message.assistant .message-text pre {
  background: var(--background);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1rem 0;
}

.message.assistant .message-text pre code {
  background: none;
  padding: 0;
}

.message.assistant .message-text blockquote {
  border-left: 4px solid var(--primary-color);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message.assistant .message-text a {
  color: var(--primary-color);
  text-decoration: underline;
}

.message.assistant .message-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.message.assistant .message-text th,
.message.assistant .message-text td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}

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

.message-sources {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.sources-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.sources-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.source-item {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--primary-color);
  font-family: "Courier New", monospace;
  transition: all 0.2s ease;
  cursor: pointer;
}

.source-item:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.source-link {
  text-decoration: none;
  display: inline-block;
}

.source-link:hover {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Image display styles */
.images-container {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
  margin-bottom: 12px;
}

.image-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 300px;
}

.source-image {
  max-width: 100%;
  height: auto;
  max-height: 200px;
  object-fit: contain;
  border-radius: 6px;
  border: 2px solid #e0e0e0;
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
}

.source-image:hover {
  border-color: var(--primary-color);
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(0, 124, 35, 0.2);
}

.image-caption {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  word-break: break-word;
}

/* Related images inline with sources */
.source-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 0 0 auto;
}

.related-images-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.related-image-thumb {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s ease;
}

.related-image-thumb:hover {
  border-color: var(--primary-color);
  transform: scale(1.05);
  box-shadow: 0 2px 6px rgba(0, 124, 35, 0.15);
}

.message-timestamp {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-top: 0.5rem;
}

.typing-indicator {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--assistant-message-bg);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  max-width: 70%;
}

.typing-indicator span {
  height: 8px;
  width: 8px;
  background: var(--secondary-color);
  border-radius: 50%;
  display: inline-block;
  margin: 0 2px;
  animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

.input-container {
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  background: var(--surface);
}

.input-wrapper {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

#messageInput {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  max-height: 150px;
  transition: border-color 0.2s;
}

#messageInput:focus {
  outline: none;
  border-color: var(--primary-color);
}

.send-button {
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-button:hover {
  background: var(--primary-hover);
}

.send-button:disabled {
  background: var(--secondary-color);
  cursor: not-allowed;
  opacity: 0.5;
}

.input-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 1rem;
}

.clear-button {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.clear-button:hover {
  background: var(--background);
  color: var(--text-primary);
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-radius: 8px;
  margin-top: 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  box-shadow: var(--shadow);
}

.error-message {
  background: var(--error);
  color: white;
  padding: 1rem;
  border-radius: 8px;
  margin: 1rem 0;
  animation: shake 0.3s;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Image Modal */
.image-modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  animation: fadeIn 0.2s ease;
}

.image-modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: zoomIn 0.2s ease;
}

.image-modal-content img {
  max-width: 100%;
  max-height: calc(90vh - 60px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.3);
}

.image-modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.3s;
  z-index: 10000;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-modal-close:hover,
.image-modal-close:focus {
  color: #bbb;
}

.image-modal-caption {
  margin-top: 15px;
  color: #ccc;
  font-size: 14px;
  text-align: center;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 6px;
  max-width: 100%;
  word-break: break-word;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes zoomIn {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 0.5rem;
  }

  .header {
    padding: 1rem;
  }

  .logo {
    max-width: 200px;
  }

  .chat-messages {
    padding: 1rem;
  }

  .message-content {
    max-width: 85%;
  }

  .input-footer {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  .image-modal-content {
    max-width: 95%;
    max-height: 95%;
  }

  .image-modal-close {
    font-size: 32px;
    top: -35px;
  }
}
