/* ==================================================================
   Global Research Firm Reports v2
   โครงหน้า: บริบทด้านบน -> การ์ดหมวดหมู่ -> ตารางรายงาน
   ================================================================== */

:root {
    --emr-primary: #5b5fd6;
    --emr-primary-dark: #43479f;
    --emr-accent: #764ba2;
    --emr-ink: #22242e;
    --emr-muted: #6b6f80;
    --emr-line: #e3e5ee;
    --emr-bg: #f4f5f9;
    --emr-card: #ffffff;
    --emr-2024: #b06a2c;
    --emr-2025: #1f7a5a;

    /* ความสูงของแถบเมนูด้านบน (.header ใน style.css เป็น position:fixed จึงต้องเผื่อที่ให้)
       ใช้ค่านี้ที่เดียว แล้วอ้างอิงต่อในส่วนที่ต้อง sticky ทั้งหมด */
    --emr-header-h: 94px;
}

.emr-page {
    font-family: 'Prompt', sans-serif;
    color: var(--emr-ink);
    background: var(--emr-bg);
    padding-top: var(--emr-header-h);
}

.emr-wrap {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ------------------------------------------------------------------
   1) ส่วนบริบท (Hero)
   ------------------------------------------------------------------ */
.emr-hero {
    background: linear-gradient(135deg, #5b5fd6 0%, #764ba2 100%);
    color: #fff;
    padding: 52px 0 48px;
}

/* บรรทัดเล็กเหนือหัวข้อ */
.emr-eyebrow {
    margin: 0 0 10px;
    font-size: .82em;
    font-weight: 500;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .72);
}

.emr-hero h1 {
    font-size: 2.35em;
    font-weight: 600;
    margin: 0 0 20px;
    line-height: 1.34;
    max-width: 22ch;          /* บังคับให้ขึ้นบรรทัดใหม่ในจุดที่อ่านสวย ไม่ลากยาวเต็มจอ */
    letter-spacing: -.01em;
}

.emr-h1-brand {
    font-weight: 700;
    white-space: nowrap;      /* ห้ามหั่นชื่อแบรนด์กลางคำ */
}

.emr-h1-tail {
    white-space: nowrap;
    font-weight: 400;
    color: rgba(255, 255, 255, .8);
}

.emr-hero .emr-lead {
    font-size: 1.04em;
    line-height: 2;
    max-width: 58ch;          /* ความยาวบรรทัดที่สายตาอ่านสบาย */
    margin: 0 0 26px;
    color: rgba(255, 255, 255, .93);

    /* ให้เบราว์เซอร์เกลี่ยบรรทัดสุดท้าย จะได้ไม่มีคำโดดอย่าง "ๆ" ตกไปบรรทัดเดียว */
    text-wrap: pretty;
}

/* เน้นคำด้วยน้ำหนักตัวอักษรพอ ไม่ขีดเส้นใต้ เพราะขีดเยอะแล้วรก */
.emr-hero .emr-lead strong {
    font-weight: 600;
    color: #fff;
}

.emr-points-title {
    margin: 0 0 10px;
    font-size: .92em;
    color: rgba(255, 255, 255, .72);
}

.emr-points {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px 30px;
    max-width: 720px;
}

.emr-points li {
    position: relative;
    padding-left: 25px;
    font-size: .96em;
    line-height: 1.65;
    color: rgba(255, 255, 255, .95);
}

.emr-points li::before {
    content: "";
    position: absolute;
    left: 2px;
    top: .55em;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .75);
}

/* แถบตัวเลขสรุป */
/* ข้อความซ้าย + ตัวเลขขวา */
.emr-hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 48px;
    align-items: center;
}

.emr-hero-copy {
    min-width: 0;
}

/* ---- แผงตัวเลขฐานข้อมูล (คอลัมน์ขวา) ---- */
.emr-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.emr-stat {
    background: rgba(255, 255, 255, .13);
    border: 1px solid rgba(255, 255, 255, .26);
    border-radius: 12px;
    padding: 16px 18px;
    text-align: center;
}

.emr-stat .emr-stat-num {
    display: block;
    font-size: 2.1em;
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -.02em;
}

.emr-stat .emr-stat-label {
    display: block;
    font-size: .82em;
    color: rgba(255, 255, 255, .82);
    margin-top: 5px;
}

/* ตัวเลขพระเอก: จำนวนรายงานทั้งหมด */
.emr-stat-hero {
    grid-column: 1 / -1;
    background: rgba(255, 255, 255, .2);
    border-color: rgba(255, 255, 255, .45);
    padding: 24px 18px;
}

.emr-stat-hero .emr-stat-num {
    font-size: 4.1em;
}

.emr-stat-hero .emr-stat-label {
    font-size: .92em;
    color: #fff;
    letter-spacing: .02em;
}

.emr-stat-wide {
    grid-column: 1 / -1;
}

/* คำแนะนำวิธีใช้ */
.emr-howto {
    background: #fff;
    border-left: 4px solid var(--emr-primary);
    border-radius: 8px;
    padding: 18px 22px;
    margin: -26px auto 0;
    max-width: 1240px;
    box-shadow: 0 4px 18px rgba(30, 32, 60, .10);
    position: relative;
    z-index: 2;
}

.emr-howto h2 {
    font-size: 1em;
    margin: 0 0 8px;
    font-weight: 600;
    color: var(--emr-primary-dark);
}

.emr-howto ol {
    margin: 0;
    padding-left: 20px;
    color: var(--emr-muted);
    font-size: .92em;
    line-height: 1.9;
}

/* ------------------------------------------------------------------
   2) การ์ดหมวดหมู่
   ------------------------------------------------------------------ */
.emr-section {
    padding: 40px 0 0;
}

.emr-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.emr-section-head h2 {
    font-size: 1.35em;
    font-weight: 600;
    margin: 0;
}

.emr-section-head .emr-sub {
    color: var(--emr-muted);
    font-size: .9em;
    margin: 0;
}

.emr-cat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
    gap: 12px;
    margin-top: 18px;
}

.emr-cat {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    background: var(--emr-card);
    border: 1px solid var(--emr-line);
    border-radius: 10px;
    padding: 14px 16px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    color: inherit;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}

.emr-cat:hover {
    border-color: var(--emr-primary);
    box-shadow: 0 6px 16px rgba(91, 95, 214, .16);
    transform: translateY(-2px);
}

.emr-cat.is-active {
    border-color: var(--emr-primary);
    background: #f0f1fe;
    box-shadow: inset 0 0 0 1px var(--emr-primary);
}

.emr-cat-th {
    font-size: .98em;
    font-weight: 600;
    line-height: 1.45;
}

.emr-cat-en {
    display: block;
    font-size: .76em;
    color: var(--emr-muted);
    font-weight: 400;
    margin-top: 2px;
}

.emr-cat-count {
    align-self: flex-start;
    background: #eef0fb;
    color: var(--emr-primary-dark);
    border-radius: 20px;
    padding: 2px 11px;
    font-size: .8em;
    font-weight: 600;
}

.emr-cat.is-active .emr-cat-count {
    background: var(--emr-primary);
    color: #fff;
}

/* ------------------------------------------------------------------
   3) แถบเครื่องมือค้นหา
   ------------------------------------------------------------------ */
.emr-toolbar {
    position: sticky;
    top: var(--emr-header-h);   /* ค้างใต้แถบเมนู ไม่มุดเข้าไปข้างหลัง */
    z-index: 20;
    background: var(--emr-bg);
    padding: 14px 0 12px;
    border-bottom: 1px solid var(--emr-line);
    margin-top: 26px;
}

.emr-toolbar-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.emr-search {
    position: relative;
    flex: 1 1 320px;
    min-width: 240px;
}

.emr-search input {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 38px 11px 40px;
    border: 1px solid var(--emr-line);
    border-radius: 8px;
    font-family: inherit;
    font-size: .95em;
    background: #fff;
}

.emr-search input:focus {
    outline: none;
    border-color: var(--emr-primary);
    box-shadow: 0 0 0 3px rgba(91, 95, 214, .15);
}

.emr-search .emr-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--emr-muted);
    pointer-events: none;
}

.emr-search .emr-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: var(--emr-muted);
    cursor: pointer;
    font-size: 1.1em;
    padding: 4px 8px;
    display: none;
}

.emr-seg {
    display: inline-flex;
    background: #fff;
    border: 1px solid var(--emr-line);
    border-radius: 8px;
    overflow: hidden;
}

.emr-seg button {
    border: 0;
    background: transparent;
    padding: 10px 15px;
    font-family: inherit;
    font-size: .9em;
    cursor: pointer;
    color: var(--emr-muted);
    border-right: 1px solid var(--emr-line);
}

.emr-seg button:last-child {
    border-right: 0;
}

.emr-seg button.is-active {
    background: var(--emr-primary);
    color: #fff;
    font-weight: 500;
}

.emr-select {
    padding: 10px 12px;
    border: 1px solid var(--emr-line);
    border-radius: 8px;
    font-family: inherit;
    font-size: .9em;
    background: #fff;
    color: var(--emr-ink);
    cursor: pointer;
}

/* ชิปแสดงตัวกรองที่เปิดอยู่ */
.emr-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 10px;
    min-height: 0;
}

.emr-chips:empty {
    display: none;
}

.emr-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: #fff;
    border: 1px solid var(--emr-primary);
    color: var(--emr-primary-dark);
    border-radius: 20px;
    padding: 5px 8px 5px 13px;
    font-size: .85em;
}

.emr-chip button {
    border: 0;
    background: #eef0fb;
    color: var(--emr-primary-dark);
    border-radius: 50%;
    width: 19px;
    height: 19px;
    line-height: 1;
    cursor: pointer;
    font-size: .95em;
    padding: 0;
}

.emr-chip button:hover {
    background: var(--emr-primary);
    color: #fff;
}

.emr-chip-clear {
    border: 0;
    background: transparent;
    color: var(--emr-muted);
    text-decoration: underline;
    cursor: pointer;
    font-family: inherit;
    font-size: .85em;
}

.emr-count {
    color: var(--emr-muted);
    font-size: .92em;
    margin: 14px 0 10px;
}

.emr-count strong {
    color: var(--emr-ink);
    font-size: 1.15em;
}

/* ------------------------------------------------------------------
   4) ตารางรายงาน
   ------------------------------------------------------------------ */
.emr-table-wrap {
    background: #fff;
    border: 1px solid var(--emr-line);
    border-radius: 10px;
    margin-bottom: 20px;
    /* ห้ามใส่ overflow ที่นี่: ถ้าใส่ (hidden/auto/clip) กล่องนี้จะกลายเป็น
       containing block ของ thead ที่เป็น position:sticky ทำให้หัวตารางถูกดัน
       ลงไปอยู่กลางตารางแทนที่จะค้างอยู่ด้านบนจอ */
}

/* มุมโค้งด้านบน ทำที่หัวตารางแทนการใช้ overflow:hidden ที่กล่องครอบ */
.emr-table thead th:first-child {
    border-top-left-radius: 10px;
}

.emr-table thead th:last-child {
    border-top-right-radius: 10px;
}

.emr-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .93em;
}

.emr-table thead th {
    background: #f7f8fc;
    text-align: left;
    font-weight: 600;
    color: var(--emr-muted);
    font-size: .88em;
    padding: 13px 14px;
    border-bottom: 1px solid var(--emr-line);
    white-space: nowrap;
    /* ค้างใต้แถบเมนู + แถบเครื่องมือ (แถบเครื่องมือสูงราว 66px) */
    position: sticky;
    top: calc(var(--emr-header-h) + 66px);
    z-index: 10;
}

.emr-table th.is-sortable {
    cursor: pointer;
    user-select: none;
}

.emr-table th.is-sortable:hover {
    color: var(--emr-primary);
}

.emr-table th .emr-sort-mark {
    opacity: .35;
    margin-left: 5px;
    font-size: .9em;
}

.emr-table th.is-sorted .emr-sort-mark {
    opacity: 1;
    color: var(--emr-primary);
}

.emr-table tbody tr {
    border-bottom: 1px solid #f0f1f6;
}

.emr-table tbody tr:hover {
    background: #fafbff;
}

.emr-table td {
    padding: 13px 14px;
    vertical-align: top;
}

/* คอลัมน์ชื่อรายงาน */
.emr-title-cell {
    min-width: 260px;
}

.emr-title-en {
    font-weight: 600;
    color: var(--emr-ink);
    line-height: 1.45;
}

.emr-title-th {
    display: block;
    color: var(--emr-muted);
    font-size: .88em;
    font-weight: 400;
    margin-top: 2px;
}

.emr-detail-toggle {
    border: 0;
    background: transparent;
    color: var(--emr-primary);
    font-family: inherit;
    font-size: .84em;
    cursor: pointer;
    padding: 4px 0 0;
    text-decoration: underline;
}

/* badge หมวด / ปี */
.emr-badge {
    display: inline-block;
    border-radius: 5px;
    padding: 3px 9px;
    font-size: .82em;
    line-height: 1.6;
    white-space: nowrap;
}

.emr-badge-cat {
    background: #eef0fb;
    color: var(--emr-primary-dark);
    margin: 0 4px 4px 0;
}

.emr-badge-year {
    font-weight: 600;
    font-size: .85em;
    padding: 3px 10px;
    border-radius: 20px;
}

.emr-badge-year[data-year="2025"] {
    background: #e2f4ed;
    color: var(--emr-2025);
}

.emr-badge-year[data-year="2024"] {
    background: #fbeee0;
    color: var(--emr-2024);
}

.emr-date-sub {
    display: block;
    color: var(--emr-muted);
    font-size: .84em;
    margin-top: 4px;
    white-space: nowrap;
}

.emr-type-cell {
    color: var(--emr-muted);
    font-size: .9em;
    white-space: nowrap;
}

.emr-price {
    font-weight: 600;
    white-space: nowrap;
}

.emr-price small {
    display: block;
    font-weight: 400;
    color: var(--emr-muted);
    font-size: .78em;
}

.emr-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 108px;
}

.emr-btn {
    display: inline-block;
    text-align: center;
    padding: 7px 12px;
    border-radius: 6px;
    font-size: .85em;
    text-decoration: none;
    white-space: nowrap;
    border: 1px solid transparent;
}

.emr-btn-primary {
    background: var(--emr-primary);
    color: #fff;
}

.emr-btn-primary:hover {
    background: var(--emr-primary-dark);
}

.emr-btn-ghost {
    border-color: var(--emr-line);
    color: var(--emr-muted);
    background: #fff;
}

.emr-btn-ghost:hover {
    border-color: var(--emr-primary);
    color: var(--emr-primary);
}

/* แถวรายละเอียดที่กางออก */
.emr-detail-row {
    display: none;
    background: #fafbff;
}

.emr-detail-row.is-open {
    display: table-row;
}

.emr-detail-row td {
    padding: 4px 16px 18px;
    color: #4a4d5c;
    line-height: 1.85;
    font-size: .92em;
}

.emr-detail-kw {
    margin-top: 10px;
    color: var(--emr-muted);
    font-size: .88em;
}

/* .emr-kw เป็นแค่กล่องครอบไว้ให้ JS หยิบไปทำดัชนีค้นหา ไม่ต้องมีสไตล์ */
.emr-detail-kw .emr-kw > span {
    display: inline-block;
    background: #eef0f6;
    border-radius: 4px;
    padding: 2px 8px;
    margin: 0 5px 5px 0;
}

/* คำที่ตรงกับการค้นหา */
mark.emr-hit {
    background: #fff2a8;
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

/* ไม่พบผลลัพธ์ */
.emr-empty {
    padding: 54px 20px;
    text-align: center;
    color: var(--emr-muted);
}

.emr-empty h3 {
    color: var(--emr-ink);
    margin: 0 0 8px;
    font-size: 1.1em;
}

.emr-empty-suggest {
    margin-top: 14px;
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.emr-empty-suggest button {
    border: 1px solid var(--emr-line);
    background: #fff;
    border-radius: 20px;
    padding: 6px 14px;
    font-family: inherit;
    font-size: .88em;
    cursor: pointer;
    color: var(--emr-primary-dark);
}

.emr-empty-suggest button:hover {
    border-color: var(--emr-primary);
}

/* ปุ่มโหลดเพิ่ม */
.emr-more {
    text-align: center;
    padding: 0 0 44px;
}

.emr-more button {
    background: #fff;
    border: 1px solid var(--emr-primary);
    color: var(--emr-primary-dark);
    border-radius: 8px;
    padding: 11px 30px;
    font-family: inherit;
    font-size: .95em;
    cursor: pointer;
}

.emr-more button:hover {
    background: var(--emr-primary);
    color: #fff;
}

/* ------------------------------------------------------------------
   ท้ายหน้า: ติดต่อ
   ------------------------------------------------------------------ */
.emr-contact {
    background: #fff;
    border: 1px solid var(--emr-line);
    border-radius: 10px;
    padding: 26px 28px;
    margin-bottom: 46px;
}

.emr-contact h2 {
    margin: 0 0 10px;
    font-size: 1.15em;
}

.emr-contact p {
    margin: 0 0 8px;
    color: var(--emr-muted);
    line-height: 1.8;
    font-size: .94em;
}

.emr-contact a {
    color: var(--emr-primary-dark);
}

.emr-source-note {
    margin-top: 16px !important;
    padding-top: 14px;
    border-top: 1px solid var(--emr-line);
    font-size: .88em !important;
    color: #8b8f9e !important;
}

/* ------------------------------------------------------------------
   จอเล็ก: ตารางแปลงเป็นการ์ด
   ------------------------------------------------------------------ */
/* จอกลาง: ลดความกว้างคอลัมน์ขวาลงก่อน */
@media (max-width: 1100px) {
    .emr-hero-grid {
        grid-template-columns: minmax(0, 1fr) 290px;
        gap: 30px;
    }

    .emr-stat-hero .emr-stat-num {
        font-size: 3.4em;
    }
}

@media (max-width: 860px) {
    :root {
        --emr-header-h: 76px;
    }

    /* จอแคบ: ตัวเลขลงมาอยู่ใต้ข้อความ */
    .emr-hero-grid {
        grid-template-columns: 1fr;
        gap: 30px;
    }

    .emr-stat-hero {
        padding: 18px;
    }

    .emr-stat-hero .emr-stat-num {
        font-size: 3em;
    }

    .emr-hero h1 {
        font-size: 1.6em;
        max-width: none;
    }

    .emr-h1-brand,
    .emr-h1-tail {
        white-space: normal;   /* จอแคบ ปล่อยให้ขึ้นบรรทัดได้ ไม่งั้นล้นขอบ */
    }

    .emr-points {
        grid-template-columns: 1fr;   /* จอแคบเหลือคอลัมน์เดียว */
    }

    /* จอเล็กไม่ต้องค้าง จะได้ไม่กินพื้นที่อ่าน */
    .emr-toolbar,
    .emr-table thead th {
        position: static;
    }

    .emr-table thead {
        display: none;
    }

    /* หมายเหตุ: ห้ามใส่ ".emr-table tr" รวมในนี้
       เพราะ specificity จะสูงกว่า ".emr-detail-row { display:none }"
       ทำให้แถวรายละเอียดกางออกเองตั้งแต่ยังไม่ได้กด */
    .emr-table,
    .emr-table tbody,
    .emr-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    /* การ์ด 1 ใบ = 1 รายงาน : ชื่อเต็มบรรทัด แล้วข้อมูลย่อยเรียงต่อกันในบรรทัดเดียว */
    .emr-table tbody tr.emr-row {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px 10px;
        background: #fff;
        border: 1px solid var(--emr-line);
        border-radius: 10px;
        margin: 0 0 10px;
        padding: 14px;
    }

    .emr-table td {
        width: auto;
        padding: 0;
    }

    .emr-table .emr-title-cell {
        width: 100%;
        min-width: 0;
        margin-bottom: 4px;
    }

    /* ป้ายกำกับช่อง: แสดงเฉพาะช่องที่ดูแล้วไม่รู้ว่าคืออะไร */
    .emr-table td[data-label]::before {
        content: attr(data-label);
        font-size: .72em;
        color: var(--emr-muted);
        margin-right: 5px;
    }

    .emr-table .emr-title-cell::before,
    .emr-table td[data-label="กลุ่มอุตสาหกรรม"]::before,
    .emr-table td[data-label="ปีข้อมูล"]::before,
    .emr-table td[data-label="ประเภท"]::before,
    .emr-table td[data-label="ขอรายงาน"]::before {
        display: none;
    }

    /* เดือน/ไตรมาส ต่อท้ายปีในบรรทัดเดียวกัน */
    .emr-date-sub {
        display: inline;
        margin-left: 5px;
    }

    .emr-price {
        width: 100%;
        margin-top: 2px;
    }

    .emr-price small {
        display: inline;
        margin-left: 5px;
    }

    .emr-table td[data-label="ขอรายงาน"] {
        width: 100%;
        margin-top: 10px;
    }

    .emr-actions {
        flex-direction: row;
    }

    .emr-actions .emr-btn {
        flex: 1;
        padding: 10px 12px;
    }

    .emr-table-wrap {
        border: 0;
        background: transparent;
    }

    .emr-detail-row.is-open {
        display: block;
        background: #fff;
        border: 1px solid var(--emr-line);
        border-radius: 10px;
        margin: -6px 0 10px;
    }

    .emr-detail-row.is-open td {
        padding: 14px;
    }
}
