/* ============================================
   POST LIST WIDGET — FRONTEND STYLE
   Version: 1.7.1
   Semua class prefix: plw- (Post List Widget)
   ============================================ */

/* ============================================
   VISIBILITY PER DEVICE — GLOBAL RULE
   WAJIB di paling atas agar tidak di-override rule lain
   ============================================ */

/* DESKTOP (>= 768px) */
@media (min-width: 768px) {
    .plw-show-desktop { display: revert !important; }
    .plw-hide-desktop { display: none !important; }
}

/* MOBILE (<= 767px) */
@media (max-width: 767px) {
    .plw-show-mobile { display: revert !important; }
    .plw-hide-mobile  { display: none !important; }

    /* ✅ Excerpt — WAJIB pakai -webkit-box agar line-clamp jalan */
    .plw-excerpt.plw-show-mobile {
        display: -webkit-box !important;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        visibility: visible !important;
        height: auto !important;
        max-height: none !important;
        margin-top: 4px !important;
        font-size: 13px !important;
        line-height: 1.4 !important;
        color: #6B7280 !important;
    }

    /* Date & Author */
    .plw-date.plw-show-mobile,
    .plw-author.plw-show-mobile {
        display: inline-flex !important;
    }

    /* Thumbnail wrapper */
    .plw-thumb-wrap.plw-show-mobile {
        display: block !important;
    }

    /* ✅ PRIORITAS TERTINGGI: excerpt di grid manapun tetap tampil
       jika punya class plw-show-mobile */
    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-excerpt.plw-show-mobile,
    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-excerpt.plw-show-mobile,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-excerpt.plw-show-mobile,
    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-excerpt.plw-show-mobile,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-excerpt.plw-show-mobile,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-excerpt.plw-show-mobile {
        display: -webkit-box !important;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        visibility: visible !important;
        height: auto !important;
        max-height: none !important;
    }
}

/* ============================================
   WRAPPER
   ============================================ */
.plw-wrapper {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
}

.plw-heading {
    font-size: 18px;
    font-weight: 900;
    color: #1F2937;
    margin: 0 0 8px 0;
    padding: 0 0 0 5px;
    font-family: Roboto, sans-serif;
    border-left: 5px solid #FFD700;
}

/* ============================================
   LIST — CSS GRID
   ============================================ */
.plw-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    grid-template-columns: repeat(var(--plw-grid-mobile, 1), minmax(0, 1fr));
    gap: var(--plw-gap, 12px);
}

/* ============================================
   ITEM
   ============================================ */
.plw-item {
    margin: 0;
    padding: 12px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    background: transparent;
    transition: all 0.25s ease;
    opacity: 0;
    transform: translateY(10px);
    animation: plwFadeInUp 0.4s ease forwards;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.plw-item:hover {
    border-color: rgba(59, 130, 246, 0.3);
    background: rgba(59, 130, 246, 0.02);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.plw-link {
    display: flex;
    align-items: center;
    gap: 16px;
    text-decoration: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    flex: 1;
    height: 100%;
    min-width: 0;
}

/* ============================================
   THUMBNAIL
   ============================================ */
.plw-thumb-wrap {
    display: block;
    flex-shrink: 0;
}

.plw-thumb {
    display: block;
    width: 120px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background: #F3F4F6;
    position: relative;
}

.plw-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.plw-item:hover .plw-thumb img {
    transform: scale(1.05);
}

.plw-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #E5E7EB;
    min-height: 80px;
}

.plw-thumb-placeholder::before {
    content: '📄';
    font-size: 24px;
    opacity: 0.5;
}

/* ============================================
   CONTENT
   ============================================ */
.plw-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 6px;
    min-width: 0;
}

.plw-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.45;
    color: #1F2937;
    letter-spacing: -0.2px;
    transition: color 0.2s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.plw-item:hover .plw-title {
    color: #3B82F6;
}

.plw-excerpt {
    display: none;
    font-size: 13px;
    line-height: 1.4;
    color: #6B7280;
    margin-top: 4px;
}

/* ============================================
   META
   ============================================ */
.plw-meta {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 12px;
    line-height: 1.3;
    color: #6B7280;
    font-weight: 400;
    width: fit-content;
    padding-top: 6px;
    font-family: Roboto, sans-serif;
    border-top: 1px solid #00000052;
}

.plw-meta .plw-date,
.plw-meta .plw-author {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: inherit;
    color: inherit;
    font-weight: inherit;
    margin: 0;
    padding: 0;
    border: none;
    width: auto;
    white-space: nowrap;
}

.plw-meta .plw-meta-separator {
    color: #D1D5DB;
    font-weight: 300;
    margin: 0 2px;
    user-select: none;
}

.plw-meta .fas,
.plw-meta .fa {
    display: inline-block;
    font-size: 0.85em;
    color: inherit;
    opacity: 0.85;
    vertical-align: middle;
    margin-right: 3px;
}

.plw-item:hover .plw-meta {
    color: #9CA3AF;
}

/* ============================================
   EMPTY STATE
   ============================================ */
.plw-empty {
    text-align: center;
    color: #6B7280;
    padding: 20px;
    font-style: italic;
}

/* ============================================
   HIDDEN MOBILE — item yang di-hide saat mobile
   ============================================ */
.plw-item.plw-hidden-mobile {
    display: none;
}

/* ============================================
   LOAD MORE
   ============================================ */
.plw-loadmore-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 24px;
    padding: 8px 0;
    gap: 12px;
}

.plw-loadmore-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 32px;
    min-width: 160px;
    font-size: 14px;
    font-weight: 500;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #3B82F6;
    background: transparent;
    border: 2px solid #3B82F6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.3px;
}

.plw-loadmore-btn::before {
    content: '↓';
    display: inline-block;
    font-size: 16px;
    transition: transform 0.3s ease;
}

.plw-loadmore-btn:hover {
    background: #3B82F6;
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
}

.plw-loadmore-btn:hover::before {
    transform: translateY(2px);
}

.plw-loadmore-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none !important;
    color: #9CA3AF;
    border-color: #D1D5DB;
    pointer-events: none;
}

.plw-loadmore-btn:disabled::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid rgba(59, 130, 246, 0.2);
    border-top: 2px solid #3B82F6;
    border-radius: 50%;
    animation: plwSpin 0.8s linear infinite;
    margin-right: 8px;
}

.plw-loadmore-complete {
    text-align: center;
    color: #6B7280;
    font-size: 13px;
    padding: 8px 0;
    margin-top: 12px;
}

.plw-loadmore-complete::before {
    content: '✓ ';
    color: #10B981;
}

.plw-loadmore-error {
    color: #EF4444;
    font-size: 13px;
    text-align: center;
    padding: 10px 14px;
    margin-top: 8px;
    background: #FEF2F2;
    border-radius: 8px;
    border: 1px solid #FCA5A5;
}

@keyframes plwSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes plwFadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   DESKTOP (>= 768px)
   ============================================ */
@media (min-width: 768px) {
    .plw-list {
        grid-template-columns: repeat(var(--plw-grid-desktop, 1), minmax(0, 1fr));
    }

    /* ✅ Override hidden mobile — di desktop semua item tampil */
    .plw-item.plw-hidden-mobile {
        display: flex !important;
    }

    /* --------------------------------------------
       Grid 1 — List horizontal (thumb kiri)
       -------------------------------------------- */
    .plw-wrapper[style*="--plw-grid-desktop: 1"] .plw-excerpt.plw-show-desktop {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        font-family: Roboto, sans-serif;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 1"] .plw-title {
        font-size: 16px;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 1"] .plw-meta {
        margin-top: auto;
        padding-top: 8px;
        gap: 5px;
    }

    /* --------------------------------------------
       Grid 2-3 — Kartu vertikal (thumb atas)
       -------------------------------------------- */
    .plw-wrapper[style*="--plw-grid-desktop: 2"] .plw-link,
    .plw-wrapper[style*="--plw-grid-desktop: 3"] .plw-link {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 2"] .plw-thumb-wrap,
    .plw-wrapper[style*="--plw-grid-desktop: 3"] .plw-thumb-wrap {
        width: 100%;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 2"] .plw-thumb,
    .plw-wrapper[style*="--plw-grid-desktop: 3"] .plw-thumb {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 10;
        border-radius: 8px;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 2"] .plw-thumb-placeholder,
    .plw-wrapper[style*="--plw-grid-desktop: 3"] .plw-thumb-placeholder {
        aspect-ratio: 16 / 10;
        min-height: auto;
        border-radius: 8px;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 2"] .plw-excerpt.plw-show-desktop,
    .plw-wrapper[style*="--plw-grid-desktop: 3"] .plw-excerpt.plw-show-desktop {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        font-family: Roboto, sans-serif;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 2"] .plw-title,
    .plw-wrapper[style*="--plw-grid-desktop: 3"] .plw-title {
        font-size: 15px;
        line-height: 1.45;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 2"] .plw-meta,
    .plw-wrapper[style*="--plw-grid-desktop: 3"] .plw-meta {
        margin-top: auto;
        padding-top: 8px;
        gap: 5px;
    }

    /* --------------------------------------------
       Grid 4+ — Kartu kecil, excerpt hidden
       -------------------------------------------- */
    .plw-wrapper[style*="--plw-grid-desktop: 4"] .plw-link,
    .plw-wrapper[style*="--plw-grid-desktop: 5"] .plw-link,
    .plw-wrapper[style*="--plw-grid-desktop: 6"] .plw-link {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 4"] .plw-thumb-wrap,
    .plw-wrapper[style*="--plw-grid-desktop: 5"] .plw-thumb-wrap,
    .plw-wrapper[style*="--plw-grid-desktop: 6"] .plw-thumb-wrap {
        width: 100%;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 4"] .plw-thumb,
    .plw-wrapper[style*="--plw-grid-desktop: 5"] .plw-thumb,
    .plw-wrapper[style*="--plw-grid-desktop: 6"] .plw-thumb {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 10;
        border-radius: 8px;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 4"] .plw-thumb-placeholder,
    .plw-wrapper[style*="--plw-grid-desktop: 5"] .plw-thumb-placeholder,
    .plw-wrapper[style*="--plw-grid-desktop: 6"] .plw-thumb-placeholder {
        aspect-ratio: 16 / 10;
        min-height: auto;
        border-radius: 8px;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 4"] .plw-excerpt,
    .plw-wrapper[style*="--plw-grid-desktop: 5"] .plw-excerpt,
    .plw-wrapper[style*="--plw-grid-desktop: 6"] .plw-excerpt {
        display: none !important;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 4"] .plw-title,
    .plw-wrapper[style*="--plw-grid-desktop: 5"] .plw-title,
    .plw-wrapper[style*="--plw-grid-desktop: 6"] .plw-title {
        font-size: 14px;
        line-height: 1.4;
    }

    .plw-wrapper[style*="--plw-grid-desktop: 4"] .plw-meta,
    .plw-wrapper[style*="--plw-grid-desktop: 5"] .plw-meta,
    .plw-wrapper[style*="--plw-grid-desktop: 6"] .plw-meta {
        font-size: 11px;
        margin-top: auto;
        padding-top: 6px;
        gap: 3px;
    }
}

/* ============================================
   MOBILE (<= 767px)
   ============================================ */
@media (max-width: 767px) {

    /* --------------------------------------------
       MOBILE GRID 1 — List horizontal (thumb kiri)
       -------------------------------------------- */
    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-item {
        padding: 5px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-link {
        flex-direction: row;
        align-items: stretch;
        gap: 12px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-thumb {
        width: 100px;
        height: 66px;
        border-radius: 6px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-thumb-placeholder {
        min-height: 66px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-title {
        font-size: 14px;
        line-height: 1.4;
    }

    /* ✅ Excerpt di grid 1 — hidden KECUALI jika plw-show-mobile */
    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-excerpt:not(.plw-show-mobile) {
        display: none !important;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-meta {
        font-size: 11px;
        margin-top: auto;
        padding-top: 6px;
        gap: 3px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-meta .fas,
    .plw-wrapper[style*="--plw-grid-mobile: 1"] .plw-meta .fa {
        font-size: 0.8em;
    }

    /* ============================================
       MOBILE GRID 2-3 — Kartu vertikal (seperti desktop)
       ============================================ */
    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-item,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-item {
        padding: 8px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-link,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-link {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-thumb-wrap,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-thumb-wrap {
        width: 100%;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-thumb,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-thumb {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 10;
        border-radius: 8px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-thumb-placeholder,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-thumb-placeholder {
        aspect-ratio: 16 / 10;
        min-height: auto;
        border-radius: 8px;
    }

    /* Excerpt di grid 2-3 mobile — default hidden, tampil jika plw-show-mobile */
    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-excerpt:not(.plw-show-mobile),
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-excerpt:not(.plw-show-mobile) {
        display: none !important;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-title,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-title {
        font-size: 14px;
        line-height: 1.4;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-meta,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-meta {
        font-size: 11px;
        margin-top: auto;
        padding-top: 6px;
        gap: 3px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-meta .fas,
    .plw-wrapper[style*="--plw-grid-mobile: 2"] .plw-meta .fa,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-meta .fas,
    .plw-wrapper[style*="--plw-grid-mobile: 3"] .plw-meta .fa {
        font-size: 0.8em;
    }

    /* ============================================
       MOBILE GRID 4+ — Kartu kecil, excerpt hidden
       ============================================ */
    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-item,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-item,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-item {
        padding: 5px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-link,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-link,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-link {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-thumb-wrap,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-thumb-wrap,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-thumb-wrap {
        width: 100%;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-thumb,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-thumb,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-thumb {
        width: 100%;
        height: auto;
        aspect-ratio: 16 / 10;
        border-radius: 6px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-thumb-placeholder,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-thumb-placeholder,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-thumb-placeholder {
        aspect-ratio: 16 / 10;
        min-height: auto;
        border-radius: 6px;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-excerpt:not(.plw-show-mobile),
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-excerpt:not(.plw-show-mobile),
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-excerpt:not(.plw-show-mobile) {
        display: none !important;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-title,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-title,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-title {
        font-size: 12px;
        line-height: 1.35;
    }

    .plw-wrapper[style*="--plw-grid-mobile: 4"] .plw-meta,
    .plw-wrapper[style*="--plw-grid-mobile: 5"] .plw-meta,
    .plw-wrapper[style*="--plw-grid-mobile: 6"] .plw-meta {
        font-size: 10px;
        margin-top: auto;
        padding-top: 4px;
        gap: 2px;
    }

    /* --------------------------------------------
       LOAD MORE (mobile)
       -------------------------------------------- */
    .plw-loadmore-btn {
        padding: 8px 24px;
        min-width: 140px;
        font-size: 13px;
        border-width: 1.5px;
    }

    .plw-loadmore-container {
        margin-top: 16px;
        padding: 4px 0;
        gap: 8px;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .plw-loadmore-container,
    .plw-loadmore-btn {
        display: none !important;
    }

    .plw-item,
    .plw-item.plw-hidden-mobile {
        display: flex !important;
        opacity: 1 !important;
        transform: none !important;
        animation: none !important;
        border-color: #ddd !important;
    }

    .plw-excerpt,
    .plw-date,
    .plw-author,
    .plw-thumb-wrap {
        display: revert !important;
    }
}