/* ==========================================================================
   Mortuza's Assistant — Facebook-style chat head
   ========================================================================== */

.ms-assistant {
  --msa-blue: #0084ff;
  --msa-blue-dark: #0066cc;
  --msa-panel-w: min(370px, calc(100vw - 24px));
  --msa-panel-h: min(520px, calc(100vh - 120px));
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10050;
  font-family: var(--font-sans, system-ui, sans-serif);
}

/* Chat head (FAB) — Messenger icon + blue outer ring */
.msa-head {
  width: 64px;
  height: 64px;
  border: none;
  padding: 0;
  cursor: pointer;
  background: transparent;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.msa-head:hover,
.msa-head:focus-visible {
  transform: scale(1.08);
  outline: none;
}

.msa-head-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--msa-blue);
  box-shadow: 0 4px 18px rgba(0, 132, 255, 0.4);
  animation: msaRingPulse 2.8s ease-in-out infinite;
  pointer-events: none;
}

.msa-head-inner {
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00b2ff 0%, #006aff 55%, #a033ff 100%);
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.msa-head-inner i {
  color: #fff;
  font-size: 1.55rem;
  line-height: 1;
}

.msa-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e41e3f;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  z-index: 3;
}

.msa-badge.is-visible {
  display: flex;
}

@keyframes msaRingPulse {
  0%, 100% {
    box-shadow: 0 4px 18px rgba(0, 132, 255, 0.4), 0 0 0 0 rgba(0, 132, 255, 0.35);
  }
  50% {
    box-shadow: 0 4px 18px rgba(0, 132, 255, 0.45), 0 0 0 8px rgba(0, 132, 255, 0);
  }
}

.ms-assistant.is-open .msa-head {
  animation: none;
  transform: scale(0.92);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Chat panel */
.msa-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: var(--msa-panel-w);
  height: var(--msa-panel-h);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  color: #050505;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.94);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.22s;
  pointer-events: none;
}

.ms-assistant.is-open .msa-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header — Facebook Messenger style */
.msa-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  background: linear-gradient(135deg, #0084ff 0%, #0066cc 100%);
  color: #fff;
  min-height: 64px;
}

.msa-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.85);
  flex-shrink: 0;
  position: relative;
}

.msa-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msa-header-info {
  flex: 1;
  min-width: 0;
}

.msa-header-title {
  margin: 0;
  font-family: var(--font-display, "Space Grotesk", sans-serif);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msa-header-status {
  margin: 2px 0 0;
  font-size: 0.75rem;
  opacity: 0.92;
  display: flex;
  align-items: center;
  gap: 6px;
}

.msa-header-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #31a24c;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.msa-header.is-responding .msa-header-status::before {
  background: #fff;
  animation: msaStatusPulse 1s ease-in-out infinite;
}

.msa-header.is-responding .msa-header-status {
  opacity: 1;
  font-style: italic;
}

@keyframes msaStatusPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.msa-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.msa-icon-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.msa-icon-btn:hover,
.msa-icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.18);
  outline: none;
}

/* Messages */
.msa-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px;
  background: #f0f2f5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.msa-day-note {
  align-self: center;
  font-size: 0.72rem;
  color: #65676b;
  background: rgba(0, 0, 0, 0.05);
  padding: 4px 10px;
  border-radius: 999px;
  margin: 4px 0 8px;
}

.msa-bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 92%;
}

.msa-bubble-row.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msa-bubble-row.is-bot {
  align-self: flex-start;
}

.msa-bubble-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.msa-bubble-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msa-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.92rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msa-bubble-row.is-bot .msa-bubble {
  background: #e4e6eb;
  color: #050505;
  border-bottom-left-radius: 6px;
}

.msa-bubble-row.is-user .msa-bubble {
  background: var(--msa-blue);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msa-typing {
  display: none;
  align-self: flex-start;
  gap: 8px;
  align-items: flex-end;
  margin: 4px 0 2px;
  max-width: 92%;
}

.msa-typing.is-visible {
  display: flex;
  animation: msaTypingIn 0.2s ease;
}

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

/* WhatsApp-style … waiting bubble */
.msa-typing-dots {
  background: #e4e6eb;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 52px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

.msa-typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #99a1a9;
  animation: msaWhatsAppDot 1.4s ease-in-out infinite;
}

.msa-typing-dots span:nth-child(1) { animation-delay: 0s; }
.msa-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.msa-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* Composer */
.msa-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  background: #fff;
  border-top: 1px solid #e4e6eb;
}

.msa-composer textarea {
  flex: 1;
  resize: none;
  border: none;
  background: #f0f2f5;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 0.92rem;
  line-height: 1.4;
  max-height: 100px;
  color: #050505;
  font-family: inherit;
  outline: none;
}

.msa-composer textarea::placeholder {
  color: #8a8d91;
}

.msa-send {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--msa-blue);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.msa-send:hover:not(:disabled) {
  background: var(--msa-blue-dark);
  transform: scale(1.05);
}

.msa-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ms-assistant.is-responding .msa-send:disabled {
  opacity: 1;
  background: var(--msa-blue-dark);
}

.ms-assistant.is-responding .msa-composer textarea:disabled {
  opacity: 0.7;
  cursor: wait;
}

.msa-footer-note {
  text-align: center;
  font-size: 0.65rem;
  color: #8a8d91;
  padding: 0 12px 8px;
  background: #fff;
}

/* Keep back-to-top clear of chat head */
.back-to-top {
  right: 24px;
  bottom: 96px;
}

@media (max-width: 480px) {
  .ms-assistant {
    right: 12px;
    bottom: 12px;
  }

  .msa-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-height: none;
  }

  .ms-assistant.is-open .msa-head {
    display: none;
  }

  .back-to-top {
    bottom: 88px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .msa-head-ring {
    animation: none;
  }

  .msa-panel,
  .msa-head {
    transition: none;
  }
}
