/* Peptide Expert chat widget */
.pex-root {
  --pex-brand: #2b6cb0;
  --pex-brand-fg: #fff;
  --pex-bg: #fff;
  --pex-text: #1a202c;
  --pex-muted: #718096;
  --pex-border: #e2e8f0;
  --pex-bubble-bg: #f7fafc;
  --pex-radius: 14px;
  --pex-shadow: 0 12px 36px rgba(15, 23, 42, 0.18);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--pex-text);
  line-height: 1.5;
  font-size: 15px;
  box-sizing: border-box;
}
.pex-root *, .pex-root *::before, .pex-root *::after { box-sizing: border-box; }

/* Floating bubble launcher */
.pex-mode-bubble {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999999;
}
.pex-bubble {
  background: var(--pex-brand);
  color: var(--pex-brand-fg);
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--pex-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}
.pex-bubble:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
}
.pex-bubble::before {
  content: "💬";
  margin-right: 8px;
  font-size: 16px;
}

/* Panel */
.pex-panel {
  background: var(--pex-bg);
  border-radius: var(--pex-radius);
  box-shadow: var(--pex-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pex-mode-bubble .pex-panel {
  position: fixed;
  right: 20px;
  bottom: 80px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 580px;
  max-height: calc(100vh - 120px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 999998;
}
.pex-mode-bubble .pex-panel.pex-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.pex-mode-inline .pex-panel {
  position: relative;
  width: 100%;
  height: 560px;
  border: 1px solid var(--pex-border);
}

/* Header */
.pex-header {
  background: var(--pex-brand);
  color: var(--pex-brand-fg);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}
.pex-title { display: flex; align-items: center; gap: 10px; }
.pex-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.25);
}
.pex-close {
  background: transparent;
  color: inherit;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  font-family: inherit;
}

/* Messages */
.pex-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pex-msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}
.pex-msg-user { align-self: flex-end; align-items: flex-end; }
.pex-msg-assistant { align-self: flex-start; align-items: flex-start; }

.pex-bubble-msg {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--pex-bubble-bg);
  color: var(--pex-text);
  max-width: 100%;
  word-wrap: break-word;
}
.pex-msg-user .pex-bubble-msg {
  background: var(--pex-brand);
  color: var(--pex-brand-fg);
  border-bottom-right-radius: 4px;
}
.pex-msg-assistant .pex-bubble-msg {
  background: #fff;
  border: 1px solid var(--pex-border);
  border-bottom-left-radius: 4px;
}
.pex-bubble-msg p { margin: 0 0 8px 0; }
.pex-bubble-msg p:last-child { margin-bottom: 0; }
.pex-bubble-msg a { color: var(--pex-brand); text-decoration: underline; }
.pex-msg-user .pex-bubble-msg a { color: inherit; }

/* Typing indicator */
.pex-typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
}
.pex-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--pex-muted);
  opacity: 0.4;
  animation: pex-blink 1.2s infinite;
}
.pex-typing span:nth-child(2) { animation-delay: 0.15s; }
.pex-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pex-blink {
  0%, 60%, 100% { opacity: 0.2; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* Products */
.pex-products {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}
.pex-product {
  display: flex;
  gap: 10px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--pex-border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--pex-text);
  transition: border-color 0.15s, transform 0.15s;
}
.pex-product:hover {
  border-color: var(--pex-brand);
  transform: translateY(-1px);
}
.pex-prod-img {
  width: 60px; height: 60px;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  border-radius: 8px;
  background-color: #edf2f7;
}
.pex-prod-img-empty { background-color: #edf2f7; }
.pex-prod-body { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.pex-prod-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.pex-prod-price { color: var(--pex-brand); font-weight: 600; font-size: 13px; margin-top: 2px; }
.pex-prod-oos { color: #e53e3e; font-size: 12px; margin-top: 2px; }

/* Coupon */
.pex-coupon {
  margin-top: 8px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(43, 108, 176, 0.06), rgba(43, 108, 176, 0.12));
  border: 1px dashed var(--pex-brand);
  border-radius: 10px;
  text-align: center;
}
.pex-coupon-label { font-size: 11px; color: var(--pex-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.pex-coupon-code {
  font-size: 20px; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 4px 0;
  color: var(--pex-brand);
  letter-spacing: 0.05em;
}
.pex-coupon-desc { font-size: 13px; color: var(--pex-muted); }

/* Lead capture ack */
.pex-ack {
  margin-top: 6px;
  padding: 8px 12px;
  background: #f0fff4;
  border: 1px solid #9ae6b4;
  border-radius: 8px;
  font-size: 13px;
  color: #22543d;
}

/* Input */
.pex-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--pex-border);
  background: #fff;
}
.pex-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--pex-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
  color: var(--pex-text);
  outline: none;
  transition: border-color 0.12s;
}
.pex-textarea:focus { border-color: var(--pex-brand); }
.pex-send {
  background: var(--pex-brand);
  color: var(--pex-brand-fg);
  border: none;
  border-radius: 10px;
  width: 40px; height: 40px;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  transition: opacity 0.15s, transform 0.15s;
}
.pex-send:hover { transform: translateY(-1px); }
.pex-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.pex-footer {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--pex-muted);
  text-align: center;
  background: #fff;
  border-top: 1px solid var(--pex-border);
}

/* Mobile */
@media (max-width: 480px) {
  .pex-mode-bubble .pex-panel {
    right: 10px;
    left: 10px;
    bottom: 80px;
    width: auto;
    max-width: none;
  }
  .pex-bubble { padding: 12px 18px; font-size: 14px; }
}
