/* ── Reset ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:        #003087;
  --navy-dark:   #00225e;
  --navy-light:  #1a4aaa;
  --gold:        #FFB800;
  --gold-light:  #FFD45E;
  --bg:          #F0F3FA;
  --surface:     #FFFFFF;
  --bot-bg:      #E8EDF8;
  --user-bg:     #003087;
  --text:        #111827;
  --text-light:  #6B7280;
  --border:      #D4DBEE;
  --source-bg:   #DDE8F7;
  --source-txt:  #1A4FA3;
  --suggestion-bg:  #EEF4FF;
  --suggestion-txt: #2563EB;
  --error-bg:    #FEE2E2;
  --error-txt:   #991B1B;
  --code-bg:     #1E293B;
  --code-txt:    #E2E8F0;
  --radius:      14px;
  --shadow:      0 2px 16px rgba(0,48,135,.10);
  --header-h:    64px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.header {
  background: var(--navy);
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 2px 12px rgba(0,0,0,.30);
}
.header-inner {
  max-width: 800px;
  margin: 0 auto;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-logo  { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--gold);
  color: var(--navy);
  font-weight: 800; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; letter-spacing: .5px;
}
.logo-text    { display: flex; flex-direction: column; }
.logo-title   { color: #fff; font-size: 15px; font-weight: 700; }
.logo-sub     { color: rgba(255,255,255,.6); font-size: 11.5px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.status-badge {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 12px;
  color: rgba(255,255,255,.85);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22C55E;
  animation: pulse 2.4s ease infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
  50%      { box-shadow: 0 0 0 6px rgba(34,197,94,.08); }
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.20);
  background: rgba(255,255,255,.10);
  color: rgba(255,255,255,.80);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.20); color: #fff; }

/* ── Layout ───────────────────────────────────────────────────────────── */
.chat-container {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
}

/* ── Messages ─────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Message row ──────────────────────────────────────────────────────── */
.message {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: fadeUp .22s ease-out both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message.bot  { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

/* ── Avatar ───────────────────────────────────────────────────────────── */
.avatar {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
  flex-shrink: 0; margin-top: 2px;
}
.message.bot  .avatar { background: var(--navy); color: var(--gold); }
.message.user .avatar { background: var(--gold); color: var(--navy); }

/* ── Bubble ───────────────────────────────────────────────────────────── */
.msg-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
  position: relative;
}
.message.bot  .bubble {
  background: var(--surface);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow);
  color: var(--text);
}
.message.user .bubble {
  background: var(--user-bg);
  border-top-right-radius: 4px;
  color: #fff;
}
.bubble.error { background: var(--error-bg); color: var(--error-txt); }

/* ── Markdown styles inside bubble ───────────────────────────────────── */
.bubble h2   { font-size: 15px; font-weight: 700; margin: 14px 0 6px; color: var(--navy); }
.bubble h3   { font-size: 14.5px; font-weight: 700; margin: 12px 0 5px; color: var(--navy); }
.bubble h4   { font-size: 14px; font-weight: 600; margin: 10px 0 4px; color: var(--navy-light); }

/* Ordered list — explicit decimal keeps counter even after UL interruptions */
.bubble ol {
  list-style-type: decimal;
  padding-left: 22px;
  margin: 8px 0;
}
/* Unordered list — explicit disc */
.bubble ul {
  list-style-type: disc;
  padding-left: 22px;
  margin: 8px 0;
}
.bubble li { margin: 5px 0; line-height: 1.6; }

.bubble strong { font-weight: 700; }
.bubble em   { font-style: italic; }
.bubble code {
  background: #EEF1F8; border-radius: 4px;
  padding: 2px 6px; font-family: ui-monospace, monospace; font-size: 13px;
  border: 1px solid var(--border);
}
.bubble pre  {
  background: var(--code-bg); color: var(--code-txt);
  border-radius: 10px; padding: 12px 16px;
  overflow-x: auto; margin: 10px 0; font-size: 13px; line-height: 1.5;
}
/* Inline links inside answers */
.bubble a {
  color: #1155CC;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  word-break: break-word;
  transition: color .15s;
}
.bubble a:hover {
  color: #0B3D91;
  text-decoration-thickness: 2px;
}
.message.user .bubble a { color: var(--gold-light); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.message.user .bubble strong { color: #fff; }
.message.user .bubble code   { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.2); }
.message.user .bubble a      { color: var(--gold-light); }

/* ── Feature 6: Citation superscripts ────────────────────────────────── */
sup.cite {
  font-size: 10px;
  font-weight: 700;
  color: var(--navy);
  background: #dde8f7;
  border-radius: 3px;
  padding: 0 3px;
  margin-left: 2px;
  vertical-align: super;
  line-height: 1;
  cursor: default;
}
.message.user sup.cite { color: var(--gold); background: rgba(255,255,255,.2); }

/* ── Feature 7: Markdown tables ───────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
}
.md-table th {
  background: var(--navy);
  color: #fff;
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  white-space: nowrap;
}
.md-table td {
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}
.md-table tr:nth-child(even) td { background: #f5f7fc; }
.md-table tr:hover td { background: #eef1f8; }

/* ── Streaming cursor ─────────────────────────────────────────────────── */
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.stream-cursor::after {
  content: "▌";
  color: var(--navy);
  animation: blink 0.8s step-end infinite;
  font-weight: 300;
}

/* ── Timestamp + copy row ─────────────────────────────────────────────── */
.msg-meta {
  display: flex; align-items: center; gap: 8px;
  opacity: 0;
  transition: opacity .2s;
}
.message:hover .msg-meta { opacity: 1; }
.timestamp { font-size: 11px; color: var(--text-light); }
.copy-btn {
  font-size: 11px; color: var(--text-light);
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 3px;
  padding: 2px 6px; border-radius: 4px;
  transition: background .15s, color .15s;
}
.copy-btn:hover { background: var(--border); color: var(--text); }
.copy-btn.copied { color: #16A34A; }

/* ── Sources ──────────────────────────────────────────────────────────── */
/* When empty (before stream ends) take no space at all */
.sources:empty { display: none; }

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;   /* space between bubble text and pills */
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
/* Label above the pills */
.sources::before {
  content: "Sources";
  display: block;
  width: 100%;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--text-light);
  text-transform: uppercase;
  margin-bottom: 2px;
}
.source-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--source-bg);
  color: var(--source-txt);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px 4px 9px;
  border-radius: 99px;
  text-decoration: none;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid #c3d8f0;
  transition: background .15s, border-color .15s, transform .1s;
}
.source-pill:hover {
  background: #c4d7f3;
  border-color: #93b8e0;
  transform: translateY(-1px);
}
.source-pill svg { flex-shrink: 0; opacity: .7; }
.source-num {
  font-size: 10px;
  font-weight: 700;
  color: var(--navy);
  background: #c3d8f0;
  border-radius: 3px;
  padding: 0 4px;
  margin-right: 4px;
  flex-shrink: 0;
}

/* ── Typing indicator ─────────────────────────────────────────────────── */
.typing-indicator {
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border-top-left-radius: 4px;
  display: flex; align-items: center; gap: 5px;
  box-shadow: var(--shadow);
}
.typing-indicator span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-light);
  animation: bounce 1.3s ease infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .18s; }
.typing-indicator span:nth-child(3) { animation-delay: .36s; }
@keyframes bounce {
  0%,60%,100% { transform: translateY(0); }
  30%          { transform: translateY(-7px); }
}

/* ── Suggestion chips (after bot answers) ─────────────────────────────── */
.suggestions {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 2px 0 0 42px;
  animation: fadeUp .3s ease both;
}
.suggestion-chip {
  background: var(--suggestion-bg);
  color: var(--suggestion-txt);
  border: 1.5px solid #BFDBFE;
  border-radius: 99px;
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.suggestion-chip:hover {
  background: #DBEAFE; border-color: #93C5FD; transform: translateY(-1px);
}

/* ── Quick-action chips ───────────────────────────────────────────────── */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 20px 10px;
}
.chip-label { font-size: 12px; color: var(--text-light); flex-basis: 100%; }
.chip {
  background: var(--surface);
  color: var(--navy);
  border: 1.5px solid var(--border);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
  white-space: nowrap;
}
.chip:hover { background: var(--navy); color: #fff; border-color: var(--navy); transform: translateY(-1px); }

/* ── Input area ───────────────────────────────────────────────────────── */
.input-area {
  padding: 10px 20px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color .2s;
}
.input-wrapper:focus-within { border-color: var(--navy); }
.user-input {
  flex: 1;
  background: transparent; border: none; outline: none;
  font-size: 14.5px; line-height: 1.55;
  resize: none; max-height: 150px; overflow-y: auto;
  font-family: inherit; color: var(--text);
}
.user-input::placeholder { color: var(--text-light); }
.send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--navy); color: #fff;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s, opacity .15s;
}
.send-btn:enabled:hover  { background: var(--navy-dark); }
.send-btn:active         { transform: scale(.93); }
.send-btn:disabled       { opacity: .45; cursor: not-allowed; }
.input-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; padding: 0 2px;
}
.disclaimer { font-size: 11.5px; color: var(--text-light); }
.disclaimer a { color: var(--navy); text-decoration: none; }
.disclaimer a:hover { text-decoration: underline; }
.char-count { font-size: 11.5px; color: var(--text-light); }
.char-count.warn { color: #D97706; }
.char-count.over { color: #DC2626; }

/* ── Session divider ──────────────────────────────────────────────────── */
.session-divider {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-light);
  padding: 4px 0 10px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ── Welcome card ─────────────────────────────────────────────────────── */
.welcome-card {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: #fff; border-radius: 16px;
  padding: 20px 24px;
  margin-bottom: 4px;
  box-shadow: var(--shadow);
}
.welcome-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.welcome-card p  { font-size: 14px; color: rgba(255,255,255,.80); line-height: 1.55; }

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  :root { --header-h: 58px; }
  .message { max-width: 97%; }
  .logo-sub { display: none; }
  .header-inner { padding: 0 12px; }
  .messages { padding: 14px 12px 4px; }
  .quick-actions { padding: 6px 12px 8px; }
  .input-area { padding: 8px 12px 14px; }
  .suggestions { padding-left: 0; }
}
