:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1f2329;
  --muted: #5f6772;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --bot-bg: #f1f3f5;
  --user-bg: #1f6feb;
  --user-text: #ffffff;
  --danger: #b32d2d;
  --radius: 14px;
  --max-w: 760px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand strong { font-size: 16px; margin-right: 8px; }
.brand span { color: var(--muted); font-size: 13px; }

.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg {
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  max-width: 80%;
}

.msg.bot .bubble {
  background: var(--bot-bg);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg.bot.error .bubble {
  background: #fdecec;
  color: var(--danger);
}

.citations {
  font-size: 12.5px;
  color: var(--muted);
  padding-left: 4px;
}
.citations strong { color: var(--text); }
.citations ol { margin: 4px 0 0; padding-left: 22px; }
.citations a { color: var(--accent); text-decoration: none; word-break: break-all; }
.citations a:hover { text-decoration: underline; }

.bubble sup a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  padding: 0 2px;
}
.bubble sup a:hover { text-decoration: underline; }

.composer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  outline: none;
  max-height: 160px;
  background: #fff;
  color: var(--text);
}
.composer textarea:focus { border-color: var(--accent); }

.composer button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 10px 18px;
  font-size: 15px;
  border-radius: 10px;
  cursor: pointer;
}
.composer button:disabled { opacity: 0.6; cursor: not-allowed; }

.typing {
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
}
.typing::after {
  content: "";
  display: inline-block;
  width: 8px;
  animation: dots 1.2s infinite steps(4, end);
}
@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}
