.rpbd-chat {
  --rpbd-blue: #4f46e5;
  --rpbd-violet: #7c3aed;
  --rpbd-ink: #0f172a;
  --rpbd-muted: #64748b;
  --rpbd-line: #e8eef6;
  --rpbd-bg: #f3f6fb;
  --rpbd-shadow: 0 22px 60px rgba(15, 23, 42, .22);
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 99999;
  font-family: "Plus Jakarta Sans", Inter, system-ui, sans-serif;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 12px;
  -webkit-font-smoothing: antialiased;
  pointer-events: none;
}

.rpbd-chat__toggle,
.rpbd-chat__panel {
  pointer-events: auto;
}

.rpbd-chat *,
.rpbd-chat *::before,
.rpbd-chat *::after { box-sizing: border-box; }

.rpbd-chat__toggle {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(160deg, #6366f1 0%, #4f46e5 46%, #7c3aed 100%);
  color: #fff;
  cursor: pointer;
  position: relative;
  box-shadow: 0 16px 36px rgba(79, 70, 229, .36);
  display: grid;
  place-items: center;
  transition: transform .2s ease, box-shadow .2s ease;
}

.rpbd-chat__toggle:hover { transform: translateY(-2px) scale(1.03); }
.rpbd-chat__toggle:focus-visible { outline: 3px solid rgba(99, 102, 241, .45); outline-offset: 3px; }
.rpbd-chat.is-open .rpbd-chat__toggle { display: none; }

.rpbd-chat__mascot {
  width: 34px;
  height: 34px;
  display: block;
}

.rpbd-chat__mini .rpbd-chat__mascot,
.rpbd-chat__mini svg {
  width: 16px;
  height: 16px;
}

.rpbd-chat__online {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 12px;
  height: 12px;
  background: #22c55e;
  border: 2px solid #fff;
  border-radius: 50%;
}

.rpbd-chat__badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.rpbd-chat__panel {
  width: min(408px, calc(100vw - 24px));
  height: min(660px, calc(100vh - 32px));
  background: #fff;
  border-radius: 24px;
  box-shadow: var(--rpbd-shadow);
  overflow: hidden;
  display: none;
  flex-direction: column;
  border: 1px solid rgba(226, 232, 240, .95);
  transform-origin: bottom right;
  overscroll-behavior: contain;
  pointer-events: auto;
}

.rpbd-chat__panel.is-open {
  display: flex;
  animation: rpbdPanelIn .22s ease;
}

.rpbd-chat__header {
  background:
    radial-gradient(1200px 180px at 100% -20%, rgba(167, 139, 250, .28), transparent 55%),
    linear-gradient(135deg, #0b1220 0%, #172554 55%, #4c1d95 130%);
  color: #fff;
  padding: 16px 14px 16px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.rpbd-chat__brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.rpbd-chat__avatar {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.14);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.rpbd-chat__avatar svg { width: 26px; height: 26px; }

.rpbd-chat__kicker {
  display: block;
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .7;
  font-weight: 700;
  margin-bottom: 1px;
}

.rpbd-chat__brand strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 700;
}

.rpbd-chat__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  margin-top: 4px;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 2px 8px 2px 6px;
  opacity: .95;
}

.rpbd-chat__status i {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, .18);
}

.rpbd-chat__actions { display: flex; gap: 4px; }

.rpbd-chat__iconbtn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: .92;
}

.rpbd-chat__iconbtn:hover { background: rgba(255,255,255,.12); }
.rpbd-chat__iconbtn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

.rpbd-chat__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 10px;
  background:
    radial-gradient(circle at top right, rgba(99, 102, 241, .06), transparent 32%),
    var(--rpbd-bg);
}

.rpbd-chat__empty {
  height: 100%;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--rpbd-muted);
  padding: 24px 16px;
}

.rpbd-chat__empty-mark {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  background: linear-gradient(160deg, #6366f1, #7c3aed);
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  box-shadow: 0 10px 24px rgba(79, 70, 229, .22);
}

.rpbd-chat__empty-mark svg { width: 28px; height: 28px; }

.rpbd-chat__empty strong {
  display: block;
  color: var(--rpbd-ink);
  font-size: 15px;
  margin-bottom: 4px;
}

.rpbd-chat__empty span {
  font-size: 13px;
  line-height: 1.45;
  max-width: 240px;
}

.rpbd-chat__row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: flex-end;
}

.rpbd-chat__row--user { justify-content: flex-end; }

.rpbd-chat__mini {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: linear-gradient(145deg, #6366f1, #7c3aed);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.rpbd-chat__mini svg { width: 16px; height: 16px; }

.rpbd-chat__col { max-width: 80%; min-width: 0; }

.rpbd-chat__row--user .rpbd-chat__col { max-width: 74%; }

.rpbd-chat__who {
  font-size: 11px;
  color: var(--rpbd-muted);
  margin: 0 4px 4px;
  font-weight: 600;
}

.rpbd-chat__bubble {
  padding: 11px 13px;
  border-radius: 18px 18px 18px 6px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.rpbd-chat__bubble a {
  color: #4338ca;
  font-weight: 650;
  text-decoration: none;
  border-bottom: 1px solid rgba(67, 56, 202, .35);
}

.rpbd-chat__bubble a:hover { border-bottom-color: #4338ca; }

.rpbd-chat__bubble--bot,
.rpbd-chat__bubble--admin {
  background: #fff;
  border: 1px solid #e6ebf4;
  color: #0f172a;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.rpbd-chat__bubble--user {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 8px 18px rgba(79, 70, 229, .18);
}

.rpbd-chat__bubble--user a { color: #e0e7ff; border-bottom-color: rgba(224, 231, 255, .5); }

.rpbd-chat__bubble ul {
  margin: 6px 0 0;
  padding-left: 18px;
  white-space: normal;
}

.rpbd-chat__bubble li { margin: 3px 0; }

.rpbd-chat__bubble strong { font-weight: 700; }

.rpbd-chat__bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #eef2ff;
  padding: 1px 5px;
  border-radius: 6px;
}

.rpbd-chat__img {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.rpbd-chat__ticket {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.rpbd-chat__ticket-btn {
  border: 0;
  border-radius: 11px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.rpbd-chat__ticket-btn:disabled { opacity: .55; cursor: not-allowed; }

.rpbd-chat__ticket-btn--yes {
  background: #0f172a;
  color: #fff;
}

.rpbd-chat__ticket-btn--no {
  background: #fff;
  color: #334155;
  border: 1px solid #dbe3f0;
}

.rpbd-chat__ticket-note {
  font-size: 12px;
  color: var(--rpbd-muted);
  font-weight: 600;
}

.rpbd-chat__typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #e6ebf4;
  border-radius: 16px 16px 16px 6px;
}

.rpbd-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: rpbdDots 1s infinite ease-in-out;
}

.rpbd-chat__typing span:nth-child(2) { animation-delay: .15s; }
.rpbd-chat__typing span:nth-child(3) { animation-delay: .3s; }

.rpbd-chat__form {
  background: #fff;
  border-top: 1px solid var(--rpbd-line);
  padding: 10px 12px 12px;
  flex-shrink: 0;
}

.rpbd-chat__composer {
  display: flex;
  gap: 8px;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #dbe3f0;
  border-radius: 16px;
  padding: 4px 4px 4px 14px;
}

.rpbd-chat__composer:focus-within {
  border-color: #a5b4fc;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, .12);
  background: #fff;
}

.rpbd-chat__composer input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 14px;
  padding: 11px 0;
  color: var(--rpbd-ink);
}

.rpbd-chat__send {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 16px rgba(79, 70, 229, .22);
}

.rpbd-chat__send:hover { filter: brightness(1.05); }
.rpbd-chat__send:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.rpbd-chat__secure {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
  color: #94a3b8;
  font-weight: 600;
}

.rpbd-chat__secure svg {
  width: 12px;
  height: 12px;
}

@keyframes rpbdPanelIn {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@keyframes rpbdDots {
  0%, 80%, 100% { transform: translateY(0); opacity: .45; }
  40% { transform: translateY(-3px); opacity: 1; }
}

.rpbd-chat__body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.rpbd-chat__toggle,
.rpbd-chat__iconbtn,
.rpbd-chat__send,
.rpbd-chat__ticket-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 640px) {
  html.rpbd-chat-lock,
  body.rpbd-chat-lock {
    overflow: hidden !important;
    height: 100%;
    overscroll-behavior: none;
  }

  .rpbd-chat {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .rpbd-chat__toggle {
    width: 56px;
    height: 56px;
  }

  .rpbd-chat.is-open {
    inset: 0;
    right: 0;
    bottom: 0;
    left: 0;
    top: var(--rpbd-vvo, 0px);
    width: 100%;
    height: var(--rpbd-vvh, 100dvh);
    gap: 0;
    align-items: stretch;
    flex-direction: column;
  }

  .rpbd-chat__panel,
  .rpbd-chat.is-open .rpbd-chat__panel {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }

  .rpbd-chat__panel.is-open {
    animation: none;
  }

  .rpbd-chat__header {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

  .rpbd-chat__iconbtn {
    width: 44px;
    height: 44px;
  }

  .rpbd-chat__body {
    padding: 14px 14px 8px;
  }

  .rpbd-chat__col,
  .rpbd-chat__row--user .rpbd-chat__col {
    max-width: 88%;
  }

  .rpbd-chat__bubble {
    font-size: 15px;
  }

  .rpbd-chat__form {
    padding: 8px 12px max(10px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .rpbd-chat__composer {
    min-height: 48px;
  }

  .rpbd-chat__composer input {
    font-size: 16px;
    padding: 12px 0;
  }

  .rpbd-chat__send {
    width: 44px;
    height: 44px;
  }

  .rpbd-chat__ticket {
    width: 100%;
  }

  .rpbd-chat__ticket-btn {
    min-height: 44px;
    flex: 1;
    padding: 10px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rpbd-chat__panel.is-open,
  .rpbd-chat__toggle,
  .rpbd-chat__typing span { animation: none; transition: none; }
}
