/* ── Chat widget — floating AI assistant ───────────────────────────────────── */

#rw-chat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 900;
  height: 52px;
  border-radius: 28px;
  padding: 0 20px 0 16px;
  gap: 8px;
  background: #2563eb;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37,99,235,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s, box-shadow .15s;
}
#rw-chat-btn:hover { transform: scale(1.04); box-shadow: 0 6px 20px rgba(37,99,235,.45); }
#rw-chat-btn svg   { display: block; flex-shrink: 0; }
.rw-chat-label {
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

#rw-chat-bubble {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 901;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 110px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(16px) scale(.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), opacity .15s;
}
#rw-chat-bubble.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
.rw-chat-head {
  background: #2563eb;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.rw-chat-head-icon {
  width: 36px; height: 36px;
  background: rgba(255,255,255,.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.rw-chat-head-title   { font-weight: 700; font-size: 14px; line-height: 1.2; }
.rw-chat-head-sub     { font-size: 11px; opacity: .8; margin-top: 1px; }
.rw-chat-close {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  color: #fff; opacity: .7; padding: 4px;
  line-height: 1; font-size: 18px;
  transition: opacity .15s;
}
.rw-chat-close:hover { opacity: 1; }

/* Messages */
.rw-chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.rw-msg { display: flex; flex-direction: column; max-width: 88%; min-width: 0; }
.rw-msg--bot  { align-self: flex-start; }
.rw-msg--user { align-self: flex-end; }

.rw-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 0;
}
.rw-msg--bot  .rw-msg-bubble { background: #f1f5f9; color: #1e293b; border-bottom-left-radius: 4px; }
.rw-msg--user .rw-msg-bubble { background: #2563eb; color: #fff; border-bottom-right-radius: 4px; }

.rw-msg-time {
  font-size: 10px; color: #94a3b8;
  margin-top: 3px;
  padding: 0 4px;
}
.rw-msg--user .rw-msg-time { text-align: right; }

/* Typing indicator */
.rw-typing { display: flex; align-items: center; gap: 4px; padding: 8px 12px; }
.rw-typing span {
  width: 7px; height: 7px; background: #94a3b8; border-radius: 50%;
  animation: rw-bounce .8s infinite;
}
.rw-typing span:nth-child(2) { animation-delay: .15s; }
.rw-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes rw-bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

/* Auth / signup card */
.rw-auth-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 16px;
  font-size: 13px;
  width: 100%;
  max-width: 100%;
}
.rw-auth-card h4 { margin: 0 0 6px; font-size: 14px; color: #1e293b; }
.rw-auth-card p  { margin: 0 0 12px; color: #64748b; font-size: 12.5px; line-height: 1.4; }
.rw-auth-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 8px;
  box-sizing: border-box;
  outline: none;
  transition: border-color .15s;
}
.rw-auth-input:focus { border-color: #2563eb; }
.rw-auth-btn {
  width: 100%;
  padding: 9px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.rw-auth-btn:hover   { background: #1d4ed8; }
.rw-auth-btn:disabled { background: #93c5fd; cursor: default; }
.rw-auth-error { color: #ef4444; font-size: 12px; margin-top: 6px; }
.rw-auth-switch { font-size: 12px; color: #64748b; margin-top: 8px; text-align: center; }
.rw-auth-switch a { color: #2563eb; cursor: pointer; text-decoration: none; }

/* OTP input row */
.rw-otp-row { display: flex; gap: 6px; margin-bottom: 8px; }
.rw-otp-digit {
  flex: 1; padding: 10px 0; text-align: center;
  border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 20px; font-weight: 700;
  outline: none; width: 0;
  transition: border-color .15s;
}
.rw-otp-digit:focus { border-color: #2563eb; }

/* Input bar */
.rw-chat-foot {
  border-top: 1.5px solid #e2e8f0;
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;      /* badge gets its own row above textarea+button */
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: #fff;
  box-shadow: 0 -2px 8px rgba(0,0,0,.05);
}
.rw-chat-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 9px 14px;
  border: 1.5px solid #cbd5e1;
  border-radius: 20px;
  font-size: 13.5px;
  outline: none;
  resize: none;
  line-height: 1.4;
  background: #f1f5f9;
  transition: border-color .15s, background .15s;
  font-family: inherit;
  max-height: 80px;
  overflow-y: auto;
}
.rw-chat-input:focus { border-color: #2563eb; background: #fff; }
.rw-chat-input::placeholder { color: #94a3b8; }
.rw-send-btn {
  width: 36px; height: 36px;
  background: #2563eb; border: none; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: flex-end;
  transition: background .15s;
}
.rw-send-btn:hover    { background: #1d4ed8; }
.rw-send-btn:disabled { background: #93c5fd; cursor: default; }

/* Free-query counter badge */
.rw-free-badge {
  font-size: 11px;
  color: #64748b;
  text-align: center;
  padding: 4px 0 0;
  flex-basis: 100%;
}

/* Success greeting */
.rw-verified-badge {
  display: flex; align-items: center; gap: 6px;
  background: #f0fdf4; border: 1px solid #bbf7d0;
  border-radius: 10px; padding: 8px 12px;
  font-size: 12.5px; color: #166534;
}

/* Suggestions */
.rw-suggestions {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
}
.rw-suggestion-chip {
  background: #eff6ff; color: #2563eb;
  border: 1px solid #bfdbfe; border-radius: 12px;
  padding: 5px 10px; font-size: 12px; cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.rw-suggestion-chip:hover { background: #dbeafe; }

/* ── Premium panel — slightly wider ──────────────────────────────────────── */
#rw-chat-bubble.rw-premium {
  width: 400px;
}

/* "Full view ↗" link in premium header */
.rw-fullview-link {
  font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.15);
  border-radius: 6px; padding: 3px 8px;
  text-decoration: none; white-space: nowrap; flex-shrink: 0;
  transition: background .15s;
}
.rw-fullview-link:hover { background: rgba(255,255,255,.25); color: #fff; }

/* ── Chat map — full-width sibling of .rw-msg ────────────────────────────── */
.rw-chat-map-wrap {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  height: 280px;
  /* No width constraint: direct child of .rw-chat-msgs, so full panel width */
}
.rw-chat-map-wrap .leaflet-container {
  height: 100%; width: 100%;
  font-size: 12px;
}

/* ── Mobile: bottom-sheet layout ──────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Full-width bottom sheet anchored to screen bottom.
     dvh shrinks when the soft keyboard appears → input stays visible. */
  #rw-chat-bubble {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 90vh;
    height: 90dvh;
    max-height: 100%;
    border-radius: 20px 20px 0 0;

    /* Slide-up animation: start fully off-screen below, no fade */
    transform: translateY(100%);
    opacity: 1;
    transition: transform .35s cubic-bezier(.32,.72,0,1);
  }
  #rw-chat-bubble.open {
    transform: translateY(0);
    opacity: 1;
  }

  /* Hide the floating button while the panel is open */
  body.rw-open #rw-chat-btn { display: none; }

  #rw-chat-btn {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  /* Extra padding so the input bar clears notched-phone home bars */
  .rw-chat-foot {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  /* Suggestion chips: allow wrapping so they don't overflow narrow screens */
  .rw-suggestion-chip {
    white-space: normal;
    font-size: 11.5px;
  }

  /* Larger tap targets for send button on mobile */
  .rw-send-btn {
    width: 42px;
    height: 42px;
  }
}

/* ── Premium nudge card ──────────────────────────────────────────────────── */
.rw-nudge-card {
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  width: 100%;
  max-width: 100%;
}
.rw-nudge-tag {
  display: inline-block;
  background: #1d4ed8;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 99px;
  margin-bottom: 6px;
}
.rw-nudge-card strong { display: block; color: #1e293b; margin-bottom: 4px; font-size: 13.5px; }
.rw-nudge-card p { margin: 0 0 10px; color: #475569; font-size: 12.5px; line-height: 1.4; }
.rw-nudge-btn {
  display: block;
  text-align: center;
  background: #1d4ed8;
  color: #fff !important;
  text-decoration: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
}
.rw-nudge-btn:hover { background: #1e40af; }

/* ── Map legend ──────────────────────────────────────────────────────────── */
.rw-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 6px 10px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  font-size: 11.5px;
  color: #475569;
}
.rw-leg-item { display: flex; align-items: center; gap: 5px; }
.rw-leg-dot  { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
