/* Refera Assistant widget - floating button + panel.
   Zero dependencies. Uses the brand green var with a safe fallback.
   Administrative process-state only - Refera performs no clinical triage. */

#ra-root {
  --ra-green: var(--green, #15803D);
  --ra-ink: var(--ink, #111827);
  --ra-ink-2: var(--ink-2, #4B5563);
  --ra-ink-3: var(--ink-3-text, #6B7280);
  --ra-paper: var(--paper, #FAFAF8);
  --ra-surface: var(--surface, #FFFFFF);
  --ra-hair: var(--hair, #E8E6E1);
  --ra-wash: var(--green-wash, #F0FDF4);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ra-ink);
}
#ra-root *, #ra-root *::before, #ra-root *::after { box-sizing: border-box; }

/* ---- Launcher ---- */
#ra-launcher {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 480;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: var(--ra-green);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px rgba(21, 128, 61, .35), 0 2px 6px rgba(17, 24, 39, .12);
  transition: transform 160ms ease-out, box-shadow 160ms ease-out;
}
#ra-launcher:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(21, 128, 61, .4); }
#ra-launcher:active { transform: translateY(0); }
#ra-launcher:focus-visible { outline: 2px solid var(--ra-green); outline-offset: 3px; }
#ra-launcher svg { width: 26px; height: 26px; }
#ra-root.ra-lift #ra-launcher { bottom: 62px; } /* clear the fixed concept badge */
/* Support register (in the console): sit above the fixed bottom tab bar so the
   bubble never lands on the app nav. Uses the app's own layout vars. */
#ra-root.ra-support #ra-launcher {
  bottom: calc(var(--tabbar-h, 62px) + var(--safe-bottom, 0px) + var(--tabbar-gap, 12px) + 20px);
}
/* On desktop the tab bar is a centred pill, not full-width - nudge the launcher
   left of it as well so it clears the pill's right edge on narrow desktops. */
@media (min-width: 720px) {
  #ra-root.ra-support #ra-launcher { bottom: 24px; right: 24px; }
}
#ra-root.ra-open #ra-launcher { display: none; }

/* ---- Panel ---- */
#ra-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 490;
  width: 392px;
  max-width: calc(100vw - 36px);
  height: min(560px, calc(100vh - 48px));
  height: min(560px, calc(100dvh - 48px));
  display: none;
  flex-direction: column;
  background: var(--ra-paper);
  border: 1px solid var(--ra-hair);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(17, 24, 39, .16), 0 40px 80px -24px rgba(17, 24, 39, .28);
}
#ra-root.ra-open #ra-panel { display: flex; animation: ra-in 200ms cubic-bezier(.22, 1, .36, 1); }
@keyframes ra-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

#ra-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px 16px;
  background: var(--ra-surface);
  border-bottom: 1px solid var(--ra-hair);
}
#ra-head .ra-dot {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ra-green);
  color: #fff;
  display: grid;
  place-items: center;
}
#ra-head .ra-dot svg { width: 18px; height: 18px; }
#ra-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  font-family: 'Fraunces', Georgia, serif;
  letter-spacing: -.01em;
}
/* SUPPORT register: the demo-tenant badge beside the title */
#ra-head .ra-demo-badge {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 7px 2px;
  vertical-align: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .58rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #92400E;
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  border-radius: 999px;
}
#ra-head p {
  margin: 1px 0 0;
  font-size: .7rem;
  color: var(--ra-ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#ra-head .ra-id { min-width: 0; flex: 1; }
#ra-close {
  flex: none;
  width: 44px;
  height: 44px;
  margin: -5px -5px -5px 0;
  border: 0;
  background: none;
  color: var(--ra-ink-3);
  cursor: pointer;
  border-radius: 10px;
  display: grid;
  place-items: center;
}
#ra-close:hover { color: var(--ra-ink); background: var(--ra-paper); }
#ra-close:focus-visible { outline: 2px solid var(--ra-green); outline-offset: -2px; }
#ra-close svg { width: 16px; height: 16px; }

/* ---- Messages ---- */
#ra-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}
.ra-msg {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: .9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ra-msg.ra-user {
  align-self: flex-end;
  background: var(--ra-ink);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ra-msg.ra-bot {
  align-self: flex-start;
  background: var(--ra-surface);
  border: 1px solid var(--ra-hair);
  border-bottom-left-radius: 4px;
  color: var(--ra-ink);
}
.ra-msg.ra-note {
  align-self: flex-start;
  background: var(--ra-wash);
  border: 1px solid #CBEBD3;
  color: var(--ra-ink-2);
  font-size: .84rem;
}
.ra-sources {
  align-self: flex-start;
  max-width: 86%;
  margin-top: -4px;
  font-size: .74rem;
  color: var(--ra-ink-3);
  padding: 0 4px;
}

/* CTA chips under a reply (Sign up / Read the docs / Email me more info)
   and the greeting's starter questions. Tidy pills, brand green, 44px-tap
   friendly without shouting. */
.ra-actions {
  align-self: flex-start;
  max-width: 92%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px;
}
.ra-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 13px;
  font: 600 .78rem/1.2 'Inter', system-ui, sans-serif;
  color: var(--ra-green);
  background: var(--ra-wash);
  border: 1px solid #CBEBD3;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: background 140ms ease-out, border-color 140ms ease-out;
}
.ra-chip:hover { background: #E3F7EA; border-color: var(--ra-green); }
.ra-chip:focus-visible { outline: 2px solid var(--ra-green); outline-offset: 2px; }
.ra-sources a {
  color: var(--ra-green);
  text-decoration: none;
  font-weight: 600;
}
.ra-sources a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* Typing indicator - three pulsing dots, honest fallback for reduced motion */
.ra-typing { display: inline-flex; align-items: center; gap: 5px; padding: 13px; }
.ra-typing i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ra-ink-2);
  animation: ra-pulse 1.1s ease-in-out infinite;
}
.ra-typing i:nth-child(2) { animation-delay: .18s; }
.ra-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes ra-pulse { 0%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---- Input ---- */
#ra-form {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  background: var(--ra-surface);
  border-top: 1px solid var(--ra-hair);
}
#ra-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  /* 16px floor: iOS Safari force-zooms the page when a focused input is
     under 16px - the "widget zooms in on mobile" bug (Zura, 8 Jul). */
  font-size: 16px;
  color: var(--ra-ink);
  background: var(--ra-paper);
  border: 1px solid var(--ra-hair);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
}
#ra-input::placeholder { color: var(--ra-ink-3); }
#ra-input:focus {
  outline: none;
  border-color: var(--ra-green);
  box-shadow: 0 0 0 3px rgba(21, 128, 61, .14);
}
#ra-send {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: var(--ra-green);
  color: #fff;
  display: grid;
  place-items: center;
  transition: transform 140ms ease-out, opacity 140ms ease-out;
}
#ra-send:hover { transform: translateY(-1px); }
#ra-send:disabled { opacity: .45; cursor: default; transform: none; }
#ra-send:focus-visible { outline: 2px solid var(--ra-green); outline-offset: 2px; }
#ra-send svg { width: 18px; height: 18px; }

#ra-foot {
  flex: none;
  padding: 0 14px 10px;
  background: var(--ra-surface);
  font-size: .66rem;
  color: var(--ra-ink-3);
  text-align: center;
}

/* ---- Mobile: full sheet ---- */
@media (max-width: 480px) {
  #ra-panel {
    position: fixed;
    inset: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }
  /* Keep the conversation scrollable inside the sheet, not the page. */
  #ra-log { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  #ra-launcher { right: 14px; bottom: 14px; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  #ra-launcher, #ra-launcher:hover, #ra-send, #ra-send:hover, .ra-chip,
  .ra-enq-send, .ra-enq-send:hover { transition: none; transform: none; }
  #ra-root.ra-open #ra-panel { animation: none; }
  #ra-enq.ra-enq-open { animation: none; }
  .ra-typing i { animation: none; opacity: .6; }
}

/* Escalation: email the transcript to a human */
#ra-mail {
  display: block;
  margin: 6px auto 0;
  background: none;
  border: none;
  color: var(--ra-green, #0F766E);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  min-height: 44px;
}

/* ---- In-widget enquiry form (marketing register) ----
   "Send us this conversation" slides this panel in over the chat. Same
   family as the rest of the widget: paper ground, hairline borders, brand
   green, 44px tap targets, 16px inputs (the iOS zoom floor). */
#ra-enq {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  flex-direction: column;
  background: var(--ra-paper);
}
#ra-enq.ra-enq-open { display: flex; animation: ra-enq-in 220ms cubic-bezier(.22, 1, .36, 1); }
@keyframes ra-enq-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
.ra-enq-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 11px 8px;
  background: var(--ra-surface);
  border-bottom: 1px solid var(--ra-hair);
}
.ra-enq-back {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--ra-ink-3);
  cursor: pointer;
  border-radius: 10px;
  display: grid;
  place-items: center;
}
.ra-enq-back:hover { color: var(--ra-ink); background: var(--ra-paper); }
.ra-enq-back:focus-visible { outline: 2px solid var(--ra-green); outline-offset: -2px; }
.ra-enq-back svg { width: 18px; height: 18px; }
.ra-enq-id { min-width: 0; flex: 1; }
.ra-enq-id h3, .ra-enq-done h3 {
  margin: 0;
  font-size: .95rem;
  font-weight: 600;
  font-family: 'Fraunces', Georgia, serif;
  letter-spacing: -.01em;
  color: var(--ra-ink);
}
.ra-enq-id p {
  margin: 1px 0 0;
  font-size: .7rem;
  color: var(--ra-ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ra-enq-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px 18px;
}
.ra-field { margin: 0 0 10px; }
.ra-row { display: flex; gap: 10px; }
.ra-row .ra-field { flex: 1; min-width: 0; }
.ra-field label {
  display: block;
  margin: 0 0 4px 2px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--ra-ink-2);
}
.ra-req { color: var(--ra-green); }
.ra-field input, .ra-field textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOS zoom floor - same rule as #ra-input */
  color: var(--ra-ink);
  background: var(--ra-surface);
  border: 1px solid var(--ra-hair);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
.ra-field textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.ra-field input::placeholder, .ra-field textarea::placeholder { color: var(--ra-ink-3); }
.ra-field input:focus, .ra-field textarea:focus {
  outline: none;
  border-color: var(--ra-green);
  box-shadow: 0 0 0 3px rgba(21, 128, 61, .14);
}
/* Honeypot: off-screen for everyone real; bots fill it, the server drops it. */
.ra-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}
.ra-enq-err { margin: 2px 2px 8px; min-height: 1em; font-size: .78rem; color: #B91C1C; }
.ra-enq-send {
  display: block;
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  background: var(--ra-green);
  color: #fff;
  font: 600 .9rem/1.2 'Inter', system-ui, sans-serif;
  transition: transform 140ms ease-out, opacity 140ms ease-out;
}
.ra-enq-send:hover { transform: translateY(-1px); }
.ra-enq-send:disabled { opacity: .55; cursor: default; transform: none; }
.ra-enq-send:focus-visible { outline: 2px solid var(--ra-green); outline-offset: 2px; }
.ra-enq-mailto {
  display: block;
  margin: 10px auto 0;
  background: none;
  border: none;
  color: var(--ra-green);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  min-height: 44px;
}
.ra-enq-done { flex: 1; overflow-y: auto; padding: 22px 20px; }
.ra-enq-done p { margin: 10px 0 0; font-size: .9rem; line-height: 1.55; color: var(--ra-ink-2); }
.ra-enq-done p.ra-enq-ref {
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .7rem;
  color: var(--ra-ink-3);
}
.ra-enq-done .ra-enq-send { margin-top: 18px; }

/* Teaser bubble + launcher pulse */
#ra-tease {
  position: fixed;
  right: 24px;
  bottom: 92px;
  z-index: 2147483645;
  max-width: 260px;
  background: var(--ra-surface, #fff);
  color: var(--ra-ink, #111827);
  border: 1px solid var(--ra-hair, #E8E6E1);
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.14);
  padding: 12px 14px;
  font: 500 13.5px/1.45 'Inter', system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
}
@media (max-width: 480px) { #ra-tease { right: 16px; bottom: 84px; } }
.ra-pulse { animation: ra-pulse 1.6s ease-in-out 3; }
@keyframes ra-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 18px rgba(15, 118, 110, 0.35); }
  50% { transform: scale(1.08); box-shadow: 0 10px 26px rgba(15, 118, 110, 0.5); }
}
@media (prefers-reduced-motion: reduce) { .ra-pulse { animation: none; } }
