:root {
  --bg: #07090f;
  --surface: #0e1219;
  --surface-2: #141a24;
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --text: #e8ecf4;
  --text-muted: #7a8499;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.15);
  --accent-glow: rgba(0, 212, 170, 0.35);
  --user-bg: rgba(59, 130, 246, 0.12);
  --user-border: rgba(59, 130, 246, 0.25);
  --ai-bg: rgba(255, 255, 255, 0.03);
  --danger: #f87171;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Outfit', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --header-h: 64px;
  --input-h: auto;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow: hidden;
}

/* Ambient background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 212, 170, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(59, 130, 246, 0.05), transparent),
    radial-gradient(ellipse 50% 30% at 0% 80%, rgba(139, 92, 246, 0.04), transparent);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  height: 100%;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: rgba(7, 9, 15, 0.85);
  backdrop-filter: blur(20px);
}

/* Header */
.header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #3b82f6);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 0 24px var(--accent-glow);
}

.logo svg { width: 20px; height: 20px; color: var(--bg); }

.brand-text h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}

.status.thinking .status-dot {
  background: #fbbf24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.6);
  animation: blink 0.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.header-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--surface);
}

.btn-primary {
  background: var(--accent-dim);
  border-color: rgba(0, 212, 170, 0.3);
  color: var(--accent);
}

.btn-primary:hover {
  background: rgba(0, 212, 170, 0.22);
  color: var(--accent);
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.25);
  background: rgba(248, 113, 113, 0.08);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn svg { width: 14px; height: 14px; }

/* Messages */
.messages-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.messages {
  height: 100%;
  overflow-y: auto;
  padding: 24px 20px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border-radius: 3px;
}

/* Welcome */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60%;
  text-align: center;
  padding: 40px 20px;
  animation: fadeUp 0.5s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent-dim);
  border: 1px solid rgba(0, 212, 170, 0.2);
  display: grid;
  place-items: center;
  margin-bottom: 20px;
}

.welcome-icon svg { width: 28px; height: 28px; color: var(--accent); }

.welcome h2 {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.welcome p {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 380px;
  line-height: 1.5;
  margin-bottom: 28px;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 520px;
}

.chip {
  padding: 10px 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  color: var(--accent);
  border-color: rgba(0, 212, 170, 0.3);
  background: var(--accent-dim);
}

/* Message rows */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: msgIn 0.3s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 600;
}

.message.ai .avatar {
  background: linear-gradient(135deg, var(--accent-dim), rgba(59, 130, 246, 0.15));
  border: 1px solid rgba(0, 212, 170, 0.2);
  color: var(--accent);
}

.message.user .avatar {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  color: #60a5fa;
}

.bubble-wrap { max-width: calc(100% - 44px); min-width: 0; }

.message.user .bubble-wrap { display: flex; flex-direction: column; align-items: flex-end; }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 0.92rem;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-bottom-right-radius: 4px;
}

.message.ai .bubble {
  background: var(--ai-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Markdown in AI bubbles */
.bubble .md-content { overflow-x: auto; }
.bubble .md-content > *:first-child { margin-top: 0; }
.bubble .md-content > *:last-child { margin-bottom: 0; }

.md-content p { margin: 0.6em 0; }
.md-content h1, .md-content h2, .md-content h3 {
  margin: 1em 0 0.4em;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.md-content h1 { font-size: 1.2em; }
.md-content h2 { font-size: 1.1em; }
.md-content h3 { font-size: 1em; }

.md-content ul, .md-content ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}

.md-content li { margin: 0.25em 0; }

.md-content code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

.md-content pre {
  margin: 0.8em 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}

.md-content pre code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
  background: #0d1117;
  color: var(--text);
  font-size: 0.82em;
  line-height: 1.5;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #161b22;
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.copy-btn {
  padding: 2px 8px;
  font-size: 0.68rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}

.copy-btn:hover { color: var(--accent); border-color: rgba(0, 212, 170, 0.3); }
.copy-btn.copied { color: var(--accent); }

.md-content blockquote {
  margin: 0.6em 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
}

.md-content a { color: #60a5fa; text-decoration: none; }
.md-content a:hover { text-decoration: underline; }

.md-content table {
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 0.85em;
  width: 100%;
}

.md-content th, .md-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.md-content th { background: var(--surface-2); }

/* Streaming cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  margin: 0 2px;
  animation: dotBounce 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.input-area {
  flex-shrink: 0;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: linear-gradient(to top, var(--bg), transparent);
}

.input-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-box:focus-within {
  border-color: rgba(0, 212, 170, 0.35);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#user-input {
  width: 100%;
  min-height: 24px;
  max-height: 160px;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  line-height: 1.5;
  outline: none;
}

#user-input::placeholder { color: var(--text-muted); }

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.input-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.input-hint kbd {
  font-family: var(--mono);
  font-size: 0.65rem;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #00b894);
  color: var(--bg);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 20px var(--accent-glow);
}

.send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }
.send-btn svg { width: 18px; height: 18px; }

.scroll-fab {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  opacity: 0;
  pointer-events: none;
  padding: 8px 14px;
  font-size: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.25s ease;
  z-index: 10;
  font-family: var(--font);
}

.scroll-fab.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.scroll-fab:hover { color: var(--accent); border-color: rgba(0, 212, 170, 0.3); }

.error-text { color: var(--danger); }

@media (max-width: 600px) {
  .header { padding: 0 14px; }
  .brand-text p { display: none; }
  .status span.label { display: none; }
  .messages { padding: 16px 14px; }
  .input-area { padding: 12px 14px 16px; }
  .prompt-chips { flex-direction: column; align-items: stretch; }
}