/* ============================================================================
   PHƯỢT 4P — FLAGSHIP MOTORSPORT MOTION & INTERACTION ENGINE (`p4p-motion-pro.css`)
   - Native Cross-Document View Transitions (@view-transition)
   - Native CSS Scroll-Driven Reveals (animation-timeline: view())
   - Physics-Based Spring Easing (linear() with cubic-bezier fallback)
   - Cursor-Reactive Studio Spotlight, Glass Sheen & Tactile Micro-Interactions
   - 100% Compositor-Thread (opacity/transform/scale) & prefers-reduced-motion safe
   ============================================================================ */

:root {
  --p4p-ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --p4p-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  /* Fallback for browsers without CSS linear() easing */
  --p4p-ease-spring: cubic-bezier(0.34, 1.38, 0.64, 1);
  --p4p-ease-spring-soft: cubic-bezier(0.22, 1.24, 0.36, 1);
}

@supports (animation-timing-function: linear(0, 1)) {
  :root {
    /* Crisp damped motorsport spring (subtle overshoot, fast clean settle) */
    --p4p-ease-spring: linear(
      0, 0.009, 0.035 2.1%, 0.141 4.4%, 0.723 12.9%, 0.938 16.7%,
      1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%,
      1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%,
      0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1
    );
    --p4p-ease-spring-soft: linear(
      0, 0.012, 0.048 2.4%, 0.19 5.3%, 0.785 15.2%, 0.968 20.4%,
      1.042 25.5%, 1.062 29.8%, 1.055 34.4%, 1.018 44.5%,
      0.996 54.8%, 0.993 62.5%, 1.001 79%, 1
    );
  }
}

/* ============================================================================
   1. NATIVE CROSS-DOCUMENT VIEW TRANSITIONS (App-Like Page Glides)
   ============================================================================ */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  #site-main-header {
    view-transition-name: p4p-site-header;
  }

  ::view-transition-group(p4p-site-header) {
    animation-duration: 0.2s;
    z-index: 20;
  }

  ::view-transition-old(root) {
    animation: p4pVtFadeOut 0.22s var(--p4p-ease-smooth) both;
  }
  ::view-transition-new(root) {
    animation: p4pVtGlideIn 0.28s var(--p4p-ease-smooth) both;
  }

  :active-view-transition-type(backward) {
    &::view-transition-old(root) {
      animation: p4pVtBackOut 0.22s var(--p4p-ease-smooth) both;
    }
    &::view-transition-new(root) {
      animation: p4pVtBackIn 0.26s var(--p4p-ease-smooth) both;
    }
  }

  @keyframes p4pVtFadeOut {
    from { opacity: 1; transform: translate3d(0, 0, 0); }
    to   { opacity: 0; transform: translate3d(-12px, 0, 0); }
  }
  @keyframes p4pVtGlideIn {
    from { opacity: 0; transform: translate3d(14px, 0, 0); }
    to   { opacity: 1; transform: translate3d(0, 0, 0); }
  }
  @keyframes p4pVtBackOut {
    from { opacity: 1; transform: translate3d(0, 0, 0); }
    to   { opacity: 0; transform: translate3d(14px, 0, 0); }
  }
  @keyframes p4pVtBackIn {
    from { opacity: 0; transform: translate3d(-12px, 0, 0); }
    to   { opacity: 1; transform: translate3d(0, 0, 0); }
  }
}

/* ============================================================================
   2. LUMINOUS SCROLL PROGRESS HAIRLINE + HERO ENTRANCE CHOREOGRAPHY
   ============================================================================ */
#vfScrollProgress {
  background: linear-gradient(90deg, var(--vf-blue, #111318) 0%, var(--vf-blue-hover, #007A3D) 100%) !important;
  box-shadow: 0 0 8px color-mix(in oklab, var(--vf-blue, #111318) 38%, transparent);
}
html:not([data-holiday]) #vfScrollProgress,
html[data-holiday="default"] #vfScrollProgress {
  background: linear-gradient(90deg, #008C45 0% 33.33%, #E8ECF0 33.33% 66.66%, #CD212A 66.66% 100%) !important;
  box-shadow: 0 1px 6px rgba(11, 13, 17, 0.24);
}

@media (prefers-reduced-motion: no-preference) {
  /* Live showroom status pulse (slow 2.6s radar halo — WCAG safe) */
  .vf-hero-live-dot,
  .p4p-drawer-live-dot {
    animation: p4pLiveRadar 2.6s ease-out infinite;
  }
  @keyframes p4pLiveRadar {
    0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55); }
    70%  { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
  }

  /* Staggered Hero Copy Entrance (initial load only — never restarts after slide swap) */
  .vf-hero-copy:not(.has-swapped) > * {
    animation: p4pHeroRise 0.62s var(--p4p-ease-out) backwards;
  }
  .vf-hero-copy:not(.has-swapped) > :nth-child(1) { animation-delay: 0.04s; }
  .vf-hero-copy:not(.has-swapped) > :nth-child(2) { animation-delay: 0.11s; }
  .vf-hero-copy:not(.has-swapped) > :nth-child(3) { animation-delay: 0.18s; }
  .vf-hero-copy:not(.has-swapped) > :nth-child(4) { animation-delay: 0.25s; }
  .vf-hero-copy:not(.has-swapped) > :nth-child(5) { animation-delay: 0.32s; }
  .vf-hero-copy:not(.has-swapped) > :nth-child(6) { animation-delay: 0.39s; }

  @keyframes p4pHeroRise {
    from {
      opacity: 0;
      transform: translate3d(0, 18px, 0);
    }
    to {
      opacity: 1;
      transform: translate3d(0, 0, 0);
    }
  }

  /* Smooth slide text cross-rise when hero slide swaps */
  .vf-hero.is-paused .vf-hero-thumb-bar {
    transition: none !important;
  }
  .vf-hero-copy.is-swapping .vf-hero-tag,
  .vf-hero-copy.is-swapping .vf-hero-title,
  .vf-hero-copy.is-swapping .vf-hero-desc {
    animation: p4pHeroSwap 0.42s var(--p4p-ease-out) both;
  }
  @keyframes p4pHeroSwap {
    from { opacity: 0; transform: translate3d(0, 10px, 0); }
    to   { opacity: 1; transform: translate3d(0, 0, 0); }
  }

  /* Native CSS Scroll-Driven Hero Parallax Depth on Desktop */
  @media (min-width: 900px) {
    @supports ((animation-timeline: view()) and (animation-range: exit)) {
      @keyframes p4pHeroParallax {
        from { transform: translate3d(0, 0, 0) scale(1); }
        to   { transform: translate3d(0, 10%, 0) scale(1.04); }
      }
      .vf-hero-slides {
        animation: p4pHeroParallax linear both;
        animation-timeline: view(block);
        animation-range: exit 0% exit 100%;
      }
    }
  }
}

/* ============================================================================
   3. NATIVE CSS SCROLL-DRIVEN REVEALS (view() timeline + IO fallback)
   ============================================================================ */
@media (prefers-reduced-motion: no-preference) {
  @supports ((animation-timeline: view()) and (animation-range: entry)) {
    @keyframes p4pScrollSectionRise {
      from {
        opacity: 0.15;
        transform: translate3d(0, 26px, 0);
      }
      to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
      }
    }

    @keyframes p4pScrollCardEnter {
      from {
        opacity: 0.2;
        transform: translate3d(0, 22px, 0) scale(0.975);
      }
      to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
      }
    }

    .p4p-home-showroom .p4p-sr-split,
    .p4p-home-news .p4p-news-card,
    .vf-obsidian-cta > div {
      animation: p4pScrollSectionRise auto linear backwards;
      animation-timeline: view(block);
      animation-range: entry 0% entry 28%;
    }

    .p4p-cat-tile,
    .p4p-sr-perk,
    .p4p-mobile-4col-grid > article {
      animation: p4pScrollCardEnter auto linear backwards;
      animation-timeline: view(block);
      animation-range: entry 0% entry 24%;
    }
  }

  /* Fallback class-based reveal (used only when view() timeline unsupported) */
  .p4p-io-reveal {
    opacity: 0;
    transform: translate3d(0, 20px, 0) scale(0.985);
    transition: opacity 0.48s var(--p4p-ease-out), transform 0.56s var(--p4p-ease-out);
    transition-delay: var(--p4p-stagger, 0ms);
  }
  .p4p-io-reveal.is-inview {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }

  /* Dynamic Grid Filter / Pagination Staggered Pop (Homepage filter & Catalog pages) */
  .p4p-fx-card-enter {
    animation: p4pCardCascade 0.38s var(--p4p-ease-out) backwards;
    animation-delay: var(--p4p-stagger, 0ms);
  }
  @keyframes p4pCardCascade {
    from {
      opacity: 0;
      transform: translate3d(0, 14px, 0) scale(0.975);
    }
    to {
      opacity: 1;
      transform: translate3d(0, 0, 0) scale(1);
    }
  }
}

/* ============================================================================
   4. CURSOR-REACTIVE STUDIO SPOTLIGHT + GLASS SHEEN + SPRING CARD ELEVATION
   ============================================================================ */
.p4p-prod-card,
#main-products-grid .product-card.vf-pcard,
.p4p-uni-card,
.p4p-cat-tile,
.p4p-news-card {
  position: relative;
  --mx: 50%;
  --my: 35%;
}

/* Soft luminous cursor-tracking rim glow on desktop fine-pointer devices */
@media (hover: hover) and (pointer: fine) {
  .p4p-prod-card::before,
  #main-products-grid .product-card.vf-pcard::before,
  .p4p-uni-card::before,
  .p4p-cat-tile::before,
  .p4p-news-card::before {
    content: "";
    position: absolute;
    inset: 0 !important;
    height: auto !important;
    border-radius: inherit;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
    background: radial-gradient(
      260px circle at var(--mx) var(--my),
      color-mix(in srgb, var(--vf-blue, #1464F4) 11%, transparent),
      transparent 68%
    );
    transition: opacity 0.28s ease;
  }

  .p4p-prod-card:hover::before,
  #main-products-grid .product-card.vf-pcard:hover::before,
  .p4p-uni-card:hover::before,
  .p4p-cat-tile:hover::before,
  .p4p-news-card:hover::before {
    opacity: 1;
  }

  /* Crisp diagonal glass sheen sweeping across product thumbnail stages */
  .p4p-prod-thumb,
  .vf-pcard-stage,
  .p4p-uni-stage {
    position: relative;
    overflow: hidden;
  }
  .p4p-prod-thumb::after,
  .vf-pcard-stage::after,
  .p4p-uni-stage::after {
    content: "";
    position: absolute;
    inset: -20% -60%;
    pointer-events: none;
    z-index: 4;
    background: linear-gradient(
      112deg,
      transparent 38%,
      rgba(255, 255, 255, 0.52) 50%,
      transparent 62%
    );
    transform: translate3d(-115%, 0, 0);
  }

  @media (prefers-reduced-motion: no-preference) {
    .p4p-prod-card:hover .p4p-prod-thumb::after,
    #main-products-grid .product-card.vf-pcard:hover .vf-pcard-stage::after,
    .p4p-uni-card:hover .p4p-uni-stage::after {
      transition: transform 0.72s var(--p4p-ease-smooth);
      transform: translate3d(115%, 0, 0);
    }

    /* Spring-elevated hover lift & product image float */
    .p4p-prod-card,
    #main-products-grid .product-card.vf-pcard,
    .p4p-uni-card,
    .p4p-cat-tile,
    .p4p-news-card {
      transition:
        transform 0.42s var(--p4p-ease-spring-soft),
        border-color 0.2s ease,
        box-shadow 0.28s var(--p4p-ease-smooth);
    }
    .p4p-prod-card:hover,
    #main-products-grid .product-card.vf-pcard:hover,
    .p4p-uni-card:hover,
    .p4p-news-card:hover {
      transform: translate3d(0, -5px, 0);
      border-color: color-mix(in srgb, var(--vf-blue, #1464F4) 38%, #E2E8F0) !important;
      box-shadow:
        0 20px 38px -22px rgba(15, 23, 42, 0.26),
        0 6px 16px -10px color-mix(in srgb, var(--vf-blue, #1464F4) 22%, transparent) !important;
    }
    .p4p-cat-tile:hover {
      transform: translate3d(0, -4px, 0);
      box-shadow: 0 14px 26px -16px color-mix(in srgb, var(--vf-blue, #1464F4) 32%, transparent);
    }

    .p4p-prod-thumb img,
    .vf-pcard-stage img.product-img,
    .p4p-uni-stage img,
    .p4p-cat-tile img {
      transition: transform 0.52s var(--p4p-ease-spring-soft);
    }
    .p4p-prod-card:hover .p4p-prod-thumb img,
    #main-products-grid .product-card.vf-pcard:hover .vf-pcard-stage img.product-img,
    .p4p-uni-card:hover .p4p-uni-stage img {
      transform: scale(1.075) translate3d(0, -2px, 0);
    }
    .p4p-cat-tile:hover img {
      transform: scale(1.1) translate3d(0, -2px, 0);
    }

    /* Quick action circular icon spring pop */
    .vf-pcard-qbtn {
      transition: transform 0.36s var(--p4p-ease-spring), background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
    }
    .vf-pcard-qbtn:hover {
      transform: scale(1.12);
    }
  }
}

/* ============================================================================
   5. TACTILE SPRING BUTTONS, SHIMMER CTAS & FLOATING ZALO BREATHING HALO
   ============================================================================ */
.p4p-btn--primary,
.vf-pcard-btn-primary,
.p4p-cta-zalo {
  position: relative;
  overflow: clip;
}

@media (prefers-reduced-motion: no-preference) {
  .p4p-btn--primary::after,
  .vf-pcard-btn-primary::after,
  .p4p-cta-zalo::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(112deg, transparent 28%, rgba(255, 255, 255, 0.32) 50%, transparent 72%);
    transform: translate3d(-135%, 0, 0);
    transition: transform 0.62s var(--p4p-ease-smooth);
  }
  .p4p-btn--primary:hover::after,
  .vf-pcard-btn-primary:hover::after,
  .p4p-cta-zalo:hover::after {
    transform: translate3d(135%, 0, 0);
  }

  /* Tactile spring micro-press across desktop & touch */
  .p4p-btn,
  .vf-pcard-btn-primary,
  .vf-pcard-btn-outline,
  .vf-util-btn,
  .vf-price-chip,
  .vf-mcol-btn,
  .vf-density-btn,
  .p4p-filter-pills button,
  .vf-vcat-card,
  .p4p-quick-cat-tile,
  .p4p-cta-zalo,
  .p4p-cta-call {
    transition:
      transform 0.34s var(--p4p-ease-spring),
      background-color 0.18s ease,
      border-color 0.18s ease,
      color 0.18s ease,
      box-shadow 0.22s ease;
  }
  .p4p-btn:active,
  .vf-pcard-btn-primary:active,
  .vf-pcard-btn-outline:active,
  .vf-util-btn:active,
  .vf-price-chip:active,
  .vf-mcol-btn:active,
  .vf-density-btn:active,
  .p4p-filter-pills button:active,
  .vf-vcat-card:active,
  .p4p-prod-card:active,
  #main-products-grid .product-card.vf-pcard:active,
  .p4p-uni-card:active {
    transform: scale(0.968);
  }

  /* Gentle breathing glow on Floating Zalo FAB (3.2s cycle — subtle, non-flashing) */
  #vfFloatingDock > a {
    position: relative;
    transition: transform 0.38s var(--p4p-ease-spring), box-shadow 0.24s ease;
  }
  #vfFloatingDock > a::before {
    content: "";
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    border: 2px solid var(--vf-blue, #1464F4);
    opacity: 0;
    pointer-events: none;
    animation: p4pFabPulse 3.2s ease-out infinite;
  }
  #vfFloatingDock > a:hover {
    transform: translate3d(0, -4px, 0) scale(1.06);
  }
  @keyframes p4pFabPulse {
    0%   { transform: scale(0.96); opacity: 0.55; }
    65%  { transform: scale(1.36); opacity: 0; }
    100% { transform: scale(1.36); opacity: 0; }
  }

  /* Smooth Spring Pop for Back-To-Top Ring */
  #scrollTopBtn {
    transition:
      opacity 0.24s ease,
      transform 0.42s var(--p4p-ease-spring),
      border-color 0.18s ease,
      box-shadow 0.22s ease;
  }
  #scrollTopBtn:hover {
    transform: translate3d(0, -3px, 0) scale(1.06);
  }

  /* Brand Marquee Logo Hover Pop */
  .p4p-brand-link {
    transition: filter 0.22s ease, opacity 0.22s ease, transform 0.38s var(--p4p-ease-spring);
  }
  .p4p-brand-link:hover {
    transform: translate3d(0, -2px, 0) scale(1.08);
  }

  /* Showroom Photo Subtle Scale Depth on Hover */
  .p4p-sr-photo img,
  .p4p-news-img img {
    transition: transform 0.65s var(--p4p-ease-smooth);
  }
  .p4p-sr-photo:hover img {
    transform: scale(1.045);
  }
  .p4p-news-card:hover .p4p-news-img img {
    transform: scale(1.06);
  }

  /* Active Filter Pill Sliding Highlight Helper */
  .p4p-filter-pills.has-pill-glider {
    position: relative;
  }
  .p4p-filter-pills.has-pill-glider button {
    position: relative;
    z-index: 1;
  }
  .p4p-pill-glider {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    border-radius: 999px;
    background: #14171A;
    pointer-events: none;
    transition: transform 0.38s var(--p4p-ease-spring-soft), width 0.34s var(--p4p-ease-smooth);
  }
  .p4p-filter-pills.has-pill-glider button.is-active {
    background: transparent !important;
    border-color: transparent !important;
    color: #FFFFFF;
  }
}

/* Native <dialog> Quick View & Compare Smooth Top-Layer Pop (animate-to-from-top-layer) */
@media (prefers-reduced-motion: no-preference) {
  dialog.vf-dialog {
    opacity: 0;
    transform: translate3d(0, 14px, 0) scale(0.965);
    transition:
      opacity 0.24s var(--p4p-ease-smooth),
      transform 0.34s var(--p4p-ease-spring-soft),
      display 0.24s,
      overlay 0.24s;
    transition-behavior: allow-discrete;
  }
  dialog.vf-dialog[open] {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
  @starting-style {
    dialog.vf-dialog[open] {
      opacity: 0;
      transform: translate3d(0, 14px, 0) scale(0.965);
    }
  }
  dialog.vf-dialog::backdrop {
    opacity: 0;
    transition: opacity 0.24s ease, display 0.24s, overlay 0.24s;
    transition-behavior: allow-discrete;
  }
  dialog.vf-dialog[open]::backdrop {
    opacity: 1;
  }
  @starting-style {
    dialog.vf-dialog[open]::backdrop {
      opacity: 0;
    }
  }
}

/* Keep explicit reduced-motion safety */
@media (prefers-reduced-motion: reduce) {
  .p4p-io-reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}
