/* Burbuja de chat de Nivel Zero Chatbot */
.nzchat {
  --nzchat-color: #315bff;
  --nzchat-on-color: #fff;
  --nzchat-ink: #0b1730;
  --nzchat-muted: #5b6577;
  --nzchat-bg: #ffffff;
  --nzchat-soft: #f1f4fa;
  --nzchat-line: #dde3ee;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99990;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--nzchat-ink);
}
.nzchat *, .nzchat *::before, .nzchat *::after { box-sizing: border-box; }
.nzchat button, .nzchat input, .nzchat textarea { font: inherit; color: inherit; margin: 0; }

.nzchat-bubble {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin-left: auto;
  border: 0;
  border-radius: 50%;
  background: var(--nzchat-color);
  color: var(--nzchat-on-color);
  box-shadow: 0 10px 28px rgba(11, 23, 48, .28);
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
}
.nzchat-bubble:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(11, 23, 48, .32); }
.nzchat-bubble:focus-visible, .nzchat button:focus-visible, .nzchat a:focus-visible { outline: 3px solid #8fe5ff; outline-offset: 2px; }

.nzchat-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  display: flex;
  flex-direction: column;
  width: 370px;
  height: min(600px, calc(100vh - 120px));
  overflow: hidden;
  border: 1px solid var(--nzchat-line);
  border-radius: 18px;
  background: var(--nzchat-bg);
  box-shadow: 0 24px 60px rgba(11, 23, 48, .25);
  animation: nzchat-in .22s ease-out;
}
.nzchat-panel[hidden] { display: none; }
@keyframes nzchat-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.nzchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 14px 18px;
  background: var(--nzchat-color);
  color: var(--nzchat-on-color);
}
.nzchat-header p { margin: 0; }
.nzchat-title { font-weight: 700; font-size: 16px; }
.nzchat-subtitle { font-size: 12px; opacity: .85; }
.nzchat-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.nzchat-close:hover { background: rgba(255, 255, 255, .16); }

.nzchat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--nzchat-soft);
}
.nzchat-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.nzchat-model { align-self: flex-start; background: var(--nzchat-bg); border: 1px solid var(--nzchat-line); border-bottom-left-radius: 4px; }
.nzchat-user { align-self: flex-end; background: var(--nzchat-color); color: var(--nzchat-on-color); border-bottom-right-radius: 4px; }
.nzchat-msg a { color: inherit; text-decoration: underline; }
.nzchat-model a { color: var(--nzchat-color); }
.nzchat-error { border-color: #f0c2c2; background: #fff6f6; }

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

.nzchat-footer { padding: 10px 12px 12px; border-top: 1px solid var(--nzchat-line); background: var(--nzchat-bg); }
.nzchat-form { display: flex; align-items: flex-end; gap: 8px; }
.nzchat-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 12px;
  border: 1px solid var(--nzchat-line);
  border-radius: 12px;
  background: var(--nzchat-bg);
  resize: none;
  overflow-y: hidden;
  font-size: 16px !important; /* 16 px evita que el iPhone amplíe la página al escribir */
  line-height: 1.35;
}
.nzchat-input:focus, .nzchat-lead input:focus, .nzchat-lead textarea:focus { outline: 2px solid var(--nzchat-color); outline-offset: 0; border-color: transparent; }
.nzchat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: var(--nzchat-color);
  color: var(--nzchat-on-color);
  cursor: pointer;
}
.nzchat-send:disabled { opacity: .5; cursor: wait; }
.nzchat-human {
  display: block;
  margin: 8px auto 0;
  padding: 4px 6px;
  border: 0;
  background: none;
  color: var(--nzchat-muted);
  font-size: 13px !important;
  text-decoration: underline;
  cursor: pointer;
}

.nzchat-lead {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--nzchat-line);
  border-radius: 14px;
  background: var(--nzchat-bg);
}
.nzchat-lead-title { margin: 0 0 4px; font-weight: 700; }
.nzchat-lead label { font-size: 13px; font-weight: 700; }
.nzchat-lead input[type="text"], .nzchat-lead textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--nzchat-line);
  border-radius: 10px;
  background: var(--nzchat-bg);
  font-size: 16px !important;
}
.nzchat-lead textarea { resize: vertical; }
.nzchat-lead .nzchat-consent { display: block; margin-top: 4px; font-weight: 400; line-height: 1.4; }
.nzchat-consent input { margin-right: 4px; vertical-align: -2px; }
.nzchat-consent a { color: var(--nzchat-color); }
.nzchat-trap { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.nzchat-lead-send {
  margin-top: 6px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--nzchat-color);
  color: var(--nzchat-on-color);
  font-weight: 700;
  cursor: pointer;
}
.nzchat-lead-send:disabled { opacity: .6; }
.nzchat-lead-status { margin: 0; font-size: 13px; color: var(--nzchat-muted); }
.nzchat-lead-status:empty { display: none; }

/* Móvil: el chat ocupa toda la pantalla */
@media (max-width: 520px) {
  .nzchat { right: 16px; bottom: 16px; }
  .nzchat-bubble { width: 56px; height: 56px; }
  .nzchat.is-open .nzchat-bubble { display: none; }
  .nzchat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  .nzchat-header { padding-top: max(14px, env(safe-area-inset-top)); }
  .nzchat-footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .nzchat-msg { max-width: 90%; }
}

@media (prefers-reduced-motion: reduce) {
  .nzchat-panel, .nzchat-typing span { animation: none; }
  .nzchat-bubble { transition: none; }
}

@media print { .nzchat { display: none; } }
