:root {
  --pb4r-green: #047857;
  --pb4r-dark: #022c1f;
  --pb4r-paper: #f8fafc;
  --pb4r-border: #e2e8f0;
  --pb4r-text: #0f172a;
  --pb4r-muted: #64748b;
}

#pb4r-trigger,
#pb4r-window,
#pb4r-window * {
  box-sizing: border-box;
}

#pb4r-trigger {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99999;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 18px 45px rgba(2, 44, 31, .28);
  transition: transform .2s ease, box-shadow .2s ease;
}

#pb4r-trigger:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 22px 55px rgba(2, 44, 31, .35);
}

#pb4r-trigger svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

#pb4r-badge {
  display: none;
  position: absolute;
  top: -3px;
  right: -3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  align-items: center;
  justify-content: center;
  font: 700 11px/1 Arial, sans-serif;
  border: 3px solid #fff;
}

#pb4r-window {
  position: fixed;
  right: 24px;
  bottom: 98px;
  z-index: 99998;
  width: min(390px, calc(100vw - 28px));
  height: min(620px, calc(100vh - 130px));
  min-height: 460px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, .08);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, .22);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(16px) scale(.98);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--pb4r-text);
}

#pb4r-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#pb4r-header {
  min-height: 76px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #022c1f, #047857);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
}

#pb4r-avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  font-size: 21px;
}

#pb4r-header-text {
  flex: 1;
  min-width: 0;
}

#pb4r-header-text .name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .01em;
}

#pb4r-header-text .status {
  margin-top: 3px;
  font-size: 11.5px;
  opacity: .78;
  display: flex;
  align-items: center;
  gap: 6px;
}

#pb4r-header-text .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, .13);
}

#pb4r-close-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: rgba(255,255,255,.08);
  cursor: pointer;
  font-size: 17px;
}

#pb4r-close-btn:hover { background: rgba(255,255,255,.16); }

#pb4r-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 14px;
  background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
  scroll-behavior: smooth;
}

.pb4r-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 12px;
}

.pb4r-msg.user { align-items: flex-end; }

.pb4r-bubble {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 15px 15px 15px 5px;
  background: #fff;
  color: #1e293b;
  border: 1px solid var(--pb4r-border);
  box-shadow: 0 4px 14px rgba(15, 23, 42, .05);
  font-size: 13.5px;
  line-height: 1.55;
}

.pb4r-msg.user .pb4r-bubble {
  background: #047857;
  color: #fff;
  border-color: #047857;
  border-radius: 15px 15px 5px 15px;
}

.pb4r-ai-text { white-space: pre-wrap; }

.pb4r-msg-time {
  margin-top: 4px;
  padding: 0 4px;
  font-size: 10px;
  color: #94a3b8;
}

.pb4r-options {
  width: min(88%, 310px);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.pb4r-option {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 11px;
  background: #fff;
  color: #0f5132;
  text-align: left;
  cursor: pointer;
  font: 700 12.5px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}

.pb4r-option:hover {
  background: #ecfdf5;
  border-color: #6ee7b7;
  transform: translateY(-1px);
}

.pb4r-option:disabled {
  opacity: .55;
  cursor: default;
  transform: none;
}

.pb4r-form-msg,
.pb4r-form-bubble {
  width: 100%;
  max-width: 100%;
}

.pb4r-contact-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pb4r-contact-form input {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  outline: none;
  color: #0f172a;
  background: #fff;
  font-size: 13px;
}

.pb4r-contact-form input:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .10);
}

.pb4r-form-error {
  color: #dc2626;
  min-height: 0;
  font-size: 11.5px;
}

.pb4r-form-submit {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.pb4r-form-submit:disabled { opacity: .65; cursor: wait; }

#pb4r-input-area {
  padding: 11px 12px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

#pb4r-input-area.hidden { display: none; }

#pb4r-text-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  outline: none;
  font-size: 13px;
  color: #0f172a;
  background: #f8fafc;
}

#pb4r-text-input:focus {
  background: #fff;
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .10);
}

#pb4r-send-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pb4r-send-btn:disabled { opacity: .5; cursor: wait; }
#pb4r-send-btn svg { width: 19px; height: 19px; }

#pb4r-powered {
  padding: 6px 12px 8px;
  text-align: center;
  background: #fff;
  color: #94a3b8;
  font-size: 9.5px;
  letter-spacing: .01em;
}

.pb4r-typing-row { margin-bottom: 10px; }
.pb4r-typing {
  width: 54px;
  height: 34px;
  border-radius: 14px 14px 14px 5px;
  border: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.pb4r-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: pb4r-dot 1.05s infinite ease-in-out;
}
.pb4r-typing span:nth-child(2) { animation-delay: .15s; }
.pb4r-typing span:nth-child(3) { animation-delay: .30s; }

@keyframes pb4r-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.pb4r-success {
  margin: 8px 0 14px;
  padding: 18px;
  border-radius: 16px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  text-align: center;
}
.pb4r-check {
  width: 38px;
  height: 38px;
  margin: 0 auto 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #047857;
  color: #fff;
  font-weight: 900;
}
.pb4r-success h3 { margin: 0 0 5px; font-size: 16px; }
.pb4r-success p { margin: 0; color: #475569; font-size: 12.5px; line-height: 1.5; }

@media (max-width: 640px) {
  #pb4r-trigger {
    right: 14px;
    bottom: 14px;
    width: 56px;
    height: 56px;
  }
  #pb4r-window {
    right: 10px;
    bottom: 80px;
    width: calc(100vw - 20px);
    height: min(620px, calc(100vh - 96px));
    border-radius: 18px;
  }
}

/* WordPress REST lead-consent row */
.pb4r-chat-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 2px 0 4px;
  color: #64748b;
  font-size: 10.5px;
  line-height: 1.45;
}
.pb4r-chat-consent input {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  margin: 1px 0 0;
  padding: 0;
  accent-color: #047857;
}
.pb4r-chat-consent span { display: block; }
