/**
 * TWB Loop Grid Widget — Frontend Styles v3.5.0
 * Tương thích Elementor Free. Không cần Pro.
 */

/* ==========================================================================
   1. RESET & GRID
   ========================================================================== */

.twb-loop-grid-wrap *,
.twb-loop-grid-wrap *::before,
.twb-loop-grid-wrap *::after {
    box-sizing: border-box;
}

/* CSS Custom Property cho số cột — được set qua Elementor selectors */
.twb-loop-grid {
    display: grid;
    grid-template-columns: repeat( var(--twb-columns, 3), 1fr );
    gap: 30px 20px;
    align-items: start;
}

/* Masonry via CSS columns (lightweight, no JS) */
.twb-loop-grid.twb-masonry {
    display: block;
    column-count: var(--twb-columns, 3);
    column-fill: balance;
}

.twb-loop-grid.twb-masonry .twb-loop-item {
    break-inside: avoid;
    margin-bottom: 20px;
    display: block; /* reset flex từ equal-height */
}

/* ==========================================================================
   2. CARD BASE
   ========================================================================== */

.twb-loop-item {
    position: relative;
    overflow: hidden;
}

/* Entire-card clickable: dùng JS window.open thay vì CSS pseudo-overlay
   để tránh conflict với links bên trong template */
.twb-loop-item[data-href] {
    cursor: pointer;
}

/* ==========================================================================
   3. CARD HOVER ANIMATIONS
   ========================================================================== */

.twb-loop-grid.twb-hover-lift .twb-loop-item {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.twb-loop-grid.twb-hover-lift .twb-loop-item:hover {
    transform: translateY(-6px);
}

.twb-loop-grid.twb-hover-scale .twb-loop-item {
    transition: transform 0.3s ease;
}
.twb-loop-grid.twb-hover-scale .twb-loop-item:hover {
    transform: scale(1.03);
}

.twb-loop-grid.twb-hover-shadow-grow .twb-loop-item {
    transition: box-shadow 0.3s ease;
}
.twb-loop-grid.twb-hover-shadow-grow .twb-loop-item:hover {
    box-shadow: 0 20px 40px rgba(0,0,0,0.18);
}

/* ==========================================================================
   4. IMAGE
   ========================================================================== */

.twb-card-image {
    overflow: hidden;
    line-height: 0;
}

.twb-card-image a {
    display: block;
    line-height: 0;
}

/* Aspect-ratio wrapper — padding-bottom trick */
.twb-card-image-wrap {
    position: relative;
    overflow: hidden;
    padding-bottom: 56.25%; /* 16:9 default, overridden by Elementor slider */
    width: 100%;
    background: #e9e9e9;
}

.twb-card-image-wrap img.twb-card-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: transform 0.4s ease, filter 0.4s ease, opacity 0.4s ease;
}

/* Image hover effects */
.twb-card-image-wrap:hover img.twb-card-img {
    transform: scale(1.05);
}

/* ==========================================================================
   5. CARD BODY
   ========================================================================== */

.twb-card-body {
    padding: 20px;
}

/* ==========================================================================
   6. CATEGORY
   ========================================================================== */

.twb-card-category {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.twb-card-category a {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-decoration: none;
    transition: color 0.2s, background-color 0.2s;
}

/* ==========================================================================
   7. TITLE
   ========================================================================== */

.twb-card-title {
    margin: 0 0 8px;
    padding: 0;
    font-size: 1.1em;
    line-height: 1.4;
}

.twb-card-title a {
    text-decoration: none;
    transition: color 0.2s ease;
}

/* ==========================================================================
   8. META
   ========================================================================== */

.twb-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    font-size: 0.85em;
    margin-bottom: 8px;
    color: #888;
}

.twb-card-meta a {
    text-decoration: none;
    transition: color 0.2s;
}

.twb-meta-sep {
    margin: 0 6px;
    opacity: 0.5;
}

/* ==========================================================================
   9. EXCERPT
   ========================================================================== */

.twb-card-excerpt {
    margin: 0 0 16px;
    font-size: 0.92em;
    line-height: 1.65;
    color: #555;
}

/* ==========================================================================
   10. READ MORE BUTTON
   ========================================================================== */

.twb-card-footer {
    margin-top: auto;
}

.twb-card-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
    cursor: pointer;
}

/* ==========================================================================
   11. LOOP ITEM TEMPLATE — container khi dùng twb_template
   ========================================================================== */

.twb-loop-item > .elementor {
    width: 100%;
}

/* Preview placeholder trong editor */
.twb-loop-template-placeholder {
    background: #f5f5f5;
    border: 1px dashed #ccc;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #888;
    border-radius: 4px;
}

/* ==========================================================================
   12. NOTHING FOUND
   ========================================================================== */

.twb-loop-nothing-found {
    padding: 40px 20px;
    text-align: center;
    color: #888;
    font-size: 0.95em;
}

/* ==========================================================================
   13. SPINNER
   ========================================================================== */

.twb-loop-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.twb-spinner-svg {
    width: 36px;
    height: 36px;
    animation: twb-rotate 1.2s linear infinite;
}

.twb-spinner-svg circle {
    stroke: currentColor;
    stroke-linecap: round;
    animation: twb-dash 1.5s ease-in-out infinite;
    opacity: 0.7;
}

@keyframes twb-rotate {
    100% { transform: rotate(360deg); }
}
@keyframes twb-dash {
    0%   { stroke-dasharray: 1, 150;  stroke-dashoffset: 0; }
    50%  { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
    100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}

/* ==========================================================================
   14. PAGINATION — NUMBERS / PREV-NEXT
   ========================================================================== */

.twb-loop-footer {
    margin-top: 40px;
    display: flex;
    justify-content: center;
}

.twb-pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 6px;
}

.twb-pagination ul {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.twb-pagination li {
    display: inline-flex;
}

.twb-pagination a,
.twb-pagination span.current,
.twb-pagination span.dots {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.9em;
    transition: color 0.2s, background-color 0.2s, border-color 0.2s;
    background: #fff;
    color: inherit;
}

.twb-pagination .current {
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
}

.twb-pagination a:hover {
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
}

.twb-pagination .dots {
    border: none;
    background: transparent;
}

.twb-pagination-prev-next {
    display: flex;
    gap: 12px;
}

.twb-pagination-prev-next a {
    min-width: auto;
    padding: 0 16px;
}

/* ==========================================================================
   15. LOAD MORE BUTTON
   ========================================================================== */

.twb-load-more-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 28px;
    border: 1px solid #2271b1;
    border-radius: 4px;
    background: transparent;
    color: #2271b1;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s, background-color 0.2s, border-color 0.2s;
}

.twb-load-more-btn:hover:not(:disabled) {
    background: #2271b1;
    color: #fff;
}

.twb-load-more-btn:disabled,
.twb-load-more-btn.twb-loading {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.twb-load-more-btn.twb-no-more {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

/* ==========================================================================
   16. INFINITE SCROLL SENTINEL
   ========================================================================== */

.twb-infinite-sentinel {
    width: 100%;
    height: 10px;
    pointer-events: none;
}

/* ==========================================================================
   17. RESPONSIVE — fallback defaults
       (actual breakpoints managed by Elementor responsive controls)
   ========================================================================== */

@media (max-width: 1024px) {
    .twb-loop-grid:not(.twb-masonry) {
        grid-template-columns: repeat( var(--twb-columns-tablet, 2), 1fr );
    }
    .twb-loop-grid.twb-masonry {
        column-count: var(--twb-columns-tablet, 2);
    }
}

@media (max-width: 767px) {
    .twb-loop-grid:not(.twb-masonry) {
        grid-template-columns: repeat( var(--twb-columns-mobile, 1), 1fr );
    }
    .twb-loop-grid.twb-masonry {
        column-count: var(--twb-columns-mobile, 1);
    }
}