:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --assistant-bg: #f1f5f9;
  --user-bg: #2563eb;
  --user-text: #fff;
  --text: #1e293b;
  --text-light: #64748b;
  --bg: #ffffff;
  --surface: #f8fafc;
  --border: #e2e8f0;
  --max-width: 700px;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--surface);
  color: var(--text);
  height: 100vh;
  display: flex;
  justify-content: center;
}

.chat-container {
  width: 100%;
  max-width: var(--max-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.chat-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
}

.chat-header p {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 2px;
}

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

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 0.95rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
  white-space: normal;
}

/* Markdown content inside assistant messages */
.message.assistant p { margin: 0.4em 0; }
.message.assistant p:first-child { margin-top: 0; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant strong { font-weight: 700; }
.message.assistant ul,
.message.assistant ol { margin: 0.4em 0; padding-left: 1.4em; }
.message.assistant code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.88em;
}
.message.assistant pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.5em 0;
}
.message.assistant pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.message.error {
  align-self: center;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  font-size: 0.85rem;
}

/* Typing indicator (inside chat messages, below assistant bubble) */
.typing-indicator {
  align-self: flex-start;
  padding: 6px 12px;
  display: flex;
  gap: 4px;
}

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

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

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

/* Input form */
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chat-form input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.chat-form input:focus {
  border-color: var(--primary);
}

.chat-form button {
  padding: 10px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-form button:hover {
  background: var(--primary-dark);
}

.chat-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Chart */
.chart-wrapper {
  width: 100%;
  max-width: 900px;
  padding: 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.chart-wrapper canvas {
  min-height: 400px;
}

/* Mobile */
@media (max-width: 600px) {
  .chat-container {
    border: none;
  }

  .message {
    max-width: 90%;
  }
}
