/*
 * Maison Jaheena — motion.
 * Page transitions (View Transitions API), scroll reveals and micro-interactions.
 * Everything here is progressive: without support, or with "reduce motion", pages simply appear.
 */
:root {
  --ease-out: cubic-bezier(.2, .7, .2, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);
  interpolate-size: allow-keywords;
}

a, button, label, summary { -webkit-tap-highlight-color: transparent; }

/* ——— Horizontal scrollers (mobile tabs, thumbnails) ——— */
.gallery__thumbs { overscroll-behavior: contain; scroll-snap-type: y proximity; }
.gallery__thumbs button { scroll-snap-align: start; }

@media (max-width: 900px) {
  .gallery__thumbs { scroll-snap-type: x mandatory; scrollbar-width: none; }
  .gallery__thumbs::-webkit-scrollbar { display: none; }
}

@media (max-width: 720px) {
  .chips {
    flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; scrollbar-width: none;
    margin-inline: calc(-1 * var(--gutter)); padding: 2px var(--gutter);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent);
            mask-image: linear-gradient(90deg, transparent, #000 var(--gutter), #000 calc(100% - var(--gutter)), transparent);
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; scroll-snap-align: center; }
  .shop-toolbar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .shop-toolbar .sort-form { align-self: flex-end; }
}

/* ——— Navigation progress bar ——— */
.nav-progress {
  position: fixed; inset: 0 0 auto; z-index: 100; height: 2px; pointer-events: none;
  background: linear-gradient(90deg, var(--gold-soft), var(--gold));
  transform: scaleX(0); transform-origin: 0 50%; opacity: 0;
}
.nav-progress.is-active { opacity: 1; transform: scaleX(.85); transition: transform 8s cubic-bezier(.1, .8, .2, 1), opacity .2s; }

/* ——— Catalogue filtered in place (assets/app.js, "catalog") ——— */
.product-grid > .card[hidden] { display: none; }
.catalog-leaving { position: fixed; z-index: 0; margin: 0; pointer-events: none; }
.product-grid > .card.is-moving { z-index: 1; }

/* ——— Page swaps (assets/app.js) ——— */
/* The previous page's content, fading out above the new one. */
.nav-leaving { position: fixed; z-index: 30; margin: 0; pointer-events: none; }
/* A product photo flying between a card and the product page. */
.morph { position: fixed; z-index: 45; margin: 0; object-fit: cover; object-position: top; transform-origin: 0 0; pointer-events: none; border-radius: var(--radius); }
/* Cards leaving the grid, fading where they were. */
.grid-ghost { position: fixed; z-index: 20; margin: 0; pointer-events: none; }
/* Moving content into a leaving layer re-inserts it: its entrance animations must not replay. */
.nav-leaving *, .grid-ghost, .grid-ghost *, .catalog-leaving, .catalog-leaving * { animation: none !important; transition: none !important; }
/* The selected tab's pill gliding to the newly selected tab. */
.chips, .admin-nav { position: relative; isolation: isolate; }
.glider { position: absolute; z-index: -1; pointer-events: none; }
@media (min-width: 961px) { .site-nav { position: relative; } }
.glider--line { z-index: 0; }
.is-gliding > .is-active { background: transparent !important; border-color: transparent !important; transition: none !important; }

/* ——— Checkout: the address block unfolds ——— */
.shipping-fields { display: grid; grid-template-rows: 1fr; }
.shipping-fields__inner { min-height: 0; overflow: hidden; }
.shipping-fields.is-collapsed { grid-template-rows: 0fr; opacity: 0; margin-top: 0 !important; }

@media (prefers-reduced-motion: no-preference) {
  /* ——— Entrances (after a page swap, and on first load) ——— */
  .page-hero > *, .product__info > *, .confirmation > *, .results-count { animation: .6s var(--ease-out) both mj-rise; }
  .page-hero > :nth-child(2), .product__info > :nth-child(2), .confirmation > :nth-child(2) { animation-delay: .04s; }
  .page-hero > :nth-child(3), .product__info > :nth-child(3), .confirmation > :nth-child(3) { animation-delay: .08s; }
  .product__info > :nth-child(4), .confirmation > :nth-child(4) { animation-delay: .12s; }
  .product__info > :nth-child(n + 5) { animation-delay: .16s; }
  @keyframes mj-rise { from { opacity: 0; transform: translateY(10px); } }

  /* Scroll reveals (classes set by app.js on elements below the fold). */
  .will-reveal { opacity: 0; transform: translateY(28px); }
  /* Table rows only fade: sliding up from below would overflow their table's box. */
  .table tbody tr.will-reveal { transform: none; }
  .will-reveal.is-revealed {
    opacity: 1; transform: none;
    transition: opacity .9s var(--ease-out), transform 1s var(--ease-out);
    transition-delay: var(--reveal-delay, 0s);
  }

  /* Photos fade in once decoded instead of popping. */
  img.is-pending { opacity: 0; }
  img.is-loaded { transition: opacity .7s var(--ease-out), transform 1.2s var(--ease-out); }
  .card__media img.card__hover.is-loaded { transition: opacity .6s ease, transform 1.2s var(--ease-out); }

  /* ——— Micro-interactions ——— */
  .btn, .chip, .swatch, .icon-btn, .qty button, .gallery__nav, .link-btn, .radio-card, .gallery__thumbs button, .size-pill {
    transition-property: background, color, border-color, opacity, transform, box-shadow;
    transition-duration: .25s;
    transition-timing-function: var(--ease-out);
  }
  .btn:active, .chip:active, .swatch:active, .icon-btn:active, .qty button:active, .gallery__nav:active, .radio-card:active {
    transform: scale(.96); transition-duration: .08s;
  }
  .gallery__nav:active { transform: translateY(-50%) scale(.92); }
  .card__body { transition: transform .5s var(--ease-out); }
  @media (hover: hover) {
    .card:hover .card__body { transform: translateY(-3px); }
    .gallery__nav { opacity: 0; }
    .gallery__main:hover .gallery__nav, .gallery__nav:focus-visible { opacity: 1; }
  }
  .radio-card:has(input:checked) { box-shadow: 0 10px 26px -18px rgba(58, 41, 34, .55); }

  /* Mobile menu: links cascade in. */
  @media (max-width: 960px) {
    .site-nav { transition: opacity .3s var(--ease-out), transform .35s var(--ease-out); }
    .site-header.is-open .site-nav .nav-link { animation: .45s var(--ease-out) both mj-slide-in; }
    .site-header.is-open .site-nav .nav-link:nth-child(2) { animation-delay: .04s; }
    .site-header.is-open .site-nav .nav-link:nth-child(3) { animation-delay: .08s; }
    .site-header.is-open .site-nav .nav-link:nth-child(4) { animation-delay: .12s; }
    .site-header.is-open .site-nav .nav-link:nth-child(n + 5) { animation-delay: .16s; }
  }
  @keyframes mj-slide-in { from { opacity: 0; transform: translateX(-14px); } }

  /* Flash messages glide in and out. */
  .flash-wrap, .admin-main > .flash, .admin-login > .flash { animation: .5s var(--ease-spring) both mj-drop; }
  .flash-wrap.is-leaving, .flash.is-leaving { opacity: 0; transform: translateY(-8px); transition: opacity .35s, transform .35s; }
  @keyframes mj-drop { from { opacity: 0; transform: translateY(-10px); } }

  /* Cart badge bounces when something was added. */
  .cart-count.is-bumped { animation: .6s var(--ease-spring) .35s both mj-bump; }
  @keyframes mj-bump { 0% { transform: scale(.4); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }

  /* Checkout totals and address block. */
  .shipping-fields { transition: grid-template-rows .5s var(--ease-out), opacity .35s, margin-top .5s var(--ease-out); }
  .is-updated { animation: .4s var(--ease-out) mj-flash-value; }
  @keyframes mj-flash-value { from { opacity: .2; transform: translateY(3px); } }

  /* Gallery: the main photo follows the finger. */
  .gallery__main { touch-action: pan-y; }
  .gallery__main img { will-change: transform, opacity; }
  .gallery__main.is-dragging img { transition: none; }

  /* Disclosure panels open smoothly (admin tables). */
  details::details-content { height: 0; overflow: clip; transition: height .45s var(--ease-out), content-visibility .45s allow-discrete; }
  details[open]::details-content { height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
