/* ============================================================
   PPA AI Chat Widget — Premium Styles
   ============================================================ */

/* ---------- Variables ---------- */
:root {
  --chat-primary:    #1a3a6b;
  --chat-accent:     #FF5A00;
  --chat-accent2:    #ff7a30;
  --chat-bg:         #0d1f3c;
  --chat-surface:    #152847;
  --chat-bubble-ai:  #1c3254;
  --chat-bubble-usr: #FF5A00;
  --chat-text:       #e8eef7;
  --chat-muted:      #7b91b0;
  --chat-border:     rgba(255,255,255,0.09);
  --chat-glow:       rgba(255,90,0,0.25);
  --chat-radius:     18px;
  --chat-w:          380px;
  --chat-h:          580px;
  --chat-z:          var(--z-chat, 9999);
  --chat-edge:       var(--floating-edge, max(1rem, env(safe-area-inset-right)));
  --chat-bottom:     var(--floating-bottom, max(1rem, env(safe-area-inset-bottom)));
}

/* ---------- Floating trigger button ---------- */
#ppa-chat-trigger {
  position: fixed;
  bottom: calc(var(--chat-bottom) + (var(--floating-size, 60px) + var(--floating-gap, 12px)) * 2);
  right: var(--chat-edge);
  z-index: var(--chat-z);
  width: var(--floating-size, 60px);
  height: var(--floating-size, 60px);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent2));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--chat-glow), 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.25s;
  outline: none;
}
#ppa-chat-trigger:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px var(--chat-glow), 0 4px 12px rgba(0,0,0,0.35);
}
#ppa-chat-trigger i {
  font-size: 1.5rem;
  color: #fff;
  transition: transform 0.3s;
}
#ppa-chat-trigger.is-open i.ph-chats-circle {
  display: none;
}
#ppa-chat-trigger.is-open i.ph-x {
  display: block !important;
}
#ppa-chat-trigger i.ph-x {
  display: none;
}

/* Pulse ring for new users */
#ppa-chat-trigger::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--chat-accent);
  opacity: 0;
  animation: chatPulse 2.5s ease-out infinite;
  animation-play-state: paused;
}
#ppa-chat-trigger.pulse::before {
  animation-play-state: running;
}
@keyframes chatPulse {
  0%   { transform: scale(0.95); opacity: 0.7; }
  70%  { transform: scale(1.3);  opacity: 0;   }
  100% { transform: scale(0.95); opacity: 0;   }
}

/* ---------- Notification bubble ---------- */
#ppa-chat-notif {
  position: fixed;
  bottom: calc(var(--chat-bottom) + (var(--floating-size, 60px) + var(--floating-gap, 12px)) * 3);
  right: var(--chat-edge);
  z-index: var(--chat-z);
  background: #fff;
  color: #1a3a6b;
  border-radius: 14px 14px 2px 14px;
  padding: 0.75rem 1rem;
  max-width: 220px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.1);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  transform: scale(0) translateY(10px);
  transform-origin: bottom right;
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
  opacity: 0;
  pointer-events: none;
}
#ppa-chat-notif.show {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
#ppa-chat-notif .notif-avatar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
#ppa-chat-notif .notif-avatar span {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--chat-primary);
}
#ppa-chat-notif .notif-avatar .dot {
  width: 8px; height: 8px;
  background: #22c55e;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---------- Chat window ---------- */
#ppa-chat-window {
  position: fixed;
  bottom: calc(var(--chat-bottom) + var(--floating-size, 60px) + var(--floating-gap, 12px));
  right: var(--chat-edge);
  z-index: var(--chat-z);
  width: var(--chat-w);
  height: min(var(--chat-h), calc(100dvh - var(--banner-height, 0px) - 2rem));
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  border: 1px solid var(--chat-border);
  box-shadow: 0 25px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.85) translateY(30px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.3s;
  backdrop-filter: blur(20px);
}
#ppa-chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Header */
#ppa-chat-header {
  background: linear-gradient(135deg, #0f2547 0%, #1a3a6b 100%);
  padding: 0.9rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--chat-glow);
}
.chat-header-info {
  flex: 1;
}
.chat-header-info h4 {
  color: #fff;
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0 0 0.1rem;
}
.chat-header-info p {
  color: #86efac;
  font-size: 0.72rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.chat-header-info p::before {
  content: '';
  width: 6px; height: 6px;
  background: #22c55e;
  border-radius: 50%;
  display: inline-block;
}
.chat-header-actions {
  display: flex;
  gap: 0.4rem;
}
.chat-header-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: rgba(255,255,255,0.7);
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s;
}
.chat-header-btn:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* Messages area */
#ppa-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#ppa-chat-messages::-webkit-scrollbar { width: 4px; }
#ppa-chat-messages::-webkit-scrollbar-track { background: transparent; }
#ppa-chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

/* Individual messages */
.chat-msg {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  animation: msgIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-msg.user {
  flex-direction: row-reverse;
}
.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #fff;
  flex-shrink: 0;
}
.msg-bubble {
  max-width: 82%;
  padding: 0.6rem 0.9rem;
  border-radius: 16px 16px 16px 4px;
  background: var(--chat-bubble-ai);
  color: var(--chat-text);
  font-size: 0.84rem;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  border: 1px solid var(--chat-border);
}
.chat-msg.user .msg-bubble {
  background: var(--chat-bubble-usr);
  border-radius: 16px 16px 4px 16px;
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px rgba(255,90,0,0.3);
}
.msg-bubble strong { color: #fff; }
.msg-bubble a {
  color: #60a5fa;
  text-decoration: underline;
}
.msg-bubble ul {
  margin: 0.4rem 0 0 1rem;
  padding: 0;
}
.msg-bubble li { margin-bottom: 0.2rem; }

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.6rem 0.9rem;
  background: var(--chat-bubble-ai);
  border-radius: 16px 16px 16px 4px;
  border: 1px solid var(--chat-border);
  width: fit-content;
  max-width: 70px;
}
.chat-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--chat-muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ---------- Product widget cards ---------- */
.chat-product-card {
  background: linear-gradient(135deg, #1c3254, #1a2f4a);
  border: 1px solid rgba(255,90,0,0.25);
  border-radius: 14px;
  padding: 0.75rem;
  margin-top: 0.4rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  max-width: 100%;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: border-color 0.2s, transform 0.2s;
}
.chat-product-card:hover {
  border-color: rgba(255,90,0,0.55);
  transform: translateY(-1px);
}
.chat-product-img {
  width: 56px; height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: #0f2035;
  flex-shrink: 0;
}
.chat-product-img-placeholder {
  width: 56px; height: 56px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0f2035, #1a3a6b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--chat-accent);
  flex-shrink: 0;
}
.chat-product-info {
  flex: 1;
  min-width: 0;
}
.chat-product-info h5 {
  color: #e8eef7;
  font-size: 0.8rem;
  font-weight: 700;
  margin: 0 0 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-product-info p {
  color: var(--chat-muted);
  font-size: 0.72rem;
  margin: 0 0 0.4rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-product-actions {
  display: flex;
  gap: 0.35rem;
}
.chat-prod-btn {
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: opacity 0.2s, transform 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.chat-prod-btn:hover { opacity: 0.85; transform: scale(1.04); }
.chat-prod-btn.add {
  background: var(--chat-accent);
  color: #fff;
}
.chat-prod-btn.wa {
  background: #25D366;
  color: #fff;
}
.chat-prod-btn.view {
  background: rgba(255,255,255,0.1);
  color: var(--chat-text);
}

/* ---------- Input area ---------- */
#ppa-chat-inputarea {
  padding: 0.75rem 0.85rem;
  background: var(--chat-surface);
  border-top: 1px solid var(--chat-border);
  flex-shrink: 0;
}
.chat-quick-chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-bottom: 0.6rem;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chat-quick-chips::-webkit-scrollbar { display: none; }
.chat-chip {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--chat-muted);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.72rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  flex-shrink: 0;
}
.chat-chip:hover {
  background: rgba(255,90,0,0.15);
  border-color: rgba(255,90,0,0.4);
  color: #fff;
}
.chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
#ppa-chat-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 0.6rem 0.85rem;
  color: var(--chat-text);
  font-size: 0.84rem;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  line-height: 1.5;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  overflow-y: auto;
}
#ppa-chat-input::placeholder { color: var(--chat-muted); }
#ppa-chat-input:focus {
  border-color: rgba(255,90,0,0.5);
}
#ppa-chat-send {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent2));
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 2px 8px rgba(255,90,0,0.3);
}
#ppa-chat-send:hover { opacity: 0.9; transform: scale(1.05); }
#ppa-chat-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* ---------- Disclaimer text ---------- */
.chat-disclaimer {
  text-align: center;
  font-size: 0.65rem;
  color: var(--chat-muted);
  margin-top: 0.4rem;
}

/* ---------- Mobile overrides ---------- */
@media (max-width: 480px) {
  :root {
    --chat-w: min(380px, calc(100vw - 1rem));
    --chat-h: min(72dvh, calc(100dvh - var(--banner-height, 0px) - 1.5rem));
  }
  #ppa-chat-window {
    right: 0.5rem;
    bottom: calc(var(--chat-bottom) + var(--floating-size, 60px) + var(--floating-gap, 12px));
    max-height: calc(100dvh - var(--banner-height, 0px) - 6rem - env(safe-area-inset-bottom));
    border-radius: 16px;
  }
  #ppa-chat-trigger {
    right: var(--chat-edge);
    bottom: calc(var(--chat-bottom) + (var(--floating-size, 60px) + var(--floating-gap, 12px)) * 2);
    width: 56px;
    height: 56px;
  }
  #ppa-chat-notif {
    right: var(--chat-edge);
    bottom: calc(var(--chat-bottom) + (var(--floating-size, 60px) + var(--floating-gap, 12px)) * 3);
    max-width: 180px;
  }
  #ppa-chat-header {
    padding: 0.75rem 0.85rem;
  }
  .chat-header-info h4 {
    font-size: 0.86rem;
  }
  .chat-header-info p {
    font-size: 0.68rem;
  }
  .chat-header-btn {
    width: 34px;
    height: 34px;
  }
  #ppa-chat-messages {
    padding: 0.8rem 0.7rem;
  }
  #ppa-chat-inputarea {
    padding: 0.65rem 0.7rem;
  }
  .chat-product-card {
    align-items: flex-start;
  }
}

@media (max-width: 360px) {
  #ppa-chat-window {
    right: 0.35rem;
    width: calc(100vw - 0.7rem);
  }
  .chat-header-avatar {
    width: 34px;
    height: 34px;
  }
  .chat-header-actions {
    gap: 0.25rem;
  }
  .chat-product-card {
    flex-direction: column;
  }
  .chat-product-actions {
    flex-wrap: wrap;
  }
}
