/* ============================================
   Spencer AI — WebChat Widget
   Floating chat bubble + glassmorphic chat window
   ============================================ */

/* ===== CHAT BUBBLE (floating button) ===== */
.webchat-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 4px 24px rgba(59, 130, 246, 0.4), 0 0 0 0 rgba(59, 130, 246, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  animation: webchat-pulse 2.5s infinite;
}

.webchat-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 32px rgba(59, 130, 246, 0.5);
  animation: none;
}

.webchat-bubble.active {
  animation: none;
  transform: scale(1);
}

.webchat-bubble .bubble-icon-chat,
.webchat-bubble .bubble-icon-close {
  position: absolute;
  transition: opacity 0.2s ease, transform 0.2s ease;
  line-height: 1;
}

.webchat-bubble .bubble-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.webchat-bubble.active .bubble-icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.webchat-bubble.active .bubble-icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

@keyframes webchat-pulse {
  0%, 100% { box-shadow: 0 4px 24px rgba(59, 130, 246, 0.4), 0 0 0 0 rgba(59, 130, 246, 0.3); }
  50% { box-shadow: 0 4px 24px rgba(59, 130, 246, 0.4), 0 0 0 12px rgba(59, 130, 246, 0); }
}

/* ===== CHAT WINDOW ===== */
.webchat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 9998;
  width: 380px;
  height: 520px;
  border-radius: var(--border-radius-lg);
  background: rgba(10, 14, 26, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(59, 130, 246, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.webchat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ===== HEADER ===== */
.webchat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: rgba(15, 23, 42, 0.8);
  border-bottom: 1px solid var(--border);
}

.webchat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.webchat-header-info {
  flex: 1;
  min-width: 0;
}

.webchat-header-name {
  font-family: var(--font-main);
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--text-primary);
}

.webchat-header-status {
  font-size: var(--text-xs);
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 4px;
}

.webchat-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.webchat-header-badge {
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: rgba(59, 130, 246, 0.1);
  padding: 2px 8px;
  border-radius: var(--border-radius-full);
  border: 1px solid rgba(59, 130, 246, 0.15);
}

/* ===== MESSAGES AREA ===== */
.webchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.webchat-messages::-webkit-scrollbar {
  width: 4px;
}

.webchat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.webchat-messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.2);
  border-radius: 2px;
}

/* ===== MESSAGE BUBBLES ===== */
.wchat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-family: var(--font-main);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-primary);
  animation: msg-in 0.3s ease;
  word-wrap: break-word;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.wchat-msg-bot {
  align-self: flex-start;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.wchat-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.wchat-msg-bot strong, .wchat-msg-bot b {
  color: var(--accent);
  font-weight: 600;
}

.wchat-msg-bot em, .wchat-msg-bot i {
  color: var(--text-secondary);
}

.wchat-msg-bot code {
  background: rgba(59, 130, 246, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent);
}

/* ===== TYPING INDICATOR ===== */
.wchat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.wchat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.wchat-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.wchat-typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== INPUT BAR ===== */
.webchat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.8);
  border-top: 1px solid var(--border);
}

.webchat-input input {
  flex: 1;
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-full);
  padding: 10px 16px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--transition);
}

.webchat-input input::placeholder {
  color: var(--text-muted);
}

.webchat-input input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.webchat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.webchat-send:hover {
  transform: scale(1.1);
}

.webchat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ===== WELCOME MESSAGE ===== */
.wchat-welcome {
  text-align: center;
  padding: 20px 16px 8px;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.wchat-welcome-emoji {
  font-size: 40px;
  margin-bottom: 8px;
  display: block;
}

.wchat-welcome strong {
  color: var(--text-primary);
}

/* ===== POWERED BY ===== */
.webchat-powered {
  text-align: center;
  padding: 4px 0 8px;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.6;
}

/* ===== MOBILE ===== */
@media (max-width: 480px) {
  .webchat-window {
    width: calc(100vw - 16px);
    height: calc(100dvh - 100px);
    right: 8px;
    bottom: 80px;
    border-radius: 16px;
  }

  .webchat-bubble {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
    font-size: 24px;
  }
}
