/* =========================================================
   AWBY Tutoring — Chat / Lead-Capture Widget
   Self-contained FAQ bot, bottom-right on every page.
   ========================================================= */

.chat-fab {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 70;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--gradient-brand);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: transform var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) ease;
}

.chat-fab svg {
  width: 26px;
  height: 26px;
}

.chat-fab__icon-close {
  display: none;
}

.chat-fab.is-open .chat-fab__icon-chat {
  display: none;
}

.chat-fab.is-open .chat-fab__icon-close {
  display: block;
}

@media (hover: hover) {
  .chat-fab:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: var(--glow-purple);
  }
}

.chat-fab:active {
  transform: scale(0.95);
}

.chat-fab__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e0457b;
  border: 2px solid var(--color-white);
}

@keyframes chat-fab-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(109, 40, 217, 0.35); }
  50% { box-shadow: 0 0 0 10px rgba(109, 40, 217, 0); }
}

.chat-fab:not(.is-open) {
  animation: chat-fab-pulse 2.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .chat-fab:not(.is-open) {
    animation: none;
  }
}

.chat-panel {
  position: fixed;
  right: var(--space-5);
  bottom: calc(var(--space-5) + 74px);
  z-index: 70;
  width: min(360px, calc(100vw - 2 * var(--space-5)));
  max-height: min(560px, calc(100vh - 140px));
  background: var(--color-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.9) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms var(--ease-standard), opacity 220ms var(--ease-standard);
}

.chat-panel.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel {
    transition: none;
  }
}

.chat-panel__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--gradient-brand);
  color: var(--color-white);
  flex-shrink: 0;
}

.chat-panel__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-panel__avatar svg {
  width: 20px;
  height: 20px;
}

.chat-panel__title {
  font-weight: 700;
  font-size: var(--text-sm);
  line-height: 1.3;
}

.chat-panel__subtitle {
  font-size: 0.75rem;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-panel__subtitle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}

.chat-panel__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chat-bubble {
  background: var(--color-bg-alt);
  color: var(--color-text);
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  line-height: 1.5;
  max-width: 90%;
  align-self: flex-start;
}

.chat-bubble a {
  color: var(--color-primary);
}

.chat-bubble--user {
  background: var(--gradient-brand);
  color: var(--color-white);
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: 4px;
  align-self: flex-end;
}

.chat-quick-replies {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-self: stretch;
}

.chat-quick-reply {
  text-align: left;
  background: var(--color-white);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-blob-alt);
  padding: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary-strong);
  cursor: pointer;
  transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease,
    color var(--duration-fast) ease, transform var(--duration-fast) ease;
}

@media (hover: hover) {
  .chat-quick-reply:hover {
    border-color: var(--color-purple-700);
    background: var(--color-purple-700);
    color: var(--color-white);
    transform: translateX(2px) scale(1.03);
  }
}

.chat-panel__footer {
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  flex-shrink: 0;
}

.chat-lead-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  align-self: stretch;
}

.chat-lead-form input,
.chat-lead-form textarea {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-family: inherit;
  width: 100%;
}

.chat-lead-form textarea {
  min-height: 60px;
  resize: vertical;
}

.chat-typing {
  display: flex;
  gap: 4px;
  align-self: flex-start;
  background: var(--color-bg-alt);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-top-left-radius: 4px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing span {
    animation: none;
  }
}

@media (max-width: 480px) {
  .chat-panel {
    right: var(--space-3);
    left: var(--space-3);
    width: auto;
    bottom: calc(var(--space-4) + 70px);
  }
  .chat-fab {
    right: var(--space-4);
    bottom: var(--space-4);
  }
}
