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

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --user-bg: #1f6feb;
  --ai-bg: #161b22;
  --code-bg: #0d1117;
  --radius: 12px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

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

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

#clear-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
#clear-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Messages */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 60vh;
  gap: 16px;
}

.welcome-icon { color: var(--accent); opacity: 0.7; }
.welcome h1 { font-size: 28px; font-weight: 600; }
.welcome p { color: var(--text-muted); font-size: 15px; max-width: 400px; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}

.suggestion {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.05); }

/* Message bubbles */
.message {
  display: flex;
  gap: 14px;
  margin-bottom: 28px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .avatar { background: var(--user-bg); color: #fff; }
.message.ai .avatar { background: var(--surface); border: 1px solid var(--border); color: var(--accent); }

.content { flex: 1; min-width: 0; }

.message.user .text {
  background: var(--user-bg);
  padding: 10px 14px;
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  display: inline-block;
  max-width: 80%;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.ai .text {
  color: var(--text);
  word-break: break-word;
}

/* Markdown styles */
.message.ai .text h1,
.message.ai .text h2,
.message.ai .text h3 { margin: 16px 0 8px; font-weight: 600; }
.message.ai .text h1 { font-size: 20px; }
.message.ai .text h2 { font-size: 17px; }
.message.ai .text h3 { font-size: 15px; }

.message.ai .text p { margin-bottom: 12px; }
.message.ai .text p:last-child { margin-bottom: 0; }

.message.ai .text ul,
.message.ai .text ol { margin: 8px 0 12px 20px; }
.message.ai .text li { margin-bottom: 4px; }

.message.ai .text code:not(pre code) {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.875em;
  color: #f78166;
}

.message.ai .text pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}

.message.ai .text pre code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  background: none;
  border: none;
  padding: 0;
  color: inherit;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }

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

.message.ai .text table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
}
.message.ai .text th,
.message.ai .text td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
}
.message.ai .text th { background: var(--surface); }
.message.ai .text tr:nth-child(even) { background: rgba(255,255,255,0.02); }

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

/* Typing cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Footer / input */
footer {
  padding: 16px 24px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color 0.15s;
}
.input-wrapper:focus-within { border-color: var(--accent); }

#user-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}
#user-input::placeholder { color: var(--text-muted); }

#send-btn {
  background: var(--accent);
  border: none;
  color: #000;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { background: var(--border); cursor: not-allowed; }

/* Download button */
.download-wrapper {
  margin-top: 12px;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s;
}
.download-btn:hover { background: rgba(88, 166, 255, 0.18); }
.download-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Scrollbar */
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
