/* ============================================================
   CASAI Chat Bubble (sitewide floating launcher + modal)
   ============================================================ */

/* ----- Floating launcher (bottom-right circle) ----- */
.casai-bubble {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1100;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-pink, #ff26b9) 0%, var(--accent-purple, #cb6ce6) 100%);
  border: none;
  color: white;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(255, 38, 185, 0.5), 0 0 0 2px rgba(255, 38, 185, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.125rem;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  font-family: inherit;
}

.casai-bubble:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 36px rgba(255, 38, 185, 0.6), 0 0 0 3px rgba(255, 38, 185, 0.4);
}

.casai-bubble:active {
  transform: translateY(-1px) scale(1.02);
}

.casai-bubble__icon {
  font-size: 1.5rem;
  line-height: 1;
}

.casai-bubble__label {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* gentle pulse to draw the eye on first load */
.casai-bubble--pulse::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent-pink, #ff26b9);
  opacity: 0;
  animation: casaiBubblePulse 2.2s infinite;
  pointer-events: none;
}

@keyframes casaiBubblePulse {
  0%   { opacity: 0.6; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.5); }
}

/* hide bubble while modal is open */
.casai-bubble[hidden] { display: none; }

/* If the Feedback-Tab also sits in bottom-right on mobile,
   push it leftwards so it doesn't collide with the bubble. */
@media (max-width: 768px) {
  .feedback-button {
    right: auto !important;
    left: 20px !important;
  }
}

/* ----- Modal backdrop ----- */
.casai-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(5, 5, 9, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.casai-modal[data-open='true'] {
  opacity: 1;
  visibility: visible;
}

/* ----- Modal panel (the actual chat surface) ----- */
.casai-modal__panel {
  background: rgba(20, 20, 28, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 480px;
  height: min(720px, calc(100vh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.3, 1), opacity 0.3s ease;
}

.casai-modal[data-open='true'] .casai-modal__panel {
  transform: translateY(0);
  opacity: 1;
}

/* ----- Modal header ----- */
.casai-modal__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.02);
}

.casai-modal__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-pink, #ff26b9) 0%, var(--accent-purple, #cb6ce6) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.casai-modal__meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.casai-modal__name {
  font-weight: 700;
  font-size: 0.9375rem;
  color: #fff;
  line-height: 1.2;
}

.casai-modal__status {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.casai-modal__status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1ec76b;
  box-shadow: 0 0 6px rgba(30, 199, 107, 0.5);
}

.casai-modal__close {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}

.casai-modal__close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.casai-modal__expand {
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  margin-right: 0.25rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.casai-modal__expand:hover {
  color: #fff;
}

/* ----- Modal body: stream + replies ----- */
.casai-modal__stream {
  flex: 1;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
}

.casai-modal__stream::-webkit-scrollbar { width: 6px; }
.casai-modal__stream::-webkit-scrollbar-track { background: transparent; }
.casai-modal__stream::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

.casai-modal__replies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.015);
  min-height: 4rem;
  align-items: center;
}

/* The chat.js classes (chat-msg, chat-reply, chat-typing, chat-result)
   are styled in chat.css. We include the minimum set inline so the modal
   works on pages that DON'T load chat.css. */

/* ----- Bubble inline message styles (copied from chat.css, scoped) ----- */
.casai-modal .chat-msg {
  display: flex;
  gap: 0.5rem;
  max-width: 90%;
  animation: casaiMsgIn 0.3s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.casai-modal .chat-msg--bot { align-self: flex-start; }
.casai-modal .chat-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.casai-modal .chat-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.6875rem;
  color: white;
}

.casai-modal .chat-msg--bot .chat-msg__avatar {
  background: linear-gradient(135deg, var(--accent-pink, #ff26b9) 0%, var(--accent-purple, #cb6ce6) 100%);
}

.casai-modal .chat-msg--user .chat-msg__avatar {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
}

.casai-modal .chat-msg__bubble {
  padding: 0.625rem 0.875rem;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 0.875rem;
  word-wrap: break-word;
  color: #fff;
}

.casai-modal .chat-msg--bot .chat-msg__bubble {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top-left-radius: 4px;
}

.casai-modal .chat-msg--user .chat-msg__bubble {
  background: linear-gradient(135deg, var(--accent-pink, #ff26b9) 0%, var(--accent-purple, #cb6ce6) 100%);
  border-top-right-radius: 4px;
}

.casai-modal .chat-msg__hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
  font-style: italic;
}

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

.casai-modal .chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 0.875rem;
}

.casai-modal .chat-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  animation: casaiTyping 1.2s infinite ease-in-out;
}
.casai-modal .chat-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.casai-modal .chat-typing__dot:nth-child(3) { animation-delay: 0.3s; }

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

.casai-modal .chat-reply {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.casai-modal .chat-reply:hover {
  background: rgba(255, 38, 185, 0.12);
  border-color: var(--accent-pink, #ff26b9);
}

.casai-modal .chat-reply--selected {
  background: linear-gradient(135deg, var(--accent-pink, #ff26b9) 0%, var(--accent-purple, #cb6ce6) 100%);
  border-color: transparent;
  pointer-events: none;
}

/* ----- Result card inside modal ----- */
.casai-modal .chat-result {
  margin-top: 0.75rem;
  padding: 1.25rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  animation: casaiMsgIn 0.4s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.casai-modal .chat-result__brand-header {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.casai-modal .chat-result__logo {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.casai-modal .chat-result__brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
  color: #fff;
  line-height: 1.2;
}

.casai-modal .chat-result__match {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

.casai-modal .chat-result__match-bar {
  width: 50px;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.casai-modal .chat-result__match-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-pink, #ff26b9) 0%, var(--accent-purple, #cb6ce6) 100%);
  transition: width 0.6s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.casai-modal .chat-result__reason {
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.5;
  font-size: 0.875rem;
  margin: 0;
}

.casai-modal .chat-result__cta {
  width: 100%;
  text-align: center;
  background: linear-gradient(135deg, var(--accent-pink, #ff26b9) 0%, var(--accent-purple, #cb6ce6) 100%);
  color: white;
  padding: 0.875rem 1.25rem;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9375rem;
  display: inline-block;
  transition: transform 0.2s, box-shadow 0.2s;
  border: none;
  cursor: pointer;
}

.casai-modal .chat-result__cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(255, 38, 185, 0.35);
}

.casai-modal .chat-result__secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  justify-content: center;
}

.casai-modal .chat-result__secondary a {
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 1px;
}

.casai-modal .chat-result__secondary a:hover {
  color: #fff;
  border-color: var(--accent-pink, #ff26b9);
}

.casai-modal .chat-error {
  padding: 0.875rem 1rem;
  background: rgba(255, 100, 100, 0.08);
  border: 1px solid rgba(255, 100, 100, 0.2);
  border-radius: 10px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.875rem;
}

/* ----- Mobile: bubble + modal go full-width / full-height ----- */
@media (max-width: 540px) {
  .casai-bubble {
    width: 56px;
    height: 56px;
    right: 16px;
    bottom: 16px;
  }
  .casai-bubble__icon { font-size: 1.375rem; }
  .casai-bubble__label { display: none; }

  .casai-modal {
    padding: 0;
  }
  .casai-modal__panel {
    max-width: none;
    width: 100%;
    height: 100vh;
    border-radius: 0;
  }
}
