/* ─────────────────────────────────────────────────────────────────
   IMMAC — Asistente con IA (diseño A · cristal oscuro)
   Lógica: js/chatbot.js · servidor: api/chat.php y api/lead.php
───────────────────────────────────────────────────────────────── */
.ia {
  --ia-accent: #3FB4E6;
  --ia-green: #7CDB5A;
  --ia-glass: rgba(14, 18, 24, 0.8);
  --ia-line: rgba(255, 255, 255, 0.14);
  --ia-soft: rgba(255, 255, 255, 0.09);
  --ia-muted: rgba(255, 255, 255, 0.66);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #fff;
  -webkit-font-smoothing: antialiased;
}
.ia *, .ia *::before, .ia *::after { box-sizing: border-box; }
.ia [hidden] { display: none !important; }
:where(.ia) button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.ia :focus-visible { outline: 2px solid var(--ia-accent); outline-offset: 2px; }

/* ── Botón flotante: disco de vidrio oscuro con aro de color (verde → azul) separado
   del orbe central, y el punto verde de "en línea" sobre el aro ── */
.ia-launch {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 1200;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  padding: 0;
  border-radius: 50%;
  color: #fff;
  background: radial-gradient(circle at 50% 35%, rgba(30, 40, 52, 0.78), rgba(10, 14, 19, 0.82));
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: inset 0 0 0 1px rgba(63, 180, 230, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 18px 36px -14px rgba(0, 0, 0, 0.65);
  transition: opacity 240ms ease, transform 240ms cubic-bezier(0.23, 1, 0.32, 1);
}
/* aro de color, separado del orbe por un espacio oscuro */
.ia-launch::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  padding: 2.5px;
  background: conic-gradient(from 20deg, var(--ia-green), var(--ia-accent) 45%, var(--ia-accent) 60%, var(--ia-green));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
/* pulso: invita a abrirlo la primera vez */
.ia:not(.is-seen) .ia-launch::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--ia-accent);
  animation: ia-pulse 2.6s cubic-bezier(0.22, 1, 0.36, 1) infinite;
  pointer-events: none;
}
@keyframes ia-pulse { 0% { transform: scale(1); opacity: 0.6; } 100% { transform: scale(1.4); opacity: 0; } }
@media (hover: hover) and (pointer: fine) {
  .ia-launch:hover { transform: scale(1.05); }
}
.ia-launch.is-away { opacity: 0; transform: translateY(16px) scale(0.92); pointer-events: none; }
/* orbe central (y la X cuando el chat está abierto) */
.ia-launch .ia-launch__av,
.ia-launch .ia-launch__x {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #222C38 0%, #0B0F14 75%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  animation: none;
}
.ia-launch .ia-launch__av { display: grid; place-items: center; }
.ia-launch .ia-launch__av > span { background: none; animation: none; }
.ia-launch__av svg { width: 20px; height: 20px; }
.ia-launch__t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ia-launch .ia-launch__x { display: none; }
.ia.is-open .ia-launch__av { display: none; }
.ia.is-open .ia-launch .ia-launch__x { display: grid; place-items: center; }
.ia-launch__x svg { width: 18px; height: 18px; }
/* punto verde "en línea", sobre el aro arriba a la derecha */
.ia-launch__ping {
  position: absolute; top: 6px; right: 6px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--ia-green); box-shadow: 0 0 0 2.5px #0E1218;
}
.ia.is-open .ia-launch__ping { display: none; }

/* ── Saludo de bienvenida: aparece una vez sobre el orbe ── */
.ia-hello {
  position: fixed;
  right: 28px;
  bottom: 108px;
  z-index: 1199;
  width: 268px;
  max-width: calc(100vw - 32px);
  padding: 16px 18px;
  border-radius: 18px 18px 6px 18px;
  color: #0E1318;
  background: #fff;
  box-shadow: 0 24px 48px -20px rgba(10, 40, 70, 0.5), 0 0 0 1px rgba(14, 19, 24, 0.06);
  transform-origin: 100% 100%;
  animation: ia-hello-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes ia-hello-in { from { opacity: 0; transform: translateY(10px) scale(0.9); } }
.ia-hello b { display: block; padding-right: 22px; font-size: 14px; font-weight: 700; line-height: 1.3; }
.ia-hello p { margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: #4A5562; }
.ia-hello__q { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.ia .ia-hello__q button { min-height: 34px; padding: 0 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: #0A5F9A; background: #EEF6FB; transition: background 0.2s ease, color 0.2s ease; }
.ia .ia-hello__q button:hover { color: #fff; background: #0A5F9A; }
.ia .ia-hello__x { position: absolute; right: 8px; top: 8px; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: #5F6B78; }
.ia .ia-hello__x:hover { background: #EEF2F6; }
.ia-hello__x svg { width: 14px; height: 14px; }
.ia .ia-hello :focus-visible { outline-color: #0A5F9A; }
.ia-launch.is-away + .ia-hello, .ia.is-open .ia-hello { display: none; }

/* Avatar con aro de color */
.ia-av {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 2px;
  border-radius: 50%;
  background: conic-gradient(from 200deg, var(--ia-accent), var(--ia-green), var(--ia-accent));
}
.ia-av > span { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50%; background: #0E1218; }
.ia-av svg { width: 19px; height: 19px; }
.ia.is-thinking .ia-av { animation: ia-spin 2.4s linear infinite; }
.ia.is-thinking .ia-av > span { animation: ia-spin 2.4s linear infinite reverse; }
@keyframes ia-spin { to { transform: rotate(360deg); } }

/* ── Ventana ── */
.ia-panel {
  position: fixed;
  right: 28px;
  bottom: 108px;
  z-index: 1201;
  display: flex;
  flex-direction: column;
  width: 400px;
  height: min(640px, calc(100vh - 128px));
  height: min(640px, calc(100svh - 128px));
  border-radius: 22px;
  overflow: hidden;
  background: var(--ia-glass);
  -webkit-backdrop-filter: blur(26px) saturate(1.3);
  backdrop-filter: blur(26px) saturate(1.3);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.7), inset 0 0 0 1px var(--ia-line);
  transform-origin: 100% 100%;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  visibility: hidden;
  /* cierre: respuesta rápida (160 ms) */
  transition: opacity 160ms ease, transform 160ms cubic-bezier(0.23, 1, 0.32, 1), visibility 0s linear 160ms;
}
.ia.is-open .ia-panel {
  opacity: 1; transform: none; pointer-events: auto; visibility: visible;
  /* apertura: 240 ms, crece desde el botón */
  transition: opacity 200ms ease, transform 240ms cubic-bezier(0.23, 1, 0.32, 1), visibility 0s;
}

.ia-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 14px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.ia-title { font-size: 15px; font-weight: 700; line-height: 1.2; }
.ia-status { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 12px; color: var(--ia-muted); }
.ia-status i { width: 7px; height: 7px; border-radius: 50%; background: var(--ia-green); box-shadow: 0 0 8px var(--ia-green); }
.ia-hbtns { display: flex; gap: 6px; margin-left: auto; }
.ia-hbtn { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--ia-soft); transition: background 0.2s ease; }
@media (hover: hover) and (pointer: fine) {
  .ia-hbtn:hover { background: rgba(255, 255, 255, 0.16); }
}
.ia-hbtn svg { width: 16px; height: 16px; }

/* Mensajes */
.ia-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.ia-log > * { flex: none; }
.ia-msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; animation: ia-in 240ms cubic-bezier(0.23, 1, 0.32, 1) both; }
.ia-msg b { font-weight: 700; }
.ia-msg ul { margin: 6px 0 2px; padding-left: 18px; }
.ia-msg li { margin: 2px 0; }
.ia-msg--bot { align-self: flex-start; border-bottom-left-radius: 4px; background: rgba(255, 255, 255, 0.1); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
.ia-msg--me { align-self: flex-end; border-bottom-right-radius: 4px; color: #0E1318; background: #fff; }
.ia-msg--note { align-self: center; max-width: 100%; padding: 4px 10px; font-size: 11.5px; color: var(--ia-muted); background: none; text-align: center; }
@keyframes ia-in { from { opacity: 0; transform: translateY(6px); } }

.ia-chips { display: flex; flex-wrap: wrap; gap: 6px; animation: ia-in 240ms cubic-bezier(0.23, 1, 0.32, 1) both; }
.ia-chip {
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12.5px !important;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  background: var(--ia-soft) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
@media (hover: hover) and (pointer: fine) {
  .ia-chip:hover { background: rgba(255, 255, 255, 0.18) !important; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4); }
}
.ia-chips.is-used { display: none; }

/* Tarjeta de producto / sección */
.ia-card {
  align-self: flex-start;
  width: 88%;
  border-radius: 14px;
  overflow: hidden;
  background: var(--ia-soft);
  box-shadow: inset 0 0 0 1px var(--ia-line);
  animation: ia-in 240ms cubic-bezier(0.23, 1, 0.32, 1) both;
}
.ia-card__img { height: 104px; background: #2A2F36 center / cover no-repeat; }
.ia-card__img--mx { background-size: 260% auto; background-position: 88% 50%; }
.ia-card__ic { display: grid; place-items: center; height: 78px; color: var(--ia-accent); background: linear-gradient(135deg, rgba(63, 180, 230, 0.16), rgba(124, 219, 90, 0.08)); }
.ia-card__ic svg { width: 34px; height: 34px; }
.ia-card__b { padding: 12px 14px 14px; }
.ia-card__k { font-size: 10.5px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ia-accent); }
.ia-card h4 { margin: 3px 0 0; font-size: 15px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.25; color: #fff; }
.ia-card p { margin: 3px 0 0; font-size: 12px; line-height: 1.45; color: var(--ia-muted); }
.ia-specs { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 0; font-size: 11px; color: var(--ia-muted); }
.ia-specs b { display: block; font-size: 12.5px; color: #fff; }
.ia-acts { display: flex; gap: 8px; margin-top: 12px; }
.ia-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 12.5px !important;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.2s ease, background 0.2s ease;
}
@media (hover: hover) and (pointer: fine) {
  .ia-btn:hover { transform: translateY(-1px); }
}
.ia-btn svg { width: 15px; height: 15px; flex: none; }
.ia-btn--light { color: #111 !important; background: #fff !important; }
.ia-btn--ghost { color: #fff !important; background: var(--ia-soft) !important; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22); }
.ia-btn--wa { color: #7EF0A8 !important; background: rgba(37, 211, 102, 0.16) !important; box-shadow: inset 0 0 0 1px rgba(37, 211, 102, 0.42); }
.ia-cta { display: flex; gap: 8px; align-self: flex-start; width: 88%; animation: ia-in 240ms cubic-bezier(0.23, 1, 0.32, 1) both; }

/* Escribiendo… */
.ia-typing { align-self: flex-start; display: flex; gap: 4px; padding: 13px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.1); }
.ia-typing i { width: 6px; height: 6px; border-radius: 50%; background: #fff; opacity: 0.35; animation: ia-dot 1.1s ease-in-out infinite; }
.ia-typing i:nth-child(2) { animation-delay: 0.15s; }
.ia-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ia-dot { 40% { opacity: 1; transform: translateY(-3px); } }

/* Paso a paso de la cotización */
.ia-flow { display: flex; align-items: center; gap: 10px; margin: 0 16px; padding: 8px 12px; border-radius: 10px; font-size: 11.5px; font-weight: 600; color: var(--ia-muted); background: rgba(63, 180, 230, 0.1); box-shadow: inset 0 0 0 1px rgba(63, 180, 230, 0.3); }
.ia-flow__bar { flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.ia-flow__bar i { display: block; height: 100%; width: var(--p, 0%); background: var(--ia-accent); transition: width 0.4s ease; }
.ia-flow button { font-size: 11.5px !important; font-weight: 700; color: #fff; text-decoration: underline; text-underline-offset: 2px; }

.ia-sum { align-self: flex-start; width: 88%; padding: 12px 14px; border-radius: 14px; font-size: 12.5px; line-height: 1.5; background: var(--ia-soft); box-shadow: inset 0 0 0 1px var(--ia-line); animation: ia-in 240ms cubic-bezier(0.23, 1, 0.32, 1) both; }
.ia-sum dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.ia-sum dt { color: var(--ia-muted); }
.ia-sum dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.ia-consent { display: flex; gap: 9px; margin-top: 12px; font-size: 11.5px; line-height: 1.45; color: var(--ia-muted); cursor: pointer; }
.ia-consent input { flex: none; width: 16px; height: 16px; margin: 1px 0 0; accent-color: var(--ia-accent); }
.ia-consent.is-invalid { color: #FFB3B3; }

/* Entrada */
.ia-form { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px 8px; }
.ia-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  resize: none;
  font: inherit;
  font-size: 14px !important;
  line-height: 1.45;
  color: #0E1318;
  background: rgba(236, 238, 245, 0.96);
}
.ia-input::placeholder { color: #6B7180; }
.ia-input:focus { outline: none; background: #fff; box-shadow: 0 0 0 3px rgba(63, 180, 230, 0.5); }
.ia-send { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 12px; color: #04182C; background: var(--ia-accent) !important; transition: transform 0.2s ease, opacity 0.2s ease; }
@media (hover: hover) and (pointer: fine) {
  .ia-send:hover { transform: translateY(-1px); }
}
.ia-send:disabled { opacity: 0.45; cursor: default; transform: none; }
.ia-send svg { width: 18px; height: 18px; }
.ia-foot { padding: 0 14px 12px; font-size: 10.5px; text-align: center; color: rgba(255, 255, 255, 0.5); }
.ia-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ia-scrim { display: none; }

/* ── Celular: hoja inferior ── */
@media (max-width: 600px) {
  .ia-launch { right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); width: 62px; height: 62px; }
  .ia-launch::before { inset: 6px; }
  .ia-launch .ia-launch__av, .ia-launch .ia-launch__x { width: 38px; height: 38px; }
  .ia-launch__ping { top: 5px; right: 5px; width: 13px; height: 13px; }
  .ia-hello { right: 14px; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 74px); }
  .ia.is-open .ia-launch { opacity: 0; pointer-events: none; }
  .ia-scrim { display: block; position: fixed; inset: 0; z-index: 1200; background: rgba(4, 10, 18, 0.5); opacity: 0; pointer-events: none; transition: opacity 240ms ease; }
  .ia.is-open .ia-scrim { opacity: 1; pointer-events: auto; }
  .ia-panel {
    left: 0; right: 0; bottom: 0; width: auto;
    height: 88vh; height: 88svh;
    border-radius: 22px 22px 0 0;
    transform-origin: 50% 100%;
    transform: translateY(100%);   /* la hoja sale desde el borde inferior */
    opacity: 1;
    transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 240ms;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .ia.is-open .ia-panel { transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1), visibility 0s; }
  .ia-panel::before { content: ''; display: block; width: 40px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: rgba(255, 255, 255, 0.28); }
  .ia-input { font-size: 16px !important; } /* evita el zoom de iOS */
  .ia-card, .ia-cta, .ia-sum { width: 94%; }
}

@media (prefers-reduced-motion: reduce) {
  .ia-launch, .ia-panel { transform: none !important; }
  .ia:not(.is-seen) .ia-launch::after, .ia-hello { animation: none; }
  .ia-msg, .ia-card, .ia-chips, .ia-cta, .ia-sum { animation: rm-fade 150ms ease both !important; }
  .ia.is-thinking .ia-av, .ia.is-thinking .ia-av > span, .ia-typing i { animation: none; }
}
