/**
 * ai-assistant.css — Panel de AI Assistant
 * AHAN Technological Medical Solution
 *
 * Panel lateral derecho, no modal: la agenda sigue siendo
 * utilizable mientras el asistente permanece abierto.
 * Soporte light/dark vía tokens existentes.
 */

/* ─── Panel ────────────────────────────────────────────────── */
.ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100vw;
  background: var(--color-bg-surface);
  border-left: 1px solid var(--color-border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--duration-md) ease;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
}
.ai-panel--open {
  transform: translateX(0);
}

/* ─── Header ───────────────────────────────────────────────── */
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.ai-header__title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.ai-header__icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-brand-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-header__icon svg {
  width: 12px;
  height: 12px;
  color: #fff;
}
.ai-header__close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--duration-sm), color var(--duration-sm);
}
.ai-header__close:hover {
  background: var(--color-border);
  color: var(--color-text-primary);
}
.ai-header__close:focus-visible {
  outline: 2px solid var(--color-brand-blue);
  outline-offset: 2px;
}

/* ─── Messages area ────────────────────────────────────────── */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

/* ─── Message bubbles ──────────────────────────────────────── */
.ai-msg {
  max-width: 85%;
  line-height: 1.5;
  font-size: var(--font-size-sm);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  word-break: break-word;
}
.ai-msg--user {
  align-self: flex-end;
  background: var(--color-brand-blue);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}
.ai-msg--assistant {
  align-self: flex-start;
  background: var(--color-gray-100);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: var(--radius-sm);
}
.ai-msg--assistant p {
  margin: 0;
}
.ai-msg--assistant ul,
.ai-msg--assistant ol {
  margin: var(--space-1) 0;
  padding-left: var(--space-4);
}
.ai-msg--assistant li {
  margin-bottom: var(--space-1);
}

/* ─── Suggested prompts ────────────────────────────────────── */
.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-3);
}
.ai-suggestion {
  position: relative;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-elevated);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--duration-sm), border-color var(--duration-sm),
              color var(--duration-sm), transform var(--duration-sm),
              box-shadow var(--duration-sm);
  white-space: nowrap;
}
.ai-suggestion::before {
  content: "";
  position: absolute;
  left: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-brand-blue);
  opacity: 0.55;
}
.ai-suggestion:hover {
  background: var(--color-brand-blue);
  border-color: var(--color-brand-blue);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.25);
}
.ai-suggestion:hover::before {
  background: #fff;
  opacity: 1;
}
.ai-suggestion:focus-visible {
  outline: 2px solid var(--color-brand-blue);
  outline-offset: 2px;
}

/* ─── Input area ───────────────────────────────────────────── */
.ai-input-area {
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  flex-shrink: 0;
  background: linear-gradient(to top, var(--color-bg-surface), transparent);
}
.ai-input {
  flex: 1;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-sm);
  font-family: inherit;
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
  resize: none;
  min-height: 42px;
  max-height: 96px;
  line-height: 1.5;
  transition: border-color var(--duration-sm), box-shadow var(--duration-sm),
              background var(--duration-sm);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.ai-input::placeholder {
  color: var(--color-text-muted);
}
.ai-input:hover {
  border-color: var(--color-border-strong);
}
.ai-input:focus {
  outline: none;
  border-color: var(--color-brand-blue);
  background: var(--color-bg-surface);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.ai-send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-brand-gradient);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--duration-sm), transform var(--duration-sm),
              opacity var(--duration-sm), box-shadow var(--duration-sm);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}
.ai-send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}
.ai-send:active:not(:disabled) {
  transform: translateY(0);
}
.ai-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.ai-send:focus-visible {
  outline: 2px solid var(--color-brand-blue);
  outline-offset: 2px;
}
.ai-send svg {
  width: 18px;
  height: 18px;
}

/* ─── Typing indicator ─────────────────────────────────────── */
.ai-typing {
  display: flex;
  gap: 4px;
  padding: var(--space-2) var(--space-3);
  align-self: flex-start;
}
.ai-typing__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: ai-bounce 1.2s infinite ease-in-out;
}
.ai-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.ai-typing__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* ─── Recalibración de la agenda ────────────────────────────── */
/* Mientras el chat está abierto, la agenda se refluye a la
   izquierda reservando el ancho del panel para que el calendario
   se muestre completo (no queda oculto debajo del chat). */
.app {
  transition: margin-right var(--duration-md) ease;
}
body.ai-panel-open .app {
  margin-right: 420px;
}

/* Íconos del asistente con chat-bot.svg (marca) */
.ai-header__img {
  width: 14px;
  height: 14px;
  display: block;
  pointer-events: none;
  object-fit: contain;
}
.ai-empty__img {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
  object-fit: contain;
}

/* Al abrir el panel, el .app encoge 420px: el logo centrado con
   subtítulo largo se superpondría al bloque de sesión → el logo
   pasa al flujo (izquierda) mostrando solo "AHAN". */
body.ai-panel-open .nav__logo {
  position: static;
  transform: none;
  pointer-events: auto;
}
body.ai-panel-open .nav__logo-subtitulo {
  display: none;
}
body.ai-panel-open .nav__logo-img {
  width: 26px;
  height: 26px;
}

/* ─── Trigger button ───────────────────────────────────────── */
.ai-trigger {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-brand-gradient);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 80;
  transition: transform var(--duration-md), box-shadow var(--duration-md);
}
.ai-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.ai-trigger:focus-visible {
  outline: 2px solid var(--color-brand-blue);
  outline-offset: 3px;
}
.ai-trigger svg {
  width: 22px;
  height: 22px;
}
.ai-trigger__img {
  width: 26px;
  height: 26px;
  pointer-events: none;
}
/* Ocultar trigger cuando el panel está abierto */
.ai-trigger--hidden {
  display: none;
}

/* ─── Empty state ──────────────────────────────────────────── */
.ai-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: var(--space-6);
  color: var(--color-text-muted);
}
.ai-empty__icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-brand-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
}
.ai-empty__icon svg {
  width: 24px;
  height: 24px;
  color: #fff;
}
.ai-empty__text {
  font-size: var(--font-size-sm);
  max-width: 260px;
  line-height: 1.5;
}

/* ─── Error message ────────────────────────────────────────── */
.ai-msg--error {
  background: var(--color-danger);
  color: #fff;
  align-self: center;
  font-size: var(--font-size-xs);
}

/* ─── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
  .ai-panel {
    width: 100vw;
  }
  body.ai-panel-open .app {
    margin-right: 0;
  }
  .ai-trigger {
    bottom: var(--space-4);
    right: var(--space-4);
  }
}
