/*
 * Edderton Scott Theme: UX Enhancements
 * File: /assets/css/ux-enhancements.css
 *
 * Covers:
 *   1. Scroll-triggered entrance animations
 *   2. Shimmer skeleton loaders (cases grid)
 *   3. Smooth anchor scroll + reading progress bar
 *   4. Magnetic button pull effect (CSS side)
 *   5. Pills bar momentum scroll (mobile)
 *   6. Count-up number animation (CSS side)
 *   7. Reduced motion safety net
 */

/* ==========================================================================
   1. SCROLL-TRIGGERED ENTRANCE ANIMATIONS
   ==========================================================================
   Elements gain [data-es-reveal] from JS when they enter the viewport.
   Initial state is set here; the .es-revealed class triggers the transition.
   ========================================================================== */

[data-es-reveal] {
    opacity: 0;
    transform: translateY(28px);
    transition:
        opacity 0.65s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        transform 0.65s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    /* Stagger delay is applied inline by JS via --es-reveal-delay */
    transition-delay: var(--es-reveal-delay, 0ms);
    will-change: opacity, transform;
}

[data-es-reveal].es-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Slide-from-left variant: used for split-layout text columns */
[data-es-reveal="left"] {
    transform: translateX(-24px);
}
[data-es-reveal="left"].es-revealed {
    transform: translateX(0);
}

/* Slide-from-right variant: used for split-layout visual columns */
[data-es-reveal="right"] {
    transform: translateX(24px);
}
[data-es-reveal="right"].es-revealed {
    transform: translateX(0);
}

/* Scale-up variant: used for metric/stat numbers */
[data-es-reveal="scale"] {
    transform: scale(0.94);
    opacity: 0;
}
[data-es-reveal="scale"].es-revealed {
    transform: scale(1);
    opacity: 1;
}


/* ==========================================================================
   2. SHIMMER SKELETON LOADERS
   ==========================================================================
   Injected by JS into .es-cases-output during AJAX fetch.
   Matches the card dimensions exactly so layout doesn't shift.
   ========================================================================== */

@keyframes es-shimmer {
    0%   { background-position: -600px 0; }
    100% { background-position:  600px 0; }
}

.es-skeleton-card {
    border: 1px solid var(--es-border, #e0e0e0);
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: none;
    user-select: none;
}

.es-skeleton-img {
    height: 200px;
    background: #f0f0f0;
}

.es-skeleton-body {
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

/* The shimmer pulse, a travelling highlight */
.es-skeleton-line {
    border-radius: 3px;
    background: linear-gradient(
        90deg,
        #ebebeb 25%,
        #f8f8f8 50%,
        #ebebeb 75%
    );
    background-size: 600px 100%;
    animation: es-shimmer 1.4s ease-in-out infinite;
}

.es-skeleton-line--tag    { height: 18px; width: 60px; }
.es-skeleton-line--title  { height: 24px; width: 85%; margin-top: 8px; }
.es-skeleton-line--title2 { height: 24px; width: 55%; }
.es-skeleton-line--desc   { height: 14px; width: 100%; margin-top: 4px; }
.es-skeleton-line--desc2  { height: 14px; width: 80%; }
.es-skeleton-line--metric {
    height: 18px;
    width: 50%;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

/* Stagger shimmer phase across cards so they don't pulse in unison */
.es-skeleton-card:nth-child(2) .es-skeleton-line { animation-delay: 0.15s; }
.es-skeleton-card:nth-child(3) .es-skeleton-line { animation-delay: 0.30s; }
.es-skeleton-card:nth-child(4) .es-skeleton-line { animation-delay: 0.05s; }
.es-skeleton-card:nth-child(5) .es-skeleton-line { animation-delay: 0.20s; }
.es-skeleton-card:nth-child(6) .es-skeleton-line { animation-delay: 0.35s; }


/* ==========================================================================
   3. READING PROGRESS BAR
   ==========================================================================
   Thin bar at the top of the viewport, visible on long single-column pages
   (single case, discovery, for-smart-businesses, etc.).
   ========================================================================== */

#es-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 0%;
    background: var(--es-text, #1a1a1a);
    z-index: 9999;
    transition: width 0.08s linear;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, width 0.08s linear;
}

#es-progress-bar.es-progress-visible {
    opacity: 1;
}


/* ==========================================================================
   4. MAGNETIC BUTTON EFFECT (CSS side)
   ==========================================================================
   JS applies a CSS custom property --es-mag-x / --es-mag-y on hover.
   The transform here reads those values.
   ========================================================================== */

.es-btn,
.es-cta-btn,
.es-disc-cta-btn,
.es-td-cta-btn {
    --es-mag-x: 0px;
    --es-mag-y: 0px;
    /* Extend existing transition to include the magnetic translate */
    transition:
        background var(--es-t-fast),
        color var(--es-t-fast),
        border-color var(--es-t-fast),
        transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
        box-shadow var(--es-t-base) var(--es-t-ease);
}

/* When magnetic mode is active, the JS-driven translate reads the vars */
.es-btn.es-magnetic,
.es-cta-btn.es-magnetic,
.es-disc-cta-btn.es-magnetic,
.es-td-cta-btn.es-magnetic {
    transform: translate(var(--es-mag-x), var(--es-mag-y));
}

/* Release animation: snaps back with a little overshoot feel */
.es-btn.es-magnetic-release,
.es-cta-btn.es-magnetic-release,
.es-disc-cta-btn.es-magnetic-release,
.es-td-cta-btn.es-magnetic-release {
    transform: translate(0, 0);
    transition: transform 0.55s cubic-bezier(0.23, 1, 0.32, 1);
}


/* ==========================================================================
   5. PILLS BAR: MOBILE MOMENTUM SCROLL
   ==========================================================================
   On narrow viewports the filter pills overflow horizontally with
   momentum scrolling (iOS rubber-band) instead of wrapping to two rows.
   ========================================================================== */

@media (max-width: 768px) {
    .es-pills-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        -ms-overflow-style: none;
        /* Extend slightly beyond padding so first/last pills breathe */
        padding-bottom: 4px;
        /* Fade the trailing edge to hint scrollability */
        -webkit-mask-image: linear-gradient(to right, black 80%, transparent 100%);
        mask-image: linear-gradient(to right, black 80%, transparent 100%);
    }

    .es-pills-bar::-webkit-scrollbar {
        display: none;
    }

    .es-pill-btn {
        flex-shrink: 0;
        scroll-snap-align: start;
    }
}


/* ==========================================================================
   6. COUNT-UP ANIMATION (CSS side)
   ==========================================================================
   While a number is counting, a subtle scale pulse draws the eye.
   JS drives the actual value; this just adds visual interest.
   ========================================================================== */

.es-counting {
    display: inline-block;
    animation: es-count-pulse 0.08s ease-in-out infinite alternate;
}

@keyframes es-count-pulse {
    from { transform: scale(1);     }
    to   { transform: scale(1.012); }
}

/* Once finished, pop to full size cleanly */
.es-count-done {
    animation: none;
    transform: scale(1);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}


/* ==========================================================================
   7. REDUCED MOTION SAFETY NET
   ==========================================================================
   Respect the OS "reduce motion" preference; skip all animations and
   reveal everything immediately, keep interactions functional.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {

    [data-es-reveal],
    [data-es-reveal="left"],
    [data-es-reveal="right"],
    [data-es-reveal="scale"] {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }

    .es-skeleton-line {
        animation: none;
        background: #ebebeb;
    }

    .es-counting {
        animation: none;
    }

    .es-btn,
    .es-cta-btn,
    .es-disc-cta-btn,
    .es-td-cta-btn {
        transition:
            background var(--es-t-fast),
            color var(--es-t-fast),
            border-color var(--es-t-fast);
    }
}