/*
 * chat-widget.css — Widget flotante de chat
 * Tokens de root.css
 */

/* ── Trigger (botón flotante) ────────────────────────────────────────── */
.cw-trigger {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 1000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(0 0 0 / 0.35);
  transition:
    transform 200ms ease,
    box-shadow 200ms ease;
}

.cw-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(0 0 0 / 0.45);
}

.cw-trigger__icon svg {
  width: 24px;
  height: 24px;
}

/* ── Panel ───────────────────────────────────────────────────────────── */
.cw-panel {
  position: fixed;
  bottom: calc(var(--space-6) + 56px + var(--space-3));
  right: var(--space-6);
  z-index: 999;
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 48px rgba(0 0 0 / 0.5);
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.92) translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 220ms ease,
    opacity 220ms ease;
}

.cw-panel.cw-panel--open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Selector ────────────────────────────────────────────────────────── */
.cw-selector__header {
  padding: var(--space-6) var(--space-5) var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.cw-selector__eyebrow {
  font-family: var(--font-mono);
  font-size: var(--size-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 var(--space-1);
}

.cw-selector__title {
  font-family: var(--font-display);
  font-size: var(--size-xl);
  font-weight: var(--weight-bold);
  color: var(--text);
  margin: 0 0 var(--space-1);
}

.cw-selector__sub {
  font-size: var(--size-sm);
  color: var(--muted);
  margin: 0;
}

.cw-selector__options {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ── Opciones ────────────────────────────────────────────────────────── */
.cw-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: pointer;
  text-decoration: none;
  transition:
    border-color var(--transition),
    background var(--transition);
}

.cw-option:hover {
  border-color: var(--line-2);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface-2));
}

.cw-option__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cw-option__icon svg {
  width: 20px;
  height: 20px;
}

.cw-option--wa .cw-option__icon {
  background: color-mix(in srgb, #25d366 12%, transparent);
  color: #25d366;
}

.cw-option__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}

.cw-option__text strong {
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
}

.cw-option__text small {
  font-size: var(--size-xs);
  color: var(--muted);
}

.cw-option__arrow,
.cw-option__arrow svg {
  width: 16px;
  height: 16px;
  color: var(--dim);
  flex-shrink: 0;
}

/* ── Chat header ─────────────────────────────────────────────────────── */
.cw-chat__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.cw-back,
.cw-reset {
  background: transparent;
  border: none;
  color: var(--dim);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: color var(--transition);
  flex-shrink: 0;
}

.cw-back svg,
.cw-reset svg {
  width: 18px;
  height: 18px;
}

.cw-back:hover,
.cw-reset:hover {
  color: var(--text);
}

.cw-chat__header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cw-chat__header-name {
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
}

.cw-chat__header-status {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

.cw-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* ── Mensajes ────────────────────────────────────────────────────────── */
.cw-chat__messages {
  height: 420px;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}

.cw-msg {
  max-width: 85%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--size-sm);
  line-height: 1.55;
}

.cw-msg p {
  margin: 0;
}

.cw-msg__body {
  font-size: inherit;
  line-height: 1.55;
}

.cw-msg__body strong {
  font-weight: var(--weight-semibold, 600);
}

.cw-msg__body ul {
  margin: var(--space-2) 0 0;
  padding-left: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cw-msg__body li {
  line-height: 1.5;
}

.cw-msg--bot {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.cw-msg--user {
  background: var(--accent);
  color: var(--accent-ink);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.cw-msg--typing {
  background: var(--surface-2);
  border: 1px solid var(--line);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  padding: var(--space-3) var(--space-4);
}

.cw-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  height: 18px;
}

.cw-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: cw-bounce 1.2s infinite ease-in-out;
}

.cw-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.cw-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes cw-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.7);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ── Input ───────────────────────────────────────────────────────────── */
.cw-chat__input {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.cw-chat__field {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--size-sm);
  padding: var(--space-2) var(--space-3);
  outline: none;
  transition: border-color var(--transition);
}

.cw-chat__field:focus {
  border-color: var(--accent);
}

.cw-chat__field::placeholder {
  color: var(--dim);
}

.cw-chat__send {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--transition);
}

.cw-chat__send:hover {
  opacity: 0.85;
}

.cw-chat__send svg {
  width: 16px;
  height: 16px;
}

.cw-chat__send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Responsive móvil ────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Panel: selector compacto (igual que desktop pero más ancho) */
  .cw-panel {
    width: calc(100vw - 32px);
    right: 16px;
    bottom: calc(72px + 12px);
  }

  /* Chat: fullscreen independiente encima de todo */
  #cw-chat {
    position: fixed;
    inset: 0;
    z-index: 1002;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 260ms cubic-bezier(0.32, 0.72, 0, 1);
    /* Siempre en DOM, animado por clase */
  }

  #cw-chat.cw-chat--mobile-open {
    transform: translateY(0);
  }

  /* Mensajes ocupan todo el espacio disponible */
  .cw-chat__messages {
    flex: 1;
    height: auto;
  }

  /* Trigger en esquina inferior */
  .cw-trigger {
    right: var(--space-4);
    bottom: var(--space-4);
  }
}
