/* =============================================================
   MindGurus AI Chat — Global Widget Styles
   Floating button + popup panel rendered on every page
   ============================================================= */

/* ---------- Floating trigger button ---------- */
.mg-chat-widget-trigger {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--mg-destructive, #B23B2E);
  color: #fff;
  border: none;
  border-radius: 9999px;
  font-family: 'Public Sans', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(178,59,46,0.40), 0 1px 4px rgba(0,0,0,0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.mg-chat-widget-trigger:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(178,59,46,0.45), 0 2px 8px rgba(0,0,0,0.14);
}

.mg-chat-widget-trigger.is-open {
  background: var(--mg-muted-fg, #6B6459);
}

.mg-chat-widget-trigger svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Pulse ring on idle */
.mg-chat-widget-trigger::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 9999px;
  border: 2px solid rgba(178,59,46,0.35);
  animation: mg-widget-pulse 2.5s ease-out infinite;
  pointer-events: none;
}

.mg-chat-widget-trigger.is-open::before {
  display: none;
}

@keyframes mg-widget-pulse {
  0%   { transform: scale(1);   opacity: 0.7; }
  70%  { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}

/* ---------- Popup Panel ---------- */
.mg-chat-popup {
  position: fixed;
  bottom: 90px;
  right: 28px;
  z-index: 9998;
  width: 400px;
  max-width: calc(100vw - 40px);
  max-height: 70vh;
  background: var(--mg-primary-fg, #FDFAF3);
  border: 1px solid var(--mg-input, #E4D7B8);
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(43,36,28,0.15), 0 2px 8px rgba(43,36,28,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.92) translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1),
              opacity 0.18s ease;
}

.mg-chat-popup.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ---- Popup header ---- */
.mg-chat-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(228,215,184,0.60);
  flex-shrink: 0;
}

.mg-chat-popup-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mg-chat-popup-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--mg-ring, #B98A3D);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.mg-chat-popup-title {
  font-family: 'Fraunces', serif;
  font-size: 16px;
  font-weight: 400;
  color: var(--mg-accent-fg, #2B241C);
  margin: 0;
}

.mg-chat-popup-subtitle {
  font-family: 'Public Sans', sans-serif;
  font-size: 11px;
  color: var(--mg-muted-fg, #6B6459);
  margin: 0;
}

.mg-chat-popup-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mg-chat-popup-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mg-muted-fg, #6B6459);
  transition: background 0.15s ease, color 0.15s ease;
}

.mg-chat-popup-icon-btn:hover {
  background: rgba(228,215,184,0.40);
  color: var(--mg-accent-fg, #2B241C);
}

/* ---- Thread view (list of past chats) ---- */
.mg-chat-thread-view {
  flex: 1;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
}

.mg-chat-thread-view.is-active {
  display: flex;
}

.mg-chat-thread-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.mg-chat-thread-item:hover {
  background: var(--mg-destructive-fg, #F8F3E9);
}

.mg-chat-thread-item.active {
  background: rgba(185,138,61,0.10);
}

.mg-chat-thread-item-title {
  font-family: 'Public Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--mg-accent-fg, #2B241C);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.mg-chat-thread-item-meta {
  font-family: 'Public Sans', sans-serif;
  font-size: 11px;
  color: var(--mg-muted-fg, #6B6459);
  white-space: nowrap;
}

.mg-chat-thread-new-btn {
  margin: 8px 12px 12px;
  padding: 10px;
  border-radius: 12px;
  border: 1px dashed var(--mg-input, #E4D7B8);
  background: transparent;
  font-family: 'Public Sans', sans-serif;
  font-size: 13px;
  color: var(--mg-muted-fg, #6B6459);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.mg-chat-thread-new-btn:hover {
  background: rgba(185,138,61,0.08);
  border-color: var(--mg-ring, #B98A3D);
  color: var(--mg-accent-fg, #2B241C);
}

/* ---- Active chat view ---- */
.mg-chat-active-view {
  flex: 1;
  display: none;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.mg-chat-active-view.is-active {
  display: flex;
}

/* Messages */
.mg-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.mg-chat-messages::-webkit-scrollbar {
  width: 3px;
}
.mg-chat-messages::-webkit-scrollbar-thumb {
  background: var(--mg-input, #E4D7B8);
  border-radius: 2px;
}

.mg-chat-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: mg-bubble-in 0.22s ease both;
}

.mg-chat-bubble-wrap.ai  { flex-direction: row; }
.mg-chat-bubble-wrap.user { flex-direction: row-reverse; }

.mg-chat-mini-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--mg-ring, #B98A3D);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}

.mg-chat-bubble {
  max-width: 280px;
  padding: 10px 14px;
  border-radius: 16px;
  font-family: 'Public Sans', sans-serif;
  font-size: 13px;
  line-height: 19px;
  color: var(--mg-accent-fg, #2B241C);
}

.mg-chat-bubble-wrap.ai .mg-chat-bubble {
  background: var(--mg-destructive-fg, #F8F3E9);
  border-radius: 4px 16px 16px 16px;
}

.mg-chat-bubble h1, .mg-chat-bubble h2, .mg-chat-bubble h3 {
  margin: 0 0 8px 0;
  font-size: 1.1em;
  font-weight: 600;
}

.mg-chat-bubble strong {
  font-weight: 600;
}

.mg-ai-button-link {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--mg-ring, #B98A3D);
  color: #ffffff !important;
  text-decoration: none;
  border-radius: 9999px;
  font-family: 'Public Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.mg-ai-button-link:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.mg-chat-bubble-wrap.user .mg-chat-bubble {
  background: var(--mg-ring, #B98A3D);
  color: #FDFAF3;
  border-radius: 16px 4px 16px 16px;
}

/* Typing dots in widget */
.mg-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--mg-destructive-fg, #F8F3E9);
  border-radius: 4px 16px 16px 16px;
  width: fit-content;
}

.mg-chat-typing span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mg-muted-fg, #6B6459);
  animation: mg-typing-dot 1.3s infinite ease-in-out;
}

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

/* Input bar */
.mg-chat-input-bar {
  padding: 12px 14px;
  border-top: 1px solid rgba(228,215,184,0.60);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mg-chat-input-field {
  flex: 1;
  height: 40px;
  padding: 10px 16px;
  border-radius: 9999px;
  border: none;
  background: #ffffff;
  font-family: 'Public Sans', sans-serif;
  font-size: 13px;
  color: #000000;
  outline: none;
  transition: box-shadow 0.2s ease;
}

.mg-chat-input-field::placeholder {
  color: var(--mg-muted-fg, #6B6459);
}

.mg-chat-input-field:focus {
  box-shadow: 0 0 0 2px rgba(185,138,61,0.15);
}

.mg-chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--mg-ring, #B98A3D);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.mg-chat-send-btn:hover:not(:disabled) {
  opacity: 0.85;
  transform: translateY(-1px);
}

.mg-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 480px) {
  .mg-chat-popup {
    right: 12px;
    bottom: 80px;
    width: calc(100vw - 24px);
    max-height: 65vh;
  }

  .mg-chat-widget-trigger {
    right: 12px;
    bottom: 16px;
  }
}
