/* NS Shop Assistant - widget. Todo va bajo #nsa-root para no chocar con el tema. */

#nsa-root {
  --nsa-color: #2563eb;
  --nsa-ink: #1d2433;
  --nsa-muted: #667085;
  --nsa-line: #e4e7ec;
  --nsa-canvas: #f6f7f9;
  position: fixed;
  bottom: 20px;
  z-index: 2147483000;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--nsa-ink);
  text-align: left;
}
#nsa-root.nsa-right { right: 20px; }
#nsa-root.nsa-left { left: 20px; }
#nsa-root *, #nsa-root *::before, #nsa-root *::after { box-sizing: border-box; }
#nsa-root button {
  margin: 0; font: inherit; text-transform: none; letter-spacing: normal;
  line-height: 1; cursor: pointer; -webkit-appearance: none; appearance: none;
}
#nsa-root button:focus-visible, #nsa-root a:focus-visible, #nsa-root textarea:focus-visible {
  outline: 2px solid var(--nsa-color); outline-offset: 2px;
}

/* Botón flotante */
#nsa-root .nsa-launcher {
  position: relative;
  width: 58px; height: 58px; border-radius: 50%; border: 0; padding: 0;
  background: var(--nsa-color); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(16, 24, 40, .22);
  transition: transform .15s ease;
}
#nsa-root .nsa-launcher:hover { transform: scale(1.05); }

/* Halo para llamar la atención mientras no se ha abierto el chat */
#nsa-root.nsa-pulse .nsa-launcher::after {
  content: ""; position: absolute; width: 58px; height: 58px; border-radius: 50%;
  border: 2px solid var(--nsa-color); opacity: 0; pointer-events: none;
  animation: nsa-ring 2.4s ease-out infinite;
}
@keyframes nsa-ring {
  0% { transform: scale(1); opacity: .55; }
  70% { transform: scale(1.45); opacity: 0; }
  100% { transform: scale(1.45); opacity: 0; }
}

/* Aviso junto al botón: "Estoy aquí para ayudarte" */
#nsa-root .nsa-teaser {
  position: absolute; bottom: 6px; display: none; align-items: center; gap: 2px;
  max-width: min(300px, calc(100vw - 110px));
  background: #fff; border: 1px solid var(--nsa-line); border-radius: 16px;
  box-shadow: 0 10px 28px rgba(16, 24, 40, .18);
  padding: 4px 4px 4px 6px;
}
#nsa-root.nsa-right .nsa-teaser { right: 70px; }
#nsa-root.nsa-left .nsa-teaser { left: 70px; }
#nsa-root.nsa-teaser-on:not(.nsa-is-open) .nsa-teaser { display: flex; animation: nsa-teaser-in .25s ease-out; }
@keyframes nsa-teaser-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#nsa-root .nsa-teaser-text {
  border: 0; background: transparent; color: var(--nsa-ink); text-align: left;
  padding: 7px 8px; font-size: 14px; font-weight: 600; line-height: 1.3; border-radius: 12px;
}
#nsa-root .nsa-teaser-text:hover { color: var(--nsa-color); }
#nsa-root .nsa-teaser-close {
  flex: 0 0 26px; width: 26px; height: 26px; border: 0; border-radius: 50%; padding: 0;
  background: transparent; color: var(--nsa-muted);
  display: flex; align-items: center; justify-content: center;
}
#nsa-root .nsa-teaser-close svg { width: 14px; height: 14px; }
#nsa-root .nsa-teaser-close:hover { background: var(--nsa-canvas); color: var(--nsa-ink); }

/* Panel */
#nsa-root .nsa-panel {
  position: absolute; bottom: 72px; right: 0;
  width: 380px; max-width: calc(100vw - 32px);
  height: 600px; max-height: calc(100vh - 110px);
  background: #fff; border-radius: 18px; overflow: hidden;
  box-shadow: 0 18px 48px rgba(16, 24, 40, .24), 0 0 0 1px rgba(16, 24, 40, .05);
  display: none; flex-direction: column;
}
#nsa-root.nsa-left .nsa-panel { left: 0; right: auto; }
#nsa-root.nsa-is-open .nsa-panel { display: flex; animation: nsa-in .18s ease-out; }
@keyframes nsa-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

#nsa-root .nsa-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 10px 12px 14px; background: var(--nsa-color); color: #fff;
}
#nsa-root .nsa-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
  background: rgba(255, 255, 255, .2); display: flex; align-items: center; justify-content: center;
}
#nsa-root .nsa-titles { flex: 1; min-width: 0; }
#nsa-root .nsa-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#nsa-root .nsa-sub { font-size: 12px; opacity: .85; }
#nsa-root .nsa-actions { display: flex; gap: 2px; }
#nsa-root .nsa-icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 8px; padding: 0;
  background: transparent; color: #fff; display: flex; align-items: center; justify-content: center;
}
#nsa-root .nsa-icon-btn:hover { background: rgba(255, 255, 255, .16); }

/* Mensajes */
#nsa-root .nsa-list {
  flex: 1; overflow-y: auto; padding: 16px 14px;
  background: var(--nsa-canvas); display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain;
}
#nsa-root .nsa-row { display: flex; flex-direction: column; max-width: 88%; }
#nsa-root .nsa-user { align-self: flex-end; align-items: flex-end; }
#nsa-root .nsa-assistant { align-self: flex-start; align-items: stretch; }
#nsa-root .nsa-bubble {
  padding: 9px 13px; border-radius: 16px; font-size: 14.5px;
  overflow-wrap: anywhere; word-break: normal;
}
#nsa-root .nsa-user .nsa-bubble { background: var(--nsa-color); color: #fff; border-bottom-right-radius: 5px; white-space: pre-wrap; }
#nsa-root .nsa-assistant .nsa-bubble { background: #fff; border: 1px solid var(--nsa-line); border-bottom-left-radius: 5px; }
#nsa-root .nsa-bubble a { color: var(--nsa-color); text-decoration: underline; }
#nsa-root .nsa-bubble strong { font-weight: 700; }
#nsa-root .nsa-error .nsa-bubble { background: #fef3f2; border-color: #fecdca; color: #912018; }

#nsa-root .nsa-typing { display: inline-flex; gap: 4px; padding: 13px 14px; align-self: flex-start; }
#nsa-root .nsa-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--nsa-muted);
  animation: nsa-dot 1s infinite ease-in-out;
}
#nsa-root .nsa-typing span:nth-child(2) { animation-delay: .15s; }
#nsa-root .nsa-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes nsa-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Fichas de producto */
#nsa-root .nsa-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#nsa-root .nsa-card {
  display: flex; gap: 10px; padding: 8px; background: #fff;
  border: 1px solid var(--nsa-line); border-radius: 12px;
  color: inherit; text-decoration: none;
}
#nsa-root a.nsa-card:hover { border-color: var(--nsa-color); text-decoration: none; }
#nsa-root .nsa-card-img {
  flex: 0 0 72px; width: 72px; height: 72px; border-radius: 8px; overflow: hidden;
  background: #fff; display: flex; align-items: center; justify-content: center;
}
#nsa-root .nsa-card-img img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
#nsa-root .nsa-card-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#nsa-root .nsa-card-name {
  font-size: 13.5px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
#nsa-root .nsa-card-price { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
#nsa-root .nsa-price { font-weight: 700; font-size: 14.5px; }
#nsa-root .nsa-old { color: var(--nsa-muted); font-size: 12.5px; }
#nsa-root .nsa-stock { font-size: 12px; }
#nsa-root .nsa-ok { color: #067647; }
#nsa-root .nsa-ko { color: #b42318; }
#nsa-root .nsa-card-cta { font-size: 12.5px; font-weight: 600; color: var(--nsa-color); margin-top: 2px; }

/* Contacto con persona */
#nsa-root .nsa-contact {
  margin-top: 8px; padding: 10px 12px; background: #fff;
  border: 1px solid var(--nsa-line); border-radius: 12px;
}
#nsa-root .nsa-contact-title { font-size: 13.5px; font-weight: 600; margin-bottom: 8px; }
#nsa-root .nsa-contact-btns { display: flex; flex-wrap: wrap; gap: 6px; }
#nsa-root .nsa-cbtn {
  display: inline-block; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--nsa-color); color: var(--nsa-color); background: #fff; text-decoration: none;
}
#nsa-root .nsa-cbtn:hover { background: var(--nsa-color); color: #fff; text-decoration: none; }
#nsa-root .nsa-cbtn.nsa-wa { background: #25d366; border-color: #25d366; color: #fff; }
#nsa-root .nsa-cbtn.nsa-wa:hover { background: #1da851; border-color: #1da851; }

/* Sugerencias iniciales */
#nsa-root .nsa-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; background: var(--nsa-canvas); }
#nsa-root .nsa-chips[hidden] { display: none; }
#nsa-root .nsa-chip {
  padding: 7px 12px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--nsa-line); background: #fff; color: var(--nsa-ink);
}
#nsa-root .nsa-chip:hover { border-color: var(--nsa-color); color: var(--nsa-color); }

/* Entrada */
#nsa-root .nsa-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 6px; border-top: 1px solid var(--nsa-line); background: #fff; }
#nsa-root .nsa-input {
  flex: 1; resize: none; min-height: 42px; max-height: 120px; margin: 0;
  padding: 10px 12px; border: 1px solid var(--nsa-line); border-radius: 12px;
  font: inherit; font-size: 15px; line-height: 1.35; color: var(--nsa-ink); background: #fff;
  box-shadow: none; outline: none;
}
#nsa-root .nsa-input:focus { border-color: var(--nsa-color); }
#nsa-root .nsa-send {
  flex: 0 0 42px; width: 42px; height: 42px; border: 0; border-radius: 12px; padding: 0;
  background: var(--nsa-color); color: #fff; display: flex; align-items: center; justify-content: center;
}
#nsa-root .nsa-send:disabled { opacity: .45; cursor: default; }
#nsa-root .nsa-foot { padding: 0 12px 10px; font-size: 11.5px; color: var(--nsa-muted); text-align: center; background: #fff; }
#nsa-root .nsa-foot a { color: var(--nsa-muted); text-decoration: underline; }

/* Móvil: pantalla completa al abrir */
@media (max-width: 520px) {
  #nsa-root { bottom: 16px; }
  #nsa-root.nsa-right { right: 16px; }
  #nsa-root.nsa-left { left: 16px; }
  #nsa-root.nsa-is-open .nsa-panel {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; max-width: none; height: 100%; max-height: none; border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #nsa-root.nsa-is-open .nsa-head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  #nsa-root.nsa-is-open .nsa-launcher { display: none; }
  #nsa-root .nsa-input { font-size: 16px; } /* evita el zoom automático en iOS */
  #nsa-root .nsa-teaser { max-width: calc(100vw - 100px); }
  #nsa-root .nsa-teaser-text { font-size: 13.5px; }
}

@media (prefers-reduced-motion: reduce) {
  #nsa-root .nsa-launcher, #nsa-root.nsa-is-open .nsa-panel, #nsa-root .nsa-typing span,
  #nsa-root.nsa-pulse .nsa-launcher::after, #nsa-root.nsa-teaser-on .nsa-teaser { animation: none; transition: none; }
  #nsa-root.nsa-pulse .nsa-launcher::after { display: none; }
}
