/* ================================================================
   CAMALARM CRM — Micro-animations v2
   Transitions · Skeleton · Toasts · Page · Interactions
   ================================================================ */

/* ══════════════════════════════════════════════════════════════
   1. KEYFRAMES — Bibliothèque complète
   ══════════════════════════════════════════════════════════════ */

/* ── Entrées ── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fadeLeft {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes slideRight {
  from { transform: translateX(-100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ── Sorties ── */
@keyframes fadeOut {
  to { opacity: 0; transform: scale(.96); }
}
@keyframes slideDown {
  to { transform: translateY(8px); opacity: 0; }
}

/* ── Loaders ── */
@keyframes shimmer {
  0%   { background-position: -600px 0; }
  100% { background-position: 600px 0; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .45; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-4px); }
}

/* ── Micro-interactions ── */
@keyframes ripple {
  from { transform: scale(0); opacity: .4; }
  to   { transform: scale(2.5); opacity: 0; }
}
@keyframes checkMark {
  from { stroke-dashoffset: 30; opacity: 0; }
  to   { stroke-dashoffset: 0; opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}
@keyframes pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ── Toast spécifique ── */
@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(24px) scale(.94); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastSlideOut {
  to { opacity: 0; transform: translateX(12px) scale(.96); }
}
@keyframes toastProgress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* ── Counter ── */
@keyframes countUp {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}


/* ══════════════════════════════════════════════════════════════
   2. CLASSES UTILITAIRES D'ANIMATION
   ══════════════════════════════════════════════════════════════ */

.anim-fade-in    { animation: fadeIn   .25s var(--ease) both; }
.anim-fade-up    { animation: fadeUp   .3s  var(--ease) both; }
.anim-fade-down  { animation: fadeDown .25s var(--ease) both; }
.anim-scale-in   { animation: scaleIn  .22s var(--ease) both; }
.anim-slide-up   { animation: slideUp  .3s  var(--ease) both; }
.anim-shake      { animation: shake    .35s var(--ease) both; }
.anim-pop        { animation: pop      .3s  var(--ease) both; }

/* Stagger helpers */
.anim-d1  { animation-delay: .04s; }
.anim-d2  { animation-delay: .08s; }
.anim-d3  { animation-delay: .12s; }
.anim-d4  { animation-delay: .16s; }
.anim-d5  { animation-delay: .20s; }
.anim-d6  { animation-delay: .24s; }


/* ══════════════════════════════════════════════════════════════
   3. SKELETON LOADERS
   ══════════════════════════════════════════════════════════════ */

/* Base skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--neutral-100) 25%,
    var(--neutral-50)  50%,
    var(--neutral-100) 75%
  );
  background-size: 600px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-md);
  display: block;
}

/* ── Skeleton texte ── */
.skeleton-text {
  height: 13px;
  border-radius: 6px;
}
.skeleton-text.sm  { height: 11px; width: 60%; }
.skeleton-text.lg  { height: 18px; }
.skeleton-text.xl  { height: 22px; width: 40%; }

/* ── Skeleton tableau ── */
.skeleton-table {
  width: 100%;
  border-collapse: collapse;
}
.skeleton-table td {
  padding: var(--s3);
  border-bottom: 1px solid var(--neutral-100);
}
.skeleton-table tr:last-child td { border-bottom: none; }

/* Ligne skeleton */
.skeleton-row {
  display: grid;
  gap: var(--s3);
  align-items: center;
  padding: var(--s3) var(--s3);
  border-bottom: 1px solid var(--neutral-100);
  grid-template-columns: 80px 1fr 100px 80px;
}
.skeleton-row:last-child { border-bottom: none; }

/* ── Skeleton card ── */
.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s4);
  box-shadow: var(--shadow-xs);
}
.skeleton-card-header {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s3);
}
.skeleton-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.skeleton-lines { display: flex; flex-direction: column; gap: var(--s2); flex: 1; }

/* ── Skeleton stat card ── */
.skeleton-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s4) var(--s5);
}

/* ── Liste skeleton — 5 items ── */
.skeleton-list {
  display: flex;
  flex-direction: column;
}
.skeleton-list-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) 0;
  border-bottom: 1px solid var(--neutral-100);
}
.skeleton-list-item:last-child { border-bottom: none; }
.skeleton-bullet {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}


/* ══════════════════════════════════════════════════════════════
   4. TOAST NOTIFICATIONS — Redesign premium
   ══════════════════════════════════════════════════════════════ */

.toast-c {
  position: fixed;
  bottom: var(--s5);
  right: var(--s5);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  pointer-events: none;
  max-width: 340px;
}

.tst {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  background: var(--neutral-900);
  color: var(--text-inverse);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  box-shadow:
    0 4px 16px rgba(0,0,0,.16),
    0 1px 4px rgba(0,0,0,.08),
    0 0 0 1px rgba(255,255,255,.06) inset;
  animation: toastSlideIn .22s var(--ease) both;
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  min-width: 240px;
  border-left: 3px solid rgba(255,255,255,.15);
  line-height: var(--lh-tight);
}

/* Icône du toast */
.tst-icon {
  font-size: 15px;
  flex-shrink: 0;
  margin-top: 1px;
  width: 18px;
  text-align: center;
}

/* Contenu */
.tst-body { flex: 1; min-width: 0; }
.tst-title {
  font-weight: var(--fw-semibold);
  font-size: var(--text-sm);
  line-height: 1.35;
}
.tst-sub {
  font-size: var(--text-xs);
  opacity: .65;
  margin-top: 2px;
}

/* Bouton fermer */
.tst-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.45);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  flex-shrink: 0;
  transition: color var(--tr-fast);
  align-self: flex-start;
  margin-top: 1px;
}
.tst-close:hover { color: rgba(255,255,255,.9); }

/* Barre de progression */
.tst::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: rgba(255,255,255,.2);
  transform-origin: left;
  animation: toastProgress 2.8s linear forwards;
}

/* ── Variantes ── */
.tst.ok {
  background: #14532d;
  border-left-color: var(--success);
}
.tst.ok::after { background: var(--success); opacity: .6; }

.tst.er {
  background: #7f1d1d;
  border-left-color: var(--danger);
}
.tst.er::after { background: var(--danger); opacity: .6; }

.tst.warn {
  background: #78350f;
  border-left-color: var(--warning);
}
.tst.warn::after { background: var(--warning); opacity: .6; }

.tst.info {
  background: #1e3a5f;
  border-left-color: var(--brand);
}
.tst.info::after { background: var(--brand); opacity: .6; }

/* Animation sortie */
.tst.removing {
  animation: toastSlideOut .2s var(--ease) forwards;
}


/* ══════════════════════════════════════════════════════════════
   5. TRANSITIONS DE PAGE
   ══════════════════════════════════════════════════════════════ */

/* Tab panels */
.tp {
  display: none;
}
.tp.a {
  display: block;
  padding: 0 var(--s5);
  box-sizing: border-box;
  animation: pageIn .22s var(--ease) both;
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* Landing */
#landP {
  animation: fadeIn .3s var(--ease) both;
}

/* Modal */
.ml {
  animation: scaleIn .22s var(--ease) both;
}

/* Dropdown menus */
.act-pop {
  animation: fadeDown .15s var(--ease) both;
}


/* ══════════════════════════════════════════════════════════════
   6. BOUTONS — Micro-interactions
   ══════════════════════════════════════════════════════════════ */

/* Ripple effect */
.btn { position: relative; overflow: hidden; }
.btn-ripple {
  position: absolute;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,.3);
  pointer-events: none;
  transform: scale(0);
  animation: ripple .5s var(--ease) forwards;
}

/* Loading state */
.btn.loading {
  pointer-events: none;
  opacity: .75;
}
.btn.loading::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
  margin-right: var(--s1);
  flex-shrink: 0;
}

/* Success flash */
.btn.success-flash {
  animation: pop .3s var(--ease);
  background: var(--success) !important;
}


/* ══════════════════════════════════════════════════════════════
   7. INPUTS — Focus & States
   ══════════════════════════════════════════════════════════════ */

/* Focus ring plus doux */
.fi:focus, .fs:focus, .ft:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
  transition:
    border-color var(--tr-fast),
    box-shadow var(--tr-fast);
}

/* Error shake */
.fi.error, .fs.error {
  border-color: var(--danger) !important;
  animation: shake .35s var(--ease);
}
.fi.success { border-color: var(--success) !important; }


/* ══════════════════════════════════════════════════════════════
   8. TABLEAU — Row animations
   ══════════════════════════════════════════════════════════════ */

/* Rows apparaissent progressivement */
.data-table tbody tr {
  animation: fadeUp .2s var(--ease) both;
}
.data-table tbody tr:nth-child(1) { animation-delay: .02s; }
.data-table tbody tr:nth-child(2) { animation-delay: .04s; }
.data-table tbody tr:nth-child(3) { animation-delay: .06s; }
.data-table tbody tr:nth-child(4) { animation-delay: .08s; }
.data-table tbody tr:nth-child(5) { animation-delay: .10s; }
.data-table tbody tr:nth-child(6) { animation-delay: .12s; }
.data-table tbody tr:nth-child(7) { animation-delay: .14s; }
.data-table tbody tr:nth-child(8) { animation-delay: .16s; }

/* Highlight row on action */
.data-table tbody tr.row-highlight {
  animation: rowPulse .6s var(--ease);
}
@keyframes rowPulse {
  0%   { background: var(--brand-light); }
  100% { background: transparent; }
}

/* Row delete animation */
.data-table tbody tr.row-removing {
  animation: rowRemove .25s var(--ease) forwards;
}
@keyframes rowRemove {
  to { opacity: 0; transform: translateX(8px); max-height: 0; overflow: hidden; }
}


/* ══════════════════════════════════════════════════════════════
   9. STAT CARDS — Compteurs animés
   ══════════════════════════════════════════════════════════════ */

.stat-v {
  animation: countUp .4s var(--ease) both;
}
.stat-card {
  animation: fadeUp .3s var(--ease) both;
}
.stat-card:nth-child(1) { animation-delay: .04s; }
.stat-card:nth-child(2) { animation-delay: .08s; }
.stat-card:nth-child(3) { animation-delay: .12s; }
.stat-card:nth-child(4) { animation-delay: .16s; }


/* ══════════════════════════════════════════════════════════════
   10. CLIENT CARDS — Stagger
   ══════════════════════════════════════════════════════════════ */

.client-grid .cl-card,
.client-grid .client-card {
  animation: fadeUp .25s var(--ease) both;
}
.client-grid > *:nth-child(1) { animation-delay: .03s; }
.client-grid > *:nth-child(2) { animation-delay: .06s; }
.client-grid > *:nth-child(3) { animation-delay: .09s; }
.client-grid > *:nth-child(4) { animation-delay: .12s; }
.client-grid > *:nth-child(5) { animation-delay: .15s; }
.client-grid > *:nth-child(6) { animation-delay: .18s; }


/* ══════════════════════════════════════════════════════════════
   11. SPINNER GLOBAL
   ══════════════════════════════════════════════════════════════ */

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
.spinner.sm { width: 14px; height: 14px; border-width: 1.5px; }
.spinner.lg { width: 28px; height: 28px; border-width: 3px; }

/* Loading overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.8);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: inherit;
  animation: fadeIn .15s var(--ease);
}


/* ══════════════════════════════════════════════════════════════
   12. BADGE COUNTER — Pop
   ══════════════════════════════════════════════════════════════ */

.tc {
  transition: transform .15s var(--ease), background .15s var(--ease);
}
.tc.updated {
  animation: pop .3s var(--ease);
}


/* ══════════════════════════════════════════════════════════════
   13. SCROLL REVEAL (via JS IntersectionObserver)
   ══════════════════════════════════════════════════════════════ */

.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}
.reveal.visible {
  opacity: 1;
  transform: none;
}


/* ══════════════════════════════════════════════════════════════
   14. FORMULAIRE — Smooth field transitions
   ══════════════════════════════════════════════════════════════ */

/* Label flottant implicite via animation */
.fgp .fl-l {
  transition: color var(--tr-fast);
}
.fgp:focus-within .fl-l {
  color: var(--brand);
}

/* Checkbox / radio — custom */
.calc-opt input[type="radio"],
.calc-opt input[type="checkbox"] {
  transition: accent-color var(--tr-fast), transform var(--tr-fast);
}
.calc-opt input[type="radio"]:checked,
.calc-opt input[type="checkbox"]:checked {
  animation: pop .25s var(--ease);
}


/* ══════════════════════════════════════════════════════════════
   15. REDUCED MOTION — Accessibilité
   ══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .skeleton {
    animation: none;
    background: var(--neutral-100);
  }
}
