/*
 * WhatsApp Widget
 * Floating FAB with optional speech bubble greeting (sits to its left)
 */

@layer components {
  .whatsapp-widget {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.625rem;
    pointer-events: none;
  }

  .whatsapp-widget > * {
    pointer-events: auto;
  }

  .btn-whatsapp {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #25d366, #128c7e);
    box-shadow: var(--shadow);
    color: var(--color-white);
    animation: heartbeat 3s cubic-bezier(0.165, 0.85, 0.45, 1) infinite;

    @media (any-hover: hover) {
      &:hover {
        transform: scale(1.1);
        animation: none;
      }
    }

    .icon {
      --icon-md: 32px;
    }
  }

  .whatsapp-widget__bubble {
    position: relative;
    max-width: min(14rem, calc(100vw - 8rem));
    border-radius: var(--radius);
    background-color: oklch(var(--lch-white) / 50%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--color-gray-darker);
    box-shadow: var(--shadow);
    transform-origin: center right;
    animation: whatsapp-bubble-in 320ms cubic-bezier(0.2, 0.8, 0.3, 1.2) both;
  }

  .whatsapp-widget__bubble[hidden] {
    display: none;
  }

  .whatsapp-widget__bubble::after {
    content: "";
    position: absolute;
    top: 50%;
    right: -5px;
    width: 12px;
    height: 12px;
    background-color: oklch(var(--lch-white) / 50%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transform: translateY(-50%) rotate(45deg);
    border-radius: 2px;
  }

  .whatsapp-widget__bubble-link {
    display: block;
    padding: 0.75rem 2rem 0.75rem 0.875rem;
    color: var(--color-gray-darker);
    text-decoration: none;
    font-size: var(--text-x-small);
    line-height: 1.45;
    font-weight: 500;
  }

  .whatsapp-widget__close {
    position: absolute;
    top: 0.125rem;
    right: 0.125rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--color-gray);
    cursor: pointer;

    &:hover {
      background: oklch(var(--lch-black) / 6%);
      color: var(--color-gray-darker);
    }

    .icon {
      --icon-md: 14px;
    }
  }

  /* When the bubble is showing, calm the FAB so the greeting is the focal point */
  .whatsapp-widget:has(.whatsapp-widget__bubble:not([hidden])) .btn-whatsapp {
    animation: none;
  }

  @keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    10% { transform: scale(1.12); }
    20% { transform: scale(1); }
    30% { transform: scale(1.08); }
    40% { transform: scale(1); }
  }

  @keyframes whatsapp-bubble-in {
    from {
      opacity: 0;
      transform: translateX(8px) scale(0.85);
    }
    to {
      opacity: 1;
      transform: translateX(0) scale(1);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .btn-whatsapp,
    .whatsapp-widget__bubble {
      animation: none;
    }
  }
}
