/* ============================================
   Floating Chat Widget - Complete Rewrite
   Desktop: Smooth animations + Glassmorphism
   Mobile: Liquid Glass effect
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
  --fcw-primary: #25D366;
  --fcw-secondary: #128C7E;
  --fcw-glass-bg: rgba(255, 255, 255, 0.72);
  --fcw-glass-border: rgba(255, 255, 255, 0.5);
  --fcw-glass-shadow: 0 8px 32px rgba(31, 38, 135, 0.15);
  --fcw-text: #1a1a2e;
  --fcw-text-light: #4a4a6a;
  --fcw-transition-fast: 0.2s ease;
  --fcw-transition-normal: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  --fcw-transition-bounce: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Widget Container ---------- */
.fcw-widget {
  position: fixed;
  bottom: 24px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.fcw-widget.fcw-position-right { right: 24px; }
.fcw-widget.fcw-position-left { left: 24px; }

/* ---------- Main Button ---------- */
.fcw-main-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--fcw-primary), var(--fcw-secondary));
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(37, 211, 102, 0.35), 0 0 0 1px rgba(255,255,255,0.1) inset;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 100000;
  padding: 0;
  opacity: 0;
  transform: scale(0) translateY(20px);
  transition: transform var(--fcw-transition-bounce), box-shadow var(--fcw-transition-fast);
}

/* Entrance animation - triggered by JS */
.fcw-main-btn.fcw-ready {
  animation: fcw-btn-in 0.6s var(--fcw-transition-bounce) forwards;
}

@keyframes fcw-btn-in {
  0% { opacity: 0; transform: scale(0) translateY(20px); }
  60% { opacity: 1; transform: scale(1.08) translateY(-3px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.fcw-main-btn:hover {
  transform: scale(1.12);
  box-shadow: 0 6px 28px rgba(37, 211, 102, 0.45), 0 0 0 1px rgba(255,255,255,0.15) inset;
}

.fcw-main-btn:active {
  transform: scale(0.92);
}

/* Icon */
.fcw-btn-icon {
  width: 26px;
  height: 26px;
  position: relative;
}

.fcw-btn-icon::before,
.fcw-btn-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: all var(--fcw-transition-normal);
}

/* Chat icon */
.fcw-btn-icon::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z'/%3E%3C/svg%3E");
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
  opacity: 1;
}

/* Close icon */
.fcw-btn-icon::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/%3E%3C/svg%3E");
  transform: translate(-50%, -50%) rotate(-90deg) scale(0.5);
  opacity: 0;
}

/* Active state - swap icons */
.fcw-widget.active .fcw-btn-icon::before {
  transform: translate(-50%, -50%) rotate(90deg) scale(0.5);
  opacity: 0;
}

.fcw-widget.active .fcw-btn-icon::after {
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
  opacity: 1;
}

/* Pulse ring */
.fcw-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--fcw-primary);
  animation: fcw-pulse-ring 2s ease-out infinite;
  pointer-events: none;
}

@keyframes fcw-pulse-ring {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* ---------- Toast ---------- */
.fcw-toast {
  position: absolute;
  bottom: 68px;
  right: 0;
  background: var(--fcw-glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--fcw-glass-border);
  border-radius: 14px;
  padding: 12px 18px;
  box-shadow: var(--fcw-glass-shadow);
  font-size: 14px;
  font-weight: 500;
  color: var(--fcw-text);
  max-width: 320px;
  width: max-content;
  white-space: nowrap;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.95);
  transform-origin: bottom right;
  transition: all var(--fcw-transition-normal);
  z-index: 99998;
  pointer-events: none;
}

.fcw-position-left .fcw-toast {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.fcw-toast.fcw-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.fcw-toast::after {
  content: '';
  position: absolute;
  bottom: -5px;
  right: 22px;
  width: 10px;
  height: 10px;
  background: var(--fcw-glass-bg);
  border-right: 1px solid var(--fcw-glass-border);
  border-bottom: 1px solid var(--fcw-glass-border);
  transform: rotate(45deg);
}

.fcw-position-left .fcw-toast::after {
  right: auto;
  left: 22px;
}

/* ---------- Panel (Desktop) ---------- */
.fcw-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 360px;
  max-height: 580px;
  background: var(--fcw-glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--fcw-glass-border);
  border-radius: 20px;
  box-shadow: var(--fcw-glass-shadow), 0 20px 60px rgba(0,0,0,0.1);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  transition: all var(--fcw-transition-normal);
  z-index: 99999;
}

.fcw-position-left .fcw-panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

.fcw-widget.active .fcw-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.fcw-header {
  background: linear-gradient(135deg, var(--fcw-primary), var(--fcw-secondary));
  padding: 18px 20px;
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.fcw-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  border: 2.5px solid rgba(255,255,255,0.35);
  flex-shrink: 0;
  background: #e0e0e0;
}

.fcw-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.fcw-header-info { flex: 1; min-width: 0; }
.fcw-header-info h4 {
  margin: 0 0 3px;
  font-size: 15px;
  font-weight: 600;
}

.fcw-status {
  margin: 0;
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 5px;
}

.fcw-status-dot {
  width: 7px;
  height: 7px;
  background: #7CFC00;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(124, 252, 0, 0.5);
  animation: fcw-dot-pulse 2s ease infinite;
}

@keyframes fcw-dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.fcw-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--fcw-transition-fast);
}

.fcw-close-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: rotate(90deg);
}

/* Body */
.fcw-body {
  padding: 18px;
  max-height: 420px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.15) transparent;
}

.fcw-body::-webkit-scrollbar { width: 4px; }
.fcw-body::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 4px;
}

/* Quick Actions */
.fcw-quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.fcw-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 8px;
  border-radius: 14px;
  text-decoration: none;
  color: white;
  font-size: 12px;
  font-weight: 600;
  gap: 6px;
  transition: all var(--fcw-transition-fast);
  position: relative;
  overflow: hidden;
}

.fcw-action-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
  opacity: 0;
  transition: opacity var(--fcw-transition-fast);
}

.fcw-action-btn:hover::before { opacity: 1; }

.fcw-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

.fcw-action-icon { font-size: 22px; line-height: 1; position: relative; z-index: 1; }
.fcw-action-btn span:last-child { position: relative; z-index: 1; }

.fcw-whatsapp { background: linear-gradient(135deg, #25D366, #128C7E); }
.fcw-email { background: linear-gradient(135deg, #EA4335, #C62828); }

/* Inquiry Section */
.fcw-inquiry-section {
  background: rgba(248, 249, 250, 0.8);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.fcw-inquiry-section h5 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fcw-text);
}

.fcw-form-group { margin-bottom: 10px; }

.fcw-form input,
.fcw-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 10px;
  font-size: 13px;
  background: rgba(255,255,255,0.7);
  transition: all var(--fcw-transition-fast);
  box-sizing: border-box;
  font-family: inherit;
  color: var(--fcw-text);
}

.fcw-form input:focus,
.fcw-form textarea:focus {
  outline: none;
  border-color: var(--fcw-primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.1);
}

.fcw-form textarea {
  resize: vertical;
  min-height: 70px;
}

.fcw-submit-btn {
  width: 100%;
  padding: 11px;
  background: linear-gradient(135deg, var(--fcw-primary), var(--fcw-secondary));
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--fcw-transition-fast);
  position: relative;
  overflow: hidden;
  font-family: inherit;
}

.fcw-submit-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.3);
}

.fcw-submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.fcw-btn-loader {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: fcw-spin 0.7s linear infinite;
  position: absolute;
  right: 14px;
  top: 50%;
  margin-top: -9px;
}

.fcw-submit-btn.loading .fcw-btn-loader { display: block; }

@keyframes fcw-spin {
  to { transform: rotate(360deg); }
}

.fcw-form-message {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  display: none;
}

.fcw-form-message.success {
  display: block;
  background: rgba(37, 211, 102, 0.1);
  color: #1b7a3a;
  border: 1px solid rgba(37, 211, 102, 0.2);
}

.fcw-form-message.error {
  display: block;
  background: rgba(234, 67, 53, 0.1);
  color: #c62828;
  border: 1px solid rgba(234, 67, 53, 0.2);
}

/* Other Channels */
.fcw-other-channels {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fcw-channel-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: rgba(248, 249, 250, 0.6);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: all var(--fcw-transition-fast);
  border: 1px solid transparent;
}

.fcw-channel-item:hover {
  background: rgba(255,255,255,0.9);
  border-color: rgba(0,0,0,0.05);
  transform: translateX(3px);
}

.fcw-channel-icon {
  font-size: 18px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.8);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  flex-shrink: 0;
}

.fcw-channel-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.fcw-channel-label {
  font-size: 11px;
  color: var(--fcw-text-light);
  margin-bottom: 1px;
}

.fcw-channel-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--fcw-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fcw-copy-btn {
  padding: 5px 12px;
  background: rgba(255,255,255,0.8);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--fcw-transition-fast);
  color: var(--fcw-text);
  font-family: inherit;
  flex-shrink: 0;
  font-weight: 500;
}

.fcw-copy-btn:hover {
  background: var(--fcw-primary);
  color: white;
  border-color: var(--fcw-primary);
}

.fcw-copy-btn.copied {
  background: #4CAF50;
  color: white;
  border-color: #4CAF50;
}

/* ---------- Mobile Bar ---------- */
.fcw-mobile-bar {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 32px rgba(31, 38, 135, 0.12), inset 0 1px 0 rgba(255,255,255,0.6);
  z-index: 99998;
  padding: 6px;
  gap: 6px;
  transition: all var(--fcw-transition-normal);
  max-width: 92%;
}

.fcw-mobile-btn {
  padding: 10px 22px;
  border-radius: 50px;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  border: none;
  cursor: pointer;
  transition: all var(--fcw-transition-fast);
  font-family: inherit;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  overflow: hidden;
}

.fcw-mobile-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.3), transparent);
  opacity: 0.5;
}

.fcw-mobile-whatsapp {
  background: linear-gradient(135deg, #25D366, #128C7E);
  color: white;
  box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}

.fcw-mobile-chat {
  background: linear-gradient(135deg, var(--fcw-primary), var(--fcw-secondary));
  color: white;
  box-shadow: 0 2px 8px rgba(37, 211, 102, 0.3);
}

.fcw-mobile-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ---------- Mobile Panel (Liquid Glass) ---------- */
@media screen and (max-width: 768px) {
  .fcw-main-btn { display: none; }
  .fcw-toast { display: none !important; }

  .fcw-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 88vh;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-bottom: none;
    box-shadow: 0 -8px 32px rgba(31, 38, 135, 0.1), inset 0 1px 0 rgba(255,255,255,0.5);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .fcw-widget.active .fcw-panel {
    transform: translateY(0);
  }

  .fcw-header {
    border-radius: 24px 24px 0 0;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(37, 211, 102, 0.9), rgba(18, 140, 126, 0.9));
  }

  .fcw-body {
    max-height: calc(88vh - 76px);
    background: rgba(255, 255, 255, 0.05);
  }

  .fcw-inquiry-section,
  .fcw-channel-item {
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.3);
  }

  .fcw-form input,
  .fcw-form textarea {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(255, 255, 255, 0.3);
  }

  .fcw-mobile-bar {
    display: flex;
  }

  .fcw-widget.active .fcw-mobile-bar {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(20px);
  }

  /* Mobile overlay */
  .fcw-widget::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: all var(--fcw-transition-normal);
    z-index: -1;
  }

  .fcw-widget.active::before {
    opacity: 1;
    visibility: visible;
  }
}

@media screen and (max-width: 380px) {
  .fcw-quick-actions { grid-template-columns: 1fr; }
  .fcw-mobile-btn { padding: 9px 16px; font-size: 12px; }
}

/* ---------- WeChat QR Inline ---------- */
.fcw-wechat-qr {
  padding: 12px 16px 10px;
  text-align: center;
  border-top: 1px solid rgba(0,0,0,0.06);
}

.fcw-wechat-qr img {
  width: 180px;
  height: 180px;
  object-fit: contain;
  border-radius: 10px;
  display: block;
  margin: 0 auto 8px;
}

.fcw-wechat-qr .fcw-qr-hint {
  font-size: 12px;
  color: var(--fcw-text-light);
  margin: 0;
  text-align: center;
}

/* ---------- Auto Hide / Show ---------- */
.fcw-main-btn.fcw-hidden {
  opacity: 0;
  transform: scale(0.8) translateY(20px);
  pointer-events: none;
  transition: all 0.4s ease;
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .fcw-widget *, .fcw-widget *::before, .fcw-widget *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
