/* ==========================================================================
   Decode Widget — Tirto.id Clone
   Layout: Horizontal Grid (default 5 columns)
   Each card: Thumbnail + PIN Icon (bottom center) + Meta + Title
   ========================================================================== */

.decode-widget {
    background: #fff;
    margin-top: 22px;
    margin-bottom: 22px;
    font-family: 'Inter', Arial, Roboto, sans-serif;
    box-sizing: border-box;
}

.decode-widget *,
.decode-widget *::before,
.decode-widget *::after {
    box-sizing: border-box;
}

.decode-widget-inner {
    max-width: 1033px;
    margin: 0 auto;
    padding: 0 24px;
    width: 100%;
}

/* ==========================================================================
   HEADER
   Garis atas dan bawah dipastikan sejajar (width 100%)
   ========================================================================== */
.decode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 14px;
    padding-bottom: 10px;
    margin-bottom: 18px;
    border-top: 1px solid #2d2d2d;
    border-bottom: 1px dashed #d9d9d9;
    width: 100%;
}

.decode-header-title {
    font-size: 18px;
    font-weight: 700;
    color: #111;
    margin: 0;
    line-height: 1.2;
}

.decode-more {
    font-size: 14px;
    color: #2d5bd1;
    text-decoration: none;
    font-weight: 500;
}
.decode-more:hover {
    text-decoration: underline;
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */
.decode-layout {
    display: grid;
    row-gap: 24px;
    column-gap: 0;
}

/* Kolom Dinamis */
.decode-layout.cols-3 { grid-template-columns: repeat(3, minmax(166px, 1fr)); }
.decode-layout.cols-4 { grid-template-columns: repeat(4, minmax(166px, 1fr)); }
.decode-layout.cols-5 { grid-template-columns: repeat(5, minmax(166px, 1fr)); }
.decode-layout.cols-6 { grid-template-columns: repeat(6, minmax(166px, 1fr)); }

/* Agar struktur HTML main/side tidak merusak grid di desktop */
.decode-main, 
.decode-side {
    display: contents;
}

/* ==========================================================================
   CARD ITEM
   ========================================================================== */
.decode-item {
    display: flex;
    flex-direction: column;
    padding: 0 16px;
    border-right: 1px solid #ececec;
}

/* Pertama tanpa padding kiri */
.decode-item:first-child {
    padding-left: 0;
}

/* Terakhir tanpa border kanan & padding kanan */
.decode-item:last-child {
    border-right: none;
    padding-right: 0;
}

/* ==========================================================================
   THUMBNAIL + PIN ICON
   ========================================================================== */
.decode-item-imglink {
    display: block;
    text-decoration: none;
}

.decode-thumb {
    margin: 0;
    padding: 0;
    line-height: 0;
    position: relative;
    aspect-ratio: 16 / 9;
    border-radius: 2px;
    overflow: hidden; /* Prevent pin from breaking layout if inside */
    border: 1px solid #e5e5e5;
    background: #f0f0f0;
}

.decode-thumb-img-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: block;
}

.decode-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.25s ease;
    border-radius: 2px;
}

.decode-item:hover .decode-thumb-img-wrapper img {
    transform: scale(1.03);
}

/* Ikon Pinned — Kiri Atas */
.decode-pinned {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 32px;
    height: 32px;
    background: rgba(60, 60, 60, 0.88);
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    transition: 0.2s ease;
}

/* Override overflow to visible if needed, but not needed for top-left inside */
.decode-thumb {
    overflow: hidden;
}

.decode-pinned svg {
    color: #ffffff;
    width: 14px;
    height: 14px;
    transform: rotate(-25deg);
}

/* ==========================================================================
   CONTENT (Meta + Title)
   ========================================================================== */
.decode-item-content {
    display: flex;
    flex-direction: column;
    margin-top: 10px; /* Jarak thumbnail ke metadata */
}

.decode-meta {
    display: flex;
    align-items: center;
    line-height: 1;
    margin-bottom: 6px; /* Jarak metadata ke judul */
}

.decode-category {
    font-size: 13px;
    color: #2f5fd3;
    font-weight: 600;
    text-decoration: none;
}
.decode-category:hover {
    text-decoration: underline;
}

.decode-meta-sep {
    margin: 0 6px;
    color: #ccc;
    font-size: 11px;
}

.decode-time {
    font-size: 12px;
    color: #777;
}

.decode-title {
    font-size: 15px; /* Atau 15.5px sesuai instruksi */
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.15px;
    margin: 0;
    max-height: 60px; /* min-height:54px approx. Limit to 3 lines */
    overflow: hidden;
}
.decode-title a {
    color: #111;
    text-decoration: none;
    transition: color 0.2s;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.decode-item:hover .decode-title a {
    color: #0d47a1;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 1024px) {
    .decode-grid.cols-4,
    .decode-grid.cols-5,
    .decode-grid.cols-6 {
        grid-template-columns: repeat(3, minmax(166px, 1fr));
    }
    
    .decode-item:nth-child(3n) {
        border-right: none;
        padding-right: 0;
    }
}

/* Mobile: 1 Main Post + Horizontal Scroll Grid (1 row or 2 rows) */
@media (max-width: 768px) {
    /* Thick gray separator for widget */
    .decode-widget {
        border-top: 10px solid #f5f5f5 !important;
        border-bottom: 10px solid #f5f5f5 !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding-top: 20px !important;
        padding-bottom: 20px !important;
    }
    /* Header Updates */
    .decode-header {
        border-top: none !important;
        border-bottom: none !important;
        padding-top: 0;
        margin-bottom: 12px;
    }
    .decode-more {
        display: none !important;
    }
    .decode-header-title {
        font-size: 16px;
    }
    
    /* Layout Reset */
    .decode-layout {
        display: flex;
        flex-direction: column;
        gap: 16px;
    }
    .decode-main, 
    .decode-side {
        display: block; /* Override display: contents */
    }

    /* Main Featured Post (First Child) */
    .decode-main .decode-item {
        border: none;
        padding: 0;
        margin-bottom: 0;
    }
    .decode-main .decode-item-imglink {
        width: 100%;
        margin-bottom: 12px;
        display: block;
    }
    .decode-main .decode-thumb {
        aspect-ratio: 16 / 9;
        border-radius: 6px;
        width: 100%;
    }
    .decode-main .decode-thumb-img-wrapper img {
        border-radius: 6px;
    }
    .decode-main .decode-item-content {
        margin-top: 0;
    }
    .decode-main .decode-title {
        font-size: 18px;
        font-weight: 700;
        line-height: 1.4;
        max-height: none;
        -webkit-line-clamp: 3;
    }

    /* Small Cards Wrapper (decode-side) */
    .decode-side.mobile-rows-1row,
    .decode-side.mobile-rows-2row {
        display: grid !important;
        grid-template-columns: none !important;
        grid-auto-flow: column !important;
        grid-auto-columns: 88% !important;
        overflow-x: auto !important;
        scroll-snap-type: x mandatory;
        gap: 12px !important;
        padding-bottom: 10px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .decode-side.mobile-rows-1row {
        grid-template-rows: auto !important;
    }
    .decode-side.mobile-rows-2row {
        grid-template-rows: repeat(2, auto) !important;
    }
    .decode-side::-webkit-scrollbar {
        display: none;
    }
    
    /* Small Cards Style */
    .decode-side .decode-item {
        width: 100% !important;
        max-width: none !important;
        scroll-snap-align: start;
        border: 1px solid #eee !important;
        border-radius: 10px !important;
        padding: 12px !important;
        display: grid !important;
        grid-template-columns: 1fr 100px !important; /* Text takes left, image takes exactly 100px on right */
        gap: 14px !important;
        align-items: center !important;
        margin: 0 !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.02) !important;
        height: 100%;
        box-sizing: border-box;
    }
    
    /* Image on the right */
    .decode-side .decode-item-imglink {
        width: 100px;
        height: 75px;
        margin: 0;
        display: block;
        order: 2; /* Move image to the right column */
    }
    .decode-side .decode-thumb {
        height: 100%;
        border-radius: 6px;
        aspect-ratio: auto;
    }
    .decode-side .decode-thumb-img-wrapper {
        height: 100%;
    }
    .decode-side .decode-thumb-img-wrapper img {
        width: 100px;
        height: 75px;
        object-fit: cover;
        border-radius: 6px;
    }
    
    /* Text content on the left */
    .decode-side .decode-item-content {
        display: flex;
        flex-direction: column;
        margin-top: 0;
        justify-content: center;
        min-width: 0;
        order: 1; /* Move text to the left column */
    }
    
    .decode-side .decode-meta {
        order: -1; /* Kategori & waktu di atas judul */
        margin-bottom: 6px;
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 11px;
    }
    
    .decode-side .decode-category {
        color: #2d5bd1 !important; /* Biru tebal seperti referensi */
        font-weight: 700;
        text-transform: capitalize;
    }
    
    .decode-side .decode-meta-sep {
        color: #ccc;
    }
    
    .decode-side .decode-time {
        color: #888;
    }
    
    .decode-side .decode-title {
        font-family: 'PT Serif', 'Merriweather', 'Times New Roman', serif;
        font-size: 15px;
        font-weight: 700;
        line-height: 1.4;
        margin: 0;
        color: #222;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .decode-side .decode-title a {
        color: inherit;
        text-decoration: none;
    }
}
