/* ============================================================
   Chat Widget — Axera Flow (Phase 01)
   Vanilla CSS + Alpine.js. Matches landing v2 brand tokens.
   Spec: ~/Axera Flow/Marketing/bloco-4.5/01-chat-widget-SPEC.md
   ============================================================ */

.cw-root { position: fixed; bottom: 24px; right: 24px; z-index: 80; font-family: var(--font-body); }
.cw-root[x-cloak] { display: none !important; }

/* ============ Bubble (collapsed state) ============ */
.cw-bubble {
  display: flex; align-items: center; justify-content: center;
  width: 60px; height: 60px;
  border-radius: 999px;
  background: var(--grad-electric);
  color: #fff;
  border: 0; cursor: pointer;
  box-shadow: 0 8px 28px rgba(27, 79, 232, 0.35), 0 2px 8px rgba(11, 15, 26, 0.12);
  transition: transform .18s ease, box-shadow .18s ease, opacity .25s ease;
  opacity: 0; transform: translateY(8px) scale(0.96);
  pointer-events: none;
}
.cw-root.cw-visible .cw-bubble { opacity: 1; transform: none; pointer-events: auto; }
.cw-bubble:hover { transform: translateY(-1px) scale(1.03); box-shadow: 0 12px 32px rgba(27, 79, 232, 0.45), 0 4px 10px rgba(11, 15, 26, 0.18); }
.cw-bubble:active { transform: scale(0.97); }
.cw-bubble svg { width: 26px; height: 26px; }

/* Pulse animation for UTM-driven hero pivot (5s on load) */
@keyframes cw-pulse {
  0%, 100% { box-shadow: 0 8px 28px rgba(27, 79, 232, 0.35), 0 2px 8px rgba(11, 15, 26, 0.12), 0 0 0 0 rgba(42, 111, 255, 0.5); }
  50%      { box-shadow: 0 12px 36px rgba(27, 79, 232, 0.5), 0 4px 12px rgba(11, 15, 26, 0.18), 0 0 0 12px rgba(42, 111, 255, 0); }
}
.cw-bubble.cw-pulse { animation: cw-pulse 1.4s ease-in-out 3; }

/* ============ Panel (expanded state) ============ */
.cw-panel {
  position: absolute; bottom: 76px; right: 0;
  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 120px));
  background: #FFFFFF;
  border: 1px solid var(--line-l);
  border-radius: var(--r-lg);
  box-shadow: 0 24px 56px rgba(11, 15, 26, 0.18), 0 8px 16px rgba(11, 15, 26, 0.08);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
}

.cw-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-l);
  background: linear-gradient(180deg, #FBFCFE 0%, #F6F7FA 100%);
}
.cw-header-title { display: flex; align-items: center; gap: 10px; }
.cw-header-dot {
  width: 8px; height: 8px; border-radius: 999px;
  background: #2BB673;
  box-shadow: 0 0 0 3px rgba(43, 182, 115, 0.18);
}
.cw-header-name { font-weight: 600; color: var(--text); font-size: 14px; }
.cw-header-sub { color: var(--text-soft); font-size: 12px; }
.cw-close {
  background: transparent; border: 0; cursor: pointer; padding: 4px 8px;
  color: var(--text-soft); border-radius: var(--r-sm);
  font-size: 18px; line-height: 1;
}
.cw-close:hover { background: rgba(11, 15, 26, 0.06); color: var(--text); }

/* ============ Messages ============ */
.cw-messages {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg);
  scroll-behavior: smooth;
}
.cw-msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: var(--r-md);
  font-size: 14px; line-height: 1.45;
  word-wrap: break-word; overflow-wrap: break-word;
  white-space: pre-wrap;
}
.cw-msg-user {
  align-self: flex-end;
  background: var(--grad-electric);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.cw-msg-assistant {
  align-self: flex-start;
  background: #FFFFFF;
  color: var(--text);
  border: 1px solid var(--line-l);
  border-bottom-left-radius: 6px;
}
.cw-msg-assistant a { color: #1B4FE8; text-decoration: underline; }
.cw-msg-system {
  align-self: center;
  background: rgba(11, 15, 26, 0.04);
  color: var(--text-soft);
  font-size: 12px; font-style: italic;
  max-width: 95%; text-align: center;
}

/* Welcome message */
.cw-welcome {
  align-self: flex-start;
  max-width: 95%;
  padding: 12px 14px;
  background: #FFFFFF;
  border: 1px solid var(--line-l);
  border-radius: var(--r-md);
  border-bottom-left-radius: 6px;
  color: var(--text);
  font-size: 14px; line-height: 1.5;
}

/* Loading dots */
.cw-typing { align-self: flex-start; display: flex; gap: 4px; padding: 14px 16px; }
.cw-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-soft);
  animation: cw-bounce 1.2s infinite ease-in-out;
}
.cw-typing span:nth-child(2) { animation-delay: 0.15s; }
.cw-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cw-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

/* ============ Input ============ */
.cw-input-row {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line-l);
  background: #FFFFFF;
}
.cw-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line-l);
  border-radius: var(--r-md);
  font: inherit; font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cw-input:focus { border-color: #2A6FFF; box-shadow: 0 0 0 3px rgba(42, 111, 255, 0.15); }
.cw-input:disabled { opacity: 0.6; cursor: not-allowed; }
.cw-input::placeholder { color: var(--text-soft); }

.cw-send {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: 0; border-radius: 999px;
  background: var(--grad-electric);
  color: #fff; cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}
.cw-send:hover:not(:disabled) { transform: translateY(-1px); }
.cw-send:disabled { opacity: 0.4; cursor: not-allowed; }
.cw-send svg { width: 16px; height: 16px; }

.cw-footer {
  padding: 8px 14px 10px;
  text-align: center;
  font-size: 11px;
  color: var(--text-soft);
  border-top: 1px solid var(--line-l);
  background: #FFFFFF;
}
.cw-footer a { color: var(--text-soft); text-decoration: underline; }

/* Honeypot (anti-bot) — hidden but in DOM for bots to fill */
.cw-honeypot {
  position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden;
  opacity: 0; pointer-events: none; tab-index: -1;
}

/* ============ Responsive (mobile) ============ */
@media (max-width: 480px) {
  .cw-root { bottom: 16px; right: 16px; left: 16px; }
  .cw-bubble { margin-left: auto; }
  .cw-panel {
    width: 100%;
    right: 0;
    height: min(80vh, 560px);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .cw-bubble, .cw-send, .cw-msg { transition: none; }
  .cw-bubble.cw-pulse { animation: none; }
  .cw-typing span { animation: none; opacity: 0.7; }
  .cw-messages { scroll-behavior: auto; }
}
