/**
 * Motion / présence — à côté de theme.css.
 * Light, informatif, respect --tf-motion + prefers-reduced-motion.
 * Pas de foire : calcul / analyse / settle uniquement.
 */

:root {
  --tf-dur-fast: calc(120ms * var(--tf-motion, 1));
  --tf-dur-base: calc(280ms * var(--tf-motion, 1));
  --tf-dur-slow: calc(520ms * var(--tf-motion, 1));
  --tf-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --tf-ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
  --tf-safe-bottom: env(safe-area-inset-bottom, 0px);
  --tf-safe-top: env(safe-area-inset-top, 0px);
  --tf-mobile-nav-h: calc(3.5rem + var(--tf-safe-bottom));
}

/* —— Mobile chrome —— */
.tf-safe-pad-x {
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
}

.tf-safe-pad-b {
  padding-bottom: max(0px, var(--tf-safe-bottom));
}

.tf-mobile-tabbar {
  height: var(--tf-mobile-nav-h);
  padding-bottom: var(--tf-safe-bottom);
}

.tf-shell-main-mobile {
  padding-bottom: var(--tf-mobile-nav-h);
}

.tf-drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: color-mix(in srgb, var(--tf-text) 40%, transparent);
}

.tf-drawer-panel {
  position: absolute;
  z-index: 40;
  top: 3.5rem;
  bottom: var(--tf-mobile-nav-h);
  left: 0;
  width: min(16rem, 86vw);
  background: var(--tf-surface);
  border-right: 1px solid var(--tf-border);
  transform: translateX(0);
  transition: transform var(--tf-dur-base) var(--tf-ease-out);
}

html[data-reduced-motion='1'] .tf-drawer-panel,
.tf-reduced-motion .tf-drawer-panel {
  transition: none;
}

/* —— Analyse / calcul (informative) —— */
@keyframes tf-run-breathe {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

@keyframes tf-run-sweep {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(220%);
  }
}

@keyframes tf-run-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes tf-settle-in {
  from {
    opacity: 0;
    transform: translateY(0.4rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tf-phase-dot {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--tf-brand) 0%, transparent);
  }
  50% {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--tf-brand) 22%, transparent);
  }
}

@keyframes tf-chain-draw {
  from {
    stroke-dashoffset: 48;
  }
  to {
    stroke-dashoffset: 0;
  }
}

/* Anneau d’analyse — remplace animate-spin + indigo */
.tf-run-ring {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 9999px;
  border: 3px solid color-mix(in srgb, var(--tf-brand) 22%, transparent);
  border-top-color: var(--tf-brand);
  animation: tf-run-spin calc(0.9s * var(--tf-motion, 1)) linear infinite;
}

.tf-run-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: var(--tf-accent);
  animation: tf-run-breathe calc(1.4s * var(--tf-motion, 1)) ease-in-out infinite;
}

.tf-run-rail {
  position: relative;
  height: 2px;
  overflow: hidden;
  border-radius: 9999px;
  background: var(--tf-border);
}

.tf-run-rail::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(
    90deg,
    transparent,
    var(--tf-brand),
    var(--tf-accent),
    transparent
  );
  animation: tf-run-sweep calc(1.35s * var(--tf-motion, 1)) var(--tf-ease-soft) infinite;
}

.tf-settle {
  animation: tf-settle-in var(--tf-dur-base) var(--tf-ease-out) both;
}

.tf-phase-active {
  animation: tf-phase-dot calc(1.8s * var(--tf-motion, 1)) ease-in-out infinite;
}

/* SVG chaîne écart → source → statut */
.tf-chain-svg .tf-chain-path {
  fill: none;
  stroke: var(--tf-brand);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: tf-chain-draw calc(1.1s * var(--tf-motion, 1)) var(--tf-ease-out) forwards;
}

.tf-chain-svg .tf-chain-path-delay {
  animation-delay: calc(0.28s * var(--tf-motion, 1));
}

.tf-chain-svg[data-state='idle'] .tf-chain-path {
  animation: none;
  stroke-dashoffset: 0;
  opacity: 0.45;
}

.tf-chain-svg[data-state='done'] .tf-chain-path {
  animation: none;
  stroke-dashoffset: 0;
  stroke: var(--tf-semantic-ok);
}

.tf-chain-svg[data-state='gap'] .tf-chain-node-gap {
  fill: var(--tf-accent);
}

.tf-chain-svg[data-state='running'] .tf-chain-node-gap {
  fill: var(--tf-accent);
}

.tf-chain-label {
  font-family: var(--tf-font-sans);
  font-size: 0.65rem;
  fill: var(--tf-text-muted);
}

/* Reduced motion — présence informative sans mouvement */
html[data-reduced-motion='1'] .tf-run-ring,
html[data-reduced-motion='1'] .tf-run-dot,
html[data-reduced-motion='1'] .tf-run-rail::after,
html[data-reduced-motion='1'] .tf-settle,
html[data-reduced-motion='1'] .tf-phase-active,
html[data-reduced-motion='1'] .tf-chain-svg .tf-chain-path,
.tf-reduced-motion .tf-run-ring,
.tf-reduced-motion .tf-run-dot,
.tf-reduced-motion .tf-run-rail::after,
.tf-reduced-motion .tf-settle,
.tf-reduced-motion .tf-phase-active,
.tf-reduced-motion .tf-chain-svg .tf-chain-path {
  animation: none !important;
}

html[data-reduced-motion='1'] .tf-run-ring,
.tf-reduced-motion .tf-run-ring {
  border-top-color: var(--tf-brand);
  opacity: 1;
}

html[data-reduced-motion='1'] .tf-run-rail::after,
.tf-reduced-motion .tf-run-rail::after {
  width: 100%;
  transform: none;
  background: var(--tf-brand);
  opacity: 0.35;
}

html[data-reduced-motion='1'] .tf-chain-svg .tf-chain-path,
.tf-reduced-motion .tf-chain-svg .tf-chain-path {
  stroke-dashoffset: 0;
}

@media (prefers-reduced-motion: reduce) {
  .tf-run-ring,
  .tf-run-dot,
  .tf-run-rail::after,
  .tf-settle,
  .tf-phase-active,
  .tf-chain-svg .tf-chain-path {
    animation: none !important;
  }
  .tf-run-rail::after {
    width: 100%;
    transform: none;
    background: var(--tf-brand);
    opacity: 0.35;
  }
  .tf-chain-svg .tf-chain-path {
    stroke-dashoffset: 0;
  }
}

html[data-reduced-motion='1'] .group-hover\:scale-110:hover,
.tf-reduced-motion .group-hover\:scale-110:hover {
  transform: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .group:hover .group-hover\:scale-110,
  .group:hover .group-hover\:rotate-3 {
    transform: none !important;
  }
}
