/**
 * AAE Loop Builder - Grid Styles
 * Provides styling for loop grid layouts
 */

/* Loop Wrapper - Contains grid + pagination */
.custom-loop-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* Grid Container Base */
.custom-loop-container {
    --grid-columns: 3;
    --grid-column-gap: 30px;
    --grid-row-gap: 30px;
    
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
    gap: var(--grid-row-gap) var(--grid-column-gap);
    width: 100%;
}

/* Grid Column Responsive Classes */
.elementor-grid-1 .custom-loop-container {
    --grid-columns: 1;
}

.elementor-grid-2 .custom-loop-container {
    --grid-columns: 2;
}

.elementor-grid-3 .custom-loop-container {
    --grid-columns: 3;
}

.elementor-grid-4 .custom-loop-container {
    --grid-columns: 4;
}

.elementor-grid-5 .custom-loop-container {
    --grid-columns: 5;
}

.elementor-grid-6 .custom-loop-container {
    --grid-columns: 6;
}

/* Responsive Grid */
@media (max-width: 1024px) {
    .elementor-grid-tablet-1 .custom-loop-container {
        --grid-columns: 1;
    }

    .elementor-grid-tablet-2 .custom-loop-container {
        --grid-columns: 2;
    }

    .elementor-grid-tablet-3 .custom-loop-container {
        --grid-columns: 3;
    }

    .elementor-grid-tablet-4 .custom-loop-container {
        --grid-columns: 4;
    }

    .elementor-grid-tablet-5 .custom-loop-container {
        --grid-columns: 5;
    }

    .elementor-grid-tablet-6 .custom-loop-container {
        --grid-columns: 6;
    }
}

@media (max-width: 768px) {
    .elementor-grid-mobile-1 .custom-loop-container {
        --grid-columns: 1;
    }

    .elementor-grid-mobile-2 .custom-loop-container {
        --grid-columns: 2;
    }

    .elementor-grid-mobile-3 .custom-loop-container {
        --grid-columns: 3;
    }

    .elementor-grid-mobile-4 .custom-loop-container {
        --grid-columns: 4;
    }

    .elementor-grid-mobile-5 .custom-loop-container {
        --grid-columns: 5;
    }

    .elementor-grid-mobile-6 .custom-loop-container {
        --grid-columns: 6;
    }
}

/* Loop Items */
.e-loop-item {
    display: block;
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.e-loop-item.new-item {
    animation: aae-fadeInUp 0.4s ease-out;
}

@keyframes aae-fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Masonry Layout */
.custom-loop-masonry {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
    grid-auto-rows: 10px;
    gap: var(--grid-column-gap);
}

.custom-loop-masonry .e-loop-item {
    grid-column: auto;
    grid-row: auto;
}

/* Equal Height Support */
.custom-loop-container.equal-height {
    align-items: stretch;
}

.custom-loop-container.equal-height .e-loop-item {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.custom-loop-container.equal-height .e-loop-item > .elementor {
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Pagination Styles */
.custom-loop-pagination {
    width: 100%;
    margin-top: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Numbered Pagination Wrapper */
.custom-loop-pagination-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* WordPress generates pagination as ul.page-numbers */
.custom-loop-pagination-wrapper ul.page-numbers {
    display: flex !important;
    justify-content: center;
    align-items: center;
    list-style: none !important;
    list-style-type: none !important;
    margin: 0 !important;
    padding: 0 !important;
    /* gap controlled by Elementor */
}

.custom-loop-pagination-wrapper ul.page-numbers li {
    display: flex !important;
    list-style: none !important;
    list-style-type: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.custom-loop-pagination-wrapper ul.page-numbers li::before,
.custom-loop-pagination-wrapper ul.page-numbers li::after {
    display: none !important;
    content: none !important;
}

/* Additional reset for theme conflicts */
.custom-loop-pagination .page-numbers,
.custom-loop-pagination ul,
.custom-loop-pagination ol,
.custom-loop-pagination li {
    list-style: none !important;
    list-style-type: none !important;
}

.custom-loop-pagination ul::before,
.custom-loop-pagination ul::after,
.custom-loop-pagination ol::before,
.custom-loop-pagination ol::after {
    display: none !important;
    content: none !important;
}

.custom-loop-pagination-wrapper .page-numbers,
.custom-loop-pagination-wrapper ul.page-numbers li a,
.custom-loop-pagination-wrapper ul.page-numbers li span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.3s ease;
    line-height: 1;
}

/* Dots (ellipsis) - minimal styles */
.custom-loop-pagination-wrapper ul.page-numbers li span.dots {
    cursor: default;
    pointer-events: none;
}

.custom-loop-pagination-wrapper .page-numbers i {
    font-size: 14px;
    line-height: 1;
}

.custom-loop-pagination-wrapper .page-numbers span {
    margin: 0 4px;
    line-height: 1;
}

/* Icon spacing for prev/next in numbered pagination */
.custom-loop-pagination-wrapper ul.page-numbers li a.prev i {
    margin-right: 6px;
}

.custom-loop-pagination-wrapper ul.page-numbers li a.next i {
    margin-left: 6px;
}

/* Full width pagination option */
.pagination-full-width-yes .custom-loop-pagination-wrapper,
.pagination-full-width-yes .custom-loop-pagination-prevnext,
.pagination-full-width-yes .custom-loop-load-more-wrapper {
    max-width: 100% !important;
}

.pagination-full-width-yes .custom-loop-pagination-prevnext {
    justify-content: space-between;
}

.pagination-full-width-yes .custom-loop-pagination-wrapper ul.page-numbers {
    width: 100%;
    justify-content: space-between;
}

/* Center aligned full width */
.pagination-full-width-yes .custom-loop-pagination-wrapper {
    justify-content: center;
}

.pagination-full-width-yes .custom-loop-pagination-wrapper ul.page-numbers {
    justify-content: center;
}

/* Previous/Next Pagination */
.custom-loop-pagination-prevnext {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.custom-loop-pagination-prevnext .custom-loop-prev,
.custom-loop-pagination-prevnext .custom-loop-next {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    min-width: 140px;
    background: linear-gradient(135deg, #007cba 0%, #005a87 100%);
    color: #fff;
    text-decoration: none;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 124, 186, 0.2);
    cursor: pointer;
}

.custom-loop-pagination-prevnext .custom-loop-prev:hover,
.custom-loop-pagination-prevnext .custom-loop-next:hover {
    background: linear-gradient(135deg, #005a87 0%, #004565 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 124, 186, 0.3);
}

.custom-loop-pagination-prevnext .custom-loop-prev:active,
.custom-loop-pagination-prevnext .custom-loop-next:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 124, 186, 0.3);
}

.custom-loop-pagination-prevnext .custom-loop-prev i,
.custom-loop-pagination-prevnext .custom-loop-next i {
    font-size: 16px;
    line-height: 1;
}

.custom-loop-pagination-prevnext .custom-loop-prev span,
.custom-loop-pagination-prevnext .custom-loop-next span {
    line-height: 1;
}

.custom-loop-pagination-prevnext .custom-loop-page-info {
    flex: 0 1 auto;
    text-align: center;
    color: #555;
    font-size: 14px;
    font-weight: 500;
    min-width: 120px;
    padding: 0 15px;
}

.custom-loop-pagination-prevnext .custom-loop-page-info .current {
    color: #007cba;
    font-weight: 700;
    font-size: 20px;
    margin: 0 4px;
}

.custom-loop-pagination-prevnext .custom-loop-page-info .total {
    color: #999;
    font-size: 16px;
}

@media (max-width: 768px) {
    .custom-loop-pagination-prevnext {
        flex-direction: column;
        gap: 15px;
    }

    .custom-loop-pagination-prevnext .custom-loop-prev,
    .custom-loop-pagination-prevnext .custom-loop-next {
        width: 100%;
        max-width: 300px;
    }

    .custom-loop-pagination-prevnext .custom-loop-page-info {
        order: -1;
        width: 100%;
    }
}

/* Load More Button */
.custom-loop-load-more-wrapper {
    width: 100%;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
}

.custom-loop-load-more {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 32px;
    min-width: 180px;
    background: linear-gradient(135deg, #007cba 0%, #005a87 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 124, 186, 0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}

.custom-loop-load-more:hover {
    background: linear-gradient(135deg, #005a87 0%, #004565 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 124, 186, 0.4);
}

.custom-loop-load-more:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 124, 186, 0.3);
}

.custom-loop-load-more:disabled,
.custom-loop-load-more.loading {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    pointer-events: none;
}

.custom-loop-load-more i {
    font-size: 18px;
}

.custom-loop-loading-text {
    display: none;
}

.custom-loop-load-more.loading .custom-loop-load-more-text {
    display: none;
}

.custom-loop-load-more.loading .custom-loop-loading-text {
    display: flex;
    align-items: center;
    gap: 10px;
}

.custom-loop-load-more.loading .eicon-animation-spin {
    animation: aae-spin 1s linear infinite;
}

@media (max-width: 768px) {
    .custom-loop-load-more {
        width: 100%;
        max-width: 300px;
    }
}

/* Nothing Found Message */
.custom-loop-nothing-found {
    text-align: center;
    color: #6c757d;
    font-size: 16px;
}

/* Loading States */
.ajax-loading {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
    min-height: 200px;
}

.ajax-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007cba;
    border-radius: 50%;
    animation: aae-spin 1s linear infinite;
    z-index: 10;
}

@keyframes aae-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Infinite Scroll Loading */
.infinite-scroll-loading,
.infinite-scroll-end {
    width: 100%;
    grid-column: 1 / -1;
    text-align: center;
    padding: 30px 20px;
    font-size: 14px;
    font-weight: 500;
}

.infinite-scroll-loading i {
    font-size: 32px;
    color: #007cba;
    animation: aae-spin 1s linear infinite;
}

.infinite-scroll-end {
    color: #999;
    font-style: italic;
    padding: 40px 20px;
    background: #f8f9fa;
    border-radius: 6px;
    margin-top: 20px;
}

/* Debug mode styles */
body.aae-loop-debug .custom-loop-container {
    border: 2px solid #ff6b6b;
    position: relative;
}

body.aae-loop-debug .custom-loop-container::before {
    content: 'Loop Container - ID: ' attr(data-widget-id);
    position: absolute;
    top: -25px;
    left: 0;
    background: #ff6b6b;
    color: white;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    z-index: 1000;
}

body.aae-loop-debug .e-loop-item {
    outline: 1px solid #4ecdc4;
    position: relative;
}

body.aae-loop-debug .custom-loop-pagination {
    outline: 2px dashed #95e1d3;
    position: relative;
}

/* Empty View Styles */
.custom-loop-empty-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
}

.custom-loop-empty-view__wrapper {
    text-align: center;
    max-width: 400px;
}

.custom-loop-empty-view__icon {
    font-size: 48px;
    color: #6c757d;
    margin-bottom: 20px;
}

.custom-loop-empty-view__title {
    font-size: 18px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
}

.custom-loop-empty-view__description {
    color: #6c757d;
    line-height: 1.5;
}

/* Template Preview Container */
.template-preview-container {
    margin-top: 20px;
    padding: 20px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

.template-preview h4 {
    margin: 0 0 15px 0;
    font-size: 14px;
    font-weight: 600;
    color: #495057;
}

.widget-preview {
    display: inline-block;
    padding: 4px 8px;
    margin: 2px 4px;
    background: #e9ecef;
    border-radius: 3px;
    font-size: 12px;
    color: #495057;
}

/* RTL Support */
[dir="rtl"] .custom-loop-pagination .page-numbers {
    margin: 0 4px 0 0;
}

[dir="rtl"] .custom-loop-pagination .page-numbers:first-child {
    margin-right: 0;
}

[dir="rtl"] .custom-loop-pagination .page-numbers:last-child {
    margin-left: 0;
}

.aae-loop-builder svg {
    width: 1em;
    height: 1em;
}