/* ============================================================
   SIGP-Ω · Chat público flotante (landing + tiendas)
   ============================================================ */

.chat-fab {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 60px; height: 60px;
  background: linear-gradient(135deg, #8A2BE2, #00f2ff);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(138,43,226,0.5);
  z-index: 99990;
  font-size: 1.8em;
  transition: transform .2s;
  border: none;
  color: #fff;
  animation: fabPulse 2.5s infinite;
}
.chat-fab:hover { transform: scale(1.08); animation: none; }
.chat-fab.abierto { transform: scale(0.95); animation: none; }

@keyframes fabPulse {
  0%, 100% { box-shadow: 0 10px 30px rgba(138,43,226,0.5); }
  50% { box-shadow: 0 10px 30px rgba(0,242,255,0.7); }
}

.chat-globo {
  position: fixed;
  bottom: 95px; right: 24px;
  background: #fff;
  color: #000;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.85em;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  z-index: 99989;
  display: none;
  animation: globoIn .3s ease-out;
  cursor: pointer;
}
.chat-globo.activo { display: block; }
.chat-globo::after {
  content: '';
  position: absolute;
  bottom: -6px; right: 22px;
  width: 12px; height: 12px;
  background: #fff;
  transform: rotate(45deg);
}

@keyframes globoIn {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

.chat-panel {
  position: fixed;
  bottom: 95px; right: 24px;
  width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 130px);
  background: #121212;
  border: 2px solid #8A2BE2;
  border-radius: 16px;
  display: none;
  flex-direction: column;
  z-index: 99991;
  box-shadow: 0 20px 60px rgba(138,43,226,0.4);
  overflow: hidden;
  animation: panelIn .25s ease-out;
}
.chat-panel.activo { display: flex; }

@keyframes panelIn {
  from { transform: translateY(20px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.chat-panel-header {
  background: linear-gradient(90deg, #8A2BE2, #6b1ea8);
  padding: 14px 18px;
  display: flex; align-items: center; gap: 12px;
  color: #fff;
  flex-shrink: 0;
  flex-grow: 0;
  position: sticky;
  top: 0;
  z-index: 99995;
}
.chat-panel-header .chat-avatar {
  width: 38px; height: 38px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3em;
  flex-shrink: 0;
}
.chat-panel-header .chat-info { flex: 1; min-width: 0; }
.chat-panel-header .chat-info strong { display: block; font-size: 0.95em; }
.chat-panel-header .chat-info span { font-size: 0.75em; opacity: 0.85; }

.chat-panel-header .chat-ver-productos {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1em;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  flex-shrink: 0;
  position: relative;
  z-index: 99996;
}
.chat-panel-header .chat-ver-productos:hover {
  background: rgba(255,255,255,0.35);
}
.chat-panel-header .chat-ver-productos.pulso {
  animation: pulsoProductos 0.8s ease-in-out infinite;
}
@keyframes pulsoProductos {
  0%, 100% { transform: scale(1); background: rgba(255,255,255,0.2); }
  50%      { transform: scale(1.15); background: rgba(0,242,255,0.5); }
}
@media (max-width: 1024px) {
  .chat-panel-header .chat-ver-productos { display: inline-flex; }
}
@media (min-width: 1025px) {
  .chat-panel-header .chat-ver-productos { display: none; }
  .chat-panel-header .chat-ver-productos.visible { display: inline-flex; }
}

.chat-panel-header .chat-cerrar {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 1.2em;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
  flex-shrink: 0;
  position: relative;
  z-index: 99997;
  pointer-events: auto !important;
  transition: background .2s;
}
.chat-panel-header .chat-cerrar:hover { background: rgba(0,0,0,0.3); }
.chat-panel-header .chat-cerrar:active { background: rgba(0,0,0,0.5); }

.chat-debug-banner {
  background: #ff0055;
  color: #fff;
  font-size: 0.72em;
  font-weight: 700;
  text-align: center;
  padding: 6px 10px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  position: sticky;
  top: 66px;
  z-index: 99994;
}

.chat-mensajes {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #0a0a0a;
}
.chat-mensajes::-webkit-scrollbar { width: 6px; }
.chat-mensajes::-webkit-scrollbar-thumb { background: rgba(138,43,226,0.4); border-radius: 3px; }

.burbuja {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9em;
  line-height: 1.4;
  word-wrap: break-word;
  animation: burbujaIn .2s ease-out;
}
@keyframes burbujaIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.burbuja-ia {
  background: #1a1a1a;
  border: 1px solid rgba(138,43,226,0.3);
  color: #f0f0f0;
  align-self: flex-start;
  border-top-left-radius: 4px;
}
.burbuja-usuario {
  background: #8A2BE2;
  color: #fff;
  align-self: flex-end;
  border-top-right-radius: 4px;
}

.burbuja .burbuja-audio { margin-top: 8px; }
.burbuja .burbuja-audio audio { width: 100%; height: 32px; }

.burbuja .burbuja-audio-usuario { min-width: 200px; }
.burbuja .burbuja-audio-usuario audio {
  width: 100%;
  height: 34px;
  display: block;
}

.burbuja-debug-transc {
  font-size: 0.72em;
  color: rgba(255,255,255,0.8);
  background: rgba(0,0,0,0.25);
  padding: 4px 8px;
  border-radius: 6px;
  margin-top: 6px;
  font-style: italic;
  word-break: break-word;
}

.burbuja-debug-sistema {
  align-self: center;
  max-width: 90%;
  background: #333;
  color: #00f2ff;
  border: 1px dashed #00f2ff;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.72em;
  font-family: monospace;
  text-align: center;
  word-break: break-word;
  animation: burbujaIn .2s ease-out;
}

.burbuja .burbuja-opciones {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.burbuja .burbuja-opciones button {
  background: rgba(0,242,255,0.1);
  border: 1px solid #00f2ff;
  color: #00f2ff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.82em;
  cursor: pointer;
  transition: all .2s;
}
.burbuja .burbuja-opciones button:hover {
  background: #00f2ff;
  color: #000;
}

.chat-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.chat-typing span {
  width: 6px; height: 6px;
  background: #8A2BE2;
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.chat-input-wrap {
  padding: 12px;
  background: #121212;
  border-top: 1px solid rgba(138,43,226,0.2);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  flex-grow: 0;
  position: sticky;
  bottom: 0;
  z-index: 99995;
}
.chat-input-wrap input {
  flex: 1;
  min-width: 0;
  background: #1a1a1a;
  border: 1px solid rgba(138,43,226,0.3);
  color: #f0f0f0;
  padding: 10px 14px;
  border-radius: 22px;
  font-size: 0.9em;
  font-family: inherit;
  outline: none;
}
.chat-input-wrap input:focus { border-color: #00f2ff; }
.chat-input-wrap input:disabled { opacity: 0.6; cursor: not-allowed; }

.chat-input-wrap .chat-send {
  background: #8A2BE2;
  color: #fff;
  border: none;
  width: 42px; height: 42px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1em;
  transition: all .2s;
  flex-shrink: 0;
}
.chat-input-wrap .chat-send:hover { background: #00f2ff; color: #000; }
.chat-input-wrap .chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-input-wrap .chat-mic {
  background: #1a1a1a;
  color: #8A2BE2;
  border: 2px solid #8A2BE2;
  width: 42px; height: 42px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1em;
  transition: all .2s;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}
.chat-input-wrap .chat-mic:hover { background: #8A2BE2; color: #fff; }
.chat-input-wrap .chat-mic.grabando {
  background: #ff0055;
  color: #fff;
  border-color: #ff0055;
  animation: micPulse 1s infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,0,85,0.7); }
  50%      { box-shadow: 0 0 0 10px rgba(255,0,85,0); }
}

.chat-grab-timer {
  color: #ff0055;
  font-weight: 700;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
  flex-shrink: 0;
}

.chat-grab-cancel {
  background: #ff0055;
  color: #fff;
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9em;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

/* ============================================================
   Mini-cards de productos
   ============================================================ */
.burbuja-productos {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  max-width: 100%;
}
.burbuja-productos .producto-mini {
  display: flex;
  gap: 10px;
  background: #1a1a1a;
  border: 1px solid rgba(138,43,226,0.35);
  border-radius: 10px;
  padding: 8px;
  text-decoration: none;
  color: inherit;
  transition: all .2s;
  align-items: center;
}
.burbuja-productos .producto-mini:hover {
  border-color: #00f2ff;
  transform: translateX(2px);
  box-shadow: 0 4px 12px rgba(0,242,255,0.15);
}
.burbuja-productos .producto-mini img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  background: #0a0a0a;
  flex-shrink: 0;
}
.burbuja-productos .producto-mini .producto-mini-img-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  background: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5em;
  flex-shrink: 0;
  color: #555;
}
.burbuja-productos .producto-mini .producto-mini-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.burbuja-productos .producto-mini .producto-mini-nombre {
  font-size: 0.85em;
  font-weight: 600;
  color: #f0f0f0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.25;
}
.burbuja-productos .producto-mini .producto-mini-precio {
  font-size: 0.9em;
  font-weight: 700;
  color: #00f2ff;
}
.burbuja-productos .producto-mini .producto-mini-stock {
  font-size: 0.72em;
  color: #a0a0a0;
}
.burbuja-productos .producto-mini .producto-mini-stock.sin-stock {
  color: #ff0055;
}

/* ============================================================
   FIX: Modal del carrito por ENCIMA del chat
   (el chat usa z-index 99991, el modal de la tienda suele ser más bajo)
   ============================================================ */
.modal-carrito {
  z-index: 999999 !important;
}
.modal-checkout {
  z-index: 999999 !important;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 600px) {
  .chat-panel {
    bottom: 0; right: 0;
    width: 100vw; max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .chat-fab { bottom: 18px; right: 18px; }
  .chat-globo { bottom: 88px; right: 18px; }

  .chat-mensajes { padding: 12px; }

  .burbuja-productos .producto-mini img,
  .burbuja-productos .producto-mini .producto-mini-img-placeholder {
    width: 44px;
    height: 44px;
  }
  .burbuja-productos .producto-mini .producto-mini-nombre { font-size: 0.8em; }
  .burbuja-productos .producto-mini .producto-mini-precio { font-size: 0.85em; }
}
