/**
 * WA Chat Connect – Frontend Styles
 * Version: 1.0.0
 *
 * Table of Contents:
 *  1. CSS Custom Properties
 *  2. Keyframe Animations
 *  3. Wrapper & Position
 *  4. Floating Action Button (FAB)
 *  5. Popup Card
 *  6. Popup Header
 *  7. Popup Body – Single Agent
 *  8. Popup Body – Multi Agent
 *  9. Chat Bubble
 * 10. Chat Now Button
 * 11. Popup Footer
 * 12. Backdrop
 * 13. Status Indicators
 * 14. Shortcode Button
 * 15. Responsive / Mobile
 * 16. Accessibility / Reduced Motion
 */

/* ── 1. CSS Custom Properties ──────────────────────────────────────────────── */
:root {
  --wacc-green:        #25D366;
  --wacc-green-dark:   #1ebd5a;
  --wacc-green-light:  #dcf8e8;
  --wacc-teal:         #075E54;
  --wacc-white:        #ffffff;
  --wacc-gray-50:      #f9fafb;
  --wacc-gray-100:     #f3f4f6;
  --wacc-gray-200:     #e5e7eb;
  --wacc-gray-400:     #9ca3af;
  --wacc-gray-600:     #4b5563;
  --wacc-gray-800:     #1f2937;
  --wacc-shadow-sm:    0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --wacc-shadow-md:    0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -1px rgba(0,0,0,.06);
  --wacc-shadow-lg:    0 10px 15px -3px rgba(0,0,0,.12), 0 4px 6px -2px rgba(0,0,0,.08);
  --wacc-shadow-xl:    0 20px 25px -5px rgba(0,0,0,.15), 0 10px 10px -5px rgba(0,0,0,.06);
  --wacc-radius-sm:    8px;
  --wacc-radius-md:    12px;
  --wacc-radius-lg:    20px;
  --wacc-radius-full:  9999px;
  --wacc-z-backdrop:   9998;
  --wacc-z-popup:      9999;
  --wacc-z-fab:        10000;
  --wacc-transition:   cubic-bezier(.34,1.56,.64,1);
  --wacc-ease:         cubic-bezier(.4,0,.2,1);
  --wacc-popup-width:  360px;
  --wacc-offset:       24px;
}

/* ── 2. Keyframe Animations ────────────────────────────────────────────────── */

/* FAB pulse ring */
@keyframes wacc-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(37,211,102,.55); }
  70%  { box-shadow: 0 0 0 14px rgba(37,211,102,0);  }
  100% { box-shadow: 0 0 0 0   rgba(37,211,102,0);   }
}

/* Popup entrance */
@keyframes wacc-popup-in {
  from {
    opacity:   0;
    transform: scale(.85) translateY(20px);
  }
  to {
    opacity:   1;
    transform: scale(1)   translateY(0);
  }
}

/* Badge bounce */
@keyframes wacc-badge-bounce {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.25); }
}

/* Typing dots */
@keyframes wacc-dot {
  0%,80%,100% { transform: scale(0.6); opacity: .4; }
  40%          { transform: scale(1);   opacity: 1;  }
}

/* Slide-in for bubble */
@keyframes wacc-bubble-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}

/* Icon swap crossfade */
@keyframes wacc-icon-in  { from { opacity:0; transform: rotate(-90deg) scale(.6); } to { opacity:1; transform: rotate(0) scale(1); } }
@keyframes wacc-icon-out { from { opacity:1; transform: rotate(0) scale(1); } to { opacity:0; transform: rotate(90deg) scale(.6); } }

/* ── 3. Wrapper & Position ─────────────────────────────────────────────────── */
.wacc-wrapper {
  position: fixed;
  bottom:   var(--wacc-offset);
  z-index:  var(--wacc-z-fab);
  display:  flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.wacc-position-right {
  right: var(--wacc-offset);
  align-items: flex-end;
}

.wacc-position-left {
  left: var(--wacc-offset);
  align-items: flex-start;
}

/* ── 4. Floating Action Button ─────────────────────────────────────────────── */
.wacc-fab {
  position:  relative;
  width:     60px;
  height:    60px;
  border-radius: var(--wacc-radius-full);
  border:    none;
  cursor:    pointer;
  display:   flex;
  align-items: center;
  justify-content: center;
  background-color: var(--wacc-green);
  color: var(--wacc-white);
  box-shadow: 0 4px 20px rgba(37,211,102,.45);
  transition: transform .25s var(--wacc-transition),
              box-shadow .25s var(--wacc-ease),
              background-color .2s var(--wacc-ease);
  animation: wacc-pulse 2.5s infinite;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.wacc-fab:hover {
  transform: scale(1.10);
  box-shadow: 0 6px 28px rgba(37,211,102,.55);
  animation: none;
}

.wacc-fab:focus-visible {
  outline: 3px solid rgba(37,211,102,.6);
  outline-offset: 3px;
}

.wacc-fab:active {
  transform: scale(.95);
}

/* Icons inside FAB */
.wacc-fab-icon {
  position: absolute;
  width: 28px;
  height: 28px;
  transition: opacity .2s, transform .25s var(--wacc-transition);
}

.wacc-fab-icon--close {
  opacity: 0;
  transform: rotate(90deg) scale(.6);
}

/* Active state – popup open */
.wacc-fab.is-active .wacc-fab-icon--open {
  animation: wacc-icon-out .25s var(--wacc-ease) forwards;
}

.wacc-fab.is-active .wacc-fab-icon--close {
  animation: wacc-icon-in .25s var(--wacc-ease) .05s forwards;
  opacity: 0; /* start hidden, anim will show */
}

.wacc-fab.is-active {
  animation: none;
}

/* Notification badge */
.wacc-badge {
  position: absolute;
  top:    -4px;
  right:  -4px;
  min-width:  18px;
  height:     18px;
  padding: 0 4px;
  border-radius: var(--wacc-radius-full);
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid #fff;
  animation: wacc-badge-bounce 1.5s ease-in-out infinite;
  transition: opacity .2s;
}

.wacc-fab.is-active .wacc-badge {
  opacity: 0;
}

/* ── 5. Popup Card ─────────────────────────────────────────────────────────── */
.wacc-popup {
  position:      relative;
  width:         var(--wacc-popup-width);
  max-width:     calc(100vw - 2 * var(--wacc-offset));
  background:    var(--wacc-white);
  border-radius: var(--wacc-radius-lg);
  box-shadow:    var(--wacc-shadow-xl);
  overflow:      hidden;
  display:       none;  /* JS toggles this */
  z-index:       var(--wacc-z-popup);
  transform-origin: bottom right;
}

.wacc-position-left .wacc-popup {
  transform-origin: bottom left;
}

.wacc-popup.is-open {
  display: block;
  animation: wacc-popup-in .35s var(--wacc-transition) both;
}

/* ── 6. Popup Header ───────────────────────────────────────────────────────── */
.wacc-popup-header {
  background: var(--wacc-teal);
  padding: 20px 16px 20px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wacc-popup-header-content {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.wacc-header-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,.15);
  border-radius: var(--wacc-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

.wacc-header-icon svg {
  width: 24px;
  height: 24px;
}

.wacc-popup-title {
  margin: 0 0 2px;
  font-size: 16px;
  font-weight: 700;
  color: var(--wacc-white);
  line-height: 1.3;
}

.wacc-popup-subtitle {
  margin: 0;
  font-size: 12px;
  color: rgba(255,255,255,.8);
  line-height: 1.4;
}

.wacc-close-btn {
  flex-shrink: 0;
  width:  32px;
  height: 32px;
  border: none;
  background: rgba(255,255,255,.15);
  border-radius: var(--wacc-radius-full);
  cursor: pointer;
  color: var(--wacc-white);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  padding: 0;
}

.wacc-close-btn:hover  { background: rgba(255,255,255,.28); }
.wacc-close-btn svg    { width: 16px; height: 16px; }

/* ── 7. Popup Body – Single Agent ──────────────────────────────────────────── */
.wacc-popup-body {
  padding: 20px;
  background: #ece5dd; /* WhatsApp wallpaper */
  background-image:
    radial-gradient(circle at 20% 80%, rgba(255,255,255,.25) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(0,0,0,.04) 0%, transparent 50%);
}

.wacc-single-agent {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.wacc-agent-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wacc-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.wacc-avatar {
  width:  56px;
  height: 56px;
  border-radius: var(--wacc-radius-full);
  object-fit: cover;
  border: 3px solid var(--wacc-white);
  box-shadow: var(--wacc-shadow-sm);
}

.wacc-avatar-placeholder {
  width:  56px;
  height: 56px;
  border-radius: var(--wacc-radius-full);
  background: linear-gradient(135deg, var(--wacc-teal), var(--wacc-green));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--wacc-white);
  text-transform: uppercase;
  border: 3px solid var(--wacc-white);
  box-shadow: var(--wacc-shadow-sm);
}

.wacc-agent-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.wacc-agent-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--wacc-gray-800);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wacc-agent-title {
  font-size: 12px;
  color: var(--wacc-gray-600);
}

/* ── 8. Popup Body – Multi Agent ───────────────────────────────────────────── */
.wacc-choose-label {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--wacc-gray-600);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.wacc-agents-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wacc-agent-item {
  background: var(--wacc-white);
  border-radius: var(--wacc-radius-md);
  box-shadow: var(--wacc-shadow-sm);
  overflow: hidden;
  transition: transform .2s var(--wacc-ease), box-shadow .2s;
}

.wacc-agent-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--wacc-shadow-md);
}

.wacc-agent-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
}

.wacc-agent-link:focus-visible {
  outline: 2px solid var(--wacc-green);
  outline-offset: 2px;
}

.wacc-agent-link .wacc-avatar,
.wacc-agent-link .wacc-avatar-placeholder {
  width:  48px;
  height: 48px;
  font-size: 18px;
}

.wacc-agent-status-text {
  display: block;
  font-size: 11px;
  color: var(--wacc-gray-400);
}

.wacc-arrow {
  width:  18px;
  height: 18px;
  color: var(--wacc-gray-400);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── 9. Chat Bubble ────────────────────────────────────────────────────────── */
.wacc-bubble {
  position: relative;
  background: var(--wacc-white);
  border-radius: 0 var(--wacc-radius-md) var(--wacc-radius-md) var(--wacc-radius-md);
  padding: 12px 14px;
  box-shadow: var(--wacc-shadow-sm);
  animation: wacc-bubble-in .35s var(--wacc-ease) .15s both;
  max-width: 90%;
}

.wacc-bubble p {
  margin: 0;
  font-size: 14px;
  color: var(--wacc-gray-800);
  line-height: 1.55;
}

.wacc-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top:    8px solid var(--wacc-white);
  border-left:   8px solid transparent;
}

/* Typing indicator (optional enhancement via JS) */
.wacc-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 20px;
}

.wacc-typing span {
  width:  7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wacc-gray-400);
}

.wacc-typing span:nth-child(1) { animation: wacc-dot 1.2s ease-in-out infinite; }
.wacc-typing span:nth-child(2) { animation: wacc-dot 1.2s ease-in-out .2s infinite; }
.wacc-typing span:nth-child(3) { animation: wacc-dot 1.2s ease-in-out .4s infinite; }

/* ── 10. Chat Now Button ───────────────────────────────────────────────────── */
.wacc-chat-btn {
  display:         inline-flex;
  align-items:     center;
  justify-content: center;
  gap: 8px;
  width:           100%;
  padding:         14px 20px;
  border-radius:   var(--wacc-radius-md);
  background:      var(--wacc-green);
  color:           var(--wacc-white);
  font-size:       15px;
  font-weight:     700;
  text-decoration: none;
  transition:      transform .2s var(--wacc-transition),
                   box-shadow .2s var(--wacc-ease),
                   filter    .2s;
  box-shadow: 0 4px 14px rgba(37,211,102,.4);
  animation: wacc-bubble-in .35s var(--wacc-ease) .3s both;
}

.wacc-chat-btn:hover {
  filter:    brightness(1.08);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37,211,102,.5);
  color: var(--wacc-white);
  text-decoration: none;
}

.wacc-chat-btn:active {
  transform: translateY(0);
}

.wacc-chat-btn:focus-visible {
  outline: 3px solid rgba(37,211,102,.6);
  outline-offset: 2px;
}

.wacc-btn-icon {
  width:  20px;
  height: 20px;
  flex-shrink: 0;
}

/* ── 11. Popup Footer ──────────────────────────────────────────────────────── */
.wacc-popup-footer {
  padding: 10px 20px;
  background: var(--wacc-white);
  border-top: 1px solid var(--wacc-gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 11px;
  color: var(--wacc-gray-400);
}

.wacc-footer-icon {
  width:  14px;
  height: 14px;
}

.wacc-popup-footer strong {
  color: var(--wacc-gray-600);
}

/* ── 12. Backdrop ──────────────────────────────────────────────────────────── */
.wacc-backdrop {
  display:    none;
  position:   fixed;
  inset:      0;
  background: rgba(0,0,0,.35);
  z-index:    var(--wacc-z-backdrop);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: wacc-fade-in .2s var(--wacc-ease) both;
}

.wacc-backdrop.is-visible {
  display: block;
}

@keyframes wacc-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── 13. Status Indicators ─────────────────────────────────────────────────── */
.wacc-status-dot {
  position: absolute;
  bottom:   2px;
  right:    2px;
  width:    12px;
  height:   12px;
  border-radius: 50%;
  border: 2px solid var(--wacc-white);
}

.wacc-status-online  { background: #22c55e; }
.wacc-status-offline { background: var(--wacc-gray-400); }

/* Pulse on online */
.wacc-status-online::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid rgba(34,197,94,.5);
  animation: wacc-pulse-ring .9s ease-out infinite;
}

@keyframes wacc-pulse-ring {
  0%   { transform: scale(.85); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* ── 14. Shortcode Button ──────────────────────────────────────────────────── */
.wacc-shortcode-btn {
  display:         inline-flex;
  align-items:     center;
  gap: 8px;
  padding:         12px 22px;
  border-radius:   var(--wacc-radius-full);
  border:          none;
  background:      var(--wacc-green);
  color:           var(--wacc-white);
  font-size:       15px;
  font-weight:     600;
  cursor:          pointer;
  transition:      transform .2s, box-shadow .2s;
  box-shadow:      0 3px 12px rgba(37,211,102,.35);
}

.wacc-shortcode-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 18px rgba(37,211,102,.45);
}

/* ── 15. Responsive / Mobile ───────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --wacc-offset: 16px;
    --wacc-popup-width: calc(100vw - 32px);
  }

  .wacc-popup {
    border-radius: var(--wacc-radius-md);
  }

  .wacc-fab {
    width:  54px;
    height: 54px;
  }
}

/* ── 16. Reduced Motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration:   0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration:  0.01ms !important;
  }
}
