/* ==========================================================================
   North State Construction — Widget de chat con IA
   Prefijo "nsc-" para no chocar con los estilos del sitio.
   Paleta del sitio: navy #0B1B3F · rojo #B01824
   ========================================================================== */

.nsc-chat-root,
.nsc-chat-root * {
  box-sizing: border-box;
}

.nsc-chat-root {
  --nsc-navy: #0b1b3f;
  --nsc-navy-soft: #16294f;
  --nsc-red: #b01824;
  --nsc-ink: #0f1a2e;
  --nsc-muted: #5a637a;
  --nsc-line: #e2e6f4;
  --nsc-bg: #f4f6f9;
  --nsc-radius: 16px;
  --nsc-shadow: 0 18px 48px rgba(9, 20, 45, 0.22);
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9998;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ------------------------------- Botón flotante ------------------------------ */

.nsc-launcher {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 0 16px;
  height: 54px;
  border: 0;
  border-radius: 999px;
  background: var(--nsc-red);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(176, 24, 36, 0.38);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.nsc-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 38px rgba(176, 24, 36, 0.45);
}

.nsc-launcher:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.nsc-launcher-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.nsc-chat-root.is-open .nsc-launcher {
  display: none;
}

/* Puntito de "no leído" */
.nsc-launcher-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #38c172;
  border: 2.5px solid #fff;
}

.nsc-chat-root.is-open .nsc-launcher-dot {
  display: none;
}

/* ---------------------------------- Panel ---------------------------------- */

.nsc-panel {
  display: none;
  flex-direction: column;
  width: 384px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - 120px));
  background: #fff;
  border-radius: var(--nsc-radius);
  box-shadow: var(--nsc-shadow);
  overflow: hidden;
  animation: nsc-rise 0.22s ease-out;
}

.nsc-chat-root.is-open .nsc-panel {
  display: flex;
}

@keyframes nsc-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Cabecera */
.nsc-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--nsc-navy);
  color: #fff;
  flex: 0 0 auto;
}

.nsc-head-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--nsc-red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  flex: 0 0 auto;
}

.nsc-head-text {
  flex: 1 1 auto;
  min-width: 0;
}

.nsc-head-text strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nsc-head-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: #b9c4dd;
}

.nsc-head-status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38c172;
  display: inline-block;
}

.nsc-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.15s ease;
}

.nsc-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Cuerpo con los mensajes */
.nsc-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 16px;
  background: var(--nsc-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nsc-msg {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.nsc-msg-bot {
  align-self: flex-start;
  background: #fff;
  color: var(--nsc-ink);
  border: 1px solid var(--nsc-line);
  border-bottom-left-radius: 4px;
}

.nsc-msg-user {
  align-self: flex-end;
  background: var(--nsc-navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.nsc-msg-note {
  align-self: center;
  max-width: 100%;
  background: #e8f6ee;
  border: 1px solid #bfe6d0;
  color: #1c6b40;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  border-radius: 12px;
  padding: 10px 14px;
}

/* Indicador de escritura */
.nsc-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 13px 15px;
  background: #fff;
  border: 1px solid var(--nsc-line);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.nsc-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a8b2c9;
  animation: nsc-blink 1.2s infinite ease-in-out;
}

.nsc-typing span:nth-child(2) {
  animation-delay: 0.18s;
}
.nsc-typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes nsc-blink {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* Respuestas rápidas */
.nsc-quick {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 16px 10px;
  background: var(--nsc-bg);
}

.nsc-quick:empty {
  display: none;
}

.nsc-chip {
  border: 1px solid var(--nsc-line);
  background: #fff;
  color: var(--nsc-navy);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nsc-chip:hover {
  background: var(--nsc-navy);
  border-color: var(--nsc-navy);
  color: #fff;
}

/* Formulario de envío */
.nsc-form {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid var(--nsc-line);
}

.nsc-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  border: 1px solid var(--nsc-line);
  border-radius: 11px;
  padding: 0 13px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--nsc-ink);
  background: #fff;
}

.nsc-input:focus {
  outline: none;
  border-color: var(--nsc-navy);
  box-shadow: 0 0 0 3px rgba(11, 27, 63, 0.1);
}

.nsc-send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 11px;
  background: var(--nsc-red);
  color: #fff;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s ease;
}

.nsc-send:hover:not(:disabled) {
  filter: brightness(1.1);
}

.nsc-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.nsc-foot {
  flex: 0 0 auto;
  padding: 7px 14px 10px;
  background: #fff;
  text-align: center;
  font-size: 0.68rem;
  color: #98a1b8;
}

/* Estado final: conversación cerrada */
.nsc-chat-root.is-done .nsc-form,
.nsc-chat-root.is-done .nsc-quick {
  display: none;
}

/* ---------------------------------- Móvil ---------------------------------- */

@media (max-width: 640px) {
  .nsc-chat-root {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  /* En móvil el botón se reduce a un círculo para no tapar contenido */
  .nsc-launcher {
    width: 58px;
    height: 58px;
    padding: 0;
    justify-content: center;
    margin-left: auto;
    border-radius: 50%;
  }

  .nsc-launcher-label {
    display: none;
  }

  .nsc-launcher-icon {
    font-size: 1.5rem;
  }

  .nsc-panel {
    width: 100%;
    max-width: 100%;
    height: min(560px, calc(100vh - 90px));
  }

  .nsc-head {
    padding: 12px 14px;
  }

  .nsc-msg {
    max-width: 90%;
  }
}

/* Accesibilidad: respeta a quien prefiere menos animación */
@media (prefers-reduced-motion: reduce) {
  .nsc-panel,
  .nsc-launcher,
  .nsc-typing span {
    animation: none !important;
    transition: none !important;
  }
}
