/* ── Trigger button ── */
#cw-trigger {
  position: fixed;
  bottom: calc(54px + 16px);
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg2);
  border: 1px solid var(--line);
  cursor: pointer;
  z-index: var(--z-floating-action, 280);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text);
  transition: box-shadow 200ms ease;
  padding: 0;
}

#cw-trigger:hover {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--teal) 25%, transparent);
}

/* stand down while the fullscreen mobile menu is open */
body.menu-open #cw-trigger,
body.menu-open #cw-panel { display: none; }

/* Icon visibility: show chat icon by default, hide X */
.cw-icon-chat { display: block; }
.cw-icon-close { display: none; }

/* When panel is open, swap icons (JS adds .cw-open to trigger) */
#cw-trigger[aria-expanded="true"] .cw-icon-chat { display: none; }
#cw-trigger[aria-expanded="true"] .cw-icon-close { display: block; }

/* ── Notification badge ── */
#cw-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger, #ef4444);
  display: none; /* JS shows it when there's a notification */
}

/* ── Nudge bubble ("¿Charlamos?") ── one-time, auto-hiding prompt above the launcher */
#cw-nudge {
  position: fixed;
  right: 24px;
  bottom: calc(54px + 16px + 56px + 12px); /* sits just above the 56px trigger */
  margin: 0;
  padding: 9px 15px;
  max-width: 60vw;
  background: var(--teal);
  color: rgb(2, 23, 27);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  border: 0;
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  z-index: var(--z-floating-action, 280);
  transform-origin: bottom right;
  animation: cwNudgeIn 0.42s cubic-bezier(0.16, 1, 0.3, 1) both;
}
#cw-nudge[hidden] { display: none; }
#cw-nudge::after {
  content: '';
  position: absolute;
  right: 22px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  background: var(--teal);
  border-radius: 0 0 3px 0;
  transform: rotate(45deg);
}
#cw-nudge.cw-nudge-out { animation: cwNudgeOut 0.3s ease forwards; }

@keyframes cwNudgeIn {
  from { opacity: 0; transform: translateY(10px) scale(0.88); }
  to   { opacity: 1; transform: none; }
}
@keyframes cwNudgeOut {
  to { opacity: 0; transform: translateY(6px) scale(0.94); }
}

/* gentle attention pulse on the launcher while the nudge is up (3 cycles) */
#cw-trigger.cw-pulse { animation: cwPulse 2s ease-out 3; }
@keyframes cwPulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--teal) 50%, transparent); }
  70%  { box-shadow: 0 0 0 13px color-mix(in srgb, var(--teal) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--teal) 0%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  #cw-nudge, #cw-nudge.cw-nudge-out { animation: none; }
  #cw-trigger.cw-pulse { animation: none; }
}

/* ── Panel ── */
#cw-panel {
  position: fixed;
  bottom: 136px;
  right: 24px;
  width: 360px;
  height: 500px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: var(--z-modal, 600);
  overflow: hidden;
}

/* hidden attribute keeps panel invisible; .cw-open triggers slide-up */
#cw-panel[hidden] { display: none; }

#cw-panel.cw-open {
  display: flex;
  animation: cwSlideUp 250ms var(--ease-out) both;
}

@keyframes cwSlideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── Header ── */
#cw-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
  color: var(--c-text);
  flex-shrink: 0;
}

#cw-header-title {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--c-text);
  flex: 1;
}

#cw-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--mut);
  cursor: pointer;
  padding: 0;
  transition: color 200ms, background 200ms;
  flex-shrink: 0;
}

#cw-close:hover {
  color: var(--c-text);
  background: var(--surf);
}

/* ── Messages area ── */
#cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

/* Bot bubble */
.cw-bubble {
  background: var(--surf);
  border: 1px solid var(--line);
  border-radius: 12px 12px 12px 4px;
  padding: 10px 14px;
  color: var(--c-text);
  font-size: 0.9rem;
  line-height: 1.5;
  font-family: inherit;
  animation: cwFadeIn 200ms ease both;
}

@keyframes cwFadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Typing indicator ── */
#cw-typing {
  padding: 8px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

#cw-typing[hidden] { display: none; }

/* Typing dots */
#cw-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--teal);
  animation: cwPulse 1s infinite;
}

#cw-typing span:nth-child(1) { animation-delay: 0s; }
#cw-typing span:nth-child(2) { animation-delay: 0.2s; }
#cw-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes cwPulse {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* ── Options container ── */
#cw-options {
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* Option buttons */
.cw-opt {
  width: 100%;
  padding: 10px 16px;
  border-radius: 24px;
  border: 1px solid var(--teal);
  background: transparent;
  color: var(--teal);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  text-align: left;
  transition: background 200ms, color 200ms;
  min-height: 44px;
}

.cw-opt:hover {
  background: var(--teal);
  color: var(--bg);
}

/* Back button variant */
.cw-opt--back {
  border-color: var(--mut);
  color: var(--mut);
}

.cw-opt--back:hover {
  background: var(--mut);
  color: var(--bg);
}

/* WhatsApp button variant */
.cw-opt--wa {
  border-color: #25D366;
  color: #25D366;
}

.cw-opt--wa:hover {
  background: #25D366;
  color: var(--bg);
}

/* ── Responsive: mobile bottom-sheet ── */
@media (max-width: 639px) {
  #cw-panel {
    bottom: 0;
    right: 0;
    width: 100%;
    height: calc(70vh - env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  #cw-trigger {
    bottom: calc(54px + 12px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  #cw-panel.cw-open,
  .cw-bubble,
  #cw-typing span {
    animation: none !important;
  }
}
