:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-light: #334155;
  --muted: #94a3b8;
  --text: #f1f5f9;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --user-bubble: #3b82f6;
  --assistant-bubble: #1e293b;
  --border: #334155;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
}

/* Header */
header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.header-content h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.header-content p {
  font-size: 0.875rem;
  color: var(--muted);
}

.header-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.session-label {
  font-size: 0.875rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.session-label input {
  padding: 0.5rem;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  width: 200px;
  font-family: monospace;
}

.session-label input[readonly] {
  cursor: default;
  opacity: 0.8;
}

.btn-secondary {
  padding: 0.5rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--panel-light);
  border-color: var(--accent);
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Welcome Message */
.welcome-message {
  text-align: center;
  padding: 3rem 2rem;
  max-width: 600px;
  margin: auto;
}

.welcome-message h2 {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.welcome-message p {
  color: var(--muted);
  margin-bottom: 2rem;
  line-height: 1.6;
}

.example-questions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
  margin: 0 auto;
}

.example-btn {
  padding: 0.875rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  font-size: 0.9375rem;
}

.example-btn:hover {
  background: var(--panel-light);
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* Chat Messages */
.message {
  display: flex;
  margin-bottom: 1rem;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-content {
  max-width: 70%;
  padding: 1rem 1.25rem;
  border-radius: 1rem;
  line-height: 1.6;
}

.user-message {
  justify-content: flex-end;
}

.user-message .message-content {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.assistant-message {
  justify-content: flex-start;
}

.assistant-message .message-content {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.25rem;
  color: var(--text);
}

/* Message Text with Markdown Support */
.message-text {
  overflow-wrap: break-word;
  word-wrap: break-word;
  color: var(--text);
}

.message-text h1, .message-text h2, .message-text h3 {
  margin: 1rem 0 0.5rem 0;
  font-weight: 600;
  color: var(--text);
}

.message-text h1:first-child,
.message-text h2:first-child,
.message-text h3:first-child {
  margin-top: 0;
}

.message-text p {
  margin: 0.75rem 0;
  color: var(--text);
}

.message-text p:first-child {
  margin-top: 0;
}

.message-text p:last-child {
  margin-bottom: 0;
}

.message-text ul, .message-text ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
  color: var(--text);
}

.message-text li {
  margin: 0.5rem 0;
  color: var(--text);
}

.message-text code {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.875em;
  color: #a7f3d0;
}

.message-text pre {
  background: #1e1e1e;
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 1rem 0;
  color: #d1fae5;
}

.message-text pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: #d1fae5;
}

.message-text blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--muted);
  font-style: italic;
}

.message-text a {
  color: var(--accent);
  text-decoration: none;
}

.message-text a:hover {
  text-decoration: underline;
}

.message-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
}

.message-text th,
.message-text td {
  border: 1px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}

.message-text th {
  background: var(--panel-light);
  font-weight: 600;
}

/* Typing Indicator */
.typing-indicator {
  font-size: 1.5rem;
  letter-spacing: 0.25rem;
  animation: blink 1.4s infinite;
}

@keyframes blink {
  0%, 20%, 50%, 80%, 100% { opacity: 1; }
  40%, 60% { opacity: 0.3; }
}

/* Sources */
.message-sources {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.sources-list {
  color: var(--muted);
}

.sources-list ul {
  margin: 0.5rem 0 0 0;
  padding-left: 1.25rem;
  list-style: none;
}

.sources-list li {
  margin: 0.25rem 0;
  padding: 0.25rem 0;
}

.source-title {
  color: var(--accent);
  font-weight: 500;
}

.source-id {
  color: var(--muted);
  font-size: 0.75rem;
}

/* Message Meta */
.message-meta {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.confidence {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Error Message */
.error-message {
  color: var(--error);
  padding: 0.75rem;
  background: rgba(239, 68, 68, 0.1);
  border-radius: 0.5rem;
  border: 1px solid var(--error);
}

/* Chat Input */
.chat-input-container {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 1rem 1.5rem;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
}

.chat-input-wrapper {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.75rem;
  transition: border-color 0.2s;
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent);
}

#questionInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9375rem;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 200px;
  font-family: inherit;
  line-height: 1.5;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.mode-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mode-indicator input[type="checkbox"] {
  cursor: pointer;
}

.hint {
  font-style: italic;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: var(--bg);
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--panel-light);
}

/* Responsive Design */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }
  
  .header-content h1 {
    font-size: 1.25rem;
  }
  
  .chat-messages {
    padding: 1rem;
  }
  
  .message-content {
    max-width: 85%;
  }
  
  .chat-input-container {
    padding: 1rem;
  }
  
  .welcome-message {
    padding: 2rem 1rem;
  }
}
