/* ============================================
   Aldo — Animations & Micro-interactions
   Performance: transform + opacity uniquement
   ============================================ */

/* --- Respect des préférences utilisateur --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Background animé subtil --- */
body {
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(155, 35, 53, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 50%, rgba(100, 30, 80, 0.06) 0%, transparent 50%);
  background-size: 200% 200%;
  animation: bgShift 30s ease-in-out infinite;
}

@keyframes bgShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* ============================================
   TRANSITIONS DE VUES
   ============================================ */

.view {
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.view.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

/* Nav indicator animé */
.nav-link {
  position: relative;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 3px;
  background: var(--accent-light);
  border-radius: 2px;
  transform: translateX(-50%);
  transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-link.active::after {
  width: 24px;
}

@media (min-width: 768px) {
  .nav-link::after {
    bottom: 0;
  }
}

/* ============================================
   CHAT ANIMATIONS
   ============================================ */

/* Bulles — pop in */
.chat-bubble {
  animation: none;
}

.chat-bubble.aldo {
  animation: slideInLeft 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-bubble.user {
  animation: slideInRight 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-30px) scale(0.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px) scale(0.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

/* Typing indicator amélioré */
.typing-indicator span {
  animation: typingWave 1.4s infinite ease-in-out;
}

@keyframes typingWave {
  0%, 60%, 100% { transform: translateY(0) scale(0.7); opacity: 0.3; }
  30% { transform: translateY(-8px) scale(1); opacity: 1; }
}

/* Bouton envoi — pulse quand actif */
.btn-send {
  transition: all 0.2s ease;
}

.btn-send.has-content {
  animation: sendPulse 2s ease-in-out infinite;
  box-shadow: 0 0 20px var(--accent-glow);
}

@keyframes sendPulse {
  0%, 100% { box-shadow: 0 0 10px var(--accent-glow); }
  50% { box-shadow: 0 0 25px var(--accent-glow); }
}

/* Bouton press effect */
.btn-send:active,
.btn:active,
.btn-login:active,
.filter-pill:active {
  transform: scale(0.92);
}

/* Icône attach rotation */
.btn-attach {
  transition: transform 0.3s ease;
}

.btn-attach:hover {
  transform: rotate(15deg);
}

/* Upload preview slide up */
.chat-upload-preview {
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Confettis / champagne bubbles */
.celebration-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.bubble-particle {
  position: absolute;
  bottom: -20px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.8;
  animation: bubbleRise 2s ease-out forwards;
}

@keyframes bubbleRise {
  0% { transform: translateY(0) scale(1); opacity: 0.8; }
  100% { transform: translateY(-100vh) scale(0.3); opacity: 0; }
}

/* ============================================
   CAVE ANIMATIONS
   ============================================ */

/* Cartes — cascade staggered */
.bottle-card {
  opacity: 0;
  transform: translateY(20px);
  animation: cardAppear 0.4s ease forwards;
}

.bottle-card:nth-child(1) { animation-delay: 0ms; }
.bottle-card:nth-child(2) { animation-delay: 50ms; }
.bottle-card:nth-child(3) { animation-delay: 100ms; }
.bottle-card:nth-child(4) { animation-delay: 150ms; }
.bottle-card:nth-child(5) { animation-delay: 200ms; }
.bottle-card:nth-child(6) { animation-delay: 250ms; }
.bottle-card:nth-child(7) { animation-delay: 300ms; }
.bottle-card:nth-child(8) { animation-delay: 350ms; }
.bottle-card:nth-child(9) { animation-delay: 400ms; }
.bottle-card:nth-child(n+10) { animation-delay: 450ms; }

@keyframes cardAppear {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Carte hover — élévation + glow */
.bottle-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.bottle-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.bottle-card::before {
  transition: box-shadow 0.3s ease, opacity 0.3s ease;
}

.bottle-card.rouge:hover::before {
  box-shadow: 4px 0 20px rgba(155, 35, 53, 0.4);
}

.bottle-card.blanc:hover::before {
  box-shadow: 4px 0 20px rgba(232, 216, 140, 0.3);
}

.bottle-card.rosé:hover::before,
.bottle-card.rose:hover::before {
  box-shadow: 4px 0 20px rgba(212, 120, 138, 0.3);
}

/* Ripple effect au click */
.bottle-card {
  position: relative;
  overflow: hidden;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  transform: scale(0);
  animation: ripple 0.6s ease-out;
  pointer-events: none;
}

@keyframes ripple {
  to { transform: scale(4); opacity: 0; }
}

/* Carte sortie — verse animation */
.bottle-card.drinking {
  animation: pourWine 0.6s ease forwards;
}

@keyframes pourWine {
  0% { transform: rotate(0) translateY(0); opacity: 1; }
  50% { transform: rotate(-15deg) translateY(-10px); opacity: 0.8; }
  100% { transform: rotate(-30deg) translateY(40px); opacity: 0; }
}

/* Filtre pill glow */
.filter-pill.active {
  box-shadow: 0 0 16px var(--accent-glow);
  transition: all 0.3s ease;
}

/* Search placeholder animation */
.cave-search::placeholder {
  transition: opacity 0.3s ease;
}

.cave-search:focus::placeholder {
  opacity: 0.3;
}

/* Cave vide — bouteille qui se balance */
.empty-icon {
  display: inline-block;
  animation: swingBottle 3s ease-in-out infinite;
  transform-origin: top center;
}

@keyframes swingBottle {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

/* ============================================
   DASHBOARD ANIMATIONS
   ============================================ */

/* KPI count-up — géré en JS, mais le conteneur pulse */
.stat-card {
  opacity: 0;
  animation: statAppear 0.5s ease forwards;
}

.stat-card:nth-child(1) { animation-delay: 0ms; }
.stat-card:nth-child(2) { animation-delay: 80ms; }
.stat-card:nth-child(3) { animation-delay: 160ms; }
.stat-card:nth-child(4) { animation-delay: 240ms; }
.stat-card:nth-child(5) { animation-delay: 320ms; }
.stat-card:nth-child(6) { animation-delay: 400ms; }

@keyframes statAppear {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Plus-value pulse */
.stat-gain {
  animation: gainPulse 2s ease-in-out infinite;
}

@keyframes gainPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Barres — remplissage progressif */
.chart-bar-fill {
  transform-origin: left;
  animation: barGrow 0.8s ease-out forwards;
}

.chart-bar-row:nth-child(1) .chart-bar-fill { animation-delay: 0ms; }
.chart-bar-row:nth-child(2) .chart-bar-fill { animation-delay: 100ms; }
.chart-bar-row:nth-child(3) .chart-bar-fill { animation-delay: 200ms; }
.chart-bar-row:nth-child(4) .chart-bar-fill { animation-delay: 300ms; }
.chart-bar-row:nth-child(5) .chart-bar-fill { animation-delay: 400ms; }
.chart-bar-row:nth-child(6) .chart-bar-fill { animation-delay: 500ms; }

@keyframes barGrow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* Dash cards — scroll reveal */
.dash-card {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.dash-card.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Alerte urgente clignotante */
.apogee-item .apogee-icon {
  display: inline-block;
}

.apogee-urgent .apogee-icon {
  animation: alertBlink 1.5s ease-in-out infinite;
}

@keyframes alertBlink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.15); }
}

/* Météo temperature shimmer */
.meteo-temp {
  position: relative;
  overflow: hidden;
}

.meteo-temp::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(212, 168, 83, 0.15), transparent);
  animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* ============================================
   LOGIN ANIMATIONS
   ============================================ */

/* Carte drop-in */
.login-card {
  animation: dropIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-40px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Logo oscillation */
.login-brand .logo {
  display: inline-block;
  animation: pendulum 4s ease-in-out infinite;
  transform-origin: top center;
}

@keyframes pendulum {
  0%, 100% { transform: rotate(-8deg); }
  50% { transform: rotate(8deg); }
}

/* Input focus underline */
.login-card input {
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Bouton login shimmer gradient */
.btn-login {
  position: relative;
  overflow: hidden;
}

.btn-login::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  animation: btnShimmer 3s ease-in-out infinite;
}

@keyframes btnShimmer {
  0% { left: -100%; }
  100% { left: 200%; }
}

/* Erreur — shake */
.login-card.shake {
  animation: shakeCard 0.5s ease;
}

@keyframes shakeCard {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px); }
  40% { transform: translateX(12px); }
  60% { transform: translateX(-8px); }
  80% { transform: translateX(8px); }
}

/* Flip vers 2FA */
.login-card .totp-section {
  animation: flipIn 0.5s ease;
}

@keyframes flipIn {
  from { opacity: 0; transform: rotateY(90deg) scale(0.9); }
  to { opacity: 1; transform: rotateY(0) scale(1); }
}

/* Succès — shrink avant redirect */
.login-card.success {
  animation: shrinkOut 0.4s ease forwards;
}

@keyframes shrinkOut {
  to { opacity: 0; transform: scale(0.9); }
}

/* ============================================
   ÉLÉMENTS GLOBAUX
   ============================================ */

/* Modal backdrop progressive */
.modal-overlay {
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; backdrop-filter: blur(8px); }
}

.modal {
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* Skeleton loader */
.skeleton {
  background: var(--bg-card);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent);
  animation: skeletonShimmer 1.5s ease-in-out infinite;
}

@keyframes skeletonShimmer {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

/* Toast notifications */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 14px;
  z-index: 300;
  box-shadow: var(--shadow);
  animation: toastIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
             toastOut 0.3s ease 3s forwards;
  max-width: 350px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(0.9); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px); }
}

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error { border-left: 4px solid var(--danger); }

/* Smooth scroll */
* {
  scroll-behavior: smooth;
}

/* Badge apogée — subtle animation */
.bottle-badge {
  transition: transform 0.2s ease;
}

.bottle-card:hover .bottle-badge {
  transform: scale(1.05);
}

/* Top ranking shine */
.top-rank {
  position: relative;
  overflow: hidden;
}

.top-item:first-child .top-rank::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(212, 168, 83, 0.3), transparent);
  animation: shimmer 2s ease-in-out infinite;
}

@media (min-width: 768px) {
  .toast {
    top: 80px; /* Below nav */
  }
}
