/* Widget-only styles (no global page reset/background). */

.hidden {
  display: none !important;
}

#wafi-btn,
#wafi-popup,
#wafi-notif {
  font-family: 'Inter', sans-serif;
}

#wafi-btn {
  position: fixed;
  bottom: 10px;
  left: 20px;
  /* Bottom left as requested */
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  border: none;
  cursor: pointer;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(22, 163, 74, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse-ring 2s infinite;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4);
  }

  70% {
    box-shadow: 0 0 0 15px rgba(22, 163, 74, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(22, 163, 74, 0);
  }
}

#wafi-btn:hover {
  transform: scale(1.05);
}

.wafi-btn-icon {
  position: absolute;
  width: 100%;
  height: 100%;
  transition: opacity 0.3s ease, transform 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wafi-btn-icon.open {
  overflow: hidden;
  border-radius: 50%;
}

.wafi-btn-icon.open img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wafi-btn-icon.open svg,
.wafi-btn-icon.close svg {
  width: 30px;
  height: 30px;
}

.wafi-btn-icon.close {
  opacity: 0;
  transform: rotate(-90deg);
}

#wafi-btn.active .wafi-btn-icon.open {
  opacity: 0;
  transform: rotate(90deg);
}

#wafi-btn.active .wafi-btn-icon.close {
  opacity: 1;
  transform: rotate(0deg);
}

#wafi-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ff4757;
  color: white;
  font-size: 12px;
  font-weight: bold;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
}

/* 2. Notification Bubble */
#wafi-notif {
  position: fixed;
  bottom: 80px;
  left: 20px;
  background: white;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  font-size: 14px;
  font-weight: 500;
  color: #333;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #eee;
  animation: slide-up 0.3s ease;
}

#wafi-notif span {
  white-space: pre-line;
  line-height: 1.35;
  max-width: 250px;
}

#wafi-notif-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #999;
}

#wafi-popup {
  position: fixed;
  bottom: 7px;
  left: 17px;
  /* Aligned to the left */
  width: 345px;
  height: 490px;
  max-height: calc(100vh - 110px);
  background:
    radial-gradient(circle at 18% 12%, rgba(34, 197, 94, 0.22), transparent 36%),
    radial-gradient(circle at 84% 90%, rgba(4, 120, 87, 0.15), transparent 40%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.98) 0%, rgba(244, 251, 247, 0.98) 48%, rgba(233, 247, 239, 0.98) 100%);
  border-radius: 16px;
  box-shadow: 0 22px 54px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(22, 163, 74, 0.10);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  border: 1px solid rgba(22, 163, 74, 0.12);
}

#wafi-popup.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

#wafi-popup.minimized {
  height: 70px !important;
}

#wafi-popup.minimized #wafi-messages,
#wafi-popup.minimized .wafi-input-area,
#wafi-popup.minimized #wafi-suggestions,
#wafi-popup.minimized #wafi-typing,
#wafi-popup.minimized .wafi-tabs,
#wafi-popup.minimized #wafi-history-view {
  display: none !important;
}

/* Header */
.wafi-header {
  background:
    linear-gradient(135deg, rgba(22, 163, 74, 0.96) 0%, rgba(4, 120, 87, 0.98) 100%);
  padding: 15px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  box-shadow: 0 10px 24px rgba(4, 120, 87, 0.16);
}

.wafi-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wafi-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  position: relative;
  overflow: hidden;
}

.wafi-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #2ed573;
  border-radius: 50%;
  border: 2px solid #047857;
}

.wafi-title {
  font-weight: 600;
  font-size: 15px;
}

.wafi-status {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}

.wafi-header-actions {
  display: flex;
  gap: 8px;
}

.wafi-icon-btn {
  background: none;
  border: none;
  color: white;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.wafi-icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.wafi-icon-btn.danger:hover {
  background: rgba(255, 71, 87, 0.8);
}

.wafi-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(22, 163, 74, 0.12);
}

.wafi-tab {
  flex: 1;
  border: 1px solid rgba(22, 163, 74, 0.14);
  background: rgba(248, 250, 252, 0.92);
  color: #047857;
  border-radius: 10px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.wafi-tab.active {
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  color: white;
  box-shadow: 0 8px 18px rgba(22, 163, 74, 0.18);
}

.wafi-view {
  display: none;
  min-height: 0;
}

.wafi-view.active {
  display: flex;
  flex: 1;
  min-height: 0;
}

#wafi-chat-view {
  flex-direction: column;
}

#wafi-history-view,
#wafi-important-view {
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  background:
    radial-gradient(circle at 12% 0%, rgba(34, 197, 94, 0.10), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.72) 0%, rgba(244, 251, 247, 0.9) 100%);
}

#wafi-history-list,
#wafi-important-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-empty {
  margin: auto;
  max-width: 240px;
  text-align: center;
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.history-item {
  border: 1px solid rgba(22, 163, 74, 0.10);
  background: rgba(255, 255, 255, 0.94);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.05);
}

.wafi-thread-item {
  cursor: pointer;
  position: relative;
  padding-right: 62px;
  min-height: 78px;
  padding-bottom: 14px;
  user-select: none;
}

.wafi-thread-item.active {
  border-color: rgba(22, 163, 74, 0.30);
  box-shadow: 0 10px 22px rgba(22, 163, 74, 0.14);
}

.history-role-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.wafi-thread-rename {
  position: absolute;
  right: 10px;
  top: 10px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid rgba(22, 163, 74, 0.25);
  background: rgba(248, 250, 252, 0.96);
  color: #047857;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.wafi-thread-rename:hover {
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  color: white;
  border-color: transparent;
}

.wafi-thread-delete {
  position: absolute;
  right: 10px;
  top: 38px;
  /* just below Rename */
  width: 32px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.25);
  background: rgba(248, 250, 252, 0.96);
  color: #ef4444;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.wafi-thread-delete svg {
  width: 16px;
  height: 16px;
}

.wafi-thread-delete:hover {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.45);
}

.history-item.user {
  border-color: rgba(22, 163, 74, 0.20);
}

.history-role {
  color: #047857;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.wafi-thread-star {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(248, 250, 252, 0.95);
  color: #94a3b8;
  cursor: pointer;
  transition: all 0.2s ease;
}

.wafi-thread-star svg {
  width: 13px;
  height: 13px;
}

.wafi-thread-star:hover {
  border-color: rgba(250, 204, 21, 0.5);
  color: #d97706;
}

.wafi-thread-star.active {
  color: #f59e0b;
  border-color: rgba(250, 204, 21, 0.8);
  background: rgba(254, 249, 195, 0.9);
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.18), 0 0 14px rgba(250, 204, 21, 0.35);
}

.wafi-important-toast {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 1200;
}

.wafi-important-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.history-text {
  color: #334155;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

/* Messages Area */
#wafi-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
  background:
    radial-gradient(circle at 14% -6%, rgba(34, 197, 94, 0.14), transparent 34%),
    radial-gradient(circle at 92% 105%, rgba(16, 185, 129, 0.12), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.70) 0%, rgba(241, 250, 245, 0.88) 100%);
}

.msg-row {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: slide-up 0.3s ease;
}

.msg-row.bot {
  align-self: flex-start;
}

.msg-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
}

.bot .msg-avatar {
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  color: white;
}

.user .msg-avatar {
  background: #e1e8ed;
  color: #333;
}

.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user .msg-bubble-wrap {
  align-items: flex-end;
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.bot .msg-bubble {
  background: rgba(255, 255, 255, 0.94);
  color: #333;
  border: 1px solid rgba(22, 163, 74, 0.10);
  border-top-left-radius: 4px;
}

.user .msg-bubble {
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  color: white;
  border-top-right-radius: 4px;
}

.msg-time {
  font-size: 11px;
  color: #999;
  margin-top: 2px;
}

/* Typing Indicator */
#wafi-typing {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(244, 251, 247, 0.86);
}

.wafi-av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
}

.wafi-dots {
  background: rgba(255, 255, 255, 0.94);
  padding: 10px 15px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  border: 1px solid rgba(22, 163, 74, 0.10);
  display: flex;
  gap: 4px;
}

.wafi-dots span {
  width: 6px;
  height: 6px;
  background: #a4b0be;
  border-radius: 50%;
  animation: blink 1.4s infinite both;
}

.wafi-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.wafi-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0% {
    opacity: 0.2;
    transform: scale(0.8);
  }

  20% {
    opacity: 1;
    transform: scale(1.2);
  }

  100% {
    opacity: 0.2;
    transform: scale(0.8);
  }
}

/* Suggestions */
#wafi-suggestions {
  padding: 10px 20px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  background: rgba(248, 252, 250, 0.88);
  border-top: 1px solid rgba(22, 163, 74, 0.12);
  backdrop-filter: blur(10px);
}

#wafi-suggestions::-webkit-scrollbar {
  display: none;
}

.sug-btn {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #16a34a;
  color: #047857;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.sug-btn:hover {
  background: #16a34a;
  color: white;
}

/* Input Area */
.wafi-input-area {
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid rgba(22, 163, 74, 0.12);
  backdrop-filter: blur(10px);
}

.wafi-input-wrap {
  display: flex;
  align-items: flex-end;
  background: rgba(248, 250, 252, 0.96);
  border-radius: 20px;
  padding: 8px 15px;
  border: 1px solid transparent;
  transition: border 0.3s;
}

.wafi-input-wrap:focus-within {
  border: 1px solid #16a34a;
  background: white;
}

#wafi-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 5px 0;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 80px;
}

#wafi-send {
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 10px;
  margin-bottom: 2px;
  transition: transform 0.2s;
}

#wafi-send:hover {
  transform: scale(1.1);
}

#wafi-send svg {
  width: 16px;
  height: 16px;
}

.wafi-footer {
  text-align: center;
  font-size: 10px;
  color: #a4b0be;
  margin-top: 10px;
}

.wafi-footer a {
  color: #047857;
  text-decoration: none;
}

/* Lead Form */
.lead-form-container {
  margin-top: 10px;
  background: #f8f9fa;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #eee;
}

.lead-form-container input {
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.lead-form-container button {
  width: 100%;
  padding: 10px;
  background: linear-gradient(135deg, #16a34a 0%, #047857 100%);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

/* Animations */
@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */
/* @media (max-width: 480px) {
  #wafi-popup {
    width: 100%;
    height: 100%;
    max-height: 100%;
    bottom: 0;
    left: 0;
    border-radius: 0;
  }
} */

@media (max-width: 480px) {
  .wafi-input-area {
    position: sticky;
    bottom: 0;
    background: white;
    z-index: 10;
    padding-bottom: 10px;
  }

  .wafi-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  #wafi-input {
    flex: 1;
    min-width: 0;
  }
}