.mx-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  font-size: 15px;
}

.mx-chat-toggle {
  position: relative;
  width: 68px;
  height: 68px;
  padding: 6px;
  background: #fff;
  border: 3px solid var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(59, 26, 110, 0.35);
  animation: mx-pulse 2.4s ease-out infinite;
}

.mx-chat-toggle img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.mx-chat-toggle:hover { transform: scale(1.06); }

.mx-chat-toggle[aria-expanded="true"] { animation: none; }

.mx-chat-badge {
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-right: 10px;
  white-space: nowrap;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  pointer-events: none;
}

.mx-chat-toggle[aria-expanded="true"] .mx-chat-badge { display: none; }

@keyframes mx-pulse {
  0% { box-shadow: 0 8px 24px rgba(59, 26, 110, 0.35), 0 0 0 0 rgba(106, 47, 184, 0.5); }
  70% { box-shadow: 0 8px 24px rgba(59, 26, 110, 0.35), 0 0 0 14px rgba(106, 47, 184, 0); }
  100% { box-shadow: 0 8px 24px rgba(59, 26, 110, 0.35), 0 0 0 0 rgba(106, 47, 184, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .mx-chat-toggle { animation: none; }
}

.mx-chat-panel {
  position: absolute;
  right: 0;
  bottom: 80px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 500px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.mx-chat-panel[hidden] { display: none; }

.mx-chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #3b1a6e 0%, #5c2ba0 100%);
  color: #fff;
}

.mx-chat-head > div { flex: 1; line-height: 1.3; }
.mx-chat-head small { display: block; font-size: 12px; opacity: 0.85; }

.mx-chat-avatar {
  width: 40px;
  height: 40px;
  padding: 4px;
  background: #fff;
  border-radius: 50%;
  object-fit: contain;
}

.mx-chat-close {
  background: none;
  border: 0;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.mx-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-soft);
}

.mx-msg {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
}

.mx-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}

.mx-msg-assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
}

.mx-msg-error { border-color: var(--accent-2); }

.mx-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--border);
}

.mx-chat-form textarea {
  flex: 1;
  resize: none;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.mx-chat-form button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.mx-chat-form button:disabled { opacity: 0.5; cursor: default; }

.mx-chat-note {
  margin: 0;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 12px;
}

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