/* ==============================================================================
   SIMPLIFICA CHINA - WIDGET DE CHAT INTELIGENTE (ERIC MORENO ESPIGA)
   Estilos CSS con Soporte Completo para Modo Oscuro y Modo Claro
   ============================================================================== */

/* 1. Botón Flotante Disparador (Launcher) */
.sc-chat-launcher {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 990;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: var(--bg-card, #111a2e);
  border: 2px solid var(--accent-primary, #ff6b35);
  box-shadow: 0 8px 24px rgba(255, 107, 53, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  outline: none;
}

.sc-chat-launcher:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 30px rgba(255, 107, 53, 0.5);
}

.sc-launcher-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.sc-launcher-status {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  background: #10b981;
  border: 2px solid var(--bg-card, #111a2e);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
  animation: scPulseGreen 2s infinite;
}

@keyframes scPulseGreen {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Tooltip / Globo de Diálogo de Invitación (Ubicado a la izquierda) */
.sc-launcher-tooltip {
  position: absolute;
  top: 50%;
  right: calc(100% + 16px);
  transform: translateY(-50%);
  background: var(--bg-card, #111a2e);
  color: var(--text-primary, #ffffff);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
  padding: 0.65rem 1.15rem;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  opacity: 1;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sc-launcher-tooltip::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent transparent var(--border-color, rgba(255, 255, 255, 0.15));
}

.sc-launcher-tooltip.hidden {
  opacity: 0;
  transform: translateY(-50%) translateX(10px);
  pointer-events: none;
}

/* Ocultar tooltip automáticamente si la ventana está abierta */
body:has(.sc-chat-window.open) .sc-launcher-tooltip {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* 2. Ventana del Chat */
.sc-chat-window {
  position: fixed;
  bottom: 6.8rem;
  right: 2rem;
  z-index: 995;
  width: 390px;
  max-width: calc(100vw - 2.5rem);
  height: 580px;
  max-height: calc(100vh - 8.5rem);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.92) translateY(20px);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sc-chat-window.open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* 3. Cabecera del Chat */
.sc-chat-header {
  padding: 1rem 1.15rem;
  background: rgba(30, 41, 59, 0.7);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sc-header-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.sc-header-avatar-wrap {
  position: relative;
  width: 2.75rem;
  height: 2.75rem;
  min-width: 2.75rem;
  flex-shrink: 0 !important;
}

.sc-header-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 1.5px solid var(--accent-primary, #ff6b35);
  background: #1e293b;
}

.sc-header-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  background: #10b981;
  border: 2px solid #1e293b;
  border-radius: 50%;
}

.sc-header-meta {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.sc-header-meta h4 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sc-header-sub {
  font-size: 0.74rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.15rem;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sc-header-role {
  color: var(--accent-primary, #ff6b35);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 155px;
  display: inline-block;
  vertical-align: bottom;
}

.sc-header-sep {
  color: rgba(255, 255, 255, 0.25);
  font-size: 0.65rem;
}

.sc-status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #cbd5e1;
  font-weight: 500;
}

.sc-status-green-dot {
  width: 7.5px;
  height: 7.5px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.75);
  animation: scPulseGreen 2.2s infinite ease-in-out;
  display: inline-block;
  flex-shrink: 0;
}

@keyframes scPulseGreen {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    transform: scale(1.05);
    box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.sc-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sc-btn-icon {
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 0.4rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.sc-btn-icon:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

/* 4. Cuerpo de Mensajes */
.sc-chat-messages {
  flex: 1;
  padding: 1.15rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  scroll-behavior: smooth;
}

.sc-chat-messages::-webkit-scrollbar {
  width: 5px;
}
.sc-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* Burbujas de Mensaje */
.sc-msg {
  max-width: 84%;
  font-size: 0.9rem;
  line-height: 1.48;
  padding: 0.75rem 0.95rem;
  word-break: break-word;
  animation: scFadeIn 0.25s ease-out forwards;
}

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

/* Mensajes de Eric */
.sc-msg-eric {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px 16px 16px 4px;
}

.sc-msg-eric p {
  margin: 0 0 0.5rem;
}
.sc-msg-eric p:last-child {
  margin-bottom: 0;
}

/* Mensajes del Usuario */
.sc-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #ff6b35, #e0531c);
  color: #ffffff;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 4px 14px rgba(255, 107, 53, 0.3);
}

/* Tarjeta de Acción Setter Integrada */
.sc-action-card {
  margin-top: 0.65rem;
  padding: 0.65rem 0.8rem;
  background: rgba(255, 107, 53, 0.12);
  border: 1px solid rgba(255, 107, 53, 0.35);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sc-action-card span {
  font-size: 0.8rem;
  font-weight: 600;
  color: #ffaa80;
}

.sc-action-btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sc-btn-action {
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: transform 0.2s, background 0.2s;
  border: none;
}

.sc-btn-action-primary {
  background: var(--accent-primary, #ff6b35);
  color: #ffffff;
}

.sc-btn-action-primary:hover {
  background: #ff7d4d;
  transform: translateY(-1px);
}

.sc-btn-action-wa {
  background: #25d366;
  color: #ffffff;
}

.sc-btn-action-wa:hover {
  background: #22bf5b;
  transform: translateY(-1px);
}

/* 5. Chips de Sugerencias Rápidas */
.sc-chips-container {
  padding: 0.5rem 1.15rem 0.65rem;
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  white-space: nowrap;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sc-chips-container::-webkit-scrollbar {
  display: none;
}

.sc-chip {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  padding: 0.38rem 0.75rem;
  border-radius: 20px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.sc-chip:hover {
  background: rgba(255, 107, 53, 0.18);
  border-color: rgba(255, 107, 53, 0.4);
  color: #ffffff;
  transform: translateY(-1px);
}

/* 6. Indicador de Escritura */
.sc-typing {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  padding: 0.65rem 0.95rem;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.sc-typing-dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: scTyping 1.4s infinite ease-in-out;
}

.sc-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.sc-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* 7. Barra de Entrada y Envío */
.sc-chat-input-area {
  padding: 0.85rem 1.15rem;
  background: rgba(30, 41, 59, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sc-input-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: 0.35rem 0.5rem 0.35rem 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.sc-input-form:focus-within {
  border-color: var(--accent-primary, #ff6b35);
  box-shadow: 0 0 12px rgba(255, 107, 53, 0.25);
}

.sc-input-field {
  flex: 1;
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 0.9rem;
  outline: none;
}

.sc-input-field::placeholder {
  color: #64748b;
}

.sc-btn-send {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--accent-primary, #ff6b35);
  border: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  flex-shrink: 0;
}

.sc-btn-send:hover:not(:disabled) {
  background: #ff7d4d;
  transform: scale(1.05);
}

.sc-btn-send:disabled {
  background: #475569;
  cursor: not-allowed;
  opacity: 0.5;
}

.sc-input-footnote {
  text-align: center;
  font-size: 0.68rem;
  color: #64748b;
  margin-top: 0.45rem;
}

/* ==============================================================================
   ADAPTACIONES MODO CLARO (.theme-light)
   ============================================================================== */
.theme-light .sc-chat-launcher {
  background: #ffffff;
  border-color: var(--accent-primary, #ff6b35);
  box-shadow: 0 8px 24px rgba(255, 107, 53, 0.25);
}

.theme-light .sc-launcher-tooltip {
  background: #ffffff;
  color: #0f172a;
  border-color: #e2e8f0;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}

.theme-light .sc-launcher-tooltip::after {
  border-color: transparent transparent transparent #e2e8f0;
}

.theme-light .sc-chat-window {
  background: rgba(255, 255, 255, 0.97);
  border-color: #e2e8f0;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
}

.theme-light .sc-chat-header {
  background: #f8fafc;
  border-bottom-color: #e2e8f0;
}

.theme-light .sc-header-meta h4 {
  color: #0f172a;
}

.theme-light .sc-header-sub {
  color: #64748b;
}

.theme-light .sc-header-sep {
  color: #cbd5e1;
}

.theme-light .sc-status-indicator {
  color: #059669;
  font-weight: 600;
}

.theme-light .sc-btn-icon {
  color: #64748b;
}

.theme-light .sc-btn-icon:hover {
  color: #0f172a;
  background: #f1f5f9;
}

.theme-light .sc-msg-eric {
  background: #f1f5f9;
  color: #1e293b;
  border-color: #e2e8f0;
}

.theme-light .sc-chips-container {
  border-top-color: #f1f5f9;
}

.theme-light .sc-chip {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #475569;
}

.theme-light .sc-chip:hover {
  background: rgba(255, 107, 53, 0.1);
  color: var(--accent-primary, #ff6b35);
  border-color: rgba(255, 107, 53, 0.3);
}

.theme-light .sc-typing {
  background: #f1f5f9;
}

.theme-light .sc-chat-input-area {
  background: #f8fafc;
  border-top-color: #e2e8f0;
}

.theme-light .sc-input-form {
  background: #ffffff;
  border-color: #cbd5e1;
}

.theme-light .sc-input-field {
  color: #0f172a;
}

.theme-light .sc-input-field::placeholder {
  color: #94a3b8;
}

/* ==============================================================================
   RESPONSIVE (MÓVIL Y TABLET)
   ============================================================================== */
@media (max-width: 768px) {
  .sc-chat-window {
    right: 0.85rem;
    bottom: 5.25rem;
    width: calc(100vw - 1.7rem);
    max-width: 440px;
    height: calc(100vh - 6.5rem);
    max-height: 640px;
    border-radius: 18px;
  }
  .sc-chat-launcher {
    bottom: 1.15rem;
    right: 1.15rem;
    width: 3.6rem;
    height: 3.6rem;
  }
  .sc-launcher-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
  }
  .sc-launcher-tooltip {
    display: none !important;
  }
  .sc-header-profile {
    gap: 0.6rem;
  }
  .sc-header-avatar-wrap {
    width: 2.5rem;
    height: 2.5rem;
    min-width: 2.5rem;
  }
  .sc-header-role {
    max-width: 115px;
  }
}
