/* ============================================================================
   SHAPOR — ReactBits Components + UX Enhancements
   v2.19.11
   ============================================================================
   This file is loaded only when shapor_reactbits_enabled theme_mod is '1'.
   Loaded AFTER main style.css so it can override.
   ============================================================================ */

/* ============================================================================
   0. @property registration (Star Border animation)
   ============================================================================ */
@property --shapor-star-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

/* ============================================================================
   1. ACCESSIBILITY — prefers-reduced-motion disables ALL animations
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
    .shapor-star-border-btn::before,
    .shapor-shiny-text,
    .shapor-rotating-text,
    .shapor-click-spark .shapor-spark,
    .shapor-404__emoji,
    .shapor-cart-badge-pulse,
    .shapor-blur-up::before,
    .shapor-scroll-progress-bar {
        animation: none !important;
        transition: none !important;
    }
    .shapor-tilted-card,
    .shapor-spotlight-card {
        transform: none !important;
    }
    .shapor-count-up {
        /* Will be set instantly by JS */
    }
}

/* ============================================================================
   2. COUNT UP — no visual styles, just a marker class for JS
   ============================================================================ */
.shapor-count-up {
    /* JS handles the actual number animation. The element stays in its
       existing parent styling (trust-stat-num, hero-stat-num, etc.). */
}

/* ============================================================================
   3. SHINY TEXT — moving shine gradient
   ============================================================================ */
.shapor-shiny-text {
    background: linear-gradient(
        90deg,
        var(--accent-green, #84cc16) 0%,
        var(--accent-green, #84cc16) 40%,
        #ffffff 50%,
        var(--accent-green, #84cc16) 60%,
        var(--accent-green, #84cc16) 100%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shapor-shiny 3s linear infinite;
}

@keyframes shapor-shiny {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================================================
   4. STAR BORDER — animated conic gradient border
   Applied via .shapor-star-border-btn class on any button/link.

   IMPORTANT (v2.19.11-hotfix1): The ::before uses `inset: -2px` to extend
   the border slightly outside the button. On touch devices / small screens
   this caused horizontal page scroll and broke mobile layout. The entire
   ::before is now GATED behind `@media (hover: hover) AND (min-width: 901px)`
   — meaning on phones/tablets the ::before simply doesn't exist, so no
   layout impact at all. Hover effects only make sense on hover-capable
   devices anyway.
   ============================================================================ */
.shapor-star-border-btn {
    position: relative;
    isolation: isolate;
}

/* Only render the ::before on hover-capable, desktop-size screens */
@media (hover: hover) and (min-width: 901px) {
    .shapor-star-border-btn::before {
        content: '';
        position: absolute;
        inset: -2px;
        border-radius: inherit;
        padding: 2px;
        background: conic-gradient(
            from var(--shapor-star-angle, 0deg),
            transparent 0deg,
            transparent 240deg,
            var(--accent-green, #84cc16) 290deg,
            #ffffff 320deg,
            var(--accent-green, #84cc16) 340deg,
            transparent 360deg
        );
        -webkit-mask:
            linear-gradient(#000 0 0) content-box,
            linear-gradient(#000 0 0);
        -webkit-mask-composite: xor;
                mask-composite: exclude;
        animation: shapor-star-rotate 4s linear infinite;
        pointer-events: none;
        z-index: -1;
        opacity: 0;
        transition: opacity 0.3s ease;
        /* Safety: never cause horizontal scroll even if mask fails */
        max-width: calc(100% + 4px);
        max-height: calc(100% + 4px);
        overflow: hidden;
    }

    .shapor-star-border-btn:hover::before {
        opacity: 1;
    }

    /* Always-on variant (used on CTA buttons that should always glow) */
    .shapor-star-border-btn--always::before {
        opacity: 1;
    }
}

/* On touch/mobile: the ::before is never created, so no layout impact.
   The button keeps its existing styling (gradient background, etc.) and
   just doesn't have the animated border. This is the correct UX:
   hover effects don't make sense on touch devices. */

/* Fallback for browsers without @property support — also gated to desktop */
@supports not (background: paint(test)) {
    @media (hover: hover) and (min-width: 901px) {
        .shapor-star-border-btn::before {
            animation: none;
            background: conic-gradient(
                from 0deg,
                transparent 0deg,
                transparent 240deg,
                var(--accent-green, #84cc16) 290deg,
                #ffffff 320deg,
                var(--accent-green, #84cc16) 340deg,
                transparent 360deg
            );
        }
    }
}

@keyframes shapor-star-rotate {
    to { --shapor-star-angle: 360deg; }
}

/* ============================================================================
   5. ROTATING TEXT — vertical carousel of words
   Applied via .shapor-rotating-text-wrap > .shapor-rotating-text > .rt-word
   ============================================================================ */
.shapor-rotating-text-wrap {
    display: inline-flex;
    height: 1.25em;
    overflow: hidden;
    vertical-align: bottom;
    line-height: 1.25;
}

.shapor-rotating-text {
    display: flex;
    flex-direction: column;
    animation: shapor-rt-rotate 9s infinite cubic-bezier(0.83, 0, 0.17, 1);
}

.shapor-rt-word {
    height: 1.25em;
    line-height: 1.25;
    background: var(--gradient-accent, linear-gradient(135deg, #f97316, #ef4444));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 900;
    white-space: nowrap;
    padding: 0 4px;
}

/* 4-word rotation: شوک → بمب → اکسپلود → شوک (duplicate for seamless loop) */
@keyframes shapor-rt-rotate {
    0%, 20%   { transform: translateY(0); }
    25%, 45%  { transform: translateY(-1.25em); }
    50%, 70%  { transform: translateY(-2.5em); }
    75%, 100% { transform: translateY(-3.75em); }
}

/* ============================================================================
   6. SPOTLIGHT CARD — radial gradient follows mouse
   Applied via .shapor-spotlight-card class on any card element.
   JS sets --mx and --my CSS variables on mousemove.

   HOTFIX v2.19.11.2: Gated to desktop only. On mobile, the ::after overlay
   and isolation: isolate were causing rendering issues. Now the class is
   a no-op on mobile/touch devices.
   ============================================================================ */
@media (hover: hover) and (min-width: 901px) {
    .shapor-spotlight-card {
        position: relative;
        isolation: isolate;
    }

    .shapor-spotlight-card::after {
        content: '';
        position: absolute;
        inset: 0;
        background: radial-gradient(
            circle 220px at var(--mx, 50%) var(--my, 0%),
            rgba(132, 204, 22, 0.18),
            transparent 70%
        );
        opacity: 0;
        transition: opacity 0.4s ease;
        pointer-events: none;
        z-index: 0;
    }

    .shapor-spotlight-card:hover::after {
        opacity: 1;
    }
}

/* ============================================================================
   7. TILTED CARD — 3D tilt on mouse move
   Applied via .shapor-tilted-card class.
   JS sets transform: perspective(...) rotateX(...) rotateY(...)

   HOTFIX v2.19.11.2: Gated to desktop only (hover + min-width 901px).
   On mobile, the transform-style: preserve-3d was causing rendering
   issues in some browsers. Now the class is a no-op on mobile.
   ============================================================================ */
@media (hover: hover) and (min-width: 901px) {
    .shapor-tilted-card {
        transition: transform 0.15s ease-out, box-shadow 0.3s ease, border-color 0.3s ease;
        transform-style: preserve-3d;
        will-change: transform;
    }
}

/* ============================================================================
   8. CLICK SPARK — particle burst on click
   Apply .shapor-click-spark to any clickable element.
   JS appends .shapor-spark children with random trajectories.

   HOTFIX v2.19.11.2: Removed `overflow: visible` and `position: relative`
   from the base class — these were overriding existing button styles and
   causing layout issues on the product page. The spark elements are
   position:absolute and will be positioned relative to the nearest
   positioned ancestor (which the button already is, via .shapor-star-border-btn
   or its own positioning). If the button has overflow:hidden, sparks will
   be clipped — that's acceptable and better than breaking layout.
   ============================================================================ */
.shapor-click-spark {
    /* No base styles — we don't override the element's own positioning/overflow */
}

.shapor-spark {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 100;
    will-change: transform, opacity;
}

@keyframes shapor-spark-fly {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 0px))) scale(0);
        opacity: 0;
    }
}

/* ============================================================================
   9. CART BADGE PULSE — fires when item added to cart
   ============================================================================ */
@keyframes shapor-cart-badge-pulse {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.4); }
    60%  { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.shapor-pulse-once {
    animation: shapor-cart-badge-pulse 0.6s ease-out;
}

/* ============================================================================
   10. LAZY-LOAD BLUR-UP — DISABLED in v2.19.11.2
   ============================================================================
   This feature was causing issues on the product page (images appearing
   blurred or not rendering). It has been completely removed. Images
   still use native loading="lazy" from WooCommerce/theme.
   The CSS classes are kept below but empty so existing HTML doesn't break,
   but no visual effect is applied.
   ============================================================================ */
.shapor-blur-up {
    /* DISABLED — no filter, no transform */
}

.shapor-blur-up.shapor-blur-up--loaded {
    /* DISABLED */
}

/* ============================================================================
   11. SCROLL PROGRESS BAR — top of article pages
   ============================================================================ */
.shapor-scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    z-index: 9998;
    pointer-events: none;
}

.shapor-scroll-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-green, #84cc16), var(--accent-emerald, #10b981));
    box-shadow: 0 0 8px rgba(132, 204, 22, 0.5);
    transition: width 0.05s linear;
}

/* ============================================================================
   12. SCROLL-TO-TOP — floating button on article pages
   ============================================================================ */
.shapor-article-scroll-top {
    position: fixed;
    bottom: 88px; /* above the bottom-nav on mobile */
    left: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gradient-primary, linear-gradient(135deg, #84cc16, #10b981));
    color: #0a0a0a;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(132, 204, 22, 0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    z-index: 9997;
}

.shapor-article-scroll-top.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.shapor-article-scroll-top:hover {
    transform: translateY(-4px) scale(1.05);
}

.shapor-article-scroll-top:active {
    transform: translateY(0) scale(0.95);
}

@media (min-width: 901px) {
    .shapor-article-scroll-top {
        bottom: 32px;
        left: 32px;
    }
}

/* ============================================================================
   13. AUTO-ROTATING CATEGORY SLIDER — slow horizontal scroll
   Applied to existing .cat-auto-slider on /shop/
   ============================================================================ */
@media (prefers-reduced-motion: no-preference) {
    .cat-auto-slider {
        position: relative;
    }

    .cat-auto-slider-track {
        animation: shapor-cat-scroll 30s linear infinite;
        will-change: transform;
    }

    .cat-auto-slider:hover .cat-auto-slider-track {
        animation-play-state: paused;
    }

    @keyframes shapor-cat-scroll {
        0%   { transform: translateX(0); }
        100% { transform: translateX(-50%); } /* RTL: scroll toward left */
    }
}

/* ============================================================================
   14. TOAST UPGRADE — enhance existing #shaporCartToast
   ============================================================================ */
.shapor-cart-toast {
    background: rgba(20, 20, 20, 0.95) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(132, 204, 22, 0.3) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05) !important;
}

/* ============================================================================
   15. SMOOTH SCROLL — for in-page anchors
   ============================================================================ */
html.shapor-smooth-scroll {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html.shapor-smooth-scroll {
        scroll-behavior: auto;
    }
}

/* Offset for sticky header when scrolling to anchors */
html.shapor-smooth-scroll shapor-anchor-target,
.shapor-anchor-offset {
    scroll-margin-top: 80px;
}

/* Apply scroll-margin to common anchor targets */
@media (prefers-reduced-motion: no-preference) {
    html.shapor-smooth-scroll #brands,
    html.shapor-smooth-scroll #products,
    html.shapor-smooth-scroll #wizard,
    html.shapor-smooth-scroll #trust,
    html.shapor-smooth-scroll #articles,
    html.shapor-smooth-scroll #comparison,
    html.shapor-smooth-scroll #customerResults,
    html.shapor-smooth-scroll #hero,
    html.shapor-smooth-scroll section[id] {
        scroll-margin-top: 80px;
    }
}

/* ============================================================================
   16. 404 PAGE STYLES
   ============================================================================ */
.shapor-404 {
    min-height: calc(100vh - var(--header-height, 60px));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(132, 204, 22, 0.10), transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(249, 115, 22, 0.07), transparent 50%),
        var(--bg-primary, #0a0a0a);
    text-align: center;
}

.shapor-404__container {
    max-width: 720px;
    width: 100%;
}

.shapor-404__emoji {
    font-size: 5rem;
    margin-bottom: 16px;
    display: inline-block;
    animation: shapor-404-bounce 2s ease-in-out infinite;
}

@keyframes shapor-404-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25%      { transform: translateY(-12px) rotate(-8deg); }
    50%      { transform: translateY(0) rotate(0deg); }
    75%      { transform: translateY(-6px) rotate(8deg); }
}

.shapor-404__code {
    margin-bottom: 20px;
    line-height: 1;
}

.shapor-404__code-shiny {
    font-size: 7rem;
    font-weight: 900;
    background: linear-gradient(
        90deg,
        var(--accent-green, #84cc16) 0%,
        var(--accent-green, #84cc16) 40%,
        #ffffff 50%,
        var(--accent-green, #84cc16) 60%,
        var(--accent-green, #84cc16) 100%
    );
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shapor-shiny 3s linear infinite;
    display: inline-block;
}

.shapor-404__title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 16px;
    color: var(--text-primary, #fff);
}

.shapor-404__desc {
    color: var(--text-secondary, #a0a0a0);
    font-size: 1rem;
    line-height: 1.9;
    margin-bottom: 32px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.shapor-404__search {
    display: flex;
    gap: 8px;
    max-width: 480px;
    margin: 0 auto 40px;
    background: var(--bg-card, #1a1a1a);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 50px;
    padding: 6px 6px 6px 18px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.shapor-404__search:focus-within {
    border-color: rgba(132, 204, 22, 0.5);
    box-shadow: 0 0 0 3px rgba(132, 204, 22, 0.15);
}

.shapor-404__search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary, #fff);
    font-family: inherit;
    font-size: 1rem;
    padding: 10px 0;
}

.shapor-404__search-input::placeholder {
    color: var(--text-muted, #666);
}

.shapor-404__search-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--gradient-primary, linear-gradient(135deg, #84cc16, #10b981));
    color: #0a0a0a;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.shapor-404__search-btn:hover {
    transform: scale(1.05);
}

.shapor-404__links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 40px;
}

.shapor-404__link {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 18px 12px;
    color: var(--text-primary, #fff);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    text-decoration: none;
}

.shapor-404__link:hover {
    background: var(--bg-card-hover, #222);
    border-color: rgba(132, 204, 22, 0.3);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.shapor-404__link-icon {
    font-size: 1.8rem;
}

.shapor-404__link-text {
    font-size: 0.88rem;
    font-weight: 600;
}

.shapor-404__cta {
    margin-bottom: 20px;
}

.shapor-404__hint {
    color: var(--text-muted, #666);
    font-size: 0.88rem;
}

.shapor-404__home-link {
    color: var(--accent-green, #84cc16);
    text-decoration: underline;
}

.shapor-404__home-link:hover {
    color: var(--accent-emerald, #10b981);
}

@media (max-width: 600px) {
    .shapor-404__code-shiny { font-size: 5rem; }
    .shapor-404__title { font-size: 1.5rem; }
    .shapor-404__desc { font-size: 0.92rem; }
    .shapor-404__emoji { font-size: 4rem; }
    .shapor-404__links { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================================
   17. CART BUTTON STAR BORDER (single-product + shop card)
   We add .shapor-star-border-btn to existing .product-card-btn-primary
   and .shop-card-btn-primary. They already have a background gradient,
   so the star border is hover-only (opacity 0 → 1).
   ============================================================================ */
.product-card-btn-primary.shapor-star-border-btn,
.shop-card-btn-primary.shapor-star-border-btn,
.btn-cart.shapor-star-border-btn,
.checkout-button.shapor-star-border-btn,
.shapor-404__cta.shapor-star-border-btn {
    /* inherits all existing button styles; we only add the ::before border */
}

/* ============================================================================
   18. UTILITY — hide elements when ReactBits is disabled (server-side toggle)
   This is purely defensive; the PHP toggle already prevents enqueuing.
   ============================================================================ */
body.shapor-reactbits-disabled .shapor-scroll-progress,
body.shapor-reactbits-disabled .shapor-article-scroll-top,
body.shapor-reactbits-disabled .shapor-star-border-btn::before,
body.shapor-reactbits-disabled .shapor-shiny-text,
body.shapor-reactbits-disabled .shapor-rotating-text {
    display: none !important;
    animation: none !important;
}

/* ============================================================================
   19. SMART STICKY ADD-TO-CART BAR — v2.19.11.3
   On mobile single-product pages, when cart has items, replace the
   "افزودن به سبد" button with two buttons: "ادامه خرید" + "تکمیل خرید".
   The body.cart-has-items class is toggled by JS based on cart fragments.
   ============================================================================ */

/* Hidden cart-state signal — never visible, just data carrier */
.shapor-cart-state {
    display: none !important;
}

/* Default state (cart empty): show "افزودن به سبد", hide the other two */
.sticky-atc-state-filled {
    display: none !important;
}
.sticky-atc-state-empty {
    display: inline-flex;
}

/* When cart has items: hide "افزودن به سبد", show the other two */
body.cart-has-items .sticky-atc-state-empty {
    display: none !important;
}
body.cart-has-items .sticky-atc-state-filled {
    display: inline-flex;
}

/* Stock label swap: "موجود" → "✅ به سبد اضافه شد" */
.sticky-atc-stock-added {
    display: none;
    color: var(--accent-green, #84cc16);
    font-weight: 600;
}
body.cart-has-items .sticky-atc-stock-text {
    display: none;
}
body.cart-has-items .sticky-atc-stock-added {
    display: inline;
}

/* When cart has items, layout actions as two buttons side by side */
body.cart-has-items .sticky-atc-actions {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

/* Secondary button: "ادامه خرید" — gray, smaller */
.sticky-atc-btn-secondary {
    background: rgba(255, 255, 255, 0.08) !important;
    color: var(--text-primary, #fff) !important;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 13px 16px !important;
    font-size: 0.88rem !important;
    font-weight: 600;
    border-radius: 14px !important;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    transition: background 0.2s ease;
}
.sticky-atc-btn-secondary:hover,
.sticky-atc-btn-secondary:active {
    background: rgba(255, 255, 255, 0.14) !important;
}

/* Primary "تکمیل خرید" — green with pulse */
.sticky-atc-checkout {
    background: linear-gradient(135deg, var(--accent-green, #84cc16), #65a30d) !important;
    color: #0a0a0a !important;
    padding: 13px 18px !important;
    font-size: 0.95rem !important;
    animation: shapor-sticky-checkout-pulse 2.2s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes shapor-sticky-checkout-pulse {
    0%, 100% {
        box-shadow: 0 6px 18px rgba(132, 204, 22, 0.4);
    }
    50% {
        box-shadow: 0 6px 28px rgba(132, 204, 22, 0.75), 0 0 0 2px rgba(132, 204, 22, 0.3);
    }
}

/* When cart has items, the "افزودن به سبد" button was the only .sticky-atc-btn
   visible. Now two are visible — make them flex: 1 and 1.4 so "تکمیل خرید" is wider */
body.cart-has-items .sticky-atc-btn-secondary {
    flex: 1;
}
body.cart-has-items .sticky-atc-checkout {
    flex: 1.4;
}

/* On very small screens, shrink padding to fit */
@media (max-width: 380px) {
    body.cart-has-items .sticky-atc-btn-secondary,
    body.cart-has-items .sticky-atc-checkout {
        padding: 11px 10px !important;
        font-size: 0.82rem !important;
    }
    body.cart-has-items .sticky-atc-info {
        display: none; /* hide price/stock on tiny screens to give buttons room */
    }
}

/* Respect reduced motion — disable pulse */
@media (prefers-reduced-motion: reduce) {
    .sticky-atc-checkout {
        animation: none !important;
    }
}

/* ============================================================================
   END
   ============================================================================ */
