/* ============================================================
   ZARGOLOGIX AI CHAT WIDGET
   Requires tokens.css to already be loaded on the page (true on
   every page of the marketing site and the Help Center). Uses only
   existing design tokens — no new colours, fonts, or shadows.
   ============================================================ */

/* Hide while the mobile nav drawer is open — matches the exact
   pattern already used for the WhatsApp/back-to-top floats
   (`body.menu-open .floats{display:none}`), since the launcher's
   z-index otherwise renders on top of the open drawer. */
body.menu-open .zlc-launcher,
body.menu-open .zlc-panel { display: none; }

.zlc-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9500;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--grad-blue);
  box-shadow: var(--sh-blue, 0 8px 24px rgba(21,101,192,.35));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: transform .2s, box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
}
.zlc-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(21,101,192,.45); }
.zlc-launcher svg { width: 24px; height: 24px; }
.zlc-launcher .zlc-icon-close { display: none; }
.zlc-launcher[aria-expanded="true"] .zlc-icon-chat { display: none; }
.zlc-launcher[aria-expanded="true"] .zlc-icon-close { display: block; }
.zlc-launcher-badge {
  position: absolute; top: -3px; right: -3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--green-500, #22C55E);
  border: 2px solid white;
}
/* When the site's WhatsApp/back-to-top floats are present, stack above them.
   .floats is 104px tall (48px WhatsApp + 8px gap + 48px back-to-top), sitting
   at bottom:20px — so its top edge is at 124px. 140px gives the launcher a
   clean 16px gap above the back-to-top button instead of overlapping it. */
.floats ~ .zlc-launcher,
body:has(.floats) .zlc-launcher { bottom: 140px; }

.zlc-panel {
  position: fixed;
  right: 20px;
  bottom: 88px;
  z-index: 9499;
  width: min(392px, calc(100vw - 40px));
  height: min(600px, calc(100vh - 140px));
  background: white;
  border-radius: var(--r20, 20px);
  box-shadow: 0 24px 64px rgba(10,22,40,.28), 0 0 0 1px var(--g200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.98);
  pointer-events: none;
  transition: opacity .22s cubic-bezier(.4,0,.2,1), transform .22s cubic-bezier(.4,0,.2,1);
}
.zlc-panel.is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
/* Keeps the panel's usual 12px gap above the launcher: 140px + 56px + 12px. */
body:has(.floats) .zlc-panel { bottom: 208px; }

@media (max-width: 480px) {
  .zlc-panel { right: 12px; left: 12px; width: auto; bottom: 84px; height: min(70vh, 560px); }
  .zlc-launcher { right: 16px; bottom: 16px; }
  /* .floats keeps the same 104px/bottom:20px footprint at this breakpoint
     (it has no mobile override), so the same 140px/208px values apply. */
  .floats ~ .zlc-launcher, body:has(.floats) .zlc-launcher { bottom: 140px; }
  body:has(.floats) .zlc-panel { bottom: 208px; }
}

/* Header */
.zlc-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  background: var(--grad-hero);
  flex-shrink: 0;
}
.zlc-header-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.zlc-header-avatar svg { width: 18px; height: 18px; color: white; }
.zlc-header-text { flex: 1; min-width: 0; }
.zlc-header-title { font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 700; font-size: .88rem; color: white; line-height: 1.3; }
.zlc-header-status { display: flex; align-items: center; gap: 5px; font-size: .68rem; color: rgba(255,255,255,.6); margin-top: 1px; }
.zlc-header-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green-500, #22C55E); flex-shrink: 0; }
.zlc-header-close {
  width: 30px; height: 30px; border-radius: var(--r8);
  border: none; background: rgba(255,255,255,.08); color: rgba(255,255,255,.8);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background .15s; flex-shrink: 0;
}
.zlc-header-close:hover { background: rgba(255,255,255,.16); color: white; }
.zlc-header-close svg { width: 15px; height: 15px; }

/* Message thread */
.zlc-thread {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--g50);
}
.zlc-msg { display: flex; gap: 8px; max-width: 88%; }
.zlc-msg--user { align-self: flex-end; flex-direction: row-reverse; }
.zlc-msg--assistant { align-self: flex-start; }
.zlc-msg-avatar {
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  margin-top: 2px;
}
.zlc-msg--assistant .zlc-msg-avatar { background: var(--grad-blue); }
.zlc-msg--assistant .zlc-msg-avatar svg { width: 13px; height: 13px; color: white; }
.zlc-msg-bubble {
  padding: 10px 13px;
  border-radius: var(--r14, 14px);
  font-size: .84rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.zlc-msg--user .zlc-msg-bubble { background: var(--grad-blue); color: white; border-bottom-right-radius: 4px; }
.zlc-msg--assistant .zlc-msg-bubble { background: white; color: var(--g800, var(--g700)); border: 1px solid var(--g200); border-bottom-left-radius: 4px; }
.zlc-msg-bubble a { color: var(--blue700); font-weight: 600; text-decoration: underline; }
.zlc-msg--user .zlc-msg-bubble a { color: white; text-decoration-color: rgba(255,255,255,.5); }

.zlc-typing { display: flex; gap: 4px; padding: 4px 2px; }
.zlc-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--g400);
  animation: zlc-bounce 1.2s infinite ease-in-out;
}
.zlc-typing span:nth-child(2) { animation-delay: .15s; }
.zlc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes zlc-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Welcome / suggestions */
.zlc-welcome { padding: 4px 2px 8px; }
.zlc-welcome-title { font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 700; font-size: .95rem; color: var(--navy); margin-bottom: 4px; }
.zlc-welcome-sub { font-size: .8rem; color: var(--g600); line-height: 1.55; margin-bottom: 12px; }
.zlc-suggestions { display: flex; flex-direction: column; gap: 6px; }
.zlc-suggestion {
  text-align: left; font-size: .8rem; font-weight: 500; color: var(--navy);
  background: white; border: 1px solid var(--g200); border-radius: var(--r10);
  padding: 9px 12px; cursor: pointer; transition: all .15s;
}
.zlc-suggestion:hover { border-color: var(--blue400); background: var(--blue50); }

/* Error / notice bubble */
.zlc-notice {
  align-self: center; font-size: .74rem; color: var(--g500);
  background: var(--g100); border-radius: 99px; padding: 5px 12px;
  text-align: center;
}
.zlc-notice--error { color: var(--amber-700, #92400E); background: var(--amber-bg, #FEF3C7); }

/* Composer */
.zlc-composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px; border-top: 1px solid var(--g200);
  background: white; flex-shrink: 0;
}
.zlc-input {
  flex: 1; resize: none; border: 1.5px solid var(--g200); border-radius: var(--r12);
  padding: 9px 12px; font-family: inherit; font-size: .84rem; line-height: 1.4;
  max-height: 90px; outline: none; transition: border-color .15s;
  color: var(--g900);
}
.zlc-input:focus { border-color: var(--blue400); }
.zlc-input:disabled { background: var(--g50); color: var(--g400); }
.zlc-send {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  border: none; background: var(--grad-blue); color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .1s;
}
.zlc-send:hover:not(:disabled) { transform: scale(1.05); }
.zlc-send:disabled { opacity: .4; cursor: not-allowed; }
.zlc-send svg { width: 15px; height: 15px; }

.zlc-footer-note {
  text-align: center; font-size: .65rem; color: var(--g400);
  padding: 6px 12px 10px; background: white;
}
.zlc-footer-note a { color: var(--g500); text-decoration: underline; }

/* Scrollbar to match the rest of the site */
.zlc-thread::-webkit-scrollbar { width: 4px; }
.zlc-thread::-webkit-scrollbar-track { background: transparent; }
.zlc-thread::-webkit-scrollbar-thumb { background: var(--g300); border-radius: 99px; }

/* ============================================================
   WHATSAPP FLOAT — "feels alive" touches
   Purely decorative CSS (no layout, no new HTML/JS): a soft
   continuous pulse ring behind the button, plus a short, on-brand
   nudge that floats OUTSIDE the button (never inside it) and
   fades away on its own. Both are position:absolute overlays, so
   they never take up layout space or push anything else around.
   Always active (not gated behind a media query) so it's never
   silently switched off — prefers-reduced-motion only simplifies
   the motion further down, it doesn't remove the feature.
   ============================================================ */
.float-btn--wa { position: relative; }

/* Soft pulse ring, always-on, subtle */
.float-btn--wa::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: #25D366;
  opacity: .5;
  animation: zlWaPulse 2.6s ease-out infinite;
  pointer-events: none;
}
@keyframes zlWaPulse {
  0%   { transform: scale(1);    opacity: .45; }
  70%  { transform: scale(1.7);  opacity: 0; }
  100% { transform: scale(1.7);  opacity: 0; }
}

/* Short, on-brand nudge card — sits to the left of the button,
   never overlapping or resizing it. Visible for ~3s roughly
   every 13s, and pauses on hover so it's never in the way. */
.float-btn--wa::before {
  content: "Need help with your shipment?";
  position: absolute;
  z-index: 1;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(8px) scale(.94);
  background: var(--white, #fff);
  color: var(--navy, #0A1628);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: .72rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: .01em;
  white-space: nowrap;
  padding: 9px 14px;
  border-radius: var(--r12, 12px);
  border: 1px solid var(--g200, #E5E7EB);
  box-shadow: var(--sh3, 0 8px 32px rgba(0,0,0,.1), 0 4px 12px rgba(0,0,0,.06));
  opacity: 0;
  pointer-events: none;
  animation: zlWaBubble 13s cubic-bezier(.2,.8,.2,1) 2s infinite;
}
.float-btn--wa:hover::before { animation-play-state: paused; opacity: 0; }
@keyframes zlWaBubble {
  0%, 15%  { opacity: 0; transform: translateY(-50%) translateX(8px) scale(.94); }
  19%, 34% { opacity: 1; transform: translateY(-50%) translateX(0) scale(1); }
  38%, 100%{ opacity: 0; transform: translateY(-50%) translateX(8px) scale(.94); }
}

/* Reduced motion: skip CSS animation entirely (some browsers force
   ALL animation durations to ~0 when this is on, which would make
   a CSS-only version silently never appear no matter how it's
   written). ai-chat.js drives an instant, non-animated show/hide on
   the same ~13s schedule via this class instead. */
@media (prefers-reduced-motion: reduce) {
  .float-btn--wa::after { animation: none; opacity: .35; }
  .float-btn--wa::before {
    animation: none;
    transform: translateY(-50%);
  }
  .float-btn--wa.zl-wa-nudge::before { opacity: 1; }
}
