/* ──────────────────────────────────────────────────────────────
   motion.css — общий слой анимаций мини-аппа.
   Подключается на всех страницах после основного CSS.
   Все правила обёрнуты в :where(), т.е. имеют нулевую специфичность:
   любое правило конкретной страницы их переопределяет.
   ────────────────────────────────────────────────────────────── */

:root {
  --mo-ease: cubic-bezier(0.25, 0.8, 0.35, 1);
  --mo-spring: cubic-bezier(0.2, 1.4, 0.4, 1);
  --mo-fast: 0.14s;
  --mo-base: 0.26s;
}

@media (prefers-reduced-motion: no-preference) {
  /* ── появление страницы ─────────────────────────────────── */
  body { animation: mo-page-in 0.22s var(--mo-ease) both; }
  body.mo-leaving {
    animation: mo-page-out 0.14s ease both;
    pointer-events: none;
  }

  /* блоки страницы выезжают каскадом (--i ставит motion.js);
     главная профиля и каталог уже анимированы своими стилями */
  :where(main:not(.home):not(.profile):not(.catalog)) > :where(:not([hidden]):not(.toast):not(.cart-toast):not(.modal):not(.sheet):not(.lightbox)) {
    animation: mo-rise 0.32s var(--mo-ease) backwards;
    animation-delay: calc(var(--i, 0) * 45ms);
  }

  /* ── элементы, появившиеся позже (списки, строки, карточки) ── */
  .mo-in {
    animation: mo-rise 0.28s var(--mo-ease) backwards;
    animation-delay: calc(var(--i, 0) * 35ms);
  }

  /* ── нажатие: все кнопки и всё, что ведёт себя как кнопка ──── */
  :where(button, [role="button"], .btn, .btn-ghost, .home-tile, .home-order, .back-button,
         .cat-chip, .chip, .qty-button, .file-input__btn, .profile-resources__btn,
         .profile-card, .load-more, .form__submit, .admin-card, .order-card, .promo-card,
         .model-card, .product-card, label.option, .option, summary) {
    transition:
      transform var(--mo-fast) var(--mo-ease),
      box-shadow var(--mo-fast) var(--mo-ease),
      background-color 0.18s ease,
      border-color 0.18s ease,
      color 0.18s ease,
      opacity 0.18s ease;
    -webkit-tap-highlight-color: transparent;
  }
  :where(button, [role="button"], .btn, .btn-ghost, .home-tile, .home-order, .back-button,
         .cat-chip, .chip, .file-input__btn, .profile-resources__btn, .load-more,
         .form__submit, .admin-card, .order-card, .promo-card, label.option, .option):active:not(:disabled) {
    transform: scale(0.96);
  }
  :where(.qty-button, .modal__close, .toast__close, .circle-button):active:not(:disabled) {
    transform: scale(0.88);
  }
  :where(.profile-card, .model-card, .product-card):active {
    transform: scale(0.985);
  }
  :where(button, .btn):disabled {
    transition: opacity 0.18s ease, transform var(--mo-fast) var(--mo-ease);
  }

  /* ── волна от точки нажатия ───────────────────────────────── */
  .mo-ripple-host { position: relative; overflow: hidden; isolation: isolate; }
  .mo-ripple {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    background: currentColor;
    opacity: 0.18;
    transform: translate(-50%, -50%) scale(0);
    animation: mo-ripple 0.55s var(--mo-ease) forwards;
    z-index: 0;
  }

  /* ── поля ввода ───────────────────────────────────────────── */
  :where(input, textarea, select) {
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, transform 0.2s var(--mo-ease);
  }
  :where(input, textarea, select):focus { transform: translateY(-1px); }

  /* ── занятая кнопка: точки вместо текста ──────────────────── */
  .mo-busy {
    position: relative;
    color: transparent !important;
    pointer-events: none;
  }
  .mo-busy::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    animation: mo-spin 0.7s linear infinite;
  }
  .mo-busy.btn--ghost::after,
  .mo-busy.btn-ghost::after {
    border-color: rgba(60, 73, 199, 0.25);
    border-top-color: #3c49c7;
  }

  /* ── обратная связь по действию ───────────────────────────── */
  .mo-shake { animation: mo-shake 0.42s var(--mo-ease); }
  .mo-pulse { animation: mo-pulse 0.45s var(--mo-spring); }
  .mo-flash-ok { animation: mo-flash-ok 0.9s ease; }
  .mo-out {
    animation: mo-out 0.22s var(--mo-ease) forwards;
    pointer-events: none;
  }

  /* всплывающий «+1» над кнопкой */
  .mo-float {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    font-weight: 800;
    font-size: 0.95rem;
    color: #3c49c7;
    text-shadow: 0 1px 0 #fff, 0 0 8px rgba(255, 255, 255, 0.9);
    transform: translate(-50%, -50%);
    animation: mo-float 0.7s var(--mo-ease) forwards;
  }
  .mo-float--minus { color: #dc2626; }

  /* летящая точка в корзину */
  .mo-fly {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f5ee8, #7c3aed);
    box-shadow: 0 6px 16px rgba(79, 94, 232, 0.45);
    transform: translate(-50%, -50%);
  }

  /* ссылки/вкладки */
  :where(a) { transition: color 0.18s ease, opacity 0.18s ease; }
  :where(.is-active) { transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease; }

  /* детали, раскрывающиеся списки */
  :where(details) > :where(:not(summary)) { animation: mo-rise 0.22s var(--mo-ease); }
}

/* ── ключевые кадры ────────────────────────────────────────── */
@keyframes mo-page-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes mo-page-out {
  to { opacity: 0; transform: translateY(6px); }
}
@keyframes mo-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes mo-out {
  to { opacity: 0; transform: translateX(28px) scale(0.96); }
}
@keyframes mo-ripple {
  to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
@keyframes mo-spin {
  to { transform: rotate(360deg); }
}
@keyframes mo-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
@keyframes mo-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes mo-flash-ok {
  0% { box-shadow: 0 0 0 0 rgba(150, 190, 40, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(150, 190, 40, 0); }
}
@keyframes mo-float {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -80%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .mo-ripple, .mo-float, .mo-fly { display: none !important; }
}
