/* The Help Buddy (ha-): the Help Buddy button at the bottom left of every page and
   its chat panel (Views/Shared/_HelpAssistant.cshtml, help-assistant.js). The
   bottom right is left to the Buddies chat window and its toasts. */

.ha {
  --ha-blue: var(--bb-blue-600);
  --ha-blue-dark: var(--bb-blue-700);
  --ha-ink: #1f2937;
  --ha-soft: #6b7280;
  --ha-line: #e5e7eb;
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 1040;
  font-size: 0.95rem;
}

.ha-fab {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 1.05rem 0.7rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--ha-blue), var(--bb-blue-900));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(30, 58, 138, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ha-fab:hover,
.ha-fab:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(30, 58, 138, 0.4);
}

.ha.is-open .ha-fab {
  display: none;
}

.ha-panel {
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 2rem));
  border: 1px solid var(--ha-line);
  border-radius: 1.1rem;
  background: #fff;
  box-shadow: 0 24px 60px rgba(17, 24, 39, 0.25);
  overflow: hidden;
}

.ha-panel[hidden] {
  display: none;
}

.ha-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 0.75rem 0.8rem 1rem;
  background: linear-gradient(135deg, var(--ha-blue), var(--bb-blue-900));
  color: #fff;
}

.ha-avatar {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1.15rem;
}

.ha-head-text {
  flex: 1;
  min-width: 0;
}

.ha-head h2 {
  margin: 0;
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
}

.ha-head p {
  margin: 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.8rem;
}

.ha-icon-btn {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
}

.ha-icon-btn:hover,
.ha-icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}

.ha-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem;
  overflow-y: auto;
  background: var(--bb-sage-50);
}

.ha-msg {
  max-width: 88%;
  padding: 0.6rem 0.8rem;
  border-radius: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.ha-msg p {
  margin: 0 0 0.45rem;
}

.ha-msg p:last-child,
.ha-msg ol:last-child,
.ha-msg ul:last-child {
  margin-bottom: 0;
}

.ha-msg ol,
.ha-msg ul {
  margin: 0 0 0.45rem;
  padding-left: 1.2rem;
}

.ha-bot {
  align-self: flex-start;
  border: 1px solid var(--ha-line);
  border-bottom-left-radius: 0.3rem;
  background: #fff;
  color: var(--ha-ink);
}

.ha-bot a {
  color: var(--ha-blue-dark);
  font-weight: 600;
}

.ha-user {
  align-self: flex-end;
  border-bottom-right-radius: 0.3rem;
  background: var(--ha-blue);
  color: #fff;
  white-space: pre-wrap;
}

/* The best FAQ matches, when the answer isn't written by AI. */
.help-entry + .help-entry {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--ha-line);
}

.ha-sources {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--ha-line);
  font-size: 0.82rem;
}

.ha-sources span {
  color: var(--ha-soft);
}

.ha-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ha-suggestions[hidden] {
  display: none;
}

.ha-chip {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--bb-blue-200);
  border-radius: 999px;
  background: #fff;
  color: var(--ha-blue-dark);
  font-size: 0.85rem;
  font-weight: 600;
}

.ha-chip:hover,
.ha-chip:focus-visible {
  border-color: var(--ha-blue);
  background: var(--bb-blue-50);
}

.ha-typing {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.8rem 0.9rem;
}

.ha-typing span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--ha-soft);
  animation: ha-bounce 1.2s infinite ease-in-out;
}

.ha-typing span:nth-child(2) { animation-delay: 0.15s; }
.ha-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ha-bounce {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.ha-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--ha-line);
  background: #fff;
}

.ha-form textarea {
  flex: 1;
  max-height: 120px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--ha-line);
  border-radius: 0.9rem;
  resize: none;
  line-height: 1.4;
}

.ha-form textarea:focus {
  border-color: var(--ha-blue);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.ha-send {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 50%;
  background: var(--ha-blue);
  color: #fff;
}

.ha-send:disabled {
  opacity: 0.5;
}

.ha-foot {
  margin: 0;
  padding: 0 0.9rem 0.65rem;
  background: #fff;
  color: var(--ha-soft);
  font-size: 0.75rem;
}

@media (max-width: 575.98px) {
  .ha {
    left: 0.75rem;
    bottom: 0.75rem;
  }

  .ha-fab-text {
    display: none;
  }

  .ha-fab {
    padding: 0.8rem;
  }

  .ha.is-open {
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.5rem;
  }

  .ha-panel {
    width: 100%;
    height: min(560px, calc(100vh - 1rem));
  }
}

@media (prefers-reduced-motion: reduce) {
  .ha-typing span { animation: none; }
  .ha-fab { transition: none; }
}
