/* ═══════════════════════════════════════════════════════════════════
   aiChat.css — Estilos del Asistente IA Nutricional
   Integrar en diagnosticos/css/styles.css o importar globalmente
   ═══════════════════════════════════════════════════════════════════ */

/* ── Variables ────────────────────────────────────────────────────── */
:root {
  --ai-color:        #0f9d6d;
  --ai-color-light:  #e8f8f2;
  --ai-color-dark:   #0a7a56;
  --ai-user-bg:      #eff6ff;
  --ai-user-color:   #1e40af;
  --ai-msg-radius:   14px;
  --ai-shadow:       0 4px 24px rgba(15,157,109,.12);
}

/* ── Panel principal ──────────────────────────────────────────────── */
.ni-ai-chat {
  display: flex;
  flex-direction: column;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--ai-shadow);
  margin-top: 1.5rem;
  font-family: inherit;
}

/* ── Header ───────────────────────────────────────────────────────── */
.ni-ai-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
  background: linear-gradient(135deg, var(--ai-color-dark) 0%, var(--ai-color) 100%);
  color: #fff;
}

.ni-ai-chat__header-left {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.ni-ai-chat__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.ni-ai-chat__title {
  font-weight: 800;
  font-size: .95rem;
  letter-spacing: -.01em;
}

.ni-ai-chat__subtitle {
  font-size: .75rem;
  opacity: .8;
  margin-top: .1rem;
}

.ni-ai-chat__clear {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .875rem;
  transition: background .2s;
  flex-shrink: 0;
}

.ni-ai-chat__clear:hover { background: rgba(255,255,255,.3); }

/* ── Badge de contexto clínico ────────────────────────────────────── */
.ni-ai-chat__context-badge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .375rem .75rem;
  padding: .625rem 1.25rem;
  background: var(--ai-color-light);
  border-bottom: 1px solid #c8edd8;
  font-size: .8rem;
  color: #1e5740;
}

.ni-ai-chat__context-badge i {
  color: var(--ai-color);
}

.ni-ai-chat__context-sep {
  color: #94a3b8;
}

/* ── Prompts rápidos ──────────────────────────────────────────────── */
.ni-ai-chat__quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid #f1f5f9;
  background: #fafcff;
}

.ni-ai-chat__quick-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .75rem;
  border: 1px solid #cbd5e1;
  border-radius: 99px;
  background: #fff;
  color: #475569;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s, background .2s, color .2s, transform .15s;
  white-space: nowrap;
}

.ni-ai-chat__quick-btn:hover {
  border-color: var(--ai-color);
  background: var(--ai-color-light);
  color: var(--ai-color-dark);
  transform: translateY(-1px);
}

.ni-ai-chat__quick-btn i { font-size: .8rem; }

/* ── Área de mensajes ─────────────────────────────────────────────── */
.ni-ai-chat__messages {
  flex: 1;
  min-height: 320px;
  max-height: 480px;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #f8fafc;
  scroll-behavior: smooth;
}

/* scrollbar sutil */
.ni-ai-chat__messages::-webkit-scrollbar { width: 5px; }
.ni-ai-chat__messages::-webkit-scrollbar-track { background: transparent; }
.ni-ai-chat__messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

/* Mensaje de bienvenida */
.ni-ai-chat__welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: .75rem;
  padding: 2rem 1.5rem;
  color: #64748b;
  font-size: .9rem;
  line-height: 1.6;
}

.ni-ai-chat__welcome i {
  font-size: 2.5rem;
  color: var(--ai-color);
  opacity: .6;
}

/* ── Burbujas de mensaje ──────────────────────────────────────────── */
.ni-ai-chat__msg {
  display: flex;
  align-items: flex-end;
  gap: .625rem;
  max-width: 88%;
  animation: msgIn .25s ease-out;
}

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

/* Mensajes del asistente — izquierda */
.ni-ai-chat__msg--assistant {
  align-self: flex-start;
}

/* Mensajes del usuario — derecha */
.ni-ai-chat__msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* Errores */
.ni-ai-chat__msg--error {
  align-self: center;
  max-width: 100%;
}

.ni-ai-chat__msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ai-color-light);
  color: var(--ai-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.ni-ai-chat__msg--user .ni-ai-chat__msg-avatar {
  background: var(--ai-user-bg);
  color: var(--ai-user-color);
}

.ni-ai-chat__msg-bubble {
  padding: .75rem 1rem;
  border-radius: var(--ai-msg-radius);
  font-size: .875rem;
  line-height: 1.65;
  color: #1e293b;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  word-break: break-word;
}

/* Burbuja asistente */
.ni-ai-chat__msg--assistant .ni-ai-chat__msg-bubble {
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--ai-color);
}

/* Burbuja usuario */
.ni-ai-chat__msg--user .ni-ai-chat__msg-bubble {
  background: var(--ai-user-bg);
  color: var(--ai-user-color);
  border-bottom-right-radius: 4px;
}

/* Burbuja error */
.ni-ai-chat__msg-bubble--error {
  background: #fff1f2;
  color: #be123c;
  border-left: 3px solid #f43f5e;
  width: 100%;
}

/* Markdown renderizado */
.ni-ai-chat__msg-bubble h4 {
  font-size: .9rem;
  font-weight: 700;
  margin: .75rem 0 .3rem;
  color: var(--ai-color-dark);
}

.ni-ai-chat__msg-bubble h5 {
  font-size: .85rem;
  font-weight: 700;
  margin: .6rem 0 .2rem;
  color: #475569;
}

.ni-ai-chat__msg-bubble ul {
  padding-left: 1.2rem;
  margin: .4rem 0;
}

.ni-ai-chat__msg-bubble li {
  margin-bottom: .2rem;
}

.ni-ai-chat__msg-bubble strong { color: #0f172a; }

/* ── Indicador de "pensando" ──────────────────────────────────────── */
.ni-ai-chat__dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai-color);
  margin: 0 2px;
  animation: dotBounce 1.4s infinite ease-in-out;
}

.ni-ai-chat__dot:nth-child(2) { animation-delay: .2s; }
.ni-ai-chat__dot:nth-child(3) { animation-delay: .4s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .5; }
  40%           { transform: scale(1);  opacity: 1;   }
}

/* ── Input area ───────────────────────────────────────────────────── */
.ni-ai-chat__input-area {
  padding: .875rem 1.25rem;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.ni-ai-chat__input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: .625rem .875rem;
  font-size: .875rem;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  color: #1e293b;
  background: #f8fafc;
  line-height: 1.5;
  box-sizing: border-box;
}

.ni-ai-chat__input:focus {
  border-color: var(--ai-color);
  box-shadow: 0 0 0 3px rgba(15,157,109,.15);
  background: #fff;
}

.ni-ai-chat__input::placeholder { color: #94a3b8; }

.ni-ai-chat__input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ni-ai-chat__char-count {
  font-size: .75rem;
  color: #94a3b8;
}

.ni-ai-chat__send {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.125rem;
  background: var(--ai-color);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s, transform .15s, box-shadow .2s;
}

.ni-ai-chat__send:hover:not(:disabled) {
  background: var(--ai-color-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15,157,109,.3);
}

.ni-ai-chat__send:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* ── Disclaimer ───────────────────────────────────────────────────── */
.ni-ai-chat__disclaimer {
  padding: .5rem 1.25rem;
  background: #fffbeb;
  border-top: 1px solid #fef08a;
  font-size: .75rem;
  color: #92400e;
  display: flex;
  align-items: center;
  gap: .4rem;
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .ni-ai-chat__quick-prompts { gap: .25rem; }
  .ni-ai-chat__quick-btn span { display: none; }
  .ni-ai-chat__quick-btn { padding: .4rem .6rem; }
  .ni-ai-chat__msg { max-width: 95%; }
  .ni-ai-chat__messages { min-height: 260px; max-height: 360px; }
}

/* ── Print: ocultar el chat ───────────────────────────────────────── */
@media print {
  .ni-ai-chat { display: none !important; }
}
