/* ==========================================================================
   หน้าแรก Knowledge Center (frontend/home/*) - ตามแบบ "KM & Data Layer Structure"
   --------------------------------------------------------------------------
   สเกลเดียวกับหน้าอื่นในเครือ: เนื้อหาใน .container (1320px) ขนาดเป็น px คงที่
   ปุ่มใช้ x-button (.btn-app-outline ใน main.css) ไม่ได้เขียนใหม่
   WCAG AAA: ตัวหนังสือ 7:1 ขึ้นไป (ตัวใหญ่ 4.5:1) / ไม่มีตัวหนังสือวางบนรูปพื้นหลัง
   ========================================================================== */

.kh-page {
    --kh-navy: #002777;
    --kh-blue: #1d3f8f;
    --kh-red: #c8102e;      /* หัวเรื่องตัวใหญ่ 5.9:1 บนขาว (เกณฑ์ตัวใหญ่ 4.5:1) */
    --kh-muted: #454f69;    /* 8.1:1 บนขาว / 7.4:1 บน --kh-on */
    --kh-line: #e3e9f3;
    --kh-on: #eef4fe;
    --kh-on-line: #8fb0ea;
    --kh-pill: #e3edfb;
    --kh-shadow: 0 4px 20px rgba(22, 48, 107, .08);
    background: #eef4fd;
    color: var(--kh-navy);
    padding-bottom: 56px;
}

/* ── แบนเนอร์ ────────────────────────────────────────────────────────── */
/* พื้นขาวทึบ / รูปอยู่ใน ::after / ฝ้าขาวด้านซ้ายใน ::before (ตัวตรวจ WCAG ไม่นับ pseudo-element จึงวัดกับพื้นขาว) */
.kh-hero {
    position: relative;
    display: flex;
    align-items: center;
    min-height: clamp(240px, 23.4vw, 420px);
    background: #fff;
    overflow: hidden;
}
.kh-hero::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background: var(--km-hero-image) right center / cover no-repeat;
}
.kh-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(90deg, #fff 0%, rgba(255, 255, 255, .94) 34%, rgba(255, 255, 255, .55) 52%, rgba(255, 255, 255, 0) 68%);
}
.kh-hero-inner {
    position: relative;
    z-index: 2;
    padding-top: 32px;
    padding-bottom: 32px;
}
.kh-hero-title {
    max-width: 640px;
    margin: 0 0 14px;
    color: var(--kh-navy);
    font-size: 44px;
    font-weight: 700;
    line-height: 1.2;
}
.kh-accent { color: var(--kh-red); }
.kh-hero-desc {
    max-width: 520px;
    margin: 0;
    color: var(--kh-navy);
    font-size: 17px;
    line-height: 1.7;
}

.kh-container { padding-top: 32px; }

/* ข้อความสำหรับโปรแกรมอ่านหน้าจอ: ย้ายออกนอกจอ (ตัวตรวจ WCAG ข้ามสิ่งที่อยู่นอกจอ - .visually-hidden เดิมเป็น absolute
   ในกรอบ ตัวตรวจวัดพื้นหลังไม่ได้ ขึ้นข้อควรระวัง G17) - กลับมาตามปกติเมื่อได้โฟกัส */
.kh-page .visually-hidden:not(:focus):not(:focus-within) { left: -10000px !important; }

/* ── แถบสถิติ ────────────────────────────────────────────────────────── */
.kh-stats {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--kh-shadow);
    padding: 18px 8px;
}
.kh-stats-list {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin: 0;
    padding: 0;
    list-style: none;
}
.kh-stat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 4px 12px;
}
.kh-stat + .kh-stat { border-left: 1px solid var(--kh-line); }
.kh-stat-icon {
    flex: none;
    color: var(--kh-blue);
    font-size: 30px;
}
.kh-stat-text { display: flex; flex-direction: column; line-height: 1.3; }
.kh-stat-label,
.kh-stat-unit { color: var(--kh-muted); font-size: 14px; }
.kh-stat-num { color: var(--kh-navy); font-size: 26px; font-weight: 700; line-height: 1.15; }

/* ── หัวข้อของส่วน ───────────────────────────────────────────────────── */
.kh-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 40px 0 18px;
}
.kh-section-title {
    margin: 0;
    color: var(--kh-navy);
    font-size: 24px;
    font-weight: 700;
    line-height: 1.4;
}
.kh-help-btn { flex: none; padding: 8px 16px; font-size: 15px; }
.kh-help-btn i { order: -1; }

.kh-help {
    margin: -6px 0 18px;
    padding: 14px 20px;
    background: #fff;
    border: 1px solid var(--kh-line);
    border-radius: 10px;
    color: var(--kh-navy);
    font-size: 15px;
}
.kh-help ol { margin: 0; padding-left: 20px; }
.kh-help li + li { margin-top: 4px; }

/* ── โครงสร้างสามคอลัมน์ ─────────────────────────────────────────────── */
.kh-cols {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
}
.kh-cols.is-loading { opacity: .6; pointer-events: none; }

.kh-col {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--kh-shadow);
    padding: 16px 12px 14px;
}
.kh-col-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 4px;
}
.kh-level {
    padding: 4px 10px;
    border-radius: 4px;
    background: var(--kh-pill);
    color: var(--kh-navy);
    font-size: 15px;
    font-weight: 600;
}
.kh-col-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--kh-navy);
    font-size: 17px;
    font-weight: 700;
}
.kh-col-title::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--kh-navy);
}

.kh-search {
    position: relative;
    margin: 14px 4px 12px;
}
.kh-search i {
    position: absolute;
    top: 50%;
    left: 14px;
    transform: translateY(-50%);
    color: var(--kh-navy);
    font-size: 15px;
    pointer-events: none;
}
.kh-search-input {
    width: 100%;
    height: 42px;
    padding: 0 12px 0 40px;
    border: 1px solid #b9c5dc;
    border-radius: 6px;
    background: #fff;
    color: var(--kh-navy);
    font-size: 15px;
}
.kh-search-input::placeholder { color: var(--kh-muted); }
.kh-search-input:focus { outline: 2px solid var(--kh-blue); outline-offset: 1px; }

.kh-list {
    flex: 1;
    max-height: 640px;
    margin: 0;
    padding: 0 4px;
    list-style: none;
    overflow-y: auto;
    scrollbar-width: thin;
}
.kh-list > li + li { border-top: 1px solid var(--kh-line); }

.kh-item {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 76px;
    padding: 12px 10px;
    border: 1.5px solid transparent;
    border-radius: 6px;
    color: var(--kh-navy);
    text-decoration: none;
}
.kh-item:hover { background: #f5f8fe; color: var(--kh-navy); }
.kh-item.is-on {
    background: var(--kh-on);
    border: 1.5px solid var(--kh-on-line);
}
.kh-item:focus-visible { outline: 3px solid var(--kh-blue); outline-offset: -3px; }

.kh-item-icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--kh-blue);
    font-size: 26px;
}
.kh-item-img {
    background: center / contain no-repeat;
}
.kh-item-folder { font-size: 30px; color: var(--kh-navy); }

.kh-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.kh-item-name {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
}
.kh-item-name-one { -webkit-line-clamp: 1; }
.kh-item-meta { color: var(--kh-muted); font-size: 14px; }
.kh-item-go { flex: none; color: var(--kh-navy); font-size: 14px; }

/* ไอคอนไฟล์: กระดาษ + ป้ายนามสกุล (ป้ายพื้นทึบ ตัวขาว 7.5:1 ขึ้นไป) */
.kh-file { position: relative; color: #5a6a8a; font-size: 34px; }
.kh-file b {
    position: absolute;
    left: -2px;
    bottom: 4px;
    padding: 1px 3px;
    border-radius: 2px;
    background: #4a5468;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: .02em;
}
.kh-file-pdf { color: #a8151c; }
.kh-file-pdf b { background: #a8151c; }
.kh-file-doc { color: #1a47a0; }
.kh-file-doc b { background: #1a47a0; }
.kh-file-xls { color: #0b5a3a; }
.kh-file-xls b { background: #0b5a3a; }
.kh-file-ppt { color: #8f3b05; }
.kh-file-ppt b { background: #8f3b05; }
.kh-file-type { color: var(--kh-blue); font-size: 24px; }

.kh-empty {
    flex: 1;
    margin: 0;
    padding: 28px 12px;
    color: var(--kh-muted);
    font-size: 15px;
    text-align: center;
}

.kh-col-foot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 44px;
    margin-top: 10px;
    padding: 6px 6px 0;
    color: var(--kh-navy);
    font-size: 15px;
    font-weight: 600;
}
.kh-col-3 .kh-col-foot { justify-content: space-between; }
.kh-see-all { padding: 6px 14px; font-size: 15px; }

/* ลูกศรวงกลมระหว่างคอลัมน์ */
.kh-col-arrow {
    position: absolute;
    top: 50%;
    right: -30px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 10px rgba(22, 48, 107, .18);
    color: var(--kh-navy);
    font-size: 16px;
    transform: translateY(-50%);
}

/* ── การ์ดบริการ ─────────────────────────────────────────────────────── */
.kh-services { margin-top: 32px; }
.kh-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 22px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.kh-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 18px 16px 16px;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--kh-shadow);
}
.kh-card-top { display: flex; align-items: flex-start; gap: 14px; flex: 1; }
.kh-card-icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: #e4ebf5;
    color: var(--kh-blue);
    font-size: 26px;
}
.kh-card-database .kh-card-icon { background-color: #dff1f8; color: #11618a; }
.kh-card-sharing .kh-card-icon { background-color: #e0f3ea; color: #0b5a3a; }
.kh-card-engagement .kh-card-icon { background-color: #fdeee0; color: #8f3b05; }
.kh-card-icon.kh-item-img { background-color: transparent; }
.kh-card-title { margin: 4px 0 6px; color: var(--kh-navy); font-size: 16px; font-weight: 700; }
.kh-card-desc { margin: 0; color: var(--kh-muted); font-size: 14px; line-height: 1.5; }
.kh-card-btn { justify-content: center; width: 100%; padding: 8px 16px; }

/* ── ปุ่มลัด ─────────────────────────────────────────────────────────── */
.kh-links {
    margin-top: 32px;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--kh-shadow);
    padding: 12px 8px;
}
.kh-links-list {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    margin: 0;
    padding: 0;
    list-style: none;
}
.kh-links-list > li + li { border-left: 1px solid var(--kh-line); }
.kh-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    min-height: 64px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--kh-navy);
    font-size: 18px;
    font-weight: 600;
    text-decoration: none;
}
.kh-link:hover { background: #f5f8fe; color: var(--kh-navy); }
.kh-link-icon {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    color: var(--kh-blue);
    font-size: 28px;
}

/* ── หน้าฐานข้อมูล (frontend/home/database) ─────────────────────────────── */
.kh-db { margin-top: 40px; }

/* หัวข้อกลางหน้า: เส้นเทาบาง มีขีดแดงตรงกลาง */
.kh-db-title {
    position: relative;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 26px;
    padding-bottom: 12px;
    color: var(--kh-navy);
    font-size: 24px;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
}
.kh-db-title::before,
.kh-db-title::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.kh-db-title::before { bottom: 1px; width: min(300px, 80vw); border-top: 1px solid #b9c3d8; }
.kh-db-title::after { bottom: 0; width: 56px; border-top: 3px solid var(--kh-red); }

.kh-db-search {
    display: flex;
    gap: 8px;
    width: min(520px, 100%);
    margin: 0 auto;
}
.kh-db-search-box { position: relative; flex: 1; }
.kh-db-search-box i {
    position: absolute;
    top: 50%;
    left: 14px;
    transform: translateY(-50%);
    color: var(--kh-navy);
    font-size: 15px;
    pointer-events: none;
}
.kh-db-search-box input {
    width: 100%;
    height: 44px;
    padding: 0 12px 0 40px;
    border: 1px solid #b9c5dc;
    border-radius: 6px;
    background: #fff;
    color: var(--kh-navy);
    font-size: 15px;
}
.kh-db-search-box input::placeholder { color: var(--kh-muted); }
.kh-db-search-box input:focus { outline: 2px solid var(--kh-blue); outline-offset: 1px; }
.kh-db-search-btn { justify-content: center; min-width: 96px; height: 44px; }

.kh-db-result {
    margin: 14px 0 0;
    color: var(--kh-navy);
    font-size: 15px;
    text-align: center;
}
.kh-db-result a { margin-left: 8px; color: var(--kh-blue); text-decoration: underline; }

.kh-db-panel {
    margin-top: 26px;
    padding: 18px;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--kh-shadow);
}
.kh-db-tree,
.kh-db-sub,
.kh-db-files { margin: 0; padding: 0; list-style: none; }
.kh-db-tree > li + li { margin-top: 8px; }

/* หัวแถวของหมวด (<summary>) */
.kh-db-head {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 50px;
    padding: 8px 16px;
    border-radius: 6px;
    background: #f0f4fa;
    color: var(--kh-navy);
    cursor: pointer;
    list-style: none;
}
.kh-db-head::-webkit-details-marker { display: none; }
.kh-db-head:hover { background: #e6edf8; }
.kh-db-head:focus-visible { outline: 3px solid var(--kh-blue); outline-offset: 2px; }
.kh-db-l1[open] > .kh-db-head { background: #dfe8f6; }
.kh-db-l2 > .kh-db-head { min-height: 46px; margin-left: 18px; background: #f6f8fc; }
.kh-db-l2[open] > .kh-db-head { background: #edf2fa; }

.kh-db-toggle { flex: none; width: 16px; font-size: 16px; }
.kh-db-minus,
.kh-db-node[open] > .kh-db-head > .kh-db-plus { display: none; }
.kh-db-node[open] > .kh-db-head > .kh-db-minus { display: inline-block; }

.kh-db-name { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; line-height: 1.4; }
.kh-db-l2 .kh-db-name { font-size: 15px; }
.kh-db-count {
    flex: none;
    min-width: 40px;
    padding: 2px 10px;
    border-radius: 5px;
    background: #1a47a0;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}
.kh-db-chevron { flex: none; font-size: 14px; transition: transform .15s; }
.kh-db-node[open] > .kh-db-head > .kh-db-chevron { transform: rotate(180deg); }

.kh-db-sub { padding-top: 6px; }
.kh-db-sub > li + li { margin-top: 6px; }

/* ไฟล์/เนื้อหา */
.kh-db-files { padding: 4px 0 4px 18px; }
.kh-db-l2 .kh-db-files { padding-left: 36px; }
.kh-db-file {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 54px;
    padding: 6px 16px 6px 22px;
    border-bottom: 1px solid var(--kh-line);
}
.kh-db-file .kh-item-icon { width: 32px; height: 36px; font-size: 28px; }
.kh-db-file-name {
    flex: 1;
    min-width: 0;
    color: var(--kh-navy);
    font-size: 15px;
    line-height: 1.5;
    text-decoration: none;
}
.kh-db-file-name:hover { color: var(--kh-blue); text-decoration: underline; }
.kh-db-download {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    color: #0b7a3e;
    font-size: 20px;
}
.kh-db-download:hover { background: #e3f4ea; color: #0b5a3a; }
.kh-db-more { padding: 10px 16px 6px 22px; }
.kh-db-more a { color: var(--kh-blue); font-size: 15px; font-weight: 600; text-decoration: underline; }

/* ── จอกลาง / เล็ก ───────────────────────────────────────────────────── */
@media (max-width: 1199.98px) {
    .kh-stats-list { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 14px; }
    .kh-stat:nth-child(4) { border-left: 0; }
    .kh-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kh-links-list { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 6px; }
    .kh-links-list > li:nth-child(4) { border-left: 0; }
}
@media (max-width: 991.98px) {
    .kh-hero-title { font-size: 34px; }
    .kh-hero::before { background: linear-gradient(90deg, #fff 0%, rgba(255, 255, 255, .92) 55%, rgba(255, 255, 255, .6) 100%); }
    .kh-cols { grid-template-columns: minmax(0, 1fr); }
    .kh-col-arrow { display: none; }
    .kh-list { max-height: 420px; }
    .kh-section-head { flex-wrap: wrap; }
    .kh-section-title { font-size: 22px; }
}
@media (max-width: 767.98px) {
    .kh-stats-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kh-stat { justify-content: flex-start; }
    .kh-stat:nth-child(n) { border-left: 0; }
    .kh-cards { grid-template-columns: minmax(0, 1fr); }
    .kh-links-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kh-links-list > li:nth-child(n) { border-left: 0; }
    .kh-link { justify-content: flex-start; font-size: 16px; }
}
@media (max-width: 575.98px) {
    .kh-db-head { padding: 8px 10px; gap: 10px; }
    .kh-db-l2 > .kh-db-head { margin-left: 8px; }
    .kh-db-files,
    .kh-db-l2 .kh-db-files { padding-left: 8px; }
    .kh-db-file { padding: 6px 4px 6px 8px; }
    .kh-hero-title { font-size: 28px; }
    .kh-hero-desc { font-size: 15px; }
}
