/* ============================================================
   FastBook Premium Motion System
   A cohesive, performant motion language for the entire SaaS.
   ============================================================ */

/* -----------------------------------------------
   1. DESIGN TOKENS — Durations, Easings
   ----------------------------------------------- */
:root {
  /* Durations */
  --fb-dur-instant: 100ms;
  --fb-dur-fast:    180ms;
  --fb-dur-normal:  280ms;
  --fb-dur-smooth:  400ms;
  --fb-dur-slow:    600ms;

  /* Easings  — Apple-style spring curves */
  --fb-ease-out:      cubic-bezier(0.22, 1, 0.36, 1);
  --fb-ease-in-out:   cubic-bezier(0.65, 0, 0.35, 1);
  --fb-ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);
  --fb-ease-soft:     cubic-bezier(0.25, 0.1, 0.25, 1);

  /* Stagger base increment */
  --fb-stagger: 60ms;
}

/* Respect user preference for reduced motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --fb-dur-instant: 0ms;
    --fb-dur-fast:    0ms;
    --fb-dur-normal:  0ms;
    --fb-dur-smooth:  0ms;
    --fb-dur-slow:    0ms;
  }
  .fb-page-content,
  .fb-stagger,
  .fb-animate { animation: none !important; }
}

/* -----------------------------------------------
   2. PAGE ENTRANCE — Fade-up on load
   ----------------------------------------------- */
@keyframes fb-page-enter {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fb-page-content {
  animation: fb-page-enter var(--fb-dur-smooth) var(--fb-ease-out) both;
}

/* -----------------------------------------------
   3. STAGGER REVEAL — Cards, list items, rows
   ----------------------------------------------- */
@keyframes fb-stagger-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fb-stagger {
  opacity: 0;
  animation: fb-stagger-in var(--fb-dur-normal) var(--fb-ease-out) both;
}
.fb-stagger:nth-child(1)  { animation-delay: calc(var(--fb-stagger) * 0); }
.fb-stagger:nth-child(2)  { animation-delay: calc(var(--fb-stagger) * 1); }
.fb-stagger:nth-child(3)  { animation-delay: calc(var(--fb-stagger) * 2); }
.fb-stagger:nth-child(4)  { animation-delay: calc(var(--fb-stagger) * 3); }
.fb-stagger:nth-child(5)  { animation-delay: calc(var(--fb-stagger) * 4); }
.fb-stagger:nth-child(6)  { animation-delay: calc(var(--fb-stagger) * 5); }
.fb-stagger:nth-child(7)  { animation-delay: calc(var(--fb-stagger) * 6); }
.fb-stagger:nth-child(8)  { animation-delay: calc(var(--fb-stagger) * 7); }
.fb-stagger:nth-child(9)  { animation-delay: calc(var(--fb-stagger) * 8); }
.fb-stagger:nth-child(10) { animation-delay: calc(var(--fb-stagger) * 9); }
.fb-stagger:nth-child(11) { animation-delay: calc(var(--fb-stagger) * 10); }
.fb-stagger:nth-child(12) { animation-delay: calc(var(--fb-stagger) * 11); }

/* -----------------------------------------------
   4. SCROLL-TRIGGERED REVEAL (lazy)
   Uses IntersectionObserver — see motion.js
   ----------------------------------------------- */
.fb-animate {
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity var(--fb-dur-smooth) var(--fb-ease-out),
    transform var(--fb-dur-smooth) var(--fb-ease-out);
}
.fb-animate.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* -----------------------------------------------
   5. CARD & PANEL HOVER LIFT
   ----------------------------------------------- */
.fb-card {
  transition:
    transform var(--fb-dur-fast) var(--fb-ease-out),
    box-shadow var(--fb-dur-fast) var(--fb-ease-out),
    border-color var(--fb-dur-fast) var(--fb-ease-out);
  will-change: transform;
}
.fb-card:hover {
  transform: translateY(-2px);
  box-shadow:
    0 4px 6px -1px rgba(0,0,0,.04),
    0 10px 15px -3px rgba(0,0,0,.06);
}
.fb-card:active {
  transform: translateY(0);
  transition-duration: var(--fb-dur-instant);
}

/* -----------------------------------------------
   6. BUTTON MICRO-INTERACTIONS
   ----------------------------------------------- */
.fb-btn {
  transition:
    transform var(--fb-dur-fast) var(--fb-ease-spring),
    box-shadow var(--fb-dur-fast) var(--fb-ease-out),
    background-color var(--fb-dur-fast) var(--fb-ease-out),
    color var(--fb-dur-fast) var(--fb-ease-out);
}
.fb-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.fb-btn:active {
  transform: translateY(0) scale(0.97);
  box-shadow: none;
  transition-duration: var(--fb-dur-instant);
}

/* Primary button glow on hover */
.fb-btn-primary:hover {
  box-shadow:
    0 4px 14px rgba(99, 102, 241, 0.35),
    0 1px 3px rgba(99, 102, 241, 0.15);
}

/* -----------------------------------------------
   7. SIDEBAR NAV LINK TRANSITIONS
   ----------------------------------------------- */
.fb-nav-link {
  position: relative;
  transition:
    background-color var(--fb-dur-fast) var(--fb-ease-out),
    color var(--fb-dur-fast) var(--fb-ease-out),
    padding-left var(--fb-dur-fast) var(--fb-ease-out);
}
.fb-nav-link:hover:not(.active-nav) {
  padding-left: 1.25rem;
}
.fb-nav-link .fa, .fb-nav-link .fas, .fb-nav-link .far, .fb-nav-link .fab {
  transition: transform var(--fb-dur-fast) var(--fb-ease-spring);
}
.fb-nav-link:hover .fa,
.fb-nav-link:hover .fas,
.fb-nav-link:hover .far,
.fb-nav-link:hover .fab {
  transform: scale(1.12);
}

/* -----------------------------------------------
   8. MODAL / DRAWER TRANSITIONS
   ----------------------------------------------- */
@keyframes fb-modal-overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fb-modal-content-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fb-modal-overlay-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}
@keyframes fb-modal-content-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(8px) scale(0.98); }
}

.fb-modal-overlay {
  animation: fb-modal-overlay-in var(--fb-dur-normal) var(--fb-ease-out) both;
}
.fb-modal-content {
  animation: fb-modal-content-in var(--fb-dur-smooth) var(--fb-ease-spring) both;
}
.fb-modal-overlay.is-closing {
  animation: fb-modal-overlay-out var(--fb-dur-fast) var(--fb-ease-in-out) both;
}
.fb-modal-content.is-closing {
  animation: fb-modal-content-out var(--fb-dur-fast) var(--fb-ease-in-out) both;
}

/* Slide-in drawer (mobile sidebar style) */
@keyframes fb-drawer-in {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}
.fb-drawer {
  animation: fb-drawer-in var(--fb-dur-normal) var(--fb-ease-out) both;
}

/* -----------------------------------------------
   9. FORM INPUT FOCUS TRANSITIONS
   ----------------------------------------------- */
.fb-input {
  transition:
    border-color var(--fb-dur-fast) var(--fb-ease-out),
    box-shadow var(--fb-dur-fast) var(--fb-ease-out),
    background-color var(--fb-dur-fast) var(--fb-ease-out);
}
.fb-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
  outline: none;
}

/* Success state */
.fb-input-success {
  border-color: #22c55e !important;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1) !important;
}

/* Error state with subtle shake */
@keyframes fb-shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-4px); }
  40%  { transform: translateX(4px); }
  60%  { transform: translateX(-3px); }
  80%  { transform: translateX(2px); }
}
.fb-input-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
  animation: fb-shake var(--fb-dur-smooth) var(--fb-ease-out);
}

/* -----------------------------------------------
   10. TAB INDICATOR MOTION
   ----------------------------------------------- */
.fb-tabs {
  position: relative;
}
.fb-tab {
  transition:
    color var(--fb-dur-fast) var(--fb-ease-out),
    background-color var(--fb-dur-fast) var(--fb-ease-out);
}
.fb-tab-indicator {
  transition:
    left var(--fb-dur-normal) var(--fb-ease-spring),
    width var(--fb-dur-normal) var(--fb-ease-spring);
}

/* -----------------------------------------------
   11. DATA VISUALIZATION MOTION
   ----------------------------------------------- */
/* Animated number counter — controlled by JS */
.fb-count-up {
  display: inline-block;
}

/* Progress bar fill */
@keyframes fb-progress-fill {
  from { width: 0%; }
}
.fb-progress-bar {
  animation: fb-progress-fill var(--fb-dur-slow) var(--fb-ease-out) both;
  animation-delay: var(--fb-dur-normal);
}

/* Stat number pop */
@keyframes fb-number-pop {
  0%   { transform: scale(0.8); opacity: 0; }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}
.fb-stat-number {
  animation: fb-number-pop var(--fb-dur-smooth) var(--fb-ease-spring) both;
}

/* -----------------------------------------------
   12. DROPDOWN MOTION
   ----------------------------------------------- */
@keyframes fb-dropdown-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.fb-dropdown {
  animation: fb-dropdown-in var(--fb-dur-fast) var(--fb-ease-out) both;
  transform-origin: top center;
}

/* -----------------------------------------------
   13. TOOLTIP FADE
   ----------------------------------------------- */
@keyframes fb-tooltip-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fb-tooltip {
  animation: fb-tooltip-in var(--fb-dur-fast) var(--fb-ease-out) both;
}

/* -----------------------------------------------
   14. TOAST / NOTIFICATION SLIDE-IN
   ----------------------------------------------- */
@keyframes fb-toast-in {
  from { opacity: 0; transform: translateY(-10px) translateX(-50%); }
  to   { opacity: 1; transform: translateY(0) translateX(-50%); }
}
@keyframes fb-toast-out {
  from { opacity: 1; transform: translateY(0) translateX(-50%); }
  to   { opacity: 0; transform: translateY(-10px) translateX(-50%); }
}
.fb-toast {
  animation: fb-toast-in var(--fb-dur-normal) var(--fb-ease-spring) both;
}
.fb-toast.is-leaving {
  animation: fb-toast-out var(--fb-dur-fast) var(--fb-ease-in-out) both;
}

/* -----------------------------------------------
   15. SKELETON LOADING SHIMMER
   ----------------------------------------------- */
@keyframes fb-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.fb-skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
  background-size: 200% 100%;
  animation: fb-shimmer 1.6s ease-in-out infinite;
  border-radius: 8px;
}

/* -----------------------------------------------
   16. BADGE PULSE (e.g., notification dot)
   ----------------------------------------------- */
@keyframes fb-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.3); opacity: 0.7; }
}
.fb-pulse {
  animation: fb-pulse 2s var(--fb-ease-in-out) infinite;
}

/* -----------------------------------------------
   17. SMOOTH SCROLLBAR (dashboard)
   ----------------------------------------------- */
.fb-smooth-scroll {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* -----------------------------------------------
   18. ICON SPIN (loading)
   ----------------------------------------------- */
@keyframes fb-spin {
  to { transform: rotate(360deg); }
}
.fb-spin {
  animation: fb-spin 0.8s linear infinite;
}

/* -----------------------------------------------
   19. CONTENT FADE-SWITCH (tab/section swap)
   ----------------------------------------------- */
@keyframes fb-fade-switch {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.fb-fade-switch {
  animation: fb-fade-switch var(--fb-dur-normal) var(--fb-ease-out) both;
}
