:root {
  --accent-color: #2563eb;
  --neutral-bg: #f1f5f9;
  --refusal-bg: #e5e7eb;
  --text-color: #1e293b;
  --error-color: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text-color);
  background: #fff;
}

.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Wraps the loading shell (progress popup + disabled input) whether it's
   nested inside #app on full page load, or swapped in as a direct child of
   #app after a corpus pick / share link / gate form submit. Mirrors #app's
   own flex layout so the message-history/chat-form children keep filling
   the full height instead of collapsing to content size, see
   00_bsn_req_0011_quick_conversation_load. */
.conversation-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.message-history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bubble {
  max-width: 70%;
  padding: 0.6rem 0.9rem;
  border-radius: 1rem;
  line-height: 1.4;
}

.bubble-text {
  margin: 0;
  white-space: pre-wrap;
}

.bubble-user {
  align-self: flex-end;
  background: var(--accent-color);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.bubble-bot {
  align-self: flex-start;
  background: var(--neutral-bg);
  color: var(--text-color);
  border-bottom-left-radius: 0.25rem;
}

.bubble-refusal {
  background: var(--refusal-bg);
  color: #4b5563;
}

.bubble-sources {
  margin-top: 0.4rem;
  font-size: 0.85rem;
}

.bubble-agent-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
}

.agent-icon,
.corpus-icon {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  object-fit: cover;
}

.corpus-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}

.chat-form {
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid #e2e8f0;
}

.chat-form input[type="text"],
.gate-form input[type="text"] {
  padding: 0.6rem 0.8rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  font-size: 1rem;
}

.chat-form input[type="text"] {
  flex: 1;
}

.chat-form textarea,
.gate-form textarea {
  padding: 0.6rem 0.8rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

.gate-form input[type="text"],
.gate-form textarea {
  width: 100%;
  box-sizing: border-box;
}

.chat-form button {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--accent-color);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.form-button-block {
  display: block;
  width: 100%;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 0.5rem;
  background: var(--accent-color);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.chat-form button:disabled,
.chat-form input:disabled,
.chat-form textarea:disabled,
.gate-form input:disabled,
.gate-form textarea:disabled,
.form-button-block:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.corpus-picker {
  margin: auto;
  text-align: center;
}

.gate-form {
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 24rem;
  padding: 1rem;
}

.corpus-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.corpus-option {
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--accent-color);
  border-radius: 0.5rem;
  background: #fff;
  color: var(--accent-color);
  font-size: 1rem;
  cursor: pointer;
}

.corpus-option:hover {
  background: var(--accent-color);
  color: #fff;
}

.empty-state {
  margin: auto;
  color: #64748b;
  text-align: center;
}

.chat-error {
  padding: 0.5rem 1rem;
  color: var(--error-color);
  font-size: 0.9rem;
}

.htmx-indicator {
  opacity: 0;
  transition: opacity 150ms ease-in;
}

.htmx-indicator.htmx-request {
  opacity: 1;
}

/* Thinking indicator: appended by chat.js as the last item inside
   .message-history while a response is pending, so it scrolls with the
   conversation like any other bubble and is removed once the response
   bubble replaces it, see 20_frt_cmp_0003_thinking_bubble. */
.thinking-bar {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  border-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
  background: var(--neutral-bg);
  color: #64748b;
}

.thinking-dots {
  display: flex;
  gap: 0.2rem;
}

.thinking-dots span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: #94a3b8;
  animation: thinking-bounce 1s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

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

.thinking-text {
  margin: 0;
  color: #64748b;
  font-style: italic;
  font-size: 0.9rem;
}

/* Progress popup: overlay shown centered over the (empty) history area while
   an existing conversation's messages load asynchronously, see
   00_bsn_req_0011_quick_conversation_load / 20_frt_cmp_0004_progress_popup. */
.progress-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.progress-spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 2px solid var(--neutral-bg);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: progress-spin 0.7s linear infinite;
}

.progress-text {
  margin: 0;
  color: #64748b;
  font-size: 0.9rem;
}

@keyframes progress-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Top bar: fixed, right-aligned row holding info button, contact button, and
   lang toggle, see 20_frt_cmp_0007_top_bar. Carries the z-index that used to
   live on .lang-toggle alone, so every child inherits stacking above both
   .summary-overlay / .contact-overlay (z-index: 20) — this keeps the lang
   toggle reachable while either overlay is open, see 20_frt_pop_0001_summary
   / 20_frt_pop_0002_contact_data "Language toggle stays active". */
.top-bar {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lang-toggle {
  display: flex;
  gap: 0.25rem;
}

.lang-toggle button {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--accent-color);
  border-radius: 0.4rem;
  background: #fff;
  color: var(--accent-color);
  font-size: 0.8rem;
  cursor: pointer;
}

.lang-toggle button.lang-active {
  background: var(--accent-color);
  color: #fff;
}

/* Info + contact buttons: plain round icon buttons, positioned by the
   .top-bar flex row (no position: fixed of their own), see
   20_frt_cmp_0005_info_button / 20_frt_cmp_0008_contact_button. */
.info-button,
.contact-button {
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--accent-color);
  border-radius: 50%;
  background: #fff;
  color: var(--accent-color);
  font-size: 0.9rem;
  font-weight: 700;
  font-style: italic;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.info-button:hover,
.contact-button:hover {
  background: var(--accent-color);
  color: #fff;
}

.contact-button::before {
  content: "\260E";
  font-style: normal;
}

/* Summary popup: static "about" content, see 20_frt_pop_0001_summary.
   Overlay sits above all page content but below .top-bar (z-index 30 above),
   so the language toggle stays clickable while the popup is open. */
.summary-overlay,
.contact-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease;
}

.summary-overlay[hidden],
.contact-overlay[hidden] {
  display: none;
}

.summary-overlay.open,
.contact-overlay.open {
  opacity: 1;
  visibility: visible;
}

.summary-popup,
.contact-popup {
  position: relative;
  z-index: 21;
  background: #fff;
  border-radius: 1rem;
  padding: 1.5rem;
  width: min(90vw, 40rem);
  max-height: 85vh;
  /* Popup itself never scrolls — only .summary-bottom does, below — so
     .summary-close (position: absolute against this element) stays pinned
     top-right no matter how long the bottom block's content gets, see
     20_frt_pop_0001_summary "Layout" / pln_0007. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3);
  transform: scale(0.1);
  transform-origin: 2.5% 2.5%;
  opacity: 0;
  transition: transform 220ms ease, opacity 220ms ease;
}

.summary-overlay.open .summary-popup,
.contact-overlay.open .contact-popup {
  transform: scale(1);
  opacity: 1;
}

.summary-close,
.contact-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 50%;
  background: #fff;
  color: var(--text-color);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.summary-close:hover,
.contact-close:hover {
  background: var(--neutral-bg);
}

/* Contact popup two-column layout: headshot left, name/bio/experience/
   LinkedIn right, see 20_frt_pop_0002_contact_data "Layout". */
.contact-top {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 1.25rem;
  align-items: start;
}

.contact-image img {
  width: 8rem;
  height: 8rem;
  border-radius: 0.75rem;
  object-fit: cover;
  aspect-ratio: 1 / 1;
}

.contact-info-name {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
}

.contact-info-bio,
.contact-info-experience {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
  color: var(--text-color);
}

.contact-info-linkedin {
  display: inline-block;
  font-size: 0.9rem;
  color: var(--accent-color);
}

.summary-bottom {
  /* No .summary-top above it anymore — nothing to separate from, see
     20_frt_pop_0001_summary "Layout" / pln_0008. This is the only
     scrollable region in the popup, see .summary-popup. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.summary-bottom h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

.summary-bottom p {
  margin: 0 0 0.6rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

@media (max-width: 32rem) {
  .contact-top {
    grid-template-columns: 1fr;
  }

  .contact-image img {
    width: 6rem;
    height: 6rem;
  }
}
