/* ================================================
   PATHFINDER -- Chatbot Widget
   Floating button + Chat window
   ================================================ */

/* ---------- Floating Button ---------- */
.chatbot-fab {
  position: fixed;
  bottom: 100px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s;
}

.chatbot-fab.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.chatbot-fab__bubble {
  background: var(--white);
  color: var(--text-dark);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  animation: chatbotPulse 3s ease-in-out infinite;
  position: relative;
}

.chatbot-fab__bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 20px;
  width: 12px;
  height: 12px;
  background: var(--white);
  transform: rotate(45deg);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.06);
}

.chatbot-fab__btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--terracotta);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  transition: background-color 0.2s var(--ease), transform 0.2s var(--ease);
  cursor: pointer;
  border: none;
  flex-shrink: 0;
}

.chatbot-fab__btn:hover {
  background: var(--terracotta-dark);
  transform: scale(1.08);
}

.chatbot-fab__btn:active {
  transform: scale(0.96);
}

.chatbot-fab__btn:focus-visible {
  outline: 3px solid var(--terracotta);
  outline-offset: 3px;
}

@keyframes chatbotPulse {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* ---------- Chat Widget Container ---------- */
.chatbot-widget {
  position: fixed;
  bottom: 100px;
  right: 20px;
  width: 400px;
  max-height: 600px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  background: var(--cream);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease), visibility 0.3s;
}

.chatbot-widget.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ---------- Header ---------- */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--navy);
  color: var(--white);
  flex-shrink: 0;
}

.chatbot-header__title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chatbot-header__status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.chatbot-header__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: var(--white);
  border: none;
  cursor: pointer;
  transition: background-color 0.15s var(--ease);
}

.chatbot-header__close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chatbot-header__close:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: 2px;
}

/* ---------- Chat Area ---------- */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  background: var(--cream);
  scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
}

/* ---------- Messages ---------- */
.chatbot-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: chatMsgFadeIn 0.3s var(--ease);
}

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

/* Bot message */
.chatbot-msg--bot {
  align-self: flex-start;
}

.chatbot-msg__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.chatbot-msg__content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chatbot-msg__bubble {
  padding: 10px 14px;
  font-size: 0.9rem;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.chatbot-msg--bot .chatbot-msg__bubble {
  background: var(--white);
  color: var(--text-dark);
  border-radius: 2px 12px 12px 12px;
  box-shadow: var(--shadow-sm);
}

/* User message */
.chatbot-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chatbot-msg--user .chatbot-msg__bubble {
  background: var(--terracotta);
  color: var(--white);
  border-radius: 12px 2px 12px 12px;
}

/* System message */
.chatbot-msg--system {
  align-self: center;
  max-width: 90%;
}

.chatbot-msg--system .chatbot-msg__bubble {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-sub);
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  text-align: center;
  padding: 6px 12px;
}

/* Timestamp */
.chatbot-msg__time {
  font-size: 0.7rem;
  color: var(--text-sub);
  padding: 0 4px;
}

.chatbot-msg--user .chatbot-msg__time {
  text-align: right;
}

/* ---------- Typing Indicator ---------- */
.chatbot-typing {
  display: flex;
  gap: 8px;
  align-self: flex-start;
  max-width: 85%;
  animation: chatMsgFadeIn 0.3s var(--ease);
}

.chatbot-typing__dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--white);
  border-radius: 2px 12px 12px 12px;
  box-shadow: var(--shadow-sm);
}

.chatbot-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-sub);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.chatbot-typing__dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbot-typing__dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---------- Quick Actions ---------- */
.chatbot-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  animation: chatMsgFadeIn 0.3s var(--ease);
}

.chatbot-quick-btn {
  padding: 8px 14px;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--terracotta);
  background: var(--white);
  border: 1.5px solid var(--terracotta);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
  white-space: nowrap;
}

.chatbot-quick-btn:hover {
  background: var(--terracotta);
  color: var(--white);
}

.chatbot-quick-btn:focus-visible {
  outline: 2px solid var(--terracotta);
  outline-offset: 2px;
}

/* ---------- Diagnosis Card ---------- */
.chatbot-card {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 16px;
  max-width: 90%;
  align-self: flex-start;
  animation: chatMsgFadeIn 0.3s var(--ease);
}

.chatbot-card__title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 10px;
  line-height: 1.5;
}

.chatbot-card__desc {
  font-size: 0.83rem;
  color: var(--text-sub);
  line-height: 1.6;
  margin-bottom: 12px;
}

.chatbot-card__buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chatbot-card__btn {
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--terracotta);
  background: var(--white);
  border: 1.5px solid var(--terracotta);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.chatbot-card__btn:hover {
  background: var(--terracotta);
  color: var(--white);
}

.chatbot-card__btn:focus-visible {
  outline: 2px solid var(--terracotta);
  outline-offset: 2px;
}

.chatbot-card__btn.selected {
  background: var(--terracotta);
  color: var(--white);
  pointer-events: none;
}

/* ---------- Diagnosis Result Card ---------- */
.chatbot-result {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 20px 16px;
  max-width: 90%;
  align-self: flex-start;
  animation: chatMsgFadeIn 0.3s var(--ease);
}

.chatbot-result__indicator {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.chatbot-result__indicator--green {
  background: #ecfdf5;
  color: var(--green);
  border: 1px solid var(--green);
}

.chatbot-result__indicator--yellow {
  background: #fefce8;
  color: #b45309;
  border: 1px solid var(--gold);
}

.chatbot-result__indicator--red {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #ef4444;
}

.chatbot-result__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
}

.chatbot-result__desc {
  font-size: 0.83rem;
  color: var(--text-sub);
  line-height: 1.6;
  margin-bottom: 14px;
}

.chatbot-result__cta {
  display: block;
  width: 100%;
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--white);
  background: var(--terracotta);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: background-color 0.15s var(--ease);
}

.chatbot-result__cta:hover {
  background: var(--terracotta-dark);
}

/* ---------- Crisis Card ---------- */
.chatbot-crisis {
  background: #fef2f2;
  border: 2px solid #ef4444;
  border-radius: var(--radius-md);
  padding: 16px;
  max-width: 90%;
  align-self: flex-start;
  animation: chatMsgFadeIn 0.3s var(--ease);
}

.chatbot-crisis__title {
  font-size: 0.9rem;
  font-weight: 700;
  color: #dc2626;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chatbot-crisis__desc {
  font-size: 0.83rem;
  color: var(--text-dark);
  line-height: 1.7;
  margin-bottom: 10px;
}

.chatbot-crisis__numbers {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chatbot-crisis__number {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--white);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  text-decoration: none;
  transition: background-color 0.15s var(--ease);
}

.chatbot-crisis__number:hover {
  background: #fee2e2;
}

/* ---------- Phone Collection Card ---------- */
.chatbot-phone {
  background: var(--white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 16px;
  max-width: 90%;
  align-self: flex-start;
  animation: chatMsgFadeIn 0.3s var(--ease);
}

.chatbot-phone__title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 6px;
  line-height: 1.5;
}

.chatbot-phone__desc {
  font-size: 0.8rem;
  color: var(--text-sub);
  line-height: 1.6;
  margin-bottom: 12px;
}

.chatbot-phone__input-wrap {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.chatbot-phone__input {
  flex: 1;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: var(--font-family);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-gray);
  color: var(--text-dark);
  transition: border-color 0.2s var(--ease);
}

.chatbot-phone__input:focus {
  outline: none;
  border-color: var(--terracotta);
}

.chatbot-phone__input.error {
  border-color: #ef4444;
}

.chatbot-phone__submit {
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--white);
  background: var(--terracotta);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s var(--ease);
}

.chatbot-phone__submit:hover {
  background: var(--terracotta-dark);
}

.chatbot-phone__submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chatbot-phone__error {
  font-size: 0.75rem;
  color: #ef4444;
  margin-bottom: 6px;
  display: none;
}

.chatbot-phone__error.visible {
  display: block;
}

.chatbot-phone__skip {
  display: block;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-sub);
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px;
  font-family: var(--font-family);
  transition: color 0.15s var(--ease);
}

.chatbot-phone__skip:hover {
  color: var(--text-dark);
}

/* ---------- Input Area ---------- */
.chatbot-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chatbot-input__field {
  flex: 1;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: var(--font-family);
  border: 2px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-gray);
  color: var(--text-dark);
  transition: border-color 0.2s var(--ease);
  min-width: 0;
}

.chatbot-input__field:focus {
  outline: none;
  border-color: var(--terracotta);
}

.chatbot-input__field::placeholder {
  color: var(--text-sub);
}

/* Mic button */
.chatbot-input__mic {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-gray);
  color: var(--text-sub);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease),
    border-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.chatbot-input__mic:hover {
  background: var(--white);
  color: var(--terracotta);
  border-color: var(--terracotta);
}

.chatbot-input__mic:active {
  transform: scale(0.92);
}

.chatbot-input__mic:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chatbot-input__mic:focus-visible {
  outline: 2px solid var(--terracotta);
  outline-offset: 2px;
}

.chatbot-input__mic.recording {
  background: #ef4444;
  color: var(--white);
  border-color: #ef4444;
  animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.chatbot-input__send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--terracotta);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s var(--ease), transform 0.15s var(--ease);
}

.chatbot-input__send:hover {
  background: var(--terracotta-dark);
}

.chatbot-input__send:active {
  transform: scale(0.92);
}

.chatbot-input__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chatbot-input__send:focus-visible {
  outline: 2px solid var(--terracotta);
  outline-offset: 2px;
}

/* ---------- Mobile Responsive ---------- */
@media (max-width: 767px) {
  .chatbot-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    transform: translateY(100%);
  }

  .chatbot-widget.open {
    transform: translateY(0);
  }

  .chatbot-fab {
    bottom: 80px;
    right: 14px;
  }

  .chatbot-fab__btn {
    width: 54px;
    height: 54px;
  }

  .chatbot-fab__bubble {
    font-size: 0.8rem;
    padding: 6px 12px;
  }

  .chatbot-msg__bubble {
    font-size: 0.92rem;
  }

  .chatbot-input__field {
    font-size: 16px; /* Prevent iOS zoom */
  }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .chatbot-widget,
  .chatbot-fab,
  .chatbot-msg,
  .chatbot-typing,
  .chatbot-card,
  .chatbot-result,
  .chatbot-crisis,
  .chatbot-phone,
  .chatbot-quick-actions {
    animation: none;
    transition-duration: 0.01ms !important;
  }

  .chatbot-fab__bubble {
    animation: none;
  }

  .chatbot-typing__dot {
    animation: none;
    opacity: 0.6;
  }
}
