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

:root {
  --primary: #2563eb;
  --primary-light: #cbdcff;
  --primary-dark: #1e40af;
  --secondary: #64748b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg-light: #f8fafc;
  --bg-dark: #1e293b;
  --text-dark: #0f172a;
  --text-light: #64748b;
  --border: #e2e8f0;
  --shadow: rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  margin: 0;
  padding: 0;
  color: var(--text-dark);
  overflow: auto;
}

.chat-container {
  background: white;
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 12px;
  animation: slideIn 0.3s ease-out;
}

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

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  background: var(--bg-light);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
}

.message.user .avatar {
  background: var(--primary-light);
  color: white;
}

.content {
  flex: 1;
  max-width: 80%;
}

.message.user .content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.content strong {
  margin-bottom: 4px;
  color: var(--text-light);
}

.message-text {
  background: var(--bg-light);
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
}

.message.user .message-text {
  background: var(--primary-light);
}

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

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

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

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

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

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

.message.user .message-text strong {
  color: white;
}

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

.message-text code {
  background: rgba(0, 0, 0, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9em;
}

.message.user .message-text code {
  background: rgba(255, 255, 255, 0.2);
}

.message-text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.message-text br {
  line-height: 1.5;
}

.message-text blockquote {
  margin: 12px 0;
  padding: 12px 16px;
  background: rgba(37, 99, 235, 0.05);
  border-left: 4px solid var(--primary);
  border-radius: 4px;
  font-style: italic;
  color: var(--text-dark);
}

.message.user .message-text blockquote {
  background: rgba(255, 255, 255, 0.2);
  border-left-color: white;
  color: white;
}

.message-text h1,
.message-text h2,
.message-text h3 {
  margin: 16px 0 8px 0;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-dark);
}

.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child {
  margin-top: 0;
}

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

.message-text h2 {
  font-size: 1.3em;
  color: var(--primary);
}

.message-text h3 {
  font-size: 1.1em;
  color: var(--secondary);
}

.message.user .message-text h1,
.message.user .message-text h2,
.message.user .message-text h3 {
  color: white;
}

.message.user .message-text h1 {
  border-bottom-color: rgba(255, 255, 255, 0.3);
}

.sources {
  margin-top: 8px;
  padding: 8px 12px;
  background: #fef3c7;
  border-left: 3px solid var(--warning);
  border-radius: 4px;
  font-size: 12px;
}

.sources strong {
  color: var(--warning);
}

.cache-indicator {
  margin-top: 2px;
  padding: 0 12px;
  border-radius: 4px;
  font-size: 10px;
  opacity: 0.7;
  text-align: right;
}

/* Thinking indicator */
.message.thinking {
  opacity: 0.8;
}

.thinking-text {
  padding: 12px 16px;
}

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

.thinking-dots .dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: thinking-bounce 1.4s infinite ease-in-out both;
}

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

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

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

.input-area {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-light);
}

#chat-form {
  display: flex;
  gap: 12px;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
}

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

#send-button {
  padding: 12px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#send-button:hover:not(:disabled) {
  background: var(--primary-dark);
}

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

#message-input:disabled {
  background: var(--bg-light);
  cursor: not-allowed;
  opacity: 0.7;
}

.spinner {
  animation: spin 1s linear infinite;
}

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

.hidden {
  display: none;
}

/* Context panel and header styles removed for simplified UI */

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

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

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

.messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-dark);
}

/* Responsive */
@media (max-width: 768px) {
  .content {
    max-width: 95%;
  }

  .message {
    flex-direction: column;
    align-items: flex-start;
  }

  .avatar {
    margin-bottom: 8px;
  }
}
