/* AI Reconstruction Assistant — premium "liaison" chat widget (v2). Self-contained. */
.rbuf-ai {
  --rbuf-ai-action: #1f6fe5;
  --rbuf-ai-action-hover: #195ac0;
  --rbuf-ai-deep: #0f2747;
  --rbuf-ai-border: #d9e0ea;
  --rbuf-ai-bg: #ffffff;
  --rbuf-ai-slate: #eef2f7;
  --rbuf-ai-text: #1f2a37;
  --rbuf-ai-muted: #6b7686;
  --rbuf-ai-online: #22c55e;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9990;
  font-family: inherit;
}

/* ---- Launch button: agent avatar + name (premium pill) ------------------- */
.rbuf-ai__launch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  padding: 7px 18px 7px 7px;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  border-radius: 999px;
  background-color: #15396b !important;
  background-image: linear-gradient(135deg, #15396b 0%, #1f6fe5 100%) !important;
  color: #ffffff !important;
  opacity: 1 !important;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(15, 39, 71, 0.34), 0 2px 6px rgba(15, 39, 71, 0.18);
  transition: transform .18s ease, box-shadow .18s ease, filter .18s ease;
}
.rbuf-ai__launch:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 44px rgba(15, 39, 71, 0.42), 0 3px 8px rgba(15, 39, 71, 0.22);
  filter: brightness(1.05);
}
.rbuf-ai__launch:active { transform: translateY(0); }
.rbuf-ai__launch:focus-visible { outline: 3px solid rgba(31, 111, 229, 0.45); outline-offset: 2px; }

.rbuf-ai__launch-avatar {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
}
.rbuf-ai__launch-avatar img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 2px solid rgba(255, 255, 255, 0.7);
}
.rbuf-ai__dot {
  position: absolute;
  right: 0;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--rbuf-ai-online);
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: rbuf-ai-online 2.4s ease-out infinite;
}
@keyframes rbuf-ai-online {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.rbuf-ai__launch-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}
.rbuf-ai__launch-text { color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .01em; }
.rbuf-ai__launch-sub { color: rgba(255, 255, 255, 0.82); font-size: 11px; font-weight: 500; }

.rbuf-ai.is-open .rbuf-ai__launch { display: none; }

/* ---- Panel -------------------------------------------------------------- */
.rbuf-ai__panel {
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 32px));
  height: min(600px, calc(100vh - 120px));
  background: var(--rbuf-ai-bg);
  border: 1px solid var(--rbuf-ai-border);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(15, 39, 71, 0.32);
  overflow: hidden;
  animation: rbuf-ai-pop .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes rbuf-ai-pop {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}

/* Header with agent identity */
.rbuf-ai__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  background: linear-gradient(135deg, #0f2747 0%, #163a63 100%);
  color: #fff;
}
.rbuf-ai__agent { display: flex; align-items: center; gap: 11px; min-width: 0; }
.rbuf-ai__agent-avatar { position: relative; flex: none; width: 40px; height: 40px; }
.rbuf-ai__agent-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.35);
}
.rbuf-ai__agent-meta { min-width: 0; }
.rbuf-ai__title { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.2; }
.rbuf-ai__subtitle { margin: 1px 0 0; font-size: 11.5px; opacity: .85; line-height: 1.3; }
.rbuf-ai__status { color: #7ef0a6; font-weight: 600; }
.rbuf-ai__close {
  flex: none;
  display: inline-flex;
  padding: 6px;
  border: none;
  border-radius: 9px;
  background: rgba(255, 255, 255, .08);
  color: #fff;
  cursor: pointer;
  transition: background .15s ease;
}
.rbuf-ai__close:hover { background: rgba(255, 255, 255, .2); }

/* AI-10: transparency badge — answers come only from approved PHS documents. */
.rbuf-ai__trust {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #eef5ff;
  border-bottom: 1px solid var(--rbuf-ai-border);
  font-size: 11px;
  line-height: 1.35;
}
.rbuf-ai__trust-icon { flex: none; color: var(--rbuf-ai-action); }
.rbuf-ai__trust-text { color: var(--rbuf-ai-muted); }
.rbuf-ai__trust-text strong { color: var(--rbuf-ai-deep); font-weight: 700; }

/* AI-06: specialised assistant focus tabs (General / Procurement / Standards / Explorer).
   Single row, horizontally scrollable — never wraps or steals vertical space. */
.rbuf-ai__modes {
  flex: none;
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--rbuf-ai-border);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.rbuf-ai__modes::-webkit-scrollbar { display: none; }
.rbuf-ai__mode {
  flex: none;
  scroll-snap-align: start;
  padding: 6px 12px;
  border: 1px solid var(--rbuf-ai-border);
  border-radius: 999px;
  background-color: #fff !important;
  color: var(--rbuf-ai-muted) !important;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.rbuf-ai__mode:hover { color: var(--rbuf-ai-action) !important; border-color: var(--rbuf-ai-action); }
.rbuf-ai__mode.is-active {
  color: #fff !important;
  background-color: var(--rbuf-ai-deep) !important;
  border-color: var(--rbuf-ai-deep);
}
.rbuf-ai__mode:focus-visible { outline: 2px solid rgba(31, 111, 229, 0.45); outline-offset: 1px; }

/* Phones: keep the tab row compact and swipeable so it never eats the chat
   area or wraps onto a second line. Comfortable tap height is preserved. */
@media (max-width: 767.98px) {
  .rbuf-ai__modes {
    gap: 5px;
    padding: 7px 10px;
    padding-right: 16px; /* a sliver of trailing space hints at more tabs */
  }
  .rbuf-ai__mode {
    padding: 7px 12px;
    font-size: 11.5px;
  }
}

/* ---- Message log -------------------------------------------------------- */
.rbuf-ai__log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--rbuf-ai-slate);
}

.rbuf-ai__msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: rbuf-ai-in .25s ease both;
}
@keyframes rbuf-ai-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}
.rbuf-ai__msg--bot { align-self: flex-start; }
.rbuf-ai__msg--user { align-self: flex-end; }

.rbuf-ai__avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(15, 39, 71, 0.18);
}

.rbuf-ai__bubble {
  max-width: 100%;
  padding: 10px 13px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--rbuf-ai-border);
  box-shadow: 0 1px 2px rgba(15, 39, 71, 0.05);
}
.rbuf-ai__msg--bot .rbuf-ai__bubble { border-bottom-left-radius: 6px; }
.rbuf-ai__msg--user .rbuf-ai__bubble {
  background: var(--rbuf-ai-action);
  border-color: transparent;
  border-bottom-right-radius: 6px;
}
.rbuf-ai__bubble--error { background: #fef2f2; border-color: #fecaca; }

.rbuf-ai__name {
  display: block;
  margin-bottom: 3px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--rbuf-ai-deep);
}
.rbuf-ai__text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--rbuf-ai-text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.rbuf-ai__msg--user .rbuf-ai__text { color: #fff; }
.rbuf-ai__bubble--error .rbuf-ai__text { color: #991b1b; }

/* Markdown inside answers */
.rbuf-ai__text p { margin: 0; }
.rbuf-ai__text p + p { margin-top: 8px; }
.rbuf-ai__text ul,
.rbuf-ai__text ol { margin: 6px 0; padding-left: 20px; }
.rbuf-ai__text li { margin: 3px 0; }
.rbuf-ai__text h4,
.rbuf-ai__text h5,
.rbuf-ai__text h6 { margin: 10px 0 4px; font-size: 13.5px; font-weight: 700; color: var(--rbuf-ai-deep); }
.rbuf-ai__text strong { font-weight: 700; }
.rbuf-ai__text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--rbuf-ai-slate);
  padding: 1px 5px;
  border-radius: 5px;
}
.rbuf-ai__text a { color: var(--rbuf-ai-action); text-decoration: underline; }
.rbuf-ai__msg--user .rbuf-ai__text a { color: #fff; }

/* Typewriter caret */
.rbuf-ai__text.is-typing::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  vertical-align: -2px;
  background: var(--rbuf-ai-action);
  animation: rbuf-ai-caret .9s steps(1) infinite;
}
@keyframes rbuf-ai-caret { 50% { opacity: 0; } }

/* Answer action bar (copy / rate) */
.rbuf-ai__actions { display: flex; gap: 5px; margin-top: 9px; }
.rbuf-ai__act {
  width: 27px;
  height: 27px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rbuf-ai-border);
  border-radius: 8px;
  background-color: #fff !important;
  color: var(--rbuf-ai-muted);
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.rbuf-ai__act:hover { color: var(--rbuf-ai-action); border-color: var(--rbuf-ai-action); }
.rbuf-ai__act.is-active { color: #fff !important; background-color: var(--rbuf-ai-action) !important; border-color: var(--rbuf-ai-action); }
.rbuf-ai__act.is-done { color: #16a34a !important; border-color: #16a34a; }

/* AI-03: "Sources" block (document + version) from the Document Centre. */
.rbuf-ai__sources {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--rbuf-ai-border);
}
.rbuf-ai__sources-title {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--rbuf-ai-muted);
}
.rbuf-ai__sources-list { margin: 0; padding: 0; list-style: none; }
.rbuf-ai__source {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12.5px;
  line-height: 1.4;
  padding: 2px 0;
}
.rbuf-ai__source-link { color: var(--rbuf-ai-action); text-decoration: underline; }
.rbuf-ai__source-link:hover { color: var(--rbuf-ai-action-hover); }
.rbuf-ai__source-version {
  flex: none;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--rbuf-ai-muted);
  letter-spacing: .02em;
}
.rbuf-ai__source-status {
  flex: none;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--rbuf-ai-slate);
  color: var(--rbuf-ai-muted);
  font-size: 10.5px;
  font-weight: 600;
}

/* MAP-06 — quick platform links (map, profiles, Document Centre). */
.rbuf-ai__map-actions {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--rbuf-ai-border);
}
.rbuf-ai__map-actions-title {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--rbuf-ai-muted);
}
.rbuf-ai__map-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.rbuf-ai__map-action {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border: 1px solid var(--rbuf-ai-border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--rbuf-ai-action);
  text-decoration: none;
  background: #f8fafc;
  transition: background-color .15s ease, border-color .15s ease;
}
.rbuf-ai__map-action:hover {
  background: #eef4ff;
  border-color: var(--rbuf-ai-action);
  text-decoration: none;
}

/* Suggestion chips (welcome) — aligned under the bubble */
.rbuf-ai__suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding-left: 40px; }
.rbuf-ai__chip {
  padding: 8px 12px;
  border: 1px solid var(--rbuf-ai-border);
  border-radius: 999px;
  background-color: #ffffff !important;
  color: #0f2747 !important;
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.rbuf-ai__chip:hover { border-color: var(--rbuf-ai-action); box-shadow: 0 2px 8px rgba(31, 111, 229, 0.14); }

/* Thinking / typing wait states (human pacing before the answer). */
.rbuf-ai__phase { display: inline-block; font-size: 13.5px; color: var(--rbuf-ai-muted); }
.rbuf-ai__phase--think {
  animation: rbuf-ai-think 1.4s ease-in-out infinite;
}
@keyframes rbuf-ai-think {
  0%, 100% { opacity: .45; }
  50% { opacity: 1; }
}

/* Typing indicator */
.rbuf-ai__typing { display: inline-flex; gap: 4px; padding: 2px 0; }
.rbuf-ai__typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9aa7b8; animation: rbuf-ai-bounce 1.2s infinite ease-in-out;
}
.rbuf-ai__typing span:nth-child(2) { animation-delay: .15s; }
.rbuf-ai__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes rbuf-ai-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---- Input form --------------------------------------------------------- */
.rbuf-ai__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--rbuf-ai-border);
  background: #fff;
}
.rbuf-ai__input {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 13px;
  border: 1px solid var(--rbuf-ai-border);
  border-radius: 13px;
  /* 16px prevents iOS Safari from auto-zooming the page on focus. */
  font-size: 16px;
  line-height: 1.35;
  font-family: inherit;
  color: var(--rbuf-ai-text);
}
.rbuf-ai__input:focus { outline: 2px solid var(--rbuf-ai-action); outline-offset: 0; border-color: transparent; }
.rbuf-ai__send {
  flex: none;
  display: inline-flex;
  padding: 11px;
  border: none;
  border-radius: 13px;
  background-color: #1f6fe5 !important;
  color: #ffffff !important;
  opacity: 1;
  cursor: pointer;
  transition: background-color .15s ease;
}
.rbuf-ai__send:hover { background-color: #195ac0 !important; }
.rbuf-ai__send:disabled { opacity: .5; cursor: not-allowed; }

.rbuf-ai__disclaimer {
  margin: 0;
  padding: 8px 14px 12px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--rbuf-ai-muted);
  background: #fff;
  border-top: 1px solid var(--rbuf-ai-slate);
}

.rbuf-ai__sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Background scroll lock while the mobile sheet is open. */
html.rbuf-ai-lock,
html.rbuf-ai-lock body {
  overflow: hidden;
  overscroll-behavior: none;
}

/* While the phone sheet is open, hide every page section behind it and paint
   the document white. On iOS the on-screen keyboard reserves a strip (the
   autofill/QuickType bar) where a fixed overlay cannot reach, so the only
   browser-proof way to stop the site showing through that strip is to make the
   underlying page itself invisible — leaving solid white there. */
@media (max-width: 767.98px) {
  html.rbuf-ai-lock,
  html.rbuf-ai-lock body {
    background: #ffffff !important;
  }
  html.rbuf-ai-lock body > *:not(.rbuf-ai) {
    visibility: hidden !important;
  }
}

/* Mobile: below the nav breakpoint the launcher becomes the agent's avatar. */
@media (max-width: 1023.98px) {
  .rbuf-ai { right: 16px; bottom: 16px; }
  .rbuf-ai__launch {
    padding: 0;
    gap: 0;
    border-radius: 50%;
    background-image: none !important;
    background-color: transparent !important;
    border-color: transparent !important;
    box-shadow: 0 10px 26px rgba(15, 39, 71, 0.4);
  }
  .rbuf-ai__launch-copy { display: none; }
  .rbuf-ai__launch-avatar,
  .rbuf-ai__launch-avatar img { width: 56px; height: 56px; }
  .rbuf-ai__launch-avatar img { border-color: #fff; }
  .rbuf-ai__dot { width: 13px; height: 13px; bottom: 2px; right: 2px; }
}

/* Phones: full-screen sheet. JS sets exact top/height from VisualViewport so
   the on-screen keyboard never pushes the input off-screen. */
@media (max-width: 767.98px) {
  .rbuf-ai.is-sheet {
    position: fixed;
    inset: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    min-height: 100vh;
    background: var(--rbuf-ai-bg);
  }
  .rbuf-ai.is-sheet .rbuf-ai__panel {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    animation: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rbuf-ai__launch, .rbuf-ai__typing span, .rbuf-ai__msg, .rbuf-ai__panel, .rbuf-ai__dot { transition: none; animation: none; }
  .rbuf-ai__text.is-typing::after { animation: none; }
}
