/* =========================================================
   Affinity Smart POS – animation system  (public/css/animations.css)
   Load after pos.css.

   1. Automatic: page entrance, cards, tables, menus, buttons,
      inputs, tabs, charts and toasts animate by themselves.
   2. Opt-in classes: add them to any element (see /components).
   3. JavaScript helpers: POS.animate, POS.loading, POS.loader ...
   Everything switches off for people who prefer reduced motion.
   ========================================================= */

:root {
    --ease: cubic-bezier(.22, 1, .36, 1);          /* smooth, soft landing */
    --ease-bounce: cubic-bezier(.34, 1.56, .64, 1); /* small overshoot */
    --dur: .6s;
    --delay: 0s;
}

/* ---------- Keyframes ---------- */
@keyframes fadeIn      { from { opacity: 0; } }
@keyframes riseIn      { from { opacity: 0; transform: translateY(24px); } }
@keyframes dropIn      { from { opacity: 0; transform: translateY(-24px); } }
@keyframes slideInLeft { from { opacity: 0; transform: translateX(-34px); } }
@keyframes slideInRight{ from { opacity: 0; transform: translateX(34px); } }
@keyframes zoomIn      { from { opacity: 0; transform: scale(.86); } }
@keyframes popIn       { 0% { opacity: 0; transform: scale(.55); } 60% { opacity: 1; transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes spin        { to { transform: rotate(360deg); } }
@keyframes pulse       { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
@keyframes floatY      { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes wiggle      { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-7deg); } 75% { transform: rotate(7deg); } }
@keyframes bounceY     { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-16px); } 60% { transform: translateY(-5px); } }
@keyframes shake       { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes shimmer     { to { background-position: -200% 0; } }
@keyframes shimmerText { to { background-position: -200% 0; } }
@keyframes drawStroke  { to { stroke-dashoffset: 0; } }
@keyframes lineGrow    { to { transform: scaleX(1); } }
@keyframes ringOut     { 0% { transform: scale(.6); opacity: .8; } 100% { transform: scale(2.2); opacity: 0; } }
@keyframes dotBounce   { 0%, 80%, 100% { transform: scale(.55); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }
@keyframes barDance    { 0%, 100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }
@keyframes indeterminate { 0% { left: -40%; } 100% { left: 100%; } }
@keyframes rippleOut   { from { transform: scale(0); opacity: .3; } to { transform: scale(1); opacity: 0; } }
@keyframes exitOut     { to { opacity: 0; transform: translateX(26px) scale(.97); } }
@keyframes toastBar    { from { width: 100%; } to { width: 0; } }
@keyframes menuIn      { from { opacity: 0; translate: 0 -8px; scale: .96; } }
@keyframes menuItemIn  { from { opacity: 0; translate: -8px 0; } }
@keyframes dotGlow     { 0%, 100% { box-shadow: 0 0 0 0 rgba(240, 108, 26, .55); } 70% { box-shadow: 0 0 0 9px rgba(240, 108, 26, 0); } }

/* ---------- 1. Automatic animations ---------- */
.stage { animation: riseIn .55s var(--ease) backwards; }

/* Children of .bento and .stagger rise in one after another */
:is(.bento, .stagger) > :not(.reveal) {
    animation: riseIn var(--dur) var(--ease) backwards;
    animation-delay: calc(var(--i, 0) * 70ms);
}
:is(.bento, .stagger) > :nth-child(1)  { --i: 0; }
:is(.bento, .stagger) > :nth-child(2)  { --i: 1; }
:is(.bento, .stagger) > :nth-child(3)  { --i: 2; }
:is(.bento, .stagger) > :nth-child(4)  { --i: 3; }
:is(.bento, .stagger) > :nth-child(5)  { --i: 4; }
:is(.bento, .stagger) > :nth-child(6)  { --i: 5; }
:is(.bento, .stagger) > :nth-child(7)  { --i: 6; }
:is(.bento, .stagger) > :nth-child(8)  { --i: 7; }
:is(.bento, .stagger) > :nth-child(9)  { --i: 8; }
:is(.bento, .stagger) > :nth-child(10) { --i: 9; }
:is(.bento, .stagger) > :nth-child(11) { --i: 10; }
:is(.bento, .stagger) > :nth-child(12) { --i: 11; }

/* Table rows */
.pos-table tbody tr { animation: riseIn .5s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 50ms + .2s); transition: background .2s; }
.pos-table tbody tr:hover { background: var(--accent-soft); }
.pos-table tbody tr:nth-child(1) { --i: 0; } .pos-table tbody tr:nth-child(2) { --i: 1; }
.pos-table tbody tr:nth-child(3) { --i: 2; } .pos-table tbody tr:nth-child(4) { --i: 3; }
.pos-table tbody tr:nth-child(5) { --i: 4; } .pos-table tbody tr:nth-child(6) { --i: 5; }
.pos-table tbody tr:nth-child(7) { --i: 6; } .pos-table tbody tr:nth-child(8) { --i: 7; }

/* Charts fade in as they draw */
.chart-box { animation: fadeIn .8s .25s backwards; }

/* Buttons */
.btn-pos { transition: transform .22s var(--ease), box-shadow .25s var(--ease), background-color .2s, opacity .2s, border-color .2s; }
.btn-pos:hover { transform: translateY(-2px); }
.btn-pos:active { transform: scale(.96); }
.btn-pos.accent { box-shadow: var(--glow-sm); }
.btn-pos.accent:hover { box-shadow: var(--glow); }
.btn-pos i { transition: transform .3s var(--ease-bounce); }
.btn-pos:hover i { transform: scale(1.18) rotate(-6deg); }
.btn-pos:disabled, .btn-pos:disabled:hover { transform: none; }

/* Navigation */
.tabs { position: relative; }
.tab i, .bottom-tabs a i { transition: transform .35s var(--ease-bounce); }
.tab:hover i { transform: translateY(-2px) scale(1.15); }
.bottom-tabs a.is-active i { animation: popIn .45s var(--ease-bounce); }
.round-btn, .avatar { transition: transform .25s var(--ease-bounce), border-color .2s; }
#themeToggle i { display: inline-block; transition: transform .5s var(--ease); }
#themeToggle:hover i { transform: rotate(35deg) scale(1.1); }
.logo-mark { transition: transform .45s var(--ease-bounce); }
.logo:hover .logo-mark { transform: rotate(-9deg) scale(1.1); }

/* Sliding pill used by .tabs and .seg (placed by pos.js) */
.tab-indicator {
    position: absolute;
    top: var(--ind-pad, 5px);
    bottom: var(--ind-pad, 5px);
    left: 0;
    width: 0;
    z-index: 0;
    background: var(--accent);
    border-radius: 999px;
    box-shadow: var(--glow-sm);
    opacity: 0;
    pointer-events: none;
    transition: transform .45s var(--ease), width .45s var(--ease), opacity .2s;
}
[data-indicator]:not(.has-indicator) > .is-active { background: var(--accent); color: var(--on-accent); }

/* Segmented control */
.seg { --ind-pad: 4px; position: relative; display: inline-flex; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
.seg > button {
    position: relative;
    z-index: 1;
    height: 38px;
    padding: 0 18px;
    font: inherit;
    font-weight: 500;
    color: var(--muted);
    background: none;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    transition: color .25s;
}
.seg > button:hover { color: var(--ink); }
.seg > button.is-active { color: var(--on-accent); font-weight: 600; }

/* Dropdown menus (uses translate/scale so Popper positioning is not disturbed) */
.pos-menu.show { animation: menuIn .24s var(--ease) backwards; transform-origin: top right; }
.pos-menu.show > li, .pos-menu.show > .dropdown-item, .pos-menu.show > .dropdown-header { animation: menuItemIn .32s var(--ease) backwards; animation-delay: calc(var(--n, 0) * 45ms + 60ms); }
.pos-menu > :nth-child(1) { --n: 0; } .pos-menu > :nth-child(2) { --n: 1; } .pos-menu > :nth-child(3) { --n: 2; }
.pos-menu > :nth-child(4) { --n: 3; } .pos-menu > :nth-child(5) { --n: 4; } .pos-menu > :nth-child(6) { --n: 5; }
.pos-menu .dropdown-item { transition: background .2s, padding-left .25s var(--ease); }
.pos-menu .dropdown-item:hover { padding-left: 17px; }

/* Inputs */
.form-control, .form-select, .disc-input, .search input {
    transition: border-color .2s, box-shadow .3s var(--ease), background-color .2s, width .3s var(--ease);
}
.form-control:focus, .form-select:focus, .disc-input:focus, .search input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}
.search i { transition: color .2s, transform .3s var(--ease-bounce); }
.search:focus-within i { color: var(--accent); transform: translateY(-50%) scale(1.15); }

/* Product cards, chips and misc controls */
.p-card, .cat-chip, .pay-methods button, .quick-cash button, .stepper button { transition: transform .2s var(--ease), background-color .2s, color .2s, border-color .2s, box-shadow .25s var(--ease); }
.p-card:hover { box-shadow: 0 20px 36px -18px rgba(240, 108, 26, .45); }
.p-icon { transition: transform .35s var(--ease-bounce); }
.p-card:hover .p-icon { transform: scale(1.08) rotate(-4deg); }
.pay-methods button:active, .cat-chip:active, .quick-cash button:active { transform: scale(.94); }
.stepper span { transition: transform .2s var(--ease-bounce); }
.cart-bar { animation: popIn .45s var(--ease-bounce) backwards; }

/* Messages and toasts */
.flash { animation: dropIn .5s var(--ease) backwards; }
.pos-toast { position: relative; overflow: hidden; }
.pos-toast::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); animation: toastBar 3.5s linear forwards; }

/* Smooth light/dark switch (class added by pos.js for half a second) */
html.theme-fade *, html.theme-fade *::before, html.theme-fade *::after {
    transition: background-color .4s ease, color .4s ease, border-color .4s ease, fill .4s ease, stroke .4s ease !important;
}

/* ---------- 2. Opt-in classes ---------- */

/* Entrance (play once) */
.anim-fade  { animation: fadeIn       var(--dur) var(--ease) var(--delay) backwards; }
.anim-up    { animation: riseIn       var(--dur) var(--ease) var(--delay) backwards; }
.anim-down  { animation: dropIn       var(--dur) var(--ease) var(--delay) backwards; }
.anim-left  { animation: slideInLeft  var(--dur) var(--ease) var(--delay) backwards; }
.anim-right { animation: slideInRight var(--dur) var(--ease) var(--delay) backwards; }
.anim-zoom  { animation: zoomIn       var(--dur) var(--ease) var(--delay) backwards; }
.anim-pop   { animation: popIn        var(--dur) var(--ease-bounce) var(--delay) backwards; }
.anim-shake { animation: shake .5s ease backwards; }
.anim-out   { animation: exitOut .35s var(--ease) both; pointer-events: none; }

/* Speed and delay modifiers */
.anim-fast { --dur: .3s; }
.anim-slow { --dur: 1.1s; }
.anim-delay-1 { --delay: .1s; } .anim-delay-2 { --delay: .2s; } .anim-delay-3 { --delay: .3s; }
.anim-delay-4 { --delay: .4s; } .anim-delay-5 { --delay: .5s; } .anim-delay-6 { --delay: .6s; }

/* Continuous */
.anim-pulse  { animation: pulse 1.8s ease-in-out infinite; }
.anim-float  { animation: floatY 3.2s ease-in-out infinite; }
.anim-wiggle { animation: wiggle 1.2s ease-in-out infinite; }
.anim-bounce { animation: bounceY 1.4s ease infinite; }
.anim-spin   { animation: spin 1.2s linear infinite; }

/* Scroll reveal (pos.js adds .is-visible when the element enters the screen) */
.js .reveal       { opacity: 0; transform: translateY(28px); transition: opacity .8s var(--ease), transform .8s var(--ease); transition-delay: var(--delay); }
.js .reveal-left  { transform: translateX(-36px); }
.js .reveal-right { transform: translateX(36px); }
.js .reveal-zoom  { transform: scale(.9); }
.js .reveal.is-visible { opacity: 1; transform: none; }

/* Hover and press effects */
.hover-lift { transition: transform .3s var(--ease), box-shadow .3s var(--ease); }
.hover-lift:hover { transform: translateY(-7px); box-shadow: 0 26px 44px -20px rgba(32, 35, 43, .3); }
.hover-glow { transition: box-shadow .3s var(--ease), transform .3s var(--ease); }
.hover-glow:hover { transform: translateY(-3px); box-shadow: var(--glow); }
.hover-grow { transition: transform .3s var(--ease-bounce); }
.hover-grow:hover { transform: scale(1.05); }
.press { transition: transform .15s var(--ease); }
.press:active { transform: scale(.95); }

/* Links with a growing underline */
.link-anim { background: linear-gradient(var(--accent), var(--accent)) left bottom / 0 2px no-repeat; transition: background-size .35s var(--ease), color .2s; padding-bottom: 2px; }
.link-anim:hover { background-size: 100% 2px; color: var(--accent); }

/* Headings */
.title-underline { position: relative; display: inline-block; }
.title-underline::after { content: ""; position: absolute; left: 0; bottom: -8px; width: 100%; height: 5px; background: var(--accent); border-radius: 5px; transform: scaleX(0); transform-origin: left; animation: lineGrow .8s .3s var(--ease) forwards; }
.text-shimmer { background: linear-gradient(90deg, var(--ink) 0%, var(--accent) 45%, var(--ink) 90%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmerText 3.5s linear infinite; }

/* Badges and labels */
.badge-pos.pop { animation: popIn .5s var(--ease-bounce) backwards; }
.badge-pos.live { display: inline-flex; align-items: center; gap: 7px; background: var(--accent-soft); }
.badge-pos.live::before { content: ""; width: 8px; height: 8px; background: var(--accent); border-radius: 50%; animation: dotGlow 1.6s ease-out infinite; }

/* Floating-label field:  <div class="float-field"><input class="form-control" placeholder=" "><label>Name</label></div> */
.float-field { position: relative; }
.float-field > label {
    position: absolute;
    left: 14px;
    top: 13px;
    padding: 0 6px;
    color: var(--muted);
    background: transparent;
    pointer-events: none;
    transform-origin: left;
    transition: top .22s var(--ease), font-size .22s var(--ease), color .2s, background-color .2s;
}
.float-field > .form-control:focus + label,
.float-field > .form-control:not(:placeholder-shown) + label { top: -10px; font-size: 12.5px; font-weight: 600; background: var(--card); }
.float-field > .form-control:focus + label { color: var(--accent); }

/* Switch:  <label class="switch"><input type="checkbox"><span></span></label> */
.switch { position: relative; display: inline-block; width: 52px; height: 30px; margin: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background-color .3s var(--ease); }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); transition: transform .35s var(--ease-bounce); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 3px; }

/* Ripple (added by pos.js to buttons) */
.ripple-host { position: relative; overflow: hidden; }
.ripple { position: absolute; border-radius: 50%; background: currentColor; pointer-events: none; animation: rippleOut .65s ease-out forwards; }

/* ---------- Loading and processing ---------- */
.spinner {
    --s: 28px;
    display: inline-block;
    width: var(--s);
    height: var(--s);
    vertical-align: middle;
    border: calc(var(--s) / 9) solid color-mix(in srgb, var(--accent) 22%, transparent);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .75s linear infinite;
}
.spinner-sm { --s: 18px; }
.spinner-lg { --s: 52px; }

.dots { display: inline-flex; gap: 6px; vertical-align: middle; }
.dots i { width: 10px; height: 10px; background: var(--accent); border-radius: 50%; animation: dotBounce 1.2s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }

.bars { display: inline-flex; align-items: center; gap: 4px; height: 30px; vertical-align: middle; }
.bars i { width: 5px; height: 100%; background: var(--accent); border-radius: 3px; animation: barDance 1s ease-in-out infinite; }
.bars i:nth-child(2) { animation-delay: .12s; } .bars i:nth-child(3) { animation-delay: .24s; } .bars i:nth-child(4) { animation-delay: .36s; }

.pulse-ring { position: relative; display: inline-block; width: 18px; height: 18px; background: var(--accent); border-radius: 50%; }
.pulse-ring::before, .pulse-ring::after { content: ""; position: absolute; inset: 0; border: 2px solid var(--accent); border-radius: 50%; animation: ringOut 1.8s ease-out infinite; }
.pulse-ring::after { animation-delay: .9s; }

.progress-anim { position: relative; height: 12px; overflow: hidden; background: var(--lilac); border-radius: 999px; }
.progress-anim > span { display: block; width: var(--value, 0%); height: 100%; background: var(--accent); border-radius: 999px; transition: width 1s var(--ease); }
.progress-anim.indeterminate > span { position: absolute; width: 40%; animation: indeterminate 1.3s ease-in-out infinite; }

.skeleton { color: transparent !important; background: linear-gradient(90deg, var(--line) 25%, color-mix(in srgb, var(--line) 35%, var(--card)) 50%, var(--line) 75%); background-size: 200% 100%; border-radius: 10px; animation: shimmer 1.4s linear infinite; }
.skeleton-line { height: 14px; margin: 9px 0; }
.skeleton-circle { width: 48px; height: 48px; border-radius: 50%; }
.skeleton-block { height: 110px; border-radius: 16px; }

.check-anim { width: 64px; height: 64px; }
.check-anim circle { fill: none; stroke: var(--ok); stroke-width: 3; stroke-dasharray: 151; stroke-dashoffset: 151; animation: drawStroke .6s ease forwards; }
.check-anim path { fill: none; stroke: var(--ok); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; animation: drawStroke .4s .45s ease forwards; }

/* Button loading state: POS.loading($btn, true) */
.btn-pos { --spin: var(--bg); }
.btn-pos.accent { --spin: var(--on-accent); }
.btn-pos.ghost { --spin: var(--ink); }
.btn-pos.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn-pos.is-loading > * { visibility: hidden; }
.btn-pos.is-loading::after { content: ""; position: absolute; width: 22px; height: 22px; top: 50%; left: 50%; margin: -11px 0 0 -11px; border: 3px solid color-mix(in srgb, var(--spin) 30%, transparent); border-top-color: var(--spin); border-radius: 50%; animation: spin .7s linear infinite; }

/* Full-screen loader: POS.loader.show('Processing payment') */
.page-loader { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(7px); opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s; }
.page-loader.show { opacity: 1; visibility: visible; }
.loader-card { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 34px 44px; background: var(--card); border-radius: 26px; box-shadow: var(--shadow); transform: scale(.9); transition: transform .4s var(--ease-bounce); }
.page-loader.show .loader-card { transform: none; }
.loader-card p { margin: 0; font-weight: 600; }

/* Thin bar at the top of the screen: POS.progress.start() / .done() */
.top-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 3100; pointer-events: none; opacity: 0; transition: opacity .3s; }
.top-progress.on { opacity: 1; }
.top-progress > span { display: block; width: 0; height: 100%; background: var(--accent); box-shadow: 0 0 10px var(--accent); transition: width .3s var(--ease); }

/* ---------- Reduced motion ---------- */
/* pos.css switches animation off for everyone who asks for less motion.
   Loading indicators still turn (slowly) so people can see that something is happening. */
@media (prefers-reduced-motion: reduce) {
    .js .reveal { opacity: 1; transform: none; }
    .spinner, .btn-pos.is-loading::after { animation: spin 1.6s linear infinite !important; }
    .progress-anim.indeterminate > span { animation: indeterminate 2.6s ease-in-out infinite !important; }
}