/* Raeforge Building Services — chat widget styles (preview build)
 * Brand: Deep Navy #0B1D3A, Forge Gold #C8963E, page bg #F7F8FA,
 * ink #1A1A2E, muted #5A6377, border #E2E6ED. Mobile-first.
 */

.rf-chat-root {
  --rf-navy: #0b1d3a;
  --rf-navy-hover: #142e55;
  --rf-gold: #c8963e;
  --rf-gold-hover: #b07f2d;
  --rf-bg: #f7f8fa;
  --rf-ink: #1a1a2e;
  --rf-muted: #5a6377;
  --rf-border: #e2e6ed;
  --rf-radius: 16px;
  font-family: "Plus Jakarta Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--rf-ink);
  z-index: 99990;
}

/* ---------- Launcher ---------- */
.rf-chat-launcher {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 99991;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 18px;
  border: none;
  border-radius: 999px;
  background: var(--rf-navy);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(11, 29, 58, 0.28);
  border-bottom: 3px solid var(--rf-gold);
}
.rf-chat-launcher:hover { background: var(--rf-navy-hover); }
.rf-chat-launcher-open { background: var(--rf-navy-hover); }

/* ---------- Panel ---------- */
.rf-chat-panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 82px;
  z-index: 99992;
  display: flex;
  flex-direction: column;
  height: min(580px, calc(100dvh - 98px));
  background: var(--rf-bg);
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-radius);
  box-shadow: 0 18px 48px rgba(11, 29, 58, 0.25);
  overflow: hidden;
}
.rf-chat-panel[hidden] { display: none; }

@media (min-width: 480px) {
  .rf-chat-panel {
    left: auto;
    right: 16px;
    width: 384px;
    bottom: 84px;
  }
}

.rf-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--rf-navy);
  color: #fff;
  border-bottom: 3px solid var(--rf-gold);
  flex: 0 0 auto;
}
.rf-chat-header-text { flex: 1 1 auto; min-width: 0; }
.rf-chat-title { font-weight: 700; font-size: 16px; line-height: 1.25; }
.rf-chat-subtitle { font-size: 12.5px; color: #cfd8e6; margin-top: 2px; }
.rf-chat-close {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border: none; border-radius: 8px;
  background: transparent; color: #fff;
  font-size: 24px; line-height: 1; cursor: pointer;
}
.rf-chat-close:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- Messages ---------- */
.rf-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.rf-chat-row { display: flex; }
.rf-chat-row-bot { justify-content: flex-start; }
.rf-chat-row-user { justify-content: flex-end; }
.rf-chat-bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.45;
  overflow-wrap: break-word;
}
.rf-chat-bubble-bot {
  background: #fff;
  border: 1px solid var(--rf-border);
  border-bottom-left-radius: 4px;
}
.rf-chat-bubble-user {
  background: var(--rf-navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.rf-chat-bubble a { color: var(--rf-gold-hover); font-weight: 600; }
.rf-chat-bubble-user a { color: #f3e9d2; }

/* ---------- Chips ---------- */
.rf-chat-chips {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--rf-border);
  max-height: 132px;
  overflow-y: auto;
}
.rf-chat-chips:empty { display: none; }
.rf-chat-chip {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--rf-gold);
  background: #fff;
  color: var(--rf-navy);
  cursor: pointer;
}
.rf-chat-chip:hover { background: #f3e9d2; }
.rf-chat-chip-selected {
  background: var(--rf-gold);
  color: var(--rf-navy);
}

/* ---------- Input row ---------- */
.rf-chat-form {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--rf-border);
}
.rf-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 15px;
  padding: 11px 13px;
  border: 1.5px solid var(--rf-border);
  border-radius: 10px;
  color: var(--rf-ink);
  background: #fff;
}
.rf-chat-input:focus { outline: none; border-color: var(--rf-gold); }
.rf-chat-send {
  flex: 0 0 auto;
  width: 46px;
  border: none;
  border-radius: 10px;
  background: var(--rf-gold);
  color: var(--rf-navy);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.rf-chat-send:hover { background: var(--rf-gold-hover); color: #fff; }

/* ---------- Rae: avatar, motion, teaser, typing ---------- */
.rf-chat-avatar {
  display: inline-flex;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
}
.rf-chat-avatar svg { display: block; }
.rf-chat-header .rf-chat-avatar { width: 38px; height: 38px; }
.rf-chat-row-bot { align-items: flex-end; gap: 7px; }

/* Panel open/close motion */
.rf-chat-panel:not([hidden]) { animation: rf-panel-in 0.26s ease-out; }
@keyframes rf-panel-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Launcher attention pulse — the class is added by JS for a few cycles
 * shortly after page load, then removed; it never loops forever. */
.rf-chat-launcher-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  box-shadow: 0 0 0 0 rgba(200, 150, 62, 0.5);
  animation: rf-pulse 1.5s ease-out 3;
  pointer-events: none;
}
@keyframes rf-pulse {
  0% { box-shadow: 0 0 0 0 rgba(200, 150, 62, 0.5); }
  100% { box-shadow: 0 0 0 16px rgba(200, 150, 62, 0); }
}

/* Teaser bubble */
.rf-chat-teaser {
  position: fixed;
  right: 16px;
  bottom: 88px;
  z-index: 99991;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(276px, calc(100vw - 32px));
  padding: 11px 32px 11px 12px;
  background: #fff;
  border: 1px solid var(--rf-border);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(11, 29, 58, 0.22);
  font-size: 14px;
  line-height: 1.4;
  color: var(--rf-ink);
  cursor: pointer;
  animation: rf-teaser-in 0.3s ease-out;
}
.rf-chat-teaser[hidden] { display: none; }
.rf-chat-teaser .rf-chat-avatar { width: 30px; height: 30px; }
.rf-chat-teaser-close {
  position: absolute;
  top: 2px;
  right: 5px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--rf-muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.rf-chat-teaser-close:hover { background: var(--rf-bg); color: var(--rf-ink); }
@keyframes rf-teaser-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Typing indicator */
.rf-chat-typing-row { display: none; }
.rf-chat-typing-row.rf-on { display: flex; }
.rf-chat-bubble-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 15px;
}
.rf-chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rf-muted);
  opacity: 0.35;
  animation: rf-dot 1.1s ease-in-out infinite;
}
.rf-chat-dot:nth-child(2) { animation-delay: 0.15s; }
.rf-chat-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes rf-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-3px); opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  .rf-chat-panel:not([hidden]),
  .rf-chat-teaser { animation: none; }
  .rf-chat-launcher-pulse::after { animation: none; box-shadow: none; }
  .rf-chat-dot { animation: none; opacity: 0.5; }
}
