/* ==========================================================================
   Biltum — Animations & Interactions
   Philosophy: Calm, purposeful, warm. Motion confirms; never decorates.
   Durations align with --rf-dur-* tokens in colors_and_type.css.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0 · RESPECT REDUCED MOTION
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .rf-house-loader__piece { animation: none !important; opacity: 1 !important; }
}

/* --------------------------------------------------------------------------
   1 · KEYFRAMES
   -------------------------------------------------------------------------- */

/* Fade + tiny slide — the workhorse entrance */
@keyframes rf-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Scale pop — for modals */
@keyframes rf-pop-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* Slide from right — for drawers */
@keyframes rf-slide-in-right {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

/* Slide up — for bottom sheets / toasts */
@keyframes rf-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Toast entrance from top-right */
@keyframes rf-toast-in {
  from { opacity: 0; transform: translateX(20px) translateY(-4px); }
  to   { opacity: 1; transform: translateX(0) translateY(0); }
}

/* Input shake for errors — small, quick */
@keyframes rf-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-4px); }
  40%      { transform: translateX(4px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(2px); }
}

/* Shimmer for skeletons — sage-tinted */
@keyframes rf-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Button success checkmark draw */
@keyframes rf-check-draw {
  0%   { stroke-dashoffset: 24; }
  100% { stroke-dashoffset: 0; }
}

/* Spinner rotation */
@keyframes rf-spin {
  to { transform: rotate(360deg); }
}

/* Pulse — subtle, for new-item highlights */
@keyframes rf-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--rf-orange-ring); }
  50%      { box-shadow: 0 0 0 8px rgba(249, 115, 22, 0); }
}

/* Count-up number roll — used with JS, no keyframes needed */

/* Underline slide for tabs — relies on transitions, no keyframes */

/* House loader pieces — each piece fades + settles in */
@keyframes rf-house-piece {
  0%   { opacity: 0; transform: translateY(-6px); }
  60%  { opacity: 1; transform: translateY(1px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Smoke puffs from chimney */
@keyframes rf-smoke {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.5); }
  30%  { opacity: 0.7; }
  100% { opacity: 0; transform: translate(-8px, -32px) scale(1.4); }
}

/* Hammer tap — rotate around handle */
@keyframes rf-hammer-tap {
  0%, 100% { transform: rotate(-10deg); }
  50%      { transform: rotate(20deg); }
}

/* Confetti — mild celebration */
@keyframes rf-confetti-fall {
  0%   { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); }
  100% { opacity: 0; transform: translate3d(var(--x, 40px), 200px, 0) rotate(720deg); }
}

/* Stagger helper: each child delays by --rf-stagger-i * 60ms */

/* --------------------------------------------------------------------------
   2 · UTILITY CLASSES
   -------------------------------------------------------------------------- */

.rf-animate-fade-in      { animation: rf-fade-in var(--rf-dur-base) var(--rf-ease-out) both; }
.rf-animate-pop-in       { animation: rf-pop-in var(--rf-dur-base) var(--rf-ease-out) both; }
.rf-animate-slide-in     { animation: rf-slide-in-right var(--rf-dur-base) var(--rf-ease-soft) both; }
.rf-animate-slide-up     { animation: rf-slide-up var(--rf-dur-base) var(--rf-ease-out) both; }
.rf-animate-toast-in     { animation: rf-toast-in var(--rf-dur-base) var(--rf-ease-spring) both; }
.rf-animate-shake        { animation: rf-shake 400ms var(--rf-ease-out); }
.rf-animate-pulse        { animation: rf-pulse 1.4s var(--rf-ease-out) infinite; }

/* Stagger: apply to a container, children get sequenced delay */
.rf-stagger > * {
  animation: rf-fade-in var(--rf-dur-base) var(--rf-ease-out) both;
  animation-delay: calc(var(--rf-stagger-step, 60ms) * var(--rf-i, 0));
}

/* --------------------------------------------------------------------------
   3 · INTERACTIVE STATES (hover / active / focus)
   -------------------------------------------------------------------------- */

/* Primary button — lift on hover, press on active */
.rf-btn-primary {
  transition:
    background-color var(--rf-dur-fast) var(--rf-ease-out),
    transform var(--rf-dur-fast) var(--rf-ease-out),
    box-shadow var(--rf-dur-fast) var(--rf-ease-out);
}
.rf-btn-primary:hover  { transform: translateY(-1px); background-color: var(--rf-orange-hover); }
.rf-btn-primary:active { transform: translateY(0);    transition-duration: 80ms; }
.rf-btn-primary:focus-visible { outline: none; box-shadow: var(--rf-shadow-cta), var(--rf-shadow-focus); }

/* Ghost button */
.rf-btn-ghost {
  transition:
    background-color var(--rf-dur-fast) var(--rf-ease-out),
    border-color var(--rf-dur-fast) var(--rf-ease-out);
}
.rf-btn-ghost:hover  { background-color: var(--rf-surface-alt); }
.rf-btn-ghost:active { background-color: var(--rf-surface-recessed); }
.rf-btn-ghost:focus-visible { outline: none; box-shadow: var(--rf-shadow-focus); }

/* Card hover — gentle lift, no aggressive tilt */
.rf-card-interactive {
  transition:
    box-shadow var(--rf-dur-base) var(--rf-ease-out),
    transform var(--rf-dur-base) var(--rf-ease-out),
    border-color var(--rf-dur-fast) var(--rf-ease-out);
}
.rf-card-interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--rf-shadow-ambient);
  border-color: var(--rf-border);
}

/* Row hover — no lift, just tonal shift */
.rf-row-interactive {
  transition: background-color var(--rf-dur-fast) var(--rf-ease-out);
}
.rf-row-interactive:hover { background-color: var(--rf-surface-alt); }

/* Focus ring (generic) */
.rf-focusable:focus-visible {
  outline: none;
  box-shadow: var(--rf-shadow-focus);
  border-radius: var(--rf-r-sm);
}

/* --------------------------------------------------------------------------
   4 · SKELETON SHIMMER
   -------------------------------------------------------------------------- */
.rf-skeleton {
  background: linear-gradient(
    90deg,
    var(--rf-surface-recessed) 0%,
    #F3EFEB 50%,
    var(--rf-surface-recessed) 100%
  );
  background-size: 200% 100%;
  animation: rf-shimmer 1.4s var(--rf-ease-soft) infinite;
  border-radius: var(--rf-r-sm);
}
.rf-skeleton--line { height: 12px; border-radius: 6px; }
.rf-skeleton--line-sm { height: 10px; border-radius: 5px; }
.rf-skeleton--title { height: 18px; border-radius: 8px; }
.rf-skeleton--avatar { width: 36px; height: 36px; border-radius: 50%; }
.rf-skeleton--thumb { height: 76px; border-radius: 10px; }
.rf-skeleton--card { height: 200px; border-radius: var(--rf-r-xl); }

/* --------------------------------------------------------------------------
   5 · HOUSE LOADER
   House builds piece by piece: foundation → walls → roof → chimney
   → windows → door. Then smoke puffs from chimney.
   Variant A (inline 48px): 1.6s cycle, loops
   Variant B (inline 80px, with caption): 2.0s cycle
   Variant C (overlay 160px, with progress/caption): 2.4s cycle
   Variant D (success/complete): 1.2s, plays once, ends with check
   -------------------------------------------------------------------------- */
.rf-house-loader {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}
.rf-house-loader svg { display: block; overflow: visible; }

/* Each piece — animated in sequence via nth-child / data-index */
.rf-house-loader__piece {
  transform-origin: center;
  animation: rf-house-piece var(--rf-dur-base) var(--rf-ease-out) both;
}

/* Smoke puffs */
.rf-house-loader__smoke {
  animation: rf-smoke 1.6s var(--rf-ease-out) infinite;
  transform-origin: center;
}
.rf-house-loader__smoke--2 { animation-delay: 0.5s; }
.rf-house-loader__smoke--3 { animation-delay: 1s; }

/* --------------------------------------------------------------------------
   6 · PROGRESS BAR ANIMATION
   -------------------------------------------------------------------------- */
.rf-progress-bar {
  height: 4px;
  background: rgba(28, 27, 27, 0.06);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.rf-progress-bar__fill {
  height: 100%;
  background: var(--rf-orange);
  border-radius: 2px;
  transition: width 600ms var(--rf-ease-spring);
}

/* Indeterminate (unknown duration) */
.rf-progress-bar--indeterminate .rf-progress-bar__fill {
  width: 35% !important;
  animation: rf-indeterminate 1.6s var(--rf-ease-soft) infinite;
  transform-origin: left center;
}
@keyframes rf-indeterminate {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

/* --------------------------------------------------------------------------
   7 · TOAST
   -------------------------------------------------------------------------- */
.rf-toast {
  background: var(--rf-surface);
  border: 1px solid var(--rf-border);
  border-radius: var(--rf-r-md);
  padding: 12px 16px;
  box-shadow: var(--rf-shadow-raised);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  font-size: 14px;
  font-weight: 500;
  color: var(--rf-text);
  animation: rf-toast-in var(--rf-dur-base) var(--rf-ease-spring) both;
}
.rf-toast--success { border-left: 3px solid var(--rf-sage); }
.rf-toast--warning { border-left: 3px solid var(--rf-warning); }
.rf-toast--danger  { border-left: 3px solid var(--rf-danger); }
.rf-toast--info    { border-left: 3px solid var(--rf-info); }

/* --------------------------------------------------------------------------
   8 · MODAL BACKDROP + SCALE
   -------------------------------------------------------------------------- */
.rf-modal-backdrop {
  background: rgba(28, 27, 27, 0.48);
  animation: rf-fade-in var(--rf-dur-base) var(--rf-ease-out) both;
}
.rf-modal {
  animation: rf-pop-in var(--rf-dur-base) var(--rf-ease-out) both;
}

/* --------------------------------------------------------------------------
   9 · CONFETTI (tasteful, sage + orange only)
   -------------------------------------------------------------------------- */
.rf-confetti-piece {
  position: absolute;
  top: 0;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: rf-confetti-fall 1.4s var(--rf-ease-out) both;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   10 · SPINNER (in-button loading)
   -------------------------------------------------------------------------- */
.rf-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: rf-spin 720ms linear infinite;
  display: inline-block;
}

/* --------------------------------------------------------------------------
   11 · TAB UNDERLINE SLIDER (relies on a moving ::before element)
   Use: add .rf-tabs, mark buttons with .rf-tab and active one with .active.
   The sliding underline is a pseudo-element on the container, positioned
   via CSS variables (--rf-tab-x, --rf-tab-w) set by JS on active change.
   -------------------------------------------------------------------------- */
.rf-tabs-slider {
  position: relative;
}
.rf-tabs-slider::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: var(--rf-tab-x, 0);
  width: var(--rf-tab-w, 0);
  height: 2px;
  background: var(--rf-orange);
  border-radius: 2px 2px 0 0;
  transition:
    left  var(--rf-dur-base) var(--rf-ease-out),
    width var(--rf-dur-base) var(--rf-ease-out);
}

/* --------------------------------------------------------------------------
   12 · CHANGE ORDER ACCEPT — STRIKETHROUGH DRAW (REN-453)
   .co-strike renders a permanent line through superseded figures. Adding
   .co-strike-animate (done once, right after a CO is accepted) draws the
   line left-to-right; on every later render the line is simply there.
   Reduced motion: section 0 collapses the animation to an instant snap.
   -------------------------------------------------------------------------- */
.co-strike {
  position: relative;
}
.co-strike::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1.5px;
  background: currentColor;
  transform: scaleX(1);
  transform-origin: left center;
  pointer-events: none;
}
.co-strike-animate::after {
  animation: rf-co-strike-draw var(--rf-dur-slow) var(--rf-ease-out) both;
}
@keyframes rf-co-strike-draw {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
