/*
 * Don Pepe: asistente CTI compartido por /wms, /wms/app y /cliente.
 * Única entrada: el botón flotante con el orbe. Abre un panel (hoja inferior en
 * móvil, panel lateral en escritorio) con botón Cerrar, Esc y clic en el fondo.
 * El orbe es CSS puro (gradientes + blur) en colores CTI: navy, lima, azul y cian.
 */
:root {
  --dp-navy: #0b1b4b;
  --dp-navy-2: #16296b;
  --dp-lima: #c4e000;
  --dp-blue: #2f6bff;
  --dp-cyan: #22d3ee;
  --dp-line: #d9dee8;
  --dp-muted: #5b6b8c;
}

.dp-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Orbe ---------- */
.dp-orb {
  position: relative;
  display: inline-block;
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(circle at 50% 60%, var(--dp-navy-2), var(--dp-navy) 70%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.18),
    0 0 0 0 rgba(196, 224, 0, 0);
  animation: dp-breathe 5.5s ease-in-out infinite;
}

.dp-orb i {
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  mix-blend-mode: screen;
  filter: blur(4px);
  opacity: 0.85;
  animation: dp-swirl 9s linear infinite;
}

.dp-orb i:nth-child(1) {
  background: radial-gradient(circle at 30% 70%, var(--dp-lima) 0 10%, rgba(196, 224, 0, 0) 38%);
}

.dp-orb i:nth-child(2) {
  background: radial-gradient(circle at 72% 38%, var(--dp-cyan) 0 9%, rgba(34, 211, 238, 0) 36%);
  animation-duration: 11s;
  animation-direction: reverse;
}

.dp-orb i:nth-child(3) {
  background: radial-gradient(circle at 42% 24%, var(--dp-blue) 0 14%, rgba(47, 107, 255, 0) 44%);
  animation-duration: 13s;
}

/* Brillo especular encima de los colores. */
.dp-orb::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0) 22%);
  pointer-events: none;
}

/* Anillo que gira solo mientras piensa. */
.dp-orb::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 50%;
  padding: 2px;
  background: conic-gradient(from 0deg, var(--dp-lima), var(--dp-cyan), var(--dp-blue), var(--dp-lima));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.dp-orb-lg {
  width: 4.25rem;
  height: 4.25rem;
}

.dp-orb-lg i {
  filter: blur(8px);
}

/* Pensando: colores más vivos, más rápido, pulso y anillo girando. */
.dp-orb.is-thinking,
.is-busy .dp-orb {
  animation: dp-pulse 1.3s ease-in-out infinite;
}

.dp-orb.is-thinking i,
.is-busy .dp-orb i {
  animation-duration: 2.4s;
  opacity: 1;
  filter: blur(3px) saturate(1.4);
}

.dp-orb.is-thinking i:nth-child(2),
.is-busy .dp-orb i:nth-child(2) {
  animation-duration: 3s;
}

.dp-orb.is-thinking i:nth-child(3),
.is-busy .dp-orb i:nth-child(3) {
  animation-duration: 3.6s;
}

.dp-orb.is-thinking::before,
.is-busy .dp-orb::before {
  opacity: 1;
  animation: dp-spin 1.6s linear infinite;
}

@keyframes dp-breathe {
  0%, 100% { transform: scale(1); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 0 0 0 rgba(196, 224, 0, 0); }
  50% { transform: scale(1.045); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22), 0 0 14px 2px rgba(34, 211, 238, 0.28); }
}

@keyframes dp-pulse {
  0%, 100% { transform: scale(0.96); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), 0 0 10px 2px rgba(196, 224, 0, 0.35); }
  50% { transform: scale(1.08); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3), 0 0 22px 6px rgba(34, 211, 238, 0.45); }
}

@keyframes dp-swirl {
  0% { transform: rotate(0deg) translate(4%, -3%) scale(1); }
  33% { transform: rotate(120deg) translate(-5%, 4%) scale(1.08); }
  66% { transform: rotate(240deg) translate(3%, 5%) scale(0.95); }
  100% { transform: rotate(360deg) translate(4%, -3%) scale(1); }
}

@keyframes dp-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Botón flotante (única entrada) ---------- */
.don-pepe-fab {
  display: none;
  position: fixed;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  z-index: 14; /* debajo de modales, cámara y drawers (40-60): nunca los tapa */
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--dp-navy);
  color: #fff;
  font-family: "Poppins", system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(11, 27, 75, 0.32), inset 0 -3px 0 var(--dp-lima);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.don-pepe-fab:not([hidden]) {
  display: inline-flex;
}

.don-pepe-fab .dp-orb {
  width: 2.6rem;
  height: 2.6rem;
}

/* Solo el orbe (3.5rem, cabe en el canal que reservan recibo/series): el nombre queda para lectores de pantalla y como title. */
.don-pepe-fab-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.don-pepe-fab:hover,
.don-pepe-fab:focus-visible {
  background: var(--dp-navy-2);
}

.don-pepe-fab:focus-visible {
  outline: 3px solid var(--dp-lima);
  outline-offset: 3px;
}

.don-pepe-fab.is-hidden-over-chat {
  display: none;
}

@media (min-width: 800px) {
  .don-pepe-fab {
    right: 1.25rem;
    bottom: 1.25rem;
  }
}

/* Con el botón visible, el final de la página deja espacio: el orbe nunca tapa los últimos botones ni el pie (#170). */
body:has(#don-pepe-fab:not([hidden])) main {
  padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
}

body:has(#don-pepe-fab:not([hidden])) .site-footer {
  padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
}

/* ---------- Fondo y panel ---------- */
.don-pepe-backdrop {
  position: fixed;
  inset: 0;
  z-index: 125;
  background: rgba(11, 27, 75, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: dp-fade 0.2s ease-out;
}

.don-pepe-backdrop[hidden],
.don-pepe[hidden] {
  display: none !important;
}

.don-pepe {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  z-index: 130;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  max-height: min(88dvh, 44rem);
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: #fff;
  color: var(--dp-navy);
  font-family: "Poppins", system-ui, sans-serif;
  box-shadow: 0 -12px 40px rgba(11, 27, 75, 0.28);
  animation: dp-sheet-up 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.don-pepe-grip {
  display: block;
  width: 2.75rem;
  height: 0.3rem;
  margin: 0.55rem auto 0;
  border-radius: 999px;
  background: #cfd6e4;
}

.don-pepe-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem 0.5rem 1rem;
  border-bottom: 1px solid var(--dp-line);
}

.don-pepe-head-copy {
  flex: 1;
  min-width: 0;
}

.don-pepe-kicker {
  margin: 0;
  color: var(--dp-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.don-pepe-head h2 {
  margin: 0;
  color: var(--dp-navy);
  font-size: 1.15rem;
  line-height: 1.2;
}

.don-pepe-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--dp-navy);
  cursor: pointer;
}

.don-pepe-close svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.don-pepe-close:hover,
.don-pepe-close:focus-visible {
  background: rgba(11, 27, 75, 0.07);
}

.don-pepe-close:focus-visible {
  outline: 3px solid var(--dp-lima);
  outline-offset: 1px;
}

.don-pepe-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.75rem 1rem 0.5rem;
}

.don-pepe-lead {
  margin: 0 0 0.6rem;
  color: var(--dp-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.don-pepe-log {
  display: grid;
  align-content: start;
  gap: 0.6rem;
  min-height: 5rem;
  max-height: none;
  overflow: visible;
  padding: 0.1rem 0 0.5rem;
}

.don-pepe-msg {
  max-width: 88%;
  padding: 0.65rem 0.85rem;
  border-radius: 16px;
  font-size: 0.93rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.don-pepe-msg p {
  margin: 0;
  white-space: pre-line;
}

.don-pepe-msg-assistant {
  justify-self: start;
  border: 1px solid rgba(11, 27, 75, 0.12);
  border-bottom-left-radius: 6px;
  background: #eef1f7;
  color: var(--dp-navy);
}

.don-pepe-msg-user {
  justify-self: end;
  border-bottom-right-radius: 6px;
  background: var(--dp-navy);
  color: #fff;
}

.don-pepe-msg-cite {
  display: block;
  margin-top: 0.4rem;
  color: var(--dp-muted);
  font-size: 0.75rem;
}

/* Pensando (mientras llega la respuesta). */
.don-pepe-thinking {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0 0.6rem;
  color: var(--dp-navy);
  font-size: 0.9rem;
  font-weight: 500;
}

.don-pepe-thinking[hidden] {
  display: none;
}

.don-pepe-thinking .dp-orb {
  width: 2.75rem;
  height: 2.75rem;
}

.don-pepe-dots::after {
  content: "…";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: dp-dots 1.2s steps(4, end) infinite;
  overflow: hidden;
  vertical-align: bottom;
}

@keyframes dp-dots {
  0% { width: 0; }
  100% { width: 1.2em; }
}

.don-pepe-foot {
  padding: 0.6rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--dp-line);
  background: #fff;
}

.don-pepe-form {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin: 0;
}

.don-pepe-ask {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.don-pepe-ask input {
  width: 100%;
  min-height: 3rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--dp-line);
  border-radius: 14px;
  background: #fff;
  color: var(--dp-navy);
  font: inherit;
  font-size: 1rem; /* 16px: iOS no hace zoom al enfocar */
}

.don-pepe-ask input:focus {
  outline: 2px solid var(--dp-lima);
  outline-offset: 1px;
  border-color: var(--dp-navy);
}

.don-pepe-send {
  flex: none;
  min-height: 3rem;
  padding: 0 1.05rem;
  border: 0;
  border-radius: 14px;
  background: var(--dp-navy);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

.don-pepe-status {
  margin: 0.45rem 0 0;
  color: var(--dp-muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

html.dp-scroll-lock,
html.dp-scroll-lock body {
  overflow: hidden;
}

/* Escritorio: panel lateral derecho. */
@media (min-width: 800px) {
  .don-pepe {
    top: 0;
    left: auto;
    right: 0;
    bottom: 0;
    width: min(27rem, 100vw);
    max-height: none;
    border-radius: 22px 0 0 22px;
    box-shadow: -12px 0 40px rgba(11, 27, 75, 0.25);
    animation-name: dp-panel-in;
  }

  .don-pepe-grip {
    display: none;
  }

  .don-pepe-head {
    padding-top: 0.9rem;
  }
}

@keyframes dp-sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes dp-panel-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes dp-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Sin movimiento: el orbe queda quieto; el estado «pensando» se nota por el anillo y el texto. */
@media (prefers-reduced-motion: reduce) {
  .dp-orb,
  .dp-orb i,
  .dp-orb::before,
  .don-pepe,
  .don-pepe-backdrop,
  .don-pepe-dots::after {
    animation: none !important;
  }

  .dp-orb.is-thinking::before,
  .is-busy .dp-orb::before {
    opacity: 1;
  }
}
