/* ==========================================================================
   Asistente Alrisha (chat con IA). Usa los colores del tema activo.
   ========================================================================== */
.ai-launch {
  position: fixed; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 780; display: inline-flex; align-items: center; gap: .6rem;
  height: 56px; padding: 0 1.25rem 0 1rem; border: 0; border-radius: 999px;
  background: var(--gold); color: #0A0A0A; font: 500 .9rem/1 var(--sans); letter-spacing: .02em;
  box-shadow: 0 10px 30px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.08) inset;
  cursor: pointer; transition: transform .35s var(--ease-out), opacity .3s, background-color .3s;
}
.ai-launch:hover { background: var(--gold-soft); transform: translateY(-2px); }
.ai-launch:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.ai-launch svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.is-locked .ai-launch, .ai-open .ai-launch { opacity: 0; pointer-events: none; transform: translateY(12px); }

.ai-panel {
  position: fixed; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 820; width: min(400px, calc(100vw - 2rem)); height: min(620px, calc(100dvh - 2rem));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--cream-2); color: var(--ink); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
  font-family: var(--sans);
  opacity: 0; transform: translateY(16px) scale(.98); transform-origin: bottom right;
  transition: opacity .3s, transform .4s var(--ease-out);
}
.ai-panel[hidden] { display: none; }
.ai-panel.is-open { opacity: 1; transform: none; }

.ai-head {
  display: flex; align-items: center; gap: .75rem; padding: .9rem 1rem;
  border-bottom: 1px solid var(--line); background: var(--cream);
}
.ai-avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--gold); color: #0A0A0A;
}
.ai-avatar svg { width: 18px; height: 18px; fill: currentColor; }
.ai-title { flex: 1; min-width: 0; }
.ai-title strong { display: block; font: 500 1.15rem/1.1 var(--serif); letter-spacing: .01em; }
.ai-title span { display: block; font-size: .75rem; color: var(--ink-mute); margin-top: .15rem; }
.ai-close {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: transparent;
  color: var(--ink); display: grid; place-items: center; cursor: pointer; flex: none;
}
.ai-close:hover { border-color: var(--gold); color: var(--gold); }
.ai-close svg { width: 16px; height: 16px; }

.ai-log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 1rem;
  display: flex; flex-direction: column; gap: .7rem; scroll-behavior: smooth;
}
.ai-msg {
  max-width: 88%; padding: .7rem .9rem; border-radius: 14px; font-size: .92rem; line-height: 1.5;
  overflow-wrap: anywhere; white-space: normal;
}
.ai-msg p { margin: 0 0 .5em; }
.ai-msg p:last-child, .ai-msg ul:last-child { margin-bottom: 0; }
.ai-msg ul { margin: .2em 0 .5em; padding-left: 1.2em; list-style: disc; }
.ai-msg li { margin: .15em 0; list-style: inherit; }
.ai-msg li::marker { color: var(--gold); }
.ai-msg strong { font-weight: 500; color: var(--gold-ink); }
.ai-bot { align-self: flex-start; background: var(--cream); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.ai-user { align-self: flex-end; background: var(--gold); color: #0A0A0A; border-bottom-right-radius: 4px; }
.ai-error { border-color: rgba(220,120,100,.45); }
.ai-error a { color: var(--gold-ink); }

.ai-typing { display: inline-flex; gap: 4px; padding: .2rem 0; }
.ai-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-mute); animation: ai-dot 1.2s infinite ease-in-out; }
.ai-typing i:nth-child(2) { animation-delay: .15s; }
.ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-dot { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }

.ai-chips { display: flex; flex-wrap: wrap; gap: .45rem; padding: 0 1rem .8rem; }
.ai-chips[hidden] { display: none; }
.ai-chip {
  border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 999px;
  padding: .5rem .8rem; font: 400 .8rem/1.2 var(--sans); text-align: left; cursor: pointer;
}
.ai-chip:hover { border-color: var(--gold); color: var(--gold-ink); }

.ai-form { display: flex; gap: .5rem; align-items: flex-end; padding: .75rem; border-top: 1px solid var(--line); background: var(--cream); }
.ai-input {
  flex: 1; min-width: 0; resize: none; max-height: 120px; min-height: 44px;
  padding: .65rem .85rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--cream-2); color: var(--ink); font: 400 16px/1.4 var(--sans); /* 16px evita el zoom en iPhone */
}
.ai-input::placeholder { color: var(--ink-mute); }
.ai-input:focus { outline: none; border-color: var(--gold); }
.ai-send {
  width: 44px; height: 44px; flex: none; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--gold); color: #0A0A0A; display: grid; place-items: center;
}
.ai-send:disabled { opacity: .45; cursor: default; }
.ai-send svg { width: 20px; height: 20px; }
.ai-note { margin: 0; padding: 0 1rem .7rem; font-size: .7rem; line-height: 1.4; color: var(--ink-mute); background: var(--cream); }
.ai-note a { color: var(--gold-ink); }

/* Teléfono: el chat ocupa toda la pantalla y el botón se vuelve compacto */
@media (max-width: 560px) {
  .ai-launch { height: 48px; padding: 0 .95rem 0 .8rem; font-size: .82rem; gap: .5rem; }
  .ai-panel {
    inset: 0; width: 100%; height: 100%; height: 100dvh; border-radius: 0; border: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .ai-open, .ai-open body { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .ai-launch, .ai-panel { transition: none; }
  .ai-typing i { animation: none; opacity: .6; }
}
@media print { .ai-launch, .ai-panel { display: none !important; } }
