/* === Base === */
:root {
  /* Bubble / action styling (match your manual-decision-button look) */
  --action-bg: #f5f7ff;
  --action-text: #1c2a4b;
  --action-border: #cfd7ff;
  --action-radius: 14px;
  --shadow-sm: 0 2px 6px rgba(0,0,0,0.08);

  /* layout helpers (JS updates --input-bar-h dynamically) */
  --input-bar-h: 72px;    /* fallback */
  --scroll-btn-gap: 12px; /* gap above input for the floating button */
}

* { box-sizing: border-box; }

body {
  background: #fff;
  font-family: 'Segoe UI', sans-serif;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === App Layout === */
#chat-container {
  position: relative;  /* anchor for the floating button */
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;    /* prevent overscroll glow */
}

/* wrapper for scroller (messages) */
#chat-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;       /* critical so the child scroller can shrink */
}

/* === Scrollable chat area === */
#chat-output {
  position: relative;
  overflow-y: auto;
  /* start collapsed; fade/expand when .expanded is added */
  max-height: 0;
  opacity: 0;
  transition: max-height 0.6s ease, opacity 0.6s ease;
  padding: 0 1rem;
  /* keep last lines visible above input bar */
  padding-bottom: calc(var(--input-bar-h) + 24px);
  overflow-anchor: none; 
  overscroll-behavior: auto;
}

#chat-output.expanded {
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
  opacity: 1;
  padding-top: 1rem;
}

.reply-spacer { 
  display:block; 
}

/* invisible tail spacer; just reserves height, never blocks clicks */
.reserve-tail {
  opacity: 0;
  pointer-events: none;
  display: block;
}

/* Messages */
.message {
  margin: 1rem 0;
  white-space: pre-wrap;
  line-height: 1.5;
  color: #222;
}
.user { text-align: right; font-weight: bold; }
.assistant { text-align: left; }

/* Info text (optional hint above input) */
.info-text {
  background: #fff;
  color: #555;
  text-align: center;
  margin: 1vh 0 1.5vh;
  border-radius: 0;
  font-size: 0.9rem;
}

/* === Input Bar === */
#input-area {
  background: #fff;
  box-shadow: 0 -1px 5px rgba(0,0,0,0.05);
  z-index: 1;
  padding: 0.75rem 1rem;
}

#input-box {
  display: flex;
  align-items: flex-end;          /* align input & button baseline */
  background: rgb(248,248,248);
  border: 1px solid #ccc;
  border-radius: 2rem;
  padding: 0.5rem 1rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

#messageInput {
  flex: 1 1 auto;
  border: none;
  outline: none;
  resize: none;
  min-height: 10vh;
  font-size: 0.95rem;
  background: transparent;
  padding: 0.5rem;
  color: rgb(48,48,48) !important;
  -webkit-text-fill-color: rgb(48,48,48) !important;
}

#send-button-wrapper,
.send-button-wrapper {
  display: flex;
  align-items: flex-end;
  padding-left: 0.5rem;
  padding-bottom: 0.25rem;
}

#sendButton {
  background-color: rgb(63,63,63);
  border: none;
  border-radius: 50%;
  width: 2.5rem; height: 2.5rem;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  padding: 0;
  position: relative;
}
#sendButton:hover { background-color: rgb(163,163,163); }

.send-icon svg {
  width: 22px; height: 22px;
  stroke: #fff; fill: none;
  display: block;
  margin-top: 2px;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Topic & Choices Buttons === */
.topic-buttons {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  margin: 4vh 4vw 1rem;
  align-items: center; justify-content: center;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}
@media (max-width: 600px) {
  .topic-buttons { justify-content: flex-start; }
}

#topic-buttons.collapsed { max-height: 0; opacity: 0; overflow: hidden; }

.topic-buttons button,
.choices-buttons button {
  background: #e7e7e7;
  border: none;
  padding: 6px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: bold;
  font-size: 15px;
}
.topic-buttons button:hover,
.choices-buttons button:hover { background: #cfcfcf; }

.choices-buttons {
  display: flex; gap: 0.5rem; flex-wrap: wrap;
  margin: 5vh 1rem 1rem;
  justify-content: center;
}
.choices-buttons button.selected {
  background-color: #8d8d8d !important;
  border: 1px solid #cfcfcf;
}

/* === RAG explanation box (optional) === */
.rag-box {
  background-color: #e6f0ff;
  padding: 12px;
  border-radius: 6px;
  margin-top: 10px;
  line-height: 1.4;
}

/* === User Question Bubble (right-aligned) === */
.user-question-bubble {
  background: var(--action-bg);
  color: var(--action-text);
  border: 1px solid var(--action-border);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  padding: 10px 14px;
  max-width: min(75%, 680px);
  margin: 10px 8px 16px auto;  /* right aligned */
  line-height: 1.35;
  word-wrap: break-word;
}

.user-question-meta {
  font-size: 12px;
  color: #6b7280;
  text-align: right;
  margin: -10px 8px 12px auto;
  max-width: min(75%, 680px);
}

/* === “Scroll to end” floating button (circular, centered) ===
   Lives inside #chat-container (NOT inside the scroller) */
.scroll-to-end {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--input-bar-h) + var(--scroll-btn-gap));
  width: 44px; height: 44px;
  border-radius: 50%;
  display: none; /* toggled by JS */
  align-items: center; justify-content: center;
  /* background: #fff; */
  background-color: rgba(255, 255, 255, 0.5);
  /* backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px); 
  /* border-color: rgba(0, 0, 0, 0.08); */
  border: 1px solid #e5e7eb;
  box-shadow: 0 8px 22px rgba(0,0,0,0.14);
  cursor: pointer;
  z-index: 5; /* above input bar */
}

.scroll-to-end svg { 
  width: 22px; 
  height: 22px;
  margin-top: 4px;
  /* transform: translateY(2px); */
}
.scroll-to-end:hover { filter: brightness(0.98); }
.scroll-to-end:focus { outline: 2px solid #c7d2fe; outline-offset: 2px; }

/* === Intro / Restart === */
#intro-wrapper {
  transition: max-height 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}
#intro-wrapper.collapsed { max-height: 0; opacity: 0; }

#restart-area {
  text-align: center;
  padding: 1rem 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#restart-area.visible { opacity: 1; }

#restartButton {
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  font-weight: bold;
  background-color: #e1e1e1;
  color: #fff;
  border: none;
  border-radius: 1.5rem;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(0,0,0,0.1);
  transition: background-color 0.2s ease;
}
#restartButton:hover { background-color: #adadad; }

/* === Optional: unify manual decision button look with bubbles === */
.manual-decision-button {
  background: var(--action-bg);
  color: var(--action-text);
  border: 1px solid var(--action-border);
  border-radius: var(--action-radius);
}

/* Instructions copy tidy */
#instructions {
  font-size: 0.9rem;
  color: #000;
  margin: 10px 0;
  padding: 0 10px;
  text-align: center;
  transition: opacity 1s ease;
}
#instructions.fade { opacity: 0; }

