/* ============================================================
   CHATBOT GPT — TEMA METÁLICO IA
   Paleta: Plateado / Azul Acero / Cian Metálico
   Fondo claro con cuadrícula sutil estilo AI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600&display=swap');

/* ── Variables de color ── */
:root {
  --ai-primary:       #0ea5e9;
  --ai-primary-deep:  #0284c7;
  --ai-accent:        #00b4d8;
  --ai-accent-soft:   #38bdf8;

  /* Fondos metálicos claros */
  --ai-bg-window:     #f4f8fd;
  --ai-bg-messages:   #eaf2fb;
  --ai-bg-card:       #ffffff;
  --ai-bg-input:      #f0f6fc;
  --ai-bg-composer:   #f8fbff;

  /* Header degradado metálico profundo */
  --ai-gradient-header: linear-gradient(135deg, #0d2a52 0%, #1565c0 55%, #00b4d8 100%);

  /* Botón y elementos activos */
  --ai-gradient-btn:  linear-gradient(135deg, #0ea5e9 0%, #0369a1 50%, #00b4d8 100%);

  /* Mensajes del usuario */
  --ai-gradient-user: linear-gradient(135deg, #0369a1 0%, #0ea5e9 60%, #38bdf8 100%);

  /* Bordes y sombras */
  --ai-border:        rgba(14, 165, 233, 0.18);
  --ai-border-focus:  rgba(14, 165, 233, 0.55);
  --ai-shadow-btn:    0 4px 20px rgba(14, 165, 233, 0.35);
  --ai-shadow-window: 0 20px 60px rgba(13, 42, 82, 0.18), 0 2px 8px rgba(14, 165, 233, 0.1);

  /* Texto */
  --ai-text:          #1e293b;
  --ai-text-muted:    #64748b;
  --ai-text-light:    #94a3b8;
}

/* ══════════════════════════════════════
   BASE
══════════════════════════════════════ */
.lock-scroll {
  position: fixed;
  width: 100%;
  overflow: hidden;
  top: 0;
  left: 0;
}

.ai-name {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.ai-chat-wrapper {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 999999;
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ══════════════════════════════════════
   BOTÓN FLOTANTE — metálico con glow
══════════════════════════════════════ */
.ai-chat-button {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  background: linear-gradient(#fff, #fff) padding-box, var(--ai-gradient-btn) border-box;;
  border: none;
  box-shadow:
    var(--ai-shadow-btn),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  outline: none;
  overflow: visible;
}

.ai-chat-button.pulse::before,
.ai-chat-button.pulse::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: rgba(14, 165, 233, 0.3);
  top: 0;
  left: 0;
  animation: pulse 2s infinite;
  z-index: -1;
}

.ai-chat-button.pulse::after {
  animation-delay: 1s;
  background: rgba(0, 180, 216, 0.25);
}

@keyframes pulse {
  0%   { transform: scale(1);   opacity: 0.8; }
  70%  { transform: scale(2.2); opacity: 0;   }
  100% { opacity: 0; }
}

.ai-chat-button:hover {
  transform: translateY(-5px);
  box-shadow:
    0 8px 32px rgba(14, 165, 233, 0.55),
    0 0 50px rgba(0, 180, 216, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.ai-chat-icon {
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-icon img {
  transform: translate(4px, -2px);
}

/* ── Notificación ── */
.ai-chat-notification {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, #f43f5e, #e11d48);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(244, 63, 94, 0.5);
  border: 2px solid #fff;
}

/* ══════════════════════════════════════
   VENTANA DE CHAT — vidrio plateado
══════════════════════════════════════ */
.ai-chat-window {
  position: absolute;
  bottom: 0px;
  right: 0;
  width: 400px;
  height: 680px;
  background-color: var(--ai-bg-window);
  border-radius: 20px;
  border: 1px solid var(--ai-border);
  box-shadow: var(--ai-shadow-window);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.ai-chat-window.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ══════════════════════════════════════
   CABECERA — degradado metálico profundo
══════════════════════════════════════ */
.ai-chat-header {
  padding: 5px 10px;
  background: var(--ai-gradient-header);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 3px 16px rgba(13, 42, 82, 0.35);
  cursor: move;
  position: relative;
}

.ai-chat-title {
  display: flex;
  align-items: center;
  font-weight: 600;
}

.ai-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  background-color: #fff;
  border: 2px solid rgba(56, 189, 248, 0.5);
  box-shadow: 0 0 10px rgba(14, 165, 233, 0.4);
}

.ai-chat-close {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s, box-shadow 0.2s;
}

.ai-chat-close:hover {
  background-color: rgba(56, 189, 248, 0.25);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.35);
}

/* ══════════════════════════════════════
   ÁREA DE MENSAJES — cuadrícula IA
══════════════════════════════════════ */
.ai-chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;

  /* ── Fondo plateado con cuadrícula estilo matriz ── */
  background-color: var(--ai-bg-messages);
  background-image:
    linear-gradient(rgba(14, 165, 233, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(14, 165, 233, 0.09) 1px, transparent 1px);
  background-size: 22px 22px;

  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* Scrollbar sutil metálico */
.ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}
.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--ai-primary-deep), var(--ai-accent));
  border-radius: 4px;
}

/* ── Mensajes de la IA ── */
.ai-message {
  display: flex;
  align-items: flex-start;
  max-width: 85%;
}

.ai-message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ai-gradient-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  margin-right: 10px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(14, 165, 233, 0.3);
}

.ai-message-content {
  background-color: var(--ai-bg-card);
  padding: 12px 15px;
  border-radius: 0 15px 15px 15px;
  box-shadow:
    0 2px 8px rgba(13, 42, 82, 0.08),
    inset 0 0 0 1px rgba(14, 165, 233, 0.15);
  border-left: 3px solid var(--ai-primary);
}

.ai-message-content p {
  margin: 0 0 8px 0;
  line-height: 1.5;
  color: var(--ai-text);
  font-size: 14px;
}

.ai-message-content p:last-child {
  margin-bottom: 0;
}

/* ── Mensajes del usuario ── */
.user-message {
  display: flex;
  justify-content: flex-end;
  max-width: 85%;
  align-self: flex-end;
}

.user-message-avatar {
  width: 40px;
  height: 40px;
  padding: 2px;
  border-radius: 50%;
  background: var(--ai-gradient-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  margin-left: 10px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(14, 165, 233, 0.3);
}

.user-message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.user-message-content {
  background: var(--ai-gradient-user);
  padding: 12px 15px;
  border-radius: 15px 0 15px 15px;
  box-shadow:
    0 4px 14px rgba(3, 105, 161, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.user-message-content p {
  margin: 0;
  line-height: 1.5;
  color: white;
  font-size: 14px;
}

/* ══════════════════════════════════════
   ÁREA DE COMPOSICIÓN (INPUT)
══════════════════════════════════════ */
.ai-chat-composer {
  padding: 15px;
  background-color: var(--ai-bg-composer);
  display: flex;
  align-items: center;
  border-top: 1px solid var(--ai-border);
  box-shadow: 0 -2px 12px rgba(14, 165, 233, 0.07);
}

.ai-chat-composer textarea {
  flex: 1;
  border: 1px solid var(--ai-border);
  border-radius: 20px;
  padding: 10px 15px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  resize: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  background-color: var(--ai-bg-input);
  color: var(--ai-text);
  max-height: 80px;
}

.ai-chat-composer textarea::placeholder {
  color: var(--ai-text-light);
}

.ai-chat-composer textarea:focus {
  border-color: var(--ai-primary);
  box-shadow:
    0 0 0 3px rgba(14, 165, 233, 0.12),
    0 0 16px rgba(14, 165, 233, 0.2);
}

.ai-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ai-gradient-btn);
  border: none;
  color: white;
  margin-left: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 3px 12px rgba(14, 165, 233, 0.4);
}

.ai-chat-send:hover {
  transform: rotate(360deg) scale(1.05);
  box-shadow:
    0 4px 20px rgba(14, 165, 233, 0.6),
    0 0 30px rgba(0, 180, 216, 0.3);
}

/* ══════════════════════════════════════
   INDICADOR DE ESCRITURA
══════════════════════════════════════ */
.typing-indicator .ai-message-content {
  padding: 12px 20px;
}

.dot-typing {
  display: flex;
  align-items: center;
  height: 16px;
}

.dot-typing span {
  height: 8px;
  width: 8px;
  background: linear-gradient(135deg, var(--ai-primary), var(--ai-accent));
  border-radius: 50%;
  margin-right: 5px;
  animation: typing 1.4s infinite;
  display: inline-block;
  box-shadow: 0 0 5px rgba(14, 165, 233, 0.4);
}

.dot-typing span:nth-child(2) { animation-delay: 0.2s; }
.dot-typing span:nth-child(3) { animation-delay: 0.4s; margin-right: 0; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.45; }
  30%            { transform: translateY(-4px); opacity: 1;    }
}

/* ══════════════════════════════════════
   ANIMACIONES
══════════════════════════════════════ */
.ia-entrance {
  animation: ia-entrance 1.5s ease 0s 1 normal forwards;
}

@keyframes ia-entrance {
  0%   { opacity: 0; transform: translateX(250px) rotate(200deg); }
  100% { opacity: 1; transform: translateX(0) rotate(0deg); }
}

/* ══════════════════════════════════════
   RESIZABLE
══════════════════════════════════════ */
.ui-resizable-handle {
  background: rgba(14, 165, 233, 0.15);
  z-index: 9999;
}

.ui-resizable-nw {
  width: 15px;
  height: 15px;
  position: absolute;
  top: 0;
  left: 0;
  cursor: nw-resize;
  border-radius: 0 0 4px 0;
}

/* ══════════════════════════════════════
   FEEDBACK ICONS
══════════════════════════════════════ */
.feedback {
  border: none;
  background-color: transparent;
  cursor: pointer;
  border-radius: 6px;
}

.feedback span {
  color: var(--ai-primary);
  opacity: 0.65;
  transition: color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
  padding: 6px;
  border-radius: 6px;
  display: inline-block;
  font-size: 18px;
}

.feedback span:hover {
  transform: scale(1.3);
  opacity: 1;
  filter: drop-shadow(0 0 5px rgba(14, 165, 233, 0.5));
}

.feedback span.clicked {
  transform: scale(1.8);
}

@keyframes popIn {
  0%   { transform: scale(0.5); opacity: 0; }
  80%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

.d-none { display: none; }

.icon-pop-in {
  animation: popIn 0.3s ease-out;
}

/* ── Badge BETA ── */
.beta {
  animation: animation_beta 2s infinite;
  font-weight: bold;
}

@keyframes animation_beta {
  0%, 100% { color: #ffffff; }
  50%       { color: var(--ai-accent-soft); }
}

/* ── Disclaimer ── */
.ia-disclaimer {
  font-size: 12px !important;
  color: var(--ai-text-muted);
  margin-top: 0 !important;
  text-align: center;
  line-height: 1.4;
}

.ia-disclaimer a {
  color: var(--ai-primary-deep);
  text-decoration: none;
}

.ia-disclaimer a:hover {
  color: var(--ai-primary);
}

/* ============================================================
   TUTORIA BUBBLE — Tooltip estilo Meta AI
   Aparece sobre .ai-chat-button, invita a abrir el chat
   ============================================================ */

/* ── Contenedor píldora oscura ── */
.ai-chat-bubble {
  position: absolute;
  bottom: calc(100% + 14px);
  right: 0;
  /* background: rgba(16, 18, 27, 0.93); */
  background: linear-gradient(135deg, #0ea5e9 0%, #0369a1 50%, #00b4d8 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  /* border: 1px solid rgba(255, 255, 255, 0.1); */
  border: none;
  border-radius: 22px;
  padding: 10px 16px 10px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  cursor: pointer;
  /* box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 20px rgba(124, 58, 237, 0.15); */
  box-shadow: 0 3px 12px rgba(14, 165, 233, 0.4);
  transform-origin: bottom right;
  z-index: 10;
  user-select: none;
  color: white;
  /* Entrada: pop elástico desde abajo */
  animation: tutoríaBubbleIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ── Flecha apuntando al botón ── */
.ai-chat-bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 20px;
  width: 14px;
  height: 14px;
  /* background: rgba(16, 18, 27, 0.93); */
  background: linear-gradient(135deg, #0ea5e9 0%, #0369a1 50%, #00b4d8 100%);
  /* border-right: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); */
  border: none;
  transform: rotate(45deg);
  border-radius: 0 0 3px 0;
}

/* ── Ícono: anillo giratorio gradiente cónico (igual al Meta AI) ── */
.ai-chat-bubble-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #7f00ff,
    #e100ff,
    #ff6b6b,
    #00c3ff,
    #0ea5e9,
    #7f00ff
  );
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  animation: tutoríaIconSpin 2.5s linear infinite;
}

/* Centro oscuro del anillo (efecto hueco) */
.ai-chat-bubble-icon::after {
  content: '';
  width: 18px;
  height: 18px;
  border-radius: 50%;
  /* background: rgba(16, 18, 27, 0.93); */
  background: #fff;
  display: block;
}

/* ── Texto del mensaje ── */
.ai-chat-bubble-text {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.01em;
}

/* ── Estado: ocultándose ── */
.ai-chat-bubble.is-hiding {
  animation: tutoríaBubbleOut 0.3s ease forwards;
}

/* ── Hover: leve brillo ── */
.ai-chat-bubble:hover {
  /* background: rgba(25, 28, 42, 0.97);
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1),
    0 0 28px rgba(124, 58, 237, 0.25); */
    box-shadow: 0 4px 20px rgba(14, 165, 233, 0.6), 0 0 30px rgba(0, 180, 216, 0.3);
}

/* ── Animaciones ── */
@keyframes tutoríaBubbleIn {
  0%   { opacity: 0; transform: scale(0.75) translateY(10px); }
  100% { opacity: 1; transform: scale(1)    translateY(0);     }
}

@keyframes tutoríaBubbleOut {
  0%   { opacity: 1; transform: scale(1)    translateY(0);     }
  100% { opacity: 0; transform: scale(0.8)  translateY(8px);   }
}

@keyframes tutoríaIconSpin {
  from { transform: rotate(0deg);   }
  to   { transform: rotate(360deg); }
}


/* ══════════════════════════════════════
   RESPONSIVE — MÓVILES
══════════════════════════════════════ */
@media (max-width: 768px), (max-height: 768px) {
  .ai-chat-window {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    transform: none !important;
    display: flex;
    flex-direction: column;
  }

  .ai-chat-button {
    width: 65px;
    height: 65px;
    bottom: 20px;
  }

  .ai-chat-header {
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
  }

  .ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    padding-bottom: 20px;
    background-color: var(--ai-bg-messages);
    background-image:
      linear-gradient(rgba(14, 165, 233, 0.09) 1px, transparent 1px),
      linear-gradient(90deg, rgba(14, 165, 233, 0.09) 1px, transparent 1px);
    background-size: 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0;
  }

  .ai-chat-composer {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    margin: 0;
    border-radius: 0;
    box-shadow: 0 -3px 16px rgba(13, 42, 82, 0.12);
    background-color: var(--ai-bg-composer);
    flex-shrink: 0;
    padding: 15px;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
  }

  .ai-chat-composer textarea {
    font-size: 16px;
    max-height: 100px;
  }

  .ai-chat-window.active {
    height: 100vh;
    height: 100dvh;
  }
}

/* ── iOS ── */
@supports (-webkit-touch-callout: none) {
  @media (max-width: 768px) {
    .ai-chat-window,
    .ai-chat-window.active {
      height: -webkit-fill-available;
    }
  }
}

.keyboard-open .ai-chat-messages {
  padding-bottom: 10px;
}

@media (max-width: 480px) {
  .ai-chat-composer {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .ai-chat-messages {
    padding: 15px;
  }
}

/* ============================================================
   SUGGESTION CHIPS — TutorIA
   Aparecen después del primer mensaje de bienvenida
   ============================================================ */

/* Contenedor principal de los chips */
.ai-chips-container {
  padding: 8px 0 14px 0;
  animation: chipsSlideIn 0.4s ease both;
}

/* Label "Sugerencias para ti:" */
.ai-chips-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--ai-primary-deep, #0284c7);
  text-transform: uppercase;
  margin: 0 0 8px 4px;
  opacity: 0.75;
}

/* Fila de chips con scroll horizontal en móvil */
.ai-chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 2px;
}

/* Cada chip individual */
.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px 7px 10px;
  background: var(--ai-bg-card, #ffffff);
  border: 1.5px solid var(--ai-accent-soft, #38bdf8);
  border-radius: 20px;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ai-primary-deep, #0284c7);
  transition: all 0.2s ease;
  box-shadow: 0 1px 4px rgba(14, 165, 233, 0.10);
  white-space: nowrap;
  text-align: left;
  line-height: 1.3;
}

.ai-chip:hover {
  background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
  border-color: var(--ai-primary, #0ea5e9);
  color: var(--ai-primary-deep, #0284c7);
  box-shadow: 0 3px 10px rgba(14, 165, 233, 0.22);
  transform: translateY(-1px);
}

.ai-chip:active {
  transform: translateY(0px) scale(0.97);
  box-shadow: 0 1px 4px rgba(14, 165, 233, 0.15);
}

.ai-chip-emoji {
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
}

.ai-chip-text {
  flex: 1;
}

/* Animación de entrada de los chips */
@keyframes chipsSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Animación de salida (ocultar chips) */
.ai-chips-container.chips-hiding {
  animation: chipsSlideOut 0.25s ease forwards;
  pointer-events: none;
}

@keyframes chipsSlideOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* Responsive: scroll horizontal en pantallas muy pequeñas */
@media (max-width: 420px) {
  .ai-chips-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ai-chips-list::-webkit-scrollbar {
    display: none;
  }
  .ai-chip {
    flex-shrink: 0;
    font-size: 12px;
    padding: 6px 12px 6px 9px;
  }
}