:root {
  --bg: #fdfaf7;
  --surface: #ffffff;
  --border: #eee0d3;
  --text: #2b2320;
  --text-muted: #8a7c70;
  --accent: #ea7317;
  --accent-contrast: #ffffff;
  --bubble-user: #ea7317;
  --bubble-user-text: #ffffff;
  --bubble-bot: #fff3e8;
  --bubble-bot-text: #2b2320;
  --source-bg: #fbeee0;
  --error: #d64545;
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #1c1512;
  --surface: #241a15;
  --border: #3a2c22;
  --text: #f2e9e2;
  --text-muted: #b6a595;
  --accent: #ff8c3a;
  --accent-contrast: #1c1512;
  --bubble-user: #ff8c3a;
  --bubble-user-text: #1c1512;
  --bubble-bot: #2c2119;
  --bubble-bot-text: #f2e9e2;
  --source-bg: #33261c;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.brand-icon { font-size: 1.4rem; }

.theme-toggle {
  border: none;
  background: var(--bubble-bot);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-left-radius: 4px;
}

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

.msg.error {
  align-self: flex-start;
  background: var(--error);
  color: #fff;
}

.sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sources ul { margin: 4px 0 0; padding-inline-start: 18px; }

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bubble-bot);
  border-radius: var(--radius);
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  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; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 18px 10px;
}

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.composer {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

#question-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
#question-input:focus { border-color: var(--accent); }

#send-btn {
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0 20px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}
#send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.disclaimer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0;
  padding-bottom: 10px;
}

@media (max-width: 480px) {
  .msg { max-width: 92%; }
}
