:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --text: #1c2430;
  --text-muted: #5b6677;
  --primary: #0b3d91;
  --primary-hover: #0a357a;
  --accent: #f0a500;
  --bubble-user-bg: #0b3d91;
  --bubble-user-text: #ffffff;
  --bubble-bot-bg: #ffffff;
  --bubble-bot-text: #1c2430;
  --danger: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.06), 0 6px 24px rgba(20, 30, 50, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

.app__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 4px 12px;
  border-bottom: 1px solid var(--border);
}

.app__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app__logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: 13px;
}

.app__header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.app__header p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn--ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 18px 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto;
  text-align: center;
  max-width: 560px;
  color: var(--text-muted);
  padding: 24px;
}

.empty h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 18px;
}

.empty ul {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty li {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.empty li:hover {
  border-color: var(--primary);
  background: var(--surface-2);
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
}

.msg__avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}

.msg--user .msg__avatar { background: #4a5568; }
.msg--bot .msg__avatar { background: var(--primary); }

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

.msg__bubble {
  padding: 11px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

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

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

.msg__bubble a { color: var(--primary); }
.msg__bubble code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}

.msg__sources {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.msg__source-chip {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
}

.msg--error .msg__bubble {
  background: #fdecea;
  border-color: #f5c2c0;
  color: var(--danger);
}

.caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 1px;
  background: var(--text-muted);
  vertical-align: text-bottom;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

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

.composer__input {
  flex: 1;
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer__input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 61, 145, 0.12);
}

.app__footer {
  padding: 4px 4px 16px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 600px) {
  .app { padding: 0 10px; }
  .app__header h1 { font-size: 14px; }
  .app__header p { font-size: 11px; }
  .btn--ghost { padding: 8px 10px; font-size: 13px; }
}
