:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #22c55e;
  --accent-2: #16a34a;
  --user: #2563eb;
  --bot: #374151;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #1e293b 0, var(--bg) 55%);
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 16px;
}

.app {
  width: min(920px, 100%);
  height: min(760px, calc(100vh - 32px));
  background: rgba(17, 24, 39, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.header {
  padding: 18px 20px;
  background: rgba(31, 41, 55, 0.8);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

h1 { margin: 0; font-size: 22px; }
p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

button {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  color: white;
  background: var(--accent-2);
  cursor: pointer;
  font-weight: 700;
}

button:hover { filter: brightness(1.08); }
button:disabled { cursor: not-allowed; opacity: 0.55; }
#clearBtn { background: #4b5563; }

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

.empty {
  margin: auto;
  max-width: 520px;
  text-align: center;
  color: var(--muted);
  line-height: 1.6;
}

.message {
  max-width: 78%;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--user);
  border-bottom-right-radius: 4px;
}

.message.bot {
  align-self: flex-start;
  background: var(--bot);
  border-bottom-left-radius: 4px;
  white-space: normal;
}

/* ── Markdown in bot messages ────────────────────────────── */

.message.bot p { margin: 0 0 8px; }
.message.bot p:last-child { margin-bottom: 0; }

.message.bot strong { color: var(--accent); font-weight: 700; }

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

.message.bot li { margin: 3px 0; }

.message.bot code {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}

.message.bot pre {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.message.bot pre code {
  background: none;
  padding: 0;
}

.message.bot h1,
.message.bot h2,
.message.bot h3 {
  margin: 10px 0 6px;
  font-size: 15px;
  color: var(--accent);
}

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

.message.bot a {
  color: #60a5fa;
  text-decoration: underline;
}

.message.bot table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  width: 100%;
}

.message.bot th,
.message.bot td {
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 10px;
  text-align: left;
}

.message.bot th {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
}

.message.error {
  align-self: flex-start;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.5);
}

.typing {
  color: var(--muted);
  font-size: 14px;
  padding-left: 4px;
}

.composer {
  padding: 16px;
  background: rgba(31, 41, 55, 0.85);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 10px;
}

input {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px 14px;
  background: #0b1220;
  color: var(--text);
  outline: none;
  font-size: 15px;
}

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

@media (max-width: 640px) {
  body { padding: 0; }
  .app { height: 100vh; border-radius: 0; }
  .message { max-width: 90%; }
  .header { padding: 14px; }
  .composer { padding: 12px; }
}
