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

/* Tokens */
:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --muted: #888;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --danger: #ef4444;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.nav-links a { color: var(--muted); font-size: 0.9rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--surface); text-decoration: none; }

.btn-full { width: 100%; text-align: center; padding: 0.75rem; }

/* Hero */
.hero {
  max-width: 680px;
  margin: 6rem auto 0;
  padding: 0 2rem;
  text-align: center;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.25rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 1.25rem;
}

.hero h1 span { color: var(--accent); }

.hero p {
  font-size: 1.1rem;
  color: var(--muted);
  margin-bottom: 2rem;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.hero-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Features */
.features {
  max-width: 900px;
  margin: 6rem auto;
  padding: 0 2rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.feature-card .icon {
  font-size: 1.5rem;
  margin-bottom: 0.75rem;
}

.feature-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.feature-card p {
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.6;
}

/* Auth pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.auth-card h1 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.auth-card .subtitle {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1.75rem;
}

/* Form */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-group input::placeholder { color: var(--muted); }

.form-footer {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Chat layout */
body.chat-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.chat-page nav { flex-shrink: 0; }

.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
}

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

/* Empty state */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  gap: 0.4rem;
  padding: 4rem 0;
}

.chat-empty-greeting {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

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

.bubble {
  padding: 0.7rem 1rem;
  line-height: 1.65;
  font-size: 0.95rem;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

.message.assistant .bubble {
  min-width: 2.5rem;
  min-height: 2.75rem;
  white-space: normal;
}

/* Typing cursor */
.cursor {
  display: inline-block;
  animation: blink 0.75s step-end infinite;
}

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

/* Markdown inside assistant bubbles */
.message.assistant .bubble p         { margin-bottom: 0.5em; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }

.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3        { font-weight: 600; line-height: 1.3; margin: 0.8em 0 0.35em; }
.message.assistant .bubble h1        { font-size: 1.15em; }
.message.assistant .bubble h2        { font-size: 1.05em; }
.message.assistant .bubble h3        { font-size: 0.95em; }

.message.assistant .bubble ul,
.message.assistant .bubble ol        { padding-left: 1.4em; margin: 0.35em 0; }
.message.assistant .bubble li        { margin: 0.15em 0; }

.message.assistant .bubble table     { width: 100%; border-collapse: collapse; font-size: 0.875em; margin: 0.6em 0; }
.message.assistant .bubble th,
.message.assistant .bubble td        { border: 1px solid var(--border); padding: 0.4em 0.7em; text-align: left; }
.message.assistant .bubble th        { background: rgba(255,255,255,0.06); font-weight: 600; }
.message.assistant .bubble tr:nth-child(even) td { background: rgba(255,255,255,0.02); }

.message.assistant .bubble code      { font-family: ui-monospace, monospace; font-size: 0.875em; background: rgba(0,0,0,0.35); padding: 0.1em 0.35em; border-radius: 3px; }
.message.assistant .bubble pre       { background: rgba(0,0,0,0.35); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75em 1em; overflow-x: auto; margin: 0.5em 0; }
.message.assistant .bubble pre code  { background: none; padding: 0; }

.message.assistant .bubble hr        { border: none; border-top: 1px solid var(--border); margin: 0.75em 0; }
.message.assistant .bubble blockquote { border-left: 3px solid var(--accent); margin: 0.5em 0; padding: 0.2em 0.75em; color: var(--muted); }

/* Input area */
.chat-input-area {
  flex-shrink: 0;
  padding: 0.75rem 0 1.5rem;
  border-top: 1px solid var(--border);
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--muted); }

.send-btn { flex-shrink: 0; }

/* Error */
.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
