/* Panel de la burbuja de WhatsApp con asesor de IA (public/js/asesor.js). */

.asesor {
  position: fixed;
  right: 18px;
  bottom: 86px;
  z-index: 141;
  width: min(380px, calc(100vw - 24px));
  max-height: min(600px, calc(100dvh - 120px));
  display: flex;
  flex-direction: column;
  background: #fff;
  color: var(--ink, #0d0d0d);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .28), 0 4px 14px rgba(0, 0, 0, .14);
  overflow: hidden;
  font-size: 15px;
  line-height: 1.45;
}

.asesor[hidden] { display: none; }

@media (max-width: 520px) {
  .asesor { right: 12px; bottom: 82px; max-height: calc(100dvh - 100px); }
}

.asesor-cab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  background: var(--ink, #0d0d0d);
  color: #fff;
}

.asesor-titulo {
  margin: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
}

.asesor-punto {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--brand, #f25c05);
  box-shadow: 0 0 0 4px rgba(242, 92, 5, .25);
}

.asesor-wa-cab {
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  text-decoration: none;
}

.asesor-wa-cab:hover { background: rgba(255, 255, 255, .2); text-decoration: none; }

.asesor-cerrar {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.asesor-cerrar:hover { background: rgba(255, 255, 255, .12); }

/* Inicio: WhatsApp o IA */
.asesor-inicio { padding: 16px; display: grid; gap: 10px; }

.asesor-inicio[hidden], .asesor-chat[hidden] { display: none; }

.asesor-intro { margin: 0 0 4px; font-weight: 700; }

.asesor-opcion {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #fff;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}

.asesor-opcion[hidden] { display: none; }

.asesor-opcion span { color: var(--muted, #6b7280); font-size: 13px; }

.asesor-opcion:hover,
.asesor-opcion:focus-visible {
  background: rgba(242, 92, 5, .07);
  border-color: rgba(242, 92, 5, .45);
  text-decoration: none;
}

.asesor-opcion-wa strong::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: #25d366;
  vertical-align: middle;
}

/* Chat */
.asesor-chat { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.asesor-lista {
  flex: 1;
  min-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f6f6f4;
}

.asesor-msg {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 14px;
  display: grid;
  gap: 8px;
}

.asesor-texto { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.asesor-msg-asesor,
.asesor-msg-sistema {
  align-self: flex-start;
  background: #fff;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

.asesor-msg-sistema { background: #fff7f2; }

.asesor-msg-usuario {
  align-self: flex-end;
  background: var(--ink, #0d0d0d);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.asesor-msg a { color: var(--brand, #f25c05); font-weight: 700; }

.asesor-marca {
  justify-self: start;
  font-size: 12px;
  font-weight: 700;
  color: #9a3a03;
  background: rgba(242, 92, 5, .1);
  padding: 2px 8px;
  border-radius: 999px;
}

.asesor-msg a.asesor-wa {
  justify-self: start;
  padding: 8px 12px;
  border-radius: 999px;
  background: #25d366;
  color: #0b2e17;
  font-size: 14px;
  text-decoration: none;
}

.asesor-msg a.asesor-wa:hover { filter: brightness(1.05); text-decoration: none; }

.asesor-sugerencias { display: flex; flex-wrap: wrap; gap: 6px; }

.asesor-sugerencia {
  padding: 7px 11px;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.asesor-sugerencia:hover { border-color: rgba(242, 92, 5, .5); background: rgba(242, 92, 5, .06); }

.asesor-escribiendo { grid-auto-flow: column; justify-content: start; gap: 4px; padding: 14px 12px; }

.asesor-escribiendo span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b5b5b5;
  animation: asesor-pulso 1s infinite ease-in-out;
}

.asesor-escribiendo span:nth-child(2) { animation-delay: .15s; }
.asesor-escribiendo span:nth-child(3) { animation-delay: .3s; }

@keyframes asesor-pulso {
  0%, 80%, 100% { opacity: .35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .asesor-escribiendo span { animation: none; opacity: .7; }
}

.asesor-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #ececec;
  background: #fff;
}

.asesor-campo {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  font: inherit;
  /* 16px evita el zoom automático de iOS al enfocar */
  font-size: 16px;
}

.asesor-campo:focus { outline: 2px solid rgba(242, 92, 5, .5); outline-offset: 0; border-color: transparent; }

.asesor-enviar {
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--brand, #f25c05);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.asesor-enviar:disabled { opacity: .55; cursor: progress; }

.asesor-aviso {
  margin: 0;
  padding: 0 12px 10px;
  background: #fff;
  color: var(--muted, #6b7280);
  font-size: 11.5px;
}

/* Globo de invitación al asistente (como el de codebymike.net). Nace encima
   de la burbuja y su cola apunta al centro de ella: 18px de margen + 28px de
   radio en escritorio, 14px + 26px en celular. Las palabras aparecen con el
   gesto de "texto que se genera". */
.asesor-globo {
  --globo-cola: 28px;
  position: fixed;
  right: 18px;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  z-index: 141;
  width: max-content;
  max-width: min(260px, calc(100vw - 32px));
  transform-origin: calc(100% - var(--globo-cola)) 100%;
}

.asesor-globo[hidden] { display: none; }

.asesor-globo:not([hidden]) { animation: asesor-globo-entrar .5s cubic-bezier(.16, 1, .3, 1); }

.asesor-globo[data-saliendo] { animation: asesor-globo-salir .22s ease-in forwards; }

@keyframes asesor-globo-entrar {
  from { opacity: 0; transform: translateY(10px) scale(.55); }
}

@keyframes asesor-globo-salir {
  to { opacity: 0; transform: translateY(6px) scale(.85); }
}

.asesor-globo-texto {
  position: relative;
  display: block;
  padding: 11px 36px 12px 14px;
  border: 1px solid rgba(242, 92, 5, .45);
  border-radius: 16px;
  border-bottom-right-radius: 6px;
  background: var(--ink, #0d0d0d);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .55);
  transition: border-color .2s ease;
}

.asesor-globo-texto:hover { border-color: var(--brand, #f25c05); }

.asesor-globo-texto:focus-visible { outline: 2px solid var(--brand, #f25c05); outline-offset: 2px; }

.asesor-globo-texto::after {
  content: "";
  position: absolute;
  right: calc(var(--globo-cola) - 6px);
  bottom: -6px;
  width: 11px;
  height: 11px;
  background: inherit;
  border-right: inherit;
  border-bottom: inherit;
  border-bottom-right-radius: 2px;
  transform: rotate(45deg);
}

.asesor-globo-palabra { display: inline-block; }

.asesor-globo:not([hidden]) .asesor-globo-palabra {
  animation: asesor-globo-palabra .3s ease-out both;
  animation-delay: calc(.3s + var(--i) * 70ms);
}

@keyframes asesor-globo-palabra {
  from { opacity: 0; filter: blur(4px); }
}

.asesor-globo-cerrar {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: rgba(255, 255, 255, .6);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.asesor-globo-cerrar:hover { color: #fff; background: rgba(255, 255, 255, .12); }

.asesor-globo-cerrar:focus-visible { outline: 2px solid var(--brand, #f25c05); }

/* Burbuja doble (public/js/asesor.js, burbujaDoble), como la de
   codebymike.net: píldora verde de WhatsApp, una raya y el círculo oscuro de
   la IA. La chispa grande late con brillo cada tanto y la chica titila
   después. El tooltip viejo de hover se calla: la burbuja ya no es solo
   WhatsApp. */
.whatsapp-fab[data-ia] {
  width: auto;
  height: 52px;
  gap: 10px;
  padding: 0 8px 0 14px;
  background: #25d366;
  color: #062e16;
  box-shadow: 0 8px 28px rgba(37, 211, 102, .35), 0 3px 8px rgba(0, 0, 0, .12);
}

.whatsapp-fab[data-ia]::after,
.whatsapp-fab[data-ia]::before { display: none; }

.wa-fab-raya {
  width: 1px;
  height: 22px;
  background: rgba(6, 46, 22, .3);
}

.wa-fab-ia {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--ink, #0d0d0d);
  color: var(--brand, #f25c05);
  box-shadow: inset 0 0 0 1px rgba(242, 92, 5, .4);
  transition: box-shadow .3s ease;
}

.wa-chispa-grande {
  transform-origin: 10.5px 13px;
  animation: wa-chispa-grande 7s ease-in-out infinite;
}

.wa-chispa-chica {
  transform-origin: 18.5px 5.5px;
  animation: wa-chispa-chica 7s ease-in-out infinite;
}

/* Además del latido, cada estrella gira sobre su propio centro sin parar: la
   grande despacio, la chica más rápido y al revés. El giro va en el <g> y el
   latido en el <path>, para que los dos transform no se pisen. */
.wa-giro-grande,
.wa-giro-chica {
  transform-box: fill-box;
  transform-origin: center;
}

.wa-giro-grande { animation: wa-giro 9s linear infinite; }
.wa-giro-chica { animation: wa-giro 5s linear infinite reverse; }

@keyframes wa-giro {
  to { transform: rotate(360deg); }
}

@keyframes wa-chispa-grande {
  0%, 80%, 100% { transform: scale(1); filter: none; }
  87% { transform: scale(1.2) rotate(8deg); filter: drop-shadow(0 0 3px var(--brand, #f25c05)); }
}

@keyframes wa-chispa-chica {
  0%, 84%, 100% { transform: scale(1); opacity: 1; }
  88% { transform: scale(.3); opacity: .3; }
  93% { transform: scale(1.35); opacity: 1; }
}

/* Con el globo afuera, el círculo de IA se enciende: es de donde habla. */
.whatsapp-fab[data-globo] .wa-fab-ia {
  box-shadow: inset 0 0 0 1px rgba(242, 92, 5, .7), 0 0 0 3px rgba(242, 92, 5, .25);
}

.whatsapp-fab[data-globo]:not([data-ia]) { box-shadow: 0 0 0 4px rgba(242, 92, 5, .28), 0 10px 20px rgba(0, 0, 0, .18); }

.whatsapp-fab[data-globo]::after,
.whatsapp-fab[data-globo]::before { display: none; }

/* La cola del globo apunta al centro del círculo de IA: 8px de relleno +
   18px de radio desde el borde derecho de la burbuja. */
.asesor-globo { --globo-cola: 26px; bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }

@media (max-width: 640px) {
  .whatsapp-fab[data-ia] { height: 52px; width: auto; }
  .asesor-globo { right: 14px; bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  .wa-giro-grande,
  .wa-giro-chica,
  .wa-chispa-grande,
  .wa-chispa-chica,
  .asesor-globo:not([hidden]),
  .asesor-globo[data-saliendo],
  .asesor-globo:not([hidden]) .asesor-globo-palabra { animation: none; }
}

/* Estado de la moto dentro del chat (formulario y tarjeta de la orden) */
.asesor-orden {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.asesor-orden input {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  font: inherit;
  /* 16px evita el zoom automático de iOS al enfocar */
  font-size: 16px;
}

.asesor-orden-placa { text-transform: uppercase; }
.asesor-orden-placa::placeholder { text-transform: none; }

.asesor-orden input:focus { outline: 2px solid rgba(242, 92, 5, .5); outline-offset: 0; border-color: transparent; }

.asesor-orden-ir {
  grid-column: 1 / -1;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--ink, #0d0d0d);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.asesor-orden-ir:disabled { opacity: .6; cursor: progress; }

.asesor-orden-error { grid-column: 1 / -1; margin: 0; font-size: 13px; color: #b42318; }
.asesor-orden-error[hidden] { display: none; }

.asesor-orden-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #ececec;
  border-radius: 12px;
  background: #fafaf9;
  font-size: 14px;
}

.asesor-orden-cab { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.asesor-orden-label { font-weight: 800; }

.asesor-orden-estado {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(242, 92, 5, .12);
  color: #9a3a03;
  font-size: 12.5px;
  font-weight: 800;
}

.asesor-orden-estado.es-listo { background: rgba(37, 211, 102, .16); color: #0b6b33; }
.asesor-orden-estado.es-entregado { background: #ececec; color: #4b5563; }

.asesor-orden-card p { margin: 0; }

.asesor-orden-moto { color: var(--muted, #6b7280); }

.asesor-orden-trabajos { margin: 0; padding-left: 18px; }

.asesor-orden-nota { font-size: 13.5px; }

.asesor-orden-fila { color: var(--muted, #6b7280); font-size: 13px; }

.asesor-orden-total { padding-top: 6px; border-top: 1px dashed #e5e7eb; }
