/* Emma Chat Widget — Standalone CSS (not processed by Tailwind) */
.emma-widget {
  --emma-green: #047857;
  --emma-green-deep: #065f46;
  --emma-green-glow: rgba(4, 120, 87, 0.12);
  --emma-green-light: #ecfdf5;
  --emma-ink: #0c1220;
  --emma-charcoal: #1a2335;
  --emma-warm: #faf8f5;
  --emma-mist: #8b95a7;
  --emma-cloud: #e2e8f0;
  --emma-white: #ffffff;
  --emma-panel-w: 380px;
  --emma-panel-h: 560px;
  --emma-fab-size: 56px;
  --emma-z-fab: 9998;
  --emma-z-panel: 9999;
  --emma-radius: 20px;
}

/* ===== FAB (Floating Action Button) ===== */
.emma-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: var(--emma-fab-size);
  height: var(--emma-fab-size);
  border-radius: 50%;
  background: var(--emma-green);
  border: none;
  cursor: pointer;
  z-index: var(--emma-z-fab);
  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;
}
.emma-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(4, 120, 87, 0.45);
}
.emma-fab svg {
  width: 26px;
  height: 26px;
  fill: var(--emma-white);
  transition: transform 0.2s;
}
.emma-fab .emma-icon-close { display: none; }
.emma-widget.is-open .emma-fab .emma-icon-chat { display: none; }
.emma-widget.is-open .emma-fab .emma-icon-close { display: block; }

/* FAB pulse animation — 3 cycles then stop */
.emma-fab.pulse {
  animation: emma-pulse 2s 3;
}
@keyframes emma-pulse {
  0% { box-shadow: 0 4px 16px rgba(4, 120, 87, 0.35); }
  50% { box-shadow: 0 4px 16px rgba(4, 120, 87, 0.35), 0 0 0 12px rgba(4, 120, 87, 0.1); }
  100% { box-shadow: 0 4px 16px rgba(4, 120, 87, 0.35); }
}

/* ===== Nudge Tooltip ===== */
.emma-nudge {
  position: fixed;
  bottom: 90px;
  right: 24px;
  background: var(--emma-white);
  color: var(--emma-ink);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  font-size: 14px;
  line-height: 1.4;
  max-width: 260px;
  z-index: var(--emma-z-fab);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}
.emma-nudge.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.emma-nudge::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 24px;
  width: 12px;
  height: 12px;
  background: var(--emma-white);
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(0,0,0,0.05);
}
.emma-nudge-close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  font-size: 16px;
  color: var(--emma-mist);
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}

/* ===== Panel ===== */
.emma-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: var(--emma-panel-w);
  max-height: var(--emma-panel-h);
  background: var(--emma-white);
  border-radius: var(--emma-radius);
  box-shadow: 0 12px 48px rgba(0,0,0,0.15);
  z-index: var(--emma-z-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.95) translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.emma-widget.is-open .emma-panel {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* ===== Header ===== */
.emma-header {
  background: var(--emma-charcoal);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.emma-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}
.emma-header-info {
  flex: 1;
  min-width: 0;
}
.emma-header-name {
  color: var(--emma-white);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}
.emma-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--emma-mist);
}
.emma-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
}
.emma-header-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--emma-mist);
  transition: color 0.15s;
}
.emma-header-btn:hover {
  color: var(--emma-white);
}
.emma-header-btn svg {
  width: 18px;
  height: 18px;
}

/* ===== Messages ===== */
.emma-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--emma-warm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.emma-msg {
  max-width: 85%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: emma-msg-in 0.15s ease-out;
}
@keyframes emma-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.emma-msg-assistant {
  align-self: flex-start;
  background: var(--emma-white);
  color: var(--emma-ink);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.emma-msg-user {
  align-self: flex-end;
  background: var(--emma-green);
  color: var(--emma-white);
  border-radius: 16px 16px 4px 16px;
}

/* Typing indicator */
.emma-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--emma-white);
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.emma-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emma-mist);
  animation: emma-bounce 0.6s infinite alternate;
}
.emma-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.emma-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes emma-bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-5px); }
}

/* ===== Input Area ===== */
.emma-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--emma-cloud);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--emma-white);
  flex-shrink: 0;
}
.emma-input {
  flex: 1;
  border: 1px solid var(--emma-cloud);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 100px;
  overflow-y: auto;
  background: var(--emma-white);
  color: var(--emma-ink);
}
.emma-input:focus {
  border-color: var(--emma-green);
  box-shadow: 0 0 0 2px var(--emma-green-glow);
}
.emma-input::placeholder {
  color: var(--emma-mist);
}
.emma-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--emma-green);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
.emma-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.emma-send-btn:not(:disabled):hover {
  background: var(--emma-green-deep);
}
.emma-send-btn svg {
  width: 18px;
  height: 18px;
  fill: var(--emma-white);
}

/* ===== Inline Lead Form ===== */
.emma-lead-card {
  background: var(--emma-white);
  border-left: 3px solid var(--emma-green);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  animation: emma-msg-in 0.2s ease-out;
}
.emma-lead-card h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--emma-ink);
  margin: 0 0 10px;
}
.emma-lead-card input,
.emma-lead-card select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--emma-cloud);
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  outline: none;
  font-family: inherit;
  color: var(--emma-ink);
  background: var(--emma-white);
}
.emma-lead-card input:focus,
.emma-lead-card select:focus {
  border-color: var(--emma-green);
  box-shadow: 0 0 0 2px var(--emma-green-glow);
}
.emma-lead-submit {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--emma-green);
  color: var(--emma-white);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.emma-lead-submit:hover {
  background: var(--emma-green-deep);
}
.emma-lead-submit:disabled {
  opacity: 0.5;
  cursor: default;
}
.emma-lead-error {
  color: #dc2626;
  font-size: 12px;
  margin-top: -4px;
  margin-bottom: 6px;
}
.emma-lead-success {
  text-align: center;
  padding: 12px;
}
.emma-lead-success svg {
  width: 32px;
  height: 32px;
  fill: var(--emma-green);
  margin-bottom: 6px;
}
.emma-lead-success p {
  font-size: 14px;
  color: var(--emma-ink);
  font-weight: 500;
}

/* ===== Error message with CTA ===== */
.emma-error-cta {
  display: inline-block;
  margin-top: 6px;
  padding: 6px 14px;
  background: var(--emma-green);
  color: var(--emma-white);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s;
}
.emma-error-cta:hover {
  background: var(--emma-green-deep);
}

/* ===== Hidden utility ===== */
.emma-hidden { display: none !important; }

/* ===== Bridge: quote-form.js state classes inside .emma-lead-card =====
   The chat lead form is now wired into quote-form.js's lifecycle (refactor
   2026-04-19). quote-form.js toggles standard Tailwind-named classes on
   inputs and error spans, but chat-widget.css is NOT processed by Tailwind
   (per CLAUDE.md it's standalone), so those classes have no defined visual
   in this stylesheet. These rules give them an Emma-themed rendering so
   shared-form behavior works visually inside the chat panel. */
.emma-lead-card .hidden { display: none !important; }
.emma-lead-card input.border-red-500,
.emma-lead-card select.border-red-500 {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15) !important;
}
.emma-lead-card .form-error {
  color: #dc2626;
  font-size: 12px;
  margin-top: -4px;
  margin-bottom: 6px;
}
.emma-lead-card .form-error.hidden { display: none; }
.emma-lead-card .btn-disabled {
  opacity: 0.5;
  cursor: default;
}
/* The chat lead form lives inside `<form id="chat-lead-form">` rather than
   the loose div the old implementation used, so spacing for the inner
   form children needs to match the .emma-lead-card direct-child spacing
   the old layout produced. */
.emma-lead-card form > input,
.emma-lead-card form > select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--emma-cloud);
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  outline: none;
  font-family: inherit;
  color: var(--emma-ink);
  background: var(--emma-white);
}
.emma-lead-card form > input:focus,
.emma-lead-card form > select:focus {
  border-color: var(--emma-green);
  box-shadow: 0 0 0 2px var(--emma-green-glow);
}

/* ===== Mobile (full-screen panel) ===== */
@media (max-width: 640px) {
  .emma-panel {
    inset: 0;
    width: 100%;
    max-height: 100%;
    border-radius: 0;
    bottom: 0;
    right: 0;
  }
  .emma-widget.is-open .emma-fab {
    display: none;
  }
  .emma-fab {
    bottom: 80px; /* above sticky mobile CTA */
  }
  .emma-nudge {
    bottom: 146px;
    right: 16px;
    max-width: 240px;
  }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  .emma-panel,
  .emma-msg,
  .emma-nudge,
  .emma-lead-card {
    animation: none;
    transition: none;
  }
  .emma-fab.pulse {
    animation: none;
  }
  .emma-typing-dot {
    animation: none;
  }
}
