/*
 * Micro-Interactions & Enhanced Animations
 *
 * Features:
 * 1. Scroll-to-top button with smooth animation
 * 2. Link underline animation (animated underline on hover)
 * 3. Image overlay effect (smooth darkening on hover)
 * 4. Skeleton loaders for cards
 * 5. Breadcrumb stagger animation
 * 6. Pagination spring animation (bounce on hover)
 * 7. Enhanced hero entrance animations
 *
 * @package Astra_Child
 * @version 5.6.0
 */

/* ============================================
 1. SCROLL-TO-TOP BUTTON
============================================ */
.scroll-to-top {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    right: auto;
    z-index: 9999;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: var(--med-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(85, 104, 211, 0.4);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.8);
    transition:
        opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.3s,
        background-color 0.2s ease,
        box-shadow 0.2s ease;
    will-change: opacity, transform;
}

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

.scroll-to-top:hover {
    background: var(--med-secondary);
    box-shadow: 0 6px 16px rgba(106, 65, 144, 0.5);
    transform: translateY(-2px) scale(1.05);
}

.scroll-to-top:active {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 2px 8px rgba(106, 65, 144, 0.3);
}

.scroll-to-top:focus-visible {
    outline: 3px solid var(--med-focus, #5568d3);
    outline-offset: 3px;
}

.scroll-to-top svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

@media (max-width: 768px) {
    .scroll-to-top {
        bottom: 1.5rem;
        left: 1.5rem;
        right: auto;
        width: 44px;
        height: 44px;
    }
}

/* ============================================
 2. LINK UNDERLINE ANIMATION
============================================ */
.link-underline {
    position: relative;
    text-decoration: none;
    display: inline-block;
}

.link-underline::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.link-underline:hover::after {
    transform: scaleX(1);
}

/* Variants */
.link-underline--center::after {
    transform-origin: center;
}

.link-underline--right::after {
    transform-origin: right;
}

.link-underline--thick::after {
    height: 3px;
    bottom: -3px;
}

.link-underline--gradient::after {
    background: linear-gradient(90deg, var(--med-primary), var(--med-secondary));
}

/* Apply to all content links by default (non-destructive) */
.entry-content a:not(.wp-block-button__link):not(.med-btn):not(.skip-link):not(.link-underline) {
    position: relative;
    text-decoration: none;
}

.entry-content a:not(.wp-block-button__link):not(.med-btn):not(.skip-link):not(.link-underline)::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 1px;
    background: currentColor;
    opacity: 0.4;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
}

.entry-content a:not(.wp-block-button__link):not(.med-btn):not(.skip-link):not(.link-underline):hover::after {
    transform: scaleX(1);
    opacity: 1;
}

/* ============================================
 3. IMAGE OVERLAY EFFECT
============================================ */
.image-overlay-wrap {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius, 16px);
    display: inline-block;
    max-width: 100%;
}

.image-overlay-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0) 40%,
        rgba(0, 0, 0, 0.6) 100%
    );
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
    pointer-events: none;
}

.image-overlay-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
    pointer-events: none;
}

.image-overlay-wrap:hover::before,
.image-overlay-wrap:hover::after {
    opacity: 1;
}

.image-overlay-wrap img {
    display: block;
    width: 100%;
    height: auto;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.image-overlay-wrap:hover img {
    transform: scale(1.05);
}

/* Overlay caption (optional) */
.image-overlay-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.5rem;
    color: #fff;
    z-index: 2;
    transform: translateY(10px);
    opacity: 0;
    transition:
        transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.image-overlay-wrap:hover .image-overlay-caption {
    transform: translateY(0);
    opacity: 1;
}

/* Variant: subtle overlay (less darkening) */
.image-overlay--subtle::after {
    background: rgba(0, 0, 0, 0.1);
}

.image-overlay--subtle:hover::after {
    opacity: 1;
}

.image-overlay--subtle:hover img {
    transform: scale(1.02);
}

/* Variant: color overlay */
.image-overlay--color::after {
    background: linear-gradient(135deg, rgba(85, 104, 211, 0.3), rgba(106, 65, 144, 0.3));
}

/* ============================================
 4. SKELETON LOADERS
============================================ */
.skeleton-card {
    background: var(--med-bg, #fff);
    border-radius: var(--radius, 16px);
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.skeleton-card__image {
    width: 100%;
    height: 180px;
    border-radius: 12px;
    margin-bottom: 1rem;
    background: linear-gradient(
        90deg,
        var(--med-bg-light, #f8f9fa) 25%,
        #e8e8e8 50%,
        var(--med-bg-light, #f8f9fa) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    will-change: background-position;
}

.skeleton-card__title {
    height: 1.25rem;
    width: 75%;
    border-radius: 6px;
    margin-bottom: 0.75rem;
    background: linear-gradient(
        90deg,
        var(--med-bg-light, #f8f9fa) 25%,
        #e8e8e8 50%,
        var(--med-bg-light, #f8f9fa) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    will-change: background-position;
}

.skeleton-card__text {
    height: 1rem;
    width: 100%;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    background: linear-gradient(
        90deg,
        var(--med-bg-light, #f8f9fa) 25%,
        #e8e8e8 50%,
        var(--med-bg-light, #f8f9fa) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    will-change: background-position;
}

.skeleton-card__text:last-child {
    width: 60%;
}

.skeleton-card__meta {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.skeleton-card__meta-item {
    height: 0.875rem;
    width: 80px;
    border-radius: 4px;
    background: linear-gradient(
        90deg,
        var(--med-bg-light, #f8f9fa) 25%,
        #e8e8e8 50%,
        var(--med-bg-light, #f8f9fa) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    will-change: background-position;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Skeleton for doctor cards (compact) */
.skeleton-card--compact .skeleton-card__image {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    float: left;
    margin-right: 1rem;
    margin-bottom: 0;
}

.skeleton-card--compact .skeleton-card__title {
    width: 60%;
}

/* Skeleton for service cards (horizontal) */
.skeleton-card--horizontal {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.skeleton-card--horizontal .skeleton-card__image {
    width: 120px;
    height: 120px;
    flex-shrink: 0;
    margin-bottom: 0;
}

/* ============================================
 5. BREADCRUMB STAGGER ANIMATION
============================================ */
.med-breadcrumbs.stagger-animate li {
    opacity: 0;
    transform: translateY(8px);
    animation: breadcrumbFadeIn 0.4s ease forwards;
}

.med-breadcrumbs.stagger-animate li:nth-child(1) { animation-delay: 0.05s; }
.med-breadcrumbs.stagger-animate li:nth-child(2) { animation-delay: 0.1s; }
.med-breadcrumbs.stagger-animate li:nth-child(3) { animation-delay: 0.15s; }
.med-breadcrumbs.stagger-animate li:nth-child(4) { animation-delay: 0.2s; }
.med-breadcrumbs.stagger-animate li:nth-child(5) { animation-delay: 0.25s; }
.med-breadcrumbs.stagger-animate li:nth-child(6) { animation-delay: 0.3s; }
.med-breadcrumbs.stagger-animate li:nth-child(7) { animation-delay: 0.35s; }
.med-breadcrumbs.stagger-animate li:nth-child(8) { animation-delay: 0.4s; }
.med-breadcrumbs.stagger-animate li:nth-child(9) { animation-delay: 0.45s; }
.med-breadcrumbs.stagger-animate li:nth-child(10) { animation-delay: 0.5s; }

@keyframes breadcrumbFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
 6. PAGINATION SPRING ANIMATION
============================================ */
.pagination .page-numbers {
    transition:
        transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
        background-color 0.2s ease,
        color 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.pagination .page-numbers:hover {
    transform: scale(1.15);
}

.pagination .page-numbers:active {
    transform: scale(0.95);
}

.pagination .page-numbers:focus-visible {
    outline: 3px solid var(--med-focus, #5568d3);
    outline-offset: 2px;
    transform: scale(1.05);
}

/* Next/Prev arrows get a different spring */
.pagination .page-numbers.prev:hover,
.pagination .page-numbers.next:hover {
    transform: scale(1.2) translateX(0);
}

.pagination .page-numbers.prev:hover {
    transform: scale(1.2) translateX(-2px);
}

.pagination .page-numbers.next:hover {
    transform: scale(1.2) translateX(2px);
}

/* ============================================
 7. ENHANCED HERO ENTRANCE ANIMATIONS
============================================ */

/* Hero container entrance */
.medical-hero.hero-entrance {
    animation: heroFadeIn 0.8s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes heroFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hero title — staggered reveal */
.hero-title-stagger {
    overflow: hidden;
    display: inline-block;
}

.hero-title-stagger .hero-word {
    display: inline-block;
    opacity: 0;
    transform: translateY(100%);
    animation: wordSlideUp 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.hero-title-stagger .hero-word:nth-child(1) { animation-delay: 0.2s; }
.hero-title-stagger .hero-word:nth-child(2) { animation-delay: 0.3s; }
.hero-title-stagger .hero-word:nth-child(3) { animation-delay: 0.4s; }
.hero-title-stagger .hero-word:nth-child(4) { animation-delay: 0.5s; }
.hero-title-stagger .hero-word:nth-child(5) { animation-delay: 0.6s; }
.hero-title-stagger .hero-word:nth-child(6) { animation-delay: 0.7s; }
.hero-title-stagger .hero-word:nth-child(7) { animation-delay: 0.8s; }
.hero-title-stagger .hero-word:nth-child(8) { animation-delay: 0.9s; }
.hero-title-stagger .hero-word:nth-child(9) { animation-delay: 1.0s; }
.hero-title-stagger .hero-word:nth-child(10) { animation-delay: 1.1s; }

@keyframes wordSlideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hero subtitle — fade up */
.hero-subtitle-reveal {
    opacity: 0;
    transform: translateY(15px);
    animation: subtitleFadeUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) 0.6s forwards;
}

@keyframes subtitleFadeUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hero CTA buttons — slide in */
.hero-cta-reveal {
    opacity: 0;
    transform: translateY(20px);
    animation: ctaSlideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.8s forwards;
}

@keyframes ctaSlideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Hero decorative elements — floating */
.hero-float-element {
    animation: heroFloat 3s ease-in-out infinite;
}

.hero-float-element:nth-child(2) {
    animation-delay: 0.5s;
    animation-duration: 3.5s;
}

.hero-float-element:nth-child(3) {
    animation-delay: 1s;
    animation-duration: 4s;
}

@keyframes heroFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Hero badge — pop in */
.hero-badge-pop {
    opacity: 0;
    transform: scale(0.5);
    animation: badgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.1s forwards;
}

@keyframes badgePop {
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============================================
 REDUCED MOTION OVERRIDES
============================================ */
@media (prefers-reduced-motion: reduce) {
    .scroll-to-top {
        transition: opacity 0.01ms, visibility 0.01ms;
    }

    .link-underline::after,
    .entry-content a::after {
        transition: none;
    }

    .entry-content a:hover::after {
        transform: scaleX(1);
        opacity: 1;
    }

    .image-overlay-wrap::before,
    .image-overlay-wrap::after,
    .image-overlay-wrap img,
    .image-overlay-caption {
        transition-duration: 0.01ms;
    }

    .image-overlay-wrap:hover img {
        transform: none;
    }

    .skeleton-card__image,
    .skeleton-card__title,
    .skeleton-card__text,
    .skeleton-card__meta-item {
        animation: none;
    }

    .med-breadcrumbs.stagger-animate li {
        opacity: 1;
        transform: none;
        animation: none;
    }

    .pagination .page-numbers {
        transition-duration: 0.01ms;
    }

    .pagination .page-numbers:hover {
        transform: none;
    }

    .medical-hero.hero-entrance,
    .hero-title-stagger .hero-word,
    .hero-subtitle-reveal,
    .hero-cta-reveal,
    .hero-badge-pop {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .hero-float-element {
        animation: none;
    }
}
