/* ─── AI Field Components — Animations & Effects ─────────────────
 * Used by AIInput and AITextarea components.
 * Brand gradient: hsl(var(--primary)) → hsl(var(--primary)) (blue → violet)
 * Radii: 12px inputs (brand standard)
 * ─────────────────────────────────────────────────────────────── */

/* The shared Input is also used without AI. Keep its error and keyboard
   boundary visible when the operating system replaces author colours. */
:is(.tutos-input, .tutos-textarea).ai-field-active[aria-invalid="true"] {
  border-color: hsl(var(--destructive)) !important;
}

@media (forced-colors: active) {
  :is(.tutos-input, .tutos-textarea):focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }

  :is(.tutos-input, .tutos-textarea)[aria-invalid="true"] {
    border-style: dashed;
    border-width: 2px;
  }
}

/* ── Glow ring around field when AI is active (soft breathing) ── */
@keyframes ai-field-glow {
  0%, 100% {
    box-shadow: 0 0 0 1px hsl(var(--primary) / 0.2),
                0 0 6px hsl(var(--primary) / 0.06),
                0 0 20px hsl(var(--primary) / 0.03);
  }
  50% {
    box-shadow: 0 0 0 1.5px hsl(var(--primary) / 0.3),
                0 0 10px rgba(139, 92, 246, 0.08),
                0 0 28px hsl(var(--primary) / 0.05);
  }
}

.ai-field-active {
  animation: none;
  border-color: hsl(var(--primary) / 0.5) !important;
  box-shadow: 0 0 0 1px hsl(var(--primary) / 0.15);
}

:is(.dark) .ai-field-active {
  animation: none;
  border-color: hsl(var(--primary) / 0.6) !important;
  box-shadow: 0 0 0 1px hsl(var(--primary) / 0.2);
}

@keyframes ai-field-glow-dark {
  0%, 100% {
    box-shadow: 0 0 0 1px hsl(var(--primary) / 0.15),
                0 0 8px hsl(var(--primary) / 0.04),
                0 0 24px rgba(139, 92, 246, 0.03);
  }
  50% {
    box-shadow: 0 0 0 1.5px rgba(129, 140, 248, 0.25),
                0 0 14px rgba(139, 92, 246, 0.06),
                0 0 32px hsl(var(--primary) / 0.04);
  }
}

/* ── Shimmer sweep across the field border when generating ── */
@keyframes ai-shimmer {
  0% {
    background-position: -200% center;
  }
  100% {
    background-position: 200% center;
  }
}

.ai-field-shimmer {
  position: relative;
}

.ai-field-shimmer::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    transparent 0%,
    hsl(var(--primary) / 0.1) 20%,
    hsl(var(--primary) / 0.18) 40%,
    rgba(139, 92, 246, 0.22) 50%,
    hsl(var(--primary) / 0.18) 60%,
    hsl(var(--primary) / 0.1) 80%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: ai-shimmer 1.8s ease-in-out infinite;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  padding: 1.5px;
}

/* ── Floating panel slide-in (Apple spring curve) ── */
@keyframes ai-panel-enter {
  0% {
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
    filter: blur(4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes ai-panel-exit {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
    filter: blur(2px);
  }
}

.ai-panel-enter {
  animation: ai-panel-enter 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.ai-panel-exit {
  animation: ai-panel-exit 0.18s ease-in forwards;
}

/* ── Loading wand spin ── */
@keyframes ai-field-icon-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.ai-field-icon-spin {
  animation: ai-field-icon-spin 2s linear infinite;
}

/* ── Assist strip — calm, persistent invitation ──
 * Eligible fields should advertise help before focus, especially for keyboard
 * and touch users. The panel still opens only on an explicit click. */
.ai-assist-strip {
  cursor: pointer;
  -moz-user-select: none;
       user-select: none;
  -webkit-user-select: none;
  opacity: 0.82;
  max-height: 32px;
  margin-top: 4px;
  padding-top: 2px;
  padding-bottom: 2px;
  transform: none;
  pointer-events: auto;
  overflow: hidden;
  transition: opacity 150ms ease-in, max-height 150ms ease-in,
    transform 150ms ease-in, margin-top 150ms ease-in;
}

/* Focus and an open panel add emphasis without moving the layout. */
.ai-field-wrapper:focus-within .ai-assist-strip,
.ai-assist-strip-visible {
  opacity: 1;
  max-height: 32px;
  margin-top: 4px;
  padding-top: 2px;
  padding-bottom: 2px;
  transform: none;
  pointer-events: auto;
  transition: opacity 200ms ease-out, max-height 200ms ease-out,
    transform 200ms ease-out, margin-top 200ms ease-out;
}

.ai-assist-strip:focus-visible {
  outline: 2px solid hsl(var(--primary) / 0.5);
  outline-offset: 1px;
  border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  .ai-field-shimmer::after,
  .ai-panel-enter,
  .ai-strip-shimmer,
  .ai-strip-nudge,
  .ai-field-icon-spin,
  .ai-dot-1,
  .ai-dot-2,
  .ai-dot-3,
  .ai-text-reveal,
  .ai-tip-enter,
  .ai-chat-msg-enter {
    animation: none !important;
  }
}

/* ── First-visit shimmer sweep across TutAI wordmark ── */
@keyframes ai-strip-shimmer {
  0% { background-position: -100% center; }
  100% { background-position: 200% center; }
}

.ai-strip-shimmer {
  background-size: 200% 100%;
  animation: ai-strip-shimmer 0.6s ease-out forwards;
}

/* ── Welcome nudge accent line shimmer ── */
@keyframes ai-welcome-accent {
  0% { background-position: 0% center; }
  50% { background-position: 100% center; }
  100% { background-position: 0% center; }
}

/* ── Nudge pulse on icon after 2s idle on empty field ── */
@keyframes ai-strip-nudge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.ai-strip-nudge {
  animation: ai-strip-nudge 0.6s ease;
}

/* ── Generating dots animation ── */
@keyframes ai-dot-pulse {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

.ai-dot-1 { animation: ai-dot-pulse 1.4s ease-in-out infinite; }
.ai-dot-2 { animation: ai-dot-pulse 1.4s ease-in-out 0.2s infinite; }
.ai-dot-3 { animation: ai-dot-pulse 1.4s ease-in-out 0.4s infinite; }

/* ── Result text fade-in ── */
@keyframes ai-text-reveal {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-text-reveal {
  animation: ai-text-reveal 0.3s ease-out forwards;
}

/* ── Assist strip active press ── */
.ai-field-wrapper:focus-within .ai-assist-strip:active,
.ai-assist-strip-visible:active {
  transform: scale(0.995);
  transition-duration: 80ms;
}

/* ── Guide tip bullet entrance ── */
@keyframes ai-tip-enter {
  0% {
    opacity: 0;
    transform: translateX(-6px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

.ai-tip-enter {
  animation: ai-tip-enter 0.25s ease-out forwards;
}

.ai-tip-enter:nth-child(1) { animation-delay: 0ms; }
.ai-tip-enter:nth-child(2) { animation-delay: 60ms; }
.ai-tip-enter:nth-child(3) { animation-delay: 120ms; }
.ai-tip-enter:nth-child(4) { animation-delay: 180ms; }
.ai-tip-enter:nth-child(5) { animation-delay: 240ms; }

/* ── Chat message entrance (conversational refinement) ── */
@keyframes ai-chat-msg-enter {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ai-chat-msg-enter {
  animation: ai-chat-msg-enter 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ── Respect prefers-reduced-motion ── */
@media (prefers-reduced-motion: reduce) {
  .ai-field-active,
  :is(.dark) .ai-field-active {
    animation: none;
    box-shadow: 0 0 0 1.5px hsl(var(--primary) / 0.3);
  }

  .ai-field-shimmer::after {
    animation: none;
  }

  .ai-panel-enter,
  .ai-panel-exit {
    animation: none;
  }

  .ai-assist-strip,
  .ai-field-wrapper:focus-within .ai-assist-strip,
  .ai-assist-strip-visible {
    transition: none;
  }

  .ai-strip-shimmer {
    animation: none;
  }

  .ai-strip-nudge {
    animation: none;
  }

  .ai-dot-1,
  .ai-dot-2,
  .ai-dot-3 {
    animation: none;
    opacity: 0.6;
  }

  .ai-text-reveal {
    animation: none;
  }

  .ai-field-icon-spin {
    animation: none;
  }

  .ai-tip-enter {
    animation: none;
    opacity: 1;
  }

  .ai-chat-msg-enter {
    animation: none;
  }

  .ai-welcome-nudge {
    transition: none;
  }

  /* WelcomeTour modal transitions */
  [role="dialog"][aria-modal="true"] *,
  [role="dialog"][aria-modal="true"] {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}

