:root {
  --ink: #1c2430;
  --ink-soft: #5b6675;
  --paper: #ffffff;
  --bg: #f4f5f7;
  --border: #dde1e7;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --refusal-bg: #fdf1ee;
  --refusal-ink: #9a3b1f;
  --answered-bg: #eef6f0;
  --answered-ink: #235c3d;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

/* Chat-harness shell (C-9 / UAT-6): the page itself never scrolls. The header
   and the ask bar are pinned by being fixed-size flex items in a viewport-tall
   column; only the transcript between them scrolls. Before this, the whole
   document scrolled, so a long conversation pushed the input off-screen. */
html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* The shell sets display on elements the markup toggles with the `hidden`
   attribute, which would otherwise beat the UA's [hidden] { display: none }.
   Without this the login form and the chat pane render at the same time. */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-header {
  flex: 0 0 auto; /* pinned: never scrolls with the conversation */
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.app-subtitle {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.app-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

main {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
  /* Takes the remaining column height. min-height:0 is what lets a nested
     overflow container actually shrink instead of stretching the flex item. */
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#login-section {
  max-width: 360px;
  margin: 3rem auto;
  overflow-y: auto; /* logged out there is no transcript; keep it reachable */
}

#chat-section {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

/* C-11: the OIDC sign-in affordances. Same card shape as .login-form so the
   two postures look like one product — never both on screen at once. */
.oidc-signin {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.signin-lede {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.provider-button {
  display: block;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
  text-decoration: none;
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
}

.provider-button:hover {
  border-color: var(--ink-soft);
}

.login-form label {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.login-form input {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.95rem;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-text {
  color: var(--refusal-ink);
  font-size: 0.85rem;
  min-height: 1.1em;
  margin: 0;
}

.chat-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  grid-template-rows: minmax(0, 1fr);
  gap: 1.5rem;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0; /* lets .conversation scroll rather than push the ask bar down */
  position: relative; /* anchor for the floating "new response" affordance */
}

/* UAT-9: shown only when a response arrives while the reader has scrolled up.
   Floats just above the pinned ask bar; clicking it jumps to the newest turn. */
.new-response {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 4.5rem;
  z-index: 2;
  font-size: 0.8rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

@media (max-width: 720px) {
  .chat-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  /* Narrow screens stack the sidebar under the transcript; cap it so the
     recent-queries list can't crowd out the conversation. */
  .chat-sidebar {
    max-height: 30vh;
  }
}

.conversation {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  margin-bottom: 1rem;
  /* The ONLY scrolling region in the shell. */
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.turn {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  background: var(--paper);
  border: 1px solid var(--border);
}

.turn-user {
  background: #eef2fb;
  border-color: #d7e0f5;
}

.turn-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  margin-bottom: 0.25rem;
}

.turn-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.answer-text {
  margin-top: 0.5rem;
}

.disposition-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.disposition-badge.is-answered {
  background: var(--answered-bg);
  color: var(--answered-ink);
}

.disposition-badge.is-refusal {
  background: var(--refusal-bg);
  color: var(--refusal-ink);
}

.disposition-badge.small {
  font-size: 0.7rem;
}

.citation-list {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.citation {
  font-size: 0.8rem;
  color: var(--ink-soft);
  word-break: break-word;
}

.citation-system {
  font-weight: 600;
}

.ask-form {
  flex: 0 0 auto; /* pinned at the bottom of the chat column */
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--bg);
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.ask-form textarea {
  flex: 1;
  resize: vertical;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

.chat-sidebar {
  min-height: 0;
  overflow-y: auto; /* scrolls independently; never pushes the shell taller */
}

.chat-sidebar h2 {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin: 0 0 0.5rem;
}

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

.recent-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font-size: 0.85rem;
}

.recent-query-text {
  word-break: break-word;
}

.recent-empty {
  color: var(--ink-soft);
  font-size: 0.85rem;
}
