/* KD Motion (2026-12-03): the website moves like a phone app.
 * - Page changes slide (forward = from the right, Back = from the left); the top bar, side menu and bottom tabs stay put.
 * - A thin loading bar while the next page or a form is on its way; buttons press in when tapped.
 * - Panels rise in gently, one after another, when a page opens.
 * Everything here is switched off for people who ask their phone for less motion. */

@view-transition { navigation: auto; }

/* App chrome holds still while the page under it moves */
.admin-mobile-logo-bar, .kdn-top, #mainNav { view-transition-name: kd-top; }
.admin-mobile-nav, .kdn-tabbar { view-transition-name: kd-tabs; }
aside.sidebar { view-transition-name: kd-side; }
::view-transition-group(kd-top), ::view-transition-group(kd-tabs), ::view-transition-group(kd-side) { animation-duration: 0s; }
::view-transition-old(kd-top), ::view-transition-old(kd-tabs), ::view-transition-old(kd-side) { display: none; }
::view-transition-new(kd-top), ::view-transition-new(kd-tabs), ::view-transition-new(kd-side) { animation: none; }

::view-transition-old(root) { animation: kdmOut .26s cubic-bezier(.4, 0, 1, 1) both; }
::view-transition-new(root) { animation: kdmIn .34s cubic-bezier(.2, .8, .2, 1) both; }
html:active-view-transition-type(kd-back)::view-transition-old(root) { animation-name: kdmOutBack; }
html:active-view-transition-type(kd-back)::view-transition-new(root) { animation-name: kdmInBack; }
@keyframes kdmIn      { from { opacity: 0; transform: translateX(32px); } }
@keyframes kdmOut     { to   { opacity: 0; transform: translateX(-24px); } }
@keyframes kdmInBack  { from { opacity: 0; transform: translateX(-32px); } }
@keyframes kdmOutBack { to   { opacity: 0; transform: translateX(24px); } }
@media (min-width: 900px) {   /* big screens: a quieter fade with a small lift */
  @keyframes kdmIn      { from { opacity: 0; transform: translateY(6px); } }
  @keyframes kdmOut     { to   { opacity: 0; } }
  @keyframes kdmInBack  { from { opacity: 0; transform: translateY(-6px); } }
  @keyframes kdmOutBack { to   { opacity: 0; } }
}

/* Loading: the gold KD logo fills up from the bottom (shown only when a page takes more than ~0.35 s) */
#kdm-load { position: fixed; inset: 0; z-index: 2147483000; display: grid; place-items: center; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility 0s linear .2s; }
#kdm-load::before { content: ''; position: absolute; inset: 0;
  background: color-mix(in oklch, var(--kd-bg, #f6f7fb) 45%, transparent); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
#kdm-load.on { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .25s ease .35s, visibility 0s linear .35s; }
.kdm-logo { position: relative; width: 92px; height: 82px; filter: drop-shadow(0 8px 22px rgba(201, 150, 40, .28)); }
.kdm-logo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; -webkit-user-drag: none; }
.kdm-logo .kdm-empty { filter: grayscale(1) brightness(1.1); opacity: .3; }
.kdm-logo .kdm-full { clip-path: inset(100% 0 0 0); }
#kdm-load.on .kdm-full { animation: kdmFill 1.5s cubic-bezier(.55, .1, .35, 1) .35s infinite; }
#kdm-load.on .kdm-logo { animation: kdmGlow 1.5s ease-in-out .35s infinite; }
.kdm-logo .kdm-shine { position: absolute; inset: 0; pointer-events: none;
  -webkit-mask: var(--kdm-logo) center / contain no-repeat; mask: var(--kdm-logo) center / contain no-repeat;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .85) 50%, transparent 65%) -120% 0 / 250% 100% no-repeat; }
#kdm-load.on .kdm-shine { animation: kdmShine 1.5s ease-in-out .35s infinite; }
@keyframes kdmFill { 0% { clip-path: inset(100% 0 0 0); } 62%, 82% { clip-path: inset(0 0 0 0); } 100% { clip-path: inset(0 0 0 0); opacity: .0; } }
@keyframes kdmGlow { 0%, 100% { transform: scale(1); } 70% { transform: scale(1.045); } }
@keyframes kdmShine { 0%, 55% { background-position: -120% 0; } 85%, 100% { background-position: 220% 0; } }
html[data-bs-theme=dark] #kdm-load::before { background: color-mix(in oklch, var(--kd-bg, #0b0f17) 60%, transparent); }

/* Tap feel */
html { -webkit-tap-highlight-color: transparent; }
a, button, [role=button], input[type=submit], label { touch-action: manipulation; }
:is(button, .btn, [role=button], input[type=submit], .btn-primary, .kd-wz-choice, .admin-mobile-nav a, .kdn-tabbar a) {
  transition: transform .12s ease, opacity .12s ease, background-color .15s, border-color .15s, box-shadow .15s;
}
:is(button, .btn, [role=button], input[type=submit], .btn-primary):active:not(:disabled) { transform: scale(.97); }
:is(.admin-mobile-nav a, .kdn-tabbar a):active { transform: scale(.9); }
a.premium-card:active, a.kd2-panel:active, a.card:active, .premium-card > a:only-child:active { transform: scale(.985); }
a.premium-card, a.kd2-panel, a.card { transition: transform .15s ease, box-shadow .15s; }

/* A pressed submit button shows it is working */
.kdm-busy { position: relative; pointer-events: none; opacity: .85; }
.kdm-busy::after { content: ''; display: inline-block; width: 1em; height: 1em; margin-left: .5em; vertical-align: -0.15em;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: kdmSpin .7s linear infinite; }
@keyframes kdmSpin { to { transform: rotate(360deg); } }

/* Panels rise in one after another */
html.kdm-enter :is(.main-content, main) > :is(.premium-card, .kd2-panel, .card, .row, section, .kd-wz, form, .stat-grid, .grid):nth-child(-n+10),
html.kdm-enter :is(.main-content, main) > :is(div, section) > :is(.premium-card, .kd2-panel, .card, .stat-card):nth-child(-n+10) {
  animation: kdmRise .42s cubic-bezier(.2, .8, .2, 1) both;
}
html.kdm-enter :is(.main-content, main) > :nth-child(2) { animation-delay: .03s; }
html.kdm-enter :is(.main-content, main) > :nth-child(3) { animation-delay: .06s; }
html.kdm-enter :is(.main-content, main) > :nth-child(4) { animation-delay: .09s; }
html.kdm-enter :is(.main-content, main) > :nth-child(5) { animation-delay: .12s; }
html.kdm-enter :is(.main-content, main) > :nth-child(n+6) { animation-delay: .15s; }
html.kdm-enter :is(.main-content, main) > :is(div, section) > :nth-child(2) { animation-delay: .04s; }
html.kdm-enter :is(.main-content, main) > :is(div, section) > :nth-child(3) { animation-delay: .08s; }
html.kdm-enter :is(.main-content, main) > :is(div, section) > :nth-child(n+4) { animation-delay: .12s; }
@keyframes kdmRise { from { opacity: 0; transform: translateY(10px); } }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  html.kdm-enter * { animation: none !important; }
  :is(button, .btn, [role=button], input[type=submit], .btn-primary, a):active { transform: none !important; }
  #kdm-load.on .kdm-full, #kdm-load.on .kdm-logo, #kdm-load.on .kdm-shine { animation: none; clip-path: none; }
}
@media print { #kdm-load { display: none !important; } }
