/* ซ่อน control การแบ่งหน้า (ใช้แสดงทุก viewport เหมือนเดิม) */
.grid-wrap,
.pager,
#perPage,
label[for="perPage"],
.rows-per-page,
.rows-per-page * {
    display: none !important;
}

/* =========================
   Base layout (mobile-first)
   ========================= */

.card-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 1.5rem;
    padding: 0.85rem 0;
    min-width: 0;
}

.product-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
    min-width: 0;
    overflow-wrap: anywhere;
}

/* ----- Header: ชื่อ + INCI/CAS + grade ----- */

.product-card .card-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
}

.product-card .card-header h2,
.product-card .card-header .sub {
    margin: 0;
}

.product-card .card-header h2 {
    margin-bottom: 0.35rem;
    line-height: 1.1;
}

.product-card .card-header .sub {
    margin-bottom: 0.4rem;
    font-size: 0.8rem;
    opacity: 0.85;
    font-style: italic;
}

.product-card .card-header .grade {
    align-self: flex-start;
}

/* ----- Body: รายละเอียดหลัก + Applications ----- */

.product-card .card-body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

.product-card .card-body p {
    margin: 0.35rem 0;
}

/* ----- Checklist & Tags (ใช้ร่วมกันทุก viewport) ----- */

.product-card .checklist {
    margin: 0.5rem 0 0;
    padding: 0;
}

.product-card .checklist li {
    list-style: none;
    margin: 0.2rem 0;
    display: flex;
    align-items: center;
}

.product-card .checklist,
.product-card .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.product-card .tag,
.product-card .badge {
    border: 1px solid var(--muted);
    padding: 0.125rem 0.5rem;
    border-radius: calc(var(--radius) / 2);
    font-size: 0.7rem;
    color: var(--muted);
}

/* ===============================
   Desktop layout (>= 1024px)
   =============================== */

@media (min-width: 1024px) {
    .card-list {
        align-items: stretch; /* ให้การ์ดในแถวเดียวกันสูงเท่ากัน */
    }

    .product-card {
        padding: 1.75rem 1.5rem 1.5rem;
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    /* ----- Header desktop: fix ความสูง + จัดตำแหน่ง INCI / grade ----- */

    .product-card .card-header {
        min-height: 120px;
        margin-bottom: 1.1rem;
    }

    .product-card .card-header .sub {
        margin-top: 0.65rem;
        margin-bottom: 0; /* ให้ spacing คุมที่ด้านบนแทน */
        font-size: 0.78rem;
        opacity: 0.85;
        flex-grow: 1; /* ดัน grade ลงไปด้านล่างหัวการ์ด */
    }

    .product-card .card-header .grade {
        display: inline-block;
        margin-top: 0.45rem;
        align-self: flex-start;
    }

    /* ----- Body desktop: แบ่ง block รายละเอียด + Applications ----- */

    .product-card .card-body {
        display: flex;
        flex-direction: column;
        gap: 1.1rem;
    }

    /* block แรกใน body = Function / Origin / Maker / Country / Pack / Packaging */
    .product-card .card-body .info-col:first-child {
        display: grid;
        row-gap: 0.25rem;
    }

    .product-card .card-body .info-col:first-child p {
        margin: 0;
        font-size: 0.85rem;
    }

    .product-card .card-body .info-col:first-child strong {
        display: inline-block;
        min-width: 5.8rem; /* ให้ label เรียงคอลัมน์สวย ๆ */
    }

    /* block ที่สองใน body = Applications */
    .product-card .card-body .info-col:last-child {
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        padding-top: 0.9rem;
    }

    .product-card .card-body .info-col:last-child p {
        margin: 0 0 0.3rem;
        font-size: 0.85rem;
    }

    .product-card .checklist {
        margin: 0.15rem 0 0;
        gap: 0.4rem 0.8rem;
    }

    .product-card .checklist li {
        margin: 0;
        display: inline-flex;
        gap: 0.25rem;
        font-size: 0.8rem;
    }

    /* ----- Footer desktop: Certifications (ถ้ามี) ----- */

    .product-card .card-footer {
        margin-top: 0.9rem;
        padding-top: 0.75rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .product-card .card-footer p {
        margin: 0 0 0.4rem;
        font-size: 0.85rem;
    }

    .product-card .tags {
        gap: 0.35rem;
    }

    .product-card .tag,
    .product-card .badge {
        white-space: nowrap;
    }
}

/* ===== Desktop Promote: use the source table; mobile keeps cards ===== */
@media (min-width: 1024px) {
    body[data-page="promote"] .grid-wrap {
        display: block !important;
    }

    body[data-page="promote"] .pager {
        display: flex !important;
    }

    body[data-page="promote"] #perPage {
        display: inline-block !important;
    }

    body[data-page="promote"] label[for="perPage"] {
        display: block !important;
    }

    body[data-page="promote"] .card-list {
        display: none !important;
    }
}
