/* ============================================================
   Department Detail v3 — โทนเทา-ทอง ตาม major_detail_v3
   ============================================================ */

:root {
    --ink: #1a1c20;
    --ink-2: #3d424c;
    --muted: #767b86;
    --y-brand: #e8c65a;
    --y-brand-hover: #dcb646;
    --gold: #8f6f22;
    --gold-bright: #c39429;
    --gold-line: #e2cf9d;
    --gold-tint: #fffceb;
    --paper: #ffffff;
    --canvas: #f5f6f8;
    --line: #e2e5ea;
    --sans: 'Noto Sans Thai', -apple-system, 'Segoe UI', sans-serif;
    --r-lg: 14px;
    --r-md: 10px;
    --r-sm: 8px;
    --lift: 0 10px 24px -16px rgba(26, 28, 32, .45);
}

body {
    font-family: var(--sans);
    background-color: var(--canvas);
    color: var(--ink-2);
    line-height: 1.7;
}

@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

/* ---------- ภาพส่วนหัว ---------- */
.page-header {
    margin-bottom: 0;
    border-bottom: 3px solid var(--y-brand);
    background: var(--ink);
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.page-header img {
    display: block;
    width: 100%;
    max-width: 100%;
    /* สูงตามความกว้างจอ: มือถือ ~160px → จอใหญ่สูงสุด 360px */
    height: clamp(10rem, 28vw, 22.5rem);
    object-fit: cover;
    object-position: center;
}

.page-container {
    max-width: 1120px;
    padding-top: 2.25rem;
    padding-bottom: 4.5rem;
}

.eyebrow {
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .04em;
    color: var(--muted);
    margin: 0 0 .5rem;
}

.eyebrow-gold { color: var(--gold); }

.crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    list-style: none;
    padding: 0;
    margin: 0 0 1.75rem;
    font-size: .88rem;
    color: var(--muted);
}

.crumbs li + li::before {
    content: '/';
    margin: 0 .6rem;
    color: #c3c0b8;
}

.crumbs a {
    color: var(--ink-2);
    text-decoration: none;
    border-bottom: 1px solid transparent;
}

.crumbs a:hover {
    color: var(--gold);
    border-bottom-color: var(--gold-line);
}

.dept-hero-title {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--line);
}

.dept-hero-title h1 {
    font-size: clamp(1.65rem, 2.4vw, 2.15rem);
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    line-height: 1.35;
    position: relative;
    display: inline-block;
}

.dept-hero-title h1::after {
    content: '';
    display: block;
    width: 3.5rem;
    height: 3px;
    margin-top: .85rem;
    background: var(--y-brand);
    border-radius: 999px;
}

/* ---------- โครงหลัก + ด้านข้าง ---------- */
.dept-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1.5rem 1.75rem;
    align-items: start;
}

.dept-main { min-width: 0; }
.dept-aside {
    position: sticky;
    top: 5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.aside-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 1.25rem 1.35rem 1.4rem;
}

.chair-card {
    border-top: 3px solid var(--y-brand);
}

.chair {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
}

.chair-name {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 .35rem;
    line-height: 1.4;
}

.chair-role {
    margin: 0;
    font-size: .92rem;
    color: var(--muted);
    line-height: 1.5;
}

/* ---------- เอกสาร / ส่วนเนื้อหา ---------- */
.doc-section {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 2rem 2.25rem 2.25rem;
    margin-bottom: 1.25rem;
    scroll-margin-top: 5rem;
}

.doc-section-head {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 1.5rem;
}

.doc-section-icon {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-md);
    background: var(--gold-tint);
    border: 1px solid var(--gold-line);
    color: var(--gold);
    font-size: 1rem;
}

.doc-section-title {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    line-height: 1.4;
}

.doc-section-body {
    font-size: 1.05rem;
    line-height: 1.9;
    color: var(--ink-2);
}

.rich-text > *:first-child { margin-top: 0; }
.rich-text > *:last-child { margin-bottom: 0; }
.rich-text p { margin-bottom: 1rem; }
.rich-text ul,
.rich-text ol {
    padding-left: 1.4rem;
    margin-bottom: 1rem;
}
.rich-text li { margin-bottom: .45rem; }
.rich-text li::marker { color: var(--gold-bright); }
.rich-text img { max-width: 100%; height: auto; }
.rich-text a { color: var(--gold); text-decoration: underline; }
.rich-text table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}
.rich-text th,
.rich-text td {
    border: 1px solid var(--line);
    padding: .6rem .8rem;
}

/* ---------- แท็บระดับปริญญา ---------- */
.edition-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .75rem 1.25rem;
    margin-bottom: 1.75rem;
}

.edition-label { margin-bottom: .75rem; }

.edition-tabs {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0;
}

.edition-tabs .nav-link.edition-tab {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-size: 1.02rem;
    color: var(--ink-2);
    padding: .55rem 1.1rem;
    margin: 0 .4rem .75rem 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
    transition: color .2s ease, border-color .2s ease, background-color .2s ease;
}

.edition-tabs .nav-link.edition-tab:hover {
    color: var(--gold);
    border-color: var(--gold-line);
    background: var(--gold-tint);
    text-decoration: none;
}

.edition-tabs .nav-link.edition-tab.active {
    color: var(--ink);
    font-weight: 600;
    border-color: var(--gold-line);
    background: var(--gold-tint);
    box-shadow: inset 0 -3px 0 0 var(--y-brand);
}

/* ---------- การ์ดหลักสูตร (อัตราส่วนและชื่อเดียวกับ curriculum.php) ---------- */
.program-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.15rem;
}

.program-card {
    display: block;
    text-decoration: none;
    color: inherit;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    overflow: hidden;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.program-card:hover {
    transform: translateY(-2px);
    border-color: var(--gold-line);
    box-shadow: var(--lift);
    text-decoration: none;
    color: inherit;
}

.program-card-media {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 450 / 300;
    overflow: hidden;
    background: #edeae4;
}

.program-card-media--fill.tone-0 {
    background: linear-gradient(145deg, #3d424c 0%, #1a1c20 75%);
}
.program-card-media--fill.tone-1 {
    background: linear-gradient(145deg, #4a4538 0%, #1f1c16 75%);
}
.program-card-media--fill.tone-2 {
    background: linear-gradient(145deg, #38424a 0%, #161a1f 75%);
}
.program-card-media--fill.tone-3 {
    background: linear-gradient(145deg, #3a4038 0%, #181c16 75%);
}

.program-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

.program-card:hover .program-card-media img {
    transform: none;
}

/* แถบชื่อบนภาพ — รูปแบบเดียวกับ curriculum.php (ควบคุมด้วย show_major_label) */
.program-card-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 28%;
    min-height: 1.55rem;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}

.program-card-bar-bg {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 400%;
    object-fit: cover;
    object-position: center;
    filter: blur(14px) brightness(.62) saturate(1.05);
    transform: scale(1.25);
    transform-origin: center bottom;
    display: block;
}

.program-card-bar--solid {
    background: rgba(26, 28, 32, .58);
}

.program-card-label {
    position: absolute;
    left: .4rem;
    right: .4rem;
    bottom: 0;
    z-index: 2;
    height: 28%;
    min-height: 1.55rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin: 0;
    padding: 0;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    text-align: right;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .95), 0 0 6px rgba(0, 0, 0, .7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    background: none;
}

html[data-major-label="off"] .program-card-bar,
html[data-major-label="off"] .program-card-label {
    display: none;
}

/* ---------- วิดีโอ ---------- */
.video-frame {
    position: relative;
    width: 100%;
    padding-top: 56.25%;
    border-radius: var(--r-md);
    overflow: hidden;
    background: #000;
    border: 1px solid var(--line);
}

.video-frame iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.video-trigger {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    overflow: hidden;
    background: #1a1c20;
    cursor: pointer;
    text-align: left;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.video-trigger:hover,
.video-trigger:focus {
    outline: none;
    border-color: var(--gold-line);
    transform: translateY(-2px);
    box-shadow: var(--lift);
}

.video-trigger img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
}

.video-trigger-play {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(232, 198, 90, .95);
    color: var(--ink);
    font-size: 1.15rem;
    box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .55);
    transition: transform .2s ease, background-color .2s ease;
}

.video-trigger:hover .video-trigger-play,
.video-trigger:focus .video-trigger-play {
    transform: scale(1.06);
    background: var(--y-brand);
}

.video-modal-content {
    background: #121417;
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--r-lg);
    overflow: hidden;
    color: #f7f5f0;
}

.video-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .85rem 1rem .85rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.video-modal-title {
    margin: 0;
    font-family: 'db_helvethaica_x65_med', 'Noto Sans Thai', sans-serif;
    font-size: 1.45rem;
    line-height: 1.3;
    color: #fff;
}

.video-modal-close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, .08);
    color: #fff;
    cursor: pointer;
}

.video-modal-close:hover,
.video-modal-close:focus {
    background: rgba(232, 198, 90, .9);
    color: var(--ink);
    outline: none;
}

.video-modal-body {
    padding: 0;
}

.video-modal-body .video-frame {
    border: 0;
    border-radius: 0;
}

/* ---------- บุคลากร ---------- */
.portrait {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    border-radius: var(--r-md);
    background: #edeae4;
    border: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: center;
}

.portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    transition: transform .35s ease;
}

.person:hover .portrait img,
.chair:hover .portrait img { transform: scale(1.04); }

.portrait-lg {
    width: 148px;
}

.portrait.portrait-missing::after {
    content: '\f007';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 2rem;
    color: #c4c0b8;
}

.people-grid {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 1.75rem 1.5rem;
    padding: 0;
    margin: 0;
}

.people-grid-rich {
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
}

.person {
    transition: transform .25s ease;
}

.person:hover { transform: translateY(-3px); }

.person-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.person-link:hover { text-decoration: none; color: inherit; }

.person-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin: .85rem 0 .15rem;
    line-height: 1.5;
}

.person-meta {
    margin: .2rem 0 0;
    font-size: .82rem;
    color: var(--muted);
    line-height: 1.45;
    word-break: break-word;
}

.person-meta a {
    color: var(--muted);
    text-decoration: none;
}

.person-meta a:hover { color: var(--gold); }

.person-meta i {
    color: var(--gold-bright);
    margin-right: .25rem;
    font-size: .75rem;
}

.people-group-title {
    display: flex;
    align-items: center;
    gap: .65rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 1.25rem;
}

.people-group-title::before {
    content: '';
    flex: 0 0 auto;
    width: 18px;
    height: 3px;
    background: var(--gold-bright);
}

.people-count {
    margin-left: auto;
    font-size: .78rem;
    font-weight: 600;
    color: var(--gold);
    background: var(--gold-tint);
    border: 1px solid var(--gold-line);
    border-radius: 999px;
    padding: .15rem .55rem;
}

/* ---------- ปุ่มลิงก์ ---------- */
.action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
}

.action-bar-stack {
    flex-direction: column;
}

.action {
    display: flex;
    align-items: center;
    gap: .8rem;
    flex: 1 1 240px;
    min-width: 0;
    padding: .85rem 1.1rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    color: var(--ink-2);
    text-decoration: none;
    transition: border-color .2s ease, background-color .2s ease, transform .2s ease, box-shadow .2s ease;
}

.action-bar-stack .action { flex: 0 0 auto; width: 100%; }

.action:hover {
    border-color: var(--gold-line);
    background: var(--gold-tint);
    color: var(--ink);
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: var(--lift);
}

.action-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    background: var(--gold-tint);
    border: 1px solid var(--gold-line);
    color: var(--gold);
    font-size: 1rem;
}

.action-text { min-width: 0; }

.action-name {
    display: block;
    font-size: 1.02rem;
    font-weight: 600;
    color: inherit;
    line-height: 1.4;
}

.action-meta {
    display: block;
    font-size: .78rem;
    color: var(--muted);
    line-height: 1.5;
}

/* ---------- วิดีโอที่เกี่ยวข้อง ---------- */
.related-videos {
    display: flex;
    flex-direction: column;
    gap: .85rem;
}

.related-video {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: .75rem;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.related-video:hover,
.related-video:focus {
    outline: none;
    text-decoration: none;
    color: inherit;
}

.related-video-thumb {
    position: relative;
    display: block;
    aspect-ratio: 16 / 10;
    border-radius: var(--r-sm);
    overflow: hidden;
    background: #edeae4;
    border: 1px solid var(--line);
}

.related-video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.related-video-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 28, 32, .28);
    color: #fff;
    font-size: .8rem;
}

.related-video-title {
    display: block;
    font-size: .92rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.4;
}

.related-video:hover .related-video-title { color: var(--gold); }

.related-video-meta {
    display: block;
    margin-top: .25rem;
    font-size: .75rem;
    color: var(--muted);
    line-height: 1.4;
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--muted);
}

.empty-state i {
    font-size: 2rem;
    color: var(--gold-line);
    margin-bottom: .75rem;
}

.empty-state-title {
    color: var(--ink);
    font-weight: 600;
    margin-bottom: .35rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 991.98px) {
    .dept-layout { grid-template-columns: 1fr; }
    .dept-aside { position: static; }
}

@media (max-width: 767.98px) {
    .page-container {
        padding-top: 1.5rem;
        padding-bottom: 3rem;
    }
    .doc-section {
        padding: 1.5rem 1.25rem 1.75rem;
    }
    .doc-section-title { font-size: 1.3rem; }
    .program-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .85rem;
    }
}

@media (max-width: 575.98px) {
    .program-grid {
        grid-template-columns: 1fr;
        gap: .7rem;
    }
    .program-card-label {
        font-size: .68rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .program-card,
    .program-card-media img,
    .portrait img,
    .person,
    .action {
        transition: none;
    }
    .program-card:hover,
    .person:hover,
    .action:hover { transform: none; }
    .program-card:hover .program-card-media img,
    .person:hover .portrait img { transform: none; }
}

@media print {
    body { background: #fff; }
    .page-header,
    .edition-bar,
    .dept-aside { display: none !important; }
    .doc-section { border-color: #ccc; break-inside: avoid; }
}
