/* Public-website AI chat widget — floating bubble + panel.
   Green theme to match the public site (see base.html / header). Scoped under
   #hpt-chat so it never collides with page styles. */

#hpt-chat {
  --hpt-chat-green: #45c646;
  --hpt-chat-green-dark: #2f9e30;
  --hpt-chat-ink: #1f2937;
  --hpt-chat-muted: #6b7280;
  --hpt-chat-bg: #ffffff;
  --hpt-chat-user: #e8f7e9;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1080;
  font-family: inherit;
}

/* Launcher bubble */
#hpt-chat-launcher {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--hpt-chat-green);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease, background 0.15s ease;
}
#hpt-chat-launcher:hover {
  background: var(--hpt-chat-green-dark);
  transform: translateY(-1px);
}
#hpt-chat-launcher svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

/* Panel */
#hpt-chat-panel {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--hpt-chat-bg);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}
#hpt-chat.open #hpt-chat-panel {
  display: flex;
}
#hpt-chat.open #hpt-chat-launcher {
  display: none;
}

#hpt-chat-header {
  background: var(--hpt-chat-green);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#hpt-chat-header .hpt-chat-title {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}
#hpt-chat-header .hpt-chat-sub {
  font-size: 12px;
  opacity: 0.9;
}
#hpt-chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

#hpt-chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f8faf8;
}

.hpt-chat-msg {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.hpt-chat-msg.bot {
  align-self: flex-start;
  background: #fff;
  color: var(--hpt-chat-ink);
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}
.hpt-chat-msg.user {
  align-self: flex-end;
  background: var(--hpt-chat-user);
  color: var(--hpt-chat-ink);
  border-bottom-right-radius: 4px;
}
.hpt-chat-msg a {
  color: var(--hpt-chat-green-dark);
  font-weight: 600;
}

/* typing dots */
.hpt-chat-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.hpt-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hpt-chat-muted);
  animation: hpt-chat-bounce 1.2s infinite ease-in-out;
}
.hpt-chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.hpt-chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes hpt-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

#hpt-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}
#hpt-chat-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  max-height: 96px;
  line-height: 1.4;
}
#hpt-chat-input:focus {
  outline: none;
  border-color: var(--hpt-chat-green);
  box-shadow: 0 0 0 2px rgba(69, 198, 70, 0.2);
}
#hpt-chat-send {
  flex: 0 0 auto;
  background: var(--hpt-chat-green);
  color: #fff;
  border: none;
  border-radius: 10px;
  width: 42px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#hpt-chat-send:hover {
  background: var(--hpt-chat-green-dark);
}
#hpt-chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}
#hpt-chat-send svg {
  width: 18px;
  height: 18px;
}
.hpt-chat-disclaimer {
  font-size: 11px;
  color: var(--hpt-chat-muted);
  text-align: center;
  padding: 0 12px 8px;
  background: #fff;
}

/* -------------------------------------------------------------------------
   D1 — delayed reveal. Until JS arms the widget (after ~1 screen of scroll or
   a few seconds), keep the launcher out of the way so it doesn't cover the
   hero form/CTAs on first paint. Non-interactive while hidden.
   ------------------------------------------------------------------------- */
#hpt-chat #hpt-chat-launcher {
  transition: transform 0.2s ease, background 0.15s ease, opacity 0.25s ease;
}
#hpt-chat:not(.armed):not(.open) #hpt-chat-launcher {
  opacity: 0;
  transform: translateY(14px) scale(0.92);
  pointer-events: none;
}

/* -------------------------------------------------------------------------
   D2 — trim ~15–20% on phones and tuck it a touch lower so it clears buttons.
   ------------------------------------------------------------------------- */
@media (max-width: 768px) {
  #hpt-chat { right: 14px; bottom: 14px; }
  #hpt-chat-launcher { padding: 10px 15px; font-size: 13.5px; gap: 7px; }
  #hpt-chat-launcher svg { width: 18px; height: 18px; }
  #hpt-chat-panel { height: 480px; border-radius: 14px; }
}
