.xplay-chatbox {
  --xplay-accent: #e11d48;
  --xplay-on-accent: #ffffff;
  --xplay-ink: #111827;
  --xplay-muted: #6b7280;
  --xplay-canvas: #f9fafb;
  --xplay-line: #e5e7eb;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--xplay-ink);
}

.xplay-chatbox--left { right: auto; left: 24px; }

.xplay-chatbox *,
.xplay-chatbox *::before,
.xplay-chatbox *::after { box-sizing: border-box; }

.xplay-chatbox button,
.xplay-chatbox input,
.xplay-chatbox textarea { font: inherit; margin: 0; box-shadow: none; }

.xplay-launcher {
  width: 60px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--xplay-accent);
  color: var(--xplay-on-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.xplay-launcher:hover { transform: scale(1.06); }

.xplay-launcher svg { width: 28px; height: 28px; }

.xplay-chatbox button:focus-visible,
.xplay-chatbox input:focus-visible,
.xplay-chatbox textarea:focus-visible {
  outline: 3px solid var(--xplay-accent);
  outline-offset: 2px;
}

.xplay-panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid var(--xplay-line);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(17, 24, 39, 0.2);
  transform-origin: bottom right;
}

.xplay-chatbox--left .xplay-panel { right: auto; left: 0; transform-origin: bottom left; }

.xplay-chatbox.xplay-open .xplay-panel {
  display: flex;
  animation: xplay-rise 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes xplay-rise {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.xplay-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--xplay-ink);
  color: #ffffff;
}

.xplay-avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--xplay-accent);
  color: var(--xplay-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.xplay-header-text { flex: 1; min-width: 0; }

.xplay-title { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.2; color: #ffffff; }

.xplay-subtitle { margin: 2px 0 0; font-size: 12px; color: #d1d5db; }

.xplay-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.xplay-close:hover { background: rgba(255, 255, 255, 0.12); }

.xplay-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--xplay-canvas);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
}

.xplay-msg { display: flex; }
.xplay-msg--user { justify-content: flex-end; }
.xplay-msg--bot { justify-content: flex-start; }

.xplay-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
  overflow-wrap: anywhere;
  animation: xplay-fade 0.2s ease;
}

@keyframes xplay-fade { from { opacity: 0; } to { opacity: 1; } }

.xplay-msg--bot .xplay-bubble {
  background: #ffffff;
  color: var(--xplay-ink);
  border: 1px solid var(--xplay-line);
  border-bottom-left-radius: 4px;
}

.xplay-msg--user .xplay-bubble {
  background: var(--xplay-accent);
  color: var(--xplay-on-accent);
  border-bottom-right-radius: 4px;
}

.xplay-bubble--form { max-width: 100%; width: 100%; }

.xplay-link { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

.xplay-typing { display: flex; gap: 4px; align-items: center; }

.xplay-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--xplay-muted);
  animation: xplay-bounce 1.2s infinite ease-in-out;
}

.xplay-typing span:nth-child(2) { animation-delay: 0.15s; }
.xplay-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes xplay-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.xplay-lead-form { position: relative; display: flex; flex-direction: column; gap: 8px; }

.xplay-lead-title { margin: 0 0 4px; font-weight: 600; }

.xplay-field {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #ffffff;
  color: var(--xplay-ink);
  font-size: 14px;
}

textarea.xplay-field { resize: vertical; min-height: 72px; }

.xplay-submit {
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--xplay-accent);
  color: var(--xplay-on-accent);
  font-weight: 600;
  cursor: pointer;
}

.xplay-submit:hover:not(:disabled) { filter: brightness(0.92); }
.xplay-submit:disabled { opacity: 0.6; cursor: wait; }

.xplay-form-error { margin: 0; color: #b91c1c; font-size: 13px; }
.xplay-form-error:empty { display: none; }

.xplay-success {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #ecfdf5;
  color: #065f46;
  font-weight: 500;
}

.xplay-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.xplay-chips {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  background: #ffffff;
  border-top: 1px solid var(--xplay-line);
}

.xplay-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border: 1px solid var(--xplay-line);
  border-radius: 999px;
  background: var(--xplay-canvas);
  color: var(--xplay-ink);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.xplay-chip:hover {
  background: var(--xplay-accent);
  border-color: var(--xplay-accent);
  color: var(--xplay-on-accent);
}

.xplay-chip--primary { background: var(--xplay-ink); border-color: var(--xplay-ink); color: #ffffff; }

.xplay-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #ffffff;
  border-top: 1px solid var(--xplay-line);
}

.xplay-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  background: #ffffff;
  color: var(--xplay-ink);
  font-size: 14px;
}

.xplay-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--xplay-accent);
  color: var(--xplay-on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.xplay-send svg { width: 18px; height: 18px; }

@media (max-width: 480px) {
  .xplay-chatbox { right: 16px; bottom: 16px; }
  .xplay-chatbox--left { left: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .xplay-chatbox *,
  .xplay-chatbox *::before,
  .xplay-chatbox *::after {
    animation: none !important;
    transition: none !important;
  }
}
