/* ─── Brand tokens ─────────────────────────────────────────── */
:root {
  --orange:      #F49600;
  --orange-dark: #d98500;
  --gray:        #73797D;
  --gray-light:  #f0f1f2;
  --gray-mid:    #e4e6e8;
  --white:       #ffffff;
  --text:        #1a1a1a;
  --text-muted:  #6b7280;
  --radius:      12px;
  --header-h:    60px;
  --input-h:     80px;
  --shadow:      0 2px 8px rgba(0,0,0,0.08);
}

/* ─── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--gray-light); color: var(--text); }

/* ─── Header ───────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--white);
  border-bottom: 3px solid var(--orange);
  box-shadow: var(--shadow);
  z-index: 100;
}
.header-inner {
  max-width: 780px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
}
.logo {
  height: 36px;
  width: auto;
}
.header-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray);
  letter-spacing: 0.02em;
}

/* ─── Chat area ────────────────────────────────────────────── */
.chat-area {
  max-width: 780px;
  margin: 0 auto;
  padding: calc(var(--header-h) + 24px) 20px calc(var(--input-h) + 48px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
}

/* ─── Message rows ─────────────────────────────────────────── */
.msg-row {
  display: flex;
  gap: 10px;
  animation: fadeIn 0.15s ease;
}
.msg-row.user  { justify-content: flex-end; }
.msg-row.bot   { justify-content: flex-start; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Avatar ───────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
  margin-top: 2px;
}
.avatar.bot-avatar  { background: var(--orange); color: var(--white); }
.avatar.user-avatar { background: var(--gray);   color: var(--white); }

/* ─── Bubbles ──────────────────────────────────────────────── */
.bubble {
  max-width: 72%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 0.93rem;
  box-shadow: var(--shadow);
}
.bubble.user-bubble {
  background: var(--orange);
  color: var(--white);
  border-bottom-right-radius: 3px;
}
.bubble.bot-bubble {
  background: var(--white);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

/* markdown inside bot bubble */
.bubble.bot-bubble p  { margin-bottom: 0.5em; }
.bubble.bot-bubble p:last-child { margin-bottom: 0; }
.bubble.bot-bubble ul,
.bubble.bot-bubble ol { padding-left: 1.4em; margin-bottom: 0.5em; }
.bubble.bot-bubble li { margin-bottom: 0.2em; }
.bubble.bot-bubble code {
  background: var(--gray-light);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.88em;
}
.bubble.bot-bubble pre {
  background: var(--gray-light);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
}
.bubble.bot-bubble strong { color: var(--orange-dark); }

/* ─── Sources accordion ────────────────────────────────────── */
.sources-wrapper {
  max-width: 72%;
  margin-left: 46px;
  margin-top: -10px;
}
.sources-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
  transition: color 0.15s;
}
.sources-toggle:hover { color: var(--orange); }
.sources-toggle .chevron { transition: transform 0.2s; }
.sources-toggle.open .chevron { transform: rotate(90deg); }

.sources-list {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding-top: 6px;
}
.sources-list.visible { display: flex; }

.source-chip {
  background: var(--white);
  border: 1px solid var(--gray-mid);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
}
.source-chip .source-label {
  font-weight: 600;
  color: var(--orange-dark);
  display: block;
  margin-bottom: 2px;
}
.source-chip .source-text { color: var(--text-muted); }

/* ─── Typing indicator ─────────────────────────────────────── */
.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--white);
  border-radius: var(--radius);
  border-bottom-left-radius: 3px;
  box-shadow: var(--shadow);
  width: fit-content;
}
.typing span {
  width: 7px; height: 7px;
  background: var(--gray);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

/* ─── Error bubble ─────────────────────────────────────────── */
.bubble.error-bubble {
  background: #fff3f3;
  color: #c0392b;
  border: 1px solid #f5c6c6;
}

/* ─── Input bar ────────────────────────────────────────────── */
.input-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--white);
  border-top: 1px solid var(--gray-mid);
  padding: 12px 20px 8px;
  z-index: 100;
}
.input-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.input-field {
  flex: 1;
  border: 1.5px solid var(--gray-mid);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.93rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 130px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color 0.15s;
}
.input-field:focus { border-color: var(--orange); }
.send-btn {
  width: 42px; height: 42px;
  background: var(--orange);
  color: var(--white);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover   { background: var(--orange-dark); }
.send-btn:active  { transform: scale(0.93); }
.send-btn:disabled { background: var(--gray-mid); cursor: not-allowed; }

.disclaimer {
  max-width: 780px;
  margin: 4px auto 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

/* ─── Welcome card ─────────────────────────────────────────── */
.welcome-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--orange);
  max-width: 540px;
  align-self: center;
  margin: auto;
}
.welcome-card h2 {
  font-size: 1.15rem;
  margin-bottom: 10px;
  color: var(--text);
}
.welcome-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.welcome-card ul {
  margin: 10px 0 0 1.2em;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.welcome-card ul li { margin-bottom: 4px; }

/* ─── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .bubble { max-width: 88%; }
  .sources-wrapper { max-width: 88%; }
}
