/* =============================================================
   SoulGeit — Chat Widget IA Styles v2.1
   Diseño premium consistente con la marca
   Incluye: código, offline, contador, limpiar conversación
   ============================================================= */

/* ---------- Botón flotante ---------- */
.sg-chat-toggle {
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #0b1324;
  color: #fff;
  border: 1px solid rgba(94, 226, 255, 0.5);
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(14, 165, 233, 0.4);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  animation: sg-bounce-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes sg-bounce-in {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.sg-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px rgba(14, 165, 233, 0.55);
}

.sg-chat-toggle:active {
  transform: scale(0.95);
}

.sg-chat-toggle svg {
  width: 24px;
  height: 24px;
}

/* Logo SoulGeit en el botón flotante */
.sg-chat-toggle .sg-chat-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 72px;
  height: 72px;
  object-fit: contain;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.sg-chat-close-icon {
  display: none;
}

.sg-chat-toggle.active .sg-chat-icon {
  display: none;
}

.sg-chat-toggle.active .sg-chat-close-icon {
  display: block;
  position: relative;
  z-index: 1;
}

.sg-chat-toggle.active {
  background: linear-gradient(135deg, #0ea5e9, #ec4899);
  border-color: rgba(255, 255, 255, 0.28);
}

/* ---------- Notificación de pulso ---------- */
.sg-chat-toggle::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(14, 165, 233, 0.3);
  animation: sg-pulse 2s ease-in-out infinite;
}

@keyframes sg-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0; }
}

.sg-chat-toggle.active::after {
  display: none;
}

/* ---------- Ventana de chat ---------- */
.sg-chat-window {
  position: fixed;
  bottom: 155px;
  right: 24px;
  z-index: 9998;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 540px;
  max-height: calc(100vh - 200px);
  background: #0b1526;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(14, 165, 233, 0.15);
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease, visibility 0.3s ease;
  transform-origin: bottom right;
}

.sg-chat-window.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
}

/* ---------- Header ---------- */
.sg-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, #0b1526, #101c30);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.sg-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sg-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #0b1324;
  border: 1px solid rgba(94, 226, 255, 0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.sg-chat-avatar svg {
  width: 20px;
  height: 20px;
}

/* Logo SoulGeit en el avatar de la cabecera del chat */
.sg-chat-avatar-logo {
  width: 54px;
  height: 54px;
  max-width: none;
  object-fit: contain;
  flex: 0 0 auto;
}

.sg-chat-header-title {
  font-family: 'Oxanium', 'Orbitron', system-ui, -apple-system, sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  letter-spacing: -0.02em;
}

.sg-chat-header-status {
  font-size: 0.72rem;
  color: #10b981;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: color 0.3s ease;
}

/* ---------- Header actions (clear + minimize) ---------- */
.sg-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sg-chat-clear {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #8b98ad;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.sg-chat-clear:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.2);
}

.sg-chat-minimize {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #8b98ad;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.sg-chat-minimize:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sg-chat-clear svg,
.sg-chat-minimize svg {
  width: 16px;
  height: 16px;
}

/* ---------- Mensajes ---------- */
.sg-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(14, 165, 233, 0.3) transparent;
  position: relative;
}

.sg-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.sg-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.sg-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(14, 165, 233, 0.3);
  border-radius: 10px;
}

/* ---------- Offline banner ---------- */
.sg-offline-banner {
  display: none;
  padding: 10px 16px;
  margin: 0 16px 8px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 10px;
  color: #fca5a5;
  font-size: 0.78rem;
  text-align: center;
  animation: sg-fade-in 0.3s ease;
}

.sg-offline-banner.active {
  display: block;
}

/* ---------- Burbujas de mensaje ---------- */
.sg-chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: sg-fade-in 0.3s ease;
}

@keyframes sg-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.sg-chat-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.sg-chat-msg-ai {
  align-self: flex-start;
}

.sg-chat-msg-error {
  align-self: center;
  max-width: 90%;
}

.sg-chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #0b1324;
  border: 1px solid rgba(94, 226, 255, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -0.02em;
  overflow: hidden;
}

.sg-chat-msg-avatar-logo {
  width: 44px;
  height: 44px;
  max-width: none;
  object-fit: contain;
  flex: 0 0 auto;
}

.sg-chat-msg-content {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.55;
  letter-spacing: -0.01em;
  color: #e6edf6;
}

.sg-chat-msg-ai .sg-chat-msg-content {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-top-left-radius: 4px;
}

.sg-chat-msg-user .sg-chat-msg-content {
  background: linear-gradient(135deg, #0ea5e9, #ec4899);
  border-top-right-radius: 4px;
  color: #fff;
}

.sg-chat-msg-error .sg-chat-msg-content {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  font-size: 0.82rem;
  text-align: center;
  padding: 8px 14px;
}

.sg-chat-msg-content p {
  margin: 0;
  line-height: inherit;
}

.sg-chat-msg-content p + p {
  margin-top: 8px;
}

.sg-chat-msg-content strong {
  color: inherit;
  font-weight: 600;
}

.sg-chat-msg-time {
  font-size: 0.65rem !important;
  color: rgba(255, 255, 255, 0.35) !important;
  margin-top: 4px !important;
  letter-spacing: 0.02em;
}

.sg-chat-msg-user .sg-chat-msg-time {
  color: rgba(255, 255, 255, 0.5) !important;
  text-align: right;
}

/* ============================================================
   BLOQUES DE CÓDIGO
   ============================================================ */
.sg-code-block {
  background: #050a14;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  margin: 10px 0;
  overflow: hidden;
  position: relative;
}

.sg-code-lang {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  color: #7c8aa0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.sg-code-copy {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.65rem;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #8b98ad;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s ease, color 0.2s ease;
  z-index: 1;
}

.sg-code-copy:hover {
  background: rgba(14, 165, 233, 0.15);
  color: #0ea5e9;
  border-color: rgba(14, 165, 233, 0.3);
}

.sg-code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.sg-code-block code {
  font-family: 'Share Tech Mono', 'Consolas', monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  color: #c9d1d9;
  white-space: pre;
  word-break: normal;
  word-wrap: normal;
}

/* Syntax highlighting básico */
.sg-code-block code .keyword { color: #ff79c6; }
.sg-code-block code .string { color: #50fa7b; }
.sg-code-block code .function { color: #22d3ee; }
.sg-code-block code .comment { color: #6272a4; font-style: italic; }
.sg-code-block code .number { color: #a78bfa; }
.sg-code-block code .operator { color: #ff79c6; }

/* ---------- Botón "Ir abajo" ---------- */
.sg-scroll-bottom {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8b98ad;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  animation: sg-fade-in 0.3s ease;
  transition: background 0.2s ease, color 0.2s ease;
}

.sg-scroll-bottom:hover {
  background: rgba(14, 165, 233, 0.15);
  color: #0ea5e9;
  border-color: rgba(14, 165, 233, 0.2);
}

.sg-scroll-bottom svg {
  width: 18px;
  height: 18px;
}

/* ---------- Sugerencias rápidas ---------- */
.sg-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  animation: sg-fade-in 0.5s ease 0.5s both;
}

.sg-chat-suggestion {
  padding: 6px 14px;
  font-size: 0.75rem;
  font-weight: 500;
  color: #8b98ad;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.sg-chat-suggestion:hover {
  background: rgba(14, 165, 233, 0.1);
  border-color: rgba(14, 165, 233, 0.3);
  color: #0ea5e9;
}

/* ---------- Typing indicator ---------- */
.sg-chat-typing {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 20px 8px;
}

.sg-chat-typing.active {
  display: flex;
  animation: sg-fade-in 0.3s ease;
}

.sg-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0ea5e9;
  animation: sg-dot-bounce 1.4s ease-in-out infinite;
}

.sg-dot:nth-child(2) { animation-delay: 0.2s; }
.sg-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes sg-dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.sg-typing-text {
  font-size: 0.7rem;
  color: #7c8aa0;
  margin-left: 4px;
}

/* ---------- Input area ---------- */
.sg-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: #0b1526;
  flex-shrink: 0;
}

.sg-chat-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.sg-chat-input {
  width: 100%;
  padding: 10px 14px;
  padding-right: 44px; /* espacio para el contador */
  font-size: 0.88rem;
  font-family: 'Rajdhani', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  color: #e6edf6;
  outline: none;
  transition: border-color 0.2s ease;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  box-sizing: border-box;
}

.sg-chat-input::placeholder {
  color: #7c8aa0;
}

.sg-chat-input:focus {
  border-color: rgba(14, 165, 233, 0.4);
}

/* ---------- Contador de caracteres ---------- */
.sg-chat-counter {
  position: absolute;
  right: 10px;
  bottom: 8px;
  font-size: 0.62rem;
  font-weight: 600;
  color: #7c8aa0;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease;
}

.sg-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #0ea5e9, #ec4899);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.sg-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.35);
}

.sg-chat-send:active:not(:disabled) {
  transform: scale(0.95);
}

.sg-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sg-chat-send svg {
  width: 18px;
  height: 18px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .sg-chat-window {
    right: 12px;
    bottom: 155px;
    width: calc(100vw - 24px);
    height: calc(100vh - 180px);
    max-height: calc(100vh - 180px);
    border-radius: 16px;
  }

  .sg-chat-toggle {
    right: 16px;
    bottom: 80px;
    width: 50px;
    height: 50px;
  }

  .sg-chat-header {
    padding: 14px 16px;
  }

  .sg-chat-messages {
    padding: 12px 12px 4px;
  }

  .sg-chat-input-area {
    padding: 10px 12px 14px;
  }

  .sg-code-block pre {
    padding: 10px 12px;
  }

  .sg-code-block code {
    font-size: 0.72rem;
  }
}

/* ---------- Ajuste para el botón de WhatsApp existente ---------- */
@media (min-width: 481px) {
  .sg-chat-toggle {
    bottom: 90px;
  }
}

/* ============================================================
   COMPONENTES COMPLEMENTARIOS (paleta SoulGeit)
   ============================================================ */

/* ---------- Badge de mensajes no leídos ---------- */
.sg-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 100px;
  background: linear-gradient(135deg, #ec4899, #0ea5e9);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(236, 72, 153, 0.45);
}
.sg-chat-badge.visible { display: flex; }

/* ---------- Botón de entrada por voz ---------- */
.sg-chat-voice {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #8b98ad;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.sg-chat-voice:hover {
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(14, 165, 233, 0.3);
  color: #22d3ee;
}
.sg-chat-voice:disabled { opacity: 0.5; cursor: not-allowed; }
.sg-chat-voice svg { width: 18px; height: 18px; }
.sg-chat-voice.sg-voice-active {
  background: rgba(236, 72, 153, 0.14);
  border-color: rgba(236, 72, 153, 0.45);
  color: #f472b6;
  animation: sg-voice-pulse 1.2s ease-in-out infinite;
}
@keyframes sg-voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(236, 72, 153, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(236, 72, 153, 0); }
}

/* ---------- Botones de feedback (👍 / 👎) ---------- */
.sg-chat-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  padding-left: 40px;
}
.sg-feedback-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #8b98ad;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}
.sg-feedback-btn:hover {
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(14, 165, 233, 0.3);
  transform: translateY(-1px);
}
.sg-feedback-btn.sg-feedback-active {
  background: rgba(14, 165, 233, 0.18);
  border-color: rgba(14, 165, 233, 0.5);
  color: #22d3ee;
}

/* ---------- Botón exportar conversación ---------- */
.sg-chat-export-btn {
  margin: 8px auto 4px;
  padding: 6px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #8b98ad;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 100px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}
.sg-chat-export-btn:hover {
  background: rgba(236, 72, 153, 0.12);
  border-color: rgba(236, 72, 153, 0.35);
  color: #f472b6;
}

/* ---------- Toast de confirmación (reiniciar chat) ---------- */
.sg-confirm-toast {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 5, 11, 0.65);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sg-confirm-toast.visible { opacity: 1; }
.sg-confirm-toast-content {
  width: 300px;
  max-width: calc(100vw - 48px);
  padding: 20px;
  border-radius: 16px;
  background: #0b1526;
  border: 1px solid rgba(14, 165, 233, 0.25);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.6);
  transform: translateY(10px) scale(0.97);
  transition: transform 0.25s ease;
}
.sg-confirm-toast.visible .sg-confirm-toast-content { transform: none; }
.sg-confirm-toast-content p {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: #e6edf6;
  text-align: center;
}
.sg-confirm-toast-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.sg-confirm-btn {
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}
.sg-confirm-yes {
  background: linear-gradient(135deg, #ec4899, #0ea5e9);
  color: #fff;
  border: none;
}
.sg-confirm-yes:hover { box-shadow: 0 6px 20px rgba(236, 72, 153, 0.4); }
.sg-confirm-no {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8b98ad;
}
.sg-confirm-no:hover { background: rgba(255, 255, 255, 0.1); color: #e6edf6; }
