/* HAI (Hatchnix AI) widget styles. Namespaced with hai- to avoid clashing with site CSS. */

.hai-launcher {
  position: fixed;
  right: clamp(1rem, 2vw, 1.5rem);
  bottom: clamp(1rem, 2vw, 1.5rem);
  z-index: 60;
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow-card);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 3px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.85);
  transition: opacity 0.5s var(--ease-out-expo), transform 0.5s var(--ease-spring), visibility 0.5s;
}
.hai-launcher.hai-visible { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.hai-launcher:hover .hai-chick { transform: rotate(-6deg); }
.hai-launcher:hover .hai-shell { animation: hai-wiggle 0.5s var(--ease-out-expo); }
.hai-launcher:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.hai-chick { width: 100%; height: 100%; display: block; transition: transform var(--duration-normal) var(--ease-out-expo); }
.hai-chick-body { animation: hai-bob 3s ease-in-out infinite; transform-origin: 50% 60%; }
.hai-eye { transform-origin: center; animation: hai-blink 4s ease-in-out infinite; }
.hai-spark { animation: hai-twinkle 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.hai-eye { transform-box: fill-box; }
.hai-shell { transform-box: fill-box; transform-origin: 50% 100%; }
.hai-launcher.hai-typing .hai-chick-body { animation-duration: 0.6s; }

@keyframes hai-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes hai-blink { 0%, 92%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.1); } }
@keyframes hai-twinkle { 0%, 100% { opacity: 0.5; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1.15); } }
@keyframes hai-wiggle { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

@media (prefers-reduced-motion: reduce) {
  .hai-chick-body, .hai-eye, .hai-spark, .hai-launcher:hover .hai-shell { animation: none !important; }
}

/* Speech bubble */
.hai-bubble {
  position: fixed;
  right: calc(clamp(1rem, 2vw, 1.5rem) + 74px);
  bottom: clamp(1.6rem, 2.6vw, 2.1rem);
  z-index: 59;
  max-width: 200px;
  background: var(--card);
  color: var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  padding: 0.6rem 0.9rem 0.7rem 1rem;
  font-family: var(--font-hand);
  font-size: 1.35rem;
  line-height: 1.15;
  opacity: 0;
  visibility: hidden;
  transform: translateX(8px) scale(0.9);
  transition: opacity 0.45s var(--ease-spring), transform 0.45s var(--ease-spring), visibility 0.45s;
  cursor: pointer;
}
.hai-bubble.hai-visible { opacity: 1; visibility: visible; transform: translateX(0) scale(1); }
.hai-bubble::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: 20px;
  width: 12px;
  height: 12px;
  background: var(--card);
  transform: rotate(45deg);
  border-radius: 2px;
}
.hai-bubble-close {
  position: absolute;
  top: -10px;
  left: -10px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 4px 10px -4px rgba(20, 20, 19, 0.4);
}
.hai-bubble-close:hover { background: var(--accent); }
.hai-bubble-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Fallback WhatsApp button (used when HAI is disabled) */
.hai-wa-fallback {
  position: fixed;
  right: clamp(1rem, 2vw, 1.5rem);
  bottom: clamp(1rem, 2vw, 1.5rem);
  z-index: 60;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--wa, #147a47);
  color: #fff;
  box-shadow: 0 8px 22px -8px rgba(20, 20, 19, 0.45);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.85);
  transition: opacity 0.5s var(--ease-out-expo), transform 0.5s var(--ease-spring), background-color var(--duration-fast), visibility 0.5s;
}
.hai-wa-fallback.hai-visible { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.hai-wa-fallback:hover { background: #0f5f39; transform: scale(1.06); }
.hai-wa-fallback svg { width: 24px; height: 24px; fill: currentColor; display: block; }

/* Panel */
.hai-panel {
  position: fixed;
  right: clamp(1rem, 2vw, 1.5rem);
  bottom: clamp(5.5rem, 6vw, 6.2rem);
  z-index: 61;
  width: 380px;
  max-width: calc(100vw - 2rem);
  height: min(620px, 80vh);
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(24px) scale(0.97);
  transition: opacity 0.35s var(--ease-out-expo), transform 0.35s var(--ease-out-expo), visibility 0.35s;
}
.hai-panel.hai-open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

@media (max-width: 560px) {
  .hai-panel {
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
  }
}

.hai-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.hai-header-avatar { width: 36px; height: 36px; flex: 0 0 auto; }
.hai-header-text { flex: 1 1 auto; min-width: 0; }
.hai-header-name { font-weight: 700; font-size: 1rem; display: flex; align-items: center; gap: 0.35rem; }
.hai-online-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; display: inline-block; }
.hai-header-sub { font-size: var(--text-sm); color: var(--muted); }
.hai-header-actions { display: flex; gap: 0.25rem; flex: 0 0 auto; }
.hai-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.hai-icon-btn:hover { background: var(--paper-2); }
.hai-icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hai-icon-btn svg { width: 18px; height: 18px; }

.hai-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background: var(--paper);
}

.hai-msg { max-width: 84%; display: flex; gap: 0.5rem; align-items: flex-end; }
.hai-msg-assistant { align-self: flex-start; }
.hai-msg-user { align-self: flex-end; flex-direction: row-reverse; }
.hai-bubble-text {
  padding: 0.6rem 0.85rem;
  border-radius: 16px;
  font-size: var(--text-sm);
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
}
.hai-msg-assistant .hai-bubble-text { background: var(--paper-2); color: var(--ink); border-bottom-left-radius: 4px; }
.hai-msg-user .hai-bubble-text { background: var(--ink); color: var(--paper); border-bottom-right-radius: 4px; }
.hai-bubble-text p { margin: 0 0 0.5em; }
.hai-bubble-text p:last-child { margin-bottom: 0; }
.hai-bubble-text ul { margin: 0.3em 0; padding-left: 1.1em; list-style: disc; }
.hai-bubble-text li::marker { color: var(--accent); }
.hai-bubble-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.hai-msg-avatar { width: 22px; height: 22px; flex: 0 0 auto; }

.hai-suggestions { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0 0.1rem; }
.hai-chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: var(--text-sm);
  cursor: pointer;
  min-height: 40px;
}
.hai-chip:hover { border-color: var(--accent); color: var(--accent); }
.hai-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hai-typing { display: flex; align-items: center; gap: 0.5rem; align-self: flex-start; }
.hai-typing-dots { display: flex; gap: 3px; background: var(--paper-2); padding: 0.55rem 0.75rem; border-radius: 16px; }
.hai-typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: hai-typing-bounce 1.1s ease-in-out infinite;
}
.hai-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.hai-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes hai-typing-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .hai-typing-dots span { animation: none; } }

/* Inline lead form card */
.hai-form-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  align-self: stretch;
}
.hai-field { display: flex; flex-direction: column; gap: 0.25rem; }
.hai-field label { font-size: var(--text-sm); color: var(--muted); }
.hai-field input, .hai-field select, .hai-field textarea {
  font: inherit;
  font-size: var(--text-sm);
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  min-height: 40px;
}
.hai-field textarea { min-height: 72px; resize: vertical; }
.hai-field input:focus-visible, .hai-field select:focus-visible, .hai-field textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.hai-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.hai-form-error { color: #c1401f; font-size: var(--text-sm); }
.hai-form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

.hai-btn {
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}
.hai-btn-primary { background: var(--accent); color: #fff; }
.hai-btn-primary:hover { filter: brightness(1.05); }
.hai-btn-ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.hai-btn-ghost:hover { box-shadow: inset 0 0 0 1.5px var(--ink); }
.hai-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hai-btn:disabled { opacity: 0.6; cursor: default; }

.hai-actions-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.1rem 0 0.2rem 2rem; }
.hai-btn-sm { min-height: 36px; padding: 0.4rem 0.85rem; font-size: 0.82rem; }

.hai-footer { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 0.7rem 0.8rem; background: var(--card); }
.hai-quickrow {
  display: flex;
  gap: 0.35rem;
  margin: 0 -0.8rem 0.55rem;
  padding: 2px 0.8rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.hai-quickrow::-webkit-scrollbar { display: none; }
.hai-quickrow .hai-btn { flex: 0 0 auto; min-height: 34px; padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.hai-inputrow { display: flex; align-items: flex-end; gap: 0.5rem; }
.hai-textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  font: inherit;
  font-size: var(--text-sm);
  padding: 0.6rem 0.8rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  overflow-y: hidden;
}
.hai-textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hai-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.hai-send:hover { filter: brightness(1.05); }
.hai-send:disabled { opacity: 0.5; cursor: default; }
.hai-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hai-counter { font-size: 0.7rem; color: var(--muted); text-align: right; margin-top: 0.2rem; }
.hai-footnote { font-size: 0.7rem; color: var(--muted); margin-top: 0.5rem; text-align: center; }

.hai-error-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.4rem; }
.hai-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
