/* ============================================================
   FLEXYPRO AI — microinteractions layer (Apple-grade tactility)
   Pairs with /static/js/microinteractions.js?v=12
   Vanilla CSS, transform/opacity/box-shadow only, 60fps target.

   Design system:
     ember     : #FD6143  (brand red-ember)
     ember-2   : #FD7D5A  (hover bright)
     ember-3   : #C76619  (deep)
     bg        : #080707
     ivory     : #F5F0E6

     easing    : cubic-bezier(.22,1,.36,1)  (Apple "swift-out")
     micro     : 180ms
     normal    : 280ms
     dramatic  : 480ms
   ============================================================ */

:root {
  --mi-ease: cubic-bezier(.22, 1, .36, 1);
  --mi-micro: 180ms;
  --mi-normal: 280ms;
  --mi-dramatic: 480ms;
  --mi-ember: #FD6143;
  --mi-ember-soft: rgba(253, 97, 67, 0.30);
  --mi-ember-ring: rgba(253, 97, 67, 0.55);
  --mi-success: #50C878;
  --mi-error: #FF4D4D;
}

/* ------------------------------------------------------------
   1. RIPPLE EFFECT (Material × Apple)
   ------------------------------------------------------------ */
.mi-ripple-host {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.mi-ripple-wave {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(
    circle,
    rgba(253, 97, 67, 0.45) 0%,
    rgba(253, 97, 67, 0.18) 45%,
    rgba(253, 97, 67, 0) 70%
  );
  transform: scale(0);
  opacity: 0.55;
  animation: mi-ripple 600ms cubic-bezier(.22, 1, .36, 1) forwards;
  z-index: 0;
  mix-blend-mode: screen;
}
.mi-ripple-host > * {
  position: relative;
  z-index: 1;
}
@keyframes mi-ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* ------------------------------------------------------------
   2. CLICK FEEDBACK — universal :active scale
   ------------------------------------------------------------ */
button, a.cta-primary, a.cta-secondary, .btn, .btn-primary, .btn-ghost,
.btn-tab, [role="button"], .mi-tap {
  transition:
    transform var(--mi-normal) var(--mi-ease),
    box-shadow var(--mi-normal) var(--mi-ease),
    background-color var(--mi-normal) var(--mi-ease),
    border-color var(--mi-normal) var(--mi-ease),
    color var(--mi-normal) var(--mi-ease);
  -webkit-tap-highlight-color: transparent;
}
button:active, a.cta-primary:active, a.cta-secondary:active,
.btn:active, .btn-primary:active, .btn-ghost:active,
.btn-tab:active, [role="button"]:active, .mi-tap:active {
  transform: scale(0.97);
  transition-duration: var(--mi-micro);
}

/* Subtle hover lift on primary CTAs only (when fine pointer) */
@media (hover: hover) and (pointer: fine) {
  a.cta-primary:hover, .btn-primary:hover, .cta-primary:hover {
    transform: translateY(-1px);
  }
  a.cta-primary:active, .btn-primary:active, .cta-primary:active {
    transform: scale(0.97) translateY(0);
  }
}

/* ------------------------------------------------------------
   3. FOCUS GLOW — ember-ring for keyboard nav only
   ------------------------------------------------------------ */
*:focus { outline: none; }
*:focus-visible {
  outline: 2px solid var(--mi-ember);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(253, 97, 67, 0.18),
              0 0 14px 2px rgba(253, 97, 67, 0.30);
  border-radius: inherit;
  transition: box-shadow var(--mi-micro) var(--mi-ease);
}

/* ------------------------------------------------------------
   4. INPUT FEEDBACK — gentle scale on type, error/valid states
   ------------------------------------------------------------ */
input, textarea, select {
  transition:
    transform var(--mi-micro) var(--mi-ease),
    border-color var(--mi-normal) var(--mi-ease),
    box-shadow var(--mi-normal) var(--mi-ease),
    background-color var(--mi-normal) var(--mi-ease);
}
.mi-input-pulse {
  animation: mi-input-tap var(--mi-micro) var(--mi-ease);
}
@keyframes mi-input-tap {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.005); }
  100% { transform: scale(1); }
}
.mi-input-invalid {
  animation: mi-shake 360ms var(--mi-ease);
  border-color: var(--mi-error) !important;
  box-shadow: 0 0 0 3px rgba(255, 77, 77, 0.18) !important;
}
@keyframes mi-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.mi-input-valid {
  border-color: var(--mi-success) !important;
  box-shadow: 0 0 0 3px rgba(80, 200, 120, 0.18) !important;
}
.mi-valid-check {
  position: absolute;
  right: 10px;
  top: 50%;
  width: 18px;
  height: 18px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-50%) scale(0.6);
  transition: opacity var(--mi-normal) var(--mi-ease),
              transform var(--mi-normal) var(--mi-ease);
  color: var(--mi-success);
}
.mi-valid-check.mi-show {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* ------------------------------------------------------------
   5. EMBER PULSE SPINNER — 3 concentric rings with exp delay
   ------------------------------------------------------------ */
.mi-spinner {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 48px;
  vertical-align: middle;
}
.mi-spinner__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--mi-ember);
  opacity: 0;
  transform: scale(0);
  animation: mi-pulse-ring 1600ms cubic-bezier(.22, 1, .36, 1) infinite;
}
.mi-spinner__ring:nth-child(1) { animation-delay: 0ms; }
.mi-spinner__ring:nth-child(2) { animation-delay: 300ms; }
.mi-spinner__ring:nth-child(3) { animation-delay: 600ms; }
@keyframes mi-pulse-ring {
  0%   { transform: scale(0.15); opacity: 0; border-width: 3px; }
  10%  { opacity: 0.9; }
  100% { transform: scale(1);    opacity: 0; border-width: 1px; }
}
.mi-spinner--lg { width: 72px; height: 72px; }
.mi-spinner--sm { width: 28px; height: 28px; }

/* ------------------------------------------------------------
   6. TOASTS — top slide-down notifier
   ------------------------------------------------------------ */
.mi-toast-stack {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.mi-toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 10px;
  font-family: 'Manrope', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.01em;
  color: #F5F0E6;
  background: rgba(20, 20, 20, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(253, 97, 67, 0.35);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45),
              0 0 24px rgba(253, 97, 67, 0.18);
  opacity: 0;
  transform: translateY(-20px) scale(0.96);
  transition: opacity var(--mi-normal) var(--mi-ease),
              transform var(--mi-normal) var(--mi-ease);
  pointer-events: auto;
  min-width: 200px;
  max-width: 480px;
}
.mi-toast.mi-show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.mi-toast--success {
  border-color: rgba(80, 200, 120, 0.45);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45),
              0 0 24px rgba(80, 200, 120, 0.20);
}
.mi-toast--success .mi-toast__icon { color: var(--mi-success); }
.mi-toast--error {
  border-color: rgba(255, 77, 77, 0.50);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45),
              0 0 24px rgba(255, 77, 77, 0.22);
}
.mi-toast--error .mi-toast__icon { color: var(--mi-error); }
.mi-toast__icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

/* ------------------------------------------------------------
   7. PAGE TRANSITION — fade + top progress bar
   ------------------------------------------------------------ */
.mi-page-leave {
  opacity: 0;
  transition: opacity 200ms var(--mi-ease);
}
.mi-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0%;
  background: linear-gradient(
    90deg,
    var(--mi-ember) 0%,
    #FD7D5A 50%,
    var(--mi-ember) 100%
  );
  box-shadow: 0 0 10px rgba(253, 97, 67, 0.65),
              0 0 18px rgba(253, 97, 67, 0.35);
  z-index: 99999;
  pointer-events: none;
  opacity: 1;
  transition: width 220ms var(--mi-ease), opacity 280ms var(--mi-ease);
}
.mi-progress--done {
  width: 100% !important;
  opacity: 0;
}

/* ------------------------------------------------------------
   8. MAGNETIC (extension of motion.js, with smooth release)
   ------------------------------------------------------------ */
.mi-magnetic {
  transition: transform var(--mi-normal) var(--mi-ease);
  will-change: transform;
}

/* ------------------------------------------------------------
   9. MOBILE — reduce intensity 50%
   ------------------------------------------------------------ */
@media (max-width: 767px) {
  .mi-ripple-wave { animation-duration: 480ms; opacity: 0.4; }
  .mi-toast { font-size: 13px; padding: 10px 14px; }
  .mi-spinner { width: 40px; height: 40px; }
  button:active, a.cta-primary:active, a.cta-secondary:active,
  .btn:active, .btn-primary:active, .btn-ghost:active,
  .btn-tab:active, [role="button"]:active, .mi-tap:active {
    transform: scale(0.985);
  }
}

/* ------------------------------------------------------------
   10. REDUCED MOTION — full opt-out
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .mi-ripple-wave,
  .mi-progress,
  .mi-page-leave,
  .mi-input-pulse,
  .mi-spinner__ring {
    animation: none !important;
    transition: none !important;
  }
  .mi-toast {
    transition: opacity 80ms linear !important;
    transform: none !important;
  }
  .mi-toast.mi-show { transform: none !important; }
  button:active, a.cta-primary:active, a.cta-secondary:active,
  .btn:active, .btn-primary:active, .btn-ghost:active,
  .btn-tab:active, [role="button"]:active {
    transform: none !important;
  }
  *:focus-visible {
    outline: 2px solid var(--mi-ember);
    box-shadow: none;
  }
  .mi-spinner__ring {
    /* fallback: static ember dot */
    opacity: 0.5;
    transform: scale(0.7);
    border-width: 2px;
  }
}
