/* ═══════════════════════════════════════════════════════════════════════
   BizContact Motion — built on Animate UI's motion language (tokens + rules)
   https://github.com/imskyleen/animate-ui  (skill path C: plain markup, CSS)
   Level: subtle · Springs exported with css-timing.mjs as linear() curves.
   Loaded after style.css / admin.css. Selectors are prefixed with `html body`
   so they win over the inline <style> blocks inside individual views.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* Curves (tokens.md § Curves) */
  --ease-out:   cubic-bezier(0.23, 1, 0.32, 1);       /* enters / leaves            */
  --ease-soft:  cubic-bezier(0.215, 0.61, 0.355, 1);  /* menus, overlays, sheets    */
  --ease-color: cubic-bezier(0.25, 0.1, 0.25, 1);     /* color / highlight changes  */
  --ease-away:  cubic-bezier(0.33, 0.17, 0.67, 0.5);  /* dismissed: speeding away   */

  /* Tweens (tokens.md § Tweens) */
  --t-color:   200ms var(--ease-color);   /* transition.color   */
  --t-fade:    200ms var(--ease-out);     /* transition.fade    */
  --t-reveal:  300ms var(--ease-out);     /* transition.reveal  */
  --t-menu:    220ms var(--ease-soft);    /* transition.menu    */
  --t-overlay: 400ms var(--ease-soft);    /* transition.overlay / dialogFade */
  --t-sheet:   400ms var(--ease-soft);    /* transition.sheet   */
  --t-dismiss: 200ms var(--ease-away);    /* transition.dismiss */

  /* Springs (tokens.md § Springs) as the curve Motion would play */
  --spring-press:     400ms linear(0, 0.0261, 0.0935, 0.188, 0.2977, 0.4132, 0.5271, 0.6343, 0.7313, 0.8159, 0.8872, 0.9452, 0.9906, 1.0244, 1.048, 1.063, 1.0709, 1.0732, 1.0713, 1.0663, 1.0594, 1.0514, 1.0429, 1.0346, 1.0267, 1.0196, 1.0134, 1.0082, 1.004, 1.0007, 0.9982, 0.9965, 1, 0.9948, 0.9946, 0.9948, 1, 1, 1, 1);
  --spring-pop:       450ms linear(0, 0.0189, 0.0684, 0.1388, 0.2222, 0.3122, 0.404, 0.4937, 0.5786, 0.657, 0.7276, 0.7899, 0.8438, 0.8895, 0.9275, 0.9583, 0.9828, 1.0015, 1.0154, 1.0252, 1.0316, 1.0352, 1.0366, 1.0363, 1.0348, 1.0324, 1.0294, 1.0262, 1.0228, 1.0195, 1.0163, 1.0134, 1.0107, 1.0083, 1.0063, 1.0045, 1.003, 1.0018, 1.0009, 1.0001, 0.9996, 0.9992, 0.9989, 1, 1);
  --spring-toast:     550ms linear(0, 0.0134, 0.0492, 0.1017, 0.1659, 0.2377, 0.3134, 0.3904, 0.4664, 0.5396, 0.6088, 0.673, 0.7317, 0.7846, 0.8315, 0.8726, 0.9081, 0.9382, 0.9634, 0.984, 1.0006, 1.0136, 1.0234, 1.0305, 1.0353, 1.0381, 1.0393, 1.0393, 1.0382, 1.0364, 1.0341, 1.0314, 1.0284, 1.0254, 1.0224, 1.0194, 1.0166, 1.014, 1.0116, 1.0094, 1.0075, 1.0057, 1.0042, 1.0029, 1.0019, 1.001, 1.0003, 0.9997, 0.9992, 0.9989, 1, 1, 1, 1, 1);
  --spring-dialog:    750ms linear(0, 0.0071, 0.0261, 0.0541, 0.0886, 0.1279, 0.1702, 0.2143, 0.2592, 0.3041, 0.3485, 0.3918, 0.4336, 0.4738, 0.5121, 0.5485, 0.5829, 0.6153, 0.6456, 0.674, 0.7004, 0.725, 0.7479, 0.769, 0.7886, 0.8066, 0.8233, 0.8386, 0.8527, 0.8656, 0.8775, 0.8884, 0.8983, 0.9074, 0.9158, 0.9234, 0.9303, 0.9367, 0.9424, 0.9477, 0.9525, 0.9569, 0.9609, 0.9645, 0.9678, 0.9708, 0.9735, 0.976, 0.9782, 0.9803, 0.9821, 0.9838, 0.9853, 0.9867, 0.9879, 0.9891, 0.9901, 0.9911, 0.9919, 0.9927, 0.9934, 0.994, 0.9946, 0.9951, 0.9955, 0.996, 0.9964, 0.9967, 0.997, 0.9973, 0.9976, 0.9978, 1, 1, 1);
  --spring-highlight: 300ms linear(0, 0.0233, 0.0813, 0.1598, 0.2483, 0.3396, 0.4288, 0.5126, 0.5894, 0.658, 0.7183, 0.7704, 0.8149, 0.8524, 0.8837, 0.9094, 0.9303, 0.9472, 0.9607, 0.9713, 0.9796, 0.986, 0.9908, 0.9944, 0.997, 0.9988, 1.0001, 1.001, 1.0015, 1);
  --spring-entrance:  600ms linear(0, 0.0097, 0.036, 0.0756, 0.1251, 0.1819, 0.2435, 0.3079, 0.3734, 0.4385, 0.5021, 0.5634, 0.6215, 0.676, 0.7265, 0.7728, 0.8149, 0.8526, 0.8862, 0.9157, 0.9414, 0.9634, 0.9821, 0.9977, 1.0104, 1.0206, 1.0285, 1.0345, 1.0387, 1.0414, 1.0428, 1.0432, 1.0427, 1.0415, 1.0397, 1.0376, 1.0351, 1.0324, 1.0296, 1.0268, 1.024, 1.0212, 1.0186, 1.0161, 1.0138, 1.0116, 1.0096, 1.0078, 1.0062, 1.0048, 1.0035, 1.0024, 1.0015, 1.0007, 1, 0.9995, 0.9991, 0.9987, 0.9985, 1);
  --spring-number:    2900ms linear(0, 0.0039, 0.0133, 0.026, 0.0407, 0.0564, 0.0726, 0.089, 0.1054, 0.1218, 0.1379, 0.1538, 0.1695, 0.1849, 0.2, 0.2148, 0.2294, 0.2437, 0.2578, 0.2716, 0.2851, 0.2984, 0.3115, 0.3243, 0.3368, 0.3491, 0.3612, 0.3731, 0.3848, 0.3962, 0.4074, 0.4185, 0.4293, 0.4399, 0.4503, 0.4605, 0.4705, 0.4804, 0.49, 0.4995, 0.5088, 0.5179, 0.5269, 0.5357, 0.5443, 0.5528, 0.5611, 0.5693, 0.5773, 0.5851, 0.5929, 0.6004, 0.6078, 0.6151, 0.6223, 0.6293, 0.6362, 0.643, 0.6496, 0.6561, 0.6625, 0.6688, 0.6749, 0.681, 0.6869, 0.6927, 0.6984, 0.704, 0.7096, 0.715, 0.7202, 0.7254, 0.7306, 0.7356, 0.7405, 0.7453, 0.75, 0.7547, 0.7592, 0.7637, 0.7681, 0.7724, 0.7767, 0.7808, 0.7849, 0.7889, 0.7928, 0.7967, 0.8004, 0.8041, 0.8078, 0.8114, 0.8149, 0.8183, 0.8217, 0.825, 0.8283, 0.8314, 0.8346, 0.8377, 0.8407, 0.8436, 0.8465, 0.8494, 0.8522, 0.8549, 0.8576, 0.8603, 0.8629, 0.8654, 0.8679, 0.8704, 0.8728, 0.8752, 0.8775, 0.8798, 0.882, 0.8842, 0.8863, 0.8885, 0.8905, 0.8926, 0.8946, 0.8965, 0.8984, 0.9003, 0.9022, 0.904, 0.9058, 0.9075, 0.9093, 0.9109, 0.9126, 0.9142, 0.9158, 0.9174, 0.9189, 0.9204, 0.9219, 0.9234, 0.9248, 0.9262, 0.9276, 0.9289, 0.9302, 0.9315, 0.9328, 0.934, 0.9353, 0.9365, 0.9376, 0.9388, 0.9399, 0.9411, 0.9422, 0.9432, 0.9443, 0.9453, 0.9463, 0.9473, 0.9483, 0.9493, 0.9502, 0.9511, 0.9521, 0.9529, 0.9538, 0.9547, 0.9555, 0.9563, 0.9572, 0.958, 0.9587, 0.9595, 0.9603, 0.961, 0.9617, 0.9624, 0.9631, 0.9638, 0.9645, 0.9651, 0.9658, 0.9664, 0.9671, 0.9677, 0.9683, 0.9689, 0.9694, 0.97, 0.9706, 0.9711, 0.9716, 0.9722, 0.9727, 0.9732, 0.9737, 0.9742, 0.9747, 0.9751, 0.9756, 0.9761, 0.9765, 0.9769, 0.9774, 0.9778, 0.9782, 0.9786, 0.979, 0.9794, 0.9798, 0.9802, 0.9805, 0.9809, 0.9812, 0.9816, 0.9819, 0.9823, 0.9826, 0.9829, 0.9832, 0.9835, 0.9839, 0.9842, 0.9844, 0.9847, 0.985, 0.9853, 0.9856, 0.9858, 0.9861, 0.9864, 0.9866, 0.9869, 0.9871, 0.9873, 0.9876, 0.9878, 0.988, 0.9883, 0.9885, 0.9887, 0.9889, 0.9891, 0.9893, 0.9895, 0.9897, 0.9899, 0.9901, 0.9903, 0.9905, 0.9906, 0.9908, 0.991, 0.9911, 0.9913, 0.9915, 0.9916, 0.9918, 0.9919, 0.9921, 0.9922, 0.9924, 0.9925, 0.9927, 0.9928, 0.9929, 0.9931, 0.9932, 0.9933, 0.9934, 0.9936, 0.9937, 0.9938, 0.9939, 0.994, 0.9941, 0.9942, 0.9944, 0.9945, 0.9946, 0.9947, 0.9948, 0.9949, 0.995, 1, 1, 1, 1, 1);

  /* Scales, blurs, distances (tokens.md § Scales / Blur / Shifts) */
  --press:        0.97;    /* scale.press  — buttons            */
  --press-choice: 0.985;   /* scale.choice — rows, cards        */
  --menu-from:    0.9;     /* scale.menu                        */
  --toast-from:   0.96;    /* scale.toast                       */
  --dialog-from:  perspective(500px) rotateX(-20deg) scale(0.8);  /* scale.dialog */
  --blur-icon:    blur(2px);   /* blur.icon — lines of text     */
  --blur-surface: blur(4px);   /* blur.surface — dialogs, toasts */
  --rise:         8px;         /* subtle level: a few px of rise */
  --toast-travel: -100%;       /* toasts sit at the top: rise from above */
  --lift:         -2px;        /* card lift on hover (B4)        */
  --stagger:      80ms;        /* page.md: 80–100ms between items */
}

/* Browsers without linear(): springs fall back to ease-out tweens */
@supports not (transition-timing-function: linear(0, 1)) {
  :root {
    --spring-press:     200ms var(--ease-out);
    --spring-pop:       300ms var(--ease-out);
    --spring-toast:     400ms var(--ease-out);
    --spring-dialog:    450ms var(--ease-out);
    --spring-highlight: 200ms var(--ease-out);
    --spring-entrance:  450ms var(--ease-out);
    --spring-number:    1200ms var(--ease-out);
  }
}

/* Reduced motion (rule A1): movement, scale and rotation go — fades and blurs stay */
@media (prefers-reduced-motion: reduce) {
  :root {
    --press: 1;
    --press-choice: 1;
    --menu-from: 1;
    --toast-from: 1;
    --dialog-from: none;
    --rise: 0px;
    --toast-travel: 0%;
    --lift: 0px;
  }
}

/* ── Shared keyframes (each keeps its resting state: only `from` is written) ── */
@keyframes bz-fade-text    { from { opacity: 0; filter: var(--blur-icon); } }
@keyframes bz-fade-surface { from { opacity: 0; filter: var(--blur-surface); } }
@keyframes bz-fade         { from { opacity: 0; } }
@keyframes bz-rise         { from { translate: 0 var(--rise); } }
@keyframes bz-menu-in      { from { opacity: 0; scale: var(--menu-from); } }
@keyframes bz-toast-in     { from { translate: 0 var(--toast-travel); scale: var(--toast-from); } }
@keyframes bz-toast-out    { to   { opacity: 0; scale: var(--toast-from); filter: var(--blur-surface); } }
@keyframes bz-overlay-in   { from { background-color: transparent; backdrop-filter: blur(0); -webkit-backdrop-filter: blur(0); } }
@keyframes bz-dialog-tip   { from { transform: var(--dialog-from); filter: var(--blur-surface); } }


/* ═══ 1. PRESS — buttons answer the click (recipes/press.md) ═══════════════
   scale.press (0.97) on spring.press. Uses the `scale` property so it composes
   with any transform the button already has. Nothing scales or lifts on hover. */
html body :is(button, a, input[type="submit"], input[type="button"]):is(
  .btn, [class^="btn-"], [class*=" btn-"], [class^="admin-btn"], [class*=" admin-btn"],
  .sidebar-add-contact, .topbar-btn, .email-type-chip, .quick-keyword-chip, .lang-option
) {
  transition:
    color var(--t-color),
    background-color var(--t-color),
    border-color var(--t-color),
    box-shadow var(--t-color),
    opacity var(--t-color),
    scale var(--spring-press);
}
html body :is(button, a, input[type="submit"], input[type="button"]):is(
  .btn, [class^="btn-"], [class*=" btn-"], [class^="admin-btn"], [class*=" admin-btn"],
  .sidebar-add-contact, .topbar-btn, .email-type-chip, .quick-keyword-chip, .lang-option
):active:not(:disabled, [aria-disabled="true"], .sent, .added, .loading) {
  scale: var(--press);
}

/* Hover lifts / hover scales removed from pressables (rule B4): their shadow or
   background change on hover stays as the feedback. */
html body :is(
  .btn-primary, .btn-accent, .sidebar-add-contact, .btn-ai-check,
  .login-card .btn-google, .admin-btn-success, .mob-tab-scan .mob-scan-btn, .lang-option
):hover {
  transform: none;
}
html body .mob-tab-scan:active .mob-scan-btn { transform: none; scale: var(--press); }
html body .mob-scan-btn { transition: box-shadow var(--t-color), scale var(--spring-press); }

/* Rows in a navigation list press lighter (scale.choice) and change background */
html body :is(.sidebar-item, .admin-sidebar-item, .mob-tab) {
  transition:
    color var(--t-color),
    background-color var(--t-color),
    border-color var(--t-color),
    scale var(--spring-press);
}
html body :is(.sidebar-item, .admin-sidebar-item):active { scale: var(--press-choice); }


/* ═══ 2. CARDS — surfaces lift 2px, shadow deepens (recipes/card.md) ═══════
   Shadow on transition.color, lift on spring.highlight. Hover only on fine
   pointers (rule A3); no lift under reduced motion. */
html body :is(.stat-card, .em-template-card, .login-stat) {
  transition:
    box-shadow var(--t-color),
    border-color var(--t-color),
    background-color var(--t-color),
    transform var(--spring-highlight);
}
@media (hover: hover) and (pointer: fine) {
  html body :is(.stat-card, .em-template-card, .login-stat):hover {
    transform: translateY(var(--lift));
  }
}
@media not all and (hover: hover) and (pointer: fine) {
  html body :is(.stat-card, .em-template-card, .login-stat, .login-feature):hover {
    transform: none;
  }
}
html body .login-feature {
  transition:
    background-color var(--t-color),
    border-color var(--t-color),
    transform var(--spring-highlight);
}

/* Table rows: hover highlight fades in and out instead of cutting */
html body tbody :is(tr, td) {
  transition: background-color var(--t-color);
}


/* ═══ 3. PAGE ENTRANCE — content arrives once (recipes/page.md) ════════════
   Fade on transition.reveal out of blur.icon, rise 8px on spring.entrance,
   80ms between the first blocks. The page title in the top bar is there on
   first paint, unanimated. fill-mode `backwards`: no transform left at rest. */
html body :is(.page-content, .admin-content) > :not(script, style, link, template, input[type="hidden"]) {
  animation:
    bz-fade-text var(--t-reveal) backwards,
    bz-rise var(--spring-entrance) backwards;
}
html body :is(.page-content, .admin-content) > :nth-child(2) { animation-delay: calc(var(--stagger) * 1); }
html body :is(.page-content, .admin-content) > :nth-child(3) { animation-delay: calc(var(--stagger) * 2); }
html body :is(.page-content, .admin-content) > :nth-child(4) { animation-delay: calc(var(--stagger) * 3); }
html body :is(.page-content, .admin-content) > :nth-child(n+5) { animation-delay: calc(var(--stagger) * 4); }


/* ═══ 4. MENUS & DROPDOWNS (recipes/menu.md) ═══════════════════════════════
   Opened all day: short and exact — fade + grow from scale.menu (0.9) on
   transition.menu (220ms, ease.soft), from the trigger's side. */
html body .custom-dropdown-menu {
  transform-origin: top center;
  animation: bz-menu-in var(--t-menu) backwards;
}
html body .lang-dropdown.lang-open {
  transform-origin: top right;
  animation: bz-menu-in var(--t-menu) backwards;
}


/* ═══ 5. MODALS (recipes/modal.md) ═════════════════════════════════════════
   The overlay brings its color and backdrop blur in from nothing (never its
   opacity over a backdrop blur); the dialog fades in at once and tips forward
   from perspective(500px) rotateX(-20deg) scale(0.8) on spring.dialog. */
html body :is(.wv-overlay.wv-animate-in, .import-modal-overlay.active) {
  animation: bz-overlay-in var(--t-overlay) backwards;
}
html body :is(.wv-overlay.wv-animate-in .wv-popup, .import-modal-overlay.active .import-modal) {
  animation:
    bz-fade var(--t-overlay) backwards,
    bz-dialog-tip var(--spring-dialog) backwards;
}


/* ═══ 6. TOASTS (recipes/toast.md) ═════════════════════════════════════════
   In: from its edge, out of blur.surface, growing from scale.toast on
   spring.toast. Out: fades and shrinks back into its blur in place, on
   transition.dismiss — no travel. */
html body .toast {
  transform: none;
  opacity: 1;
  transform-origin: top right;
  animation:
    bz-fade-surface var(--t-fade) backwards,
    bz-toast-in var(--spring-toast) backwards;
}
html body .toast.toast-out {
  animation: bz-toast-out var(--t-dismiss) forwards;
}

/* .ai-toast (bottom-centre, toggled with .show) */
html body .ai-toast {
  transform: translateX(-50%);
  translate: 0 100%;
  scale: var(--toast-from);
  filter: var(--blur-surface);
  transform-origin: bottom center;
  transition:
    opacity var(--t-dismiss),
    scale var(--t-dismiss),
    filter var(--t-dismiss),
    translate 0s linear 200ms; /* leaves in place, then resets off-stage */
}
html body .ai-toast.show {
  transform: translateX(-50%);
  translate: 0 0;
  scale: 1;
  filter: none;
  transition:
    opacity var(--t-fade),
    filter var(--t-fade),
    scale var(--spring-toast),
    translate var(--spring-toast);
}
@media (prefers-reduced-motion: reduce) {
  html body .ai-toast { translate: 0 0; }
}


/* ═══ 7. MOBILE SIDEBAR — a sheet (recipes/sheet.md) ═══════════════════════
   Slides in on transition.sheet (400ms, ease.soft, no bounce), leaves on
   transition.dismiss; its dim fades both ways. */
@media (max-width: 768px) {
  html body .sidebar {
    transition: transform var(--t-dismiss), box-shadow var(--t-dismiss);
  }
  html body .sidebar.mobile-open {
    transition: transform var(--t-sheet), box-shadow var(--t-sheet);
  }
  html body .sidebar-overlay {
    transition: opacity var(--t-overlay);
  }
  @starting-style {
    html body .sidebar-overlay.active { opacity: 0; }
  }
}
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  /* No slide: the sheet fades in place instead */
  html body .sidebar { transition: opacity var(--t-overlay), transform 0s linear 400ms; opacity: 0; }
  html body .sidebar.mobile-open { transition: opacity var(--t-overlay); opacity: 1; }
}


/* ═══ 8. NUMBERS — stats count up once (catalog: CountingNumber) ═══════════
   Driven by motion.js on spring.number; tabular figures so nothing jitters. */
html body :is(.stat-value, .admin-stat-value, .aud-stat-value, .stat-num) {
  font-variant-numeric: tabular-nums;
}
.bz-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}


/* ═══ 9. LOOPS (rule A4) — pause off screen / hidden tab / reduced motion ═══ */
html.bz-tab-hidden .admin-login-page::before,
html.bz-tab-hidden .admin-login-page::after,
html.bz-tab-hidden :is(.em-dot-live, .em-progress-live .em-progress-bar, .spin) {
  animation-play-state: paused;
}
@media (prefers-reduced-motion: reduce) {
  .admin-login-page::before, .admin-login-page::after, .em-dot-live {
    animation-play-state: paused;
  }
  /* A loading state keeps meaning something: slower, never frozen */
  html body .spin { animation-duration: 2.4s; }
  html body .em-progress-live .em-progress-bar { animation-duration: 3s; }
}

/* Focus ring shows at once, never animated (rule A17): box-shadow / outline
   are not transitioned while an element has keyboard focus. */
html body :is(button, a, input, select, textarea):focus-visible {
  transition:
    color var(--t-color),
    background-color var(--t-color),
    border-color var(--t-color),
    scale var(--spring-press);
}
