/* ═══════════════════════════════════════════════════════════════════════ */
/* ASISTENTE IA — Estilos                                                  */
/* ═══════════════════════════════════════════════════════════════════════ */

.ai-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,37,64,.7);
  backdrop-filter: blur(4px);
  z-index: 9000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.ai-modal-overlay.show {
  display: flex;
  animation: aiFadeIn .2s ease;
}
@keyframes aiFadeIn { from{opacity:0} to{opacity:1} }

.ai-modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
  animation: aiSlideUp .3s ease;
}
.ai-modal.ai-modal-compact { max-width: 540px; }
@keyframes aiSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.ai-modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid #e8edf2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #f8fafc, #fff);
}
.ai-modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #0A2540;
  font-family: 'Sora', sans-serif;
}
.ai-modal-close {
  background: rgba(0,0,0,.06);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.ai-modal-close:hover { background: rgba(0,0,0,.12); }

.ai-modal-tabs {
  display: flex;
  gap: 0;
  padding: 0 22px;
  border-bottom: 1px solid #e8edf2;
  background: #f8fafc;
}
.ai-tab {
  background: transparent;
  border: none;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .2s;
  font-family: inherit;
}
.ai-tab:hover { color: #0A2540; }
.ai-tab.on {
  color: #F5923A;
  border-bottom-color: #F5923A;
}

.ai-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
}

/* ═══ LOADING ═══ */
.ai-loading {
  text-align: center;
  padding: 60px 20px;
  color: #64748b;
}
.ai-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e8edf2;
  border-top-color: #F5923A;
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: aiSpin .8s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

.ai-error {
  text-align: center;
  padding: 40px 20px;
}
.ai-error h4 {
  font-size: 16px;
  color: #ef4444;
  margin: 0 0 8px;
}

/* ═══ SECCIONES ═══ */
.ai-section {
  background: linear-gradient(135deg, #fef9e7, #fff4ec);
  border-left: 3px solid #F5923A;
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.ai-section.ai-analisis p {
  margin: 4px 0 0;
  font-size: 14px;
  color: #475569;
}
.ai-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #64748b;
  text-transform: uppercase;
}

.ai-oportunidades {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
}
.ai-oportunidades li {
  padding: 4px 0;
  font-size: 13px;
  color: #475569;
}

.ai-tag-intencion {
  display: inline-block;
  background: #dbeafe;
  color: #1e40af;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 30px;
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ═══ BORRADORES ═══ */
.ai-borrador {
  background: #fff;
  border: 1.5px solid #e8edf2;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  transition: all .2s;
}
.ai-borrador:hover {
  border-color: #F5923A;
  box-shadow: 0 4px 14px rgba(245,146,58,.08);
}
.ai-borrador-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.ai-borrador-tag {
  background: #fff4ec;
  color: #e07e28;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 30px;
  letter-spacing: 0.3px;
}
.ai-borrador-asunto {
  font-size: 13px;
  color: #475569;
  background: #f1f5f9;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
}
.ai-borrador-text {
  width: 100%;
  border: 1px solid #e8edf2;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  font-family: inherit;
  color: #0A2540;
  resize: vertical;
  background: #fafbfc;
  transition: all .2s;
}
.ai-borrador-text:focus {
  outline: none;
  border-color: #F5923A;
  background: #fff;
}
.ai-borrador-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  justify-content: flex-end;
}

.ai-regenerar {
  text-align: center;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #e8edf2;
}

/* ═══ BOTONES ═══ */
.ai-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all .2s;
}
.ai-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-btn-primary { background: #0A2540; color: #fff; }
.ai-btn-primary:hover { background: #1a3a5c; }
.ai-btn-success { background: #25D366; color: #fff; }
.ai-btn-success:hover { background: #1faa50; }
.ai-btn-ghost { background: #f1f5f9; color: #475569; }
.ai-btn-ghost:hover { background: #e8edf2; }
.ai-btn-small { padding: 5px 10px; font-size: 11px; }

/* ═══ CHAT LIBRE ═══ */
.ai-chat-container {
  display: flex;
  flex-direction: column;
  height: 540px;
}
.ai-chat-context {
  background: #f1f5f9;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 12px;
}
.ai-chat-context p {
  margin: 4px 0 0;
  color: #475569;
}
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 4px 4px 12px;
  border: 1px solid #e8edf2;
  border-radius: 10px;
  background: #fafbfc;
}
.ai-chat-msg {
  margin: 10px 14px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
}
.ai-chat-msg strong {
  display: block;
  font-size: 11px;
  margin-bottom: 4px;
  color: #64748b;
  letter-spacing: 0.5px;
  font-weight: 700;
}
.ai-chat-msg p { margin: 0; }
.ai-chat-bot {
  background: #fff;
  border: 1px solid #e8edf2;
}
.ai-chat-bot-text {
  white-space: pre-wrap;
}
.ai-chat-user {
  background: #dbeafe;
  border: 1px solid #93c5fd;
  margin-left: 40px;
}
.ai-chat-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.ai-chat-input {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: flex-end;
}
.ai-chat-input textarea {
  flex: 1;
  border: 1.5px solid #e8edf2;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  min-height: 50px;
}
.ai-chat-input textarea:focus { border-color: #F5923A; }

/* ═══ BOTÓN ASISTENTE (donde se inyecta en CRM/Inbox) ═══ */
.ai-trigger-btn {
  background: linear-gradient(135deg, #F5923A, #e07e28);
  color: #fff;
  border: none;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all .2s;
  box-shadow: 0 2px 8px rgba(245,146,58,.3);
}
.ai-trigger-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(245,146,58,.4);
}

/* Mobile */
@media (max-width: 640px) {
  .ai-modal { max-height: 95vh; border-radius: 12px; }
  .ai-modal-header { padding: 14px 16px; }
  .ai-modal-body { padding: 16px; }
  .ai-borrador-actions { flex-wrap: wrap; }
  .ai-chat-msg { margin: 8px 10px; }
  .ai-chat-user { margin-left: 20px; }
}
