/* ===================================================================
   style.css — ศูนย์ดาวน์โหลดเอกสาร (เวอร์ชันมืออาชีพ)
   โทนน้ำเงิน–เทา สะอาดตา ทันสมัย รองรับมือถือ
   =================================================================== */

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-darker: #172554;
    --primary-light: #eff5ff;
    --accent: #f59e0b;
    --bg: #f6f8fc;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --border: #e6eaf1;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, .06);
    --shadow-md: 0 10px 30px rgba(15, 23, 42, .08);
    --shadow-lg: 0 20px 50px rgba(37, 99, 235, .20);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Sarabun', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container { width: min(1240px, 92%); margin: 0 auto; }

a { color: inherit; text-decoration: none; }

svg { display: block; width: 100%; height: 100%; }

/* ===== Header ===== */
.site-header {
    background: rgba(255, 255, 255, .85);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
    width: 48px; height: 48px;
    display: grid; place-items: center;
    color: #fff;
    background: linear-gradient(140deg, var(--primary), var(--primary-dark));
    border-radius: 13px;
    box-shadow: var(--shadow-sm);
}
.brand-logo svg { width: 26px; height: 26px; }
.brand-org { font-size: 12.5px; color: var(--text-muted); font-weight: 500; letter-spacing: .2px; }
.brand-title {
    font-family: 'Prompt', sans-serif;
    font-size: 19px; font-weight: 700; color: var(--primary-darker);
    line-height: 1.25;
}
.header-contact {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--primary-light);
    color: var(--primary);
    padding: 10px 18px;
    border-radius: 999px;
    font-weight: 600; font-size: 14px;
    transition: .2s;
    white-space: nowrap;
}
.header-contact svg { width: 17px; height: 17px; }
.header-contact:hover { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }

/* ===== Hero ===== */
.hero {
    background:
        radial-gradient(900px 380px at 88% -10%, rgba(245, 158, 11, .28), transparent 60%),
        linear-gradient(135deg, var(--primary-darker), var(--primary-dark) 55%, var(--primary));
    color: #fff;
    padding: 56px 0 72px;
}
.hero-tagline {
    font-family: 'Prompt', sans-serif;
    font-size: clamp(22px, 3.2vw, 33px);
    font-weight: 600;
    margin-bottom: 26px;
    max-width: 760px;
    line-height: 1.3;
}
.search-bar {
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: 999px;
    padding: 7px 7px 7px 18px;
    max-width: 680px;
    box-shadow: var(--shadow-lg);
}
.search-icon { width: 20px; height: 20px; color: var(--text-soft); flex: 0 0 auto; }
.search-bar input {
    flex: 1;
    border: none; outline: none;
    padding: 12px 14px;
    font-size: 16px;
    font-family: inherit;
    background: transparent;
    color: var(--text);
    min-width: 0;
}
.search-bar button {
    background: linear-gradient(135deg, var(--accent), #e08a06);
    color: #fff;
    border: none;
    padding: 12px 30px;
    border-radius: 999px;
    font-family: 'Prompt', sans-serif;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: .2s;
    flex: 0 0 auto;
}
.search-bar button:hover { filter: brightness(1.06); transform: translateY(-1px); }

.hero-stats {
    display: flex;
    gap: 14px;
    margin-top: 30px;
    flex-wrap: wrap;
}
.stat {
    display: flex;
    align-items: center;
    gap: 12px;
    /* พื้นเข้มของตัวเอง เพื่อให้ตัวอักษรขาวตัดกับพื้นหลังชัดทุกตำแหน่ง (แม้ทับโซนแสงสีส้ม) */
    background: rgba(15, 23, 42, .38);
    border: 1px solid rgba(255, 255, 255, .22);
    backdrop-filter: blur(4px);
    padding: 14px 20px;
    border-radius: 14px;
}
.stat-ico {
    width: 34px; height: 34px; padding: 7px;
    color: #fff;
    background: rgba(255, 255, 255, .16);
    border-radius: 9px;
    flex: 0 0 auto;
}
.stat-num { font-family: 'Prompt', sans-serif; font-size: 22px; font-weight: 700; }
.stat-label { font-size: 13px; opacity: .82; }

/* ===== Layout ===== */
.main-grid {
    display: grid;
    grid-template-columns: 264px 1fr;
    gap: 28px;
    margin-top: -36px;
    margin-bottom: 64px;
    position: relative; z-index: 2;
    align-items: start;
}

/* ===== Sidebar ===== */
.sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 16px;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 88px;
}
.sidebar-title {
    font-family: 'Prompt', sans-serif;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-soft);
    padding: 0 8px 12px;
}
.cat-list { display: flex; flex-direction: column; gap: 3px; }
.cat-group { margin-top: 12px; }
.cat-group:first-of-type { margin-top: 2px; }
.cat-group-title {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    width: 100%; background: transparent; border: none; cursor: pointer; text-align: left;
    font-family: 'Prompt', sans-serif;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--primary);
    padding: 10px 8px 6px;
    margin-bottom: 2px;
    border-top: 1px solid var(--border);
}
.cat-group-title { border-radius: 8px; transition: background .15s, color .15s; }
.cat-group-title:hover { color: var(--primary-dark); background: var(--primary-light); }

/* ---- เครื่องมือ + ปุ่มย่อ/ขยาย ---- */
.sidebar-tools { display: flex; gap: 6px; margin-bottom: 10px; }
.tool-toggle {
    flex: 1; font-family: inherit; font-size: 12px; font-weight: 600;
    padding: 6px 8px; border: 1px solid var(--border); background: #fff;
    border-radius: 8px; color: var(--text-muted); cursor: pointer; transition: .15s;
}
.tool-toggle:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.cat-row { display: flex; align-items: stretch; gap: 2px; }
.cat-row > .cat-item, .cat-row > .cat-subitem { flex: 1; min-width: 0; }
.cat-caret {
    flex: 0 0 auto; width: 28px; border: none; background: transparent; cursor: pointer;
    display: grid; place-items: center; border-radius: 8px; color: var(--text-soft);
}
.cat-caret:hover { background: var(--primary-light); color: var(--primary); }

/* สามเหลี่ยมลูกศร — ชี้ลงเมื่อขยาย, หมุนชี้ขวาเมื่อย่อ */
.caret {
    width: 0; height: 0; display: inline-block;
    border-left: 4px solid transparent; border-right: 4px solid transparent;
    border-top: 5px solid currentColor; transition: transform .15s;
}
.cat-group-title .caret { border-top-color: var(--primary); }

/* สถานะย่อ */
.cat-node.collapsed > .cat-sublist,
.cat-node.collapsed > .cat-grouplist { display: none; }
.cat-group.collapsed > .cat-group-body { display: none; }
.cat-node.collapsed > .cat-row .cat-caret .caret { transform: rotate(-90deg); }
.cat-group.collapsed > .cat-group-title .caret { transform: rotate(-90deg); }

.cat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 14.5px;
    color: var(--text);
    transition: .15s;
    position: relative;
}
.cat-item { align-items: flex-start; }
.cat-item .cat-name,
.cat-subitem .cat-name,
.cat-groupitem .cat-name {
    flex: 1;
    line-height: 1.35;
    overflow-wrap: anywhere;   /* แสดงชื่อเต็ม ขึ้นบรรทัดใหม่แทนการตัด … */
}
.cat-count { margin-top: 1px; }
.cat-item:hover { background: var(--primary-light); color: var(--primary-dark); }
.cat-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    box-shadow: var(--shadow-sm);
}
.cat-count {
    flex: 0 0 auto;
    background: rgba(15, 23, 42, .06);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 999px;
}
.cat-item:hover .cat-count { background: rgba(37, 99, 235, .14); color: var(--primary); }
.cat-item.active .cat-count { background: rgba(255, 255, 255, .25); color: #fff; }

/* หมวดย่อย */
.cat-sublist {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 3px 0 5px 14px;
    padding-left: 10px;
    border-left: 2px solid var(--border);
}
.cat-subitem {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 11px;
    border-radius: 9px;
    font-size: 13.5px;
    color: var(--text-muted);
    transition: .15s;
}
.cat-subitem { align-items: flex-start; }
.cat-subitem:hover { background: var(--primary-light); color: var(--primary-dark); }
.cat-subitem.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.cat-subitem .cat-count {
    flex: 0 0 auto;
    background: rgba(15, 23, 42, .05);
    color: var(--text-muted);
    font-size: 11px; font-weight: 600;
    padding: 1px 8px; border-radius: 999px;
}
.cat-subitem.active .cat-count { background: rgba(37, 99, 235, .14); color: var(--primary); }

/* กลุ่มย่อย (ระดับ 3) */
.cat-grouplist {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 2px 0 4px 12px;
    padding-left: 9px;
    border-left: 2px dashed var(--border);
}
.cat-groupitem {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12.5px;
    color: var(--text-soft);
    transition: .15s;
}
.cat-groupitem:hover { background: var(--primary-light); color: var(--primary-dark); }
.cat-groupitem.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.cat-groupitem .cat-count {
    flex: 0 0 auto; margin-top: 1px;
    background: rgba(15, 23, 42, .05);
    color: var(--text-muted);
    font-size: 10.5px; font-weight: 600;
    padding: 1px 7px; border-radius: 999px;
}
.cat-groupitem.active .cat-count { background: rgba(37, 99, 235, .14); color: var(--primary); }

/* ===== Content ===== */
.content-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
    /* กล่องพื้นขาว เพื่อให้หัวข้อหมวดอ่านง่าย ไม่จมไปกับพื้น hero สีน้ำเงิน */
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px 20px;
    /* ล็อกให้ติดด้านบนเสมอเวลาเลื่อน (อยู่ใต้แถบหัวเว็บ) */
    position: sticky;
    top: 76px;
    z-index: 20;
}
.content-head h2 {
    font-family: 'Prompt', sans-serif;
    font-size: 22px;
    color: var(--primary-darker);
}
.content-head h2 small { font-weight: 400; color: var(--text-muted); font-size: 16px; }
.result-count {
    color: var(--text-muted); font-size: 13.5px;
    background: var(--surface); border: 1px solid var(--border);
    padding: 4px 12px; border-radius: 999px;
}

/* ===== Doc list (1 การ์ดต่อแถว) ===== */
.doc-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}
.doc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-xs);
    transition: transform .16s, box-shadow .16s, border-color .16s;
}
.doc-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #cdd9ee;
}

/* ไอคอนชนิดไฟล์ — กล่องโทนอ่อน */
.doc-icon {
    flex: 0 0 auto;
    width: 56px; height: 56px;
    border-radius: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
}
.doc-icon svg { width: 22px; height: 22px; }
.doc-ext {
    font-family: 'Prompt', sans-serif;
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: .4px;
    line-height: 1;
}

.doc-body { flex: 1 1 320px; min-width: 0; }
.doc-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}
.doc-desc {
    font-size: 13.5px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 7px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.doc-meta {
    display: flex; align-items: center; gap: 8px;
    font-size: 12.5px; color: var(--text-soft);
    flex-wrap: wrap;
}
.doc-cat {
    color: var(--primary);
    font-weight: 600;
    background: var(--primary-light);
    padding: 2px 10px;
    border-radius: 999px;
}
.doc-dot { opacity: .5; }

/* ปุ่ม */
.doc-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 122px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    transition: .18s;
    white-space: nowrap;
    cursor: pointer;
}
.btn svg { width: 17px; height: 17px; }
.btn-view {
    background: #fff;
    color: var(--primary);
    border: 1px solid #d4ddee;
}
.btn-view:hover { background: var(--primary-light); border-color: var(--primary); }
.btn-download {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: 1px solid transparent;
    box-shadow: var(--shadow-xs);
}
.btn-download:hover { filter: brightness(1.07); box-shadow: var(--shadow-sm); transform: translateY(-1px); }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 26px;
}
.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    transition: .16s;
}
.page-btn svg { width: 16px; height: 16px; }
.page-btn:hover:not(.disabled):not(.active) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}
.page-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-color: transparent;
    color: #fff;
    box-shadow: var(--shadow-sm);
    cursor: default;
}
.page-nav { font-weight: 600; }
.page-btn.disabled {
    opacity: .45;
    cursor: not-allowed;
    color: var(--text-soft);
}
.page-ellipsis {
    min-width: 28px;
    text-align: center;
    color: var(--text-soft);
    font-weight: 600;
}
@media (max-width: 480px) {
    .page-nav span { display: none; }   /* มือถือ: เหลือไอคอนลูกศร */
    .page-nav { padding: 0; min-width: 40px; }
}

/* ===== Empty state ===== */
.empty {
    background: var(--surface);
    border: 1.5px dashed #d4ddee;
    border-radius: var(--radius);
    padding: 64px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty-icon { width: 56px; height: 56px; margin: 0 auto 14px; color: var(--text-soft); }
.btn-ghost {
    display: inline-block;
    margin-top: 16px;
    padding: 10px 24px;
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 999px;
    font-weight: 600;
    transition: .2s;
}
.btn-ghost:hover { background: var(--primary); color: #fff; }

/* ===== Footer ===== */
.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 24px 0;
}
.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 13.5px;
    flex-wrap: wrap;
    gap: 8px;
}
.footer-inner a { color: var(--primary); font-weight: 500; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
    .main-grid { grid-template-columns: 1fr; }
    .sidebar { position: static; }
}
@media (max-width: 560px) {
    .doc-card { flex-direction: column; align-items: stretch; gap: 12px; }
    .doc-icon { width: 48px; height: 48px; }
    .doc-actions { width: 100%; }
    .btn { flex: 1; min-width: 0; }
    .header-contact span { display: none; }
    .header-contact { padding: 10px; }
    .search-bar { flex-wrap: wrap; border-radius: 16px; padding: 10px 14px; }
    .search-bar button { width: 100%; margin-top: 8px; }
    .hero-stats { gap: 10px; }
    .stat { flex: 1 1 calc(50% - 10px); }
}
