/* ============================================================
   Koperasi SMKSBS: motion layer.
   Sits on top of style.css / koop.css. Everything here is progressive
   enhancement: if a browser ignores a rule the site still works, and
   nothing below runs for people who ask for reduced motion.
   ============================================================ */

/* ---------- always-on polish (no motion involved) ---------- */
html { scroll-padding-top: 118px; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--azure); outline-offset: 3px; border-radius: 6px; }
img { image-rendering: auto; }

/* Closed cart drawer must not bleed its shadow onto the page edge. */
.cart-drawer:not(.open) { box-shadow: none; visibility: hidden; transition: transform var(--dur-slow) var(--ease-out), box-shadow 0s linear var(--dur-slow), visibility 0s linear var(--dur-slow); }
.cart-drawer.open { visibility: visible; transition: transform var(--dur-slow) var(--ease-out), box-shadow var(--dur-base) var(--ease-out); }

/* Admin tables: the public-site hover colour (light grey) must never reach the dark admin. */
.admin-table tr:hover { background: transparent; }
.admin-table tbody tr:hover td { background: rgba(255,255,255,.055); }
.admin-table tbody tr.row-out:hover td { background: rgba(220,70,60,.13); }
.admin-table tbody tr.row-low:hover td { background: rgba(232,135,58,.13); }

/* If JavaScript never runs, nothing may stay hidden waiting for a scroll reveal. */
html:not(.js) .reveal { opacity: 1; transform: none; }

/* ---------- motion (skipped entirely under reduced-motion) ---------- */
@media (prefers-reduced-motion: no-preference) {

  html { scroll-behavior: smooth; }

  /* --- seamless page-to-page transitions (Chrome, Edge, Safari 18.2+) ---
     The header and floating buttons stay put while only the page body cross-fades. */
  @view-transition { navigation: auto; }
  header      { view-transition-name: site-header; }
  .cart-fab   { view-transition-name: cart-fab; }
  .wa-fab     { view-transition-name: wa-fab; }
  .admin-sidebar { view-transition-name: admin-sidebar; }
  ::view-transition-group(site-header),
  ::view-transition-group(cart-fab),
  ::view-transition-group(wa-fab),
  ::view-transition-group(admin-sidebar) { animation-duration: 0s; }
  ::view-transition-old(root) { animation: koopOut 140ms var(--ease-out) both; }
  ::view-transition-new(root) { animation: koopIn 280ms var(--ease-out) 40ms both; }

  /* --- fallback fade-out for browsers without view transitions (set by motion.js) --- */
  body.is-leaving > *:not(header):not(.cart-fab):not(.wa-fab) { opacity: 0; transition: opacity 140ms ease-out; }

  /* --- hero entrance, staggered --- */
  .home-hero-text > *, .shop-banner-inner > * { animation: koopRise 700ms var(--ease-out) both; }
  .home-hero-text > :nth-child(1), .shop-banner-inner > :nth-child(1) { animation-delay: 60ms; }
  .home-hero-text > :nth-child(2), .shop-banner-inner > :nth-child(2) { animation-delay: 150ms; }
  .home-hero-text > :nth-child(3) { animation-delay: 240ms; }
  .home-hero-text > :nth-child(4) { animation-delay: 330ms; }
  .home-info { animation: koopRise 800ms var(--ease-out) 260ms both; }
  .home-hero:not(.has-banner)::before {
    content: ""; position: absolute; width: 520px; height: 520px; right: -140px; top: -220px; border-radius: 50%;
    background: radial-gradient(closest-side, rgba(255,255,255,.75), rgba(255,255,255,0));
    animation: koopFloat 14s ease-in-out infinite alternate; pointer-events: none;
  }
  .home-hero.has-banner { background-attachment: scroll; }

  /* --- header: lifts when you scroll (class set by motion.js) --- */
  header { transition: box-shadow 260ms var(--ease-out), background-color 260ms; }
  header.is-scrolled { box-shadow: 0 10px 30px -12px rgba(8,27,54,.28); }
  header .header-inner { transition: padding 260ms var(--ease-out); }
  header.is-scrolled .header-inner { padding-top: 11px; padding-bottom: 11px; }
  .crest img { transition: transform 420ms var(--ease-spring); }
  .crest:hover img { transform: rotate(-6deg) scale(1.06); }

  /* --- scroll progress bar --- */
  .koop-progress { position: fixed; left: 0; top: 0; height: 3px; width: 100%; z-index: 120; transform-origin: 0 50%; transform: scaleX(0);
    background: linear-gradient(90deg, var(--azure), var(--gold)); pointer-events: none; }

  /* --- nav links: underline slides in --- */
  .navbtn { position: relative; }
  .navbtn::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 6px; height: 2px; border-radius: 2px;
    background: var(--azure); transform: scaleX(0); transform-origin: 0 50%; transition: transform 300ms var(--ease-out); }
  .navitem:not(.current) .navbtn:hover::after { transform: scaleX(1); }

  /* --- cards: smooth hover everywhere, image zoom, press feedback --- */
  .quick-card, .act-card, .org-node, .stat { transition: transform 320ms var(--ease-out), box-shadow 320ms var(--ease-out), border-color 200ms var(--ease-out); }
  .act-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); }
  .org-node:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
  .sp-image img, .act-img img { transition: transform 700ms var(--ease-out), opacity 500ms ease-out; }
  .shop-product:hover .sp-image img, .act-card:hover .act-img img { transform: scale(1.06); }
  .sp-image svg, .set-num { transition: transform 500ms var(--ease-spring); }
  .shop-product:hover .sp-image svg, .shop-product:hover .set-num { transform: scale(1.12) rotate(-4deg); }
  .shop-product.is-out:hover { transform: none; box-shadow: var(--shadow-xs); }
  .shop-cat-pill, .sp-size-pill, .sp-qty button { transition: background-color 180ms, color 180ms, border-color 180ms, transform 180ms var(--ease-spring); }
  .shop-cat-pill:hover, .sp-size-pill:hover { transform: translateY(-2px); }
  .shop-cat-pill:active, .sp-size-pill:active, .sp-qty button:active { transform: scale(.92); }
  .cta-btn { transition: transform 240ms var(--ease-spring), box-shadow 240ms; }
  .cta-btn:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 14px 28px rgba(0,0,0,.22); }
  .cta-band { position: relative; overflow: hidden; }
  .cta-band::before { content: ""; position: absolute; inset: -40% auto -40% -30%; width: 40%; transform: rotate(18deg);
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.16), transparent); animation: koopSweep 7s ease-in-out infinite; pointer-events: none; }
  .link-arrow svg, .quick-arrow svg { transition: transform 260ms var(--ease-out); }
  .link-arrow:hover svg, .quick-card:hover .quick-arrow svg { transform: translateX(5px); }

  /* --- stock badge: low stock breathes gently --- */
  .stk.low { animation: koopBreathe 2.4s ease-in-out infinite; }

  /* --- images fade in once loaded (class set by motion.js, only on images still loading) --- */
  img.koop-fade { opacity: 0; }
  img.koop-fade.is-loaded { opacity: 1; }

  /* --- fly-to-cart dot --- */
  .koop-fly { position: fixed; top: 0; left: 0; z-index: 130; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; pointer-events: none;
    background: radial-gradient(circle at 35% 30%, #fff, var(--azure) 60%); box-shadow: 0 6px 16px rgba(201,106,31,.5); }
  .cart-fab.bump { animation: cartBump 520ms var(--ease-spring); }

  /* --- cart drawer & checkout: items glide in one after another --- */
  .cart-line:nth-child(2) { animation-delay: 40ms; }
  .cart-line:nth-child(3) { animation-delay: 80ms; }
  .cart-line:nth-child(4) { animation-delay: 120ms; }
  .cart-line:nth-child(n+5) { animation-delay: 160ms; }
  .set-modal { animation: koopFade 200ms ease-out both; }
  .set-modal-card { animation: koopPop 360ms var(--ease-spring) both; }
  .koop-toast { transition: opacity 280ms, transform 380ms var(--ease-spring); }

  /* --- admin --- */
  .admin-card, .admin-stat { animation: koopRise 520ms var(--ease-out) both; }
  .admin-stat-grid .admin-stat:nth-child(2) { animation-delay: 60ms; }
  .admin-stat-grid .admin-stat:nth-child(3) { animation-delay: 120ms; }
  .admin-stat-grid .admin-stat:nth-child(4) { animation-delay: 180ms; }
  .admin-stat-grid .admin-stat:nth-child(5) { animation-delay: 240ms; }
  .admin-stat { transition: transform 260ms var(--ease-out), border-color 260ms; }
  .admin-stat:hover { transform: translateY(-3px); border-color: rgba(232,135,58,.45); }
  .admin-flash { animation: koopDrop 420ms var(--ease-spring) both; }
  .admin-table tbody tr { transition: background-color 160ms; }
  .admin-nav a { transition: background-color 160ms, color 160ms, padding-left 220ms var(--ease-out); }
  .admin-nav a:hover { padding-left: 16px; }
  .bar-row .bar i { transform-origin: 0 50%; animation: koopGrow 900ms var(--ease-out) 150ms both; }
  .nav-badge { animation: koopBreathe 1.8s ease-in-out infinite; }

  /* --- keyframes --- */
  @keyframes koopIn      { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
  @keyframes koopOut     { from { opacity: 1; } to { opacity: 0; } }
  @keyframes koopRise    { from { opacity: 0; transform: translateY(22px); } to { opacity: 1; transform: none; } }
  @keyframes koopFade    { from { opacity: 0; } to { opacity: 1; } }
  @keyframes koopPop     { from { opacity: 0; transform: translateY(16px) scale(.94); } to { opacity: 1; transform: none; } }
  @keyframes koopDrop    { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
  @keyframes koopGrow    { from { transform: scaleX(0); } to { transform: scaleX(1); } }
  @keyframes koopFloat   { from { transform: translate(0,0) scale(1); } to { transform: translate(-60px, 50px) scale(1.12); } }
  @keyframes koopSweep   { 0%, 55% { left: -30%; } 100% { left: 140%; } }
  @keyframes koopBreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
}

/* Reduced motion: keep the layout, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .koop-progress, .koop-fly { display: none !important; }
  img.koop-fade { opacity: 1; }
  /* Safety net: also calms the older animations in style.css (floating icons, blobs, pulses). */
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
