/* =========================================================================
 * ai.css — Asistente de IA flotante (shared/js/ai-assistant.js).
 * Se carga en todas las páginas del repositorio.
 * ========================================================================= */

.ai-root {
  --ai-accent: #6366f1;
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  font-family: var(--font-ui, "Segoe UI", system-ui, sans-serif);
}

/* ------------------------------ botón -------------------------------- */
.ai-fab {
  width: 54px; height: 54px;
  border: 0; border-radius: 50%;
  background: linear-gradient(140deg, #7c6cf7, #6366f1 60%, #8b5cf6);
  color: #fff; cursor: pointer;
  box-shadow: 0 10px 26px rgba(99, 102, 241, .42);
  display: flex; align-items: center; justify-content: center;
  transition: transform .22s cubic-bezier(.34, 1.56, .64, 1), box-shadow .22s;
}
.ai-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 32px rgba(99, 102, 241, .5); }
.ai-fab.on { transform: scale(.92); }
.ai-fab-ico svg { width: 25px; height: 25px; display: block; }

/* ------------------------------ panel -------------------------------- */
.ai-panel {
  position: absolute; right: 0; bottom: 66px;
  width: min(380px, calc(100vw - 32px));
  height: min(540px, calc(100vh - 130px));
  display: flex; flex-direction: column;
  background: rgba(255, 255, 255, .97);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  box-shadow: 0 20px 54px rgba(30, 41, 59, .22);
  overflow: hidden;
  opacity: 0; visibility: hidden;
  transform: translateY(14px) scale(.97);
  transform-origin: bottom right;
  transition: opacity .22s, transform .22s cubic-bezier(.34, 1.4, .64, 1), visibility .22s;
}
.ai-panel.on { opacity: 1; visibility: visible; transform: none; }

.ai-head {
  display: flex; align-items: center; gap: 9px;
  padding: 13px 14px;
  background: linear-gradient(120deg, #efeaff, #e8f3ff);
  border-bottom: 1px solid rgba(148, 163, 184, .22);
}
.ai-head-ico { display: inline-flex; color: var(--ai-accent); }
.ai-head-ico svg { width: 19px; height: 19px; }
.ai-head-t { font-size: 13.5px; font-weight: 700; color: #312e81; flex: 1; }
.ai-cred {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10.5px; color: #64748b;
  background: rgba(255, 255, 255, .8);
  border-radius: 999px; padding: 3px 9px; white-space: nowrap;
}
.ai-cred.pocos { color: #b91c1c; background: #fee2e2; }
.ai-x {
  background: none; border: 0; cursor: pointer; color: #64748b;
  display: inline-flex; padding: 3px; border-radius: 7px;
}
.ai-x:hover { background: rgba(148, 163, 184, .18); color: #1e293b; }
.ai-x svg { width: 16px; height: 16px; }

.ai-ctx {
  font-size: 11px; color: #6d28d9; background: #f5f3ff;
  padding: 7px 14px; border-bottom: 1px solid rgba(148, 163, 184, .18);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------------------------- mensajes ------------------------------- */
.ai-lista { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg {
  max-width: 88%; font-size: 13px; line-height: 1.5;
  border-radius: 14px; padding: 9px 12px;
  animation: ai-in .25s ease-out;
}
@keyframes ai-in { from { opacity: 0; transform: translateY(6px); } }
.ai-msg p { margin: 0 0 7px; }
.ai-msg p:last-child { margin-bottom: 0; }
.ai-user { align-self: flex-end; background: var(--ai-accent); color: #fff; }
.ai-assistant { align-self: flex-start; background: #f1f5f9; color: #1e293b; }
.ai-intro { background: #f5f3ff; color: #4c1d95; }
.ai-error { background: #fee2e2; color: #991b1b; }
.ai-nota { font-size: 11.5px; opacity: .8; }
.ai-msg code {
  font-family: var(--font-mono, ui-monospace, monospace); font-size: 12px;
  background: rgba(99, 102, 241, .12); border-radius: 5px; padding: 1px 5px;
}
.ai-msg pre {
  background: #1e293b; color: #e2e8f0; border-radius: 10px;
  padding: 10px 12px; overflow-x: auto; margin: 7px 0;
}
.ai-msg pre code { background: none; color: inherit; padding: 0; font-size: 11.5px; }

.ai-dots { display: inline-flex; gap: 4px; padding: 2px 0; }
.ai-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: #94a3b8;
  animation: ai-blink 1.1s infinite;
}
.ai-dots i:nth-child(2) { animation-delay: .18s; }
.ai-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes ai-blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* ------------------------------ pie ---------------------------------- */
.ai-pie {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px; border-top: 1px solid rgba(148, 163, 184, .22);
  background: rgba(248, 250, 252, .9);
}
.ai-input {
  flex: 1; resize: none; border: 1.5px solid #dbe2ea; border-radius: 12px;
  padding: 9px 11px; font: inherit; font-size: 13px; line-height: 1.4;
  max-height: 120px; background: #fff; color: #1e293b;
}
.ai-input:focus { outline: none; border-color: var(--ai-accent); }
.ai-enviar {
  border: 0; border-radius: 11px; cursor: pointer;
  background: var(--ai-accent); color: #fff;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  transition: background .2s, opacity .2s;
}
.ai-enviar:hover { background: #4f46e5; }
.ai-enviar:disabled { opacity: .5; cursor: default; }
.ai-enviar svg { width: 17px; height: 17px; }

@media (max-width: 560px) {
  .ai-root { right: 14px; bottom: 14px; }
  .ai-panel { height: min(70vh, calc(100vh - 110px)); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-panel, .ai-fab, .ai-msg { transition: none; animation: none; }
}
