/* ===== BAMBIE — ANIMATIONS =====
   Fenêtres façon « feuille » (montent du bas, la page recule, la taille s'adapte en douceur),
   apparition des cartes, chiffres qui défilent, boutons qui réagissent, cloche, chargement.
   Tout est coupé si le téléphone demande de réduire les animations. */
:root {
    --spring: cubic-bezier(.32, 1.25, .5, 1);   /* léger rebond */
    --ease-out: cubic-bezier(.22, 1, .36, 1);
}

/* ----- Fenêtres (feuilles) ----- */
.overlay.active { animation: ov-in .28s ease both; }
.overlay.active .sheet { animation: sheet-in .5s var(--spring) both; }
.overlay.closing { display: flex; pointer-events: none; animation: ov-out .26s ease forwards; }
.overlay.closing .sheet { animation: sheet-out .26s var(--ease-out) forwards; }
@keyframes ov-in { from { background-color: transparent; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); } }
@keyframes ov-out { to { background-color: transparent; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(28px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes sheet-out { to { opacity: 0; transform: translateY(20px) scale(.97); } }
.sheet.morphing { overflow: hidden; transition: height .38s var(--ease-out); }

/* La page derrière recule quand une fenêtre est ouverte */
.main { transition: transform .45s var(--ease-out), filter .45s var(--ease-out), border-radius .45s var(--ease-out); transform-origin: var(--recede-origin, 50% 50%); }
body.sheet-open .main { transform: scale(.955); filter: brightness(.7); border-radius: 26px; overflow: hidden; }

/* Pages à l'intérieur d'une fenêtre : glissent de côté */
.sp-out-fwd { animation: sp-out-fwd .16s ease-in forwards; }
.sp-out-back { animation: sp-out-back .16s ease-in forwards; }
.sp-in-fwd { animation: sp-in-fwd .34s var(--ease-out) both; }
.sp-in-back { animation: sp-in-back .34s var(--ease-out) both; }
@keyframes sp-out-fwd { to { opacity: 0; transform: translateX(-28px); } }
@keyframes sp-out-back { to { opacity: 0; transform: translateX(28px); } }
@keyframes sp-in-fwd { from { opacity: 0; transform: translateX(36px); } }
@keyframes sp-in-back { from { opacity: 0; transform: translateX(-36px); } }

@media (max-width: 820px) {
    /* Feuille flottante : détachée des bords, coins arrondis, monte depuis le bas */
    .overlay { padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); }
    .sheet { border-radius: 30px; max-height: calc(100% - 40px); padding-bottom: 24px; }
    .overlay.active .sheet { animation-name: sheet-up; animation-duration: .55s; }
    .overlay.closing .sheet { animation-name: sheet-down; animation-duration: .3s; }
    @keyframes sheet-up { from { transform: translateY(105%); } to { transform: none; } }
    @keyframes sheet-down { to { transform: translateY(105%); } }
    body.sheet-open .main { transform: scale(.93) translateY(10px); }
}

/* ----- Apparition des pages et des cartes ----- */
.view.active { animation: view-in .4s var(--ease-out) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.entering .rise { animation: rise .55s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.985); } to { opacity: 1; transform: none; } }

/* ----- Boutons qui réagissent ----- */
.btn-grad, .btn-ghost, .btn-danger, .icon-btn, .mini-btn, .nav-item, .bn-item, .svc-tab, .row, .kpi-btn, .adm-filters button, .theme-pick button, .link {
    transition: transform .18s var(--spring), filter .18s ease, background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn-grad:active, .btn-ghost:active, .btn-danger:active, .icon-btn:active, .mini-btn:active, .svc-tab:active, .adm-filters button:active, .theme-pick button:active { transform: scale(.94); }
.row:active, .kpi-btn:active, .nav-item:active { transform: scale(.98); }
.bn-item:active { transform: scale(.88); }
@media (hover: hover) {
    .btn-grad:hover { transform: translateY(-2px); filter: brightness(1.1); }
    .btn-ghost:hover, .icon-btn:hover { transform: translateY(-1px); }
    .row:hover { transform: translateX(3px); }
    .kpi-btn:hover { transform: translateY(-3px); }
}
.bn-item.active .ph-duotone, .nav-item.active .ph-duotone { animation: ico-pop .45s var(--spring); }
@keyframes ico-pop { 0% { transform: scale(.7); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* ----- Cloche : sonne quand il y a des alertes ----- */
.bell:has(.bell-count:not([hidden])) > .ph-duotone { animation: ring 3.2s ease-in-out 1s infinite; transform-origin: 50% 8%; }
@keyframes ring {
    0%, 22%, 100% { transform: rotate(0); }
    3% { transform: rotate(16deg); } 6% { transform: rotate(-14deg); } 9% { transform: rotate(10deg); }
    12% { transform: rotate(-7deg); } 15% { transform: rotate(4deg); } 18% { transform: rotate(-2deg); }
}
.bell-count:not([hidden]) { animation: badge-pop .5s var(--spring); }
@keyframes badge-pop { from { transform: scale(0); } }

/* ----- Chargement ----- */
.gate-card { animation: sheet-in .55s var(--spring) both; }
.gate[data-state="loading"] .welcome-mark { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.08); box-shadow: 0 0 40px rgb(var(--acc-rgb) / .55); } }
.gate-spinner { border: none; background: conic-gradient(from 0deg, transparent 0 25%, var(--cyan)); -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px)); mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3px)); animation: spin .9s linear infinite; }
.toast { animation: toast-in .45s var(--spring) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.9); } }

/* ----- Moins d'animations si demandé par le téléphone ----- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
    body.sheet-open .main { transform: none; filter: none; }
}
