/* ==========================================================================
   Saarthi Parivaar — Care Assistant (guided lead-capture chatbot)
   Self-contained: only depends on the brand tokens declared in styles.css.
   ========================================================================== */

/* ---------- Floating launchers ----------
   Phone + WhatsApp sit bottom-left; the assistant sits bottom-right so the
   two never compete for the same thumb zone. */
.sp-dock {
  position: fixed;
  bottom: 22px;
  z-index: 400;
  display: flex;
  flex-direction: column-reverse;
  gap: 12px;
}
.sp-dock--left { left: 22px; align-items: flex-start; }
.sp-dock--right { right: 22px; align-items: flex-end; }

.sp-dock__btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.sp-dock__btn:hover { transform: scale(1.07); }
.sp-dock__btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }
.sp-dock__btn svg { width: 28px; height: 28px; color: #fff; position: relative; z-index: 1; }

.sp-dock__btn--wa { background: var(--whatsapp); box-shadow: 0 6px 20px rgba(37, 211, 102, 0.42); }
.sp-dock__btn--call { background: var(--navy); box-shadow: 0 6px 20px rgba(33, 66, 142, 0.4); }

/* Hover label, desktop only */
.sp-dock__btn::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 11px);
  top: 50%;
  transform: translateY(-50%) translateX(-5px);
  background: var(--navy-ink);
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  padding: 7px 12px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.sp-dock__btn:hover::after,
.sp-dock__btn:focus-visible::after { opacity: 1; transform: translateY(-50%); }
@media (hover: none) { .sp-dock__btn::after { display: none; } }

/* ---------- Chat launcher: pill + pulsing button ---------- */
.sp-launch {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sp-launch__pill {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14.5px;
  color: var(--navy-ink);
  background: #fff;
  border-radius: var(--r-pill);
  padding: 11px 18px;
  box-shadow: 0 6px 20px rgba(16, 24, 40, 0.16);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.sp-launch__pill:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(16, 24, 40, 0.2); }
.sp-launch__pill:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; }
.sp-launch__pill::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #22c55e;
  flex: none;
}

.sp-launch__btn {
  width: 62px;
  height: 62px;
  padding: 0;
  overflow: visible;
  background: var(--gold);
  box-shadow: 0 6px 22px rgba(247, 173, 44, 0.45);
}

/* The caregiver's face fills the launcher; the gold ring keeps it on-brand */
.sp-launch__face {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 0 0 3px var(--gold);
}

/* Small bubble so it still reads unmistakably as "chat" */
.sp-launch__badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  z-index: 2;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--navy);
  border: 2px solid #fff;
  display: grid;
  place-items: center;
}
.sp-launch__badge svg { width: 12px; height: 12px; color: #fff; }

/* Pulse ring */
.sp-launch__btn::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.65;
  z-index: 0;
  animation: sp-pulse 2.4s cubic-bezier(0.24, 0, 0.38, 1) infinite;
}
@keyframes sp-pulse {
  0%   { transform: scale(1);    opacity: 0.6; }
  70%  { transform: scale(1.75); opacity: 0; }
  100% { transform: scale(1.75); opacity: 0; }
}
/* Stop the pulse once the assistant has been opened */
.sp-dock--right.is-engaged .sp-launch__btn::before { animation: none; opacity: 0; }
.sp-dock--right.is-engaged .sp-launch__pill { display: none; }

/* Unread / attention dot */
.sp-dock__dot {
  position: absolute;
  top: -1px; right: -1px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #ef4444;
  border: 2.5px solid #fff;
  z-index: 3;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.sp-dock__dot.is-on { opacity: 1; transform: scale(1); }

/* Proactive nudge bubble */
.sp-nudge {
  position: fixed;
  right: 22px;
  bottom: 96px;
  z-index: 400;
  max-width: 258px;
  background: #fff;
  border-radius: 14px 14px 4px 14px;
  box-shadow: var(--sh-lg);
  padding: 14px 16px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--navy-ink);
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.sp-nudge.is-on { opacity: 1; transform: none; pointer-events: auto; }
.sp-nudge__close {
  position: absolute;
  top: 5px; right: 7px;
  font-size: 17px;
  line-height: 1;
  color: var(--muted-light);
  padding: 3px;
}
.sp-nudge__close:hover { color: var(--ink); }

/* ---------- Panel ---------- */
.sp-chat {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 420;
  width: 384px;
  max-width: calc(100vw - 32px);
  height: 588px;
  max-height: calc(100vh - 44px);
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(16, 24, 40, 0.24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.sp-chat.is-open { opacity: 1; transform: none; pointer-events: auto; }

.sp-chat__head {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}
.sp-chat__avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--gold);
  overflow: hidden;
  flex: none;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.sp-chat__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.sp-chat__title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15.5px;
  line-height: 1.25;
}
.sp-chat__status {
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.78);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.sp-chat__status::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
}
.sp-chat__close {
  margin-left: auto;
  color: rgba(255, 255, 255, 0.85);
  padding: 6px;
  border-radius: 8px;
  flex: none;
}
.sp-chat__close:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.sp-chat__close svg { width: 20px; height: 20px; display: block; }

/* ---------- Message log ---------- */
.sp-chat__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  background: #faf8f4;
  display: flex;
  flex-direction: column;
  gap: 11px;
  scrollbar-width: thin;
}
.sp-chat__log::-webkit-scrollbar { width: 7px; }
.sp-chat__log::-webkit-scrollbar-thumb { background: #ded8cc; border-radius: 4px; }

.sp-msg {
  max-width: 84%;
  padding: 11px 14px;
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.55;
  border-radius: 14px;
  animation: sp-pop 0.24s ease both;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
@keyframes sp-pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.sp-msg--bot {
  align-self: flex-start;
  background: #fff;
  color: var(--navy-ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.sp-msg--user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.sp-msg--note {
  align-self: center;
  background: var(--gold-soft);
  color: #6b4a08;
  font-size: 13px;
  border-radius: 9px;
  max-width: 94%;
  text-align: center;
}

/* Typing indicator */
.sp-typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 5px;
  padding: 13px 15px;
  display: flex;
  gap: 4px;
}
.sp-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #c3ccd8;
  animation: sp-blink 1.3s infinite both;
}
.sp-typing span:nth-child(2) { animation-delay: 0.18s; }
.sp-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes sp-blink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Composer ---------- */
.sp-chat__foot {
  flex: none;
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
}

.sp-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.sp-chip {
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--navy);
  background: #fff;
  border: 1.5px solid var(--navy);
  border-radius: var(--r-pill);
  padding: 8px 14px;
  transition: background 0.15s ease, color 0.15s ease;
}
.sp-chip:hover { background: var(--navy); color: #fff; }
.sp-chip:focus-visible { outline: 3px solid rgba(33, 66, 142, 0.35); outline-offset: 2px; }
.sp-chip--soft { color: var(--muted); border-color: var(--line); }
.sp-chip--soft:hover { background: var(--muted); border-color: var(--muted); color: #fff; }
.sp-chip--gold { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.sp-chip--gold:hover { background: var(--gold-dark); border-color: var(--gold-dark); color: #fff; }
.sp-chip--wa { background: var(--whatsapp); border-color: var(--whatsapp); color: #fff; }
.sp-chip--wa:hover { background: #1da851; border-color: #1da851; }

.sp-input-row { display: flex; gap: 8px; align-items: center; }
.sp-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 15px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: #fcfbf9;
  color: var(--ink);
  min-width: 0;
}
.sp-input:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(33, 66, 142, 0.12);
}
.sp-send {
  width: 42px; height: 42px;
  flex: none;
  border-radius: 50%;
  background: var(--navy);
  display: grid;
  place-items: center;
  transition: background 0.15s ease;
}
.sp-send:hover { background: var(--navy-deep); }
.sp-send:disabled { background: #c3ccd8; cursor: not-allowed; }
.sp-send svg { width: 18px; height: 18px; color: #fff; }

.sp-chat__legal {
  margin-top: 9px;
  font-family: var(--font-body);
  font-size: 11.5px;
  color: var(--muted-light);
  text-align: center;
  line-height: 1.45;
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  /* Clear the sticky mobile action bar and the iOS home indicator */
  .sp-dock { bottom: calc(88px + env(safe-area-inset-bottom)); }
  .sp-dock--left { left: 14px; }
  .sp-dock--right { right: 14px; }
  .sp-dock__btn { width: 50px; height: 50px; }
  .sp-dock__btn svg { width: 25px; height: 25px; }
  .sp-launch__btn { width: 58px; height: 58px; }
  .sp-launch__badge { width: 22px; height: 22px; }
  .sp-launch__pill { font-size: 13.5px; padding: 9px 14px; }
  .sp-nudge { bottom: calc(154px + env(safe-area-inset-bottom)); right: 14px; }
  .sp-chat {
    right: 8px; left: 8px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    width: auto;
    height: min(544px, calc(100vh - 170px));
  }
}

/* ---------- Phone: the assistant takes the full screen ---------- */
@media (max-width: 640px) {
  .sp-chat {
    top: 0; right: 0; bottom: 0; left: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    opacity: 1;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  }
  .sp-chat.is-open { transform: none; }

  /* Clear the notch and the home indicator */
  .sp-chat__head { padding-top: calc(16px + env(safe-area-inset-top)); }
  .sp-chat__close { padding: 10px; }
  .sp-chat__close svg { width: 24px; height: 24px; }
  .sp-chat__log { padding: 16px; }
  .sp-chat__foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }

  /* Nothing floats over a full-screen panel */
  body.sp-locked { overflow: hidden; }
  body.sp-locked .sp-dock,
  body.sp-locked .sp-nudge,
  body.sp-locked .mobile-bar { display: none; }

  .sp-nudge { display: none; }
  .sp-launch__pill { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sp-msg, .sp-typing span, .sp-launch__btn::before { animation: none; }
  .sp-chat { transition: none; }
}
