/* ---------- Walking companion ---------- */
.companion {
  --c-skin: #c68a52;
  --c-skin-dark: #a8713f;
  --c-hair: #15110f;
  --c-shirt: #f8f7f2;
  --c-shirt-dark: #dedbd2;
  --c-shirt-line: #b9b5aa;
  --c-pants: #1f2937;
  --c-pants-dark: #111827;

  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 1040;
  width: 90px;
  transform: translateX(-200px);
  pointer-events: none;
  will-change: transform;
}

.companion-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.2s ease;
}

.companion-btn:hover {
  transform: translateY(-4px);
}

.companion-btn:focus-visible {
  outline: 3px solid var(--accent, #f59e0b);
  outline-offset: 4px;
  border-radius: 12px;
}

.companion .figure {
  display: block;
  width: 90px;
  height: 165px;
  overflow: visible;
}

.companion.face-left .figure {
  transform: scaleX(-1);
}

/* Colours */
.c-skin { fill: var(--c-skin); }
.c-skin-dark { fill: var(--c-skin-dark); }
.c-hair { fill: var(--c-hair); }
.c-hair-shine { stroke: rgba(255, 255, 255, 0.18); stroke-width: 2; stroke-linecap: round; fill: none; }
.c-beard { fill: var(--c-hair); opacity: 0.82; }
.c-brow { stroke: var(--c-hair); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.c-shirt { fill: var(--c-shirt); stroke: var(--c-shirt-line); stroke-width: 1.2; }
.c-sleeve { fill: var(--c-shirt); stroke: var(--c-shirt-line); stroke-width: 1.2; }
.c-sleeve-dark { fill: var(--c-shirt-dark); stroke: var(--c-shirt-line); stroke-width: 1.2; }
.c-collar { fill: var(--c-shirt); stroke: var(--c-shirt-line); stroke-width: 1.2; stroke-linejoin: round; }
.c-placket { stroke: var(--c-shirt-line); stroke-width: 1; }
.c-button { fill: var(--c-shirt-line); }
.c-belt { fill: #3f2a1d; }
.c-pants { fill: var(--c-pants); }
.c-pants-dark { fill: var(--c-pants-dark); }
.c-shoe { fill: #0b0b0b; }
.c-shadow { fill: rgba(0, 0, 0, 0.18); }
.c-eye { fill: #111; }
.c-mouth { stroke: #f1e3d3; stroke-width: 2; stroke-linecap: round; fill: none; }

/* Joints */
.companion .arm,
.companion .leg,
.companion .head {
  transform-box: view-box;
}

.companion .arm { transform-origin: 60px 70px; }
.companion .leg-back { transform-origin: 57px 124px; }
.companion .leg-front { transform-origin: 63px 124px; }
.companion .head { transform-origin: 60px 54px; }

/* Idle: gentle breathing + blink */
.companion .torso,
.companion .head {
  animation: c-breathe 3s ease-in-out infinite;
}

.companion .c-eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: c-blink 4.5s infinite;
}

/* Walking */
.companion.is-walking .leg-front,
.companion.is-walking .arm-back {
  animation: c-swing 0.55s ease-in-out infinite alternate;
}

.companion.is-walking .leg-back,
.companion.is-walking .arm-front {
  animation: c-swing 0.55s ease-in-out infinite alternate-reverse;
}

.companion.is-walking .head,
.companion.is-walking .torso {
  animation: c-bob 0.275s ease-in-out infinite alternate;
}

/* Waving (front arm raised) */
.companion.is-waving .arm-front {
  animation: c-wave 0.45s ease-in-out infinite alternate;
}

.companion.is-waving .head {
  animation: c-tilt 0.9s ease-in-out infinite alternate;
}

@keyframes c-swing {
  from { transform: rotate(-24deg); }
  to { transform: rotate(24deg); }
}

@keyframes c-bob {
  to { transform: translateY(-3px); }
}

@keyframes c-wave {
  from { transform: rotate(-155deg); }
  to { transform: rotate(-120deg); }
}

@keyframes c-tilt {
  from { transform: rotate(-4deg); }
  to { transform: rotate(4deg); }
}

@keyframes c-breathe {
  50% { transform: translateY(-1.5px); }
}

@keyframes c-blink {
  0%, 94%, 100% { transform: scaleY(1); }
  97% { transform: scaleY(0.1); }
}

/* Lottie character (replaces the SVG when loaded) */
.companion-lottie {
  display: none;
}

.companion.has-lottie {
  width: 200px;
}

.companion.has-lottie .figure {
  display: none;
}

.companion.has-lottie .companion-lottie {
  display: block;
  width: 200px;
  height: 200px;
  /* light outline so the dark suit stays visible on dark sections */
  filter:
    drop-shadow(0 0 1.5px rgba(255, 255, 255, 0.9))
    drop-shadow(0 0 6px rgba(255, 255, 255, 0.35))
    drop-shadow(0 6px 6px rgba(0, 0, 0, 0.25));
}

.companion.has-lottie.face-left .companion-lottie {
  transform: scaleX(-1);
}

.companion.has-lottie.is-waving .companion-lottie {
  animation: c-hop 0.45s ease-in-out infinite alternate;
}

.companion.has-lottie.face-left.is-waving .companion-lottie {
  animation-name: c-hop-left;
}

.companion.has-lottie .companion-bubble {
  left: 110px;
  bottom: calc(100% - 14px);
}

.companion.has-lottie.bubble-left .companion-bubble {
  left: auto;
  right: 110px;
}

@keyframes c-hop {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

@keyframes c-hop-left {
  from { transform: scaleX(-1) translateY(0); }
  to { transform: scaleX(-1) translateY(-8px); }
}

/* Speech bubble */
.companion-bubble {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 30px;
  width: max-content;
  max-width: 240px;
  padding: 0.65rem 0.9rem;
  border-radius: 14px 14px 14px 4px;
  font-size: 0.88rem;
  line-height: 1.4;
  color: #0f172a;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.companion-bubble.show {
  opacity: 1;
  transform: none;
}

.companion.bubble-left .companion-bubble {
  left: auto;
  right: 30px;
  border-radius: 14px 14px 4px 14px;
}

/* Floating chat button: teal circle with a smiling chat-bubble icon and an unread badge.
   Sits above the WhatsApp button (same centre line: 16 + 60/2 = 20 + 52/2). */
.companion-call {
  position: fixed;
  right: 16px;
  bottom: 84px;
  z-index: 1041;
  width: 60px;
  height: 60px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #14998a;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.3);
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.25s ease;
}

.companion-call:hover {
  transform: scale(1.06);
}

/* The icon gives a short wiggle every 6s so the button feels alive */
.companion-call .call-icon {
  width: 34px;
  height: 34px;
  animation: call-wiggle 6s ease-in-out 3s infinite;
}

body.chat-open .companion-call .call-icon {
  animation: none;
}

@keyframes call-wiggle {
  0%, 86%, 100% { transform: none; }
  88% { transform: rotate(-14deg) scale(1.1); }
  90% { transform: rotate(12deg) scale(1.1); }
  92% { transform: rotate(-9deg) scale(1.05); }
  94% { transform: rotate(6deg); }
  96% { transform: rotate(0); }
}

/* "Chat with us" pill that slides out to the left of the button */
.companion-call .call-label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 0.88rem;
  font-weight: 600;
  color: #0f766e;
  background: #fff;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
  opacity: 0;
  transform: translate(8px, -50%);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.companion-call:hover .call-label,
.companion-call .call-label.show {
  opacity: 1;
  transform: translate(0, -50%);
}

body.chat-open .companion-call .call-label {
  display: none;
}

/* Red "1" badge, shown whenever the chat is closed */
.companion-call .call-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  background: #dc2626;
}

body.chat-open .companion-call .call-badge {
  display: none;
}

/* While the chat is open the button shows a close (×) icon */
.companion-call .call-close {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  border-radius: 50%;
  font-size: 1.3rem;
  color: #fff;
  background: #14998a;
}

body.chat-open .companion-call .call-close {
  display: grid;
}

/* Greeting above the chat button: one small card with two quick chips */
.chat-teaser {
  position: fixed;
  right: 16px;
  bottom: 156px;
  z-index: 1041;
  width: 230px;
  padding: 0.75rem 0.85rem 0.8rem;
  border-radius: 14px 14px 4px 14px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.22);
  animation: teaser-in 0.35s ease-out;
}

.chat-teaser[hidden] {
  display: none;
}

.chat-teaser-msg {
  display: block;
  width: 100%;
  padding: 0 1.2rem 0 0;
  border: 0;
  background: none;
  text-align: left;
  font-size: 0.92rem;
  font-weight: 500;
  color: #0f172a;
}

.chat-teaser-close {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  padding: 0.15rem 0.3rem;
  border: 0;
  background: none;
  font-size: 1rem;
  line-height: 1;
  color: #94a3b8;
}

.chat-teaser-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.chat-teaser-chip {
  padding: 0.25rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.8rem;
  color: #0f766e;
  background: #e6f4f2;
}

.chat-teaser-chip:hover {
  border-color: #0f766e;
}

@keyframes teaser-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* Phones: floating buttons fade out while the contact form is on screen so they
   don't cover its fields (they stay if the chat itself is open) */
@media (max-width: 991.98px) {
  body.form-in-view:not(.chat-open) .companion-call,
  body.form-in-view:not(.chat-open) .whatsapp-float {
    opacity: 0;
    pointer-events: none;
  }
}

/* WhatsApp button, below the chat button */
.whatsapp-float {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1041;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  color: #fff;
  background: #25d366;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
  transition: transform 0.2s ease, opacity 0.25s ease;
}

.whatsapp-float:hover {
  color: #fff;
  transform: scale(1.08);
}

/* Chat panel, opens above both floating buttons */
.companion-chat {
  position: fixed;
  right: 20px;
  bottom: 156px;
  z-index: 1045;
  width: 340px;
  max-height: min(540px, calc(100vh - 230px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.28);
}

.companion-chat[hidden] {
  display: none;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  color: #fff;
  background: linear-gradient(135deg, #0f766e, #115e59);
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: #f8fafc;
}

.msg {
  max-width: 85%;
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-line;
}

.msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.msg.user {
  align-self: flex-end;
  color: #fff;
  background: #0f766e;
  border-bottom-right-radius: 4px;
}

.msg a {
  color: #0f766e;
  font-weight: 600;
}

.msg.typing span {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 1px;
  border-radius: 50%;
  background: #94a3b8;
  animation: c-dot 1s infinite;
}

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

@keyframes c-dot {
  0%, 60%, 100% { transform: none; opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.6rem 1rem 0;
  background: #fff;
  border-top: 1px solid #e2e8f0;
}

.chat-quick button {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  color: #0f766e;
  background: #e6f4f2;
  border: 1px solid transparent;
}

.chat-quick button:hover {
  border-color: #0f766e;
}

.chat-input {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #fff;
}

@media (max-width: 575.98px) {
  .companion,
  .companion .figure {
    width: 68px;
  }

  .companion .figure {
    height: 125px;
  }

  .companion.has-lottie,
  .companion.has-lottie .companion-lottie {
    width: 140px;
  }

  .companion.has-lottie .companion-lottie {
    height: 140px;
  }

  .companion.has-lottie .companion-bubble {
    left: 78px;
  }

  .companion.has-lottie.bubble-left .companion-bubble {
    right: 78px;
  }

  .companion-bubble {
    max-width: 200px;
    font-size: 0.82rem;
  }

  /* Phones: use the height from just below the top edge down to the buttons */
  .companion-chat {
    left: 16px;
    right: 16px;
    bottom: 156px;
    width: auto;
    max-height: calc(100vh - 172px);
    max-height: calc(100dvh - 172px);
  }

  body.chat-open .companion {
    visibility: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .companion *,
  .companion-chat *,
  .chat-teaser,
  .companion-call .call-icon {
    animation: none !important;
  }
}
