:root {
  --chat-accent: #001a42;
  --chat-accent-2: #002392;
  --chat-bg: #ffffff;
  --chat-fg: #0f172a;
}

/* Fondo */
#pageBackground {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  z-index: 0;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui;
  background: transparent;
}

/* --- Chat container --- */
.chat-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 420px;
  max-width: calc(100vw - 32px);
  z-index: 100;
  background: var(--chat-bg);
  box-shadow: 0 12px 36px rgba(2,6,23,.15);
  border: 1px solid #e2e8f0;
  overflow: visible;
  transition: all 0.35s ease;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.chat-container.cerrado .chat-body {
  max-height: 0 !important;
  height: 0;
  overflow: hidden;
  pointer-events: none; 
}

.chat-container.chatAbierto .chat-body {
  max-height: calc(80vh - 60px);
  height: 560px;
}

.chat-container.expandido {
  width: 600px;
  height: auto;
}

.chat-container.expandido.chatAbierto .chat-body {
  height: calc(80vh - 60px);
}

.chat-container.expandido.cerrado .chat-body {
  height: 0 !important;
}

/* Avatar flotante */
.avatarFloating {
  position: absolute;
  top: -30px;
  left: -50px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  background: linear-gradient(135deg, #e2e8f0, #cbd5e1);
  border: 0;
  z-index: 5;
  cursor: pointer;
}

.avatarFloating img {
  width: 100%;
  height: 100%;
  border-radius: 100%;
  object-fit: cover;
  display: flex;
  border: 3px solid #e2e8f0;
  background: white;
  background: url(../img/logo_defecto.png) no-repeat center / cover;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 14px 60px;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-2));
  color: #fff;
  cursor: pointer;
  user-select: none;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  position: relative;
}

.ChatTitulo {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-inline: auto;
}

.tituloChat {
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtituloHeader {
  font-size: 12px;
  opacity: 0.85;
}

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Botones de acción */
.iconBtn {
  position: relative;
  cursor: pointer;
  background: none;
  border: none;
  font-size: 18px;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.2s ease, transform 0.2s ease;
  overflow: visible;
  color: #fff;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
}

.iconBtn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.iconBtn:active {
  transform: scale(0.95);
}

.iconBtn .icon {
  display: inline-block;
  transition: transform 0.3s ease;
}

/* Tooltip arriba del botón */
.iconBtn::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  transform: translateX(-50%) translateY(-10px);
  background: #222;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 9999;
}

.iconBtn::before {
  content: "";
  position: absolute;
  bottom: calc(100% - 6px);
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  border: 6px solid transparent;
  border-top-color: #222;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 9998;
}

.iconBtn:hover::after,
.iconBtn:hover::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Loader */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-2));
  color: #fff;
}

.spinner {
  width: 48px;
  height: 48px;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Chat body */
.chat-body {
  background: var(--chat-bg);
  transition: max-height 0.35s ease;
  position: relative;
  contain: layout paint size;
  will-change: max-height;
  overflow: hidden;
  max-height: 0;
  height: auto;
}

.chat-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  backface-visibility: hidden;
  transform: translateZ(0);
  pointer-events: auto;
}

/* Mostrar chat */
.chat-container.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Responsive */
@media (max-width: 800px) {
  #expandirBoton {
    display: none !important;
  }

  div#chatBox {
    max-width: calc(100vw - 80px);
  }
  .chat-container.expandido.chatAbierto .chat-body {
      height: 560px;
  }
}

/* Solo avatar en móvil */
.chat-container.soloAvatar {
  width: 80px;
  height: 80px;
  background: transparent;
  border: 0px;
  border-radius: 50%;
  padding: 0;
  overflow: visible;
  transition: all 0.4s ease;
}

.chat-container.soloAvatar .chat-header,
.chat-container.soloAvatar .chat-body,
.chat-container.soloAvatar .actions {
  display: none;
}

.chat-container.soloAvatar .avatarFloating {
  position: relative;
  top: 0;
  left: 0;
  transform: scale(1);
  transition: all 0.4s ease;
  margin: auto;
}

.avatarFloating:focus {
  outline: 2px solid var(--chat-accent-2);
  outline-offset: 3px;
}

.chat-container.soloAvatar {
  pointer-events: auto;
}

.chat-container.soloAvatar .avatarFloating {
  pointer-events: auto;
  z-index: 200;
}
