/* ==========================================================================
   PureVedic Life Chatbot - Chat Widget Styles
   File: public/assets/chat.css
   Purpose:
   - Premium, modern, clinic-like floating widget
   - Calm Ayurvedic palette (configurable via CSS vars set inline from PHP)
   - Smooth animations, shine banner, chips, typing indicator
   - Mobile responsive + iPhone Safari safe (touch-action, no fixed height clipping)
   - Avoid messing with WP admin UI (scoped under #pvlcb-root)
   ========================================================================== */

/* =========================
   0) Root scope + variables
   ========================= */
#pvlcb-root {
  /* IMPORTANT: allow clicks */
  pointer-events: auto !important;
  position: fixed;
  z-index: 999999;
  /* placement set by JS inline (left/right/top/bottom) */
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji",
    "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  line-height: 1.35;
  letter-spacing: 0.2px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Default palette (can be overridden by inline vars from PHP) */
#pvlcb-root {
  --pvl-primary: #1f7a5c;
  --pvl-secondary: #0b6bcb;
  --pvl-bg: #f6faf8;         /* widget outer background */
  --pvl-panel: #ffffff;      /* panel surface */
  --pvl-text: #173028;
  --pvl-muted: #5e6b65;
  --pvl-border: rgba(23, 48, 40, 0.12);
  --pvl-shadow: 0 18px 50px rgba(14, 28, 22, 0.20);
  --pvl-shadow-soft: 0 10px 30px rgba(14, 28, 22, 0.14);
  --pvl-radius: 16px;
  --pvl-radius-sm: 12px;
  --pvl-radius-xs: 10px;
  --pvl-gap: 10px;

  --pvl-chip-bg: rgba(31, 122, 92, 0.10);
  --pvl-chip-bd: rgba(31, 122, 92, 0.18);
  --pvl-chip-tx: #135843;

  --pvl-user-bubble: linear-gradient(135deg, rgba(31, 122, 92, 0.95), rgba(13, 97, 74, 0.95));
  --pvl-bot-bubble: #ffffff;

  --pvl-focus: 0 0 0 3px rgba(11, 107, 203, 0.18);

  --pvl-danger: #c0392b;
  --pvl-ok: #1f7a5c;

  /* Send button / hover */
  --pvl-send-bg: var(--pvl-primary);
  --pvl-send-bg-hover: #1a6a50;
  --pvl-send-tx: #ffffff;

  /* launcher */
  --pvl-launcher-bg: var(--pvl-primary);
  --pvl-launcher-bg-hover: #1a6a50;
  --pvl-launcher-tx: #ffffff;

  /* banner shine */
  --pvl-shine: linear-gradient(
    110deg,
    rgba(255, 255, 255, 0.00) 0%,
    rgba(255, 255, 255, 0.35) 45%,
    rgba(255, 255, 255, 0.00) 65%
  );
}

/* Prevent any global elements from being affected */
#pvlcb-root *,
#pvlcb-root *::before,
#pvlcb-root *::after {
  box-sizing: border-box;
}

/* Ensure horizontal text; prevent vertical writing-mode bug */
#pvlcb-root,
#pvlcb-root * {
  writing-mode: horizontal-tb !important;
  word-break: normal;
  overflow-wrap: anywhere;
}

/* =========================
   1) Widget container
   ========================= */
#pvlcb-root .pvlcb-widget {
  width: auto;
  height: auto;
  pointer-events: auto;
}

/* =========================
   2) Launcher button
   ========================= */
#pvlcb-root .pvlcb-launcher {
  pointer-events: auto !important;
  touch-action: manipulation;
  cursor: pointer;

  display: inline-flex;
  align-items: center;
  gap: 10px;

  border: 0;
  outline: none;
  padding: 12px 14px;
  border-radius: 999px;

  background: var(--pvl-launcher-bg);
  color: var(--pvl-launcher-tx);
  box-shadow: var(--pvl-shadow-soft);

  transform: translateZ(0);
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

#pvlcb-root .pvlcb-launcher:hover {
  background: var(--pvl-launcher-bg-hover);
  box-shadow: var(--pvl-shadow);
  transform: translateY(-1px);
}

#pvlcb-root .pvlcb-launcher:active {
  transform: translateY(0px) scale(0.98);
}

#pvlcb-root .pvlcb-launcher:focus-visible {
  box-shadow: var(--pvl-shadow-soft), var(--pvl-focus);
}

#pvlcb-root .pvlcb-launcher__icon {
  display: inline-flex;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.16);
  font-size: 18px;
  line-height: 1;
}

#pvlcb-root .pvlcb-launcher__label {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

/* Optional pulse (if you add class later) */
#pvlcb-root .pvlcb-launcher.is-pulse {
  position: relative;
}
#pvlcb-root .pvlcb-launcher.is-pulse::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  background: rgba(31, 122, 92, 0.24);
  animation: pvlcbPulse 1400ms ease-out infinite;
  z-index: -1;
}
@keyframes pvlcbPulse {
  0% { transform: scale(0.90); opacity: 0.55; }
  100% { transform: scale(1.20); opacity: 0.0; }
}

/* =========================
   3) Panel base
   ========================= */
#pvlcb-root .pvlcb-panel {
  pointer-events: auto !important;
  touch-action: manipulation;

  margin-top: 10px;
  width: 370px;
  max-width: min(92vw, 420px);
  height: auto;

  border-radius: var(--pvl-radius);
  overflow: hidden;

  background: var(--pvl-panel);
  box-shadow: var(--pvl-shadow);

  transform-origin: 90% 100%;
  transform: translateY(10px) scale(0.96);
  opacity: 0;
  visibility: hidden;

  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

/* Open */
#pvlcb-root .pvlcb-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
}

/* Mobile sizing */
@media (max-width: 480px) {
  #pvlcb-root .pvlcb-panel {
    width: min(92vw, 420px);
    max-width: 92vw;
  }
}

/* =========================
   4) Header
   ========================= */
#pvlcb-root .pvlcb-header {
  position: relative;
  padding: 14px 14px;
  background: linear-gradient(180deg, rgba(31, 122, 92, 0.10), rgba(31, 122, 92, 0.00));
  border-bottom: 1px solid var(--pvl-border);
}

#pvlcb-root .pvlcb-header__left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#pvlcb-root .pvlcb-header__logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(31, 122, 92, 0.10);
  border: 1px solid rgba(31, 122, 92, 0.18);
  overflow: hidden;
  flex: 0 0 auto;
}

#pvlcb-root .pvlcb-header__titles {
  min-width: 0;
}

#pvlcb-root .pvlcb-header__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--pvl-text);
  line-height: 1.2;
}

#pvlcb-root .pvlcb-header__subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: var(--pvl-muted);
  line-height: 1.2;
  max-width: 260px;
}

#pvlcb-root .pvlcb-close {
  position: absolute;
  right: 10px;
  top: 10px;

  width: 34px;
  height: 34px;
  border-radius: 10px;

  border: 1px solid rgba(23, 48, 40, 0.12);
  background: rgba(255, 255, 255, 0.7);
  color: var(--pvl-text);

  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

#pvlcb-root .pvlcb-close:hover {
  background: rgba(255,255,255,0.95);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(0,0,0,0.12);
}

#pvlcb-root .pvlcb-close:active {
  transform: translateY(0px) scale(0.98);
}

#pvlcb-root .pvlcb-close:focus-visible {
  outline: none;
  box-shadow: var(--pvl-focus);
}

/* =========================
   5) Banner (shine)
   ========================= */
#pvlcb-root .pvlcb-banner {
  display: none; /* will be enabled by JS when message exists */
  position: relative;
  overflow: hidden;
  padding: 10px 14px;
  background: rgba(11, 107, 203, 0.07);
  border-bottom: 1px solid rgba(11, 107, 203, 0.14);
}

#pvlcb-root .pvlcb-banner__text {
  font-size: 12px;
  color: rgba(23, 48, 40, 0.85);
  font-weight: 600;
}

#pvlcb-root .pvlcb-banner__shine {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 60%;
  height: 100%;
  background: var(--pvl-shine);
  transform: skewX(-18deg);
  animation: pvlcbShine 2.6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes pvlcbShine {
  0% { left: -60%; opacity: 0.0; }
  10% { opacity: 1.0; }
  55% { left: 110%; opacity: 0.9; }
  100% { left: 110%; opacity: 0.0; }
}

/* =========================
   6) Body + messages
   ========================= */
#pvlcb-root .pvlcb-body {
  background: var(--pvl-bg);
  padding: 10px;
}

#pvlcb-root .pvlcb-messages {
  /* No fixed heights to avoid clipping */
  max-height: 360px;
  height: auto;
  overflow-y: auto;
  padding: 8px 6px;

  scrollbar-width: thin;
  scrollbar-color: rgba(31,122,92,0.35) rgba(0,0,0,0.06);
}

#pvlcb-root .pvlcb-messages::-webkit-scrollbar {
  width: 8px;
}
#pvlcb-root .pvlcb-messages::-webkit-scrollbar-thumb {
  background: rgba(31, 122, 92, 0.30);
  border-radius: 999px;
}
#pvlcb-root .pvlcb-messages::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.05);
  border-radius: 999px;
}

/* Messages layout */
#pvlcb-root .pvlcb-msg {
  display: flex;
  margin: 10px 0;
}

#pvlcb-root .pvlcb-msg--bot {
  justify-content: flex-start;
}

#pvlcb-root .pvlcb-msg--user {
  justify-content: flex-end;
}

#pvlcb-root .pvlcb-bubble {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;

  box-shadow: 0 8px 18px rgba(0,0,0,0.08);
}

/* Bot bubble */
#pvlcb-root .pvlcb-msg--bot .pvlcb-bubble {
  background: var(--pvl-bot-bubble);
  color: var(--pvl-text);
  border: 1px solid rgba(23, 48, 40, 0.09);
  border-top-left-radius: 10px;
}

/* User bubble */
#pvlcb-root .pvlcb-msg--user .pvlcb-bubble {
  background: var(--pvl-user-bubble);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.10);
  border-top-right-radius: 10px;
}

/* CTA card inside bubble */
#pvlcb-root .pvlcb-cta-card {
  width: 100%;
  background: rgba(255,255,255,0.75);
  border: 1px solid rgba(23, 48, 40, 0.10);
  border-radius: 14px;
  padding: 12px;
}

#pvlcb-root .pvlcb-cta-title {
  font-weight: 800;
  color: var(--pvl-text);
  margin-bottom: 6px;
  font-size: 13px;
}

#pvlcb-root .pvlcb-cta-note {
  color: var(--pvl-muted);
  font-size: 12px;
  margin-bottom: 10px;
}

#pvlcb-root .pvlcb-cta-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

/* CTA buttons */
#pvlcb-root .pvlcb-cta {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
  box-shadow: 0 10px 26px rgba(0,0,0,0.12);
  touch-action: manipulation;
}

#pvlcb-root .pvlcb-cta:active {
  transform: scale(0.99);
}

#pvlcb-root .pvlcb-cta--call {
  background: linear-gradient(135deg, rgba(11, 107, 203, 0.98), rgba(11, 107, 203, 0.78));
  color: #fff;
}

#pvlcb-root .pvlcb-cta--cb {
  background: linear-gradient(135deg, rgba(31, 122, 92, 0.98), rgba(31, 122, 92, 0.78));
  color: #fff;
}

#pvlcb-root .pvlcb-cta--wa {
  background: linear-gradient(135deg, rgba(14, 167, 84, 0.98), rgba(14, 167, 84, 0.78));
  color: #fff;
}

/* Hover readability fix */
#pvlcb-root .pvlcb-cta:hover {
  filter: brightness(1.02);
  box-shadow: 0 14px 30px rgba(0,0,0,0.16);
  transform: translateY(-1px);
}

/* =========================
   7) Typing indicator
   ========================= */
#pvlcb-root .pvlcb-typing {
  display: flex;
  gap: 6px;
  padding: 6px 10px 8px 10px;
  align-items: center;
}

#pvlcb-root .pvlcb-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(23, 48, 40, 0.55);
  animation: pvlcbDot 1.1s infinite ease-in-out;
}

#pvlcb-root .pvlcb-dot:nth-child(2) {
  animation-delay: 0.15s;
}
#pvlcb-root .pvlcb-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pvlcbDot {
  0%, 100% { transform: translateY(0); opacity: 0.45; }
  50% { transform: translateY(-3px); opacity: 0.95; }
}

/* =========================
   8) Chips / quick replies
   ========================= */
#pvlcb-root .pvlcb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 6px 0 6px;
}

#pvlcb-root .pvlcb-chip {
  pointer-events: auto !important;
  touch-action: manipulation;
  cursor: pointer;

  border: 1px solid var(--pvl-chip-bd);
  background: var(--pvl-chip-bg);
  color: var(--pvl-chip-tx);

  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;

  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease, border-color 140ms ease, color 140ms ease;
}

#pvlcb-root .pvlcb-chip:hover {
  background: rgba(31, 122, 92, 0.14);
  border-color: rgba(31, 122, 92, 0.28);
  box-shadow: 0 10px 24px rgba(0,0,0,0.10);
  transform: translateY(-1px);
  /* keep readable on hover */
  color: var(--pvl-chip-tx);
}

#pvlcb-root .pvlcb-chip:active {
  transform: translateY(0px) scale(0.98);
}

#pvlcb-root .pvlcb-chip:focus-visible {
  outline: none;
  box-shadow: var(--pvl-focus);
}

/* 2 per row on small screens */
@media (max-width: 560px) {
  #pvlcb-root .pvlcb-chip {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
  }
}

/* 1 per row on very small */
@media (max-width: 360px) {
  #pvlcb-root .pvlcb-chip {
    flex: 1 1 100%;
  }
}

/* =========================
   9) Footer + input + send
   ========================= */
#pvlcb-root .pvlcb-footer {
  border-top: 1px solid var(--pvl-border);
  background: #ffffff;
  padding: 10px 12px 12px 12px;
}

#pvlcb-root .pvlcb-inputwrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

#pvlcb-root .pvlcb-input {
  flex: 1 1 auto;
  width: 100%;
  border: 1px solid rgba(23, 48, 40, 0.14);
  background: rgba(246, 250, 248, 0.65);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--pvl-text);
  outline: none;
  transition: box-shadow 140ms ease, border-color 140ms ease, background 140ms ease;
}

#pvlcb-root .pvlcb-input::placeholder {
  color: rgba(94, 107, 101, 0.85);
}

#pvlcb-root .pvlcb-input:focus {
  border-color: rgba(11, 107, 203, 0.34);
  box-shadow: var(--pvl-focus);
  background: rgba(246, 250, 248, 0.92);
}

/* Send button fixed placement RIGHT side */
#pvlcb-root .pvlcb-send {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 14px;

  border: 0;
  cursor: pointer;
  touch-action: manipulation;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  background: var(--pvl-send-bg);
  color: var(--pvl-send-tx);

  box-shadow: 0 12px 26px rgba(31, 122, 92, 0.26);
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease, filter 140ms ease;
}

#pvlcb-root .pvlcb-send:hover {
  background: var(--pvl-send-bg-hover);
  box-shadow: 0 16px 34px rgba(31, 122, 92, 0.30);
  transform: translateY(-1px);
  filter: brightness(1.02);
}

#pvlcb-root .pvlcb-send:active {
  transform: translateY(0px) scale(0.98);
}

#pvlcb-root .pvlcb-send:focus-visible {
  outline: none;
  box-shadow: var(--pvl-shadow-soft), var(--pvl-focus);
}

#pvlcb-root .pvlcb-footnote {
  margin-top: 10px;
  font-size: 11px;
  color: rgba(94, 107, 101, 0.95);
}

/* =========================
   10) Open state root helper
   ========================= */
#pvlcb-root.pvlcb-open .pvlcb-launcher {
  /* Slightly dim launcher when open */
  filter: saturate(0.95) brightness(0.98);
}

/* =========================
   11) Accessibility tweaks
   ========================= */
#pvlcb-root button {
  font-family: inherit;
}

#pvlcb-root button:focus {
  outline: none;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  #pvlcb-root .pvlcb-panel,
  #pvlcb-root .pvlcb-launcher,
  #pvlcb-root .pvlcb-chip,
  #pvlcb-root .pvlcb-send,
  #pvlcb-root .pvlcb-cta,
  #pvlcb-root .pvlcb-banner__shine,
  #pvlcb-root .pvlcb-dot {
    animation: none !important;
    transition: none !important;
  }
}

/* =========================
   12) iOS Safari fixes
   ========================= */
#pvlcb-root input,
#pvlcb-root button {
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

#pvlcb-root .pvlcb-panel {
  -webkit-transform: translateZ(0);
}

/* =========================
   13) Minor polish utilities
   ========================= */
#pvlcb-root .pvlcb-panel::before {
  /* Subtle top glow */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 140px;
  background: radial-gradient(circle at 20% 0%, rgba(31, 122, 92, 0.18), rgba(31, 122, 92, 0.00) 60%);
  pointer-events: none;
}

/* Ensure close button stays above */
#pvlcb-root .pvlcb-header,
#pvlcb-root .pvlcb-close {
  position: relative;
  z-index: 2;
}

/* =========================
   14) Strong isolation from theme
   ========================= */
/* Some themes apply global button styles. Force ours only inside root. */
#pvlcb-root .pvlcb-launcher,
#pvlcb-root .pvlcb-close,
#pvlcb-root .pvlcb-chip,
#pvlcb-root .pvlcb-send,
#pvlcb-root .pvlcb-cta {
  text-decoration: none !important;
}

/* Avoid theme adding weird outlines or backgrounds */
#pvlcb-root .pvlcb-launcher,
#pvlcb-root .pvlcb-close,
#pvlcb-root .pvlcb-chip,
#pvlcb-root .pvlcb-send,
#pvlcb-root .pvlcb-cta {
  background-clip: padding-box;
}

/* =========================
   15) Optional: dark mode support
   ========================= */
@media (prefers-color-scheme: dark) {
  #pvlcb-root {
    --pvl-bg: rgba(16, 28, 24, 0.90);
    --pvl-panel: rgba(20, 34, 30, 0.96);
    --pvl-text: rgba(255,255,255,0.92);
    --pvl-muted: rgba(255,255,255,0.66);
    --pvl-border: rgba(255,255,255,0.14);
    --pvl-bot-bubble: rgba(24, 40, 34, 0.96);
    --pvl-chip-bg: rgba(31,122,92,0.14);
    --pvl-chip-bd: rgba(31,122,92,0.22);
    --pvl-chip-tx: rgba(233, 255, 247, 0.88);
  }

  #pvlcb-root .pvlcb-footer {
    background: rgba(20, 34, 30, 0.96);
  }

  #pvlcb-root .pvlcb-input {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.14);
    color: rgba(255,255,255,0.92);
  }

  #pvlcb-root .pvlcb-input::placeholder {
    color: rgba(255,255,255,0.55);
  }

  #pvlcb-root .pvlcb-banner {
    background: rgba(11, 107, 203, 0.14);
    border-bottom-color: rgba(11, 107, 203, 0.20);
  }

  #pvlcb-root .pvlcb-banner__text {
    color: rgba(255,255,255,0.80);
  }
}

/* =========================
   END
   ========================= */