:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c222b;
  --border: #2a313c;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #4a90d9;
  --accent-soft: #1c2a3a;
  --user-bubble: #4a90d9;
  --user-text: #eaf2fb;
  --bot-bubble: #21262d;
  --danger: #f85149;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.chat {
  width: 100%;
  max-width: 720px;
  height: min(880px, 94vh);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}

.chat__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  flex: 0 0 auto;
}

.chat__titles { min-width: 0; }

.chat__title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.chat__subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat__session {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.chat__iconbtn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.05s;
}

.chat__iconbtn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.chat__iconbtn:active:not(:disabled) { transform: scale(0.94); }
.chat__iconbtn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Messages */
.chat__messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.chat__messages::-webkit-scrollbar { width: 10px; }
.chat__messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
}

.msg {
  display: flex;
  max-width: 84%;
  animation: fade-in 0.18s ease-out;
}

.msg--user { align-self: flex-end; justify-content: flex-end; }
.msg--bot { align-self: flex-start; }

.msg__bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg--user .msg__bubble,
.msg--error .msg__bubble {
  white-space: pre-wrap;
}

.msg--user .msg__bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.msg--bot .msg__bubble {
  background: var(--bot-bubble);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* Bot answers are rendered from markdown (see renderMarkdown in app.js) */
.msg--bot .msg__bubble p { margin: 0.5em 0; }
.msg--bot .msg__bubble p:first-child { margin-top: 0; }
.msg--bot .msg__bubble p:last-child { margin-bottom: 0; }
.msg--bot .msg__bubble h1,
.msg--bot .msg__bubble h2,
.msg--bot .msg__bubble h3,
.msg--bot .msg__bubble h4,
.msg--bot .msg__bubble h5,
.msg--bot .msg__bubble h6 {
  margin: 0.6em 0 0.3em;
  font-size: 1.05em;
  font-weight: 600;
  line-height: 1.3;
}
.msg--bot .msg__bubble h1:first-child,
.msg--bot .msg__bubble h2:first-child,
.msg--bot .msg__bubble h3:first-child,
.msg--bot .msg__bubble h4:first-child { margin-top: 0; }
.msg--bot .msg__bubble ul,
.msg--bot .msg__bubble ol {
  margin: 0.4em 0;
  padding-left: 1.3em;
}
.msg--bot .msg__bubble li { margin: 0.2em 0; }
.msg--bot .msg__bubble strong { font-weight: 700; color: var(--text); }
.msg--bot .msg__bubble em { font-style: italic; }
.msg--bot .msg__bubble code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.msg--bot .msg__bubble blockquote {
  margin: 0.5em 0;
  padding-left: 0.8em;
  border-left: 2px solid var(--border);
  color: var(--text-dim);
}

.msg--error .msg__bubble {
  background: rgba(248, 81, 73, 0.12);
  color: var(--danger);
  border: 1px solid rgba(248, 81, 73, 0.4);
}

/* Typing indicator */
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

/* Input */
.chat__inputbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
}

.chat__input {
  flex: 1 1 auto;
  resize: none;
  max-height: 140px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.4;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.chat__input:focus { border-color: var(--accent); }
.chat__input::placeholder { color: var(--text-dim); }

.chat__send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #eaf2fb;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
}

.chat__send:hover { opacity: 0.9; }
.chat__send:active { transform: scale(0.94); }
.chat__send:disabled { opacity: 0.4; cursor: not-allowed; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
