/* Floating WhatsApp chat widget (includes/chat-widget.php).
   Mirrors the look and timing of the Elfsight WhatsApp Chat app it replaces. */

.wa-chat {
  --wa-green: #25d366;
  --wa-ink: #111111;
  --wa-tint: rgba(17, 17, 17, 0.05);
  --wa-offset-x: 25px;
  --wa-offset-y: 20px;
  font-family: inherit;
  line-height: normal;
}

.wa-chat *,
.wa-chat *::before,
.wa-chat *::after {
  box-sizing: border-box;
}

/* ---------- Bubble ---------- */

.wa-chat__bubble {
  position: fixed;
  right: var(--wa-offset-x);
  bottom: var(--wa-offset-y);
  z-index: 99999999;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  padding: 16px;
  margin: 0;
  border: 0;
  border-radius: 100px;
  background: var(--wa-green);
  color: #fff;
  box-shadow: 0 3px 12px 0 rgba(0, 0, 0, 0.15);
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.1s ease-in, transform 0.1s ease-in;
}

.wa-chat__bubble svg {
  position: relative;
  z-index: 1;
  display: block;
  width: 32px;
  height: 32px;
  fill: currentColor;
}

/* Pulse rings — JS toggles .is-pulsing for 2s every 12s while the window is closed */
.wa-chat__bubble::before,
.wa-chat__bubble::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 1px solid var(--wa-green);
  border-radius: 500px;
  opacity: 0;
  z-index: 0;
  pointer-events: none;
}

.wa-chat__bubble.is-pulsing::before,
.wa-chat__bubble.is-pulsing::after {
  animation: wa-chat-pulse 1s linear infinite;
}

.wa-chat__bubble.is-pulsing::after {
  animation-delay: 0.5s;
}

@keyframes wa-chat-pulse {
  0% { transform: scale(1); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: scale(1.2); opacity: 0; }
}

.wa-chat__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff0000;
}

.wa-chat__bubble:focus-visible,
.wa-chat__cta:focus-visible,
.wa-chat__close:focus-visible {
  outline: 2px solid var(--wa-green);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #fff;
}

/* ---------- Window ---------- */

.wa-chat__window {
  position: fixed;
  right: var(--wa-offset-x);
  bottom: calc(var(--wa-offset-y) + 56px);
  z-index: 2147483647;
  width: min(360px, calc(100vw - var(--wa-offset-x) - 20px));
  margin-bottom: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  touch-action: none;
  transition: opacity 0.3s ease, margin 0.3s ease, visibility 0.3s ease;
}

.wa-chat.is-open .wa-chat__window {
  margin-bottom: 20px;
  opacity: 1;
  visibility: visible;
  pointer-events: all;
  touch-action: auto;
}

.wa-chat__panel {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 4px 30px 0 rgba(0, 0, 0, 0.3);
}

.wa-chat__close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  background: none;
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.3s;
}

.wa-chat__close:hover {
  opacity: 0.8;
}

.wa-chat__close::before,
.wa-chat__close::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 2px;
  border-radius: 2px;
  background: var(--wa-ink);
}

.wa-chat__close::before { transform: rotate(45deg); }
.wa-chat__close::after { transform: rotate(-45deg); }

/* Header */

.wa-chat__header {
  display: flex;
  align-items: center;
  padding: 20px;
  background: #fff;
  border-bottom: 1px solid rgba(17, 17, 17, 0.1);
  color: var(--wa-ink);
}

.wa-chat__avatar {
  position: relative;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
}

.wa-chat__avatar img {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  border-radius: 50%;
  object-fit: cover;
}

/* Hairline ring over the photo */
.wa-chat__avatar::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--wa-tint);
  border-radius: 50%;
  pointer-events: none;
}

/* Online dot */
.wa-chat__avatar::before {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  z-index: 2;
  width: 12px;
  height: 12px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #4ad504;
}

.wa-chat__info {
  width: 100%;
  margin: 0 16px;
  overflow: hidden;
}

.wa-chat__name {
  display: -webkit-box;
  max-height: 60px;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  font-size: 16px;
  font-weight: 700;
  line-height: 20px;
  color: var(--wa-ink);
}

.wa-chat__caption {
  margin-top: 4px;
  font-size: 13px;
  line-height: 18px;
  color: var(--wa-ink);
}

/* Conversation */

.wa-chat__body {
  position: relative;
  max-height: 382px;
  padding: 10px 20px 12px;
  overflow: auto;
  background: #fff;
}

.wa-chat__time {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
  padding: 4px;
  font-size: 10px;
  color: var(--wa-ink);
  opacity: 0.3;
}

.wa-chat__message-row {
  position: relative;
  display: flex;
}

.wa-chat__typing {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 53px;
  height: 32px;
  border-radius: 16px;
  background: var(--wa-tint);
  box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.15);
  transition: opacity 0.1s ease;
}

.wa-chat__typing span {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 2px;
  border-radius: 50%;
  background: var(--wa-ink);
  animation: wa-chat-typing 1.2s linear infinite;
}

.wa-chat__typing span:nth-child(2) { animation-delay: 0.1s; }
.wa-chat__typing span:nth-child(3) { animation-delay: 0.2s; }

@keyframes wa-chat-typing {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.75; }
}

.wa-chat__message {
  position: relative;
  z-index: 2;
  max-width: calc(100% - 66px);
  padding: 6px 14px;
  border-radius: 0 16px 16px;
  background: var(--wa-tint);
  box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.15);
  color: var(--wa-tint);
  hyphens: auto;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.wa-chat__message-tail {
  position: absolute;
  top: 0;
  left: -9px;
}

.wa-chat__text {
  overflow: hidden;
  font-size: 15px;
  line-height: 20px;
  color: var(--wa-ink);
}

.wa-chat.is-replied .wa-chat__typing {
  opacity: 0;
  pointer-events: none;
}

.wa-chat.is-replied .wa-chat__message {
  opacity: 1;
}

/* CTA */

.wa-chat__cta-wrap {
  display: flex;
  justify-content: center;
  background: #fff;
}

.wa-chat__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  margin: 20px;
  padding: 12px 27px;
  border-radius: 24px;
  background: var(--wa-green);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 22px;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.1s ease-in, background-color 0.1s ease-in;
}

.wa-chat__cta:hover {
  color: #fff;
  text-decoration: none;
}

.wa-chat__cta svg {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: 0 8px 0 -4px;
  fill: currentColor;
}

.wa-chat__cta span {
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (prefers-reduced-motion: reduce) {
  .wa-chat__bubble,
  .wa-chat__window,
  .wa-chat__message,
  .wa-chat__cta {
    transition: none;
  }
}
