/* =====================================================================
   CAPI — el capivara electrónico de CAPIDEV
   Camina, parpadea, piensa y explica la IA.
   ===================================================================== */

.capi-stage {
  position: relative;
  display: grid;
  gap: 1.6rem;
  justify-items: center;
  padding-top: .5rem;
}

/* ------------------------------ GLOBO ------------------------------- */
.capi-bubble {
  position: relative;
  width: min(100%, 620px);
  padding: 1.3rem 1.5rem 1.4rem;
  border-radius: 20px;
  background: rgba(255, 255, 255, .055);
  border: 1px solid rgba(29, 186, 224, .3);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, .8), inset 0 1px 0 rgba(255, 255, 255, .07);
  min-height: 148px;
}
.capi-bubble::before {
  content: '';
  position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(120deg, rgba(29,186,224,.55), transparent 35%, transparent 65%, rgba(21,119,184,.45));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.bubble-tail {
  position: absolute; left: 50%; bottom: -11px; width: 22px; height: 22px;
  transform: translateX(-50%) rotate(45deg);
  background: rgba(255, 255, 255, .055);
  border-right: 1px solid rgba(29, 186, 224, .3);
  border-bottom: 1px solid rgba(29, 186, 224, .3);
  backdrop-filter: blur(14px);
}

.bubble-head { display: flex; align-items: center; gap: .7rem; margin-bottom: .7rem; }
.bubble-name {
  font-family: var(--mono); font-size: .72rem; font-weight: 800; letter-spacing: .22em;
  color: #5ad5f0; padding: .25rem .6rem; border-radius: 6px;
  background: rgba(29, 186, 224, .12); border: 1px solid rgba(29, 186, 224, .28);
}
.bubble-status {
  display: inline-flex; align-items: center; gap: .4rem; margin-left: auto;
  font-family: var(--mono); font-size: .65rem; letter-spacing: .1em; color: #717c88;
}
.bubble-status i {
  width: 6px; height: 6px; border-radius: 50%; background: #4ade80;
  box-shadow: 0 0 8px #4ade80; animation: blip 1.4s ease-in-out infinite;
}

.bubble-text {
  font-size: clamp(.95rem, 1.6vw, 1.1rem);
  line-height: 1.68; color: #d7e2ec; min-height: 3.4em;
}
.bubble-text strong { color: #fff; font-weight: 800; }
.bubble-text em { color: #5ad5f0; font-style: normal; font-weight: 700; }
.capi-link {
  display: inline-block; font-weight: 800; color: #fff; text-decoration: none;
  padding: .1rem .55rem; margin: 0 .1rem; border-radius: 7px;
  background: linear-gradient(135deg, #1577b8, #1dbae0);
  box-shadow: 0 6px 16px -6px rgba(29, 186, 224, .8);
  transition: transform .25s, box-shadow .25s;
}
.capi-link:hover { transform: translateY(-2px); box-shadow: 0 10px 22px -6px rgba(29, 186, 224, 1); }
.caret {
  display: inline-block; width: 9px; height: 1.05em; margin-left: 2px;
  background: #1dbae0; vertical-align: text-bottom; animation: caret .85s steps(1) infinite;
}
@keyframes caret { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* ----------------------------- ESCENARIO ---------------------------- */
.capi-scene {
  position: relative; width: min(100%, 760px); height: clamp(210px, 30vw, 300px);
  overflow: hidden;
}

/* piso con líneas que se desplazan = CAPI avanza */
.capi-ground { position: absolute; left: 0; right: 0; bottom: 26px; height: 60px; }
.capi-ground::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(29,186,224,.55) 15%, rgba(29,186,224,.55) 85%, transparent);
}
.capi-ground::after {
  content: ''; position: absolute; inset: 2px 0 0;
  background-image: linear-gradient(90deg, rgba(29,186,224,.35) 2px, transparent 2px);
  background-size: 46px 100%;
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
  animation: ground-scroll 1.1s linear infinite;
}
@keyframes ground-scroll { to { background-position-x: -46px; } }

/* partículas de datos que pasan */
.capi-scene::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(90,213,240,.5) 1.5px, transparent 2px),
    radial-gradient(circle, rgba(21,119,184,.4) 1.5px, transparent 2px);
  background-size: 190px 90px, 260px 130px;
  background-position: 0 30px, 60px 96px;
  animation: dust 5s linear infinite;
  mask-image: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
}
@keyframes dust { to { background-position: -190px 30px, -260px 96px; } }

/* --------------------------- EL PERSONAJE --------------------------- */
.capi-walker {
  position: absolute; left: 50%; bottom: 0; width: min(78%, 460px);
  transform: translateX(-50%);
  animation: stride 2.6s ease-in-out infinite alternate;
}
@keyframes stride {
  from { transform: translateX(-54%); }
  to   { transform: translateX(-46%); }
}
.capi-svg { width: 100%; height: auto; overflow: visible; }

/* --- ciclo de marcha --- */
.leg { transform-box: fill-box; transform-origin: top center; }
.legF1, .legB2 { animation: step-a .62s ease-in-out infinite; }
.legB1, .legF2 { animation: step-b .62s ease-in-out infinite; }
@keyframes step-a { 0%, 100% { transform: rotate(17deg); } 50% { transform: rotate(-17deg); } }
@keyframes step-b { 0%, 100% { transform: rotate(-17deg); } 50% { transform: rotate(17deg); } }

.capi-body, .capi-head {
  transform-box: fill-box; transform-origin: center;
  animation: body-bob .31s ease-in-out infinite alternate;
}
.capi-head { animation: head-bob .62s ease-in-out infinite; }
@keyframes body-bob { from { transform: translateY(0); } to { transform: translateY(-4px); } }
@keyframes head-bob { 0%, 100% { transform: translateY(-2px) rotate(-.8deg); } 50% { transform: translateY(2px) rotate(.8deg); } }

.capi-shadow { animation: shadow-pulse .62s ease-in-out infinite alternate; }
@keyframes shadow-pulse { from { opacity: .38; transform: scaleX(1); } to { opacity: .26; transform: scaleX(.94); } }

/* --- vida: ojo, antena, núcleo, circuitos --- */
.capi-lid { transform-box: fill-box; transform-origin: top center; animation: blink 5.2s ease-in-out infinite; }
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(0); }
  95%, 97%      { transform: scaleY(1); }
}
.capi-eye { animation: eye-glow 2.6s ease-in-out infinite; }
@keyframes eye-glow { 0%, 100% { opacity: 1; } 50% { opacity: .68; } }

.capi-antenna { transform-box: fill-box; transform-origin: center; animation: antenna 1.8s ease-in-out infinite; }
@keyframes antenna { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(1.25); } }

.capi-waves path { animation: waves 2.2s ease-out infinite; }
.capi-waves path:last-child { animation-delay: .35s; }
@keyframes waves { 0% { opacity: 0; } 30% { opacity: .8; } 100% { opacity: 0; } }

.capi-core { transform-box: fill-box; transform-origin: center; animation: core 2.4s ease-in-out infinite; }
@keyframes core { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.09); } }

.circuit path { stroke-dasharray: 10 16; animation: trace 2.4s linear infinite; }
.circuit path:last-child { animation-direction: reverse; animation-duration: 3s; }
@keyframes trace { to { stroke-dashoffset: -52; } }

/* --- CAPI se detiene mientras habla --- */
.capi-stage.thinking .leg,
.capi-stage.thinking .capi-body,
.capi-stage.thinking .capi-head,
.capi-stage.thinking .capi-shadow,
.capi-stage.thinking .capi-walker,
.capi-stage.thinking .capi-ground::after,
.capi-stage.thinking .capi-scene::after { animation-play-state: paused; }
.capi-stage.thinking .capi-antenna { animation-duration: .55s; }

/* ----------------------------- CONTROLES ---------------------------- */
.capi-controls { display: flex; align-items: center; gap: 1rem; }
.capi-btn {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; cursor: pointer;
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .14);
  color: #a3adb8; transition: .25s;
}
.capi-btn:hover { color: #fff; border-color: rgba(29, 186, 224, .55); background: rgba(29, 186, 224, .12); }
.capi-btn svg { width: 18px; height: 18px; }

.capi-dots { display: flex; gap: .45rem; }
.capi-dots button {
  width: 9px; height: 9px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: rgba(255, 255, 255, .2); transition: .3s;
}
.capi-dots button:hover { background: rgba(255, 255, 255, .4); }
.capi-dots button.on {
  width: 30px; border-radius: 5px;
  background: linear-gradient(90deg, #1577b8, #1dbae0);
  box-shadow: 0 0 14px rgba(29, 186, 224, .6);
}

@media (max-width: 620px) {
  .capi-scene { height: 190px; }
  .capi-walker { width: 92%; }
  .capi-bubble { min-height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  .capi-walker, .leg, .capi-body, .capi-head, .capi-shadow,
  .capi-ground::after, .capi-scene::after { animation: none !important; }
}

/* =====================================================================
   CHAT CON CAPI — la única puerta de entrada al CRM
   Vive en sección clara, así que usa la paleta clara.
   ===================================================================== */

.chat-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; min-height: 520px; }
.chat-card::before { display: none; }

/* ------------------------------ HEADER ------------------------------ */
.chat-head {
  display: flex; align-items: center; gap: .8rem; padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line); background: var(--g-50);
}
.chat-avatar {
  width: 46px; height: 46px; border-radius: 13px; flex: none; display: grid; place-items: center;
  background: linear-gradient(150deg, #262c33, #0e1114); padding: .45rem;
  box-shadow: 0 8px 20px -8px rgba(14, 17, 20, .5);
}
.chat-avatar svg { width: 100%; height: auto; overflow: visible; }
.chat-antenna { animation: antenna 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }

.chat-id { flex: 1; min-width: 0; }
.chat-id b { display: block; font-size: 1rem; letter-spacing: -.02em; }
.chat-id span {
  display: inline-flex; align-items: center; gap: .38rem;
  font-size: .74rem; color: var(--ink-mute); font-family: var(--mono);
}
.chat-id span i {
  width: 6px; height: 6px; border-radius: 50%; background: #16a34a;
  box-shadow: 0 0 7px #16a34a; animation: blip 2s ease-in-out infinite;
}

.chat-switch {
  border: 1px solid var(--line-2); background: var(--g-0); cursor: pointer;
  font-size: .74rem; font-weight: 700; color: var(--ink-soft);
  padding: .42rem .78rem; border-radius: 100px; white-space: nowrap; transition: .22s;
}
.chat-switch:hover { border-color: var(--b-500); color: var(--b-700); }

/* -------------------------------- LOG ------------------------------- */
.chat-log {
  flex: 1; min-height: 260px; max-height: 380px; overflow-y: auto;
  padding: 1.3rem 1.2rem; display: flex; flex-direction: column; gap: .6rem;
  scroll-behavior: smooth;
}
.chat-log::-webkit-scrollbar { width: 6px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--g-300); border-radius: 6px; border: 0; }

.msg { max-width: 82%; padding: .72rem 1rem; border-radius: 16px; font-size: .91rem; line-height: 1.55; animation: pop .35s cubic-bezier(.2,.9,.3,1.3); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }

.msg.bot {
  align-self: flex-start; background: var(--g-100); color: var(--ink);
  border-bottom-left-radius: 5px;
}
.msg.bot strong { font-weight: 800; }
.msg.bot em { font-style: normal; font-weight: 700; color: var(--b-700); }

.msg.user {
  align-self: flex-end; background: var(--grad); color: #fff; font-weight: 600;
  border-bottom-right-radius: 5px; box-shadow: var(--sh-signal);
}

.msg.note {
  align-self: center; max-width: 100%; background: transparent; color: var(--ink-mute);
  font-size: .76rem; font-family: var(--mono); padding: .3rem 0;
}
.msg.ok {
  align-self: flex-start; background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857;
  font-weight: 600;
}
.msg.bad {
  align-self: flex-start; background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
}

/* puntitos de "escribiendo" */
.typing { align-self: flex-start; display: flex; gap: 4px; padding: .85rem 1rem; background: var(--g-100); border-radius: 16px; border-bottom-left-radius: 5px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--g-400); animation: dot 1.2s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ------------------------------ PROGRESO ---------------------------- */
.chat-progress { height: 3px; background: var(--g-150); }
.chat-progress i { display: block; height: 100%; width: 0; background: var(--grad); transition: width .5s cubic-bezier(.2,.8,.2,1); }

/* ------------------------------- ENTRADA ---------------------------- */
.chat-input { padding: .9rem 1.2rem 1.1rem; border-top: 1px solid var(--line); background: var(--g-0); }
.chat-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .7rem; }
.chat-chips:empty { display: none; }
.chat-chips button {
  padding: .5rem .9rem; border-radius: 100px; cursor: pointer; font-size: .82rem; font-weight: 700;
  background: var(--g-0); border: 1px solid var(--line-2); color: var(--ink-soft); transition: .22s;
}
.chat-chips button:hover { border-color: var(--b-500); color: var(--b-700); transform: translateY(-2px); }
.chat-chips button.skip { color: var(--ink-mute); font-weight: 600; }

.chat-entry { display: flex; gap: .5rem; align-items: flex-end; }
.chat-entry input {
  flex: 1; padding: .82rem 1rem; border-radius: 100px; font-size: .92rem;
  background: var(--g-50); border: 1px solid var(--line-2); transition: .22s;
}
.chat-entry input:focus { outline: none; background: var(--g-0); border-color: var(--b-500); box-shadow: 0 0 0 4px rgba(26,162,209,.12); }
.chat-entry input::placeholder { color: var(--g-400); }
.chat-entry input:disabled { opacity: .5; }

.chat-send {
  width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--grad); color: #fff;
  box-shadow: var(--sh-signal); transition: transform .25s, box-shadow .25s;
}
.chat-send:hover { transform: translateY(-2px) scale(1.05); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.chat-send svg { width: 18px; height: 18px; }

.chat-input.hidden { display: none; }

@media (max-width: 620px) {
  .chat-card { min-height: 480px; }
  .chat-log { max-height: 320px; }
  .msg { max-width: 90%; }
  .chat-head { flex-wrap: wrap; }
  .chat-switch { order: 3; width: 100%; }
}

/* =====================================================================
   CAPI EN EL HERO
   Vive dentro de una tarjeta oscura sobre la página clara: el contraste
   lo convierte en lo primero que mira el ojo al entrar.
   ===================================================================== */
.hero-capi{
  position:relative;border-radius:28px;padding:1.4rem 1.2rem 1.1rem;overflow:hidden;
  background:linear-gradient(160deg,#171b20,#0e1114);
  border:1px solid rgba(255,255,255,.07);
  box-shadow:0 30px 70px -25px rgba(14,17,20,.55), 0 2px 8px rgba(14,17,20,.1);
}
.hero-capi::before{
  content:'';position:absolute;inset:0;pointer-events:none;
  background:
    radial-gradient(520px 320px at 20% 0%, rgba(21,119,184,.30), transparent 62%),
    radial-gradient(420px 280px at 90% 100%, rgba(29,186,224,.18), transparent 62%);
}
.hero-capi::after{
  content:'';position:absolute;inset:0;pointer-events:none;opacity:.5;
  background-image:
    linear-gradient(rgba(255,255,255,.03) 1px,transparent 1px),
    linear-gradient(90deg,rgba(255,255,255,.03) 1px,transparent 1px);
  background-size:56px 56px;
  mask-image:radial-gradient(ellipse 85% 65% at 50% 0%,#000,transparent 78%);
}
.hero-capi > *{position:relative;z-index:1}

/* dentro del hero el escenario es más compacto */
.hero-capi .capi-stage{gap:1rem;padding-top:0}
.hero-capi .capi-bubble{width:100%;min-height:132px;padding:1rem 1.15rem 1.1rem;border-radius:16px}
.hero-capi .bubble-text{font-size:.92rem;line-height:1.6;min-height:4.2em}
.hero-capi .capi-scene{height:clamp(160px,17vw,205px);width:100%}
.hero-capi .capi-walker{width:min(88%,380px)}
.hero-capi .capi-ground{bottom:16px}
.hero-capi .capi-controls{gap:.8rem}
.hero-capi .capi-btn{width:36px;height:36px;border-radius:10px}
.hero-capi .capi-btn svg{width:16px;height:16px}

@media (max-width:1040px){
  .hero-capi{max-width:600px;margin-inline:auto}
}
@media (max-width:620px){
  .hero-capi{padding:1.1rem .9rem .9rem;border-radius:22px}
  .hero-capi .capi-bubble{min-height:170px}
  .hero-capi .capi-scene{height:150px}
}
