/* =========================================================
   Asistente virtual CEPSA · abajo a la izquierda
   Usa las variables de color de styles.css
   ========================================================= */

.cx { position: fixed; left: 22px; bottom: 22px; z-index: 70; font-family: var(--font-sans); }
.cx-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Botón lanzador ---------- */
.cx-launcher {
  position: relative; width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(145deg, #C2185B, var(--brand) 55%, var(--brand-700));
  color: #fff; box-shadow: var(--shadow-brand);
  display: grid; place-items: center;
  transition: transform .3s var(--ease), box-shadow .3s var(--ease);
}
.cx-launcher:hover { transform: scale(1.06); }
.cx-launcher::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid rgba(164, 0, 70, .35);
  animation: cx-ring 2.6s var(--ease) infinite;
}
.cx-open .cx-launcher::before { display: none; }
@keyframes cx-ring { 0% { transform: scale(.9); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }
.cx-launcher-icon { position: absolute; display: grid; place-items: center; transition: transform .35s var(--ease), opacity .25s; }
.cx-launcher-icon svg { width: 28px; height: 28px; }
.cx-i-chat svg { fill: #fff; }
.cx-i-chat svg circle { fill: var(--brand); }
.cx-i-close { opacity: 0; transform: rotate(-90deg) scale(.6); }
.cx-i-close svg { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; width: 24px; height: 24px; }
.cx-open .cx-i-chat { opacity: 0; transform: rotate(90deg) scale(.6); }
.cx-open .cx-i-close { opacity: 1; transform: none; }
.cx-dot {
  position: absolute; top: 4px; right: 4px; width: 13px; height: 13px; border-radius: 50%;
  background: #2ECC71; border: 2.5px solid #fff;
}
.cx-open .cx-dot { display: none; }

/* ---------- Burbuja de bienvenida ---------- */
.cx-teaser {
  position: absolute; left: 0; bottom: 78px; width: 250px;
  padding: 16px 38px 16px 18px; border-radius: 18px 18px 18px 6px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  font-size: 14px; line-height: 1.5; cursor: pointer;
  opacity: 0; transform: translateY(10px) scale(.96); transform-origin: bottom left;
  transition: opacity .3s, transform .35s var(--ease);
}
.cx-teaser.cx-show { opacity: 1; transform: none; }
.cx-teaser strong { color: var(--brand); }
.cx-teaser-close {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%;
  border: 0; background: var(--stone-100); cursor: pointer; display: grid; place-items: center; padding: 0;
}
.cx-teaser-close svg { width: 12px; height: 12px; fill: none; stroke: var(--ink-soft); stroke-width: 2.4; stroke-linecap: round; }

/* ---------- Panel ---------- */
.cx-panel {
  position: absolute; left: 0; bottom: 80px;
  width: 390px; height: min(640px, calc(100vh - 130px));
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 24px; overflow: hidden;
  box-shadow: 0 30px 80px -20px rgba(42, 35, 38, .45), 0 0 0 1px rgba(42, 35, 38, .05);
  opacity: 0; visibility: hidden; transform: translateY(16px) scale(.97); transform-origin: bottom left;
  transition: opacity .3s, transform .4s var(--ease), visibility .3s;
}
.cx-open .cx-panel { opacity: 1; visibility: visible; transform: none; }

.cx-head {
  position: relative; display: flex; align-items: center; gap: 12px;
  padding: 18px 14px 18px 18px; color: #fff;
  background: radial-gradient(ellipse at 100% 0%, #C2185B, transparent 60%), linear-gradient(135deg, var(--brand-700), var(--brand));
}
.cx-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: #fff; display: grid; place-items: center;
  box-shadow: 0 0 0 3px rgba(255,255,255,.2);
}
.cx-avatar img { width: 30px; height: 30px; }
.cx-head-text { flex: 1; min-width: 0; }
.cx-head h2 { font-size: 16px; font-weight: 600; letter-spacing: 0; color: #fff; }
.cx-head p { font-size: 12px; color: rgba(255,255,255,.8); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.cx-online { width: 7px; height: 7px; border-radius: 50%; background: #2ECC71; box-shadow: 0 0 0 2px rgba(46,204,113,.3); }
.cx-icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.12); display: grid; place-items: center; padding: 0;
  transition: background .2s;
}
.cx-icon-btn:hover { background: rgba(255,255,255,.22); }
.cx-icon-btn svg { width: 17px; height: 17px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Mensajes ---------- */
.cx-body {
  position: relative; flex: 1; overflow-y: auto; padding: 20px 16px 8px;
  display: flex; flex-direction: column; gap: 12px;
  overscroll-behavior: contain; scroll-behavior: smooth;
}
.cx-msg { display: flex; animation: cx-in .35s var(--ease); }
@keyframes cx-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.cx-bubble { max-width: 88%; padding: 12px 15px; border-radius: 18px; font-size: 14px; line-height: 1.55; }
.cx-bot .cx-bubble { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.cx-user { justify-content: flex-end; }
.cx-user .cx-bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.cx-bubble p + p, .cx-bubble p + ul, .cx-bubble ul + p, .cx-bubble p + .cx-card, .cx-card + .cx-card { margin-top: 8px; }
.cx-bubble ul { list-style: none; padding: 0; margin-top: 6px; display: grid; gap: 5px; }
.cx-bubble li { position: relative; padding-left: 14px; }
.cx-bubble li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 5px; height: 5px; border-radius: 50%; background: var(--brand); }
.cx-bubble strong { font-weight: 600; }
.cx-muted { color: var(--ink-soft); font-size: 13px; }
.cx-warn { background: var(--brand-50); color: var(--brand-700); padding: 8px 10px; border-radius: 10px; font-size: 13px; }
.cx-card {
  display: grid; gap: 2px; padding: 10px 12px; border-radius: 12px;
  background: var(--bg); border: 1px solid var(--line); font-size: 13px; color: var(--ink-soft);
}
.cx-card strong { color: var(--brand); font-size: 13.5px; }

.cx-crisis .cx-bubble { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }

/* Botones dentro de las respuestas */
.cx-actions { display: grid; gap: 7px; margin-top: 12px; }
.cx-action {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 12px; border-radius: 12px;
  font-size: 13px; font-weight: 500; line-height: 1.3;
  background: var(--brand-50); color: var(--brand);
  transition: background .2s, transform .2s;
}
.cx-action:hover { background: var(--brand-100); transform: translateX(2px); }
.cx-action svg { width: 17px; height: 17px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cx-action.cx-wa { background: #E7F8EE; color: #128C4B; }
.cx-action.cx-wa:hover { background: #D3F2E0; }
.cx-action.cx-wa svg { fill: currentColor; stroke: none; }
.cx-action.cx-urgent { background: var(--brand); color: #fff; }
.cx-action.cx-urgent:hover { background: var(--brand-600); }
.cx-action.cx-urgent svg, .cx-action.cx-tel svg { fill: currentColor; stroke: none; }

/* Sugerencias */
.cx-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 2px 0 6px; animation: cx-in .4s var(--ease); }
.cx-chip {
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 8px 13px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--brand-100); background: var(--surface); color: var(--brand);
  transition: background .2s, border-color .2s, color .2s;
}
.cx-chip:hover { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Escribiendo… */
.cx-typing .cx-bubble { display: flex; gap: 5px; padding: 15px 16px; }
.cx-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--stone); animation: cx-blink 1.2s infinite; }
.cx-typing span:nth-child(2) { animation-delay: .15s; }
.cx-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cx-blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Campo de texto ---------- */
.cx-form { display: flex; gap: 8px; padding: 12px 14px 8px; background: var(--bg); border-top: 1px solid var(--line); }
.cx-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; /* 16px evita el zoom automático en iPhone */
  padding: 11px 16px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  transition: border-color .2s;
}
.cx-form input::placeholder { color: var(--stone); font-size: 14px; }
.cx-form input:focus { outline: none; border-color: var(--brand); }
.cx-send {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--brand); display: grid; place-items: center; transition: background .2s, transform .2s;
}
.cx-send:hover { background: var(--brand-600); transform: scale(1.05); }
.cx-send svg { width: 19px; height: 19px; fill: #fff; margin-left: -2px; }
.cx-note { padding: 0 16px 12px; font-size: 11px; line-height: 1.4; color: var(--stone); text-align: center; background: var(--bg); }
.cx-note a { color: var(--brand); font-weight: 600; }

/* ---------- Móvil: panel a pantalla completa ---------- */
@media (max-width: 640px) {
  .cx { left: 16px; bottom: 16px; }
  .cx-launcher { width: 56px; height: 56px; }
  .cx-teaser { width: min(250px, calc(100vw - 110px)); bottom: 70px; }
  .cx-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: 0;
    width: auto; height: auto; border-radius: 0;
    transform: translateY(24px);
  }
  .cx-head { padding-top: max(18px, env(safe-area-inset-top)); }
  .cx-note { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .cx-open .cx-launcher { opacity: 0; pointer-events: none; }
  body.cx-locked { overflow: hidden; }
  body.cx-locked .wa-float { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cx-launcher::before { animation: none; display: none; }
}
