/**
 * Smart Pagination Styles
 *
 * @package SmartPagination
 * @since 1.0.0
 */

/* ==========================================================================
   Layout - Single Row Flex Container
   ========================================================================== */

/* Fix Elementor widget wrapper to allow content to wrap */
.elementor-widget-smart-pagination .elementor-widget-container {
    overflow: visible !important;
    max-width: 100%;
}

.smart-pagination {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    position: relative;
    box-sizing: border-box;
    overflow: visible;
}

/* Allow wrapping when show-all-pages is enabled */
.smart-pagination[data-show-all-pages="true"] {
    flex-wrap: wrap !important;
    row-gap: 10px;
    align-content: flex-start;
}

.smart-pagination__pages {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    max-width: 100%;
    overflow: visible;
}

/* Allow page numbers to wrap when show-all-pages is enabled */
.smart-pagination[data-show-all-pages="true"] .smart-pagination__pages {
    flex-wrap: wrap !important;
    justify-content: center;
    flex-shrink: 1;
    flex-grow: 1;
    max-width: 100%;
    row-gap: 8px;
}

/* Ensure prev is at the start, next is at the end when justified */
.smart-pagination__prev {
    order: -1;
}

.smart-pagination__next {
    order: 1;
}

/* ==========================================================================
   Page Numbers
   ========================================================================== */

.smart-pagination__page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    background-color: #f5f5f5;
    color: #333333;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    position: relative;
    z-index: 1;
}

.smart-pagination__page:hover:not(.is-active):not(.is-disabled) {
    background-color: #666666;
    color: #ffffff;
}

.smart-pagination__page:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.smart-pagination__page:focus:not(:focus-visible) {
    outline: none;
}

.smart-pagination__page:focus-visible {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Active State */
.smart-pagination__page.is-active {
    background-color: #0073aa;
    color: #ffffff;
    cursor: default;
    font-weight: 600;
}

/* ==========================================================================
   Prev/Next Navigation Buttons
   ========================================================================== */

.smart-pagination__nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    background-color: #f5f5f5;
    color: #333333;
    font-size: 14px;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    user-select: none;
    box-sizing: border-box;
    flex-shrink: 0;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    position: relative;
    z-index: 1;
}

.smart-pagination__nav:hover:not(.is-disabled) {
    background-color: #0073aa;
    color: #ffffff;
}

.smart-pagination__nav:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.smart-pagination__nav:focus:not(:focus-visible) {
    outline: none;
}

.smart-pagination__nav:focus-visible {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Disabled State */
.smart-pagination__nav.is-disabled {
    background-color: #eeeeee;
    color: #aaaaaa;
    cursor: not-allowed;
    opacity: 0.6;
    pointer-events: none;
}

/* Icon styling */
.smart-pagination__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.smart-pagination__icon svg {
    width: 1em;
    height: 1em;
    fill: currentColor;
}

.smart-pagination__icon i {
    font-size: inherit;
}

/* Text styling */
.smart-pagination__text {
    display: inline-block;
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.smart-pagination.is-loading {
    pointer-events: none;
    position: relative;
}

.smart-pagination.is-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 4px;
    z-index: 10;
}

/* ==========================================================================
   Fade/Dim Effect (Smooth Loading Style)
   ========================================================================== */

/* Fade effect on pagination widget */
.smart-pagination.is-fading {
    pointer-events: none !important;
    opacity: 0.5 !important;
    transition: opacity 0.15s ease-out !important;
}

/* Hide the overlay pseudo-element when using fade mode */
.smart-pagination.is-fading::after {
    display: none !important;
    content: none !important;
}

/* Provider/Loop Grid fade effect - use opacity for reliable dimming */
.is-fading:not(.smart-pagination) {
    pointer-events: none !important;
}

/* Target ALL images within the fading container - very specific */
.is-fading img {
    opacity: 0.4 !important;
    filter: brightness(0.7) grayscale(0.3) !important;
    transition: opacity 0.15s ease-out, filter 0.15s ease-out !important;
}

/* Target image wrappers and figures */
.is-fading figure,
.is-fading picture,
.is-fading .elementor-image,
.is-fading .attachment-full,
.is-fading .wp-post-image {
    opacity: 0.4 !important;
    transition: opacity 0.15s ease-out !important;
}

/* Target Elementor loop item containers */
.is-fading .e-loop-item,
.is-fading .elementor-post,
.is-fading .jet-listing-grid__item {
    opacity: 0.5 !important;
    transition: opacity 0.15s ease-out !important;
}

/* Target text content within fading container */
.is-fading h1, .is-fading h2, .is-fading h3, 
.is-fading h4, .is-fading h5, .is-fading h6,
.is-fading p, .is-fading span, .is-fading a,
.is-fading .elementor-heading-title,
.is-fading .elementor-widget-text-editor {
    opacity: 0.5 !important;
    transition: opacity 0.15s ease-out !important;
}

/* Dim the entire loop container as fallback */
.is-fading .elementor-loop-container,
.is-fading .jet-listing-grid__items {
    opacity: 0.45 !important;
    transition: opacity 0.15s ease-out !important;
}

/* Loading indicator wrapper */
.smart-pagination__loader {
    display: none !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 11;
    pointer-events: none;
}

.smart-pagination.is-loading .smart-pagination__loader {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Ensure loader children are visible */
.smart-pagination.is-loading .smart-pagination__loader > * {
    visibility: visible !important;
    opacity: 1 !important;
}

/* ==========================================================================
   Loading Indicator Styles
   ========================================================================== */

/* CSS Custom Property for loader color */
.smart-pagination__loader {
    --sp-loader-color: #0073aa;
}

/* Style: Classic Spinner */
.smart-pagination__spinner {
    display: block !important;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border: 4px solid var(--sp-loader-color, #0073aa);
    border-top-color: transparent !important;
    border-radius: 50%;
    box-sizing: border-box;
    animation: smart-pagination-spin 0.8s linear infinite;
}

.smart-pagination__spinner--provider {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-width: 5px;
}

@keyframes smart-pagination-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Style: Bouncing Dots */
.smart-pagination__loader-dots {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 60px;
    min-height: 20px;
}

.smart-pagination__loader-dot {
    display: block !important;
    width: 14px;
    height: 14px;
    min-width: 14px;
    min-height: 14px;
    background-color: var(--sp-loader-color, #0073aa);
    border-radius: 50%;
    animation: smart-pagination-bounce 0.7s ease-in-out infinite;
}

.smart-pagination__loader-dot:nth-child(1) {
    animation-delay: 0s;
}

.smart-pagination__loader-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.smart-pagination__loader-dot:nth-child(3) {
    animation-delay: 0.4s;
}

.smart-pagination__loader-dots--provider .smart-pagination__loader-dot {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
}

@keyframes smart-pagination-bounce {
    0%, 100% {
        transform: scale(0.5);
        opacity: 0.4;
    }
    50% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Style: Pulse Ring */
.smart-pagination__loader-pulse {
    display: block !important;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border: 4px solid var(--sp-loader-color, #0073aa);
    border-radius: 50%;
    box-sizing: border-box;
    animation: smart-pagination-pulse 1.2s ease-in-out infinite;
}

.smart-pagination__loader-pulse--provider {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    border-width: 5px;
}

@keyframes smart-pagination-pulse {
    0%, 100% {
        transform: scale(0.85);
        opacity: 1;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.5;
    }
}

/* Style: Loading Bars */
.smart-pagination__loader-bars {
    display: inline-flex !important;
    align-items: flex-end;
    justify-content: center;
    gap: 5px;
    height: 36px;
    min-height: 36px;
    min-width: 40px;
}

.smart-pagination__loader-bar {
    display: block !important;
    width: 8px;
    min-width: 8px;
    height: 100%;
    background-color: var(--sp-loader-color, #0073aa);
    border-radius: 4px;
    animation: smart-pagination-bars 0.9s ease-in-out infinite;
    transform-origin: bottom center;
}

.smart-pagination__loader-bar:nth-child(1) {
    animation-delay: 0s;
}

.smart-pagination__loader-bar:nth-child(2) {
    animation-delay: 0.12s;
}

.smart-pagination__loader-bar:nth-child(3) {
    animation-delay: 0.24s;
}

.smart-pagination__loader-bar:nth-child(4) {
    animation-delay: 0.36s;
}

.smart-pagination__loader-bars--provider {
    height: 48px;
    min-height: 48px;
}

.smart-pagination__loader-bars--provider .smart-pagination__loader-bar {
    width: 10px;
    min-width: 10px;
    border-radius: 5px;
}

@keyframes smart-pagination-bars {
    0%, 100% {
        transform: scaleY(0.35);
        opacity: 0.5;
    }
    50% {
        transform: scaleY(1);
        opacity: 1;
    }
}

/* Style: Skeleton Shimmer */
.smart-pagination__loader-skeleton {
    display: block !important;
    width: 100px;
    height: 30px;
    min-width: 100px;
    min-height: 30px;
    background: linear-gradient(
        90deg, 
        rgba(0, 115, 170, 0.2) 0%,
        rgba(0, 115, 170, 0.4) 25%, 
        rgba(0, 115, 170, 0.6) 50%, 
        rgba(0, 115, 170, 0.4) 75%,
        rgba(0, 115, 170, 0.2) 100%
    );
    background-size: 200% 100%;
    border-radius: 6px;
    animation: smart-pagination-shimmer 1.2s ease-in-out infinite;
    overflow: hidden;
}

.smart-pagination__loader-skeleton--provider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    min-width: unset;
    min-height: unset;
    border-radius: 0;
    background: linear-gradient(
        90deg, 
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%, 
        transparent 100%
    );
    background-size: 200% 100%;
}

@keyframes smart-pagination-shimmer {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: -100% 0;
    }
}

/* ==========================================================================
   Provider Overlay (Loop Grid / Content)
   ========================================================================== */

.smart-pagination__provider-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.85);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.smart-pagination__provider-overlay.is-visible {
    opacity: 1;
}

.smart-pagination__provider-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    --sp-loader-color: #0073aa;
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

/* Tablet - hide text on nav buttons if space is tight */
@media (max-width: 1024px) {
    .smart-pagination__nav {
        padding: 8px 12px;
    }
}

/* Tablet - more compact and ensure wrapping */
@media (max-width: 1024px) {
    .smart-pagination__nav {
        padding: 8px 12px;
    }
    
    /* Show all pages - ensure proper wrapping on tablet */
    .smart-pagination[data-show-all-pages="true"] {
        flex-wrap: wrap !important;
        row-gap: 8px;
    }
    
    .smart-pagination[data-show-all-pages="true"] .smart-pagination__pages {
        flex-basis: 100%;
        width: 100%;
        order: 0;
        row-gap: 6px;
    }
    
    .smart-pagination[data-show-all-pages="true"] .smart-pagination__prev {
        order: -1;
    }
    
    .smart-pagination[data-show-all-pages="true"] .smart-pagination__next {
        order: 1;
    }
}

/* Mobile - more compact */
@media (max-width: 767px) {
    .smart-pagination {
        gap: 4px;
    }
    
    .smart-pagination__pages {
        gap: 4px;
    }
    
    .smart-pagination__page {
        min-width: 36px;
        height: 36px;
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .smart-pagination__nav {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    /* Optionally hide text on mobile, show only icons */
    .smart-pagination__nav .smart-pagination__text {
        /* Uncomment below to hide text on mobile */
        /* display: none; */
    }
    
    /* Show all pages - ensure proper wrapping on mobile */
    .smart-pagination[data-show-all-pages="true"] {
        flex-wrap: wrap !important;
        row-gap: 8px;
        justify-content: center;
    }
    
    .smart-pagination[data-show-all-pages="true"] .smart-pagination__pages {
        width: 100%;
        flex-basis: 100%;
        row-gap: 6px;
        justify-content: center;
    }
    
    .smart-pagination[data-show-all-pages="true"] .smart-pagination__prev,
    .smart-pagination[data-show-all-pages="true"] .smart-pagination__next {
        flex-basis: auto;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* Screen reader only text */
.smart-pagination__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .smart-pagination__page,
    .smart-pagination__nav {
        border: 2px solid currentColor;
    }
    
    .smart-pagination__page.is-active {
        outline: 3px solid;
        outline-offset: 2px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .smart-pagination__page,
    .smart-pagination__nav {
        transition: none;
    }
    
    .smart-pagination__spinner {
        animation-duration: 1.5s;
    }
    
    .smart-pagination__loader-dot {
        animation: none;
        opacity: 0.7;
    }
    
    .smart-pagination__loader-pulse {
        animation: none;
    }
    
    .smart-pagination__loader-bar {
        animation: none;
        transform: scaleY(0.7);
    }
    
    .smart-pagination__loader-skeleton {
        animation: none;
    }
    
    .smart-pagination__provider-overlay {
        transition: none;
    }
}

/* ==========================================================================
   RTL Support
   ========================================================================== */

[dir="rtl"] .smart-pagination__prev {
    order: 1;
}

[dir="rtl"] .smart-pagination__next {
    order: -1;
}

[dir="rtl"] .smart-pagination__prev .smart-pagination__icon {
    transform: scaleX(-1);
}

[dir="rtl"] .smart-pagination__next .smart-pagination__icon {
    transform: scaleX(-1);
}

/* ==========================================================================
   Editor Preview Styles
   ========================================================================== */

.elementor-editor-active .smart-pagination {
    min-height: 50px;
}

.elementor-editor-active .smart-pagination::before {
    content: none;
}
