/* ==========================================================================
   UhAI Intelligence — AI Website Assistant widget
   Floating chat launcher + panel. Brand palette (navy / green / white).
   Self-contained: no dependency on the rest of the site's CSS. Colours that
   the admin can change (primary/accent) come in as the CSS custom properties
   --uhai-a-primary / --uhai-a-accent, set inline on #uhai-assistant.
   ========================================================================== */

#uhai-assistant {
  --uhai-a-primary: #071a3d;
  --uhai-a-accent: #20a65a;
  --uhai-a-radius: 18px;
  --uhai-a-shadow: 0 18px 48px rgba(7, 26, 61, 0.22);
  position: fixed;
  z-index: 2147483000; /* above site chrome, below nothing important */
  bottom: clamp(16px, 3vw, 26px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#uhai-assistant.uhai-pos-bottom-right { right: clamp(16px, 3vw, 26px); }
#uhai-assistant.uhai-pos-bottom-left { left: clamp(16px, 3vw, 26px); }

#uhai-assistant *, #uhai-assistant *::before, #uhai-assistant *::after { box-sizing: border-box; }

/* ---- Launcher button ---- */
.uhai-a-launcher {
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--uhai-a-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--uhai-a-shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.uhai-a-launcher:hover { transform: translateY(-2px); }
.uhai-a-launcher:focus-visible { outline: 3px solid var(--uhai-a-accent); outline-offset: 3px; }
.uhai-a-launcher svg { width: 28px; height: 28px; }
.uhai-a-launcher .uhai-a-badge {
  position: absolute; top: -3px; right: -3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--uhai-a-accent); border: 2px solid #fff;
}
/* Subtle pulse until first opened */
#uhai-assistant.uhai-pulse .uhai-a-launcher::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(32, 166, 90, 0.55);
  animation: uhai-a-pulse 2.2s ease-out infinite;
}
@keyframes uhai-a-pulse {
  0% { box-shadow: 0 0 0 0 rgba(32, 166, 90, 0.5); }
  70% { box-shadow: 0 0 0 16px rgba(32, 166, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(32, 166, 90, 0); }
}
@media (prefers-reduced-motion: reduce) {
  #uhai-assistant.uhai-pulse .uhai-a-launcher::after { animation: none; }
  .uhai-a-panel { transition: none !important; }
}

/* ---- Panel ---- */
.uhai-a-panel {
  position: absolute; bottom: 74px; right: 0;
  width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 110px);
  background: #fff;
  border-radius: var(--uhai-a-radius);
  box-shadow: var(--uhai-a-shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0; transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
#uhai-assistant.uhai-pos-bottom-left .uhai-a-panel { right: auto; left: 0; transform-origin: bottom left; }
#uhai-assistant.uhai-size-large .uhai-a-panel { width: 440px; height: 620px; }
#uhai-assistant.uhai-open .uhai-a-panel { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
#uhai-assistant.uhai-open .uhai-a-launcher { transform: scale(0.94); }

/* ---- Header ---- */
.uhai-a-header {
  background: var(--uhai-a-primary);
  color: #fff;
  padding: 13px 14px;
  display: flex; align-items: center; gap: 11px;
}
.uhai-a-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: #fff; flex: none;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.uhai-a-avatar img { width: 100%; height: 100%; object-fit: contain; }
.uhai-a-titles { flex: 1; min-width: 0; line-height: 1.2; }
.uhai-a-name { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uhai-a-status { font-size: 11.5px; opacity: 0.85; display: flex; align-items: center; gap: 5px; }
.uhai-a-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--uhai-a-accent); box-shadow: 0 0 0 2px rgba(255,255,255,0.25); }
.uhai-a-hdr-btns { display: flex; gap: 2px; }
.uhai-a-iconbtn {
  width: 32px; height: 32px; border: none; background: transparent; color: #fff;
  border-radius: 8px; cursor: pointer; opacity: 0.85;
  display: flex; align-items: center; justify-content: center;
}
.uhai-a-iconbtn:hover { opacity: 1; background: rgba(255,255,255,0.14); }
.uhai-a-iconbtn:focus-visible { outline: 2px solid var(--uhai-a-accent); outline-offset: 1px; opacity: 1; }
.uhai-a-iconbtn svg { width: 18px; height: 18px; }

/* ---- Message list ---- */
.uhai-a-body {
  flex: 1; overflow-y: auto; padding: 16px 14px;
  background: #f6f8fb;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.uhai-a-msg { max-width: 84%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.uhai-a-msg-bot { align-self: flex-start; background: #fff; color: #12151f; border: 1px solid #e2e7ef; border-bottom-left-radius: 5px; white-space: normal; }
/* Rendered Markdown inside an assistant bubble (see renderMarkdown in assistant.js) */
.uhai-a-md p { margin: 0 0 8px; }
.uhai-a-md p:last-child { margin-bottom: 0; }
.uhai-a-md strong { font-weight: 700; }
.uhai-a-md ul { margin: 4px 0 8px; padding-left: 18px; }
.uhai-a-md ul:last-child { margin-bottom: 0; }
.uhai-a-md li { margin: 2px 0; }
.uhai-a-msg-user { align-self: flex-end; background: var(--uhai-a-primary); color: #fff; border-bottom-right-radius: 5px; }
.uhai-a-msg-time { font-size: 10.5px; opacity: 0.6; margin-top: 4px; }
.uhai-a-msg-error { align-self: center; background: #fdecec; color: #b3261e; border: 1px solid #f6c9c6; font-size: 13px; text-align: center; }
.uhai-a-retry { margin-left: 6px; background: none; border: none; color: #b3261e; font-weight: 700; text-decoration: underline; cursor: pointer; font-size: 13px; }

/* Quick questions */
.uhai-a-quick { display: flex; flex-wrap: wrap; gap: 7px; padding: 2px 0 4px; }
.uhai-a-chip {
  border: 1px solid var(--uhai-a-accent); color: #147a45; background: #fff;
  border-radius: 999px; padding: 7px 12px; font-size: 12.5px; cursor: pointer; font-weight: 600;
}
.uhai-a-chip:hover { background: #eafaf1; }
.uhai-a-chip:focus-visible { outline: 2px solid var(--uhai-a-accent); outline-offset: 1px; }

/* Typing indicator */
.uhai-a-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; background: #fff; border: 1px solid #e2e7ef; border-radius: 14px; border-bottom-left-radius: 5px; }
.uhai-a-typing span { width: 7px; height: 7px; border-radius: 50%; background: #b6c0d0; animation: uhai-a-blink 1.2s infinite ease-in-out both; }
.uhai-a-typing span:nth-child(2) { animation-delay: 0.18s; }
.uhai-a-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes uhai-a-blink { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Ended state */
.uhai-a-ended { align-self: center; text-align: center; color: #4b5568; font-size: 13px; background: #eef1f7; border-radius: 12px; padding: 12px 14px; }
.uhai-a-ended-actions { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 9px; }
.uhai-a-ended-actions a, .uhai-a-ended-actions button {
  font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 7px 12px; cursor: pointer; text-decoration: none; border: 1px solid #cbd4e1; color: #12151f; background: #fff;
}
.uhai-a-ended-actions .uhai-a-primary-btn { background: var(--uhai-a-accent); border-color: var(--uhai-a-accent); color: #fff; }

/* ---- Composer ---- */
.uhai-a-composer { border-top: 1px solid #e2e7ef; background: #fff; padding: 9px 10px; }
.uhai-a-input-row { display: flex; align-items: flex-end; gap: 8px; }
.uhai-a-input {
  flex: 1; resize: none; border: 1px solid #cbd4e1; border-radius: 12px;
  padding: 9px 11px; font-size: 14px; font-family: inherit; line-height: 1.4;
  max-height: 96px; min-height: 40px; color: #12151f;
}
.uhai-a-input:focus { outline: none; border-color: var(--uhai-a-accent); box-shadow: 0 0 0 3px rgba(32,166,90,0.15); }
.uhai-a-send {
  flex: none; width: 40px; height: 40px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--uhai-a-accent); color: #fff; display: flex; align-items: center; justify-content: center;
}
.uhai-a-send:disabled { opacity: 0.45; cursor: not-allowed; }
.uhai-a-send:focus-visible { outline: 2px solid var(--uhai-a-primary); outline-offset: 2px; }
.uhai-a-send svg { width: 19px; height: 19px; }
.uhai-a-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 5px; padding: 0 3px; }
.uhai-a-count { font-size: 11px; color: #99a5b8; flex: none; }
.uhai-a-count.uhai-a-over { color: #e5484d; font-weight: 700; }
.uhai-a-hint { font-size: 11px; color: #b6c0d0; flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uhai-a-end { font-size: 11px; color: #6b7789; background: none; border: none; cursor: pointer; text-decoration: underline; padding: 0; flex: none; }
.uhai-a-end:hover { color: #b3261e; }
.uhai-a-end:focus-visible { outline: 2px solid var(--uhai-a-accent); outline-offset: 2px; }

/* ---- Mobile: near-full-screen ---- */
@media (max-width: 480px) {
  #uhai-assistant.uhai-mobile-full.uhai-open .uhai-a-panel {
    position: fixed; inset: 0; width: 100vw; height: 100vh;
    max-width: 100vw; max-height: 100vh; border-radius: 0;
  }
  #uhai-assistant.uhai-mobile-full.uhai-open .uhai-a-launcher { opacity: 0; pointer-events: none; }
}
