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

body {
  font-family: 'Heebo', Helvetica, Arial, Lucida, sans-serif;
  background-color: #ffffff;
  color: #333;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  padding-top: 66px;
}

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  background-color: #ffffff;
  padding: 5px 20px;
  width: 100%;
  border-bottom: 1px solid #ccc;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  height: 66px;
}

.logo img {
  max-width: 380px;
  max-height: 54px;
  width: auto;
  height: auto;
}

/* ── Page body ── */
.page-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: #f5f8fc;
  border-right: 1px solid #c5d8e8;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 20px;
  gap: 0;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section {
  margin-bottom: 28px;
}

.sidebar h3 {
  color: #16479C;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #c5d8e8;
}

/* Quick topic buttons */
.quick-topics {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.quick-topics button {
  background: none;
  border: none;
  color: #333;
  font-family: 'Heebo', Helvetica, Arial, sans-serif;
  font-size: 0.92rem;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}
.quick-topics button:hover {
  background: #e6f0f7;
  color: #16479C;
}

/* Resource links */
.sidebar-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-links li a {
  display: block;
  color: #333;
  font-size: 0.92rem;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-links li a:hover {
  background: #e6f0f7;
  color: #16479C;
}

/* Clear button at bottom of sidebar */
.sidebar-bottom {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid #c5d8e8;
}

.clear-btn {
  background: none;
  border: none;
  color: #6B6868;
  font-family: 'Heebo', Helvetica, Arial, sans-serif;
  font-size: 0.88rem;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.clear-btn:hover {
  background: #fde8e8;
  color: #c0271f;
}

/* ── Chat panel ── */
.chat-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

.chat-header {
  padding: 22px 36px 18px;
  border-bottom: 1px solid #e0e8f0;
  background: #fff;
  flex-shrink: 0;
}

.chat-header h2 {
  color: #16479C;
  font-size: 1.75em;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.description {
  font-size: 1em;
  color: #6B6868;
  line-height: 1.5;
  text-align: center;
}

/* ── Messages ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 36px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.97rem;
  line-height: 1.65;
  word-break: break-word;
}

.message.user .message-bubble {
  background: #16479C;
  color: #fff;
  align-self: flex-end;
  max-width: 72%;
  border-bottom-right-radius: 3px;
}

.message.assistant .message-bubble {
  background: #e6f0f7;
  color: #333;
  align-self: flex-start;
  border-left: 3px solid #16479C;
  border-bottom-left-radius: 3px;
}

/* Markdown */
.message-bubble p { margin: 0 0 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { padding-left: 1.3em; margin: 6px 0; }
.message-bubble li { margin-bottom: 3px; }
.message-bubble code {
  background: rgba(0,0,0,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'Courier New', monospace;
}
.message-bubble strong { font-weight: 700; }
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  color: #16479C;
  margin: 10px 0 4px;
}

/* Streaming cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: #16479C;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Sources expander */
.sources-expander { align-self: flex-start; margin-top: 2px; }

.sources-toggle {
  background: none;
  border: 1px solid #16479C;
  color: #16479C;
  font-family: 'Heebo', Helvetica, Arial, sans-serif;
  font-size: 0.8rem;
  padding: 3px 12px;
  border-radius: 2em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sources-toggle:hover { background: #16479C; color: #fff; }

.sources-list {
  margin-top: 6px;
  padding: 10px 14px;
  background: #e6f0f7;
  border-left: 3px solid #16479C;
  border-radius: 0 6px 6px 0;
  font-size: 0.85rem;
  line-height: 1.6;
  display: none;
}
.sources-list.open { display: block; }
.sources-list li { margin: 2px 0 2px 14px; color: #333; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 13px 16px;
  background: #e6f0f7;
  border-left: 3px solid #16479C;
  border-radius: 8px;
  border-bottom-left-radius: 3px;
  align-self: flex-start;
  width: fit-content;
}
.typing-indicator span {
  width: 7px; height: 7px;
  background: #16479C;
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── Chat input ── */
.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 16px 36px 18px;
  border-top: 1px solid #e0e8f0;
  background: #fff;
  flex-shrink: 0;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid #16479C;
  border-radius: 5px;
  padding: 11px 14px;
  font-family: 'Heebo', Helvetica, Arial, sans-serif;
  font-size: 1em;
  line-height: 1.5;
  outline: none;
  max-height: 140px;
  overflow-y: auto;
  transition: box-shadow 0.2s;
  background: #fff;
  color: #333;
}
.chat-input-row textarea:focus {
  box-shadow: 0 0 0 2px rgba(22,71,156,0.2);
}
.chat-input-row textarea::placeholder { color: #aaa; }

#sendBtn {
  width: 44px;
  height: 44px;
  background: #16479C;
  border: none;
  border-radius: 2em;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
#sendBtn:hover { background: #0d2f6e; }
#sendBtn:active { transform: scale(0.94); }
#sendBtn:disabled { background: #a3b2bf; cursor: not-allowed; }

/* Mobile sidebar toggle (hidden on desktop) */
.sidebar-toggle { display: none; }

/* ── Footer ── */
.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px 20px;
  font-size: 0.82rem;
  color: #6B6868;
  border-top: 1px solid #ccc;
  background: #fff;
  flex-shrink: 0;
  gap: 4px;
}
.footer a { color: #16479C; text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ── Mobile ── */
@media (max-width: 768px) {
  body { overflow: auto; }

  .page-body { flex-direction: column; overflow: visible; }

  .sidebar {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid #c5d8e8;
    padding: 14px 16px;
    display: none;
  }
  .sidebar.open { display: flex; }

  .sidebar-toggle {
    display: block;
    background: #16479C;
    border: none;
    color: #fff;
    font-family: 'Heebo', Helvetica, Arial, sans-serif;
    font-size: 0.88rem;
    padding: 10px 16px;
    cursor: pointer;
    width: 100%;
    text-align: left;
  }

  .chat-panel { overflow: visible; }
  .chat-messages { max-height: 50vh; }
  .chat-input-row, .chat-header { padding-left: 16px; padding-right: 16px; }
  .chat-messages { padding: 16px; }

  .top-bar { padding: 5px 10px; }
  .logo img { max-height: 46px; max-width: 240px; }

  .message.user .message-bubble { max-width: 90%; }
}