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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #222;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-muted: #888;
  --accent: #6366f1;
  --accent-dim: #4f46e5;
  --user-bg: #1e293b;
  --assistant-bg: #171717;
  --radius: 12px;
}

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

.chat-container {
  width: 100%;
  max-width: 800px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.chat-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status.online::before {
  background: #22c55e;
}

.status.error::before {
  background: #ef4444;
}

.api-key-bar {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.api-key-bar input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  font-family: monospace;
  font-size: 13px;
  outline: none;
}

.api-key-bar input:focus {
  border-color: var(--accent-dim);
}

.api-key-bar button {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.api-key-bar button:hover {
  background: var(--accent-dim);
}

.api-key-bar.saved input {
  border-color: #22c55e;
}

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

.welcome {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  max-width: 400px;
  line-height: 1.6;
}

.message {
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 85%;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  border: 1px solid #293548;
  white-space: pre-wrap;
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--border);
}

.message.assistant .cursor {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.model-tag {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 0 0 4px;
  align-self: flex-start;
  margin-bottom: 12px;
}

.model-tag span {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
}

.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.chat-input textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input textarea:focus {
  border-color: var(--accent-dim);
}

.chat-input textarea::placeholder {
  color: var(--text-muted);
}

.chat-input button {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.chat-input button:hover {
  background: var(--accent-dim);
}

.chat-input button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

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

/* Markdown content in assistant messages */
.message.assistant p {
  margin: 0 0 8px;
}

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

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

.message.assistant code {
  font-family: "SF Mono", "Fira Code", "JetBrains Mono", monospace;
  font-size: 13px;
}

.message.assistant :not(pre) > code {
  background: #2a2a2a;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

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

.message.assistant li {
  margin: 4px 0;
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3,
.message.assistant h4 {
  margin: 12px 0 6px;
  font-weight: 600;
}

.message.assistant h1 { font-size: 18px; }
.message.assistant h2 { font-size: 16px; }
.message.assistant h3 { font-size: 15px; }

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

.message.assistant blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-muted);
}

.message.assistant table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
}

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

.message.assistant th {
  background: var(--surface);
}
