/**
 * TWB Archive Widgets – Frontend Styles
 *
 * Styles cho 2 Archive Widgets:
 *   - Archive Title  (.twb-archive-title-wrap)
 *   - Archive Posts  (.twb-archive-posts)
 *
 * Nguyên tắc:
 *   - Không dùng !important trừ gradient text
 *   - Không đặt màu cứng – chỉ layout/base reset nhẹ
 *   - Tất cả màu sắc để Elementor controls quyết định
 *   - Mobile-first
 */

/* ─── ARCHIVE TITLE ───────────────────────────────────────────────────────── */

.twb-archive-title-wrap {
    line-height: 1;
}

.twb-archive-title {
    margin: 0;
    padding: 0;
    line-height: inherit;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.2em;
}

.twb-archive-prefix {
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    white-space: nowrap;
}

.twb-archive-title-text {
    /* Displayed inline alongside prefix */
}

/* Gradient text — hỗ trợ giống Post Title widget */
.twb-archive-title-text.twb-title-gradient {
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
    display: inline-block;
}

.twb-archive-count {
    font-size: 0.6em;
    font-weight: 400;
    opacity: 0.75;
    vertical-align: middle;
    white-space: nowrap;
}

.twb-archive-description {
    margin: 8px 0 0;
    line-height: 1.6;
    word-break: break-word;
}

/* ─── ARCHIVE POSTS – WRAPPER ─────────────────────────────────────────────── */

.twb-archive-posts {
    /* Base container */
}

.twb-archive-posts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Elementor controls ghi đè */
    column-gap: 24px;
    row-gap: 32px;
}

.twb-archive-posts-list {
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* Editor preview note */
.twb-ap-editor-note {
    font-size: 12px;
    opacity: 0.55;
    text-align: center;
    margin-top: 8px;
    font-style: italic;
}

/* No posts message */
.twb-ap-no-posts {
    text-align: center;
    padding: 40px 20px;
    opacity: 0.65;
}

/* ─── ARCHIVE POSTS – CARD ────────────────────────────────────────────────── */

.twb-ap-card {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* clipper cho border-radius */
    box-sizing: border-box; /* padding không làm vỡ grid */
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

/* List layout: card ngang */
.twb-archive-posts-list .twb-ap-card {
    flex-direction: row;
}

.twb-archive-posts-list .twb-ap-card-body {
    flex: 1;
    min-width: 0;
}

/* Lift hover effect */
.twb-ap-card-lift:hover {
    transform: translateY(-4px);
}

.twb-ap-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    /* padding qua Elementor controls */
}

/* ─── THUMBNAIL ───────────────────────────────────────────────────────────── */

.twb-ap-thumb {
    position: relative;
    overflow: hidden;
    display: block;
    background-color: rgba(0, 0, 0, 0.06); /* subtle placeholder bg */
    flex-shrink: 0;
}

/* Khi có aspect-ratio inline style */
.twb-ap-thumb[style*="aspect-ratio"] .twb-ap-img,
.twb-ap-thumb[style*="aspect-ratio"] > a {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.twb-ap-thumb > a {
    display: block;
    overflow: hidden;
    height: 100%;
}

.twb-ap-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    transition: transform 0.35s ease, filter 0.35s ease;
}

/* Placeholder khi không có ảnh */
.twb-ap-img-placeholder {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 120px;
}

/* List layout thumbnail */
.twb-archive-posts-list .twb-ap-thumb {
    width: 200px;
    flex-shrink: 0;
}

/* Hover animations */
.twb-ap-thumb-zoom_in:hover .twb-ap-img {
    transform: scale(1.06);
}

.twb-ap-thumb-zoom_out .twb-ap-img {
    transform: scale(1.06);
}

.twb-ap-thumb-zoom_out:hover .twb-ap-img {
    transform: scale(1);
}

.twb-ap-thumb-move_up:hover .twb-ap-img {
    transform: translateY(-5%);
}

/* CSS Filters */
.twb-img-filter-grayscale .twb-ap-img {
    filter: grayscale(100%);
    transition: filter 0.35s ease, transform 0.35s ease;
}

.twb-img-filter-grayscale:hover .twb-ap-img {
    filter: grayscale(0%);
}

.twb-img-filter-sepia .twb-ap-img {
    filter: sepia(80%);
    transition: filter 0.35s ease, transform 0.35s ease;
}

.twb-img-filter-sepia:hover .twb-ap-img {
    filter: sepia(0%);
}

.twb-img-filter-brightness .twb-ap-img {
    filter: brightness(0.8);
    transition: filter 0.35s ease, transform 0.35s ease;
}

.twb-img-filter-brightness:hover .twb-ap-img {
    filter: brightness(1);
}

/* ─── META BAR ────────────────────────────────────────────────────────────── */

.twb-ap-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 0.8125em; /* ~13px */
    line-height: 1.4;
    margin-bottom: 6px;
}

.twb-ap-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

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

.twb-ap-meta a:hover {
    text-decoration: underline;
}

.twb-ap-meta-sep {
    opacity: 0.4;
    flex-shrink: 0;
    font-size: 1em;
}

/* ─── TITLE ───────────────────────────────────────────────────────────────── */

.twb-ap-title {
    margin: 0 0 8px;
    line-height: 1.35;
    font-size: 1.125rem;
    word-break: break-word;
}

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

.twb-ap-title a:hover {
    text-decoration: underline;
}

/* ─── EXCERPT ─────────────────────────────────────────────────────────────── */

.twb-ap-excerpt {
    margin: 0 0 12px;
    line-height: 1.6;
    word-break: break-word;
    flex: 1; /* Đẩy nút read more xuống cuối card */
}

/* ─── READ MORE BUTTON ────────────────────────────────────────────────────── */

.twb-ap-readmore {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: inherit;
    margin-top: auto; /* Dính xuống đáy card-body */
    transition: color 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
    cursor: pointer;
    line-height: 1.4;
    align-self: flex-start;
}

.twb-ap-readmore i,
.twb-ap-readmore svg {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

/* ─── PAGINATION ──────────────────────────────────────────────────────────── */

.twb-ap-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 40px;
}

.twb-ap-pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    text-decoration: none;
    color: inherit;
    border: 1px solid transparent;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    font-size: 0.9375em;
    line-height: 1;
}

.twb-ap-pagination .page-numbers:hover,
.twb-ap-pagination a.page-numbers:focus {
    border-color: currentColor;
}

.twb-ap-pagination .page-numbers.current {
    font-weight: 600;
    pointer-events: none;
}

.twb-ap-pagination .page-numbers.dots {
    border: none;
    pointer-events: none;
    opacity: 0.5;
}

.twb-ap-prev,
.twb-ap-next {
    display: inline-flex;
}

.twb-ap-prev a,
.twb-ap-next a {
    text-decoration: none;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid currentColor;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-size: 0.9375em;
}

/* Load More button */
.twb-ap-load-more {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: none;
    padding: 10px 28px;
    font-size: 0.9375em;
    line-height: 1.4;
    transition: background-color 0.25s ease, color 0.25s ease, opacity 0.25s ease;
    border-radius: 4px;
}

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

/* Spinner khi loading */
.twb-ap-load-more.is-loading::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: twb-spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes twb-spin {
    to { transform: rotate(360deg); }
}

/* ─── RESPONSIVE ──────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .twb-archive-posts-grid {
        /* Elementor tablet controls ghi đè */
    }
}

@media (max-width: 767px) {
    /* Mobile: list thumbnail nhỏ lại */
    .twb-archive-posts-list .twb-ap-thumb {
        width: 120px;
    }

    .twb-ap-pagination .page-numbers {
        min-width: 32px;
        height: 32px;
        font-size: 0.875em;
    }

    /* Grid: fallback 1 cột nếu Elementor mobile control không override */
    .twb-archive-posts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    /* Rất nhỏ: list thành dọc */
    .twb-archive-posts-list .twb-ap-card {
        flex-direction: column;
    }

    .twb-archive-posts-list .twb-ap-thumb {
        width: 100%;
    }
}