/* widget/pacod-widget.css
   Estilos del widget PACOD. Todo va namespaced bajo #pacod-root para no
   interferir con el CSS del sitio donde se embeba. Los colores se pueden
   sobrescribir desde config.js (se inyectan como variables en línea). */

#pacod-root {
  --pcd-primary: #0068B0;
  --pcd-secondary: #20B8E8;
  --pcd-navy: #003878;
  --pcd-bg: #FFFFFF;
  --pcd-bubble-user: #0068B0;
  --pcd-bubble-pacod: #E8F5FC;
  --pcd-text: #1f2937;
  --pcd-muted: #6b7280;
  --pcd-border: #e5e7eb;
  --pcd-wa: #25D366;
  --pcd-shadow: 0 12px 32px rgba(16, 36, 64, 0.18);

  position: fixed;
  z-index: 2147483000; /* por encima de casi todo */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--pcd-text);
  font-size: 15px;
  line-height: 1.5;
}

#pacod-root *,
#pacod-root *::before,
#pacod-root *::after { box-sizing: border-box; }

/* ---------- Launcher flotante ---------- */
.pcd-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: linear-gradient(160deg, var(--pcd-secondary), var(--pcd-navy));
  box-shadow: var(--pcd-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.18s ease;
}
.pcd-launcher:hover { transform: scale(1.05); }
.pcd-launcher img { width: 100%; height: 100%; object-fit: cover; }

.pcd-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--pcd-wa);
  border: 2px solid #fff;
  animation: pcd-pulse 1.8s ease-in-out infinite;
}
.pcd-badge[hidden] { display: none; }

@keyframes pcd-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.7; }
}

/* ---------- Burbuja de invitación (teaser) ---------- */
.pcd-teaser {
  position: fixed;
  right: 24px;
  bottom: 104px;
  max-width: 220px;
  background: #fff;
  color: var(--pcd-text);
  border-radius: 14px 14px 4px 14px;
  box-shadow: var(--pcd-shadow);
  padding: 12px 30px 12px 14px;
  font-size: 13.5px;
  line-height: 1.4;
  cursor: pointer;
  animation: pcd-teaser-in 0.25s ease;
}
.pcd-teaser[hidden] { display: none; }
.pcd-teaser-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--pcd-muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.pcd-teaser-close:hover { background: #f3f4f6; }
@keyframes pcd-teaser-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Panel ---------- */
.pcd-panel {
  position: fixed;
  right: 24px;
  bottom: 104px;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--pcd-bg);
  border-radius: 16px;
  box-shadow: var(--pcd-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.pcd-panel.pcd-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- Header ---------- */
.pcd-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(135deg, var(--pcd-navy), var(--pcd-primary));
  color: #fff;
}
.pcd-header img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.pcd-header .pcd-h-text { flex: 1; min-width: 0; }
.pcd-header .pcd-h-name { font-weight: 600; font-size: 15px; }
.pcd-header .pcd-h-status { font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 5px; }
.pcd-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--pcd-wa); display: inline-block;
}
.pcd-close {
  background: transparent; border: none; color: #fff;
  font-size: 22px; line-height: 1; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px;
}
.pcd-close:hover { background: rgba(255,255,255,0.15); }

/* ---------- Mensajes ---------- */
.pcd-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafbfc;
}
.pcd-msg {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.pcd-msg-pacod {
  align-self: flex-start;
  background: var(--pcd-bubble-pacod);
  color: var(--pcd-text);
  border-bottom-left-radius: 4px;
}
.pcd-msg-user {
  align-self: flex-end;
  background: var(--pcd-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.pcd-msg-emergencia {
  align-self: flex-start;
  background: #FEF2F2;
  color: #991B1B;
  border: 1px solid #FCA5A5;
  border-bottom-left-radius: 4px;
  font-weight: 500;
}

/* Indicador de escritura */
.pcd-typing { align-self: flex-start; display: flex; gap: 4px; padding: 11px 14px; background: var(--pcd-bubble-pacod); border-radius: 14px; border-bottom-left-radius: 4px; }
.pcd-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--pcd-muted); animation: pcd-bounce 1.2s infinite ease-in-out; }
.pcd-typing span:nth-child(2) { animation-delay: 0.15s; }
.pcd-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pcd-bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Chips ---------- */
.pcd-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 6px; }
.pcd-opts { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 14px 4px; }
.pcd-chip {
  background: #fff;
  border: 1px solid var(--pcd-primary);
  color: var(--pcd-primary);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.pcd-chip:hover { background: #eef4fb; }

/* ---------- Consentimiento ---------- */
.pcd-consent {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid var(--pcd-border);
  font-size: 12px;
  color: var(--pcd-muted);
}
.pcd-consent label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.pcd-consent input { margin-top: 2px; }
.pcd-consent a { color: var(--pcd-primary); }

/* ---------- Botón WhatsApp persistente ---------- */
.pcd-wa-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 8px 14px 0;
  padding: 10px;
  background: var(--pcd-wa);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pcd-wa-btn:hover { filter: brightness(0.96); }

/* ---------- Input ---------- */
.pcd-input-row {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--pcd-border);
  background: #fff;
}
.pcd-input {
  flex: 1;
  resize: none;
  max-height: 96px;
  border: 1px solid var(--pcd-border);
  border-radius: 12px;
  padding: 9px 12px;
  font: inherit;
  outline: none;
}
.pcd-input:focus { border-color: var(--pcd-primary); }
.pcd-input:disabled { background: #f3f4f6; cursor: not-allowed; }
.pcd-send {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: none; border-radius: 12px;
  background: var(--pcd-primary);
  color: #fff; cursor: pointer;
  font-size: 18px;
}
.pcd-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Accesibilidad: foco visible ---------- */
#pacod-root button:focus-visible,
#pacod-root textarea:focus-visible,
#pacod-root input:focus-visible,
#pacod-root a:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .pcd-panel {
    right: 0; bottom: 0;
    width: 100vw; height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .pcd-launcher { right: 16px; bottom: 16px; }
  .pcd-teaser { right: 16px; bottom: 92px; max-width: calc(100vw - 32px); }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  #pacod-root *, #pacod-root *::before, #pacod-root *::after {
    animation: none !important;
    transition: none !important;
  }
}
