/* ===== CHAT WIDGET — Emma AI Assistant ===== */
/* Design tokens mapped to site's Tailwind palette */

.chat-widget {
  --chat-navy: #0f172a;
  --chat-navy-light: #1e293b;
  --chat-gold: #d4a843;
  --chat-gold-light: #e4c373;
  --chat-warm: #faf8f5;
  --chat-cream: #f5f0eb;
  --chat-ink: #0f172a;
  --chat-mist: #596879;
  --chat-cloud: #e2e8f0;
  --chat-success: #059669;
  --chat-error: #dc2626;
  --chat-white: #ffffff;
  --chat-radius: 16px;
  --chat-radius-sm: 8px;
  font-family: "Geist", system-ui, -apple-system, sans-serif;
}

/* ===== TRIGGER FAB ===== */
.chat-trigger {
  position: fixed;
  bottom: 80px; /* above sticky call button on mobile */
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--chat-gold);
  color: var(--chat-navy);
  border: none;
  cursor: pointer;
  z-index: 88;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(212, 168, 67, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}

@media (min-width: 768px) {
  .chat-trigger {
    bottom: 24px; /* no call button on desktop */
  }
}

.chat-trigger:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(212, 168, 67, 0.45);
}

.chat-trigger svg {
  width: 24px;
  height: 24px;
}

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

.chat-widget.is-open .chat-trigger-icon { display: none; }
.chat-widget.is-open .chat-trigger-close { display: block; }

.chat-trigger-pulse {
  animation: chatPulse 2s infinite;
}

@keyframes chatPulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(212, 168, 67, 0.35); }
  50% { box-shadow: 0 4px 24px rgba(212, 168, 67, 0.55), 0 0 0 8px rgba(212, 168, 67, 0.1); }
}

/* ===== NUDGE TOOLTIP ===== */
.chat-nudge {
  position: fixed;
  bottom: 148px; /* above FAB on mobile */
  right: 24px;
  background: var(--chat-white);
  color: var(--chat-ink);
  padding: 10px 16px;
  border-radius: var(--chat-radius-sm);
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  font-size: 0.875rem;
  line-height: 1.4;
  max-width: 260px;
  z-index: 87;
  display: none;
  animation: chatNudgeIn 0.3s ease-out;
}

@media (min-width: 768px) {
  .chat-nudge {
    bottom: 92px;
  }
}

.chat-nudge.is-visible { display: flex; align-items: center; gap: 8px; }

.chat-nudge-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--chat-mist);
  font-size: 1rem;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

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

/* ===== CHAT PANEL ===== */
.chat-panel {
  position: fixed;
  bottom: 148px; /* above FAB on mobile */
  right: 24px;
  width: 380px;
  max-height: 560px;
  background: var(--chat-white);
  border-radius: var(--chat-radius) var(--chat-radius) var(--chat-radius-sm) var(--chat-radius);
  box-shadow: 0 12px 48px rgba(0,0,0,0.15);
  z-index: 89;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: chatPanelIn 0.2s ease-out;
}

@media (min-width: 768px) {
  .chat-panel {
    bottom: 96px;
  }
}

.chat-widget.is-open .chat-panel { display: flex; }

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

/* Mobile: full screen */
@media (max-width: 640px) {
  .chat-panel {
    inset: 0;
    width: 100%;
    max-height: 100%;
    border-radius: 0;
    bottom: 0;
    right: 0;
  }
  .chat-widget.is-open .chat-trigger {
    display: none;
  }
}

/* ===== HEADER ===== */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--chat-navy);
  color: var(--chat-white);
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

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

.chat-header-name {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
}

.chat-header-status {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-success);
  display: inline-block;
}

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

.chat-header-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
}

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

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

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

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

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

.chat-message-user {
  align-self: flex-end;
  background: var(--chat-gold);
  color: var(--chat-navy);
  border-radius: 16px 16px 4px 16px;
}

.chat-message-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);
}

/* Markdown-like formatting in assistant messages */
.chat-message-assistant p { margin: 0 0 8px 0; }
.chat-message-assistant p:last-child { margin-bottom: 0; }
.chat-message-assistant ul, .chat-message-assistant ol {
  margin: 4px 0 8px 0;
  padding-left: 18px;
}
.chat-message-assistant li { margin-bottom: 2px; }
.chat-message-assistant strong { font-weight: 600; }

/* ===== 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: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-mist);
  animation: chatBounce 0.6s infinite;
}

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

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

/* ===== LEAD CAPTURE CARD ===== */
.chat-lead-card {
  align-self: flex-start;
  background: var(--chat-white);
  border: 1px solid var(--chat-cloud);
  border-radius: var(--chat-radius-sm);
  padding: 14px;
  max-width: 90%;
  animation: chatMsgIn 0.15s ease-out;
}

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

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

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

.chat-lead-card input.has-error {
  border-color: var(--chat-error);
}

.chat-lead-submit {
  width: 100%;
  padding: 8px;
  background: var(--chat-gold);
  color: var(--chat-navy);
  border: none;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.chat-lead-submit:hover {
  background: var(--chat-gold-light);
}

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

.chat-lead-success {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--chat-success);
  font-size: 0.8125rem;
  font-weight: 500;
}

/* ===== 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);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--chat-cloud);
  border-radius: var(--chat-radius-sm);
  padding: 8px 12px;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.4;
  max-height: 100px;
  outline: none;
  transition: border-color 0.15s;
}

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

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

.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-gold);
  color: var(--chat-navy);
  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-gold-light); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

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

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  .chat-trigger,
  .chat-panel,
  .chat-message,
  .chat-nudge,
  .chat-typing-dot {
    animation: none !important;
    transition: none !important;
  }
}
