/* ====================================================================
   PERDYSY GEMINI CHATBOT v2 — Button-First Conversion UX
   Scoped to .pdsy-chat-* to avoid theme conflicts
   ==================================================================== */

/* ---------- CSS Variables ---------- */
.pdsy-chat {
  --chat-primary: #1b72b9;
  --chat-primary-dark: #145a94;
  --chat-primary-light: #e8f2fc;
  --chat-accent: #e8792b;
  --chat-bg: #ffffff;
  --chat-surface: #f4f6f9;
  --chat-text: #1a1a2e;
  --chat-text-muted: #64748b;
  --chat-radius: 16px;
  --chat-shadow: 0 8px 32px rgba(0,0,0,0.15);
  --chat-font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --chat-transition: 0.3s cubic-bezier(0.4,0,0.2,1);
  font-family: var(--chat-font);
  z-index: 999999;
}

/* ---------- Position ---------- */
.pdsy-chat { position: fixed; bottom: 24px; z-index: 999999; }
.pdsy-chat--bottom-right { right: 24px; }
.pdsy-chat--bottom-left { left: 24px; }

/* ---------- Toggle Button ---------- */
.pdsy-chat__toggle {
  width: 60px; height: 60px; border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 4px 20px rgba(27,114,185,0.4);
  transition: all var(--chat-transition);
  position: relative;
}
.pdsy-chat__toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(27,114,185,0.5);
}
.pdsy-chat__toggle .pdsy-chat__icon-close { display: none; }
.pdsy-chat--open .pdsy-chat__toggle .pdsy-chat__icon-chat { display: none; }
.pdsy-chat--open .pdsy-chat__toggle .pdsy-chat__icon-close { display: block; }

/* Badge */
.pdsy-chat__badge {
  position: absolute; top: -4px; right: -4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #e53e3e; color: #fff;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  animation: pdsy-chat-bounce 0.4s ease;
}
@keyframes pdsy-chat-bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

/* ---------- Chat Window ---------- */
.pdsy-chat__window {
  position: absolute; bottom: 72px;
  width: 380px; max-height: 560px;
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.06);
  animation: pdsy-chat-slide-up 0.3s ease;
}
.pdsy-chat--bottom-right .pdsy-chat__window { right: 0; }
.pdsy-chat--bottom-left .pdsy-chat__window { left: 0; }
.pdsy-chat--open .pdsy-chat__window { display: flex; }

@keyframes pdsy-chat-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Header ---------- */
.pdsy-chat__header {
  background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
  padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.pdsy-chat__header-info { display: flex; align-items: center; gap: 12px; }
.pdsy-chat__avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 16px;
}
.pdsy-chat__header-name { color: #fff; font-weight: 700; font-size: 15px; }
.pdsy-chat__header-status { color: rgba(255,255,255,0.75); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.pdsy-chat__status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #48bb78; display: inline-block;
  animation: pdsy-chat-pulse-dot 2s infinite;
}
@keyframes pdsy-chat-pulse-dot {
  0%, 100% { opacity: 1; } 50% { opacity: 0.5; }
}
.pdsy-chat__minimize {
  background: rgba(255,255,255,0.15); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background var(--chat-transition);
}
.pdsy-chat__minimize:hover { background: rgba(255,255,255,0.25); }

/* ---------- Messages ---------- */
.pdsy-chat__messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 300px; max-height: 360px;
  scroll-behavior: smooth;
}
.pdsy-chat__messages::-webkit-scrollbar { width: 4px; }
.pdsy-chat__messages::-webkit-scrollbar-track { background: transparent; }
.pdsy-chat__messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.pdsy-chat__msg {
  max-width: 85%; padding: 10px 14px;
  border-radius: 14px; font-size: 14px;
  line-height: 1.5; word-wrap: break-word;
  animation: pdsy-chat-msg-in 0.25s ease;
}
@keyframes pdsy-chat-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.pdsy-chat__msg--user {
  background: var(--chat-primary); color: #fff;
  align-self: flex-end; border-bottom-right-radius: 4px;
}
.pdsy-chat__msg--bot {
  background: var(--chat-surface); color: var(--chat-text);
  align-self: flex-start; border-bottom-left-radius: 4px;
}
.pdsy-chat__msg--bot a { color: var(--chat-primary); text-decoration: underline; }

/* ---------- Action Buttons ---------- */
.pdsy-chat__buttons {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-self: flex-start;
  max-width: 95%;
  animation: pdsy-chat-msg-in 0.3s ease;
  margin-top: -4px;
}
.pdsy-chat__btn {
  font-family: var(--chat-font);
  font-size: 13px; font-weight: 600;
  padding: 9px 18px; border-radius: 50px;
  border: 1.5px solid var(--chat-primary);
  background: #fff; color: var(--chat-primary);
  cursor: pointer;
  transition: all var(--chat-transition);
  white-space: nowrap;
  line-height: 1.3;
}
.pdsy-chat__btn:hover {
  background: var(--chat-primary); color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(27,114,185,0.25);
}
.pdsy-chat__btn:active { transform: translateY(0); }
.pdsy-chat__btn--accent {
  border-color: var(--chat-accent);
  color: var(--chat-accent);
}
.pdsy-chat__btn--accent:hover {
  background: var(--chat-accent); color: #fff;
  border-color: var(--chat-accent);
  box-shadow: 0 3px 10px rgba(232,121,43,0.25);
}
.pdsy-chat__btn--full {
  width: 100%; text-align: center;
}

/* ---------- Product Cards ---------- */
.pdsy-chat__products {
  display: flex; flex-direction: column; gap: 8px;
  align-self: flex-start; max-width: 95%;
  animation: pdsy-chat-msg-in 0.3s ease;
}
.pdsy-chat__product {
  display: flex; gap: 12px;
  background: #fff; border: 1px solid #e8ecf1;
  border-radius: 12px; padding: 10px;
  transition: all var(--chat-transition);
}
.pdsy-chat__product:hover {
  border-color: var(--chat-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.pdsy-chat__product-img {
  width: 64px; height: 64px;
  border-radius: 8px; object-fit: cover;
  background: var(--chat-surface);
  flex-shrink: 0;
}
.pdsy-chat__product-info {
  display: flex; flex-direction: column;
  justify-content: center; gap: 2px;
  min-width: 0;
}
.pdsy-chat__product-name {
  font-size: 13px; font-weight: 600;
  color: var(--chat-text);
  white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.pdsy-chat__product-price {
  font-size: 14px; font-weight: 700;
  color: var(--chat-primary);
}
.pdsy-chat__product-cta {
  font-family: var(--chat-font);
  font-size: 11px; font-weight: 600;
  padding: 4px 12px; border-radius: 50px;
  border: none; background: var(--chat-primary);
  color: #fff; cursor: pointer;
  align-self: flex-start;
  margin-top: 2px;
  transition: background var(--chat-transition);
  text-decoration: none; display: inline-block;
}
.pdsy-chat__product-cta:hover { background: var(--chat-primary-dark); }

/* ---------- Typing Indicator ---------- */
.pdsy-chat__typing {
  display: flex; gap: 5px; padding: 10px 14px;
  background: var(--chat-surface); border-radius: 14px;
  align-self: flex-start; border-bottom-left-radius: 4px;
}
.pdsy-chat__typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #94a3b8;
  animation: pdsy-chat-typing 1.4s infinite;
}
.pdsy-chat__typing-dot:nth-child(2) { animation-delay: 0.2s; }
.pdsy-chat__typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pdsy-chat-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Input Area ---------- */
.pdsy-chat__input-area {
  border-top: 1px solid #e8ecf1;
  padding: 12px 16px 16px;
  flex-shrink: 0;
}
.pdsy-chat__form { display: flex; gap: 8px; align-items: center; }
.pdsy-chat__input {
  flex: 1; border: 1.5px solid #e2e8f0;
  border-radius: 12px; padding: 11px 14px;
  font-family: var(--chat-font); font-size: 14px;
  outline: none; transition: border-color var(--chat-transition);
  background: #fff; color: var(--chat-text);
}
.pdsy-chat__input:focus { border-color: var(--chat-primary); }
.pdsy-chat__input::placeholder { color: #94a3b8; }
.pdsy-chat__send {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--chat-primary); border: none;
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--chat-transition);
  flex-shrink: 0;
}
.pdsy-chat__send:hover { background: var(--chat-primary-dark); transform: scale(1.05); }
.pdsy-chat__send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Lead capture label */
.pdsy-chat__input-label {
  font-size: 11px; color: var(--chat-text-muted);
  margin-bottom: 6px; display: none;
}
.pdsy-chat__input-label.active { display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .pdsy-chat__window {
    width: calc(100vw - 32px); bottom: 72px;
    max-height: 75vh;
  }
  .pdsy-chat--bottom-right .pdsy-chat__window { right: -8px; }
  .pdsy-chat--bottom-left .pdsy-chat__window { left: -8px; }
  .pdsy-chat { bottom: 16px; }
  .pdsy-chat--bottom-right { right: 16px; }
  .pdsy-chat--bottom-left { left: 16px; }
  .pdsy-chat__btn { font-size: 12px; padding: 8px 14px; }
}
