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

:root {
  --bg: #0e0e0e;
  --surface: #161616;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #666;
  --accent: #7c6af7;
  --accent-dim: rgba(124, 106, 247, 0.15);
  --user-bg: #1e1e2e;
  --bot-bg: #161616;
  --guidance-color: #4ade80;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 1.6;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 760px;
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; flex-direction: column; gap: 2px; }

.title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 11px;
  color: var(--text-dim);
}

.clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  transition: color 0.15s, border-color 0.15s;
}
.clear-btn:hover { color: var(--text); border-color: #444; }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.message.assistant {
  align-items: flex-start;
}

.bubble {
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 88%;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bg);
  border: 1px solid var(--accent);
  border-bottom-right-radius: 3px;
  color: var(--text);
}

.message.assistant .bubble {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

/* Markdown rendering */
.bubble p { margin-bottom: 0.6em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { color: #fff; font-weight: 700; }
.bubble em { color: #aaa; font-style: italic; }
.bubble code {
  background: #222;
  border: 1px solid #333;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9em;
  color: #c4b5fd;
}
.bubble pre {
  background: #111;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
  overflow-x: auto;
}
.bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: #d4d4d4;
}
.bubble ul, .bubble ol { padding-left: 1.4em; margin: 4px 0 8px; }
.bubble li { margin-bottom: 2px; }
.bubble h1, .bubble h2, .bubble h3 {
  color: #fff;
  margin: 10px 0 4px;
  font-size: 1em;
  font-weight: 700;
}
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }

/* Guidance updated badge */
.guidance-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--guidance-color);
  margin-top: 4px;
  padding: 2px 8px;
  background: rgba(74, 222, 128, 0.08);
  border: 1px solid rgba(74, 222, 128, 0.2);
  border-radius: 20px;
  width: fit-content;
}

/* Typing indicator */
.typing .bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Input area */
.input-area {
  display: flex;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
}

textarea {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 14px;
  resize: none;
  outline: none;
  max-height: 140px;
  overflow-y: auto;
  transition: border-color 0.15s;
}
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: var(--text-dim); }

#sendBtn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
#sendBtn:hover { opacity: 0.85; }
#sendBtn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Scrollbar for textarea */
textarea::-webkit-scrollbar { width: 3px; }
textarea::-webkit-scrollbar-thumb { background: var(--border); }

@media (max-width: 600px) {
  .messages { padding: 16px; }
  .input-area { padding: 12px 16px 16px; }
  .bubble { max-width: 96%; }
}
