:root {
  --bg: #ffffff;
  --bg-alt: #f5f5f7;
  --text: #1a1a1e;
  --text-dim: #6b6b76;
  --border: #e3e3e8;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --bubble-user: #4f46e5;
  --bubble-user-text: #ffffff;
  --bubble-assistant: #f0f0f3;
  --bubble-assistant-text: #1a1a1e;
  --error: #d92d20;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171b;
    --bg-alt: #1f1f24;
    --text: #ececef;
    --text-dim: #8b8b95;
    --border: #2c2c33;
    --accent: #6366f1;
    --accent-text: #ffffff;
    --bubble-user: #6366f1;
    --bubble-user-text: #ffffff;
    --bubble-assistant: #26262c;
    --bubble-assistant-text: #ececef;
    --error: #f97066;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 48rem;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.title {
  font-weight: 600;
  font-size: 1rem;
}

.model-badge {
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
}

.new-chat {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}

.new-chat:hover {
  background: var(--bg-alt);
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.empty-state {
  margin: auto;
  color: var(--text-dim);
  font-size: 0.9rem;
  text-align: center;
}

.message {
  display: flex;
  max-width: 85%;
}

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

.message.assistant, .message.error {
  align-self: flex-start;
}

.bubble {
  padding: 0.6rem 0.9rem;
  border-radius: 1rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.45;
  font-size: 0.95rem;
}

.message.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 0.3rem;
}

.message.assistant .bubble {
  background: var(--bubble-assistant);
  color: var(--bubble-assistant-text);
  border-bottom-left-radius: 0.3rem;
}

.message.error .bubble {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
}

.bubble.thinking {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 0.9rem;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.15s; }
.dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input {
  flex: 1;
  resize: none;
  max-height: 10rem;
  padding: 0.65rem 0.9rem;
  border-radius: 1.1rem;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
}

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

#sendBtn {
  flex-shrink: 0;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#sendBtn:disabled {
  opacity: 0.5;
  cursor: default;
}

#sendBtn:not(:disabled):hover {
  filter: brightness(1.1);
}
