/* ================================================================
   Chat Widget — Emma (AI Insurance Assistant)
   Standalone CSS — not processed by Tailwind
   ================================================================ */

.chat-widget {
  --chat-green: #047857;
  --chat-green-deep: #065f46;
  --chat-green-glow: rgba(4, 120, 87, 0.12);
  --chat-ink: #0c1220;
  --chat-charcoal: #1a2335;
  --chat-warm: #faf8f5;
  --chat-mist: #8b95a7;
  --chat-cloud: #e2e8f0;
  --chat-white: #ffffff;
  --chat-radius: 20px;
}

/* ── FAB (Floating Action Button) ─────────────────────────────── */

.chat-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--chat-green);
  color: var(--chat-white);
  border: none;
  cursor: pointer;
  z-index: 88;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(4, 120, 87, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: chatPulse 2s infinite;
}

.chat-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(4, 120, 87, 0.45);
}

.chat-trigger.is-open {
  animation: none;
}

.chat-trigger-icon,
.chat-trigger-close {
  width: 24px;
  height: 24px;
  transition: opacity 0.15s, transform 0.15s;
  position: absolute;
}

.chat-trigger-icon { opacity: 1; transform: scale(1); }
.chat-trigger-close { opacity: 0; transform: scale(0.5); }
.chat-trigger.is-open .chat-trigger-icon { opacity: 0; transform: scale(0.5); }
.chat-trigger.is-open .chat-trigger-close { opacity: 1; transform: scale(1); }

@keyframes chatPulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(4, 120, 87, 0.35); }
  50% { box-shadow: 0 4px 24px rgba(4, 120, 87, 0.55), 0 0 0 8px var(--chat-green-glow); }
}

/* ── Nudge Tooltip ────────────────────────────────────────────── */

.chat-nudge {
  position: fixed;
  bottom: 92px;
  right: 24px;
  background: var(--chat-white);
  color: var(--chat-ink);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  z-index: 88;
  max-width: 240px;
  font-size: 14px;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.chat-nudge.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.chat-nudge::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 28px;
  width: 12px;
  height: 12px;
  background: var(--chat-white);
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.06);
}

.chat-nudge-close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  color: var(--chat-mist);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
}

/* ── Chat Panel ───────────────────────────────────────────────── */

.chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-height: 560px;
  background: var(--chat-white);
  border-radius: var(--chat-radius);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  z-index: 89;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: scale(0.95) translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  overflow: hidden;
}

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

/* ── Header ───────────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--chat-charcoal);
  color: var(--chat-white);
  flex-shrink: 0;
  border-radius: var(--chat-radius) var(--chat-radius) 0 0;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--chat-white);
  flex-shrink: 0;
}

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

.chat-header-name {
  font-weight: 600;
  font-size: 15px;
}

.chat-header-status {
  font-size: 12px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.chat-header-btn {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.chat-header-btn:hover {
  color: var(--chat-white);
  background: rgba(255, 255, 255, 0.1);
}

.chat-header-btn svg {
  width: 18px;
  height: 18px;
}

/* ── Messages Area ────────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--chat-warm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  animation: chatMsgIn 0.15s ease-out;
  word-wrap: break-word;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--chat-green);
  color: var(--chat-white);
  border-radius: 16px 16px 4px 16px;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--chat-white);
  color: var(--chat-ink);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.chat-msg-assistant strong { font-weight: 600; }
.chat-msg-assistant em { font-style: italic; }
.chat-msg-assistant code {
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 13px;
}

.chat-msg-assistant ul,
.chat-msg-assistant ol {
  margin: 6px 0;
  padding-left: 18px;
}

.chat-msg-assistant li {
  margin-bottom: 2px;
}

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

/* ── Typing Indicator ─────────────────────────────────────────── */

.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--chat-white);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-mist);
  animation: chatDotBounce 0.6s infinite alternate;
}

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

@keyframes chatDotBounce {
  0% { transform: translateY(0); opacity: 0.4; }
  100% { transform: translateY(-4px); opacity: 1; }
}

/* ── Lead Capture Card ────────────────────────────────────────── */

.chat-lead-card {
  margin: 8px 0;
  padding: 14px;
  background: var(--chat-white);
  border: 1px solid var(--chat-cloud);
  border-radius: 12px;
  animation: chatMsgIn 0.2s ease-out;
}

.chat-lead-card h4 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--chat-ink);
}

.chat-lead-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--chat-cloud);
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.chat-lead-input:focus {
  border-color: var(--chat-green);
}

.chat-lead-input.has-error {
  border-color: #ef4444;
}

.chat-lead-error {
  color: #ef4444;
  font-size: 12px;
  margin: -4px 0 6px;
}

.chat-lead-submit {
  width: 100%;
  padding: 9px;
  background: var(--chat-green);
  color: var(--chat-white);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.chat-lead-submit:hover {
  background: var(--chat-green-deep);
}

.chat-lead-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-lead-success {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  color: var(--chat-green-deep);
  font-size: 14px;
  font-weight: 500;
}

.chat-lead-success svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ── Input Area ───────────────────────────────────────────────── */

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--chat-cloud);
  background: var(--chat-white);
  border-radius: 0 0 var(--chat-radius) var(--chat-radius);
}

.chat-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  font-size: 14px;
  line-height: 1.4;
  max-height: 80px;
  padding: 6px 0;
  font-family: inherit;
  color: var(--chat-ink);
  background: transparent;
}

.chat-input::placeholder {
  color: var(--chat-mist);
}

.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-green);
  color: var(--chat-white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.chat-send:hover {
  background: var(--chat-green-deep);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send svg {
  width: 18px;
  height: 18px;
}

/* ── Mobile (below xl breakpoint / 1280px) ────────────────────── */

@media (max-width: 1279px) {
  .chat-trigger {
    bottom: 80px; /* clear fixed CTA bar */
  }

  .chat-nudge {
    bottom: 148px;
  }

  .chat-panel.is-open {
    inset: 0;
    width: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .chat-header {
    border-radius: 0;
  }

  .chat-input-area {
    border-radius: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  /* Hide FAB when panel is open on mobile */
  .chat-trigger.is-open {
    display: none;
  }
}

/* ── Scrollbar ────────────────────────────────────────────────── */

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

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-cloud);
  border-radius: 2px;
}
