/* หน้า /download: ใช้ตัวแปรสีของธีมเว็บ (fdspu.css) จึงตามโหมดสว่าง / มืดของเว็บโดยอัตโนมัติ */
.dl-page { padding: clamp(1.5rem, 4vw, 3rem) 1rem clamp(3rem, 6vw, 5rem); }
.dl-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
  max-width: 1200px;
  margin: 0 auto;
}
.dl-aside { position: sticky; top: 5rem; min-width: 0; }

/* เมนูหมวด */
.dl-menu { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border-subtle); }
.dl-tab {
  display: block;
  margin-left: -2px;
  padding: .5rem .85rem;
  border-left: 2px solid transparent;
  color: var(--text-secondary);
  font-size: .92rem;
  line-height: 1.45;
  text-decoration: none;
  transition: color .2s ease, border-color .2s ease;
}
.dl-cat-toggle, .dl-tab-count { display: none; }
.dl-tab:hover { color: var(--primary-blue); }
.dl-tab.active { border-left-color: var(--primary-blue); color: var(--primary-blue); font-weight: 600; }
.dl-tab:focus-visible, .dl-cat-toggle:focus-visible, .dl-btn:focus-visible {
  outline: 2px solid var(--primary-blue);
  outline-offset: 2px;
}

/* เนื้อหา */
.dl-tab-section { display: none; }
.dl-tab-section.is-active { display: block; }
.dl-section-title { margin: 0 0 1.25rem; color: var(--text-primary); font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.dl-empty { margin: 3rem 0; color: var(--text-muted); text-align: center; }
.dl-body-html {
  padding: clamp(1.25rem, 3vw, 2rem);
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-secondary);
  line-height: 1.75;
}
.dl-body-html + .dl-grid { margin-top: 1.25rem; }
.dl-body-html h2 { margin: 0 0 1rem; color: var(--text-primary); font-size: 1.35rem; font-weight: 700; }
.dl-body-html p { margin: 0 0 1rem; }
.dl-body-html p:last-child { margin-bottom: 0; }
.dl-body-html img { display: block; width: 100%; max-width: 100%; height: auto; border-radius: 6px; }
.dl-body-html a { color: var(--primary-blue); }
.dl-body-html a:hover { color: var(--primary-blue-hover); }

/* การ์ดไฟล์ */
.dl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.25rem; }
.dl-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.dl-card:hover { border-color: var(--primary-blue); box-shadow: var(--shadow-neumorphic-hover); }
.dl-card-thumb { position: relative; aspect-ratio: 16 / 9; background: var(--bg-tertiary); }
/* วางแบบ absolute เพื่อให้กรอบรูปสูงเท่ากันทุกการ์ด และรูปต้นฉบับขนาดเล็กไม่ถูกขยายจนแตก */
.dl-card-thumb img {
  position: absolute;
  inset: .85rem;
  width: calc(100% - 1.7rem);
  height: calc(100% - 1.7rem);
  object-fit: contain;
  border-radius: 4px;
  pointer-events: none;
}
/* เงาทับตารางให้เป็นโทนกลาง โลโก้โปร่งใสทั้งสีขาวและสีดำจึงมองเห็นชัด */
.dl-thumb-alpha { background: linear-gradient(rgba(0, 0, 0, .38), rgba(0, 0, 0, .38)), url(../dist/img/thm/alpha.png) center / 240px; }
.dl-thumb-black { background: #000; }
.dl-thumb-white { background: #fff; }
.dl-card-body { display: flex; flex: 1 1 auto; flex-direction: column; padding: 1.1rem 1.25rem 1.25rem; }
.dl-card-title { margin: 0 0 .35rem; color: var(--text-primary); font-size: 1rem; font-weight: 600; line-height: 1.4; }
.dl-card-desc { margin: 0 0 1rem; color: var(--text-secondary); font-size: .85rem; line-height: 1.65; overflow-wrap: anywhere; }
.dl-card-action { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; margin-top: auto; }
.dl-card-note { flex-basis: 100%; color: var(--text-muted); font-size: .75rem; line-height: 1.5; }
.dl-badge {
  padding: .1rem .5rem;
  background: var(--theme-primary-light);
  border-radius: 4px;
  color: var(--primary-blue);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
}
.dl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 40px;
  padding: .45rem 1rem;
  background: var(--primary-blue);
  border: 1px solid var(--primary-blue);
  border-radius: 8px;
  color: #fff;
  font-size: .88rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
.dl-btn:hover { background: #1d4ed8; border-color: #1d4ed8; color: #fff; }
.dl-btn-locked { background: transparent; color: var(--primary-blue); }
.dl-btn-locked:hover { background: var(--theme-primary-light); border-color: var(--primary-blue); color: var(--primary-blue); }
.dl-icon { flex: none; width: 1.1em; height: 1.1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* แท็บเล็ตและโทรศัพท์: แผงเลือกหมวดที่เห็นทุกหมวดพร้อมกัน */
@media (max-width: 991.98px) {
  .category-page-hero { padding-top: 1.5rem; padding-bottom: 1.5rem; }
  .dl-page { padding-top: 1rem; }
  /* ชื่อหมวดแสดงที่แถบเลือกหมวดอยู่แล้ว ซ่อนหัวข้อที่ซ้ำแต่คงไว้ให้โปรแกรมอ่านหน้าจอและ Google */
  .dl-section-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  /* ใช้ block + contents เพื่อให้แถบหมวดติดหน้าจอได้ตลอดความยาวของรายการไฟล์ */
  .dl-layout { display: block; }
  .dl-aside { display: contents; }
  .dl-cat {
    position: sticky;
    top: 58px;
    z-index: 20;
    margin-bottom: 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    box-shadow: var(--shadow-neumorphic-hover);
  }
  .dl-cat-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    width: 100%;
    min-height: 52px;
    padding: .4rem .9rem;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--text-primary);
    font: inherit;
    text-align: left;
  }
  .dl-cat-toggle-text { display: flex; flex-direction: column; min-width: 0; font-weight: 600; line-height: 1.35; }
  .dl-cat-toggle small { color: var(--text-muted); font-size: .72rem; font-weight: 400; }
  .dl-cat-caret {
    flex: none;
    width: 9px;
    height: 9px;
    margin-right: .25rem;
    border-right: 2px solid var(--primary-blue);
    border-bottom: 2px solid var(--primary-blue);
    transform: translateY(-2px) rotate(45deg);
    transition: transform .15s ease;
  }
  .dl-cat-toggle[aria-expanded="true"] .dl-cat-caret { transform: translateY(2px) rotate(-135deg); }
  .dl-menu {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
    padding: 0 .6rem .6rem;
    border-left: 0;
  }
  .dl-menu.is-collapsed { display: none; }
  .dl-tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .4rem;
    height: 100%;
    min-height: 44px;
    margin-left: 0;
    padding: .4rem .65rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: .82rem;
    line-height: 1.3;
  }
  .dl-tab.active { background: var(--primary-blue); border-color: var(--primary-blue); color: #fff; }
  .dl-tab-count { display: inline; flex: none; color: var(--text-muted); font-size: .72rem; }
  .dl-tab.active .dl-tab-count { color: rgba(255, 255, 255, .85); }
}

/* โทรศัพท์: รายการไฟล์แบบ List View รูปอยู่ซ้าย รายละเอียดอยู่ขวา */
@media (max-width: 767.98px) {
  .dl-grid { grid-template-columns: minmax(0, 1fr); gap: .65rem; }
  .dl-card { flex-direction: row; }
  .dl-card-thumb { flex: 0 0 88px; align-self: stretch; aspect-ratio: auto; min-height: 88px; }
  /* รูปอยู่ด้านบนของแถว การ์ดที่คำอธิบายยาวจะไม่ได้รูปลอยอยู่กลางแถว */
  .dl-card-thumb img { inset: .5rem .5rem auto; width: calc(100% - 1rem); height: 72px; }
  .dl-card-body { flex: 1 1 0; min-width: 0; padding: .7rem .8rem .8rem; }
  .dl-body-html h2 { font-size: 1.15rem; }
  .dl-card-title { margin-bottom: .2rem; font-size: .92rem; }
  .dl-card-desc { margin-bottom: .65rem; font-size: .8rem; line-height: 1.55; }
  .dl-btn { min-height: 44px; }
  .dl-card-action .dl-btn { flex: 1 1 auto; }
}
