/* Asistente Imprenta Lebrijana — inferior derecha */
.il-bot {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  /* Por encima del site-header (z-index 10050) y del menú móvil (10040) */
  z-index: 10100;
  width: auto;
  height: auto;
  font-family: inherit;
  pointer-events: none;
}

.il-bot > * {
  pointer-events: auto;
}

.il-bot-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 10101;
  width: 3.5rem;
  height: 3.5rem;
  border: 0;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #0077a8 0%, #00aeef 55%, #38bdf8 100%);
  box-shadow: 0 10px 28px rgba(0, 119, 168, 0.45);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.il-bot-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(0, 119, 168, 0.55);
}

.il-bot-fab[aria-expanded="true"] {
  background: #111827;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.il-bot-fab-icon[hidden] {
  display: none !important;
}

.il-bot-panel {
  position: absolute;
  right: 0;
  bottom: 4.5rem;
  width: min(380px, calc(100vw - 1.5rem));
  height: min(560px, calc(100dvh - 6.5rem));
  display: flex;
  flex-direction: column;
  border-radius: 1.15rem;
  border: 1px solid rgba(17, 24, 39, 0.1);
  background: rgba(255, 255, 255, 0.98);
  color: #111827;
  box-shadow: 0 24px 70px -18px rgba(15, 23, 42, 0.45), 0 0 40px -18px rgba(0, 174, 239, 0.35);
  overflow: hidden;
  transform-origin: bottom right;
  animation: il-bot-in 0.22s ease;
}

.il-bot-panel[hidden] {
  display: none !important;
}

@keyframes il-bot-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.il-bot-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid rgba(17, 24, 39, 0.08);
  background: linear-gradient(180deg, #f8fbfd 0%, #ffffff 100%);
}

.il-bot-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  object-fit: cover;
  flex-shrink: 0;
  background: #e8f7fd;
}

.il-bot-head-text {
  min-width: 0;
  flex: 1;
}

.il-bot-head-text h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.25;
  color: #111827;
}

.il-bot-status {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: #0077a8;
}

.il-bot-status.is-busy {
  color: #6b7280;
}

.il-bot-new,
.il-bot-close {
  border: 0;
  background: rgba(17, 24, 39, 0.05);
  color: #374151;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.il-bot-new:hover,
.il-bot-close:hover {
  background: rgba(17, 24, 39, 0.1);
}

.il-bot-new[hidden] {
  display: none !important;
}

.il-bot-new-label {
  font-size: 0.68rem;
  font-weight: 650;
}

.il-bot-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.9rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background:
    radial-gradient(ellipse at top right, rgba(0, 174, 239, 0.07), transparent 55%),
    #f7fafc;
}

.il-bot-msg {
  display: flex;
  gap: 0.55rem;
  max-width: 94%;
  align-items: flex-end;
}

.il-bot-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.il-bot-msg-avatar {
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 0.45rem;
  object-fit: cover;
  flex-shrink: 0;
}

.il-bot-msg--user .il-bot-msg-avatar {
  display: none;
}

.il-bot-msg-body {
  min-width: 0;
}

.il-bot-bubble {
  padding: 0.65rem 0.8rem;
  border-radius: 0.95rem;
  font-size: 0.9rem;
  line-height: 1.45;
  background: #fff;
  border: 1px solid rgba(17, 24, 39, 0.08);
  color: #1f2937;
  word-wrap: break-word;
}

.il-bot-msg--user .il-bot-bubble {
  background: linear-gradient(135deg, #0077a8, #00aeef);
  border-color: transparent;
  color: #fff;
  border-bottom-right-radius: 0.35rem;
}

.il-bot-msg:not(.il-bot-msg--user) .il-bot-bubble {
  border-bottom-left-radius: 0.35rem;
}

.il-bot-bubble a {
  color: #0077a8;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.il-bot-msg--user .il-bot-bubble a {
  color: #fff;
}

.il-bot-time {
  margin-top: 0.2rem;
  font-size: 0.68rem;
  color: #9ca3af;
  padding: 0 0.2rem;
}

.il-bot-msg--user .il-bot-time {
  text-align: right;
}

.il-bot-typing {
  display: inline-flex;
  gap: 0.28rem;
  padding: 0.75rem 0.9rem;
}

.il-bot-typing span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: #94a3b8;
  animation: il-bot-dot 1s infinite ease-in-out;
}

.il-bot-typing span:nth-child(2) { animation-delay: 0.15s; }
.il-bot-typing span:nth-child(3) { animation-delay: 0.3s; }

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

.il-bot-foot {
  padding: 0.7rem 0.75rem;
  border-top: 1px solid rgba(17, 24, 39, 0.08);
  background: #fff;
}

.il-bot-form {
  display: flex;
  gap: 0.45rem;
  align-items: flex-end;
}

.il-bot-input {
  flex: 1;
  resize: none;
  min-height: 2.5rem;
  max-height: 7rem;
  border: 1px solid rgba(17, 24, 39, 0.12);
  border-radius: 0.85rem;
  padding: 0.6rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.35;
  background: #f8fafc;
  color: #111827;
}

.il-bot-input:focus {
  outline: 2px solid rgba(0, 174, 239, 0.35);
  outline-offset: 1px;
  border-color: #00aeef;
  background: #fff;
}

.il-bot-send {
  width: 2.55rem;
  height: 2.55rem;
  border: 0;
  border-radius: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  background: #0077a8;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.il-bot-send:hover:not(:disabled) {
  background: #008fc7;
}

.il-bot-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.il-bot .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html[data-theme="dark"] .il-bot-panel {
  background: rgba(13, 17, 23, 0.98);
  border-color: rgba(255, 255, 255, 0.1);
  color: #e5e7eb;
  box-shadow: 0 24px 70px -18px rgba(0, 0, 0, 0.75), 0 0 50px -20px rgba(0, 174, 239, 0.35);
}

html[data-theme="dark"] .il-bot-head {
  background: linear-gradient(180deg, #111827 0%, #0d1117 100%);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .il-bot-head-text h2 {
  color: #f3f4f6;
}

html[data-theme="dark"] .il-bot-messages {
  background:
    radial-gradient(ellipse at top right, rgba(0, 174, 239, 0.12), transparent 55%),
    #0b1016;
}

html[data-theme="dark"] .il-bot-bubble {
  background: #151b24;
  border-color: rgba(255, 255, 255, 0.08);
  color: #e5e7eb;
}

html[data-theme="dark"] .il-bot-foot {
  background: #0d1117;
  border-top-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .il-bot-input {
  background: #111827;
  border-color: rgba(255, 255, 255, 0.12);
  color: #f3f4f6;
}

html[data-theme="dark"] .il-bot-new,
html[data-theme="dark"] .il-bot-close {
  background: rgba(255, 255, 255, 0.06);
  color: #d1d5db;
}

@media (max-width: 767px) {
  .il-bot {
    right: 0.75rem;
    bottom: 0.75rem;
  }

  .il-bot-fab {
    right: 0.75rem;
    bottom: 0.75rem;
  }

  .il-bot-panel {
    position: fixed;
    top: var(--il-bot-vvt, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    max-width: none;
    height: var(--il-bot-vvh, 100dvh);
    max-height: var(--il-bot-vvh, 100dvh);
    border-radius: 0;
    z-index: 10102;
    /* Evita que el teclado «empuje» el layout con transformaciones del body */
    transform: none;
    animation: none;
  }

  .il-bot-fab[aria-expanded="true"] {
    display: none;
  }

  .il-bot-head {
    flex-shrink: 0;
    padding-top: max(0.85rem, env(safe-area-inset-top));
  }

  .il-bot-messages {
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  .il-bot-foot {
    flex-shrink: 0;
    padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
  }

  /* Bloquear scroll de la página detrás del chat a pantalla completa */
  html.il-bot-open,
  html.il-bot-open body {
    overflow: hidden !important;
    overscroll-behavior: none;
    touch-action: none;
    height: 100%;
  }

  html.il-bot-open .site-header,
  html.il-bot-open #header,
  html.il-bot-open .mobile-nav {
    visibility: hidden !important;
    pointer-events: none !important;
  }

  html.il-bot-open .il-bot,
  html.il-bot-open .il-bot-panel,
  html.il-bot-open .il-bot-panel * {
    touch-action: manipulation;
  }

  html.il-bot-open .il-bot-messages {
    touch-action: pan-y;
  }
}
